1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include "chip.h"
8
9 #if CONFIG(HAVE_ACPI_TABLES)
10
11 #define ADAU7002_ACPI_NAME "ADAU"
12 #define ADAU7002_ACPI_HID "ADAU7002"
13
adau7002_fill_ssdt(const struct device * dev)14 static void adau7002_fill_ssdt(const struct device *dev)
15 {
16 struct drivers_generic_adau7002_config *config;
17 struct acpi_dp *dp;
18
19 if (!dev)
20 return;
21
22 const char *scope = acpi_device_scope(dev);
23 const char *name = acpi_device_name(dev);
24 if (!scope || !name)
25 return;
26
27 /* Device */
28 acpigen_write_scope(scope);
29 acpigen_write_device(name);
30 acpigen_write_name_string("_HID", ADAU7002_ACPI_HID);
31 acpigen_write_name_integer("_UID", 0);
32 acpigen_write_name_string("_DDN", dev->chip_ops->name);
33 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
34
35 /* _DSD for devicetree properties */
36 config = dev->chip_info;
37 dp = acpi_dp_new_table("_DSD");
38 acpi_dp_add_integer(dp, "wakeup-delay-ms", config->wakeup_delay);
39 acpi_dp_write(dp);
40
41 acpigen_pop_len(); /* Device */
42 acpigen_pop_len(); /* Scope */
43
44 printk(BIOS_INFO, "%s: %s\n", acpi_device_path(dev),
45 dev->chip_ops->name);
46 }
47
adau7002_acpi_name(const struct device * dev)48 static const char *adau7002_acpi_name(const struct device *dev)
49 {
50 return ADAU7002_ACPI_NAME;
51 }
52 #endif
53
54 static struct device_operations adau7002_ops = {
55 .read_resources = noop_read_resources,
56 .set_resources = noop_set_resources,
57 #if CONFIG(HAVE_ACPI_TABLES)
58 .acpi_name = adau7002_acpi_name,
59 .acpi_fill_ssdt = adau7002_fill_ssdt,
60 #endif
61 };
62
adau7002_enable(struct device * dev)63 static void adau7002_enable(struct device *dev)
64 {
65 dev->ops = &adau7002_ops;
66 }
67
68 struct chip_operations drivers_generic_adau7002_ops = {
69 .name = "Analog Digital DMIC",
70 .enable_dev = adau7002_enable
71 };
72