| 1 |
|
| 2 |
|
| 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" |
| 9 |
|
| 10 |
#define MAX98357A_ACPI_NAME "MAXM" |
| 11 |
|
| 12 |
static void max98357a_fill_ssdt(const struct device *dev) |
| 13 |
{ |
| 14 |
struct drivers_generic_max98357a_config *config = dev->chip_info; |
| 15 |
const char *path; |
| 16 |
struct acpi_dp *dp; |
| 17 |
|
| 18 |
if (!config) |
| 19 |
return; |
| 20 |
|
| 21 |
const char *scope = acpi_device_scope(dev); |
| 22 |
const char *name = acpi_device_name(dev); |
| 23 |
if (!scope || !name) |
| 24 |
return; |
| 25 |
|
| 26 |
if (!config->hid) { |
| 27 |
printk(BIOS_ERR, "%s: ERROR: _HID required\n", dev_path(dev)); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
acpigen_write_scope(scope); |
| 33 |
acpigen_write_device(name); |
| 34 |
|
| 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)); |
| 39 |
|
| 40 |
|
| 41 |
acpigen_write_name("_CRS"); |
| 42 |
acpigen_write_resourcetemplate_header(); |
| 43 |
acpi_device_write_gpio(&config->sdmode_gpio); |
| 44 |
acpigen_write_resourcetemplate_footer(); |
| 45 |
|
| 46 |
|
| 47 |
|
| 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); |
| 54 |
|
| 55 |
acpigen_pop_len(); |
| 56 |
acpigen_pop_len(); |
| 57 |
|
| 58 |
printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name); |
| 59 |
} |
| 60 |
|
| 61 |
static const char *max98357a_acpi_name(const struct device *dev) |
| 62 |
{ |
| 63 |
return MAX98357A_ACPI_NAME; |
| 64 |
} |
| 65 |
|
| 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, |
| 71 |
}; |
| 72 |
|
| 73 |
static void max98357a_enable(struct device *dev) |
| 74 |
{ |
| 75 |
struct drivers_generic_max98357a_config *config = dev->chip_info; |
| 76 |
|
| 77 |
|
| 78 |
if (config->device_present_gpio) { |
| 79 |
int present = gpio_get(config->device_present_gpio); |
| 80 |
present ^= config->device_present_gpio_invert; |
| 81 |
|
| 82 |
printk(BIOS_INFO, "%s is %spresent\n", |
| 83 |
dev->chip_ops->name, present ? "" : "not "); |
| 84 |
|
| 85 |
if (!present) { |
| 86 |
dev->enabled = 0; |
| 87 |
return; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
dev->ops = &max98357a_ops; |
| 92 |
} |
| 93 |
|
| 94 |
struct chip_operations drivers_generic_max98357a_ops = { |
| 95 |
.name = "Maxim Integrated 98357A Amplifier", |
| 96 |
.enable_dev = max98357a_enable |
| 97 |
}; |