Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpigen.h> |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 7 | #include <device/i2c_simple.h> |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 8 | #include <device/device.h> |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 9 | |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 10 | #include "chip.h" |
| 11 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 12 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 13 | |
| 14 | #define DA7219_ACPI_NAME "DLG7" |
| 15 | #define DA7219_ACPI_HID "DLGS7219" |
| 16 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 17 | static void da7219_fill_ssdt(const struct device *dev) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 18 | { |
| 19 | struct drivers_i2c_da7219_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 *dsd, *aad; |
| 28 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 29 | if (!scope) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -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", DA7219_ACPI_HID); |
| 36 | acpigen_write_name_integer("_UID", 1); |
| 37 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Tim Wawrzynczak | 72c0b54 | 2021-08-05 09:30:05 -0600 | [diff] [blame] | 38 | acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_HOT); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 39 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 40 | |
| 41 | /* Resources */ |
| 42 | acpigen_write_name("_CRS"); |
| 43 | acpigen_write_resourcetemplate_header(); |
| 44 | acpi_device_write_i2c(&i2c); |
Daniel Kurtz | 2bfae02 | 2018-01-29 15:23:39 +0530 | [diff] [blame] | 45 | /* Use either Interrupt() or GpioInt() */ |
| 46 | if (config->irq_gpio.pin_count) |
| 47 | acpi_device_write_gpio(&config->irq_gpio); |
| 48 | else |
| 49 | acpi_device_write_interrupt(&config->irq); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 50 | acpigen_write_resourcetemplate_footer(); |
| 51 | |
| 52 | /* AAD Child Device Properties */ |
| 53 | aad = acpi_dp_new_table("DAAD"); |
| 54 | acpi_dp_add_integer(aad, "dlg,btn-cfg", config->btn_cfg); |
| 55 | acpi_dp_add_integer(aad, "dlg,mic-det-thr", config->mic_det_thr); |
| 56 | acpi_dp_add_integer(aad, "dlg,jack-ins-deb", config->jack_ins_deb); |
| 57 | acpi_dp_add_string(aad, "dlg,jack-det-rate", config->jack_det_rate); |
| 58 | acpi_dp_add_integer(aad, "dlg,jack-rem-deb", config->jack_rem_deb); |
| 59 | acpi_dp_add_integer(aad, "dlg,a-d-btn-thr", config->a_d_btn_thr); |
| 60 | acpi_dp_add_integer(aad, "dlg,d-b-btn-thr", config->d_b_btn_thr); |
| 61 | acpi_dp_add_integer(aad, "dlg,b-c-btn-thr", config->b_c_btn_thr); |
| 62 | acpi_dp_add_integer(aad, "dlg,c-mic-btn-thr", config->c_mic_btn_thr); |
| 63 | acpi_dp_add_integer(aad, "dlg,btn-avg", config->btn_avg); |
| 64 | acpi_dp_add_integer(aad, "dlg,adc-1bit-rpt", config->adc_1bit_rpt); |
Daniel Kurtz | cd62cac | 2018-07-23 17:26:59 -0600 | [diff] [blame] | 65 | if (config->micbias_pulse_lvl > 0) { |
| 66 | acpi_dp_add_integer(aad, "dlg,micbias-pulse-lvl", |
| 67 | config->micbias_pulse_lvl); |
| 68 | acpi_dp_add_integer(aad, "dlg,micbias-pulse-time", |
| 69 | config->micbias_pulse_time); |
| 70 | } |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 71 | |
| 72 | /* DA7219 Properties */ |
| 73 | dsd = acpi_dp_new_table("_DSD"); |
| 74 | acpi_dp_add_integer(dsd, "dlg,micbias-lvl", config->micbias_lvl); |
| 75 | acpi_dp_add_string(dsd, "dlg,mic-amp-in-sel", config->mic_amp_in_sel); |
Akshu Agrawal | 5418b9b | 2018-04-25 17:53:56 +0800 | [diff] [blame] | 76 | if (config->mclk_name != NULL) |
| 77 | acpi_dp_add_string(dsd, "dlg,mclk-name", config->mclk_name); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 78 | acpi_dp_add_child(dsd, "da7219_aad", aad); |
| 79 | |
| 80 | /* Write Device Property Hierarchy */ |
| 81 | acpi_dp_write(dsd); |
| 82 | |
| 83 | acpigen_pop_len(); /* Device */ |
| 84 | acpigen_pop_len(); /* Scope */ |
| 85 | |
| 86 | printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 87 | acpi_device_path(dev), dev->chip_ops->name, |
| 88 | dev->path.i2c.device, config->irq.pin); |
| 89 | } |
| 90 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 91 | static const char *da7219_acpi_name(const struct device *dev) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 92 | { |
| 93 | return DA7219_ACPI_NAME; |
| 94 | } |
| 95 | #endif |
| 96 | |
| 97 | static struct device_operations da7219_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 98 | .read_resources = noop_read_resources, |
| 99 | .set_resources = noop_set_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 100 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 101 | .acpi_name = da7219_acpi_name, |
| 102 | .acpi_fill_ssdt = da7219_fill_ssdt, |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 103 | #endif |
| 104 | }; |
| 105 | |
| 106 | static void da7219_enable(struct device *dev) |
| 107 | { |
| 108 | dev->ops = &da7219_ops; |
| 109 | } |
| 110 | |
| 111 | struct chip_operations drivers_i2c_da7219_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 112 | .name = "Dialog Semiconductor DA7219 Audio Codec", |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 113 | .enable_dev = da7219_enable |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 114 | }; |