Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 4 | * 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 Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 18 | #include <device/i2c_simple.h> |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/path.h> |
| 21 | #include <stdint.h> |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 22 | #include "chip.h" |
| 23 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 24 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 25 | |
| 26 | #define NAU8825_ACPI_NAME "NAU8" |
| 27 | #define NAU8825_ACPI_HID "10508825" |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 28 | |
| 29 | #define NAU8825_DP_INT(key,val) \ |
| 30 | acpi_dp_add_integer(dp, "nuvoton," key, (val)) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 31 | |
| 32 | static 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 42 | struct acpi_dp *dp = NULL; |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 43 | |
| 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 Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 55 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 56 | |
| 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 65 | dp = acpi_dp_new_table("_DSD"); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 66 | 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 Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 80 | acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold", |
| 81 | config->sar_threshold, config->sar_threshold_num); |
| 82 | acpi_dp_write(dp); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 83 | |
| 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 Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 92 | static const char *nau8825_acpi_name(const struct device *dev) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 93 | { |
| 94 | return NAU8825_ACPI_NAME; |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | static struct device_operations nau8825_ops = { |
| 99 | .read_resources = DEVICE_NOOP, |
| 100 | .set_resources = DEVICE_NOOP, |
| 101 | .enable_resources = DEVICE_NOOP, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 102 | #if CONFIG(HAVE_ACPI_TABLES) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 103 | .acpi_name = nau8825_acpi_name, |
| 104 | .acpi_fill_ssdt_generator = nau8825_fill_ssdt, |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 105 | #endif |
| 106 | }; |
| 107 | |
| 108 | static void nau8825_enable(struct device *dev) |
| 109 | { |
| 110 | dev->ops = &nau8825_ops; |
| 111 | } |
| 112 | |
| 113 | struct chip_operations drivers_i2c_nau8825_ops = { |
| 114 | CHIP_NAME("Nuvoton NAU8825 Codec") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 115 | .enable_dev = nau8825_enable |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 116 | }; |