blob: 68681ef8461f7801bfa0f39a4ac270fa8f7a1abf [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Cheng-Yi Chiangc761f282019-10-10 01:07:44 +08003
4#include <arch/acpi.h>
5#include <arch/acpi_device.h>
6#include <arch/acpigen.h>
7#include <console/console.h>
8#include <device/i2c.h>
9#include <device/device.h>
10#include <device/path.h>
11#include <stdint.h>
12#include <vendorcode/google/chromeos/chromeos.h>
13#include "chip.h"
14
15#define RT1011_ACPI_HID "10EC1011"
16
17#define RT1011_DP_INT(key, val) acpi_dp_add_integer(dp, "realtek," key, (val))
18
19static void rt1011_fill_ssdt(struct device *dev)
20{
21 struct drivers_i2c_rt1011_config *config = dev->chip_info;
22 const char *scope = acpi_device_scope(dev);
23 struct acpi_i2c i2c = {
24 .address = dev->path.i2c.device,
25 .mode_10bit = dev->path.i2c.mode_10bit,
26 .speed = I2C_SPEED_FAST,
27 .resource = scope,
28 };
29 struct acpi_dp *dp;
30 uint64_t r0_value, temp_value;
31
32 if (!dev->enabled || !scope)
33 return;
34
35 /* Device */
36 acpigen_write_scope(scope);
37 acpigen_write_device(acpi_device_name(dev));
38 acpigen_write_name_string("_HID", RT1011_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 RT1011_DP_INT("r0_calib", r0_value);
61 RT1011_DP_INT("temperature_calib", temp_value);
62 acpi_dp_write(dp);
63 printk(BIOS_INFO, "set dsm_calib properties\n");
64 }
65 }
66
67 acpigen_pop_len(); /* Device */
68 acpigen_pop_len(); /* Scope */
69
70 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
71 dev->path.i2c.device);
72}
73
74static const char *rt1011_acpi_name(const struct device *dev)
75{
76 struct drivers_i2c_rt1011_config *config = dev->chip_info;
77 static char name[5];
78
79 if (config->name)
80 return config->name;
81
82 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
83 return name;
84}
85
86static struct device_operations rt1011_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020087 .read_resources = noop_read_resources,
88 .set_resources = noop_set_resources,
Cheng-Yi Chiangc761f282019-10-10 01:07:44 +080089 .acpi_name = rt1011_acpi_name,
Nico Huber68680dd2020-03-31 17:34:52 +020090 .acpi_fill_ssdt = rt1011_fill_ssdt,
Cheng-Yi Chiangc761f282019-10-10 01:07:44 +080091};
92
93static void rt1011_enable(struct device *dev)
94{
95 struct drivers_i2c_rt1011_config *config = dev->chip_info;
96
97 if (!config)
98 return;
99
100 dev->ops = &rt1011_ops;
101
102 /* Name the device as per description provided in devicetree */
103 if (config->desc)
104 dev->name = config->desc;
105}
106
107struct chip_operations drivers_i2c_rt1011_ops = {
108 CHIP_NAME("Realtek RT1011 Codec")
109 .enable_dev = rt1011_enable
110};