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