Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/i2c.h> |
| 7 | #include <device/device.h> |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 8 | #include <stdint.h> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame^] | 9 | #include <stdio.h> |
Matt DeVillier | 1db8c57 | 2023-01-17 13:51:29 -0600 | [diff] [blame] | 10 | #include <vendorcode/google/dsm_calib.h> |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 11 | #include "chip.h" |
| 12 | |
| 13 | #define RT1011_ACPI_HID "10EC1011" |
| 14 | |
| 15 | #define RT1011_DP_INT(key, val) acpi_dp_add_integer(dp, "realtek," key, (val)) |
| 16 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 17 | static void rt1011_fill_ssdt(const struct device *dev) |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 18 | { |
| 19 | struct drivers_i2c_rt1011_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 | }; |
| 27 | struct acpi_dp *dp; |
| 28 | uint64_t r0_value, temp_value; |
| 29 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 30 | if (!scope) |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 31 | return; |
| 32 | |
| 33 | /* Device */ |
| 34 | acpigen_write_scope(scope); |
| 35 | acpigen_write_device(acpi_device_name(dev)); |
| 36 | acpigen_write_name_string("_HID", RT1011_ACPI_HID); |
| 37 | acpigen_write_name_integer("_UID", config->uid); |
| 38 | acpigen_write_name_string("_DDN", config->desc); |
| 39 | acpigen_write_STA(acpi_device_status(dev)); |
| 40 | |
| 41 | /* Resources */ |
| 42 | acpigen_write_name("_CRS"); |
| 43 | acpigen_write_resourcetemplate_header(); |
| 44 | acpi_device_write_i2c(&i2c); |
| 45 | acpigen_write_resourcetemplate_footer(); |
| 46 | |
| 47 | /* Device Properties */ |
Matt DeVillier | 1db8c57 | 2023-01-17 13:51:29 -0600 | [diff] [blame] | 48 | if (CONFIG(GOOGLE_DSM_CALIB)) { |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 49 | if (get_dsm_calibration_from_key(config->r0_calib_key, &r0_value) |
| 50 | || get_dsm_calibration_from_key(config->temperature_calib_key, |
| 51 | &temp_value)) { |
| 52 | printk(BIOS_ERR, |
| 53 | "Failed to get dsm_calib parameters from VPD" |
| 54 | " with key %s and %s\n", |
| 55 | config->r0_calib_key, config->temperature_calib_key); |
| 56 | } else { |
| 57 | dp = acpi_dp_new_table("_DSD"); |
| 58 | RT1011_DP_INT("r0_calib", r0_value); |
| 59 | RT1011_DP_INT("temperature_calib", temp_value); |
| 60 | acpi_dp_write(dp); |
| 61 | printk(BIOS_INFO, "set dsm_calib properties\n"); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | acpigen_pop_len(); /* Device */ |
| 66 | acpigen_pop_len(); /* Scope */ |
| 67 | |
| 68 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name, |
| 69 | dev->path.i2c.device); |
| 70 | } |
| 71 | |
| 72 | static const char *rt1011_acpi_name(const struct device *dev) |
| 73 | { |
| 74 | struct drivers_i2c_rt1011_config *config = dev->chip_info; |
| 75 | static char name[5]; |
| 76 | |
| 77 | if (config->name) |
| 78 | return config->name; |
| 79 | |
| 80 | snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device); |
| 81 | return name; |
| 82 | } |
| 83 | |
| 84 | static struct device_operations rt1011_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 85 | .read_resources = noop_read_resources, |
| 86 | .set_resources = noop_set_resources, |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 87 | .acpi_name = rt1011_acpi_name, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 88 | .acpi_fill_ssdt = rt1011_fill_ssdt, |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | static void rt1011_enable(struct device *dev) |
| 92 | { |
| 93 | struct drivers_i2c_rt1011_config *config = dev->chip_info; |
| 94 | |
| 95 | if (!config) |
| 96 | return; |
| 97 | |
| 98 | dev->ops = &rt1011_ops; |
| 99 | |
| 100 | /* Name the device as per description provided in devicetree */ |
| 101 | if (config->desc) |
| 102 | dev->name = config->desc; |
| 103 | } |
| 104 | |
| 105 | struct chip_operations drivers_i2c_rt1011_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 106 | .name = "Realtek RT1011 Codec", |
Cheng-Yi Chiang | c761f28 | 2019-10-10 01:07:44 +0800 | [diff] [blame] | 107 | .enable_dev = rt1011_enable |
| 108 | }; |