| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi_device.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <device/i2c_simple.h> |
| 7 |
#include <device/device.h> |
| 8 |
#include <stdint.h> |
| 9 |
#include "chip.h" |
| 10 |
|
| 11 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 12 |
|
| 13 |
#define NAU8825_ACPI_NAME "NAU8" |
| 14 |
#define NAU8825_ACPI_HID "10508825" |
| 15 |
|
| 16 |
#define NAU8825_DP_INT(key,val) \ |
| 17 |
acpi_dp_add_integer(dp, "nuvoton," key, (val)) |
| 18 |
|
| 19 |
static void nau8825_fill_ssdt(const struct device *dev) |
| 20 |
{ |
| 21 |
struct drivers_i2c_nau8825_config *config = dev->chip_info; |
| 22 |
const char *scope = acpi_device_scope(dev); |
| 23 |
struct acpi_i2c i2c = { |
| 24 |
.address = dev->path.i2c.device, |
| 25 |
.mode_10bit = dev->path.i2c.mode_10bit, |
| 26 |
.speed = config->bus_speed ? : I2C_SPEED_FAST, |
| 27 |
.resource = scope, |
| 28 |
}; |
| 29 |
struct acpi_dp *dp = NULL; |
| 30 |
|
| 31 |
if (!scope) |
| 32 |
return; |
| 33 |
if (config->sar_threshold_num > NAU8825_MAX_BUTTONS) |
| 34 |
return; |
| 35 |
|
| 36 |
|
| 37 |
acpigen_write_scope(scope); |
| 38 |
acpigen_write_device(acpi_device_name(dev)); |
| 39 |
acpigen_write_name_string("_HID", NAU8825_ACPI_HID); |
| 40 |
acpigen_write_name_integer("_UID", 0); |
| 41 |
acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 42 |
acpigen_write_STA(acpi_device_status(dev)); |
| 43 |
|
| 44 |
|
| 45 |
acpigen_write_name("_CRS"); |
| 46 |
acpigen_write_resourcetemplate_header(); |
| 47 |
acpi_device_write_i2c(&i2c); |
| 48 |
|
| 49 |
if (config->irq_gpio.pin_count) |
| 50 |
acpi_device_write_gpio(&config->irq_gpio); |
| 51 |
else |
| 52 |
acpi_device_write_interrupt(&config->irq); |
| 53 |
acpigen_write_resourcetemplate_footer(); |
| 54 |
|
| 55 |
|
| 56 |
dp = acpi_dp_new_table("_DSD"); |
| 57 |
NAU8825_DP_INT("jkdet-enable", config->jkdet_enable); |
| 58 |
NAU8825_DP_INT("jkdet-pull-enable", config->jkdet_pull_enable); |
| 59 |
NAU8825_DP_INT("jkdet-pull-up", config->jkdet_pull_up); |
| 60 |
NAU8825_DP_INT("jkdet-polarity", config->jkdet_polarity); |
| 61 |
NAU8825_DP_INT("vref-impedance", config->vref_impedance); |
| 62 |
NAU8825_DP_INT("micbias-voltage", config->micbias_voltage); |
| 63 |
NAU8825_DP_INT("sar-hysteresis", config->sar_hysteresis); |
| 64 |
NAU8825_DP_INT("sar-voltage", config->sar_voltage); |
| 65 |
NAU8825_DP_INT("sar-compare-time", config->sar_compare_time); |
| 66 |
NAU8825_DP_INT("sar-sampling-time", config->sar_sampling_time); |
| 67 |
NAU8825_DP_INT("short-key-debounce", config->short_key_debounce); |
| 68 |
NAU8825_DP_INT("jack-insert-debounce", config->jack_insert_debounce); |
| 69 |
NAU8825_DP_INT("jack-eject-debounce", config->jack_eject_debounce); |
| 70 |
NAU8825_DP_INT("sar-threshold-num", config->sar_threshold_num); |
| 71 |
NAU8825_DP_INT("adcout-drive-strong", config->adcout_ds ? 1 : 0); |
| 72 |
acpi_dp_add_integer_array(dp, "nuvoton,sar-threshold", |
| 73 |
config->sar_threshold, config->sar_threshold_num); |
| 74 |
acpi_dp_write(dp); |
| 75 |
|
| 76 |
acpigen_pop_len(); |
| 77 |
acpigen_pop_len(); |
| 78 |
|
| 79 |
printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n", |
| 80 |
acpi_device_path(dev), dev->chip_ops->name, |
| 81 |
dev->path.i2c.device, config->irq.pin); |
| 82 |
} |
| 83 |
|
| 84 |
static const char *nau8825_acpi_name(const struct device *dev) |
| 85 |
{ |
| 86 |
return NAU8825_ACPI_NAME; |
| 87 |
} |
| 88 |
#endif |
| 89 |
|
| 90 |
static struct device_operations nau8825_ops = { |
| 91 |
.read_resources = noop_read_resources, |
| 92 |
.set_resources = noop_set_resources, |
| 93 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 94 |
.acpi_name = nau8825_acpi_name, |
| 95 |
.acpi_fill_ssdt = nau8825_fill_ssdt, |
| 96 |
#endif |
| 97 |
}; |
| 98 |
|
| 99 |
static void nau8825_enable(struct device *dev) |
| 100 |
{ |
| 101 |
dev->ops = &nau8825_ops; |
| 102 |
} |
| 103 |
|
| 104 |
struct chip_operations drivers_i2c_nau8825_ops = { |
| 105 |
.name = "Nuvoton NAU8825 Codec", |
| 106 |
.enable_dev = nau8825_enable |
| 107 |
}; |