blob: f4c4a70b92e1ac859fd8c187f42faca00b7f85b2 [file] [log] [blame]
Seunghwan Kim320d5522020-01-22 10:53:55 +09001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
Seunghwan Kim189e7532020-05-14 10:20:46 +09003#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +09005#include <console/console.h>
6#include <device/i2c.h>
7#include <device/device.h>
8#include <device/path.h>
Kyösti Mälkkib78e4622022-12-15 22:12:29 +02009#include <identity.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +090010#include <stdint.h>
Matt DeVillier1db8c572023-01-17 13:51:29 -060011#include <vendorcode/google/dsm_calib.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +090012#include "chip.h"
13
14#define MAX98390_ACPI_HID "MX98390"
15
16#define MAX98390_DP_INT(key, val) acpi_dp_add_integer(dp, "maxim," key, (val))
17
Seunghwan Kim8952de52020-05-18 15:01:06 +090018static void max98390_fill_ssdt(const struct device *dev)
Seunghwan Kim320d5522020-01-22 10:53:55 +090019{
20 struct drivers_i2c_max98390_config *config = dev->chip_info;
21 const char *scope = acpi_device_scope(dev);
22 struct acpi_i2c i2c = {
23 .address = dev->path.i2c.device,
24 .mode_10bit = dev->path.i2c.mode_10bit,
25 .speed = I2C_SPEED_FAST,
26 .resource = scope,
27 };
Wisley Chen889fa602021-08-24 18:39:06 +060028 struct acpi_dp *dp = NULL;
Seunghwan Kim320d5522020-01-22 10:53:55 +090029 uint64_t r0_value, temp_value;
Wisley Chen889fa602021-08-24 18:39:06 +060030 char dsm_name[80] = {};
Seunghwan Kim320d5522020-01-22 10:53:55 +090031
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070032 if (!scope)
Seunghwan Kim320d5522020-01-22 10:53:55 +090033 return;
34
35 /* Device */
36 acpigen_write_scope(scope);
37 acpigen_write_device(acpi_device_name(dev));
38 acpigen_write_name_string("_HID", MAX98390_ACPI_HID);
39 acpigen_write_name_integer("_UID", config->uid);
40 acpigen_write_name_string("_DDN", config->desc);
41 acpigen_write_STA(acpi_device_status(dev));
42
43 /* Resources */
44 acpigen_write_name("_CRS");
45 acpigen_write_resourcetemplate_header();
46 acpi_device_write_i2c(&i2c);
47 acpigen_write_resourcetemplate_footer();
48
49 /* Device Properties */
Matt DeVillier1db8c572023-01-17 13:51:29 -060050 if (CONFIG(GOOGLE_DSM_CALIB)) {
Seunghwan Kim320d5522020-01-22 10:53:55 +090051 if (get_dsm_calibration_from_key(config->r0_calib_key, &r0_value)
52 || get_dsm_calibration_from_key(config->temperature_calib_key,
53 &temp_value)) {
54 printk(BIOS_ERR,
55 "Failed to get dsm_calib parameters from VPD"
56 " with key %s and %s\n",
57 config->r0_calib_key, config->temperature_calib_key);
58 } else {
59 dp = acpi_dp_new_table("_DSD");
60 MAX98390_DP_INT("r0_calib", r0_value);
61 MAX98390_DP_INT("temperature_calib", temp_value);
Seunghwan Kim320d5522020-01-22 10:53:55 +090062 printk(BIOS_INFO, "set dsm_calib properties\n");
63 }
64 }
65
Matt DeVillier1db8c572023-01-17 13:51:29 -060066 if (CONFIG(GOOGLE_DSM_PARAM_FILE_NAME)) {
Wisley Chen889fa602021-08-24 18:39:06 +060067 if (config->dsm_param_file_name) {
68 if (!dp)
69 dp = acpi_dp_new_table("_DSD");
70
71 size_t chars = snprintf(dsm_name, sizeof(dsm_name), "%s_%s_%s.bin",
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020072 config->dsm_param_file_name, mainboard_vendor,
73 mainboard_part_number);
Wisley Chen889fa602021-08-24 18:39:06 +060074
75 if (chars >= sizeof(dsm_name))
Julius Wernere9665952022-01-21 17:06:20 -080076 printk(BIOS_ERR, "String too long in %s\n", __func__);
Wisley Chen889fa602021-08-24 18:39:06 +060077
78 acpi_dp_add_string(dp, "maxim,dsm_param_name", dsm_name);
79 }
80 }
81
Wisley Chen9cc550e2021-09-15 17:37:16 +060082 if (!dp)
83 dp = acpi_dp_new_table("_DSD");
84
85 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
86 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
87
Wisley Chen889fa602021-08-24 18:39:06 +060088 if (dp)
89 acpi_dp_write(dp);
90
Seunghwan Kim320d5522020-01-22 10:53:55 +090091 acpigen_pop_len(); /* Device */
92 acpigen_pop_len(); /* Scope */
93
94 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
95 dev->path.i2c.device);
96}
97
98static const char *max98390_acpi_name(const struct device *dev)
99{
100 struct drivers_i2c_max98390_config *config = dev->chip_info;
101 static char name[5];
102
103 if (config->name)
104 return config->name;
105
106 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
107 return name;
108}
109
110static struct device_operations max98390_ops = {
111 .read_resources = noop_read_resources,
112 .set_resources = noop_set_resources,
113 .acpi_name = max98390_acpi_name,
Seunghwan Kim8952de52020-05-18 15:01:06 +0900114 .acpi_fill_ssdt = max98390_fill_ssdt,
Seunghwan Kim320d5522020-01-22 10:53:55 +0900115};
116
117static void max98390_enable(struct device *dev)
118{
119 struct drivers_i2c_max98390_config *config = dev->chip_info;
120
121 if (!config)
122 return;
123
124 dev->ops = &max98390_ops;
125
126 /* Name the device as per description provided in devicetree */
127 if (config->desc)
128 dev->name = config->desc;
129}
130
131struct chip_operations drivers_i2c_max98390_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900132 .name = "Maxim MAX98390 Codec",
Seunghwan Kim320d5522020-01-22 10:53:55 +0900133 .enable_dev = max98390_enable
134};