mb/amb/birman*/gpio: remove configuration for VDD_MEM_VID[0,1]
[coreboot2.git] / src / drivers / generic / max98357a / max98357a.c
blob9b190ce20cd9c8869f3a570024b3032e33bf4816
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <gpio.h>
8 #include "chip.h"
10 #define MAX98357A_ACPI_NAME "MAXM"
12 static void max98357a_fill_ssdt(const struct device *dev)
14 struct drivers_generic_max98357a_config *config = dev->chip_info;
15 const char *path;
16 struct acpi_dp *dp;
18 if (!config)
19 return;
21 const char *scope = acpi_device_scope(dev);
22 const char *name = acpi_device_name(dev);
23 if (!scope || !name)
24 return;
26 if (!config->hid) {
27 printk(BIOS_ERR, "%s: ERROR: _HID required\n", dev_path(dev));
28 return;
31 /* Device */
32 acpigen_write_scope(scope);
33 acpigen_write_device(name);
35 acpigen_write_name_string("_HID", config->hid);
36 acpigen_write_name_integer("_UID", 0);
37 acpigen_write_name_string("_DDN", dev->chip_ops->name);
38 acpigen_write_STA(acpi_device_status(dev));
40 /* Resources */
41 acpigen_write_name("_CRS");
42 acpigen_write_resourcetemplate_header();
43 acpi_device_write_gpio(&config->sdmode_gpio);
44 acpigen_write_resourcetemplate_footer();
46 /* _DSD for devicetree properties */
47 /* This points to the first pin in the first gpio entry in _CRS */
48 path = acpi_device_path(dev);
49 dp = acpi_dp_new_table("_DSD");
50 acpi_dp_add_gpio(dp, "sdmode-gpio", path, 0, 0,
51 config->sdmode_gpio.active_low);
52 acpi_dp_add_integer(dp, "sdmode-delay", config->sdmode_delay);
53 acpi_dp_write(dp);
55 acpigen_pop_len(); /* Device */
56 acpigen_pop_len(); /* Scope */
58 printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name);
61 static const char *max98357a_acpi_name(const struct device *dev)
63 return MAX98357A_ACPI_NAME;
66 static struct device_operations max98357a_ops = {
67 .read_resources = noop_read_resources,
68 .set_resources = noop_set_resources,
69 .acpi_name = max98357a_acpi_name,
70 .acpi_fill_ssdt = max98357a_fill_ssdt,
73 static void max98357a_enable(struct device *dev)
75 struct drivers_generic_max98357a_config *config = dev->chip_info;
77 /* Check if device is present by reading GPIO */
78 if (config->device_present_gpio) {
79 int present = gpio_get(config->device_present_gpio);
80 present ^= config->device_present_gpio_invert;
82 printk(BIOS_INFO, "%s is %spresent\n",
83 dev->chip_ops->name, present ? "" : "not ");
85 if (!present) {
86 dev->enabled = 0;
87 return;
91 dev->ops = &max98357a_ops;
94 struct chip_operations drivers_generic_max98357a_ops = {
95 .name = "Maxim Integrated 98357A Amplifier",
96 .enable_dev = max98357a_enable