103-pcengines_apu6_platform.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. From 970d9af9015a387bb81841faf05dcc1a171eb97a Mon Sep 17 00:00:00 2001
  2. From: Philip Prindeville <[email protected]>
  3. Date: Sun, 1 Jan 2023 15:25:04 -0700
  4. Subject: [PATCH v3 1/1] x86: Support APU5 in PCEngines platform driver
  5. To: [email protected], [email protected]
  6. Cc: Ed Wildgoose <[email protected]>, Andres Salomon <[email protected]>, Andreas Eberlein <[email protected]>, Paul Spooren <[email protected]>
  7. PCEngines make a number of SBC. APU5 has 5 mpcie slots + MSATA.
  8. It also has support for 3x LTE modems with 6x SIM slots (pairs with a
  9. SIM switch device). Each mpcie slot for modems has a reset GPIO
  10. To ensure that the naming is sane between APU2-6 the GPIOS are
  11. renamed to be modem1-reset, modem2-reset, etc. This is significant
  12. because the slots that can be reset change between APU2 and APU3/4
  13. GPIO for simswap is moved to the end of the list as it could be dropped
  14. for APU2 boards (but causes no harm to leave it in, hardware could be
  15. added to a future rev of the board).
  16. Structure of the GPIOs for APU5 is extremely similar to APU2-4, but
  17. many lines are moved around and there are simply more
  18. modems/resets/sim-swap lines to breakout.
  19. Also added APU6, which is essentially APU4 with a different ethernet
  20. interface and SFP cage on eth0.
  21. Revision history:
  22. v1: originally titled, "apu6: add apu6 variation to apu2 driver family"
  23. this dealt only with detecting the APUv6, which is otherwise identical
  24. to the v4 excepting the SFP cage on eth0.
  25. v2: at Ed's request, merged with his previous pull-request titled
  26. "x86: Support APU5 in PCEngines platform driver", and some cleanup
  27. to that changeset (including dropping the table "apu5_driver_data"
  28. which did not have a defined type "struct apu_driver_data"), but got
  29. mistitled when the Subject of that commit got accidentally dropped.
  30. v3: retitled to match Ed's previous pull-request.
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Reviewed-by: Andreas Eberlein <[email protected]>
  34. Reviewed-by: Paul Spooren <[email protected]>
  35. Signed-off-by: Ed Wildgoose <[email protected]>
  36. Sighed-off-by: Philip Prindeville <[email protected]>
  37. ---
  38. drivers/leds/leds-apu.c | 2 +-
  39. drivers/platform/x86/Kconfig | 4 +-
  40. drivers/platform/x86/pcengines-apuv2.c | 118 ++++++++++++++++++++++---
  41. 3 files changed, 107 insertions(+), 17 deletions(-)
  42. --- a/drivers/leds/leds-apu.c
  43. +++ b/drivers/leds/leds-apu.c
  44. @@ -183,7 +183,7 @@ static int __init apu_led_init(void)
  45. if (!(dmi_match(DMI_SYS_VENDOR, "PC Engines") &&
  46. (dmi_match(DMI_PRODUCT_NAME, "APU") || dmi_match(DMI_PRODUCT_NAME, "apu1")))) {
  47. - pr_err("No PC Engines APUv1 board detected. For APUv2,3 support, enable CONFIG_PCENGINES_APU2\n");
  48. + pr_err("No PC Engines APUv1 board detected. For APUv2,3,4,5,6 support, enable CONFIG_PCENGINES_APU2\n");
  49. return -ENODEV;
  50. }
  51. --- a/drivers/platform/x86/Kconfig
  52. +++ b/drivers/platform/x86/Kconfig
  53. @@ -698,7 +698,7 @@ config XO1_RFKILL
  54. laptop.
  55. config PCENGINES_APU2
  56. - tristate "PC Engines APUv2/3 front button and LEDs driver"
  57. + tristate "PC Engines APUv2/3/4/5/6 front button and LEDs driver"
  58. depends on INPUT && INPUT_KEYBOARD && GPIOLIB
  59. depends on LEDS_CLASS
  60. select GPIO_AMD_FCH
  61. @@ -706,7 +706,7 @@ config PCENGINES_APU2
  62. select LEDS_GPIO
  63. help
  64. This driver provides support for the front button and LEDs on
  65. - PC Engines APUv2/APUv3 board.
  66. + PC Engines APUv2/APUv3/APUv4/APUv5/APUv6 board.
  67. To compile this driver as a module, choose M here: the module
  68. will be called pcengines-apuv2.
  69. --- a/drivers/platform/x86/pcengines-apuv2.c
  70. +++ b/drivers/platform/x86/pcengines-apuv2.c
  71. @@ -1,10 +1,12 @@
  72. // SPDX-License-Identifier: GPL-2.0+
  73. /*
  74. - * PC-Engines APUv2/APUv3 board platform driver
  75. + * PC-Engines APUv2-6 board platform driver
  76. * for GPIO buttons and LEDs
  77. *
  78. * Copyright (C) 2018 metux IT consult
  79. + * Copyright (C) 2022 Ed Wildgoose <[email protected]>
  80. + * Copyright (C) 2022 Philip Prindeville <[email protected]>
  81. * Author: Enrico Weigelt <[email protected]>
  82. */
  83. @@ -22,38 +24,70 @@
  84. #include <linux/platform_data/gpio/gpio-amd-fch.h>
  85. /*
  86. - * NOTE: this driver only supports APUv2/3 - not APUv1, as this one
  87. + * NOTE: this driver only supports APUv2-6 - not APUv1, as this one
  88. * has completely different register layouts.
  89. */
  90. +/*
  91. + * There are a number of APU variants, with differing features
  92. + * APU2 has SIM slots 1/2 mapping to mPCIe sockets 1/2
  93. + * APU3/4 moved SIM slot 1 to mPCIe socket 3, ie logically reversed
  94. + * However, most APU3/4 have a SIM switch which we default on to reverse
  95. + * the order and keep physical SIM order matching physical modem order
  96. + * APU6 is approximately the same as APU4 with different ethernet layout
  97. + *
  98. + * APU5 has 3x SIM sockets, all with a SIM switch
  99. + * several GPIOs are shuffled (see schematic), including MODESW
  100. + */
  101. +
  102. /* Register mappings */
  103. #define APU2_GPIO_REG_LED1 AMD_FCH_GPIO_REG_GPIO57
  104. #define APU2_GPIO_REG_LED2 AMD_FCH_GPIO_REG_GPIO58
  105. #define APU2_GPIO_REG_LED3 AMD_FCH_GPIO_REG_GPIO59_DEVSLP1
  106. #define APU2_GPIO_REG_MODESW AMD_FCH_GPIO_REG_GPIO32_GE1
  107. #define APU2_GPIO_REG_SIMSWAP AMD_FCH_GPIO_REG_GPIO33_GE2
  108. -#define APU2_GPIO_REG_MPCIE2 AMD_FCH_GPIO_REG_GPIO55_DEVSLP0
  109. -#define APU2_GPIO_REG_MPCIE3 AMD_FCH_GPIO_REG_GPIO51
  110. +#define APU2_GPIO_REG_RESETM1 AMD_FCH_GPIO_REG_GPIO51
  111. +#define APU2_GPIO_REG_RESETM2 AMD_FCH_GPIO_REG_GPIO55_DEVSLP0
  112. +
  113. +#define APU5_GPIO_REG_MODESW AMT_FCH_GPIO_REG_GEVT22
  114. +#define APU5_GPIO_REG_SIMSWAP1 AMD_FCH_GPIO_REG_GPIO68
  115. +#define APU5_GPIO_REG_SIMSWAP2 AMD_FCH_GPIO_REG_GPIO32_GE1
  116. +#define APU5_GPIO_REG_SIMSWAP3 AMD_FCH_GPIO_REG_GPIO33_GE2
  117. +#define APU5_GPIO_REG_RESETM1 AMD_FCH_GPIO_REG_GPIO51
  118. +#define APU5_GPIO_REG_RESETM2 AMD_FCH_GPIO_REG_GPIO55_DEVSLP0
  119. +#define APU5_GPIO_REG_RESETM3 AMD_FCH_GPIO_REG_GPIO64
  120. /* Order in which the GPIO lines are defined in the register list */
  121. #define APU2_GPIO_LINE_LED1 0
  122. #define APU2_GPIO_LINE_LED2 1
  123. #define APU2_GPIO_LINE_LED3 2
  124. #define APU2_GPIO_LINE_MODESW 3
  125. -#define APU2_GPIO_LINE_SIMSWAP 4
  126. -#define APU2_GPIO_LINE_MPCIE2 5
  127. -#define APU2_GPIO_LINE_MPCIE3 6
  128. +#define APU2_GPIO_LINE_RESETM1 4
  129. +#define APU2_GPIO_LINE_RESETM2 5
  130. +#define APU2_GPIO_LINE_SIMSWAP 6
  131. +
  132. +#define APU5_GPIO_LINE_LED1 0
  133. +#define APU5_GPIO_LINE_LED2 1
  134. +#define APU5_GPIO_LINE_LED3 2
  135. +#define APU5_GPIO_LINE_MODESW 3
  136. +#define APU5_GPIO_LINE_RESETM1 4
  137. +#define APU5_GPIO_LINE_RESETM2 5
  138. +#define APU5_GPIO_LINE_RESETM3 6
  139. +#define APU5_GPIO_LINE_SIMSWAP1 7
  140. +#define APU5_GPIO_LINE_SIMSWAP2 8
  141. +#define APU5_GPIO_LINE_SIMSWAP3 9
  142. +
  143. -/* GPIO device */
  144. +/* GPIO device - APU2/3/4/6 */
  145. static int apu2_gpio_regs[] = {
  146. [APU2_GPIO_LINE_LED1] = APU2_GPIO_REG_LED1,
  147. [APU2_GPIO_LINE_LED2] = APU2_GPIO_REG_LED2,
  148. [APU2_GPIO_LINE_LED3] = APU2_GPIO_REG_LED3,
  149. [APU2_GPIO_LINE_MODESW] = APU2_GPIO_REG_MODESW,
  150. + [APU2_GPIO_LINE_RESETM1] = APU2_GPIO_REG_RESETM1,
  151. + [APU2_GPIO_LINE_RESETM2] = APU2_GPIO_REG_RESETM2,
  152. [APU2_GPIO_LINE_SIMSWAP] = APU2_GPIO_REG_SIMSWAP,
  153. - [APU2_GPIO_LINE_MPCIE2] = APU2_GPIO_REG_MPCIE2,
  154. - [APU2_GPIO_LINE_MPCIE3] = APU2_GPIO_REG_MPCIE3,
  155. };
  156. static const char * const apu2_gpio_names[] = {
  157. @@ -61,9 +95,9 @@ static const char * const apu2_gpio_name
  158. [APU2_GPIO_LINE_LED2] = "front-led2",
  159. [APU2_GPIO_LINE_LED3] = "front-led3",
  160. [APU2_GPIO_LINE_MODESW] = "front-button",
  161. + [APU2_GPIO_LINE_RESETM1] = "modem1-reset",
  162. + [APU2_GPIO_LINE_RESETM2] = "modem2-reset",
  163. [APU2_GPIO_LINE_SIMSWAP] = "simswap",
  164. - [APU2_GPIO_LINE_MPCIE2] = "mpcie2_reset",
  165. - [APU2_GPIO_LINE_MPCIE3] = "mpcie3_reset",
  166. };
  167. static const struct amd_fch_gpio_pdata board_apu2 = {
  168. @@ -72,6 +106,40 @@ static const struct amd_fch_gpio_pdata b
  169. .gpio_names = apu2_gpio_names,
  170. };
  171. +/* GPIO device - APU5 */
  172. +
  173. +static int apu5_gpio_regs[] = {
  174. + [APU5_GPIO_LINE_LED1] = APU2_GPIO_REG_LED1,
  175. + [APU5_GPIO_LINE_LED2] = APU2_GPIO_REG_LED2,
  176. + [APU5_GPIO_LINE_LED3] = APU2_GPIO_REG_LED3,
  177. + [APU5_GPIO_LINE_MODESW] = APU5_GPIO_REG_MODESW,
  178. + [APU5_GPIO_LINE_RESETM1] = APU5_GPIO_REG_RESETM1,
  179. + [APU5_GPIO_LINE_RESETM2] = APU5_GPIO_REG_RESETM2,
  180. + [APU5_GPIO_LINE_RESETM3] = APU5_GPIO_REG_RESETM3,
  181. + [APU5_GPIO_LINE_SIMSWAP1] = APU5_GPIO_REG_SIMSWAP1,
  182. + [APU5_GPIO_LINE_SIMSWAP2] = APU5_GPIO_REG_SIMSWAP2,
  183. + [APU5_GPIO_LINE_SIMSWAP3] = APU5_GPIO_REG_SIMSWAP3,
  184. +};
  185. +
  186. +static const char * const apu5_gpio_names[] = {
  187. + [APU5_GPIO_LINE_LED1] = "front-led1",
  188. + [APU5_GPIO_LINE_LED2] = "front-led2",
  189. + [APU5_GPIO_LINE_LED3] = "front-led3",
  190. + [APU5_GPIO_LINE_MODESW] = "front-button",
  191. + [APU5_GPIO_LINE_RESETM1] = "modem1-reset",
  192. + [APU5_GPIO_LINE_RESETM2] = "modem2-reset",
  193. + [APU5_GPIO_LINE_RESETM3] = "modem3-reset",
  194. + [APU5_GPIO_LINE_SIMSWAP1] = "simswap1",
  195. + [APU5_GPIO_LINE_SIMSWAP2] = "simswap2",
  196. + [APU5_GPIO_LINE_SIMSWAP3] = "simswap3",
  197. +};
  198. +
  199. +static const struct amd_fch_gpio_pdata board_apu5 = {
  200. + .gpio_num = ARRAY_SIZE(apu5_gpio_regs),
  201. + .gpio_reg = apu5_gpio_regs,
  202. + .gpio_names = apu5_gpio_names,
  203. +};
  204. +
  205. /* GPIO LEDs device */
  206. static const struct gpio_led apu2_leds[] = {
  207. @@ -215,6 +283,24 @@ static const struct dmi_system_id apu_gp
  208. },
  209. .driver_data = (void *)&board_apu2,
  210. },
  211. + /* APU5 w/ mainline BIOS */
  212. + {
  213. + .ident = "apu5",
  214. + .matches = {
  215. + DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"),
  216. + DMI_MATCH(DMI_BOARD_NAME, "apu5")
  217. + },
  218. + .driver_data = (void *)&board_apu5,
  219. + },
  220. + /* APU6 w/ mainline BIOS */
  221. + {
  222. + .ident = "apu6",
  223. + .matches = {
  224. + DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"),
  225. + DMI_MATCH(DMI_BOARD_NAME, "apu6")
  226. + },
  227. + .driver_data = (void *)&board_apu2,
  228. + },
  229. {}
  230. };
  231. @@ -249,7 +335,7 @@ static int __init apu_board_init(void)
  232. id = dmi_first_match(apu_gpio_dmi_table);
  233. if (!id) {
  234. - pr_err("failed to detect APU board via DMI\n");
  235. + pr_err("No APU board detected via DMI\n");
  236. return -ENODEV;
  237. }
  238. @@ -288,8 +374,12 @@ module_init(apu_board_init);
  239. module_exit(apu_board_exit);
  240. MODULE_AUTHOR("Enrico Weigelt, metux IT consult <[email protected]>");
  241. -MODULE_DESCRIPTION("PC Engines APUv2/APUv3 board GPIO/LEDs/keys driver");
  242. +MODULE_DESCRIPTION("PC Engines APUv2-6 board GPIO/LEDs/keys driver");
  243. MODULE_LICENSE("GPL");
  244. MODULE_DEVICE_TABLE(dmi, apu_gpio_dmi_table);
  245. MODULE_ALIAS("platform:pcengines-apuv2");
  246. +MODULE_ALIAS("platform:pcengines-apuv3");
  247. +MODULE_ALIAS("platform:pcengines-apuv4");
  248. +MODULE_ALIAS("platform:pcengines-apuv5");
  249. +MODULE_ALIAS("platform:pcengines-apuv6");
  250. MODULE_SOFTDEP("pre: platform:" AMD_FCH_GPIO_DRIVER_NAME " platform:leds-gpio platform:gpio_keys_polled");