Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi.h> |
| 5 | #include <arch/acpi_device.h> |
| 6 | #include <arch/acpigen.h> |
| 7 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 8 | #include <device/i2c_simple.h> |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/path.h> |
| 11 | #include <stdint.h> |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 12 | #include "chip.h" |
| 13 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 14 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 15 | |
| 16 | #define NAU8825_ACPI_NAME "NAU8" |
| 17 | #define NAU8825_ACPI_HID "10508825" |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 18 | |
| 19 | #define NAU8825_DP_INT(key,val) \ |
| 20 | acpi_dp_add_integer(dp, "nuvoton," key, (val)) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 21 | |
| 22 | static 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 32 | struct acpi_dp *dp = NULL; |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 33 | |
| 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 Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 45 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 46 | |
| 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 55 | dp = acpi_dp_new_table("_DSD"); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 56 | 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 70 | acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold", |
| 71 | config->sar_threshold, config->sar_threshold_num); |
| 72 | acpi_dp_write(dp); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 73 | |
| 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 Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 82 | static const char *nau8825_acpi_name(const struct device *dev) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 83 | { |
| 84 | return NAU8825_ACPI_NAME; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | static struct device_operations nau8825_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 89 | .read_resources = noop_read_resources, |
| 90 | .set_resources = noop_set_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 91 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 92 | .acpi_name = nau8825_acpi_name, |
| 93 | .acpi_fill_ssdt = nau8825_fill_ssdt, |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 94 | #endif |
| 95 | }; |
| 96 | |
| 97 | static void nau8825_enable(struct device *dev) |
| 98 | { |
| 99 | dev->ops = &nau8825_ops; |
| 100 | } |
| 101 | |
| 102 | struct chip_operations drivers_i2c_nau8825_ops = { |
| 103 | CHIP_NAME("Nuvoton NAU8825 Codec") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 104 | .enable_dev = nau8825_enable |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 105 | }; |