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. */ |
Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi_device.h> |
| 5 | #include <arch/acpigen.h> |
Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 6 | #include <device/device.h> |
| 7 | #include <device/path.h> |
| 8 | #include <string.h> |
| 9 | |
| 10 | #include "chip.h" |
| 11 | |
| 12 | static void gpio_regulator_fill_ssdt_generator(struct device *dev) |
| 13 | { |
| 14 | struct drivers_generic_gpio_regulator_config *config = dev->chip_info; |
| 15 | const char *scope = acpi_device_scope(dev); |
| 16 | const char *path = acpi_device_path(dev); |
| 17 | struct acpi_dp *dsd; |
| 18 | |
| 19 | if (!dev->enabled || !scope || !path || !config->gpio.pin_count) |
| 20 | return; |
| 21 | |
| 22 | /* Device */ |
| 23 | acpigen_write_scope(scope); |
| 24 | acpigen_write_device(acpi_device_name(dev)); |
| 25 | |
| 26 | /* _HID is set to PRP0001 */ |
| 27 | acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID); |
| 28 | |
| 29 | /* Resources - _CRS */ |
| 30 | acpigen_write_name("_CRS"); |
| 31 | acpigen_write_resourcetemplate_header(); |
| 32 | acpi_device_write_gpio(&config->gpio); |
| 33 | acpigen_write_resourcetemplate_footer(); |
| 34 | |
| 35 | /* DSD */ |
| 36 | dsd = acpi_dp_new_table("_DSD"); |
| 37 | acpi_dp_add_string(dsd, "compatible", "regulator-fixed"); |
| 38 | acpi_dp_add_string(dsd, "regulator-name", config->name); |
| 39 | acpi_dp_add_gpio(dsd, "gpio-gpios", path, 0, 0, config->gpio.polarity); |
| 40 | if (config->enabled_on_boot) |
| 41 | acpi_dp_add_string(dsd, "regulator-boot-on", "on"); |
| 42 | if (config->gpio.polarity == ACPI_GPIO_ACTIVE_HIGH) |
| 43 | acpi_dp_add_string(dsd, "enable-active-high", "on"); |
| 44 | acpi_dp_write(dsd); |
| 45 | |
| 46 | acpigen_pop_len(); /* Device */ |
| 47 | acpigen_pop_len(); /* Scope */ |
| 48 | } |
| 49 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 50 | static const char *gpio_regulator_acpi_name(const struct device *dev) |
Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 51 | { |
| 52 | struct drivers_generic_gpio_regulator_config *config = dev->chip_info; |
| 53 | static char name[5]; |
| 54 | |
| 55 | snprintf(name, sizeof(name), "R%03.3X", config->gpio.pins[0]); |
| 56 | name[4] = '\0'; |
| 57 | |
| 58 | return name; |
| 59 | } |
| 60 | |
| 61 | static struct device_operations gpio_regulator_ops = { |
| 62 | .read_resources = DEVICE_NOOP, |
| 63 | .set_resources = DEVICE_NOOP, |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 64 | .acpi_name = gpio_regulator_acpi_name, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 65 | .acpi_fill_ssdt = gpio_regulator_fill_ssdt_generator, |
Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static void gpio_regulator_enable(struct device *dev) |
| 69 | { |
| 70 | dev->ops = &gpio_regulator_ops; |
| 71 | } |
| 72 | |
| 73 | struct chip_operations drivers_generic_gpio_regulator_ops = { |
| 74 | CHIP_NAME("GPIO Regulator") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 75 | .enable_dev = gpio_regulator_enable |
Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 76 | }; |