blob: 24c500bd2e64b0dcd8972bf6e7d3449f25ac7522 [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 };
28 struct acpi_dp *dp;
29 uint64_t r0_value, temp_value;
30
31 if (!dev->enabled || !scope)
32 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 */
49 if (CONFIG(CHROMEOS_DSM_CALIB)) {
50 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);
61 acpi_dp_write(dp);
62 printk(BIOS_INFO, "set dsm_calib properties\n");
63 }
64 }
65
66 acpigen_pop_len(); /* Device */
67 acpigen_pop_len(); /* Scope */
68
69 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
70 dev->path.i2c.device);
71}
72
73static const char *max98390_acpi_name(const struct device *dev)
74{
75 struct drivers_i2c_max98390_config *config = dev->chip_info;
76 static char name[5];
77
78 if (config->name)
79 return config->name;
80
81 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
82 return name;
83}
84
85static struct device_operations max98390_ops = {
86 .read_resources = noop_read_resources,
87 .set_resources = noop_set_resources,
88 .acpi_name = max98390_acpi_name,
Seunghwan Kim8952de52020-05-18 15:01:06 +090089 .acpi_fill_ssdt = max98390_fill_ssdt,
Seunghwan Kim320d5522020-01-22 10:53:55 +090090};
91
92static void max98390_enable(struct device *dev)
93{
94 struct drivers_i2c_max98390_config *config = dev->chip_info;
95
96 if (!config)
97 return;
98
99 dev->ops = &max98390_ops;
100
101 /* Name the device as per description provided in devicetree */
102 if (config->desc)
103 dev->name = config->desc;
104}
105
106struct chip_operations drivers_i2c_max98390_ops = {
107 CHIP_NAME("Maxim MAX98390 Codec")
108 .enable_dev = max98390_enable
109};