Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2016 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <arch/acpi_device.h> |
| 18 | #include <arch/acpigen.h> |
| 19 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 20 | #include <device/i2c_simple.h> |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/path.h> |
| 23 | #include <stdint.h> |
| 24 | #include <string.h> |
| 25 | #include "chip.h" |
| 26 | |
| 27 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 28 | |
| 29 | #define NAU8825_ACPI_NAME "NAU8" |
| 30 | #define NAU8825_ACPI_HID "10508825" |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 31 | |
| 32 | #define NAU8825_DP_INT(key,val) \ |
| 33 | acpi_dp_add_integer(dp, "nuvoton," key, (val)) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 34 | |
| 35 | static void nau8825_fill_ssdt(struct device *dev) |
| 36 | { |
| 37 | struct drivers_i2c_nau8825_config *config = dev->chip_info; |
| 38 | const char *scope = acpi_device_scope(dev); |
| 39 | struct acpi_i2c i2c = { |
| 40 | .address = dev->path.i2c.device, |
| 41 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 42 | .speed = config->bus_speed ? : I2C_SPEED_FAST, |
| 43 | .resource = scope, |
| 44 | }; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 45 | struct acpi_dp *dp = NULL; |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 46 | |
| 47 | if (!dev->enabled || !scope) |
| 48 | return; |
| 49 | if (config->sar_threshold_num > NAU8825_MAX_BUTTONS) |
| 50 | return; |
| 51 | |
| 52 | /* Device */ |
| 53 | acpigen_write_scope(scope); |
| 54 | acpigen_write_device(acpi_device_name(dev)); |
| 55 | acpigen_write_name_string("_HID", NAU8825_ACPI_HID); |
| 56 | acpigen_write_name_integer("_UID", 0); |
| 57 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 58 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 59 | |
| 60 | /* Resources */ |
| 61 | acpigen_write_name("_CRS"); |
| 62 | acpigen_write_resourcetemplate_header(); |
| 63 | acpi_device_write_i2c(&i2c); |
| 64 | acpi_device_write_interrupt(&config->irq); |
| 65 | acpigen_write_resourcetemplate_footer(); |
| 66 | |
| 67 | /* Device Properties */ |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 68 | dp = acpi_dp_new_table("_DSD"); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 69 | NAU8825_DP_INT("jkdet-enable", config->jkdet_enable); |
| 70 | NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable); |
| 71 | NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up); |
| 72 | NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity); |
| 73 | NAU8825_DP_INT("vref-impedance", config->vref_impedance); |
| 74 | NAU8825_DP_INT("micbias-voltage", config->micbias_voltage); |
| 75 | NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis); |
| 76 | NAU8825_DP_INT("sar-voltage", config->sar_voltage); |
| 77 | NAU8825_DP_INT("sar-compare-time", config->sar_compare_time); |
| 78 | NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time); |
| 79 | NAU8825_DP_INT("short-key-debounce", config->short_key_debounce); |
| 80 | NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce); |
| 81 | NAU8825_DP_INT("jack-eject-deboune", config->jack_eject_debounce); |
| 82 | NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 83 | acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold", |
| 84 | config->sar_threshold, config->sar_threshold_num); |
| 85 | acpi_dp_write(dp); |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 86 | |
| 87 | acpigen_pop_len(); /* Device */ |
| 88 | acpigen_pop_len(); /* Scope */ |
| 89 | |
| 90 | printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 91 | acpi_device_path(dev), dev->chip_ops->name, |
| 92 | dev->path.i2c.device, config->irq.pin); |
| 93 | } |
| 94 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 95 | static const char *nau8825_acpi_name(const struct device *dev) |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 96 | { |
| 97 | return NAU8825_ACPI_NAME; |
| 98 | } |
| 99 | #endif |
| 100 | |
| 101 | static struct device_operations nau8825_ops = { |
| 102 | .read_resources = DEVICE_NOOP, |
| 103 | .set_resources = DEVICE_NOOP, |
| 104 | .enable_resources = DEVICE_NOOP, |
| 105 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame^] | 106 | .acpi_name = nau8825_acpi_name, |
| 107 | .acpi_fill_ssdt_generator = nau8825_fill_ssdt, |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 108 | #endif |
| 109 | }; |
| 110 | |
| 111 | static void nau8825_enable(struct device *dev) |
| 112 | { |
| 113 | dev->ops = &nau8825_ops; |
| 114 | } |
| 115 | |
| 116 | struct chip_operations drivers_i2c_nau8825_ops = { |
| 117 | CHIP_NAME("Nuvoton NAU8825 Codec") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame^] | 118 | .enable_dev = nau8825_enable |
Duncan Laurie | 7522dc3 | 2016-05-10 20:20:16 -0700 | [diff] [blame] | 119 | }; |