[coreboot-gerrit] New patch to review for coreboot: drivers/regulator: Add driver for handling GPIO-based fixed regulator

Furquan Shaikh (furquan@google.com) gerrit at coreboot.org
Mon Dec 12 18:54:15 CET 2016


Furquan Shaikh (furquan at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17798

-gerrit

commit 941a82eb339ce7692a3794a236d83d8c09d9605a
Author: Furquan Shaikh <furquan at chromium.org>
Date:   Mon Dec 12 09:30:42 2016 -0800

    drivers/regulator: Add driver for handling GPIO-based fixed regulator
    
    This change adds the required device node in SSDT for defining
    GPIO-based fixed voltage regulator.
    
    BUG=chrome-os-partner:60194
    BRANCH=None
    TEST=Verified that ELAN touchscreen works with exported GPIOs and ACPI
    regulator.
    
    Change-Id: I4380aea0929fb7e81dbe83f940e3e51e983819f9
    Signed-off-by: Furquan Shaikh <furquan at chromium.org>
---
 src/drivers/regulator/gpio_regulator/Kconfig       | 17 ++++
 src/drivers/regulator/gpio_regulator/Makefile.inc  | 16 ++++
 src/drivers/regulator/gpio_regulator/chip.h        | 27 ++++++
 .../regulator/gpio_regulator/gpio_regulator.c      | 97 ++++++++++++++++++++++
 4 files changed, 157 insertions(+)

diff --git a/src/drivers/regulator/gpio_regulator/Kconfig b/src/drivers/regulator/gpio_regulator/Kconfig
new file mode 100644
index 0000000..25c13a8
--- /dev/null
+++ b/src/drivers/regulator/gpio_regulator/Kconfig
@@ -0,0 +1,17 @@
+#
+# This file is part of the coreboot project.
+#
+# Copyright 2016 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+config DRIVERS_REGULATOR_GPIO_REGULATOR
+	bool
\ No newline at end of file
diff --git a/src/drivers/regulator/gpio_regulator/Makefile.inc b/src/drivers/regulator/gpio_regulator/Makefile.inc
new file mode 100644
index 0000000..8a65561
--- /dev/null
+++ b/src/drivers/regulator/gpio_regulator/Makefile.inc
@@ -0,0 +1,16 @@
+#
+# This file is part of the coreboot project.
+#
+# Copyright 2016 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+ramstage-$(CONFIG_DRIVERS_REGULATOR_GPIO_REGULATOR) += gpio_regulator.c
diff --git a/src/drivers/regulator/gpio_regulator/chip.h b/src/drivers/regulator/gpio_regulator/chip.h
new file mode 100644
index 0000000..aee8366
--- /dev/null
+++ b/src/drivers/regulator/gpio_regulator/chip.h
@@ -0,0 +1,27 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __DRIVERS_REGULATOR_GPIO_REGULATOR_H__
+#define __DRIVERS_REGULATOR_GPIO_REGULATOR_H__
+
+#include <arch/acpi_device.h>
+
+struct drivers_regulator_gpio_regulator_config {
+	const char *name;
+	struct acpi_gpio gpio;
+	bool enabled_on_boot;
+};
+
+#endif /* __DRIVERS_REGULATOR_GPIO_REGULATOR_H__ */
diff --git a/src/drivers/regulator/gpio_regulator/gpio_regulator.c b/src/drivers/regulator/gpio_regulator/gpio_regulator.c
new file mode 100644
index 0000000..b3e120b
--- /dev/null
+++ b/src/drivers/regulator/gpio_regulator/gpio_regulator.c
@@ -0,0 +1,97 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <arch/acpi_device.h>
+#include <arch/acpigen.h>
+#include <console/console.h>
+#include <device/device.h>
+#include <device/path.h>
+#include <string.h>
+
+#include "chip.h"
+
+#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
+
+#define GPIO_REGULATOR_HID		"PRP0001"
+
+static void gpio_regulator_fill_ssdt_generator(struct device *dev)
+{
+	struct drivers_regulator_gpio_regulator_config *config = dev->chip_info;
+	const char *scope = acpi_device_scope(dev);
+	const char *path = acpi_device_path(dev);
+	struct acpi_dp *dsd;
+
+	if (!dev->enabled || !scope || !config->gpio.pin_count)
+		return;
+
+	/* Device */
+	acpigen_write_scope(scope);
+	acpigen_write_device(acpi_device_name(dev));
+
+	/* _HID is set to PRP0001 */
+	acpigen_write_name_string("_HID", GPIO_REGULATOR_HID);
+
+	/* Resources - _CRS */
+	acpigen_write_name("_CRS");
+	acpigen_write_resourcetemplate_header();
+	acpi_device_write_gpio(&config->gpio);
+	acpigen_write_resourcetemplate_footer();
+
+	/* DSD */
+	dsd = acpi_dp_new_table("_DSD");
+	acpi_dp_add_string(dsd, "compatible", "regulator-fixed");
+	acpi_dp_add_string(dsd, "supply-name", config->name);
+	acpi_dp_add_gpio(dsd, "gpio-gpios", path, 0, 0, config->gpio.polarity);
+	if (config->enabled_on_boot)
+		acpi_dp_add_string(dsd, "regulator-boot-on", "on");
+	if (config->gpio.polarity == ACPI_GPIO_ACTIVE_HIGH)
+		acpi_dp_add_string(dsd, "enable-active-high", "on");
+	acpi_dp_write(dsd);
+
+	acpigen_pop_len(); /* Device */
+	acpigen_pop_len(); /* Scope */
+}
+
+static const char *gpio_regulator_acpi_name(struct device *dev)
+{
+	struct drivers_regulator_gpio_regulator_config *config = dev->chip_info;
+	static char name[5];
+
+	snprintf(name, sizeof(name), "R%03.3X", config->gpio.pins[0]);
+	name[4] = '\0';
+
+	return name;
+}
+#endif
+
+static struct device_operations gpio_regulator_ops = {
+	.read_resources = DEVICE_NOOP,
+	.set_resources = DEVICE_NOOP,
+	.enable_resources = DEVICE_NOOP,
+#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
+	.acpi_name = &gpio_regulator_acpi_name,
+	.acpi_fill_ssdt_generator = &gpio_regulator_fill_ssdt_generator,
+#endif
+};
+
+static void gpio_regulator_enable(struct device *dev)
+{
+	dev->ops = &gpio_regulator_ops;
+}
+
+struct chip_operations drivers_regulator_gpio_regulator_ops = {
+	CHIP_NAME("GPIO Regulator")
+	.enable_dev = &gpio_regulator_enable
+};



More information about the coreboot-gerrit mailing list