blob: 5d56b243e1d99e5d5781ff390f63b00e0dc064df [file] [log] [blame]
Duncan Laurie7522dc32016-05-10 20:20:16 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Laurie7522dc32016-05-10 20:20:16 -07004 * 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 Huber0f2dd1e2017-08-01 14:02:40 +020018#include <device/i2c_simple.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -070019#include <device/device.h>
20#include <device/path.h>
21#include <stdint.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -070022#include "chip.h"
23
Julius Wernercd49cce2019-03-05 16:53:33 -080024#if CONFIG(HAVE_ACPI_TABLES)
Duncan Laurie7522dc32016-05-10 20:20:16 -070025
26#define NAU8825_ACPI_NAME "NAU8"
27#define NAU8825_ACPI_HID "10508825"
Duncan Laurieffc99902016-07-02 19:56:06 -070028
29#define NAU8825_DP_INT(key,val) \
30 acpi_dp_add_integer(dp, "nuvoton," key, (val))
Duncan Laurie7522dc32016-05-10 20:20:16 -070031
32static void nau8825_fill_ssdt(struct device *dev)
33{
34 struct drivers_i2c_nau8825_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 };
Duncan Laurieffc99902016-07-02 19:56:06 -070042 struct acpi_dp *dp = NULL;
Duncan Laurie7522dc32016-05-10 20:20:16 -070043
44 if (!dev->enabled || !scope)
45 return;
46 if (config->sar_threshold_num > NAU8825_MAX_BUTTONS)
47 return;
48
49 /* Device */
50 acpigen_write_scope(scope);
51 acpigen_write_device(acpi_device_name(dev));
52 acpigen_write_name_string("_HID", NAU8825_ACPI_HID);
53 acpigen_write_name_integer("_UID", 0);
54 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080055 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie7522dc32016-05-10 20:20:16 -070056
57 /* Resources */
58 acpigen_write_name("_CRS");
59 acpigen_write_resourcetemplate_header();
60 acpi_device_write_i2c(&i2c);
61 acpi_device_write_interrupt(&config->irq);
62 acpigen_write_resourcetemplate_footer();
63
64 /* Device Properties */
Duncan Laurieffc99902016-07-02 19:56:06 -070065 dp = acpi_dp_new_table("_DSD");
Duncan Laurie7522dc32016-05-10 20:20:16 -070066 NAU8825_DP_INT("jkdet-enable", config->jkdet_enable);
67 NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable);
68 NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up);
69 NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity);
70 NAU8825_DP_INT("vref-impedance", config->vref_impedance);
71 NAU8825_DP_INT("micbias-voltage", config->micbias_voltage);
72 NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis);
73 NAU8825_DP_INT("sar-voltage", config->sar_voltage);
74 NAU8825_DP_INT("sar-compare-time", config->sar_compare_time);
75 NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time);
76 NAU8825_DP_INT("short-key-debounce", config->short_key_debounce);
77 NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce);
78 NAU8825_DP_INT("jack-eject-deboune", config->jack_eject_debounce);
79 NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num);
Duncan Laurieffc99902016-07-02 19:56:06 -070080 acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold",
81 config->sar_threshold, config->sar_threshold_num);
82 acpi_dp_write(dp);
Duncan Laurie7522dc32016-05-10 20:20:16 -070083
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 Durbinaa090cb2017-09-13 16:01:52 -060092static const char *nau8825_acpi_name(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070093{
94 return NAU8825_ACPI_NAME;
95}
96#endif
97
98static struct device_operations nau8825_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020099 .read_resources = DEVICE_NOOP,
100 .set_resources = DEVICE_NOOP,
101 .enable_resources = DEVICE_NOOP,
Julius Wernercd49cce2019-03-05 16:53:33 -0800102#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200103 .acpi_name = nau8825_acpi_name,
104 .acpi_fill_ssdt = nau8825_fill_ssdt,
Duncan Laurie7522dc32016-05-10 20:20:16 -0700105#endif
106};
107
108static void nau8825_enable(struct device *dev)
109{
110 dev->ops = &nau8825_ops;
111}
112
113struct chip_operations drivers_i2c_nau8825_ops = {
114 CHIP_NAME("Nuvoton NAU8825 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100115 .enable_dev = nau8825_enable
Duncan Laurie7522dc32016-05-10 20:20:16 -0700116};