blob: 5f5b4d526ac3a53c61f976b0ac6cc488c976f207 [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 Laurie7522dc32016-05-10 20:20:16 -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 Laurie7522dc32016-05-10 20:20:16 -07009#include <device/device.h>
10#include <device/path.h>
11#include <stdint.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -070012#include "chip.h"
13
Julius Wernercd49cce2019-03-05 16:53:33 -080014#if CONFIG(HAVE_ACPI_TABLES)
Duncan Laurie7522dc32016-05-10 20:20:16 -070015
16#define NAU8825_ACPI_NAME "NAU8"
17#define NAU8825_ACPI_HID "10508825"
Duncan Laurieffc99902016-07-02 19:56:06 -070018
19#define NAU8825_DP_INT(key,val) \
20 acpi_dp_add_integer(dp, "nuvoton," key, (val))
Duncan Laurie7522dc32016-05-10 20:20:16 -070021
22static void nau8825_fill_ssdt(struct device *dev)
23{
24 struct drivers_i2c_nau8825_config *config = dev->chip_info;
25 const char *scope = acpi_device_scope(dev);
26 struct acpi_i2c i2c = {
27 .address = dev->path.i2c.device,
28 .mode_10bit = dev->path.i2c.mode_10bit,
29 .speed = config->bus_speed ? : I2C_SPEED_FAST,
30 .resource = scope,
31 };
Duncan Laurieffc99902016-07-02 19:56:06 -070032 struct acpi_dp *dp = NULL;
Duncan Laurie7522dc32016-05-10 20:20:16 -070033
34 if (!dev->enabled || !scope)
35 return;
36 if (config->sar_threshold_num > NAU8825_MAX_BUTTONS)
37 return;
38
39 /* Device */
40 acpigen_write_scope(scope);
41 acpigen_write_device(acpi_device_name(dev));
42 acpigen_write_name_string("_HID", NAU8825_ACPI_HID);
43 acpigen_write_name_integer("_UID", 0);
44 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080045 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie7522dc32016-05-10 20:20:16 -070046
47 /* Resources */
48 acpigen_write_name("_CRS");
49 acpigen_write_resourcetemplate_header();
50 acpi_device_write_i2c(&i2c);
51 acpi_device_write_interrupt(&config->irq);
52 acpigen_write_resourcetemplate_footer();
53
54 /* Device Properties */
Duncan Laurieffc99902016-07-02 19:56:06 -070055 dp = acpi_dp_new_table("_DSD");
Duncan Laurie7522dc32016-05-10 20:20:16 -070056 NAU8825_DP_INT("jkdet-enable", config->jkdet_enable);
57 NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable);
58 NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up);
59 NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity);
60 NAU8825_DP_INT("vref-impedance", config->vref_impedance);
61 NAU8825_DP_INT("micbias-voltage", config->micbias_voltage);
62 NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis);
63 NAU8825_DP_INT("sar-voltage", config->sar_voltage);
64 NAU8825_DP_INT("sar-compare-time", config->sar_compare_time);
65 NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time);
66 NAU8825_DP_INT("short-key-debounce", config->short_key_debounce);
67 NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce);
68 NAU8825_DP_INT("jack-eject-deboune", config->jack_eject_debounce);
69 NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num);
Duncan Laurieffc99902016-07-02 19:56:06 -070070 acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold",
71 config->sar_threshold, config->sar_threshold_num);
72 acpi_dp_write(dp);
Duncan Laurie7522dc32016-05-10 20:20:16 -070073
74 acpigen_pop_len(); /* Device */
75 acpigen_pop_len(); /* Scope */
76
77 printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n",
78 acpi_device_path(dev), dev->chip_ops->name,
79 dev->path.i2c.device, config->irq.pin);
80}
81
Aaron Durbinaa090cb2017-09-13 16:01:52 -060082static const char *nau8825_acpi_name(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070083{
84 return NAU8825_ACPI_NAME;
85}
86#endif
87
88static struct device_operations nau8825_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020089 .read_resources = DEVICE_NOOP,
90 .set_resources = DEVICE_NOOP,
91 .enable_resources = DEVICE_NOOP,
Julius Wernercd49cce2019-03-05 16:53:33 -080092#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +020093 .acpi_name = nau8825_acpi_name,
94 .acpi_fill_ssdt = nau8825_fill_ssdt,
Duncan Laurie7522dc32016-05-10 20:20:16 -070095#endif
96};
97
98static void nau8825_enable(struct device *dev)
99{
100 dev->ops = &nau8825_ops;
101}
102
103struct chip_operations drivers_i2c_nau8825_ops = {
104 CHIP_NAME("Nuvoton NAU8825 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100105 .enable_dev = nau8825_enable
Duncan Laurie7522dc32016-05-10 20:20:16 -0700106};