blob: 4beb6c29b718216c1c1454f2b65e693bdc1ec847 [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.h>
4#include <acpi/acpi_device.h>
5#include <acpi/acpigen.h>
Seunghwan Kim320d5522020-01-22 10:53:55 +09006#include <console/console.h>
7#include <device/i2c.h>
8#include <device/device.h>
9#include <device/path.h>
10#include <stdint.h>
11#include <vendorcode/google/chromeos/chromeos.h>
12#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 */
50 if (CONFIG(CHROMEOS_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,
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
Wisley Chen889fa602021-08-24 18:39:06 +060066 if (CONFIG(CHROMEOS_DSM_PARAM_FILE_NAME)) {
67 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",
72 config->dsm_param_file_name, CONFIG_MAINBOARD_VENDOR,
73 CONFIG_MAINBOARD_PART_NUMBER);
74
75 if (chars >= sizeof(dsm_name))
76 printk(BIOS_ERR, "ERROR: String too long in %s\n", __func__);
77
78 acpi_dp_add_string(dp, "maxim,dsm_param_name", dsm_name);
79 }
80 }
81
82 if (dp)
83 acpi_dp_write(dp);
84
Seunghwan Kim320d5522020-01-22 10:53:55 +090085 acpigen_pop_len(); /* Device */
86 acpigen_pop_len(); /* Scope */
87
88 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
89 dev->path.i2c.device);
90}
91
92static const char *max98390_acpi_name(const struct device *dev)
93{
94 struct drivers_i2c_max98390_config *config = dev->chip_info;
95 static char name[5];
96
97 if (config->name)
98 return config->name;
99
100 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
101 return name;
102}
103
104static struct device_operations max98390_ops = {
105 .read_resources = noop_read_resources,
106 .set_resources = noop_set_resources,
107 .acpi_name = max98390_acpi_name,
Seunghwan Kim8952de52020-05-18 15:01:06 +0900108 .acpi_fill_ssdt = max98390_fill_ssdt,
Seunghwan Kim320d5522020-01-22 10:53:55 +0900109};
110
111static void max98390_enable(struct device *dev)
112{
113 struct drivers_i2c_max98390_config *config = dev->chip_info;
114
115 if (!config)
116 return;
117
118 dev->ops = &max98390_ops;
119
120 /* Name the device as per description provided in devicetree */
121 if (config->desc)
122 dev->name = config->desc;
123}
124
125struct chip_operations drivers_i2c_max98390_ops = {
126 CHIP_NAME("Maxim MAX98390 Codec")
127 .enable_dev = max98390_enable
128};