acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / i2c / da7219 / da7219.c
blobe6a5283a92f08f93ea050a69360a1ce4cf136fbe
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi.h>
4 #include <acpi/acpi_device.h>
5 #include <acpi/acpigen.h>
6 #include <console/console.h>
7 #include <device/i2c_simple.h>
8 #include <device/device.h>
10 #include "chip.h"
12 #if CONFIG(HAVE_ACPI_TABLES)
14 #define DA7219_ACPI_NAME "DLG7"
15 #define DA7219_ACPI_HID "DLGS7219"
17 static void da7219_fill_ssdt(const struct device *dev)
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,
27 struct acpi_dp *dsd, *aad;
29 if (!scope)
30 return;
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);
38 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_HOT);
39 acpigen_write_STA(acpi_device_status(dev));
41 /* Resources */
42 acpigen_write_name("_CRS");
43 acpigen_write_resourcetemplate_header();
44 acpi_device_write_i2c(&i2c);
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);
50 acpigen_write_resourcetemplate_footer();
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);
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);
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);
76 if (config->mclk_name != NULL)
77 acpi_dp_add_string(dsd, "dlg,mclk-name", config->mclk_name);
78 acpi_dp_add_child(dsd, "da7219_aad", aad);
80 /* Write Device Property Hierarchy */
81 acpi_dp_write(dsd);
83 acpigen_pop_len(); /* Device */
84 acpigen_pop_len(); /* Scope */
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);
91 static const char *da7219_acpi_name(const struct device *dev)
93 return DA7219_ACPI_NAME;
95 #endif
97 static struct device_operations da7219_ops = {
98 .read_resources = noop_read_resources,
99 .set_resources = noop_set_resources,
100 #if CONFIG(HAVE_ACPI_TABLES)
101 .acpi_name = da7219_acpi_name,
102 .acpi_fill_ssdt = da7219_fill_ssdt,
103 #endif
106 static void da7219_enable(struct device *dev)
108 dev->ops = &da7219_ops;
111 struct chip_operations drivers_i2c_da7219_ops = {
112 .name = "Dialog Semiconductor DA7219 Audio Codec",
113 .enable_dev = da7219_enable