]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
platform/surface: Move Surface 3 Button driver to platform/surface
authorMaximilian Luz <luzmaximilian@gmail.com>
Fri, 9 Oct 2020 14:11:26 +0000 (16:11 +0200)
committerHans de Goede <hdegoede@redhat.com>
Tue, 27 Oct 2020 11:51:24 +0000 (12:51 +0100)
Move the Surface 3 Button driver from platform/x86 to the newly created
platform/surface directory.

Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20201009141128.683254-4-luzmaximilian@gmail.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/surface/Kconfig
drivers/platform/surface/Makefile
drivers/platform/surface/surface3_button.c [new file with mode: 0644]
drivers/platform/x86/Kconfig
drivers/platform/x86/Makefile
drivers/platform/x86/surface3_button.c [deleted file]

index 326f7bbf83d708d7f41e15dce491b2a73e6f937b..1a7cf6a73d523e6737adf68a77d776317b2f0298 100644 (file)
@@ -27,4 +27,10 @@ config SURFACE3_WMI
          To compile this driver as a module, choose M here: the module will
          be called surface3-wmi.
 
+config SURFACE_3_BUTTON
+       tristate "Power/home/volume buttons driver for Microsoft Surface 3 tablet"
+       depends on ACPI && KEYBOARD_GPIO && I2C
+       help
+         This driver handles the power/home/volume buttons on the Microsoft Surface 3 tablet.
+
 endif # SURFACE_PLATFORMS
index f889d521420f2f8f0b8038937aed970158046faa..8588dc178245afbff88bc099c5330e97ff001011 100644 (file)
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_SURFACE3_WMI)             += surface3-wmi.o
+obj-$(CONFIG_SURFACE_3_BUTTON)         += surface3_button.o
diff --git a/drivers/platform/surface/surface3_button.c b/drivers/platform/surface/surface3_button.c
new file mode 100644 (file)
index 0000000..48d77e7
--- /dev/null
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Supports for the button array on the Surface tablets.
+ *
+ * (C) Copyright 2016 Red Hat, Inc
+ *
+ * Based on soc_button_array.c:
+ *
+ * {C} Copyright 2014 Intel Corporation
+ */
+
+#include <linux/module.h>
+#include <linux/input.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/acpi.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio_keys.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+
+
+#define SURFACE_BUTTON_OBJ_NAME                "TEV2"
+#define MAX_NBUTTONS                   4
+
+/*
+ * Some of the buttons like volume up/down are auto repeat, while others
+ * are not. To support both, we register two platform devices, and put
+ * buttons into them based on whether the key should be auto repeat.
+ */
+#define BUTTON_TYPES                   2
+
+/*
+ * Power button, Home button, Volume buttons support is supposed to
+ * be covered by drivers/input/misc/soc_button_array.c, which is implemented
+ * according to "Windows ACPI Design Guide for SoC Platforms".
+ * However surface 3 seems not to obey the specs, instead it uses
+ * device TEV2(MSHW0028) for declaring the GPIOs. The gpios are also slightly
+ * different in which the Home button is active high.
+ * Compared to surfacepro3_button.c which also handles MSHW0028, the Surface 3
+ * is a reduce platform and thus uses GPIOs, not ACPI events.
+ * We choose an I2C driver here because we need to access the resources
+ * declared under the device node, while surfacepro3_button.c only needs
+ * the ACPI companion node.
+ */
+static const struct acpi_device_id surface3_acpi_match[] = {
+       { "MSHW0028", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, surface3_acpi_match);
+
+struct surface3_button_info {
+       const char *name;
+       int acpi_index;
+       unsigned int event_type;
+       unsigned int event_code;
+       bool autorepeat;
+       bool wakeup;
+       bool active_low;
+};
+
+struct surface3_button_data {
+       struct platform_device *children[BUTTON_TYPES];
+};
+
+/*
+ * Get the Nth GPIO number from the ACPI object.
+ */
+static int surface3_button_lookup_gpio(struct device *dev, int acpi_index)
+{
+       struct gpio_desc *desc;
+       int gpio;
+
+       desc = gpiod_get_index(dev, NULL, acpi_index, GPIOD_ASIS);
+       if (IS_ERR(desc))
+               return PTR_ERR(desc);
+
+       gpio = desc_to_gpio(desc);
+
+       gpiod_put(desc);
+
+       return gpio;
+}
+
+static struct platform_device *
+surface3_button_device_create(struct i2c_client *client,
+                             const struct surface3_button_info *button_info,
+                             bool autorepeat)
+{
+       const struct surface3_button_info *info;
+       struct platform_device *pd;
+       struct gpio_keys_button *gpio_keys;
+       struct gpio_keys_platform_data *gpio_keys_pdata;
+       int n_buttons = 0;
+       int gpio;
+       int error;
+
+       gpio_keys_pdata = devm_kzalloc(&client->dev,
+                                      sizeof(*gpio_keys_pdata) +
+                                      sizeof(*gpio_keys) * MAX_NBUTTONS,
+                                      GFP_KERNEL);
+       if (!gpio_keys_pdata)
+               return ERR_PTR(-ENOMEM);
+
+       gpio_keys = (void *)(gpio_keys_pdata + 1);
+
+       for (info = button_info; info->name; info++) {
+               if (info->autorepeat != autorepeat)
+                       continue;
+
+               gpio = surface3_button_lookup_gpio(&client->dev,
+                                                  info->acpi_index);
+               if (!gpio_is_valid(gpio))
+                       continue;
+
+               gpio_keys[n_buttons].type = info->event_type;
+               gpio_keys[n_buttons].code = info->event_code;
+               gpio_keys[n_buttons].gpio = gpio;
+               gpio_keys[n_buttons].active_low = info->active_low;
+               gpio_keys[n_buttons].desc = info->name;
+               gpio_keys[n_buttons].wakeup = info->wakeup;
+               n_buttons++;
+       }
+
+       if (n_buttons == 0) {
+               error = -ENODEV;
+               goto err_free_mem;
+       }
+
+       gpio_keys_pdata->buttons = gpio_keys;
+       gpio_keys_pdata->nbuttons = n_buttons;
+       gpio_keys_pdata->rep = autorepeat;
+
+       pd = platform_device_alloc("gpio-keys", PLATFORM_DEVID_AUTO);
+       if (!pd) {
+               error = -ENOMEM;
+               goto err_free_mem;
+       }
+
+       error = platform_device_add_data(pd, gpio_keys_pdata,
+                                        sizeof(*gpio_keys_pdata));
+       if (error)
+               goto err_free_pdev;
+
+       error = platform_device_add(pd);
+       if (error)
+               goto err_free_pdev;
+
+       return pd;
+
+err_free_pdev:
+       platform_device_put(pd);
+err_free_mem:
+       devm_kfree(&client->dev, gpio_keys_pdata);
+       return ERR_PTR(error);
+}
+
+static int surface3_button_remove(struct i2c_client *client)
+{
+       struct surface3_button_data *priv = i2c_get_clientdata(client);
+
+       int i;
+
+       for (i = 0; i < BUTTON_TYPES; i++)
+               if (priv->children[i])
+                       platform_device_unregister(priv->children[i]);
+
+       return 0;
+}
+
+static struct surface3_button_info surface3_button_surface3[] = {
+       { "power", 0, EV_KEY, KEY_POWER, false, true, true },
+       { "home", 1, EV_KEY, KEY_LEFTMETA, false, true, false },
+       { "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false, true },
+       { "volume_down", 3, EV_KEY, KEY_VOLUMEDOWN, true, false, true },
+       { }
+};
+
+static int surface3_button_probe(struct i2c_client *client,
+                                const struct i2c_device_id *id)
+{
+       struct device *dev = &client->dev;
+       struct surface3_button_data *priv;
+       struct platform_device *pd;
+       int i;
+       int error;
+
+       if (strncmp(acpi_device_bid(ACPI_COMPANION(&client->dev)),
+                   SURFACE_BUTTON_OBJ_NAME,
+                   strlen(SURFACE_BUTTON_OBJ_NAME)))
+               return -ENODEV;
+
+       error = gpiod_count(dev, NULL);
+       if (error < 0) {
+               dev_dbg(dev, "no GPIO attached, ignoring...\n");
+               return error;
+       }
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       i2c_set_clientdata(client, priv);
+
+       for (i = 0; i < BUTTON_TYPES; i++) {
+               pd = surface3_button_device_create(client,
+                                                  surface3_button_surface3,
+                                                  i == 0);
+               if (IS_ERR(pd)) {
+                       error = PTR_ERR(pd);
+                       if (error != -ENODEV) {
+                               surface3_button_remove(client);
+                               return error;
+                       }
+                       continue;
+               }
+
+               priv->children[i] = pd;
+       }
+
+       if (!priv->children[0] && !priv->children[1])
+               return -ENODEV;
+
+       return 0;
+}
+
+static const struct i2c_device_id surface3_id[] = {
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, surface3_id);
+
+static struct i2c_driver surface3_driver = {
+       .probe = surface3_button_probe,
+       .remove = surface3_button_remove,
+       .id_table = surface3_id,
+       .driver = {
+               .name = "surface3",
+               .acpi_match_table = ACPI_PTR(surface3_acpi_match),
+       },
+};
+module_i2c_driver(surface3_driver);
+
+MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
+MODULE_DESCRIPTION("surface3 button array driver");
+MODULE_LICENSE("GPL v2");
index 0759913c9846d973be96fa2d9fdd8a739af0cc1f..5fba590a1a67cf45fa7c3c238d7f203d0b54f412 100644 (file)
@@ -870,12 +870,6 @@ config INTEL_VBTN
          To compile this driver as a module, choose M here: the module will
          be called intel_vbtn.
 
-config SURFACE_3_BUTTON
-       tristate "Power/home/volume buttons driver for Microsoft Surface 3 tablet"
-       depends on ACPI && KEYBOARD_GPIO && I2C
-       help
-         This driver handles the power/home/volume buttons on the Microsoft Surface 3 tablet.
-
 config SURFACE_3_POWER_OPREGION
        tristate "Surface 3 battery platform operation region support"
        depends on ACPI && I2C
index 29563a32b3e3fdde1856ce0bc78431e421ce91ec..0fd70d5d2cf3bd9b30eb4e7bc913f8296a3fbf86 100644 (file)
@@ -82,7 +82,6 @@ obj-$(CONFIG_INTEL_OAKTRAIL)          += intel_oaktrail.o
 obj-$(CONFIG_INTEL_VBTN)               += intel-vbtn.o
 
 # Microsoft
-obj-$(CONFIG_SURFACE_3_BUTTON)         += surface3_button.o
 obj-$(CONFIG_SURFACE_3_POWER_OPREGION) += surface3_power.o
 obj-$(CONFIG_SURFACE_PRO3_BUTTON)      += surfacepro3_button.o
 
diff --git a/drivers/platform/x86/surface3_button.c b/drivers/platform/x86/surface3_button.c
deleted file mode 100644 (file)
index 48d77e7..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Supports for the button array on the Surface tablets.
- *
- * (C) Copyright 2016 Red Hat, Inc
- *
- * Based on soc_button_array.c:
- *
- * {C} Copyright 2014 Intel Corporation
- */
-
-#include <linux/module.h>
-#include <linux/input.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/i2c.h>
-#include <linux/slab.h>
-#include <linux/acpi.h>
-#include <linux/gpio/consumer.h>
-#include <linux/gpio_keys.h>
-#include <linux/gpio.h>
-#include <linux/platform_device.h>
-
-
-#define SURFACE_BUTTON_OBJ_NAME                "TEV2"
-#define MAX_NBUTTONS                   4
-
-/*
- * Some of the buttons like volume up/down are auto repeat, while others
- * are not. To support both, we register two platform devices, and put
- * buttons into them based on whether the key should be auto repeat.
- */
-#define BUTTON_TYPES                   2
-
-/*
- * Power button, Home button, Volume buttons support is supposed to
- * be covered by drivers/input/misc/soc_button_array.c, which is implemented
- * according to "Windows ACPI Design Guide for SoC Platforms".
- * However surface 3 seems not to obey the specs, instead it uses
- * device TEV2(MSHW0028) for declaring the GPIOs. The gpios are also slightly
- * different in which the Home button is active high.
- * Compared to surfacepro3_button.c which also handles MSHW0028, the Surface 3
- * is a reduce platform and thus uses GPIOs, not ACPI events.
- * We choose an I2C driver here because we need to access the resources
- * declared under the device node, while surfacepro3_button.c only needs
- * the ACPI companion node.
- */
-static const struct acpi_device_id surface3_acpi_match[] = {
-       { "MSHW0028", 0 },
-       { }
-};
-MODULE_DEVICE_TABLE(acpi, surface3_acpi_match);
-
-struct surface3_button_info {
-       const char *name;
-       int acpi_index;
-       unsigned int event_type;
-       unsigned int event_code;
-       bool autorepeat;
-       bool wakeup;
-       bool active_low;
-};
-
-struct surface3_button_data {
-       struct platform_device *children[BUTTON_TYPES];
-};
-
-/*
- * Get the Nth GPIO number from the ACPI object.
- */
-static int surface3_button_lookup_gpio(struct device *dev, int acpi_index)
-{
-       struct gpio_desc *desc;
-       int gpio;
-
-       desc = gpiod_get_index(dev, NULL, acpi_index, GPIOD_ASIS);
-       if (IS_ERR(desc))
-               return PTR_ERR(desc);
-
-       gpio = desc_to_gpio(desc);
-
-       gpiod_put(desc);
-
-       return gpio;
-}
-
-static struct platform_device *
-surface3_button_device_create(struct i2c_client *client,
-                             const struct surface3_button_info *button_info,
-                             bool autorepeat)
-{
-       const struct surface3_button_info *info;
-       struct platform_device *pd;
-       struct gpio_keys_button *gpio_keys;
-       struct gpio_keys_platform_data *gpio_keys_pdata;
-       int n_buttons = 0;
-       int gpio;
-       int error;
-
-       gpio_keys_pdata = devm_kzalloc(&client->dev,
-                                      sizeof(*gpio_keys_pdata) +
-                                      sizeof(*gpio_keys) * MAX_NBUTTONS,
-                                      GFP_KERNEL);
-       if (!gpio_keys_pdata)
-               return ERR_PTR(-ENOMEM);
-
-       gpio_keys = (void *)(gpio_keys_pdata + 1);
-
-       for (info = button_info; info->name; info++) {
-               if (info->autorepeat != autorepeat)
-                       continue;
-
-               gpio = surface3_button_lookup_gpio(&client->dev,
-                                                  info->acpi_index);
-               if (!gpio_is_valid(gpio))
-                       continue;
-
-               gpio_keys[n_buttons].type = info->event_type;
-               gpio_keys[n_buttons].code = info->event_code;
-               gpio_keys[n_buttons].gpio = gpio;
-               gpio_keys[n_buttons].active_low = info->active_low;
-               gpio_keys[n_buttons].desc = info->name;
-               gpio_keys[n_buttons].wakeup = info->wakeup;
-               n_buttons++;
-       }
-
-       if (n_buttons == 0) {
-               error = -ENODEV;
-               goto err_free_mem;
-       }
-
-       gpio_keys_pdata->buttons = gpio_keys;
-       gpio_keys_pdata->nbuttons = n_buttons;
-       gpio_keys_pdata->rep = autorepeat;
-
-       pd = platform_device_alloc("gpio-keys", PLATFORM_DEVID_AUTO);
-       if (!pd) {
-               error = -ENOMEM;
-               goto err_free_mem;
-       }
-
-       error = platform_device_add_data(pd, gpio_keys_pdata,
-                                        sizeof(*gpio_keys_pdata));
-       if (error)
-               goto err_free_pdev;
-
-       error = platform_device_add(pd);
-       if (error)
-               goto err_free_pdev;
-
-       return pd;
-
-err_free_pdev:
-       platform_device_put(pd);
-err_free_mem:
-       devm_kfree(&client->dev, gpio_keys_pdata);
-       return ERR_PTR(error);
-}
-
-static int surface3_button_remove(struct i2c_client *client)
-{
-       struct surface3_button_data *priv = i2c_get_clientdata(client);
-
-       int i;
-
-       for (i = 0; i < BUTTON_TYPES; i++)
-               if (priv->children[i])
-                       platform_device_unregister(priv->children[i]);
-
-       return 0;
-}
-
-static struct surface3_button_info surface3_button_surface3[] = {
-       { "power", 0, EV_KEY, KEY_POWER, false, true, true },
-       { "home", 1, EV_KEY, KEY_LEFTMETA, false, true, false },
-       { "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false, true },
-       { "volume_down", 3, EV_KEY, KEY_VOLUMEDOWN, true, false, true },
-       { }
-};
-
-static int surface3_button_probe(struct i2c_client *client,
-                                const struct i2c_device_id *id)
-{
-       struct device *dev = &client->dev;
-       struct surface3_button_data *priv;
-       struct platform_device *pd;
-       int i;
-       int error;
-
-       if (strncmp(acpi_device_bid(ACPI_COMPANION(&client->dev)),
-                   SURFACE_BUTTON_OBJ_NAME,
-                   strlen(SURFACE_BUTTON_OBJ_NAME)))
-               return -ENODEV;
-
-       error = gpiod_count(dev, NULL);
-       if (error < 0) {
-               dev_dbg(dev, "no GPIO attached, ignoring...\n");
-               return error;
-       }
-
-       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
-
-       i2c_set_clientdata(client, priv);
-
-       for (i = 0; i < BUTTON_TYPES; i++) {
-               pd = surface3_button_device_create(client,
-                                                  surface3_button_surface3,
-                                                  i == 0);
-               if (IS_ERR(pd)) {
-                       error = PTR_ERR(pd);
-                       if (error != -ENODEV) {
-                               surface3_button_remove(client);
-                               return error;
-                       }
-                       continue;
-               }
-
-               priv->children[i] = pd;
-       }
-
-       if (!priv->children[0] && !priv->children[1])
-               return -ENODEV;
-
-       return 0;
-}
-
-static const struct i2c_device_id surface3_id[] = {
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, surface3_id);
-
-static struct i2c_driver surface3_driver = {
-       .probe = surface3_button_probe,
-       .remove = surface3_button_remove,
-       .id_table = surface3_id,
-       .driver = {
-               .name = "surface3",
-               .acpi_match_table = ACPI_PTR(surface3_acpi_match),
-       },
-};
-module_i2c_driver(surface3_driver);
-
-MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
-MODULE_DESCRIPTION("surface3 button array driver");
-MODULE_LICENSE("GPL v2");