blob: 9e82538ff4bd0c12e1c07caf78e67bda9e27116e [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>
8#include <device/path.h>
9#include <stdint.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -070010#include "chip.h"
11
Julius Wernercd49cce2019-03-05 16:53:33 -080012#if CONFIG(HAVE_ACPI_TABLES)
Duncan Laurie7522dc32016-05-10 20:20:16 -070013
14#define NAU8825_ACPI_NAME "NAU8"
15#define NAU8825_ACPI_HID "10508825"
Duncan Laurieffc99902016-07-02 19:56:06 -070016
17#define NAU8825_DP_INT(key,val) \
18 acpi_dp_add_integer(dp, "nuvoton," key, (val))
Duncan Laurie7522dc32016-05-10 20:20:16 -070019
Furquan Shaikh7536a392020-04-24 21:59:21 -070020static void nau8825_fill_ssdt(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070021{
22 struct drivers_i2c_nau8825_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 };
Duncan Laurieffc99902016-07-02 19:56:06 -070030 struct acpi_dp *dp = NULL;
Duncan Laurie7522dc32016-05-10 20:20:16 -070031
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070032 if (!scope)
Duncan Laurie7522dc32016-05-10 20:20:16 -070033 return;
34 if (config->sar_threshold_num > NAU8825_MAX_BUTTONS)
35 return;
36
37 /* Device */
38 acpigen_write_scope(scope);
39 acpigen_write_device(acpi_device_name(dev));
40 acpigen_write_name_string("_HID", NAU8825_ACPI_HID);
41 acpigen_write_name_integer("_UID", 0);
42 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080043 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie7522dc32016-05-10 20:20:16 -070044
45 /* Resources */
46 acpigen_write_name("_CRS");
47 acpigen_write_resourcetemplate_header();
48 acpi_device_write_i2c(&i2c);
Seven Leeb8159df2021-03-29 20:00:41 +080049 /* Allow either GpioInt() or Interrupt() */
50 if (config->irq_gpio.pin_count)
51 acpi_device_write_gpio(&config->irq_gpio);
52 else
53 acpi_device_write_interrupt(&config->irq);
Duncan Laurie7522dc32016-05-10 20:20:16 -070054 acpigen_write_resourcetemplate_footer();
55
56 /* Device Properties */
Duncan Laurieffc99902016-07-02 19:56:06 -070057 dp = acpi_dp_new_table("_DSD");
Duncan Laurie7522dc32016-05-10 20:20:16 -070058 NAU8825_DP_INT("jkdet-enable", config->jkdet_enable);
59 NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable);
60 NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up);
61 NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity);
62 NAU8825_DP_INT("vref-impedance", config->vref_impedance);
63 NAU8825_DP_INT("micbias-voltage", config->micbias_voltage);
64 NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis);
65 NAU8825_DP_INT("sar-voltage", config->sar_voltage);
66 NAU8825_DP_INT("sar-compare-time", config->sar_compare_time);
67 NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time);
68 NAU8825_DP_INT("short-key-debounce", config->short_key_debounce);
69 NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce);
Matt DeVillierb7f032d2023-02-13 10:24:53 -060070 NAU8825_DP_INT("jack-eject-debounce", config->jack_eject_debounce);
Duncan Laurie7522dc32016-05-10 20:20:16 -070071 NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num);
Eric Lai82a9f862022-09-15 16:06:18 +080072 NAU8825_DP_INT("adcout-drive-strong", config->adcout_ds ? 1 : 0);
Duncan Laurieffc99902016-07-02 19:56:06 -070073 acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold",
74 config->sar_threshold, config->sar_threshold_num);
75 acpi_dp_write(dp);
Duncan Laurie7522dc32016-05-10 20:20:16 -070076
77 acpigen_pop_len(); /* Device */
78 acpigen_pop_len(); /* Scope */
79
80 printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n",
81 acpi_device_path(dev), dev->chip_ops->name,
82 dev->path.i2c.device, config->irq.pin);
83}
84
Aaron Durbinaa090cb2017-09-13 16:01:52 -060085static const char *nau8825_acpi_name(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070086{
87 return NAU8825_ACPI_NAME;
88}
89#endif
90
91static struct device_operations nau8825_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020092 .read_resources = noop_read_resources,
93 .set_resources = noop_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -080094#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +020095 .acpi_name = nau8825_acpi_name,
96 .acpi_fill_ssdt = nau8825_fill_ssdt,
Duncan Laurie7522dc32016-05-10 20:20:16 -070097#endif
98};
99
100static void nau8825_enable(struct device *dev)
101{
102 dev->ops = &nau8825_ops;
103}
104
105struct chip_operations drivers_i2c_nau8825_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900106 .name = "Nuvoton NAU8825 Codec",
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100107 .enable_dev = nau8825_enable
Duncan Laurie7522dc32016-05-10 20:20:16 -0700108};