1 From 636a1e697555e73c28cdd6952a409edbfdd16475 Mon Sep 17 00:00:00 2001
2 From: Chris Blake <chrisrblake93@gmail.com>
3 Date: Mon, 9 Aug 2021 19:40:21 -0500
4 Subject: platform/x86: add meraki-mx100 platform driver
6 This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
7 network appliance. This sets up the network LEDs and Reset
10 Depends-on: ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")
11 Co-developed-by: Christian Lamparter <chunkeey@gmail.com>
12 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
13 Signed-off-by: Chris Blake <chrisrblake93@gmail.com>
14 Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
15 Link: https://lore.kernel.org/r/20210810004021.2538308-1-chrisrblake93@gmail.com
16 Reviewed-by: Hans de Goede <hdegoede@redhat.com>
17 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
19 drivers/platform/x86/Kconfig | 13 ++
20 drivers/platform/x86/Makefile | 3 +
21 drivers/platform/x86/meraki-mx100.c | 230 ++++++++++++++++++++++++++++++++++++
22 3 files changed, 246 insertions(+)
23 create mode 100644 drivers/platform/x86/meraki-mx100.c
25 diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
26 index 6ad35158ae4ef..432d72170b003 100644
27 --- a/drivers/platform/x86/Kconfig
28 +++ b/drivers/platform/x86/Kconfig
29 @@ -302,6 +302,19 @@ config ASUS_NB_WMI
30 If you have an ACPI-WMI compatible Asus Notebook, say Y or M
34 + tristate "Cisco Meraki MX100 Platform Driver"
37 + depends on LEDS_CLASS
40 + This driver provides support for the front button and LEDs on
41 + the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
43 + To compile this driver as a module, choose M here: the module
44 + will be called meraki-mx100.
47 tristate "Eee PC Hotkey Driver"
49 diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
50 index 5edfdc2ea7f29..9bb3c3f773864 100644
51 --- a/drivers/platform/x86/Makefile
52 +++ b/drivers/platform/x86/Makefile
53 @@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI) += asus-nb-wmi.o
54 obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o
55 obj-$(CONFIG_EEEPC_WMI) += eeepc-wmi.o
58 +obj-$(CONFIG_MERAKI_MX100) += meraki-mx100.o
61 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL) += dell/
63 diff --git a/drivers/platform/x86/meraki-mx100.c b/drivers/platform/x86/meraki-mx100.c
65 index 0000000000000..3751ed36a980a
67 +++ b/drivers/platform/x86/meraki-mx100.c
69 +// SPDX-License-Identifier: GPL-2.0+
72 + * Cisco Meraki MX100 (Tinkerbell) board platform driver
74 + * Based off of arch/x86/platform/meraki/tink.c from the
75 + * Meraki GPL release meraki-firmware-sources-r23-20150601
77 + * Format inspired by platform/x86/pcengines-apuv2.c
79 + * Copyright (C) 2021 Chris Blake <chrisrblake93@gmail.com>
82 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
84 +#include <linux/dmi.h>
85 +#include <linux/err.h>
86 +#include <linux/gpio_keys.h>
87 +#include <linux/gpio/machine.h>
88 +#include <linux/input.h>
89 +#include <linux/io.h>
90 +#include <linux/kernel.h>
91 +#include <linux/leds.h>
92 +#include <linux/module.h>
93 +#include <linux/platform_device.h>
95 +#define TINK_GPIO_DRIVER_NAME "gpio_ich"
98 +static const struct gpio_led tink_leds[] = {
100 + .name = "mx100:green:internet",
101 + .default_trigger = "default-on",
104 + .name = "mx100:green:lan2",
107 + .name = "mx100:green:lan3",
110 + .name = "mx100:green:lan4",
113 + .name = "mx100:green:lan5",
116 + .name = "mx100:green:lan6",
119 + .name = "mx100:green:lan7",
122 + .name = "mx100:green:lan8",
125 + .name = "mx100:green:lan9",
128 + .name = "mx100:green:lan10",
131 + .name = "mx100:green:lan11",
134 + .name = "mx100:green:ha",
137 + .name = "mx100:orange:ha",
140 + .name = "mx100:green:usb",
143 + .name = "mx100:orange:usb",
147 +static const struct gpio_led_platform_data tink_leds_pdata = {
148 + .num_leds = ARRAY_SIZE(tink_leds),
152 +static struct gpiod_lookup_table tink_leds_table = {
153 + .dev_id = "leds-gpio",
155 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
156 + NULL, 0, GPIO_ACTIVE_LOW),
157 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
158 + NULL, 1, GPIO_ACTIVE_HIGH),
159 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
160 + NULL, 2, GPIO_ACTIVE_HIGH),
161 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
162 + NULL, 3, GPIO_ACTIVE_HIGH),
163 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
164 + NULL, 4, GPIO_ACTIVE_HIGH),
165 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
166 + NULL, 5, GPIO_ACTIVE_HIGH),
167 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
168 + NULL, 6, GPIO_ACTIVE_HIGH),
169 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
170 + NULL, 7, GPIO_ACTIVE_HIGH),
171 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
172 + NULL, 8, GPIO_ACTIVE_HIGH),
173 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
174 + NULL, 9, GPIO_ACTIVE_HIGH),
175 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
176 + NULL, 10, GPIO_ACTIVE_HIGH),
177 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
178 + NULL, 11, GPIO_ACTIVE_LOW),
179 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
180 + NULL, 12, GPIO_ACTIVE_LOW),
181 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
182 + NULL, 13, GPIO_ACTIVE_LOW),
183 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
184 + NULL, 14, GPIO_ACTIVE_LOW),
185 + {} /* Terminating entry */
190 +static struct gpio_keys_button tink_buttons[] = {
194 + .code = KEY_RESTART,
196 + .debounce_interval = 100,
200 +static const struct gpio_keys_platform_data tink_buttons_pdata = {
201 + .buttons = tink_buttons,
202 + .nbuttons = ARRAY_SIZE(tink_buttons),
203 + .poll_interval = 20,
205 + .name = "mx100-keys",
208 +static struct gpiod_lookup_table tink_keys_table = {
209 + .dev_id = "gpio-keys-polled",
211 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
212 + NULL, 0, GPIO_ACTIVE_LOW),
213 + {} /* Terminating entry */
218 +static const struct dmi_system_id tink_systems[] __initconst = {
221 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
222 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
225 + {} /* Terminating entry */
227 +MODULE_DEVICE_TABLE(dmi, tink_systems);
229 +static struct platform_device *tink_leds_pdev;
230 +static struct platform_device *tink_keys_pdev;
232 +static struct platform_device * __init tink_create_dev(
233 + const char *name, const void *pdata, size_t sz)
235 + struct platform_device *pdev;
237 + pdev = platform_device_register_data(NULL,
238 + name, PLATFORM_DEVID_NONE, pdata, sz);
240 + pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
245 +static int __init tink_board_init(void)
249 + if (!dmi_first_match(tink_systems))
253 + * We need to make sure that GPIO60 isn't set to native mode as is default since it's our
254 + * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
255 + * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
257 + outl(inl(0x530) | BIT(28), 0x530);
259 + gpiod_add_lookup_table(&tink_leds_table);
260 + gpiod_add_lookup_table(&tink_keys_table);
262 + tink_leds_pdev = tink_create_dev("leds-gpio",
263 + &tink_leds_pdata, sizeof(tink_leds_pdata));
264 + if (IS_ERR(tink_leds_pdev)) {
265 + ret = PTR_ERR(tink_leds_pdev);
269 + tink_keys_pdev = tink_create_dev("gpio-keys-polled",
270 + &tink_buttons_pdata, sizeof(tink_buttons_pdata));
271 + if (IS_ERR(tink_keys_pdev)) {
272 + ret = PTR_ERR(tink_keys_pdev);
273 + platform_device_unregister(tink_leds_pdev);
280 + gpiod_remove_lookup_table(&tink_keys_table);
281 + gpiod_remove_lookup_table(&tink_leds_table);
284 +module_init(tink_board_init);
286 +static void __exit tink_board_exit(void)
288 + platform_device_unregister(tink_keys_pdev);
289 + platform_device_unregister(tink_leds_pdev);
290 + gpiod_remove_lookup_table(&tink_keys_table);
291 + gpiod_remove_lookup_table(&tink_leds_table);
293 +module_exit(tink_board_exit);
295 +MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
296 +MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
297 +MODULE_LICENSE("GPL");
298 +MODULE_ALIAS("platform:meraki-mx100");