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