blob: 0d522d45c0ae96d86ad088aa36ea435e880d394e [file] [log] [blame]
Duncan Laurie7db15092016-05-11 11:27:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
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 <gpio.h>
22#include <stdint.h>
23#include <string.h>
24#include "chip.h"
25
26#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
27
28#define MAX98357A_ACPI_NAME "MAXM"
29#define MAX98357A_ACPI_HID "MX98357A"
30
31static void max98357a_fill_ssdt(struct device *dev)
32{
33 struct drivers_generic_max98357a_config *config = dev->chip_info;
Duncan Laurie366cd212016-06-29 22:34:01 -070034 const char *path;
Duncan Laurie7db15092016-05-11 11:27:47 -070035
Duncan Laurie366cd212016-06-29 22:34:01 -070036 if (!dev->enabled || !config)
Duncan Laurie7db15092016-05-11 11:27:47 -070037 return;
38
39 /* Device */
40 acpigen_write_scope(acpi_device_scope(dev));
41 acpigen_write_device(acpi_device_name(dev));
42 acpigen_write_name_string("_HID", MAX98357A_ACPI_HID);
43 acpigen_write_name_integer("_UID", 0);
44 acpigen_write_name_string("_DDN", dev->chip_ops->name);
45 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
46
47 /* Resources */
48 acpigen_write_name("_CRS");
49 acpigen_write_resourcetemplate_header();
50 acpi_device_write_gpio(&config->sdmode_gpio);
51 acpigen_write_resourcetemplate_footer();
52
53 /* _DSD for devicetree properties */
54 acpi_dp_write_header();
55 /* This points to the first pin in the first gpio entry in _CRS */
Duncan Laurie366cd212016-06-29 22:34:01 -070056 path = acpi_device_path(dev);
57 acpi_dp_write_gpio("sdmode-gpio", path, 0, 0, 0);
Duncan Laurie7db15092016-05-11 11:27:47 -070058 acpi_dp_write_integer("sdmode-delay", config->sdmode_delay);
59 acpi_dp_write_footer();
60
61 acpigen_pop_len(); /* Device */
62 acpigen_pop_len(); /* Scope */
63
64 printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name);
65}
66
67static const char *max98357a_acpi_name(struct device *dev)
68{
69 return MAX98357A_ACPI_NAME;
70}
71#endif
72
73static struct device_operations max98357a_ops = {
74 .read_resources = DEVICE_NOOP,
75 .set_resources = DEVICE_NOOP,
76 .enable_resources = DEVICE_NOOP,
77#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
78 .acpi_name = &max98357a_acpi_name,
79 .acpi_fill_ssdt_generator = &max98357a_fill_ssdt,
80#endif
81};
82
83static void max98357a_enable(struct device *dev)
84{
85 struct drivers_generic_max98357a_config *config = dev->chip_info;
86
87 /* Check if device is present by reading GPIO */
88 if (config->device_present_gpio) {
89 int present = gpio_get(config->device_present_gpio);
90 present ^= config->device_present_gpio_invert;
91
92 printk(BIOS_INFO, "%s is %spresent\n",
93 dev->chip_ops->name, present ? "" : "not ");
94
95 if (!present) {
96 dev->enabled = 0;
97 return;
98 }
99 }
100
101 dev->ops = &max98357a_ops;
102}
103
104struct chip_operations drivers_generic_max98357a_ops = {
105 CHIP_NAME("Maxim Integrated 98357A Amplifier")
106 .enable_dev = &max98357a_enable
107};