Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [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> |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/i2c.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 9 | #include "chip.h" |
| 10 | |
| 11 | #define RT5663_ACPI_NAME "RT53" |
| 12 | #define RT5663_ACPI_HID "10EC5663" |
| 13 | |
| 14 | #define RT5663_DP_INT(key, val) \ |
| 15 | acpi_dp_add_integer(dp, "realtek," key, (val)) |
| 16 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 17 | static void rt5663_fill_ssdt(const struct device *dev) |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 18 | { |
| 19 | struct drivers_i2c_rt5663_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 = config->bus_speed ? : I2C_SPEED_FAST, |
| 25 | .resource = scope, |
| 26 | }; |
| 27 | struct acpi_dp *dp; |
| 28 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 29 | if (!scope) |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 30 | return; |
| 31 | |
| 32 | /* Device */ |
| 33 | acpigen_write_scope(scope); |
| 34 | acpigen_write_device(acpi_device_name(dev)); |
| 35 | acpigen_write_name_string("_HID", RT5663_ACPI_HID); |
| 36 | acpigen_write_name_integer("_UID", config->uid); |
| 37 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 38 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 39 | |
| 40 | /* Resources */ |
| 41 | acpigen_write_name("_CRS"); |
| 42 | acpigen_write_resourcetemplate_header(); |
| 43 | acpi_device_write_i2c(&i2c); |
| 44 | /* Allow either GpioInt() or Interrupt() */ |
| 45 | if (config->irq_gpio.pin_count) |
| 46 | acpi_device_write_gpio(&config->irq_gpio); |
| 47 | else |
| 48 | acpi_device_write_interrupt(&config->irq); |
| 49 | acpigen_write_resourcetemplate_footer(); |
| 50 | |
| 51 | /* Device Properties */ |
| 52 | dp = acpi_dp_new_table("_DSD"); |
| 53 | if (config->irq_gpio.pin_count) |
| 54 | acpi_dp_add_gpio(dp, "irq-gpios", acpi_device_path(dev), 0, 0, |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 55 | config->irq_gpio.active_low); |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 56 | RT5663_DP_INT("dc_offset_l_manual", config->dc_offset_l_manual); |
| 57 | RT5663_DP_INT("dc_offset_r_manual", config->dc_offset_r_manual); |
| 58 | RT5663_DP_INT("dc_offset_l_manual_mic", config->dc_offset_l_manual_mic); |
| 59 | RT5663_DP_INT("dc_offset_r_manual_mic", config->dc_offset_r_manual_mic); |
| 60 | acpi_dp_write(dp); |
| 61 | |
| 62 | acpigen_pop_len(); /* Device */ |
| 63 | acpigen_pop_len(); /* Scope */ |
| 64 | |
| 65 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 66 | dev->chip_ops->name, dev->path.i2c.device); |
| 67 | } |
| 68 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 69 | static const char *rt5663_acpi_name(const struct device *dev) |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 70 | { |
| 71 | return RT5663_ACPI_NAME; |
| 72 | } |
| 73 | |
| 74 | static struct device_operations rt5663_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 75 | .read_resources = noop_read_resources, |
| 76 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 77 | .acpi_name = rt5663_acpi_name, |
| 78 | .acpi_fill_ssdt = rt5663_fill_ssdt, |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static void rt5663_enable(struct device *dev) |
| 82 | { |
| 83 | dev->ops = &rt5663_ops; |
| 84 | } |
| 85 | |
| 86 | struct chip_operations drivers_i2c_rt5663_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame^] | 87 | .name = "Realtek RT5663 Codec", |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 88 | .enable_dev = rt5663_enable |
Duncan Laurie | 6d5873d | 2017-08-07 17:43:26 -0700 | [diff] [blame] | 89 | }; |