ath25: switch default kernel to 5.15
[openwrt/staging/ldir.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 --- a/drivers/platform/x86/Kconfig
26 +++ b/drivers/platform/x86/Kconfig
27 @@ -267,6 +267,19 @@ config ASUS_NB_WMI
28 If you have an ACPI-WMI compatible Asus Notebook, say Y or M
29 here.
30
31 +config MERAKI_MX100
32 + tristate "Cisco Meraki MX100 Platform Driver"
33 + depends on GPIOLIB
34 + depends on GPIO_ICH
35 + depends on LEDS_CLASS
36 + select LEDS_GPIO
37 + help
38 + This driver provides support for the front button and LEDs on
39 + the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
40 +
41 + To compile this driver as a module, choose M here: the module
42 + will be called meraki-mx100.
43 +
44 config EEEPC_LAPTOP
45 tristate "Eee PC Hotkey Driver"
46 depends on ACPI
47 --- a/drivers/platform/x86/Makefile
48 +++ b/drivers/platform/x86/Makefile
49 @@ -33,6 +33,9 @@ obj-$(CONFIG_ASUS_NB_WMI) += asus-nb-wmi
50 obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o
51 obj-$(CONFIG_EEEPC_WMI) += eeepc-wmi.o
52
53 +# Cisco/Meraki
54 +obj-$(CONFIG_MERAKI_MX100) += meraki-mx100.o
55 +
56 # Dell
57 obj-$(CONFIG_DCDBAS) += dcdbas.o
58 obj-$(CONFIG_DELL_SMBIOS) += dell-smbios.o
59 --- /dev/null
60 +++ b/drivers/platform/x86/meraki-mx100.c
61 @@ -0,0 +1,230 @@
62 +// SPDX-License-Identifier: GPL-2.0+
63 +
64 +/*
65 + * Cisco Meraki MX100 (Tinkerbell) board platform driver
66 + *
67 + * Based off of arch/x86/platform/meraki/tink.c from the
68 + * Meraki GPL release meraki-firmware-sources-r23-20150601
69 + *
70 + * Format inspired by platform/x86/pcengines-apuv2.c
71 + *
72 + * Copyright (C) 2021 Chris Blake <chrisrblake93@gmail.com>
73 + */
74 +
75 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
76 +
77 +#include <linux/dmi.h>
78 +#include <linux/err.h>
79 +#include <linux/gpio_keys.h>
80 +#include <linux/gpio/machine.h>
81 +#include <linux/input.h>
82 +#include <linux/io.h>
83 +#include <linux/kernel.h>
84 +#include <linux/leds.h>
85 +#include <linux/module.h>
86 +#include <linux/platform_device.h>
87 +
88 +#define TINK_GPIO_DRIVER_NAME "gpio_ich"
89 +
90 +/* LEDs */
91 +static const struct gpio_led tink_leds[] = {
92 + {
93 + .name = "mx100:green:internet",
94 + .default_trigger = "default-on",
95 + },
96 + {
97 + .name = "mx100:green:lan2",
98 + },
99 + {
100 + .name = "mx100:green:lan3",
101 + },
102 + {
103 + .name = "mx100:green:lan4",
104 + },
105 + {
106 + .name = "mx100:green:lan5",
107 + },
108 + {
109 + .name = "mx100:green:lan6",
110 + },
111 + {
112 + .name = "mx100:green:lan7",
113 + },
114 + {
115 + .name = "mx100:green:lan8",
116 + },
117 + {
118 + .name = "mx100:green:lan9",
119 + },
120 + {
121 + .name = "mx100:green:lan10",
122 + },
123 + {
124 + .name = "mx100:green:lan11",
125 + },
126 + {
127 + .name = "mx100:green:ha",
128 + },
129 + {
130 + .name = "mx100:orange:ha",
131 + },
132 + {
133 + .name = "mx100:green:usb",
134 + },
135 + {
136 + .name = "mx100:orange:usb",
137 + },
138 +};
139 +
140 +static const struct gpio_led_platform_data tink_leds_pdata = {
141 + .num_leds = ARRAY_SIZE(tink_leds),
142 + .leds = tink_leds,
143 +};
144 +
145 +static struct gpiod_lookup_table tink_leds_table = {
146 + .dev_id = "leds-gpio",
147 + .table = {
148 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
149 + NULL, 0, GPIO_ACTIVE_LOW),
150 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
151 + NULL, 1, GPIO_ACTIVE_HIGH),
152 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
153 + NULL, 2, GPIO_ACTIVE_HIGH),
154 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
155 + NULL, 3, GPIO_ACTIVE_HIGH),
156 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
157 + NULL, 4, GPIO_ACTIVE_HIGH),
158 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
159 + NULL, 5, GPIO_ACTIVE_HIGH),
160 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
161 + NULL, 6, GPIO_ACTIVE_HIGH),
162 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
163 + NULL, 7, GPIO_ACTIVE_HIGH),
164 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
165 + NULL, 8, GPIO_ACTIVE_HIGH),
166 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
167 + NULL, 9, GPIO_ACTIVE_HIGH),
168 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
169 + NULL, 10, GPIO_ACTIVE_HIGH),
170 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
171 + NULL, 11, GPIO_ACTIVE_LOW),
172 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
173 + NULL, 12, GPIO_ACTIVE_LOW),
174 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
175 + NULL, 13, GPIO_ACTIVE_LOW),
176 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
177 + NULL, 14, GPIO_ACTIVE_LOW),
178 + {} /* Terminating entry */
179 + }
180 +};
181 +
182 +/* Reset Button */
183 +static struct gpio_keys_button tink_buttons[] = {
184 + {
185 + .desc = "Reset",
186 + .type = EV_KEY,
187 + .code = KEY_RESTART,
188 + .active_low = 1,
189 + .debounce_interval = 100,
190 + },
191 +};
192 +
193 +static const struct gpio_keys_platform_data tink_buttons_pdata = {
194 + .buttons = tink_buttons,
195 + .nbuttons = ARRAY_SIZE(tink_buttons),
196 + .poll_interval = 20,
197 + .rep = 0,
198 + .name = "mx100-keys",
199 +};
200 +
201 +static struct gpiod_lookup_table tink_keys_table = {
202 + .dev_id = "gpio-keys-polled",
203 + .table = {
204 + GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
205 + NULL, 0, GPIO_ACTIVE_LOW),
206 + {} /* Terminating entry */
207 + }
208 +};
209 +
210 +/* Board setup */
211 +static const struct dmi_system_id tink_systems[] __initconst = {
212 + {
213 + .matches = {
214 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
215 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
216 + },
217 + },
218 + {} /* Terminating entry */
219 +};
220 +MODULE_DEVICE_TABLE(dmi, tink_systems);
221 +
222 +static struct platform_device *tink_leds_pdev;
223 +static struct platform_device *tink_keys_pdev;
224 +
225 +static struct platform_device * __init tink_create_dev(
226 + const char *name, const void *pdata, size_t sz)
227 +{
228 + struct platform_device *pdev;
229 +
230 + pdev = platform_device_register_data(NULL,
231 + name, PLATFORM_DEVID_NONE, pdata, sz);
232 + if (IS_ERR(pdev))
233 + pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
234 +
235 + return pdev;
236 +}
237 +
238 +static int __init tink_board_init(void)
239 +{
240 + int ret;
241 +
242 + if (!dmi_first_match(tink_systems))
243 + return -ENODEV;
244 +
245 + /*
246 + * We need to make sure that GPIO60 isn't set to native mode as is default since it's our
247 + * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
248 + * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
249 + */
250 + outl(inl(0x530) | BIT(28), 0x530);
251 +
252 + gpiod_add_lookup_table(&tink_leds_table);
253 + gpiod_add_lookup_table(&tink_keys_table);
254 +
255 + tink_leds_pdev = tink_create_dev("leds-gpio",
256 + &tink_leds_pdata, sizeof(tink_leds_pdata));
257 + if (IS_ERR(tink_leds_pdev)) {
258 + ret = PTR_ERR(tink_leds_pdev);
259 + goto err;
260 + }
261 +
262 + tink_keys_pdev = tink_create_dev("gpio-keys-polled",
263 + &tink_buttons_pdata, sizeof(tink_buttons_pdata));
264 + if (IS_ERR(tink_keys_pdev)) {
265 + ret = PTR_ERR(tink_keys_pdev);
266 + platform_device_unregister(tink_leds_pdev);
267 + goto err;
268 + }
269 +
270 + return 0;
271 +
272 +err:
273 + gpiod_remove_lookup_table(&tink_keys_table);
274 + gpiod_remove_lookup_table(&tink_leds_table);
275 + return ret;
276 +}
277 +module_init(tink_board_init);
278 +
279 +static void __exit tink_board_exit(void)
280 +{
281 + platform_device_unregister(tink_keys_pdev);
282 + platform_device_unregister(tink_leds_pdev);
283 + gpiod_remove_lookup_table(&tink_keys_table);
284 + gpiod_remove_lookup_table(&tink_leds_table);
285 +}
286 +module_exit(tink_board_exit);
287 +
288 +MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
289 +MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
290 +MODULE_LICENSE("GPL");
291 +MODULE_ALIAS("platform:meraki-mx100");