blob: 6e0d5f7fb842925381f4caea8a736ac3f98511cb [file] [log] [blame]
Daniel Kurtz53b62132018-02-08 11:56:14 -07001/*
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
Julius Wernercd49cce2019-03-05 16:53:33 -080025#if CONFIG(HAVE_ACPI_TABLES)
Daniel Kurtz53b62132018-02-08 11:56:14 -070026
27#define ADAU7002_ACPI_NAME "ADAU"
28#define ADAU7002_ACPI_HID "ADAU7002"
29
30static void adau7002_fill_ssdt(struct device *dev)
31{
Akshu Agrawal7ac31492019-01-08 14:06:42 +053032 struct drivers_generic_adau7002_config *config;
33 struct acpi_dp *dp;
34
Richard Spiegele0d30642018-02-14 09:38:11 -070035 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 Kurtz53b62132018-02-08 11:56:14 -070041 return;
42
43 /* Device */
Richard Spiegele0d30642018-02-14 09:38:11 -070044 acpigen_write_scope(scope);
45 acpigen_write_device(name);
Daniel Kurtz53b62132018-02-08 11:56:14 -070046 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 Linb4be50c2018-09-10 10:55:49 +080049 acpigen_write_STA(acpi_device_status(dev));
Daniel Kurtz53b62132018-02-08 11:56:14 -070050
Akshu Agrawal7ac31492019-01-08 14:06:42 +053051 /* _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 Kurtz53b62132018-02-08 11:56:14 -070057 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
64static const char *adau7002_acpi_name(const struct device *dev)
65{
66 return ADAU7002_ACPI_NAME;
67}
68#endif
69
70static struct device_operations adau7002_ops = {
71 .read_resources = DEVICE_NOOP,
72 .set_resources = DEVICE_NOOP,
73 .enable_resources = DEVICE_NOOP,
Julius Wernercd49cce2019-03-05 16:53:33 -080074#if CONFIG(HAVE_ACPI_TABLES)
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010075 .acpi_name = adau7002_acpi_name,
76 .acpi_fill_ssdt_generator = adau7002_fill_ssdt,
Daniel Kurtz53b62132018-02-08 11:56:14 -070077#endif
78};
79
80static void adau7002_enable(struct device *dev)
81{
82 dev->ops = &adau7002_ops;
83}
84
85struct chip_operations drivers_generic_adau7002_ops = {
86 CHIP_NAME("Analog Digital DMIC")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010087 .enable_dev = adau7002_enable
Daniel Kurtz53b62132018-02-08 11:56:14 -070088};