blob: 4cfeb9fb72792cef673f54755e426de4ec9835d0 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Lauriedba7e76d2016-07-02 20:00:56 -07003
4#include <arch/acpi.h>
5#include <arch/acpi_device.h>
6#include <arch/acpigen.h>
7#include <console/console.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +02008#include <device/i2c_simple.h>
Duncan Lauriedba7e76d2016-07-02 20:00:56 -07009#include <device/device.h>
10#include <device/path.h>
11#include <stdint.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010012
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070013#include "chip.h"
14
Julius Wernercd49cce2019-03-05 16:53:33 -080015#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070016
17#define DA7219_ACPI_NAME "DLG7"
18#define DA7219_ACPI_HID "DLGS7219"
19
20static void da7219_fill_ssdt(struct device *dev)
21{
22 struct drivers_i2c_da7219_config *config = dev->chip_info;
23 const char *scope = acpi_device_scope(dev);
24 struct acpi_i2c i2c = {
25 .address = dev->path.i2c.device,
26 .mode_10bit = dev->path.i2c.mode_10bit,
27 .speed = config->bus_speed ? : I2C_SPEED_FAST,
28 .resource = scope,
29 };
30 struct acpi_dp *dsd, *aad;
31
32 if (!dev->enabled || !scope)
33 return;
34
35 /* Device */
36 acpigen_write_scope(scope);
37 acpigen_write_device(acpi_device_name(dev));
38 acpigen_write_name_string("_HID", DA7219_ACPI_HID);
39 acpigen_write_name_integer("_UID", 1);
40 acpigen_write_name_string("_DDN", dev->chip_ops->name);
41 acpigen_write_name_integer("_S0W", 4);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080042 acpigen_write_STA(acpi_device_status(dev));
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070043
44 /* Resources */
45 acpigen_write_name("_CRS");
46 acpigen_write_resourcetemplate_header();
47 acpi_device_write_i2c(&i2c);
Daniel Kurtz2bfae022018-01-29 15:23:39 +053048 /* Use either Interrupt() or GpioInt() */
49 if (config->irq_gpio.pin_count)
50 acpi_device_write_gpio(&config->irq_gpio);
51 else
52 acpi_device_write_interrupt(&config->irq);
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070053 acpigen_write_resourcetemplate_footer();
54
55 /* AAD Child Device Properties */
56 aad = acpi_dp_new_table("DAAD");
57 acpi_dp_add_integer(aad, "dlg,btn-cfg", config->btn_cfg);
58 acpi_dp_add_integer(aad, "dlg,mic-det-thr", config->mic_det_thr);
59 acpi_dp_add_integer(aad, "dlg,jack-ins-deb", config->jack_ins_deb);
60 acpi_dp_add_string(aad, "dlg,jack-det-rate", config->jack_det_rate);
61 acpi_dp_add_integer(aad, "dlg,jack-rem-deb", config->jack_rem_deb);
62 acpi_dp_add_integer(aad, "dlg,a-d-btn-thr", config->a_d_btn_thr);
63 acpi_dp_add_integer(aad, "dlg,d-b-btn-thr", config->d_b_btn_thr);
64 acpi_dp_add_integer(aad, "dlg,b-c-btn-thr", config->b_c_btn_thr);
65 acpi_dp_add_integer(aad, "dlg,c-mic-btn-thr", config->c_mic_btn_thr);
66 acpi_dp_add_integer(aad, "dlg,btn-avg", config->btn_avg);
67 acpi_dp_add_integer(aad, "dlg,adc-1bit-rpt", config->adc_1bit_rpt);
Daniel Kurtzcd62cac2018-07-23 17:26:59 -060068 if (config->micbias_pulse_lvl > 0) {
69 acpi_dp_add_integer(aad, "dlg,micbias-pulse-lvl",
70 config->micbias_pulse_lvl);
71 acpi_dp_add_integer(aad, "dlg,micbias-pulse-time",
72 config->micbias_pulse_time);
73 }
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070074
75 /* DA7219 Properties */
76 dsd = acpi_dp_new_table("_DSD");
77 acpi_dp_add_integer(dsd, "dlg,micbias-lvl", config->micbias_lvl);
78 acpi_dp_add_string(dsd, "dlg,mic-amp-in-sel", config->mic_amp_in_sel);
Akshu Agrawal5418b9b2018-04-25 17:53:56 +080079 if (config->mclk_name != NULL)
80 acpi_dp_add_string(dsd, "dlg,mclk-name", config->mclk_name);
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070081 acpi_dp_add_child(dsd, "da7219_aad", aad);
82
83 /* Write Device Property Hierarchy */
84 acpi_dp_write(dsd);
85
86 acpigen_pop_len(); /* Device */
87 acpigen_pop_len(); /* Scope */
88
89 printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n",
90 acpi_device_path(dev), dev->chip_ops->name,
91 dev->path.i2c.device, config->irq.pin);
92}
93
Aaron Durbinaa090cb2017-09-13 16:01:52 -060094static const char *da7219_acpi_name(const struct device *dev)
Duncan Lauriedba7e76d2016-07-02 20:00:56 -070095{
96 return DA7219_ACPI_NAME;
97}
98#endif
99
100static struct device_operations da7219_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200101 .read_resources = noop_read_resources,
102 .set_resources = noop_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800103#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200104 .acpi_name = da7219_acpi_name,
105 .acpi_fill_ssdt = da7219_fill_ssdt,
Duncan Lauriedba7e76d2016-07-02 20:00:56 -0700106#endif
107};
108
109static void da7219_enable(struct device *dev)
110{
111 dev->ops = &da7219_ops;
112}
113
114struct chip_operations drivers_i2c_da7219_ops = {
115 CHIP_NAME("Dialog Semiconductor DA7219 Audio Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100116 .enable_dev = da7219_enable
Duncan Lauriedba7e76d2016-07-02 20:00:56 -0700117};