Seven Lee | f147051 | 2021-03-31 15:57:38 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
Seven Lee | f147051 | 2021-03-31 15:57:38 +0800 | [diff] [blame] | 7 | #include <gpio.h> |
| 8 | #include "chip.h" |
| 9 | |
David Lin | 69a6dd6 | 2022-11-24 15:00:37 +0800 | [diff] [blame] | 10 | const char *nauhid[MAX_HID] = {"NVTN2010", "NVTN2012"}; |
| 11 | |
Seven Lee | f147051 | 2021-03-31 15:57:38 +0800 | [diff] [blame] | 12 | static void nau8315_fill_ssdt(const struct device *dev) |
| 13 | { |
| 14 | struct drivers_generic_nau8315_config *config = dev->chip_info; |
| 15 | const char *path; |
| 16 | struct acpi_dp *dp; |
| 17 | |
| 18 | if (!dev->enabled || !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 | /* Device */ |
| 27 | acpigen_write_scope(scope); |
| 28 | acpigen_write_device(name); |
| 29 | |
David Lin | 69a6dd6 | 2022-11-24 15:00:37 +0800 | [diff] [blame] | 30 | acpigen_write_name_string("_HID", nauhid[config->hid]); |
Seven Lee | f147051 | 2021-03-31 15:57:38 +0800 | [diff] [blame] | 31 | acpigen_write_name_integer("_UID", 0); |
| 32 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 33 | acpigen_write_STA(acpi_device_status(dev)); |
| 34 | |
| 35 | /* Resources */ |
| 36 | acpigen_write_name("_CRS"); |
| 37 | acpigen_write_resourcetemplate_header(); |
| 38 | acpi_device_write_gpio(&config->enable_gpio); |
| 39 | acpigen_write_resourcetemplate_footer(); |
| 40 | |
| 41 | /* _DSD for devicetree properties */ |
| 42 | /* This points to the first pin in the first gpio entry in _CRS */ |
| 43 | path = acpi_device_path(dev); |
| 44 | dp = acpi_dp_new_table("_DSD"); |
| 45 | acpi_dp_add_gpio(dp, "enable-gpios", path, 0, 0, |
| 46 | config->enable_gpio.active_low); |
| 47 | acpi_dp_write(dp); |
| 48 | |
| 49 | acpigen_pop_len(); /* Device */ |
| 50 | acpigen_pop_len(); /* Scope */ |
| 51 | |
| 52 | printk(BIOS_INFO, "%s: %s\n", path, dev->chip_ops->name); |
| 53 | } |
| 54 | |
| 55 | static const char *nau8315_acpi_name(const struct device *dev) |
| 56 | { |
| 57 | return "NVTN"; |
| 58 | } |
| 59 | |
| 60 | static struct device_operations nau8315_ops = { |
| 61 | .read_resources = noop_read_resources, |
| 62 | .set_resources = noop_set_resources, |
| 63 | .acpi_name = nau8315_acpi_name, |
| 64 | .acpi_fill_ssdt = nau8315_fill_ssdt, |
| 65 | }; |
| 66 | |
| 67 | static void nau8315_enable(struct device *dev) |
| 68 | { |
| 69 | dev->ops = &nau8315_ops; |
| 70 | } |
| 71 | |
| 72 | struct chip_operations drivers_generic_nau8315_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 73 | .name = "Nuvoton NAU8315 Amplifier", |
Seven Lee | f147051 | 2021-03-31 15:57:38 +0800 | [diff] [blame] | 74 | .enable_dev = nau8315_enable |
| 75 | }; |