blob: 4a057b51d56fcd9b97cb973786587f77de1f2783 [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 Laurieffc99902016-07-02 19:56:06 -070035 struct acpi_dp *dp;
Duncan Laurie7db15092016-05-11 11:27:47 -070036
Duncan Laurie366cd212016-06-29 22:34:01 -070037 if (!dev->enabled || !config)
Duncan Laurie7db15092016-05-11 11:27:47 -070038 return;
39
40 /* Device */
41 acpigen_write_scope(acpi_device_scope(dev));
42 acpigen_write_device(acpi_device_name(dev));
43 acpigen_write_name_string("_HID", MAX98357A_ACPI_HID);
44 acpigen_write_name_integer("_UID", 0);
45 acpigen_write_name_string("_DDN", dev->chip_ops->name);
46 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
47
48 /* Resources */
49 acpigen_write_name("_CRS");
50 acpigen_write_resourcetemplate_header();
51 acpi_device_write_gpio(&config->sdmode_gpio);
52 acpigen_write_resourcetemplate_footer();
53
54 /* _DSD for devicetree properties */
Duncan Laurie7db15092016-05-11 11:27:47 -070055 /* 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);
Duncan Laurieffc99902016-07-02 19:56:06 -070057 dp = acpi_dp_new_table("_DSD");
Furquan Shaikh028200f2016-10-04 10:53:32 -070058 acpi_dp_add_gpio(dp, "sdmode-gpio", path, 0, 0,
59 config->sdmode_gpio.polarity);
Duncan Laurieffc99902016-07-02 19:56:06 -070060 acpi_dp_add_integer(dp, "sdmode-delay", config->sdmode_delay);
61 acpi_dp_write(dp);
Duncan Laurie7db15092016-05-11 11:27:47 -070062
63 acpigen_pop_len(); /* Device */
64 acpigen_pop_len(); /* Scope */
65
66 printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name);
67}
68
69static const char *max98357a_acpi_name(struct device *dev)
70{
71 return MAX98357A_ACPI_NAME;
72}
73#endif
74
75static struct device_operations max98357a_ops = {
76 .read_resources = DEVICE_NOOP,
77 .set_resources = DEVICE_NOOP,
78 .enable_resources = DEVICE_NOOP,
79#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
80 .acpi_name = &max98357a_acpi_name,
81 .acpi_fill_ssdt_generator = &max98357a_fill_ssdt,
82#endif
83};
84
85static void max98357a_enable(struct device *dev)
86{
87 struct drivers_generic_max98357a_config *config = dev->chip_info;
88
89 /* Check if device is present by reading GPIO */
90 if (config->device_present_gpio) {
91 int present = gpio_get(config->device_present_gpio);
92 present ^= config->device_present_gpio_invert;
93
94 printk(BIOS_INFO, "%s is %spresent\n",
95 dev->chip_ops->name, present ? "" : "not ");
96
97 if (!present) {
98 dev->enabled = 0;
99 return;
100 }
101 }
102
103 dev->ops = &max98357a_ops;
104}
105
106struct chip_operations drivers_generic_max98357a_ops = {
107 CHIP_NAME("Maxim Integrated 98357A Amplifier")
108 .enable_dev = &max98357a_enable
109};