Skip to contentSkip to conversation

platform/x86: add meraki-mx100 platform driver

PATCH Superseded Chris Blake 2 participants 8 messages Aug 9, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 platform/x86: add meraki-mx100 platform driver

This adds platform support for the Cisco Meraki MX100 (Tinkerbell) network appliance. This sets up the network LEDs and Reset button.

Depends-on: ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")

---

Changelog:
V3: Additional cleanups, formatting changes
V2: Move to using gpiod lookup tables, misc cleanups
V1: Initial Patch

 drivers/platform/x86/Kconfig        |  13 ++
 drivers/platform/x86/Makefile       |   3 +
 drivers/platform/x86/meraki-mx100.c | 202 ++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/platform/x86/meraki-mx100.c
drivers/platform/x86/Kconfig +13 -0
index 7d385c3b2239..8d70176e335f 100644
@@ -302,6 +302,19 @@ config ASUS_NB_WMI
 	  If you have an ACPI-WMI compatible Asus Notebook, say Y or M
 	  here.
 
+config MERAKI_MX100
+	tristate "Cisco Meraki MX100 Platform Driver"
+	depends on GPIOLIB
+	depends on GPIO_ICH
+	depends on LEDS_CLASS
+	select LEDS_GPIO
+	help
+	  This driver provides support for the front button and LEDs on
+	  the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called meraki-mx100.
+
 config EEEPC_LAPTOP
 	tristate "Eee PC Hotkey Driver"
 	depends on ACPI
drivers/platform/x86/Makefile +3 -0
index 7ee369aab10d..25c5aee1cde7 100644
@@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)	+= asus-nb-wmi.o
 obj-$(CONFIG_EEEPC_LAPTOP)	+= eeepc-laptop.o
 obj-$(CONFIG_EEEPC_WMI)		+= eeepc-wmi.o
 
+# Cisco/Meraki
+obj-$(CONFIG_MERAKI_MX100)	+= meraki-mx100.o
+
 # Dell
 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)		+= dell/
 
drivers/platform/x86/meraki-mx100.c new file +202 -0

202 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#1 lore raw
Quoted 269 lines · Chris Blake

This adds platform support for the Cisco Meraki MX100 (Tinkerbell) network appliance. This sets up the network LEDs and Reset button.

Depends-on: ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")

---

Changelog:
V3: Additional cleanups, formatting changes
V2: Move to using gpiod lookup tables, misc cleanups
V1: Initial Patch

 drivers/platform/x86/Kconfig        |  13 ++
 drivers/platform/x86/Makefile       |   3 +
 drivers/platform/x86/meraki-mx100.c | 202 ++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/platform/x86/meraki-mx100.c
drivers/platform/x86/Kconfig +13 -0
index 7d385c3b2239..8d70176e335f 100644
@@ -302,6 +302,19 @@ config ASUS_NB_WMI
          If you have an ACPI-WMI compatible Asus Notebook, say Y or M
          here.
 
+config MERAKI_MX100
+       tristate "Cisco Meraki MX100 Platform Driver"
+       depends on GPIOLIB
+       depends on GPIO_ICH
+       depends on LEDS_CLASS
+       select LEDS_GPIO
+       help
+         This driver provides support for the front button and LEDs on
+         the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
+
+         To compile this driver as a module, choose M here: the module
+         will be called meraki-mx100.
+
 config EEEPC_LAPTOP
        tristate "Eee PC Hotkey Driver"
        depends on ACPI
drivers/platform/x86/Makefile +3 -0
index 7ee369aab10d..25c5aee1cde7 100644
@@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)     += asus-nb-wmi.o
 obj-$(CONFIG_EEEPC_LAPTOP)     += eeepc-laptop.o
 obj-$(CONFIG_EEEPC_WMI)                += eeepc-wmi.o
 
+# Cisco/Meraki
+obj-$(CONFIG_MERAKI_MX100)     += meraki-mx100.o
+
 # Dell
 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)                += dell/
 
drivers/platform/x86/meraki-mx100.c new file +202 -1
new file mode 100644
index 000000000000..eebbd0a3d806
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Cisco Meraki MX100 (Tinkerbell) board platform driver
+ *
+ * Based off of arch/x86/platform/meraki/tink.c from the
+ * Meraki GPL release meraki-firmware-sources-r23-20150601
+ *
+ * Format inspired by platform/x86/pcengines-apuv2.c
+ *
+ * Copyright (C) 2021 Chris Blake <[email protected]>
+ */
+
+#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
+
+#include <linux/dmi.h>
+#include <linux/err.h>
+#include <linux/gpio_keys.h>
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#define TINK_GPIO_DRIVER_NAME "gpio_ich"
+
+/* LEDs */
+static const struct gpio_led tink_leds[] = {
+       {
+               .name = "mx100:green:internet",
+               .default_trigger = "default-on",
+       },
+       {
+               .name = "mx100:green:lan2",
+       },
+       {
+               .name = "mx100:green:lan3",
+       },
+       {
+               .name = "mx100:green:lan4",
+       },
+       {
+               .name = "mx100:green:lan5",
+       },
+       {
+               .name = "mx100:green:lan6",
+       },
+       {
+               .name = "mx100:green:lan7",
+       },
+       {
+               .name = "mx100:green:lan8",
+       },
+       {
+               .name = "mx100:green:lan9",
+       },
+       {
+               .name = "mx100:green:lan10",
+       },
+       {
+               .name = "mx100:green:lan11",
+       },
+};
+
+static const struct gpio_led_platform_data tink_leds_pdata = {
+       .num_leds       = ARRAY_SIZE(tink_leds),
+       .leds           = tink_leds,
+};
+
+static struct gpiod_lookup_table tink_leds_table = {
+       .dev_id = "leds-gpio",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
+                               NULL, 1, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
+                               NULL, 2, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
+                               NULL, 3, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
+                               NULL, 4, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
+                               NULL, 5, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
+                               NULL, 6, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
+                               NULL, 7, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
+                               NULL, 8, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
+                               NULL, 9, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
+                               NULL, 10, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
+                               NULL, 11, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
+                               NULL, 12, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
+                               NULL, 13, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
+                               NULL, 14, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Reset Button */
+static struct gpio_keys_button tink_buttons[] = {
+       {
+               .desc                   = "Reset",
+               .type                   = EV_KEY,
+               .code                   = KEY_RESTART,
+               .active_low             = 1,
+               .debounce_interval      = 100,
+       },
+};
+
+static const struct gpio_keys_platform_data tink_buttons_pdata = {
+       .buttons        = tink_buttons,
+       .nbuttons       = ARRAY_SIZE(tink_buttons),
+       .poll_interval  = 20,
+       .rep            = 0,
+       .name           = "mx100-keys",
+};
+
+static struct gpiod_lookup_table tink_keys_table = {
+       .dev_id = "gpio-keys-polled",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Board setup */
+static const struct dmi_system_id tink_systems[] __initconst = {
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
+               },
+       },
+       {} /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(dmi, tink_systems);
+
+static struct platform_device *tink_leds_pdev;
+static struct platform_device *tink_keys_pdev;
+
+static struct platform_device * __init tink_create_dev(
+       const char *name, const void *pdata, size_t sz)
+{
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL,
+               name, PLATFORM_DEVID_NONE, pdata, sz);
+       if (IS_ERR(pdev))
+               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+       return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+       if (!dmi_first_match(tink_systems))
+               return -ENODEV;
+
+       /*
+        * We need to make sure that GPIO60 isn't set to native mode as is default since it's our
+        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+        */
+       outl(inl(0x530) | BIT(28), 0x530);
+
+       gpiod_add_lookup_table(&tink_leds_table);
+       gpiod_add_lookup_table(&tink_keys_table);
+
+       tink_leds_pdev = tink_create_dev("leds-gpio",
+               &tink_leds_pdata, sizeof(tink_leds_pdata));
+
+       tink_keys_pdev = tink_create_dev("gpio-keys-polled",
+               &tink_buttons_pdata, sizeof(tink_buttons_pdata));
+
+       return 0;
+}
+module_init(tink_board_init);
+
+static void __exit tink_board_exit(void)
+{
+       platform_device_unregister(tink_keys_pdev);
+       platform_device_unregister(tink_leds_pdev);
+       gpiod_remove_lookup_table(&tink_keys_table);
+       gpiod_remove_lookup_table(&tink_leds_table);
+}
+module_exit(tink_board_exit);
+
+MODULE_AUTHOR("Chris Blake <[email protected]>");
+MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:meraki-mx100");
--
Quoted 2 lines

2.25.1

Please do not merge, I just realized I forgot to add in 2x LEDs after the move to gpiod lookup tables. Expect a V4 in the future.

Regards,
Chris B

#2 lore raw
Quoted 4 lines · Chris

On Mon, Aug 9, 2021 at 7:13 AM Chris Blake <[email protected]> wrote:

Please do not merge, I just realized I forgot to add in 2x LEDs after the move to gpiod lookup tables. Expect a V4 in the future.

Nevertheless, take into account my previous reply to this email.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v3 1/1
#3 lore raw
In reply to Chris Blake
Quoted 4 lines · Chris Blake

This adds platform support for the Cisco Meraki MX100 (Tinkerbell) network appliance. This sets up the network LEDs and Reset button.

Almost good to me, see below for some comments. After addressing them

Quoted 232 lines

Depends-on: ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")

---

Changelog:
V3: Additional cleanups, formatting changes
V2: Move to using gpiod lookup tables, misc cleanups
V1: Initial Patch

 drivers/platform/x86/Kconfig        |  13 ++
 drivers/platform/x86/Makefile       |   3 +
 drivers/platform/x86/meraki-mx100.c | 202 ++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/platform/x86/meraki-mx100.c
drivers/platform/x86/Kconfig +13 -0
index 7d385c3b2239..8d70176e335f 100644
@@ -302,6 +302,19 @@ config ASUS_NB_WMI
          If you have an ACPI-WMI compatible Asus Notebook, say Y or M
          here.
 
+config MERAKI_MX100
+       tristate "Cisco Meraki MX100 Platform Driver"
+       depends on GPIOLIB
+       depends on GPIO_ICH
+       depends on LEDS_CLASS
+       select LEDS_GPIO
+       help
+         This driver provides support for the front button and LEDs on
+         the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
+
+         To compile this driver as a module, choose M here: the module
+         will be called meraki-mx100.
+
 config EEEPC_LAPTOP
        tristate "Eee PC Hotkey Driver"
        depends on ACPI
drivers/platform/x86/Makefile +3 -0
index 7ee369aab10d..25c5aee1cde7 100644
@@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)     += asus-nb-wmi.o
 obj-$(CONFIG_EEEPC_LAPTOP)     += eeepc-laptop.o
 obj-$(CONFIG_EEEPC_WMI)                += eeepc-wmi.o
 
+# Cisco/Meraki
+obj-$(CONFIG_MERAKI_MX100)     += meraki-mx100.o
+
 # Dell
 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)                += dell/
 
drivers/platform/x86/meraki-mx100.c new file +171 -0
new file mode 100644
index 000000000000..eebbd0a3d806
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Cisco Meraki MX100 (Tinkerbell) board platform driver
+ *
+ * Based off of arch/x86/platform/meraki/tink.c from the
+ * Meraki GPL release meraki-firmware-sources-r23-20150601
+ *
+ * Format inspired by platform/x86/pcengines-apuv2.c
+ *
+ * Copyright (C) 2021 Chris Blake <[email protected]>
+ */
+
+#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
+
+#include <linux/dmi.h>
+#include <linux/err.h>
+#include <linux/gpio_keys.h>
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#define TINK_GPIO_DRIVER_NAME "gpio_ich"
+
+/* LEDs */
+static const struct gpio_led tink_leds[] = {
+       {
+               .name = "mx100:green:internet",
+               .default_trigger = "default-on",
+       },
+       {
+               .name = "mx100:green:lan2",
+       },
+       {
+               .name = "mx100:green:lan3",
+       },
+       {
+               .name = "mx100:green:lan4",
+       },
+       {
+               .name = "mx100:green:lan5",
+       },
+       {
+               .name = "mx100:green:lan6",
+       },
+       {
+               .name = "mx100:green:lan7",
+       },
+       {
+               .name = "mx100:green:lan8",
+       },
+       {
+               .name = "mx100:green:lan9",
+       },
+       {
+               .name = "mx100:green:lan10",
+       },
+       {
+               .name = "mx100:green:lan11",
+       },
+};
+
+static const struct gpio_led_platform_data tink_leds_pdata = {
+       .num_leds       = ARRAY_SIZE(tink_leds),
+       .leds           = tink_leds,
+};
+
+static struct gpiod_lookup_table tink_leds_table = {
+       .dev_id = "leds-gpio",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
+                               NULL, 1, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
+                               NULL, 2, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
+                               NULL, 3, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
+                               NULL, 4, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
+                               NULL, 5, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
+                               NULL, 6, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
+                               NULL, 7, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
+                               NULL, 8, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
+                               NULL, 9, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
+                               NULL, 10, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
+                               NULL, 11, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
+                               NULL, 12, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
+                               NULL, 13, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
+                               NULL, 14, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Reset Button */
+static struct gpio_keys_button tink_buttons[] = {
+       {
+               .desc                   = "Reset",
+               .type                   = EV_KEY,
+               .code                   = KEY_RESTART,
+               .active_low             = 1,
+               .debounce_interval      = 100,
+       },
+};
+
+static const struct gpio_keys_platform_data tink_buttons_pdata = {
+       .buttons        = tink_buttons,
+       .nbuttons       = ARRAY_SIZE(tink_buttons),
+       .poll_interval  = 20,
+       .rep            = 0,
+       .name           = "mx100-keys",
+};
+
+static struct gpiod_lookup_table tink_keys_table = {
+       .dev_id = "gpio-keys-polled",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Board setup */
+static const struct dmi_system_id tink_systems[] __initconst = {
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
+               },
+       },
+       {} /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(dmi, tink_systems);
+
+static struct platform_device *tink_leds_pdev;
+static struct platform_device *tink_keys_pdev;
+
+static struct platform_device * __init tink_create_dev(
+       const char *name, const void *pdata, size_t sz)
+{
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL,
+               name, PLATFORM_DEVID_NONE, pdata, sz);
+       if (IS_ERR(pdev))
+               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+       return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+       if (!dmi_first_match(tink_systems))
+               return -ENODEV;
+
+       /*
+        * We need to make sure that GPIO60 isn't set to native mode as is default since it's our

drivers/platform/x86/meraki-mx100.c line 181

Quoted 10 lines
drivers/platform/x86/meraki-mx100.c new file +10 -0
+        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+        */
+       outl(inl(0x530) | BIT(28), 0x530);
+
+       gpiod_add_lookup_table(&tink_leds_table);
+       gpiod_add_lookup_table(&tink_keys_table);
+
+       tink_leds_pdev = tink_create_dev("leds-gpio",
+               &tink_leds_pdata, sizeof(tink_leds_pdata));

Seems you forgot to add
if (IS_ERR())
return PTR_ERR();

here...

drivers/platform/x86/meraki-mx100.c line 184

Quoted 2 lines
drivers/platform/x86/meraki-mx100.c new file +2 -0
+       tink_keys_pdev = tink_create_dev("gpio-keys-polled",
+               &tink_buttons_pdata, sizeof(tink_buttons_pdata));

and

if (IS_ERR()) {
pdev_unreg();
return PTR_ERR();
}

here.

Quoted 20 lines
drivers/platform/x86/meraki-mx100.c new file +17 -1
+       return 0;
+}
+module_init(tink_board_init);
+
+static void __exit tink_board_exit(void)
+{
+       platform_device_unregister(tink_keys_pdev);
+       platform_device_unregister(tink_leds_pdev);
+       gpiod_remove_lookup_table(&tink_keys_table);
+       gpiod_remove_lookup_table(&tink_leds_table);
+}
+module_exit(tink_board_exit);
+
+MODULE_AUTHOR("Chris Blake <[email protected]>");
+MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:meraki-mx100");
--

2.25.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#4 lore raw
Quoted 263 lines · Andy Shevchenko
Quoted 4 lines · Chris Blake

This adds platform support for the Cisco Meraki MX100 (Tinkerbell) network appliance. This sets up the network LEDs and Reset button.

Almost good to me, see below for some comments. After addressing them

Quoted 232 lines

Depends-on: ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")

---

Changelog:
V3: Additional cleanups, formatting changes
V2: Move to using gpiod lookup tables, misc cleanups
V1: Initial Patch

 drivers/platform/x86/Kconfig        |  13 ++
 drivers/platform/x86/Makefile       |   3 +
 drivers/platform/x86/meraki-mx100.c | 202 ++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/platform/x86/meraki-mx100.c
drivers/platform/x86/Kconfig +13 -0
index 7d385c3b2239..8d70176e335f 100644
@@ -302,6 +302,19 @@ config ASUS_NB_WMI
          If you have an ACPI-WMI compatible Asus Notebook, say Y or M
          here.
 
+config MERAKI_MX100
+       tristate "Cisco Meraki MX100 Platform Driver"
+       depends on GPIOLIB
+       depends on GPIO_ICH
+       depends on LEDS_CLASS
+       select LEDS_GPIO
+       help
+         This driver provides support for the front button and LEDs on
+         the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
+
+         To compile this driver as a module, choose M here: the module
+         will be called meraki-mx100.
+
 config EEEPC_LAPTOP
        tristate "Eee PC Hotkey Driver"
        depends on ACPI
drivers/platform/x86/Makefile +3 -0
index 7ee369aab10d..25c5aee1cde7 100644
@@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)     += asus-nb-wmi.o
 obj-$(CONFIG_EEEPC_LAPTOP)     += eeepc-laptop.o
 obj-$(CONFIG_EEEPC_WMI)                += eeepc-wmi.o
 
+# Cisco/Meraki
+obj-$(CONFIG_MERAKI_MX100)     += meraki-mx100.o
+
 # Dell
 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)                += dell/
 
drivers/platform/x86/meraki-mx100.c new file +171 -0
new file mode 100644
index 000000000000..eebbd0a3d806
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Cisco Meraki MX100 (Tinkerbell) board platform driver
+ *
+ * Based off of arch/x86/platform/meraki/tink.c from the
+ * Meraki GPL release meraki-firmware-sources-r23-20150601
+ *
+ * Format inspired by platform/x86/pcengines-apuv2.c
+ *
+ * Copyright (C) 2021 Chris Blake <[email protected]>
+ */
+
+#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
+
+#include <linux/dmi.h>
+#include <linux/err.h>
+#include <linux/gpio_keys.h>
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#define TINK_GPIO_DRIVER_NAME "gpio_ich"
+
+/* LEDs */
+static const struct gpio_led tink_leds[] = {
+       {
+               .name = "mx100:green:internet",
+               .default_trigger = "default-on",
+       },
+       {
+               .name = "mx100:green:lan2",
+       },
+       {
+               .name = "mx100:green:lan3",
+       },
+       {
+               .name = "mx100:green:lan4",
+       },
+       {
+               .name = "mx100:green:lan5",
+       },
+       {
+               .name = "mx100:green:lan6",
+       },
+       {
+               .name = "mx100:green:lan7",
+       },
+       {
+               .name = "mx100:green:lan8",
+       },
+       {
+               .name = "mx100:green:lan9",
+       },
+       {
+               .name = "mx100:green:lan10",
+       },
+       {
+               .name = "mx100:green:lan11",
+       },
+};
+
+static const struct gpio_led_platform_data tink_leds_pdata = {
+       .num_leds       = ARRAY_SIZE(tink_leds),
+       .leds           = tink_leds,
+};
+
+static struct gpiod_lookup_table tink_leds_table = {
+       .dev_id = "leds-gpio",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
+                               NULL, 1, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
+                               NULL, 2, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
+                               NULL, 3, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
+                               NULL, 4, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
+                               NULL, 5, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
+                               NULL, 6, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
+                               NULL, 7, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
+                               NULL, 8, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
+                               NULL, 9, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
+                               NULL, 10, GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
+                               NULL, 11, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
+                               NULL, 12, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
+                               NULL, 13, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
+                               NULL, 14, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Reset Button */
+static struct gpio_keys_button tink_buttons[] = {
+       {
+               .desc                   = "Reset",
+               .type                   = EV_KEY,
+               .code                   = KEY_RESTART,
+               .active_low             = 1,
+               .debounce_interval      = 100,
+       },
+};
+
+static const struct gpio_keys_platform_data tink_buttons_pdata = {
+       .buttons        = tink_buttons,
+       .nbuttons       = ARRAY_SIZE(tink_buttons),
+       .poll_interval  = 20,
+       .rep            = 0,
+       .name           = "mx100-keys",
+};
+
+static struct gpiod_lookup_table tink_keys_table = {
+       .dev_id = "gpio-keys-polled",
+       .table = {
+               GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
+                               NULL, 0, GPIO_ACTIVE_LOW),
+               {} /* Terminating entry */
+       }
+};
+
+/* Board setup */
+static const struct dmi_system_id tink_systems[] __initconst = {
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
+               },
+       },
+       {} /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(dmi, tink_systems);
+
+static struct platform_device *tink_leds_pdev;
+static struct platform_device *tink_keys_pdev;
+
+static struct platform_device * __init tink_create_dev(
+       const char *name, const void *pdata, size_t sz)
+{
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL,
+               name, PLATFORM_DEVID_NONE, pdata, sz);
+       if (IS_ERR(pdev))
+               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+       return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+       if (!dmi_first_match(tink_systems))
+               return -ENODEV;
+
+       /*
+        * We need to make sure that GPIO60 isn't set to native mode as is default since it's our

drivers/platform/x86/meraki-mx100.c line 181

Quoted 10 lines
drivers/platform/x86/meraki-mx100.c new file +10 -0
+        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+        */
+       outl(inl(0x530) | BIT(28), 0x530);
+
+       gpiod_add_lookup_table(&tink_leds_table);
+       gpiod_add_lookup_table(&tink_keys_table);
+
+       tink_leds_pdev = tink_create_dev("leds-gpio",
+               &tink_leds_pdata, sizeof(tink_leds_pdata));

Seems you forgot to add
if (IS_ERR())
return PTR_ERR();

here...

drivers/platform/x86/meraki-mx100.c line 184

Quoted 2 lines
drivers/platform/x86/meraki-mx100.c new file +2 -0
+       tink_keys_pdev = tink_create_dev("gpio-keys-polled",
+               &tink_buttons_pdata, sizeof(tink_buttons_pdata));
Quoted 9 lines

and

if (IS_ERR()) {
pdev_unreg();
return PTR_ERR();
}

here.

Are these IS_ERR catches needed since they are done in the tink_create_dev struct? This is the same structure as currently done in drivers/platform/x86/pcengines-apuv2.c. Adding these 2x additions feels a bit redundant, but if I am wrong please correct me.

Quoted 25 lines
Quoted 18 lines
drivers/platform/x86/meraki-mx100.c new file +17 -1
+       return 0;
+}
+module_init(tink_board_init);
+
+static void __exit tink_board_exit(void)
+{
+       platform_device_unregister(tink_keys_pdev);
+       platform_device_unregister(tink_leds_pdev);
+       gpiod_remove_lookup_table(&tink_keys_table);
+       gpiod_remove_lookup_table(&tink_leds_table);
+}
+module_exit(tink_board_exit);
+
+MODULE_AUTHOR("Chris Blake <[email protected]>");
+MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:meraki-mx100");
--
Quoted 2 lines

2.25.1

--
With Best Regards,
Andy Shevchenko

#5 lore raw
Quoted 3 lines · Chris
Quoted 1 line · Andy Shevchenko

On Mon, Aug 9, 2021 at 3:13 PM Chris Blake <[email protected]> wrote:

(I left below context on purpose)

Quoted 47 lines
Quoted 47 lines
Quoted 20 lines
drivers/platform/x86/meraki-mx100.c new file +20 -0
+static struct platform_device * __init tink_create_dev(
+       const char *name, const void *pdata, size_t sz)
+{
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL,
+               name, PLATFORM_DEVID_NONE, pdata, sz);
+       if (IS_ERR(pdev))
+               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+       return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+       if (!dmi_first_match(tink_systems))
+               return -ENODEV;
+
+       /*
+        * We need to make sure that GPIO60 isn't set to native mode as is default since it's our

drivers/platform/x86/meraki-mx100.c line 181

Quoted 10 lines
drivers/platform/x86/meraki-mx100.c new file +10 -0
+        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+        */
+       outl(inl(0x530) | BIT(28), 0x530);
+
+       gpiod_add_lookup_table(&tink_leds_table);
+       gpiod_add_lookup_table(&tink_keys_table);
+
+       tink_leds_pdev = tink_create_dev("leds-gpio",
+               &tink_leds_pdata, sizeof(tink_leds_pdata));

Seems you forgot to add
if (IS_ERR())
return PTR_ERR();

here...

drivers/platform/x86/meraki-mx100.c line 184

Quoted 2 lines
drivers/platform/x86/meraki-mx100.c new file +2 -0
+       tink_keys_pdev = tink_create_dev("gpio-keys-polled",
+               &tink_buttons_pdata, sizeof(tink_buttons_pdata));

and

if (IS_ERR()) {
pdev_unreg();
return PTR_ERR();
}

Quoted 6 lines
Quoted 1 line

here.

Are these IS_ERR catches needed since they are done in the tink_create_dev struct? This is the same structure as currently done in drivers/platform/x86/pcengines-apuv2.c. Adding these 2x additions feels a bit redundant, but if I am wrong please correct me.

Care to describe how it's supposed to be taken into account in your opinion?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+       return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw
Quoted 55 lines · Andy Shevchenko
Quoted 3 lines · Chris
Quoted 1 line · Andy Shevchenko

On Mon, Aug 9, 2021 at 3:13 PM Chris Blake <[email protected]> wrote:

(I left below context on purpose)

Quoted 47 lines
Quoted 47 lines
Quoted 20 lines
drivers/platform/x86/meraki-mx100.c new file +20 -0
+static struct platform_device * __init tink_create_dev(
+       const char *name, const void *pdata, size_t sz)
+{
+       struct platform_device *pdev;
+
+       pdev = platform_device_register_data(NULL,
+               name, PLATFORM_DEVID_NONE, pdata, sz);
+       if (IS_ERR(pdev))
+               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+       return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+       if (!dmi_first_match(tink_systems))
+               return -ENODEV;
+
+       /*
+        * We need to make sure that GPIO60 isn't set to native mode as is default since it's our

drivers/platform/x86/meraki-mx100.c line 181

Quoted 10 lines
drivers/platform/x86/meraki-mx100.c new file +10 -0
+        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+        */
+       outl(inl(0x530) | BIT(28), 0x530);
+
+       gpiod_add_lookup_table(&tink_leds_table);
+       gpiod_add_lookup_table(&tink_keys_table);
+
+       tink_leds_pdev = tink_create_dev("leds-gpio",
+               &tink_leds_pdata, sizeof(tink_leds_pdata));

Seems you forgot to add
if (IS_ERR())
return PTR_ERR();

here...

drivers/platform/x86/meraki-mx100.c line 184

Quoted 2 lines
drivers/platform/x86/meraki-mx100.c new file +2 -0
+       tink_keys_pdev = tink_create_dev("gpio-keys-polled",
+               &tink_buttons_pdata, sizeof(tink_buttons_pdata));

and

if (IS_ERR()) {
pdev_unreg();
return PTR_ERR();
}

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

here.

Are these IS_ERR catches needed since they are done in the tink_create_dev struct? This is the same structure as currently done in drivers/platform/x86/pcengines-apuv2.c. Adding these 2x additions feels a bit redundant, but if I am wrong please correct me.

Care to describe how it's supposed to be taken into account in your opinion?

I don't mind adding those blocks in, I am just trying to understand the benefit. In tink_create_dev() we do if (IS_ERR(pdev)) right after platform_device_register_data is called, so I am just curious why we would add another if (IS_ERR()) conditional after the 2x calls to tink_create_dev(). I don't have a ton of work in the kernel, so knowing why this was requested will help me improve any future PRs.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+       return 0;
+}

--
With Best Regards,
Andy Shevchenko

author
#7 lore raw

Hello,

After some digging I understand why Andy requested the change he did, so I will have a variant of it included in the V4 patch.

Regards,
Chris B