[coreboot-gerrit] Change in coreboot[master]: drivers/gpio_keys: Add driver for handling gpio-keys
Furquan Shaikh (Code Review)
gerrit at coreboot.org
Fri Jan 12 05:06:42 CET 2018
Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/23236
Change subject: drivers/gpio_keys: Add driver for handling gpio-keys
......................................................................
drivers/gpio_keys: Add driver for handling gpio-keys
This change adds the required device node in SSDT for defining
gpio-keys. Currently, it supports only one gpio-key per device
node.
TEST=Verified by adding details to devicetree that device node is
added to SSDT:
Device (PENH)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0024
}
})
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x01)
{
Package (0x02)
{
"compatible",
"gpio-keys"
}
}
})
Device (EJCT)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x04)
{
Package (0x02)
{
"linux,code",
0x0F
},
Package (0x02)
{
"linux,input-type",
0x05
},
Package (0x02)
{
"label",
"pen_eject"
},
Package (0x02)
{
"gpios",
Package (0x04)
{
\_SB.PCI0.I2C0.PENH,
Zero,
Zero,
One
}
}
}
})
}
}
Change-Id: I6f11397b17d9de1c87d56f6a61669ef4052ec27b
Signed-off-by: Furquan Shaikh <furquan at chromium.org>
---
A src/drivers/generic/gpio_keys/Kconfig
A src/drivers/generic/gpio_keys/Makefile.inc
A src/drivers/generic/gpio_keys/chip.h
A src/drivers/generic/gpio_keys/gpio_keys.c
4 files changed, 198 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/36/23236/1
diff --git a/src/drivers/generic/gpio_keys/Kconfig b/src/drivers/generic/gpio_keys/Kconfig
new file mode 100644
index 0000000..7db8f06
--- /dev/null
+++ b/src/drivers/generic/gpio_keys/Kconfig
@@ -0,0 +1,18 @@
+#
+# This file is part of the coreboot project.
+#
+# Copyright 2018 Google LLC
+#
+# 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_GENERIC_GPIO_KEYS
+ bool
+ depends on HAVE_ACPI_TABLES
diff --git a/src/drivers/generic/gpio_keys/Makefile.inc b/src/drivers/generic/gpio_keys/Makefile.inc
new file mode 100644
index 0000000..614a126
--- /dev/null
+++ b/src/drivers/generic/gpio_keys/Makefile.inc
@@ -0,0 +1,16 @@
+#
+# This file is part of the coreboot project.
+#
+# Copyright 2018 Google LLC
+#
+# 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_GENERIC_GPIO_KEYS) += gpio_keys.c
diff --git a/src/drivers/generic/gpio_keys/chip.h b/src/drivers/generic/gpio_keys/chip.h
new file mode 100644
index 0000000..49ea71e
--- /dev/null
+++ b/src/drivers/generic/gpio_keys/chip.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC
+ *
+ * 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_GENERIC_GPIO_KEYS_H__
+#define __DRIVERS_GENERIC_GPIO_KEYS_H__
+
+#include <arch/acpi_device.h>
+
+struct key_info {
+ const char *dev_name;
+ uint32_t linux_code;
+ uint32_t linux_input_type;
+ const char *label;
+ bool is_wakeup_source;
+ bool can_be_disabled;
+ uint32_t debounce_interval;
+};
+
+struct drivers_generic_gpio_keys_config {
+ const char *name;
+ struct acpi_gpio gpio;
+ struct key_info key;
+};
+
+#endif /* __DRIVERS_GENERIC_GPIO_KEYS_H__ */
diff --git a/src/drivers/generic/gpio_keys/gpio_keys.c b/src/drivers/generic/gpio_keys/gpio_keys.c
new file mode 100644
index 0000000..6e9e5cc
--- /dev/null
+++ b/src/drivers/generic/gpio_keys/gpio_keys.c
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC
+ *
+ * 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"
+
+static void gpio_keys_add_child_node(
+ struct drivers_generic_gpio_keys_config *config,
+ const char *parent_path)
+{
+ struct acpi_dp *dsd;
+ struct key_info *key = &config->key;
+
+ if (!key->dev_name || !key->linux_code)
+ return;
+
+ /* Device */
+ acpigen_write_device(key->dev_name);
+
+ /* _HID is set to PRP0001 */
+ acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID);
+
+ /* DSD */
+ dsd = acpi_dp_new_table("_DSD");
+ acpi_dp_add_integer(dsd, "linux,code", key->linux_code);
+ if (key->linux_input_type)
+ acpi_dp_add_integer(dsd, "linux,input-type",
+ key->linux_input_type);
+ if (key->label)
+ acpi_dp_add_string(dsd, "label", key->label);
+ if (key->is_wakeup_source)
+ acpi_dp_add_integer(dsd, "wakeup-source",
+ key->is_wakeup_source);
+ if (key->can_be_disabled)
+ acpi_dp_add_integer(dsd, "linux,can-disable",
+ key->can_be_disabled);
+ if (key->debounce_interval)
+ acpi_dp_add_integer(dsd, "debounce-interval",
+ key->debounce_interval);
+ acpi_dp_add_gpio(dsd, "gpios", parent_path, 0, 0,
+ config->gpio.polarity);
+ acpi_dp_write(dsd);
+
+ acpigen_pop_len(); /* Device */
+}
+
+static void gpio_keys_fill_ssdt_generator(struct device *dev)
+{
+ struct drivers_generic_gpio_keys_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 || !path || !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", ACPI_DT_NAMESPACE_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", "gpio-keys");
+ acpi_dp_write(dsd);
+
+ /* Child device defining key */
+ gpio_keys_add_child_node(config, path);
+
+ acpigen_pop_len(); /* Device */
+ acpigen_pop_len(); /* Scope */
+}
+
+static const char *gpio_keys_acpi_name(const struct device *dev)
+{
+ struct drivers_generic_gpio_keys_config *config = dev->chip_info;
+ static char name[5];
+
+ if (config->name)
+ return config->name;
+
+ snprintf(name, sizeof(name), "K%03.3X", config->gpio.pins[0]);
+ name[4] = '\0';
+
+ return name;
+}
+
+static struct device_operations gpio_keys_ops = {
+ .acpi_name = &gpio_keys_acpi_name,
+ .acpi_fill_ssdt_generator = &gpio_keys_fill_ssdt_generator,
+};
+
+static void gpio_keys_enable(struct device *dev)
+{
+ dev->ops = &gpio_keys_ops;
+}
+
+struct chip_operations drivers_generic_gpio_keys_ops = {
+ CHIP_NAME("GPIO Keys")
+ .enable_dev = &gpio_keys_enable
+};
--
To view, visit https://review.coreboot.org/23236
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6f11397b17d9de1c87d56f6a61669ef4052ec27b
Gerrit-Change-Number: 23236
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180112/b42385ba/attachment-0001.html>
More information about the coreboot-gerrit
mailing list