Furquan Shaikh | 60f3217 | 2016-12-12 09:30:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2016 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi_device.h> |
| 17 | #include <arch/acpigen.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/path.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include "chip.h" |
| 24 | |
| 25 | static void gpio_regulator_fill_ssdt_generator(struct device *dev) |
| 26 | { |
| 27 | struct drivers_generic_gpio_regulator_config *config = dev->chip_info; |
| 28 | const char *scope = acpi_device_scope(dev); |
| 29 | const char *path = acpi_device_path(dev); |
| 30 | struct acpi_dp *dsd; |
| 31 | |
| 32 | if (!dev->enabled || !scope || !path || !config->gpio.pin_count) |
| 33 | return; |
| 34 | |
| 35 | /* Device */ |
| 36 | acpigen_write_scope(scope); |
| 37 | acpigen_write_device(acpi_device_name(dev)); |
| 38 | |
| 39 | /* _HID is set to PRP0001 */ |
| 40 | acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID); |
| 41 | |
| 42 | /* Resources - _CRS */ |
| 43 | acpigen_write_name("_CRS"); |
| 44 | acpigen_write_resourcetemplate_header(); |
| 45 | acpi_device_write_gpio(&config->gpio); |
| 46 | acpigen_write_resourcetemplate_footer(); |
| 47 | |
| 48 | /* DSD */ |
| 49 | dsd = acpi_dp_new_table("_DSD"); |
| 50 | acpi_dp_add_string(dsd, "compatible", "regulator-fixed"); |
| 51 | acpi_dp_add_string(dsd, "regulator-name", config->name); |
| 52 | acpi_dp_add_gpio(dsd, "gpio-gpios", path, 0, 0, config->gpio.polarity); |
| 53 | if (config->enabled_on_boot) |
| 54 | acpi_dp_add_string(dsd, "regulator-boot-on", "on"); |
| 55 | if (config->gpio.polarity == ACPI_GPIO_ACTIVE_HIGH) |
| 56 | acpi_dp_add_string(dsd, "enable-active-high", "on"); |
| 57 | acpi_dp_write(dsd); |
| 58 | |
| 59 | acpigen_pop_len(); /* Device */ |
| 60 | acpigen_pop_len(); /* Scope */ |
| 61 | } |
| 62 | |
| 63 | static const char *gpio_regulator_acpi_name(struct device *dev) |
| 64 | { |
| 65 | struct drivers_generic_gpio_regulator_config *config = dev->chip_info; |
| 66 | static char name[5]; |
| 67 | |
| 68 | snprintf(name, sizeof(name), "R%03.3X", config->gpio.pins[0]); |
| 69 | name[4] = '\0'; |
| 70 | |
| 71 | return name; |
| 72 | } |
| 73 | |
| 74 | static struct device_operations gpio_regulator_ops = { |
| 75 | .read_resources = DEVICE_NOOP, |
| 76 | .set_resources = DEVICE_NOOP, |
| 77 | .enable_resources = DEVICE_NOOP, |
| 78 | .acpi_name = &gpio_regulator_acpi_name, |
| 79 | .acpi_fill_ssdt_generator = &gpio_regulator_fill_ssdt_generator, |
| 80 | }; |
| 81 | |
| 82 | static void gpio_regulator_enable(struct device *dev) |
| 83 | { |
| 84 | dev->ops = &gpio_regulator_ops; |
| 85 | } |
| 86 | |
| 87 | struct chip_operations drivers_generic_gpio_regulator_ops = { |
| 88 | CHIP_NAME("GPIO Regulator") |
| 89 | .enable_dev = &gpio_regulator_enable |
| 90 | }; |