Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <arch/acpi.h> |
| 15 | #include <arch/acpi_device.h> |
| 16 | #include <arch/acpigen.h> |
| 17 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 18 | #include <device/i2c_simple.h> |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/path.h> |
| 21 | #include <stdint.h> |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 22 | |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 23 | #include "chip.h" |
| 24 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 25 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 26 | |
| 27 | #define DA7219_ACPI_NAME "DLG7" |
| 28 | #define DA7219_ACPI_HID "DLGS7219" |
| 29 | |
| 30 | static void da7219_fill_ssdt(struct device *dev) |
| 31 | { |
| 32 | struct drivers_i2c_da7219_config *config = dev->chip_info; |
| 33 | const char *scope = acpi_device_scope(dev); |
| 34 | struct acpi_i2c i2c = { |
| 35 | .address = dev->path.i2c.device, |
| 36 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 37 | .speed = config->bus_speed ? : I2C_SPEED_FAST, |
| 38 | .resource = scope, |
| 39 | }; |
| 40 | struct acpi_dp *dsd, *aad; |
| 41 | |
| 42 | if (!dev->enabled || !scope) |
| 43 | return; |
| 44 | |
| 45 | /* Device */ |
| 46 | acpigen_write_scope(scope); |
| 47 | acpigen_write_device(acpi_device_name(dev)); |
| 48 | acpigen_write_name_string("_HID", DA7219_ACPI_HID); |
| 49 | acpigen_write_name_integer("_UID", 1); |
| 50 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 51 | acpigen_write_name_integer("_S0W", 4); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 52 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 53 | |
| 54 | /* Resources */ |
| 55 | acpigen_write_name("_CRS"); |
| 56 | acpigen_write_resourcetemplate_header(); |
| 57 | acpi_device_write_i2c(&i2c); |
Daniel Kurtz | 2bfae02 | 2018-01-29 15:23:39 +0530 | [diff] [blame] | 58 | /* Use either Interrupt() or GpioInt() */ |
| 59 | if (config->irq_gpio.pin_count) |
| 60 | acpi_device_write_gpio(&config->irq_gpio); |
| 61 | else |
| 62 | acpi_device_write_interrupt(&config->irq); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 63 | acpigen_write_resourcetemplate_footer(); |
| 64 | |
| 65 | /* AAD Child Device Properties */ |
| 66 | aad = acpi_dp_new_table("DAAD"); |
| 67 | acpi_dp_add_integer(aad, "dlg,btn-cfg", config->btn_cfg); |
| 68 | acpi_dp_add_integer(aad, "dlg,mic-det-thr", config->mic_det_thr); |
| 69 | acpi_dp_add_integer(aad, "dlg,jack-ins-deb", config->jack_ins_deb); |
| 70 | acpi_dp_add_string(aad, "dlg,jack-det-rate", config->jack_det_rate); |
| 71 | acpi_dp_add_integer(aad, "dlg,jack-rem-deb", config->jack_rem_deb); |
| 72 | acpi_dp_add_integer(aad, "dlg,a-d-btn-thr", config->a_d_btn_thr); |
| 73 | acpi_dp_add_integer(aad, "dlg,d-b-btn-thr", config->d_b_btn_thr); |
| 74 | acpi_dp_add_integer(aad, "dlg,b-c-btn-thr", config->b_c_btn_thr); |
| 75 | acpi_dp_add_integer(aad, "dlg,c-mic-btn-thr", config->c_mic_btn_thr); |
| 76 | acpi_dp_add_integer(aad, "dlg,btn-avg", config->btn_avg); |
| 77 | 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] | 78 | if (config->micbias_pulse_lvl > 0) { |
| 79 | acpi_dp_add_integer(aad, "dlg,micbias-pulse-lvl", |
| 80 | config->micbias_pulse_lvl); |
| 81 | acpi_dp_add_integer(aad, "dlg,micbias-pulse-time", |
| 82 | config->micbias_pulse_time); |
| 83 | } |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 84 | |
| 85 | /* DA7219 Properties */ |
| 86 | dsd = acpi_dp_new_table("_DSD"); |
| 87 | acpi_dp_add_integer(dsd, "dlg,micbias-lvl", config->micbias_lvl); |
| 88 | 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] | 89 | if (config->mclk_name != NULL) |
| 90 | acpi_dp_add_string(dsd, "dlg,mclk-name", config->mclk_name); |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 91 | acpi_dp_add_child(dsd, "da7219_aad", aad); |
| 92 | |
| 93 | /* Write Device Property Hierarchy */ |
| 94 | acpi_dp_write(dsd); |
| 95 | |
| 96 | acpigen_pop_len(); /* Device */ |
| 97 | acpigen_pop_len(); /* Scope */ |
| 98 | |
| 99 | printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 100 | acpi_device_path(dev), dev->chip_ops->name, |
| 101 | dev->path.i2c.device, config->irq.pin); |
| 102 | } |
| 103 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 104 | static const char *da7219_acpi_name(const struct device *dev) |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 105 | { |
| 106 | return DA7219_ACPI_NAME; |
| 107 | } |
| 108 | #endif |
| 109 | |
| 110 | static struct device_operations da7219_ops = { |
| 111 | .read_resources = DEVICE_NOOP, |
| 112 | .set_resources = DEVICE_NOOP, |
| 113 | .enable_resources = DEVICE_NOOP, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 114 | #if CONFIG(HAVE_ACPI_TABLES) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 115 | .acpi_name = da7219_acpi_name, |
| 116 | .acpi_fill_ssdt_generator = da7219_fill_ssdt, |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 117 | #endif |
| 118 | }; |
| 119 | |
| 120 | static void da7219_enable(struct device *dev) |
| 121 | { |
| 122 | dev->ops = &da7219_ops; |
| 123 | } |
| 124 | |
| 125 | struct chip_operations drivers_i2c_da7219_ops = { |
| 126 | CHIP_NAME("Dialog Semiconductor DA7219 Audio Codec") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 127 | .enable_dev = da7219_enable |
Duncan Laurie | dba7e76d | 2016-07-02 20:00:56 -0700 | [diff] [blame] | 128 | }; |