Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2018 Google LLC |
| 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_device.h> |
| 17 | #include <arch/acpigen.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/path.h> |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include "chip.h" |
| 24 | |
| 25 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 26 | |
| 27 | #define ADAU7002_ACPI_NAME "ADAU" |
| 28 | #define ADAU7002_ACPI_HID "ADAU7002" |
| 29 | |
| 30 | static void adau7002_fill_ssdt(struct device *dev) |
| 31 | { |
Akshu Agrawal | 7ac3149 | 2019-01-08 14:06:42 +0530 | [diff] [blame] | 32 | struct drivers_generic_adau7002_config *config; |
| 33 | struct acpi_dp *dp; |
| 34 | |
Richard Spiegel | e0d3064 | 2018-02-14 09:38:11 -0700 | [diff] [blame] | 35 | if (!dev || !dev->enabled) |
| 36 | return; |
| 37 | |
| 38 | const char *scope = acpi_device_scope(dev); |
| 39 | const char *name = acpi_device_name(dev); |
| 40 | if (!scope || !name) |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 41 | return; |
| 42 | |
| 43 | /* Device */ |
Richard Spiegel | e0d3064 | 2018-02-14 09:38:11 -0700 | [diff] [blame] | 44 | acpigen_write_scope(scope); |
| 45 | acpigen_write_device(name); |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 46 | acpigen_write_name_string("_HID", ADAU7002_ACPI_HID); |
| 47 | acpigen_write_name_integer("_UID", 0); |
| 48 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 49 | acpigen_write_STA(acpi_device_status(dev)); |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 50 | |
Akshu Agrawal | 7ac3149 | 2019-01-08 14:06:42 +0530 | [diff] [blame] | 51 | /* _DSD for devicetree properties */ |
| 52 | config = dev->chip_info; |
| 53 | dp = acpi_dp_new_table("_DSD"); |
| 54 | acpi_dp_add_integer(dp, "wakeup-delay-ms", config->wakeup_delay); |
| 55 | acpi_dp_write(dp); |
| 56 | |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 57 | acpigen_pop_len(); /* Device */ |
| 58 | acpigen_pop_len(); /* Scope */ |
| 59 | |
| 60 | printk(BIOS_INFO, "%s: %s\n", acpi_device_path(dev), |
| 61 | dev->chip_ops->name); |
| 62 | } |
| 63 | |
| 64 | static const char *adau7002_acpi_name(const struct device *dev) |
| 65 | { |
| 66 | return ADAU7002_ACPI_NAME; |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | static struct device_operations adau7002_ops = { |
| 71 | .read_resources = DEVICE_NOOP, |
| 72 | .set_resources = DEVICE_NOOP, |
| 73 | .enable_resources = DEVICE_NOOP, |
| 74 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame^] | 75 | .acpi_name = adau7002_acpi_name, |
| 76 | .acpi_fill_ssdt_generator = adau7002_fill_ssdt, |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 77 | #endif |
| 78 | }; |
| 79 | |
| 80 | static void adau7002_enable(struct device *dev) |
| 81 | { |
| 82 | dev->ops = &adau7002_ops; |
| 83 | } |
| 84 | |
| 85 | struct chip_operations drivers_generic_adau7002_ops = { |
| 86 | CHIP_NAME("Analog Digital DMIC") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame^] | 87 | .enable_dev = adau7002_enable |
Daniel Kurtz | 53b6213 | 2018-02-08 11:56:14 -0700 | [diff] [blame] | 88 | }; |