102-v5.15-platform-x86-add-meraki-mx100-platform-driver.patch 7.8 KB

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