blob: 86d4306ab73f905b2435f77f93d1fa3737d33333 [file] [log] [blame]
Duncan Laurie7522dc32016-05-10 20:20:16 -07001/*
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 Huber0f2dd1e2017-08-01 14:02:40 +020020#include <device/i2c_simple.h>
Duncan Laurie7522dc32016-05-10 20:20:16 -070021#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 Laurieffc99902016-07-02 19:56:06 -070031
32#define NAU8825_DP_INT(key,val) \
33 acpi_dp_add_integer(dp, "nuvoton," key, (val))
Duncan Laurie7522dc32016-05-10 20:20:16 -070034
35static 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 Laurieffc99902016-07-02 19:56:06 -070045 struct acpi_dp *dp = NULL;
Duncan Laurie7522dc32016-05-10 20:20:16 -070046
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 Linb4be50c2018-09-10 10:55:49 +080058 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie7522dc32016-05-10 20:20:16 -070059
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 Laurieffc99902016-07-02 19:56:06 -070068 dp = acpi_dp_new_table("_DSD");
Duncan Laurie7522dc32016-05-10 20:20:16 -070069 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 Laurieffc99902016-07-02 19:56:06 -070083 acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold",
84 config->sar_threshold, config->sar_threshold_num);
85 acpi_dp_write(dp);
Duncan Laurie7522dc32016-05-10 20:20:16 -070086
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 Durbinaa090cb2017-09-13 16:01:52 -060095static const char *nau8825_acpi_name(const struct device *dev)
Duncan Laurie7522dc32016-05-10 20:20:16 -070096{
97 return NAU8825_ACPI_NAME;
98}
99#endif
100
101static 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)
106 .acpi_name = &nau8825_acpi_name,
107 .acpi_fill_ssdt_generator = &nau8825_fill_ssdt,
108#endif
109};
110
111static void nau8825_enable(struct device *dev)
112{
113 dev->ops = &nau8825_ops;
114}
115
116struct chip_operations drivers_i2c_nau8825_ops = {
117 CHIP_NAME("Nuvoton NAU8825 Codec")
118 .enable_dev = &nau8825_enable
119};