x86: add support for Meraki MX100
[openwrt/staging/jow.git] / target / linux / x86 / patches-5.10 / 102-v5.15-platform-x86-add-meraki-mx100-platform-driver.patch
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
5
6 This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
7 network appliance. This sets up the network LEDs and Reset
8 button.
9
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>
18 ---
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
24
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
31 here.
32
33 +config MERAKI_MX100
34 + tristate "Cisco Meraki MX100 Platform Driver"
35 + depends on GPIOLIB
36 + depends on GPIO_ICH
37 + depends on LEDS_CLASS
38 + select LEDS_GPIO
39 + help
40 + This driver provides support for the front button and LEDs on
41 + the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
42 +
43 + To compile this driver as a module, choose M here: the module
44 + will be called meraki-mx100.
45 +
46 config EEEPC_LAPTOP
47 tristate "Eee PC Hotkey Driver"
48 depends on ACPI
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
56
57 +# Cisco/Meraki
58 +obj-$(CONFIG_MERAKI_MX100) += meraki-mx100.o
59 +
60 # Dell
61 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL) += dell/
62
63 diff --git a/drivers/platform/x86/meraki-mx100.c b/drivers/platform/x86/meraki-mx100.c
64 new file mode 100644
65 index 0000000000000..3751ed36a980a
66 --- /dev/null
67 +++ b/drivers/platform/x86/meraki-mx100.c
68 @@ -0,0 +1,230 @@
69 +// SPDX-License-Identifier: GPL-2.0+
70 +
71 +/*
72 + * Cisco Meraki MX100 (Tinkerbell) board platform driver
73 + *
74 + * Based off of arch/x86/platform/meraki/tink.c from the
75 + * Meraki GPL release meraki-firmware-sources-r23-20150601
76 + *
77 + * Format inspired by platform/x86/pcengines-apuv2.c
78 + *
79 + * Copyright (C) 2021 Chris Blake <chrisrblake93@gmail.com>
80 + */
81 +
82 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
83 +
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>
94 +
95 +#define TINK_GPIO_DRIVER_NAME "gpio_ich"
96 +
97 +/* LEDs */
98 +static const struct gpio_led tink_leds[] = {
99 + {
100 + .name = "mx100:green:internet",
101 + .default_trigger = "default-on",
102 + },
103 + {
104 + .name = "mx100:green:lan2",
105 + },
106 + {
107 + .name = "mx100:green:lan3",
108 + },
109 + {
110 + .name = "mx100:green:lan4",
111 + },
112 + {
113 + .name = "mx100:green:lan5",
114 + },
115 + {
116 + .name = "mx100:green:lan6",
117 + },
118 + {
119 + .name = "mx100:green:lan7",
120 + },
121 + {
122 + .name = "mx100:green:lan8",
123 + },
124 + {
125 + .name = "mx100:green:lan9",
126 + },
127 + {
128 + .name = "mx100:green:lan10",
129 + },
130 + {
131 + .name = "mx100:green:lan11",
132 + },
133 + {
134 + .name = "mx100:green:ha",
135 + },
136 + {
137 + .name = "mx100:orange:ha",
138 + },
139 + {
140 + .name = "mx100:green:usb",
141 + },
142 + {
143 + .name = "mx100:orange:usb",
144 + },
145 +};
146 +
147 +static const struct gpio_led_platform_data tink_leds_pdata = {
148 + .num_leds = ARRAY_SIZE(tink_leds),
149 + .leds = tink_leds,
150 +};
151 +
152 +static struct gpiod_lookup_table tink_leds_table = {
153 + .dev_id = "leds-gpio",
154 + .table = {
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 */
186 + }
187 +};
188 +
189 +/* Reset Button */
190 +static struct gpio_keys_button tink_buttons[] = {
191 + {
192 + .desc = "Reset",
193 + .type = EV_KEY,
194 + .code = KEY_RESTART,
195 + .active_low = 1,
196 + .debounce_interval = 100,
197 + },
198 +};
199 +
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,
204 + .rep = 0,
205 + .name = "mx100-keys",
206 +};
207 +
208 +static struct gpiod_lookup_table tink_keys_table = {
209 + .dev_id = "gpio-keys-polled",
210 + .table = {
211 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
212 + NULL, 0, GPIO_ACTIVE_LOW),
213 + {} /* Terminating entry */
214 + }
215 +};
216 +
217 +/* Board setup */
218 +static const struct dmi_system_id tink_systems[] __initconst = {
219 + {
220 + .matches = {
221 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
222 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
223 + },
224 + },
225 + {} /* Terminating entry */
226 +};
227 +MODULE_DEVICE_TABLE(dmi, tink_systems);
228 +
229 +static struct platform_device *tink_leds_pdev;
230 +static struct platform_device *tink_keys_pdev;
231 +
232 +static struct platform_device * __init tink_create_dev(
233 + const char *name, const void *pdata, size_t sz)
234 +{
235 + struct platform_device *pdev;
236 +
237 + pdev = platform_device_register_data(NULL,
238 + name, PLATFORM_DEVID_NONE, pdata, sz);
239 + if (IS_ERR(pdev))
240 + pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
241 +
242 + return pdev;
243 +}
244 +
245 +static int __init tink_board_init(void)
246 +{
247 + int ret;
248 +
249 + if (!dmi_first_match(tink_systems))
250 + return -ENODEV;
251 +
252 + /*
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
256 + */
257 + outl(inl(0x530) | BIT(28), 0x530);
258 +
259 + gpiod_add_lookup_table(&tink_leds_table);
260 + gpiod_add_lookup_table(&tink_keys_table);
261 +
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);
266 + goto err;
267 + }
268 +
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);
274 + goto err;
275 + }
276 +
277 + return 0;
278 +
279 +err:
280 + gpiod_remove_lookup_table(&tink_keys_table);
281 + gpiod_remove_lookup_table(&tink_leds_table);
282 + return ret;
283 +}
284 +module_init(tink_board_init);
285 +
286 +static void __exit tink_board_exit(void)
287 +{
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);
292 +}
293 +module_exit(tink_board_exit);
294 +
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");
299 --
300 cgit 1.2.3-1.el7