blob: 8bf9e4345a710541a9b297458333f79eb25e83b1 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurie7522dc32016-05-10 20:20:16 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -07005#include <console/console.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +02006#include <device/i2c_simple.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -07007#include <device/device.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -07008#include <stdint.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -07009#include "chip.h"
10
Julius Wernercd49cce2019-03-05 16:53:33 -080011#if CONFIG(HAVE_ACPI_TABLES)
Duncan Laurie7522dc32016-05-10 20:20:16 -070012
13#define NAU8825_ACPI_NAME "NAU8"
14#define NAU8825_ACPI_HID "10508825"
Duncan Laurieffc99902016-07-02 19:56:06 -070015
16#define NAU8825_DP_INT(key,val) \
17 acpi_dp_add_integer(dp, "nuvoton," key, (val))
Duncan Laurie7522dc32016-05-10 20:20:16 -070018
Furquan Shaikh7536a392020-04-24 21:59:21 -070019static void nau8825_fill_ssdt(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070020{
21 struct drivers_i2c_nau8825_config *config = dev->chip_info;
22 const char *scope = acpi_device_scope(dev);
23 struct acpi_i2c i2c = {
24 .address = dev->path.i2c.device,
25 .mode_10bit = dev->path.i2c.mode_10bit,
26 .speed = config->bus_speed ? : I2C_SPEED_FAST,
27 .resource = scope,
28 };
Duncan Laurieffc99902016-07-02 19:56:06 -070029 struct acpi_dp *dp = NULL;
Duncan Laurie7522dc32016-05-10 20:20:16 -070030
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070031 if (!scope)
Duncan Laurie7522dc32016-05-10 20:20:16 -070032 return;
33 if (config->sar_threshold_num > NAU8825_MAX_BUTTONS)
34 return;
35
36 /* Device */
37 acpigen_write_scope(scope);
38 acpigen_write_device(acpi_device_name(dev));
39 acpigen_write_name_string("_HID", NAU8825_ACPI_HID);
40 acpigen_write_name_integer("_UID", 0);
41 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080042 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie7522dc32016-05-10 20:20:16 -070043
44 /* Resources */
45 acpigen_write_name("_CRS");
46 acpigen_write_resourcetemplate_header();
47 acpi_device_write_i2c(&i2c);
Seven Leeb8159df2021-03-29 20:00:41 +080048 /* Allow either GpioInt() or Interrupt() */
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 Laurie7522dc32016-05-10 20:20:16 -070053 acpigen_write_resourcetemplate_footer();
54
55 /* Device Properties */
Duncan Laurieffc99902016-07-02 19:56:06 -070056 dp = acpi_dp_new_table("_DSD");
Duncan Laurie7522dc32016-05-10 20:20:16 -070057 NAU8825_DP_INT("jkdet-enable", config->jkdet_enable);
58 NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable);
59 NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up);
60 NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity);
61 NAU8825_DP_INT("vref-impedance", config->vref_impedance);
62 NAU8825_DP_INT("micbias-voltage", config->micbias_voltage);
63 NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis);
64 NAU8825_DP_INT("sar-voltage", config->sar_voltage);
65 NAU8825_DP_INT("sar-compare-time", config->sar_compare_time);
66 NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time);
67 NAU8825_DP_INT("short-key-debounce", config->short_key_debounce);
68 NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce);
Matt DeVillierb7f032d2023-02-13 10:24:53 -060069 NAU8825_DP_INT("jack-eject-debounce", config->jack_eject_debounce);
Duncan Laurie7522dc32016-05-10 20:20:16 -070070 NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num);
Eric Lai82a9f862022-09-15 16:06:18 +080071 NAU8825_DP_INT("adcout-drive-strong", config->adcout_ds ? 1 : 0);
Duncan Laurieffc99902016-07-02 19:56:06 -070072 acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold",
73 config->sar_threshold, config->sar_threshold_num);
74 acpi_dp_write(dp);
Duncan Laurie7522dc32016-05-10 20:20:16 -070075
76 acpigen_pop_len(); /* Device */
77 acpigen_pop_len(); /* Scope */
78
79 printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n",
80 acpi_device_path(dev), dev->chip_ops->name,
81 dev->path.i2c.device, config->irq.pin);
82}
83
Aaron Durbinaa090cb2017-09-13 16:01:52 -060084static const char *nau8825_acpi_name(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070085{
86 return NAU8825_ACPI_NAME;
87}
88#endif
89
90static struct device_operations nau8825_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020091 .read_resources = noop_read_resources,
92 .set_resources = noop_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -080093#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +020094 .acpi_name = nau8825_acpi_name,
95 .acpi_fill_ssdt = nau8825_fill_ssdt,
Duncan Laurie7522dc32016-05-10 20:20:16 -070096#endif
97};
98
99static void nau8825_enable(struct device *dev)
100{
101 dev->ops = &nau8825_ops;
102}
103
104struct chip_operations drivers_i2c_nau8825_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900105 .name = "Nuvoton NAU8825 Codec",
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100106 .enable_dev = nau8825_enable
Duncan Laurie7522dc32016-05-10 20:20:16 -0700107};