blob: 7041aa0e7c153eb1dffead4177ccf96e8c3fd062 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Furquan Shaikh60f32172016-12-12 09:30:42 -08003
4#include <arch/acpi_device.h>
5#include <arch/acpigen.h>
Furquan Shaikh60f32172016-12-12 09:30:42 -08006#include <device/device.h>
7#include <device/path.h>
8#include <string.h>
9
10#include "chip.h"
11
12static 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 Durbinaa090cb2017-09-13 16:01:52 -060050static const char *gpio_regulator_acpi_name(const struct device *dev)
Furquan Shaikh60f32172016-12-12 09:30:42 -080051{
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
61static struct device_operations gpio_regulator_ops = {
62 .read_resources = DEVICE_NOOP,
63 .set_resources = DEVICE_NOOP,
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010064 .acpi_name = gpio_regulator_acpi_name,
Nico Huber68680dd2020-03-31 17:34:52 +020065 .acpi_fill_ssdt = gpio_regulator_fill_ssdt_generator,
Furquan Shaikh60f32172016-12-12 09:30:42 -080066};
67
68static void gpio_regulator_enable(struct device *dev)
69{
70 dev->ops = &gpio_regulator_ops;
71}
72
73struct chip_operations drivers_generic_gpio_regulator_ops = {
74 CHIP_NAME("GPIO Regulator")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010075 .enable_dev = gpio_regulator_enable
Furquan Shaikh60f32172016-12-12 09:30:42 -080076};