1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
// 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 <chrisrblake93@gmail.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/dmi.h>
#include <linux/err.h>
#include <linux/gpio/machine.h>
#include <linux/gpio/property.h>
#include <linux/input-event-codes.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#define TINK_GPIO_DRIVER_NAME "gpio_ich"
static const struct software_node gpio_ich_node = {
.name = TINK_GPIO_DRIVER_NAME,
};
/* LEDs */
static const struct software_node tink_gpio_leds_node = {
.name = "meraki-mx100-leds",
};
static const struct property_entry tink_internet_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:internet"),
PROPERTY_ENTRY_STRING("linux,default-trigger", "default-on"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 11, GPIO_ACTIVE_LOW),
{ }
};
static const struct software_node tink_internet_led_node = {
.name = "internet-led",
.parent = &tink_gpio_leds_node,
.properties = tink_internet_led_props,
};
static const struct property_entry tink_lan2_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan2"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 18, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan2_led_node = {
.name = "lan2-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan2_led_props,
};
static const struct property_entry tink_lan3_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan3"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 20, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan3_led_node = {
.name = "lan3-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan3_led_props,
};
static const struct property_entry tink_lan4_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan4"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 22, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan4_led_node = {
.name = "lan4-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan4_led_props,
};
static const struct property_entry tink_lan5_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan5"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 23, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan5_led_node = {
.name = "lan5-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan5_led_props,
};
static const struct property_entry tink_lan6_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan6"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 32, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan6_led_node = {
.name = "lan6-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan6_led_props,
};
static const struct property_entry tink_lan7_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan7"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 34, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan7_led_node = {
.name = "lan7-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan7_led_props,
};
static const struct property_entry tink_lan8_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan8"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 35, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan8_led_node = {
.name = "lan8-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan8_led_props,
};
static const struct property_entry tink_lan9_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan9"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 36, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan9_led_node = {
.name = "lan9-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan9_led_props,
};
static const struct property_entry tink_lan10_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan10"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 37, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan10_led_node = {
.name = "lan10-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan10_led_props,
};
static const struct property_entry tink_lan11_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:lan11"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 48, GPIO_ACTIVE_HIGH),
{ }
};
static const struct software_node tink_lan11_led_node = {
.name = "lan11-led",
.parent = &tink_gpio_leds_node,
.properties = tink_lan11_led_props,
};
static const struct property_entry tink_ha_green_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:ha"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 16, GPIO_ACTIVE_LOW),
{ }
};
static const struct software_node tink_ha_green_led_node = {
.name = "ha-green-led",
.parent = &tink_gpio_leds_node,
.properties = tink_ha_green_led_props,
};
static const struct property_entry tink_ha_orange_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:orange:ha"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 7, GPIO_ACTIVE_LOW),
{ }
};
static const struct software_node tink_ha_orange_led_node = {
.name = "ha-orange-led",
.parent = &tink_gpio_leds_node,
.properties = tink_ha_orange_led_props,
};
static const struct property_entry tink_usb_green_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:green:usb"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 21, GPIO_ACTIVE_LOW),
{ }
};
static const struct software_node tink_usb_green_led_node = {
.name = "usb-green-led",
.parent = &tink_gpio_leds_node,
.properties = tink_usb_green_led_props,
};
static const struct property_entry tink_usb_orange_led_props[] = {
PROPERTY_ENTRY_STRING("label", "mx100:orange:usb"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 19, GPIO_ACTIVE_LOW),
{ }
};
static const struct software_node tink_usb_orange_led_node = {
.name = "usb-orange-led",
.parent = &tink_gpio_leds_node,
.properties = tink_usb_orange_led_props,
};
/* Reset Button */
static const struct property_entry tink_gpio_keys_props[] = {
PROPERTY_ENTRY_U32("poll-interval", 20),
{ }
};
static const struct software_node tink_gpio_keys_node = {
.name = "mx100-keys",
.properties = tink_gpio_keys_props,
};
static const struct property_entry tink_reset_key_props[] = {
PROPERTY_ENTRY_U32("linux,code", KEY_RESTART),
PROPERTY_ENTRY_STRING("label", "Reset"),
PROPERTY_ENTRY_GPIO("gpios", &gpio_ich_node, 60, GPIO_ACTIVE_LOW),
PROPERTY_ENTRY_U32("linux,input-type", EV_KEY),
PROPERTY_ENTRY_U32("debounce-interval", 100),
{ }
};
static const struct software_node tink_reset_key_node = {
.name = "reset",
.parent = &tink_gpio_keys_node,
.properties = tink_reset_key_props,
};
static const struct software_node *tink_swnodes[] = {
&gpio_ich_node,
/* LEDs nodes */
&tink_gpio_leds_node,
&tink_internet_led_node,
&tink_lan2_led_node,
&tink_lan3_led_node,
&tink_lan4_led_node,
&tink_lan5_led_node,
&tink_lan6_led_node,
&tink_lan7_led_node,
&tink_lan8_led_node,
&tink_lan9_led_node,
&tink_lan10_led_node,
&tink_lan11_led_node,
&tink_ha_green_led_node,
&tink_ha_orange_led_node,
&tink_usb_green_led_node,
&tink_usb_orange_led_node,
/* Keys nodes */
&tink_gpio_keys_node,
&tink_reset_key_node,
NULL
};
/* 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 int __init tink_board_init(void)
{
struct platform_device_info keys_info = {
.name = "gpio-keys-polled",
.id = PLATFORM_DEVID_NONE,
};
struct platform_device_info leds_info = {
.name = "leds-gpio",
.id = PLATFORM_DEVID_NONE,
};
int err;
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);
err = software_node_register_node_group(tink_swnodes);
if (err) {
pr_err("failed to register software nodes: %d\n", err);
return err;
}
leds_info.fwnode = software_node_fwnode(&tink_gpio_leds_node);
tink_leds_pdev = platform_device_register_full(&leds_info);
if (IS_ERR(tink_leds_pdev)) {
err = PTR_ERR(tink_leds_pdev);
pr_err("failed to create LED device: %d\n", err);
goto err_unregister_swnodes;
}
keys_info.fwnode = software_node_fwnode(&tink_gpio_keys_node);
tink_keys_pdev = platform_device_register_full(&keys_info);
if (IS_ERR(tink_keys_pdev)) {
err = PTR_ERR(tink_keys_pdev);
pr_err("failed to create key device: %d\n", err);
goto err_unregister_leds;
}
return 0;
err_unregister_leds:
platform_device_unregister(tink_leds_pdev);
err_unregister_swnodes:
software_node_unregister_node_group(tink_swnodes);
return err;
}
module_init(tink_board_init);
static void __exit tink_board_exit(void)
{
platform_device_unregister(tink_keys_pdev);
platform_device_unregister(tink_leds_pdev);
software_node_unregister_node_group(tink_swnodes);
}
module_exit(tink_board_exit);
MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:meraki-mx100");
|