<p>Furquan Shaikh has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/23236">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drivers/gpio_keys: Add driver for handling gpio-keys<br><br>This change adds the required device node in SSDT for defining<br>gpio-keys. Currently, it supports only one gpio-key per device<br>node.<br><br>TEST=Verified by adding details to devicetree that device node is<br>added to SSDT:<br>        Device (PENH)<br>        {<br>            Name (_HID, "PRP0001")  // _HID: Hardware ID<br>            Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings<br>            {<br>                GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionInputOnly,<br>                    "\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, ,<br>                    )<br>                    {   // Pin list<br>                        0x0024<br>                    }<br>            })<br>            Name (_DSD, Package (0x02)  // _DSD: Device-Specific Data<br>            {<br>                ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,<br>                Package (0x01)<br>                {<br>                    Package (0x02)<br>                    {<br>                        "compatible",<br>                        "gpio-keys"<br>                    }<br>                }<br>            })<br>            Device (EJCT)<br>            {<br>                Name (_HID, "PRP0001")  // _HID: Hardware ID<br>                Name (_DSD, Package (0x02)  // _DSD: Device-Specific Data<br>                {<br>                    ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,<br>                    Package (0x04)<br>                    {<br>                        Package (0x02)<br>                        {<br>                            "linux,code",<br>                            0x0F<br>                        },<br><br>                        Package (0x02)<br>                        {<br>                            "linux,input-type",<br>                            0x05<br>                        },<br><br>                        Package (0x02)<br>                        {<br>                            "label",<br>                            "pen_eject"<br>                        },<br><br>                        Package (0x02)<br>                        {<br>                            "gpios",<br>                            Package (0x04)<br>                            {<br>                                \_SB.PCI0.I2C0.PENH,<br>                                Zero,<br>                                Zero,<br>                                One<br>                            }<br>                        }<br>                    }<br>                })<br>            }<br>        }<br><br>Change-Id: I6f11397b17d9de1c87d56f6a61669ef4052ec27b<br>Signed-off-by: Furquan Shaikh <furquan@chromium.org><br>---<br>A src/drivers/generic/gpio_keys/Kconfig<br>A src/drivers/generic/gpio_keys/Makefile.inc<br>A src/drivers/generic/gpio_keys/chip.h<br>A src/drivers/generic/gpio_keys/gpio_keys.c<br>4 files changed, 198 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/36/23236/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/drivers/generic/gpio_keys/Kconfig b/src/drivers/generic/gpio_keys/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..7db8f06</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/gpio_keys/Kconfig</span><br><span>@@ -0,0 +1,18 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright 2018 Google LLC</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+config DRIVERS_GENERIC_GPIO_KEYS</span><br><span style="color: hsl(120, 100%, 40%);">+  bool</span><br><span style="color: hsl(120, 100%, 40%);">+  depends on HAVE_ACPI_TABLES</span><br><span>diff --git a/src/drivers/generic/gpio_keys/Makefile.inc b/src/drivers/generic/gpio_keys/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..614a126</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/gpio_keys/Makefile.inc</span><br><span>@@ -0,0 +1,16 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright 2018 Google LLC</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-$(CONFIG_DRIVERS_GENERIC_GPIO_KEYS) += gpio_keys.c</span><br><span>diff --git a/src/drivers/generic/gpio_keys/chip.h b/src/drivers/generic/gpio_keys/chip.h</span><br><span>new file mode 100644</span><br><span>index 0000000..49ea71e</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/gpio_keys/chip.h</span><br><span>@@ -0,0 +1,37 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google LLC</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef __DRIVERS_GENERIC_GPIO_KEYS_H__</span><br><span style="color: hsl(120, 100%, 40%);">+#define __DRIVERS_GENERIC_GPIO_KEYS_H__</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpi_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct key_info {</span><br><span style="color: hsl(120, 100%, 40%);">+       const char *dev_name;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint32_t linux_code;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint32_t linux_input_type;</span><br><span style="color: hsl(120, 100%, 40%);">+    const char *label;</span><br><span style="color: hsl(120, 100%, 40%);">+    bool is_wakeup_source;</span><br><span style="color: hsl(120, 100%, 40%);">+        bool can_be_disabled;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint32_t debounce_interval;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct drivers_generic_gpio_keys_config {</span><br><span style="color: hsl(120, 100%, 40%);">+  const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct acpi_gpio gpio;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct key_info key;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* __DRIVERS_GENERIC_GPIO_KEYS_H__ */</span><br><span>diff --git a/src/drivers/generic/gpio_keys/gpio_keys.c b/src/drivers/generic/gpio_keys/gpio_keys.c</span><br><span>new file mode 100644</span><br><span>index 0000000..6e9e5cc</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/gpio_keys/gpio_keys.c</span><br><span>@@ -0,0 +1,127 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google LLC</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpi_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpigen.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/path.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "chip.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void gpio_keys_add_child_node(</span><br><span style="color: hsl(120, 100%, 40%);">+                        struct drivers_generic_gpio_keys_config *config,</span><br><span style="color: hsl(120, 100%, 40%);">+                      const char *parent_path)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   struct acpi_dp *dsd;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct key_info *key = &config->key;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!key->dev_name || !key->linux_code)</span><br><span style="color: hsl(120, 100%, 40%);">+         return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_device(key->dev_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* _HID is set to PRP0001 */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* DSD */</span><br><span style="color: hsl(120, 100%, 40%);">+     dsd = acpi_dp_new_table("_DSD");</span><br><span style="color: hsl(120, 100%, 40%);">+    acpi_dp_add_integer(dsd, "linux,code", key->linux_code);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (key->linux_input_type)</span><br><span style="color: hsl(120, 100%, 40%);">+         acpi_dp_add_integer(dsd, "linux,input-type",</span><br><span style="color: hsl(120, 100%, 40%);">+                                    key->linux_input_type);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (key->label)</span><br><span style="color: hsl(120, 100%, 40%);">+            acpi_dp_add_string(dsd, "label", key->label);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (key->is_wakeup_source)</span><br><span style="color: hsl(120, 100%, 40%);">+         acpi_dp_add_integer(dsd, "wakeup-source",</span><br><span style="color: hsl(120, 100%, 40%);">+                               key->is_wakeup_source);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (key->can_be_disabled)</span><br><span style="color: hsl(120, 100%, 40%);">+          acpi_dp_add_integer(dsd, "linux,can-disable",</span><br><span style="color: hsl(120, 100%, 40%);">+                                   key->can_be_disabled);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (key->debounce_interval)</span><br><span style="color: hsl(120, 100%, 40%);">+                acpi_dp_add_integer(dsd, "debounce-interval",</span><br><span style="color: hsl(120, 100%, 40%);">+                                   key->debounce_interval);</span><br><span style="color: hsl(120, 100%, 40%);">+       acpi_dp_add_gpio(dsd, "gpios", parent_path, 0, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+                    config->gpio.polarity);</span><br><span style="color: hsl(120, 100%, 40%);">+   acpi_dp_write(dsd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_pop_len(); /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void gpio_keys_fill_ssdt_generator(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct drivers_generic_gpio_keys_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+  const char *scope = acpi_device_scope(dev);</span><br><span style="color: hsl(120, 100%, 40%);">+   const char *path = acpi_device_path(dev);</span><br><span style="color: hsl(120, 100%, 40%);">+     struct acpi_dp *dsd;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        if (!dev->enabled || !scope || !path || !config->gpio.pin_count)</span><br><span style="color: hsl(120, 100%, 40%);">+                return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_scope(scope);</span><br><span style="color: hsl(120, 100%, 40%);">+   acpigen_write_device(acpi_device_name(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* _HID is set to PRP0001 */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Resources - _CRS */</span><br><span style="color: hsl(120, 100%, 40%);">+        acpigen_write_name("_CRS");</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_resourcetemplate_header();</span><br><span style="color: hsl(120, 100%, 40%);">+      acpi_device_write_gpio(&config->gpio);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_resourcetemplate_footer();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* DSD */</span><br><span style="color: hsl(120, 100%, 40%);">+     dsd = acpi_dp_new_table("_DSD");</span><br><span style="color: hsl(120, 100%, 40%);">+    acpi_dp_add_string(dsd, "compatible", "gpio-keys");</span><br><span style="color: hsl(120, 100%, 40%);">+       acpi_dp_write(dsd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Child device defining key */</span><br><span style="color: hsl(120, 100%, 40%);">+       gpio_keys_add_child_node(config, path);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     acpigen_pop_len(); /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+       acpigen_pop_len(); /* Scope */</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const char *gpio_keys_acpi_name(const struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct drivers_generic_gpio_keys_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+  static char name[5];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        if (config->name)</span><br><span style="color: hsl(120, 100%, 40%);">+          return config->name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     snprintf(name, sizeof(name), "K%03.3X", config->gpio.pins[0]);</span><br><span style="color: hsl(120, 100%, 40%);">+   name[4] = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     return name;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct device_operations gpio_keys_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+  .acpi_name = &gpio_keys_acpi_name,</span><br><span style="color: hsl(120, 100%, 40%);">+        .acpi_fill_ssdt_generator = &gpio_keys_fill_ssdt_generator,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void gpio_keys_enable(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    dev->ops = &gpio_keys_ops;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct chip_operations drivers_generic_gpio_keys_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+      CHIP_NAME("GPIO Keys")</span><br><span style="color: hsl(120, 100%, 40%);">+      .enable_dev = &gpio_keys_enable</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/23236">change 23236</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/23236"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6f11397b17d9de1c87d56f6a61669ef4052ec27b </div>
<div style="display:none"> Gerrit-Change-Number: 23236 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Furquan Shaikh <furquan@google.com> </div>