1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/i2c.h>
7 #include <device/device.h>
11 #include <vendorcode/google/dsm_calib.h>
14 #define MAX98390_ACPI_HID "MX98390"
16 #define MAX98390_DP_INT(key, val) acpi_dp_add_integer(dp, "maxim," key, (val))
18 static void max98390_fill_ssdt(const struct device
*dev
)
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
,
28 struct acpi_dp
*dp
= NULL
;
29 uint64_t r0_value
, temp_value
;
30 char dsm_name
[80] = {};
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
));
44 acpigen_write_name("_CRS");
45 acpigen_write_resourcetemplate_header();
46 acpi_device_write_i2c(&i2c
);
47 acpigen_write_resourcetemplate_footer();
49 /* Device Properties */
50 if (CONFIG(GOOGLE_DSM_CALIB
)) {
51 if (get_dsm_calibration_from_key(config
->r0_calib_key
, &r0_value
)
52 || get_dsm_calibration_from_key(config
->temperature_calib_key
,
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
);
59 dp
= acpi_dp_new_table("_DSD");
60 MAX98390_DP_INT("r0_calib", r0_value
);
61 MAX98390_DP_INT("temperature_calib", temp_value
);
62 printk(BIOS_INFO
, "set dsm_calib properties\n");
66 if (CONFIG(GOOGLE_DSM_PARAM_FILE_NAME
)) {
67 if (config
->dsm_param_file_name
) {
69 dp
= acpi_dp_new_table("_DSD");
71 size_t chars
= snprintf(dsm_name
, sizeof(dsm_name
), "%s_%s_%s.bin",
72 config
->dsm_param_file_name
, mainboard_vendor
,
73 mainboard_part_number
);
75 if (chars
>= sizeof(dsm_name
))
76 printk(BIOS_ERR
, "String too long in %s\n", __func__
);
78 acpi_dp_add_string(dp
, "maxim,dsm_param_name", dsm_name
);
83 dp
= acpi_dp_new_table("_DSD");
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
);
91 acpigen_pop_len(); /* Device */
92 acpigen_pop_len(); /* Scope */
94 printk(BIOS_INFO
, "%s: %s address 0%xh\n", acpi_device_path(dev
), dev
->chip_ops
->name
,
95 dev
->path
.i2c
.device
);
98 static const char *max98390_acpi_name(const struct device
*dev
)
100 struct drivers_i2c_max98390_config
*config
= dev
->chip_info
;
106 snprintf(name
, sizeof(name
), "D%03.3X", dev
->path
.i2c
.device
);
110 static struct device_operations max98390_ops
= {
111 .read_resources
= noop_read_resources
,
112 .set_resources
= noop_set_resources
,
113 .acpi_name
= max98390_acpi_name
,
114 .acpi_fill_ssdt
= max98390_fill_ssdt
,
117 static void max98390_enable(struct device
*dev
)
119 struct drivers_i2c_max98390_config
*config
= dev
->chip_info
;
124 dev
->ops
= &max98390_ops
;
126 /* Name the device as per description provided in devicetree */
128 dev
->name
= config
->desc
;
131 struct chip_operations drivers_i2c_max98390_ops
= {
132 .name
= "Maxim MAX98390 Codec",
133 .enable_dev
= max98390_enable