Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi_device.h> |
| 5 | #include <arch/acpigen.h> |
| 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
| 9 | #include <gpio.h> |
| 10 | #include <stdint.h> |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 11 | #include "chip.h" |
| 12 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 13 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 14 | |
| 15 | #define MAX98357A_ACPI_NAME "MAXM" |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 16 | |
| 17 | static void max98357a_fill_ssdt(struct device *dev) |
| 18 | { |
| 19 | struct drivers_generic_max98357a_config *config = dev->chip_info; |
Duncan Laurie | 366cd21 | 2016-06-29 22:34:01 -0700 | [diff] [blame] | 20 | const char *path; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 21 | struct acpi_dp *dp; |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 22 | |
Duncan Laurie | 366cd21 | 2016-06-29 22:34:01 -0700 | [diff] [blame] | 23 | if (!dev->enabled || !config) |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 24 | return; |
| 25 | |
Jacob Garber | bdcb4d3 | 2019-05-27 17:10:24 -0600 | [diff] [blame] | 26 | const char *scope = acpi_device_scope(dev); |
| 27 | const char *name = acpi_device_name(dev); |
| 28 | if (!scope || !name) |
| 29 | return; |
| 30 | |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 31 | /* Device */ |
Jacob Garber | bdcb4d3 | 2019-05-27 17:10:24 -0600 | [diff] [blame] | 32 | acpigen_write_scope(scope); |
| 33 | acpigen_write_device(name); |
Aamir Bohra | a1c82c5 | 2020-03-16 18:57:48 +0530 | [diff] [blame] | 34 | |
| 35 | if (!config->hid) { |
| 36 | printk(BIOS_ERR, "%s: ERROR: _HID required\n", dev_path(dev)); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | acpigen_write_name_string("_HID", config->hid); |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 41 | acpigen_write_name_integer("_UID", 0); |
| 42 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 43 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 44 | |
| 45 | /* Resources */ |
| 46 | acpigen_write_name("_CRS"); |
| 47 | acpigen_write_resourcetemplate_header(); |
| 48 | acpi_device_write_gpio(&config->sdmode_gpio); |
| 49 | acpigen_write_resourcetemplate_footer(); |
| 50 | |
| 51 | /* _DSD for devicetree properties */ |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 52 | /* This points to the first pin in the first gpio entry in _CRS */ |
Duncan Laurie | 366cd21 | 2016-06-29 22:34:01 -0700 | [diff] [blame] | 53 | path = acpi_device_path(dev); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 54 | dp = acpi_dp_new_table("_DSD"); |
Furquan Shaikh | 028200f | 2016-10-04 10:53:32 -0700 | [diff] [blame] | 55 | acpi_dp_add_gpio(dp, "sdmode-gpio", path, 0, 0, |
| 56 | config->sdmode_gpio.polarity); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 57 | acpi_dp_add_integer(dp, "sdmode-delay", config->sdmode_delay); |
| 58 | acpi_dp_write(dp); |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 59 | |
| 60 | acpigen_pop_len(); /* Device */ |
| 61 | acpigen_pop_len(); /* Scope */ |
| 62 | |
| 63 | printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name); |
| 64 | } |
| 65 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 66 | static const char *max98357a_acpi_name(const struct device *dev) |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 67 | { |
| 68 | return MAX98357A_ACPI_NAME; |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | static struct device_operations max98357a_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame^] | 73 | .read_resources = noop_read_resources, |
| 74 | .set_resources = noop_set_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 75 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 76 | .acpi_name = max98357a_acpi_name, |
| 77 | .acpi_fill_ssdt = max98357a_fill_ssdt, |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | static void max98357a_enable(struct device *dev) |
| 82 | { |
| 83 | struct drivers_generic_max98357a_config *config = dev->chip_info; |
| 84 | |
| 85 | /* Check if device is present by reading GPIO */ |
| 86 | if (config->device_present_gpio) { |
| 87 | int present = gpio_get(config->device_present_gpio); |
| 88 | present ^= config->device_present_gpio_invert; |
| 89 | |
| 90 | printk(BIOS_INFO, "%s is %spresent\n", |
| 91 | dev->chip_ops->name, present ? "" : "not "); |
| 92 | |
| 93 | if (!present) { |
| 94 | dev->enabled = 0; |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | dev->ops = &max98357a_ops; |
| 100 | } |
| 101 | |
| 102 | struct chip_operations drivers_generic_max98357a_ops = { |
| 103 | CHIP_NAME("Maxim Integrated 98357A Amplifier") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 104 | .enable_dev = max98357a_enable |
Duncan Laurie | 7db1509 | 2016-05-11 11:27:47 -0700 | [diff] [blame] | 105 | }; |