blob: f4912c17df544ef930666b598799c9e379f70104 [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>
Kyösti Mälkkib78e4622022-12-15 22:12:29 +02008#include <identity.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +09009#include <stdint.h>
Matt DeVillier1db8c572023-01-17 13:51:29 -060010#include <vendorcode/google/dsm_calib.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +090011#include "chip.h"
12
13#define MAX98390_ACPI_HID "MX98390"
14
15#define MAX98390_DP_INT(key, val) acpi_dp_add_integer(dp, "maxim," key, (val))
16
Seunghwan Kim8952de52020-05-18 15:01:06 +090017static void max98390_fill_ssdt(const struct device *dev)
Seunghwan Kim320d5522020-01-22 10:53:55 +090018{
19 struct drivers_i2c_max98390_config *config = dev->chip_info;
20 const char *scope = acpi_device_scope(dev);
21 struct acpi_i2c i2c = {
22 .address = dev->path.i2c.device,
23 .mode_10bit = dev->path.i2c.mode_10bit,
24 .speed = I2C_SPEED_FAST,
25 .resource = scope,
26 };
Wisley Chen889fa602021-08-24 18:39:06 +060027 struct acpi_dp *dp = NULL;
Seunghwan Kim320d5522020-01-22 10:53:55 +090028 uint64_t r0_value, temp_value;
Wisley Chen889fa602021-08-24 18:39:06 +060029 char dsm_name[80] = {};
Seunghwan Kim320d5522020-01-22 10:53:55 +090030
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070031 if (!scope)
Seunghwan Kim320d5522020-01-22 10:53:55 +090032 return;
33
34 /* Device */
35 acpigen_write_scope(scope);
36 acpigen_write_device(acpi_device_name(dev));
37 acpigen_write_name_string("_HID", MAX98390_ACPI_HID);
38 acpigen_write_name_integer("_UID", config->uid);
39 acpigen_write_name_string("_DDN", config->desc);
40 acpigen_write_STA(acpi_device_status(dev));
41
42 /* Resources */
43 acpigen_write_name("_CRS");
44 acpigen_write_resourcetemplate_header();
45 acpi_device_write_i2c(&i2c);
46 acpigen_write_resourcetemplate_footer();
47
48 /* Device Properties */
Matt DeVillier1db8c572023-01-17 13:51:29 -060049 if (CONFIG(GOOGLE_DSM_CALIB)) {
Seunghwan Kim320d5522020-01-22 10:53:55 +090050 if (get_dsm_calibration_from_key(config->r0_calib_key, &r0_value)
51 || get_dsm_calibration_from_key(config->temperature_calib_key,
52 &temp_value)) {
53 printk(BIOS_ERR,
54 "Failed to get dsm_calib parameters from VPD"
55 " with key %s and %s\n",
56 config->r0_calib_key, config->temperature_calib_key);
57 } else {
58 dp = acpi_dp_new_table("_DSD");
59 MAX98390_DP_INT("r0_calib", r0_value);
60 MAX98390_DP_INT("temperature_calib", temp_value);
Seunghwan Kim320d5522020-01-22 10:53:55 +090061 printk(BIOS_INFO, "set dsm_calib properties\n");
62 }
63 }
64
Matt DeVillier1db8c572023-01-17 13:51:29 -060065 if (CONFIG(GOOGLE_DSM_PARAM_FILE_NAME)) {
Wisley Chen889fa602021-08-24 18:39:06 +060066 if (config->dsm_param_file_name) {
67 if (!dp)
68 dp = acpi_dp_new_table("_DSD");
69
70 size_t chars = snprintf(dsm_name, sizeof(dsm_name), "%s_%s_%s.bin",
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020071 config->dsm_param_file_name, mainboard_vendor,
72 mainboard_part_number);
Wisley Chen889fa602021-08-24 18:39:06 +060073
74 if (chars >= sizeof(dsm_name))
Julius Wernere9665952022-01-21 17:06:20 -080075 printk(BIOS_ERR, "String too long in %s\n", __func__);
Wisley Chen889fa602021-08-24 18:39:06 +060076
77 acpi_dp_add_string(dp, "maxim,dsm_param_name", dsm_name);
78 }
79 }
80
Wisley Chen9cc550eb2021-09-15 17:37:16 +060081 if (!dp)
82 dp = acpi_dp_new_table("_DSD");
83
84 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
85 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
86
Wisley Chen889fa602021-08-24 18:39:06 +060087 if (dp)
88 acpi_dp_write(dp);
89
Seunghwan Kim320d5522020-01-22 10:53:55 +090090 acpigen_pop_len(); /* Device */
91 acpigen_pop_len(); /* Scope */
92
93 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
94 dev->path.i2c.device);
95}
96
97static const char *max98390_acpi_name(const struct device *dev)
98{
99 struct drivers_i2c_max98390_config *config = dev->chip_info;
100 static char name[5];
101
102 if (config->name)
103 return config->name;
104
105 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
106 return name;
107}
108
109static struct device_operations max98390_ops = {
110 .read_resources = noop_read_resources,
111 .set_resources = noop_set_resources,
112 .acpi_name = max98390_acpi_name,
Seunghwan Kim8952de52020-05-18 15:01:06 +0900113 .acpi_fill_ssdt = max98390_fill_ssdt,
Seunghwan Kim320d5522020-01-22 10:53:55 +0900114};
115
116static void max98390_enable(struct device *dev)
117{
118 struct drivers_i2c_max98390_config *config = dev->chip_info;
119
120 if (!config)
121 return;
122
123 dev->ops = &max98390_ops;
124
125 /* Name the device as per description provided in devicetree */
126 if (config->desc)
127 dev->name = config->desc;
128}
129
130struct chip_operations drivers_i2c_max98390_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900131 .name = "Maxim MAX98390 Codec",
Seunghwan Kim320d5522020-01-22 10:53:55 +0900132 .enable_dev = max98390_enable
133};