mach-rbspi.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * MikroTik SPI-NOR RouterBOARDs support
  3. *
  4. * - MikroTik RouterBOARD mAP 2nD
  5. * - MikroTik RouterBOARD mAP L-2nD
  6. * - MikroTik RouterBOARD 911-2Hn (911 Lite2)
  7. * - MikroTik RouterBOARD 911-5Hn (911 Lite5)
  8. * - MikroTik RouterBOARD 931-2nD (hAP mini)
  9. * - MikroTik RouterBOARD 941L-2nD
  10. * - MikroTik RouterBOARD 951Ui-2nD
  11. * - MikroTik RouterBOARD 952Ui-5ac2nD
  12. * - MikroTik RouterBOARD 962UiGS-5HacT2HnT
  13. * - MikroTik RouterBOARD 750UP r2
  14. * - MikroTik RouterBOARD 750P-PBr2
  15. * - MikroTik RouterBOARD 750 r2
  16. * - MikroTik RouterBOARD LHG 5nD
  17. * - MikroTik RouterBOARD wAP2nD
  18. * - MikroTik RouterBOARD wAP G-5HacT2HnDwAP (wAP AC)
  19. * - MikroTik RouterBOARD wAP R-2nD
  20. *
  21. * Preliminary support for the following hardware
  22. * - MikroTik RouterBOARD cAP2nD
  23. * Furthermore, the cAP lite (cAPL2nD) appears to feature the exact same
  24. * hardware as the mAP L-2nD. It is unknown if they share the same board
  25. * identifier.
  26. *
  27. * Copyright (C) 2017-2018 Thibaut VARENE <varenet@parisc-linux.org>
  28. * Copyright (C) 2016 David Hutchison <dhutchison@bluemesh.net>
  29. * Copyright (C) 2017 Ryan Mounce <ryan@mounce.com.au>
  30. *
  31. * This program is free software; you can redistribute it and/or modify it
  32. * under the terms of the GNU General Public License version 2 as published
  33. * by the Free Software Foundation.
  34. */
  35. #include <linux/pci.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/phy.h>
  38. #include <linux/routerboot.h>
  39. #include <linux/gpio.h>
  40. #include <linux/spi/spi.h>
  41. #include <linux/spi/74x164.h>
  42. #include <linux/mtd/mtd.h>
  43. #include <linux/mtd/partitions.h>
  44. #include <linux/ar8216_platform.h>
  45. #include <linux/platform_data/phy-at803x.h>
  46. #include <linux/platform_data/mdio-gpio.h>
  47. #include <asm/prom.h>
  48. #include <asm/mach-ath79/ar71xx_regs.h>
  49. #include <asm/mach-ath79/ath79.h>
  50. #include "common.h"
  51. #include "dev-eth.h"
  52. #include "dev-spi.h"
  53. #include "dev-gpio-buttons.h"
  54. #include "dev-leds-gpio.h"
  55. #include "dev-m25p80.h"
  56. #include "dev-usb.h"
  57. #include "dev-wmac.h"
  58. #include "machtypes.h"
  59. #include "pci.h"
  60. #include "routerboot.h"
  61. #define RBSPI_KEYS_POLL_INTERVAL 20 /* msecs */
  62. #define RBSPI_KEYS_DEBOUNCE_INTERVAL (3 * RBSPI_KEYS_POLL_INTERVAL)
  63. #define RBSPI_HAS_USB BIT(0)
  64. #define RBSPI_HAS_WLAN0 BIT(1)
  65. #define RBSPI_HAS_WLAN1 BIT(2)
  66. #define RBSPI_HAS_WAN4 BIT(3) /* has WAN port on PHY4 */
  67. #define RBSPI_HAS_SSR BIT(4) /* has an SSR on SPI bus 0 */
  68. #define RBSPI_HAS_POE BIT(5)
  69. #define RBSPI_HAS_MDIO1 BIT(6)
  70. #define RBSPI_HAS_PCI BIT(7)
  71. #define RB_ROUTERBOOT_OFFSET 0x0000
  72. #define RB_BIOS_SIZE 0x1000
  73. #define RB_SOFT_CFG_SIZE 0x1000
  74. /* Flash partitions indexes */
  75. enum {
  76. RBSPI_PART_RBOOT,
  77. RBSPI_PART_HCONF,
  78. RBSPI_PART_BIOS,
  79. RBSPI_PART_RBOOT2,
  80. RBSPI_PART_SCONF,
  81. RBSPI_PART_FIRMW,
  82. RBSPI_PARTS
  83. };
  84. static struct mtd_partition rbspi_spi_partitions[RBSPI_PARTS];
  85. /*
  86. * Setup the SPI flash partition table based on initial parsing.
  87. * The kernel can be at any aligned position and have any size.
  88. */
  89. static void __init rbspi_init_partitions(const struct rb_info *info)
  90. {
  91. struct mtd_partition *parts = rbspi_spi_partitions;
  92. memset(parts, 0x0, sizeof(*parts));
  93. parts[RBSPI_PART_RBOOT].name = "routerboot";
  94. parts[RBSPI_PART_RBOOT].offset = RB_ROUTERBOOT_OFFSET;
  95. parts[RBSPI_PART_RBOOT].size = info->hard_cfg_offs;
  96. parts[RBSPI_PART_RBOOT].mask_flags = MTD_WRITEABLE;
  97. parts[RBSPI_PART_HCONF].name = "hard_config";
  98. parts[RBSPI_PART_HCONF].offset = info->hard_cfg_offs;
  99. parts[RBSPI_PART_HCONF].size = info->hard_cfg_size;
  100. parts[RBSPI_PART_HCONF].mask_flags = MTD_WRITEABLE;
  101. parts[RBSPI_PART_BIOS].name = "bios";
  102. parts[RBSPI_PART_BIOS].offset = info->hard_cfg_offs
  103. + info->hard_cfg_size;
  104. parts[RBSPI_PART_BIOS].size = RB_BIOS_SIZE;
  105. parts[RBSPI_PART_BIOS].mask_flags = MTD_WRITEABLE;
  106. parts[RBSPI_PART_RBOOT2].name = "routerboot2";
  107. parts[RBSPI_PART_RBOOT2].offset = parts[RBSPI_PART_BIOS].offset
  108. + RB_BIOS_SIZE;
  109. parts[RBSPI_PART_RBOOT2].size = info->soft_cfg_offs
  110. - parts[RBSPI_PART_RBOOT2].offset;
  111. parts[RBSPI_PART_RBOOT2].mask_flags = MTD_WRITEABLE;
  112. parts[RBSPI_PART_SCONF].name = "soft_config";
  113. parts[RBSPI_PART_SCONF].offset = info->soft_cfg_offs;
  114. parts[RBSPI_PART_SCONF].size = RB_SOFT_CFG_SIZE;
  115. parts[RBSPI_PART_FIRMW].name = "firmware";
  116. parts[RBSPI_PART_FIRMW].offset = parts[RBSPI_PART_SCONF].offset
  117. + parts[RBSPI_PART_SCONF].size;
  118. parts[RBSPI_PART_FIRMW].size = MTDPART_SIZ_FULL;
  119. }
  120. static struct flash_platform_data rbspi_spi_flash_data = {
  121. .parts = rbspi_spi_partitions,
  122. .nr_parts = ARRAY_SIZE(rbspi_spi_partitions),
  123. };
  124. /*
  125. * Several boards only have a single reset button, use a common
  126. * structure for that.
  127. */
  128. static struct gpio_keys_button rbspi_gpio_keys_reset[] __initdata = {
  129. {
  130. .desc = "Reset button",
  131. .type = EV_KEY,
  132. .code = KEY_RESTART,
  133. .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
  134. .gpio = -ENOENT, /* filled dynamically */
  135. .active_low = 1,
  136. },
  137. };
  138. /* RB mAP L-2nD gpios */
  139. #define RBMAPL_GPIO_LED_POWER 17
  140. #define RBMAPL_GPIO_LED_USER 14
  141. #define RBMAPL_GPIO_LED_ETH 4
  142. #define RBMAPL_GPIO_LED_WLAN 11
  143. #define RBMAPL_GPIO_BTN_RESET 16
  144. static struct gpio_led rbmapl_leds[] __initdata = {
  145. {
  146. .name = "rb:green:power",
  147. .gpio = RBMAPL_GPIO_LED_POWER,
  148. .active_low = 0,
  149. .default_state = LEDS_GPIO_DEFSTATE_ON,
  150. }, {
  151. .name = "rb:green:user",
  152. .gpio = RBMAPL_GPIO_LED_USER,
  153. .active_low = 0,
  154. }, {
  155. .name = "rb:green:eth",
  156. .gpio = RBMAPL_GPIO_LED_ETH,
  157. .active_low = 0,
  158. }, {
  159. .name = "rb:green:wlan",
  160. .gpio = RBMAPL_GPIO_LED_WLAN,
  161. .active_low = 0,
  162. },
  163. };
  164. /* RB 941L-2nD gpios */
  165. #define RBHAPL_GPIO_LED_USER 14
  166. #define RBHAPL_GPIO_BTN_RESET 16
  167. static struct gpio_led rbhapl_leds[] __initdata = {
  168. {
  169. .name = "rb:green:user",
  170. .gpio = RBHAPL_GPIO_LED_USER,
  171. .active_low = 1,
  172. },
  173. };
  174. /* common RB SSRs */
  175. #define RBSPI_SSR_GPIO_BASE 40
  176. #define RBSPI_SSR_GPIO(bit) (RBSPI_SSR_GPIO_BASE + (bit))
  177. /* RB 951Ui-2nD gpios */
  178. #define RB952_SSR_BIT_LED_LAN1 0
  179. #define RB952_SSR_BIT_LED_LAN2 1
  180. #define RB952_SSR_BIT_LED_LAN3 2
  181. #define RB952_SSR_BIT_LED_LAN4 3
  182. #define RB952_SSR_BIT_LED_LAN5 4
  183. #define RB952_SSR_BIT_USB_POWER 5
  184. #define RB952_SSR_BIT_LED_WLAN 6
  185. #define RB952_GPIO_SSR_CS 11
  186. #define RB952_GPIO_LED_USER 4
  187. #define RB952_GPIO_POE_POWER 14
  188. #define RB952_GPIO_POE_STATUS 12
  189. #define RB952_GPIO_BTN_RESET 16
  190. #define RB952_GPIO_USB_PWROFF RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER)
  191. #define RB952_GPIO_LED_LAN1 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN1)
  192. #define RB952_GPIO_LED_LAN2 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN2)
  193. #define RB952_GPIO_LED_LAN3 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN3)
  194. #define RB952_GPIO_LED_LAN4 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN4)
  195. #define RB952_GPIO_LED_LAN5 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN5)
  196. #define RB952_GPIO_LED_WLAN RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_WLAN)
  197. static struct gpio_led rb952_leds[] __initdata = {
  198. {
  199. .name = "rb:green:user",
  200. .gpio = RB952_GPIO_LED_USER,
  201. .active_low = 0,
  202. }, {
  203. .name = "rb:blue:wlan",
  204. .gpio = RB952_GPIO_LED_WLAN,
  205. .active_low = 1,
  206. }, {
  207. .name = "rb:green:port1",
  208. .gpio = RB952_GPIO_LED_LAN1,
  209. .active_low = 1,
  210. }, {
  211. .name = "rb:green:port2",
  212. .gpio = RB952_GPIO_LED_LAN2,
  213. .active_low = 1,
  214. }, {
  215. .name = "rb:green:port3",
  216. .gpio = RB952_GPIO_LED_LAN3,
  217. .active_low = 1,
  218. }, {
  219. .name = "rb:green:port4",
  220. .gpio = RB952_GPIO_LED_LAN4,
  221. .active_low = 1,
  222. }, {
  223. .name = "rb:green:port5",
  224. .gpio = RB952_GPIO_LED_LAN5,
  225. .active_low = 1,
  226. },
  227. };
  228. /* RB 962UiGS-5HacT2HnT gpios */
  229. #define RB962_WIFI_LED_1 1
  230. #define RB962_WIFI_LED_2 2
  231. #define RB962_GPIO_POE_STATUS 2
  232. #define RB962_GPIO_POE_POWER 3
  233. #define RB962_GPIO_LED_USER 12
  234. #define RB962_GPIO_USB_PWROFF 13
  235. #define RB962_GPIO_BTN_RESET 20
  236. static struct gpio_led rb962_leds_gpio[] __initdata = {
  237. {
  238. .name = "rb:green:user",
  239. .gpio = RB962_GPIO_LED_USER,
  240. .active_low = 1,
  241. },
  242. };
  243. static const struct ar8327_led_info rb962_leds_ar8327[] = {
  244. AR8327_LED_INFO(PHY0_0, HW, "rb:green:port1"),
  245. AR8327_LED_INFO(PHY1_0, HW, "rb:green:port2"),
  246. AR8327_LED_INFO(PHY2_0, HW, "rb:green:port3"),
  247. AR8327_LED_INFO(PHY3_0, HW, "rb:green:port4"),
  248. AR8327_LED_INFO(PHY4_0, HW, "rb:green:port5"),
  249. };
  250. static struct ar8327_pad_cfg rb962_ar8327_pad0_cfg = {
  251. .mode = AR8327_PAD_MAC_RGMII,
  252. .txclk_delay_en = true,
  253. .rxclk_delay_en = true,
  254. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  255. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  256. .mac06_exchange_dis = true,
  257. };
  258. static struct ar8327_pad_cfg rb962_ar8327_pad6_cfg = {
  259. /* Use SGMII interface for GMAC6 of the AR8337 switch */
  260. .mode = AR8327_PAD_MAC_SGMII,
  261. .rxclk_delay_en = true,
  262. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
  263. };
  264. static struct ar8327_led_cfg rb962_ar8327_led_cfg = {
  265. .led_ctrl0 = 0xc737c737,
  266. .led_ctrl1 = 0x00000000,
  267. .led_ctrl2 = 0x00000000,
  268. .led_ctrl3 = 0x0030c300,
  269. .open_drain = false,
  270. };
  271. static struct ar8327_platform_data rb962_ar8327_data = {
  272. .pad0_cfg = &rb962_ar8327_pad0_cfg,
  273. .pad6_cfg = &rb962_ar8327_pad6_cfg,
  274. .port0_cfg = {
  275. .force_link = 1,
  276. .speed = AR8327_PORT_SPEED_1000,
  277. .duplex = 1,
  278. .txpause = 1,
  279. .rxpause = 1,
  280. },
  281. .port6_cfg = {
  282. .force_link = 1,
  283. .speed = AR8327_PORT_SPEED_1000,
  284. .duplex = 1,
  285. .txpause = 1,
  286. .rxpause = 1,
  287. },
  288. .led_cfg = &rb962_ar8327_led_cfg,
  289. .num_leds = ARRAY_SIZE(rb962_leds_ar8327),
  290. .leds = rb962_leds_ar8327,
  291. };
  292. static struct mdio_board_info rb962_mdio0_info[] = {
  293. {
  294. .bus_id = "ag71xx-mdio.0",
  295. .mdio_addr = 0,
  296. .platform_data = &rb962_ar8327_data,
  297. },
  298. };
  299. /* RB wAP-2nD gpios */
  300. #define RBWAP_GPIO_LED_USER 14
  301. #define RBWAP_GPIO_LED_WLAN 11
  302. #define RBWAP_GPIO_BTN_RESET 16
  303. static struct gpio_led rbwap_leds[] __initdata = {
  304. {
  305. .name = "rb:green:user",
  306. .gpio = RBWAP_GPIO_LED_USER,
  307. .active_low = 1,
  308. }, {
  309. .name = "rb:green:wlan",
  310. .gpio = RBWAP_GPIO_LED_WLAN,
  311. .active_low = 1,
  312. },
  313. };
  314. /* RB cAP-2nD gpios */
  315. #define RBCAP_GPIO_LED_1 14
  316. #define RBCAP_GPIO_LED_2 12
  317. #define RBCAP_GPIO_LED_3 11
  318. #define RBCAP_GPIO_LED_4 4
  319. #define RBCAP_GPIO_LED_ALL 13
  320. static struct gpio_led rbcap_leds[] __initdata = {
  321. {
  322. .name = "rb:green:rssi1",
  323. .gpio = RBCAP_GPIO_LED_1,
  324. .active_low = 1,
  325. }, {
  326. .name = "rb:green:rssi2",
  327. .gpio = RBCAP_GPIO_LED_2,
  328. .active_low = 1,
  329. }, {
  330. .name = "rb:green:rssi3",
  331. .gpio = RBCAP_GPIO_LED_3,
  332. .active_low = 1,
  333. }, {
  334. .name = "rb:green:rssi4",
  335. .gpio = RBCAP_GPIO_LED_4,
  336. .active_low = 1,
  337. },
  338. };
  339. /* RB mAP-2nD gpios */
  340. #define RBMAP_SSR_BIT_LED_LAN1 0
  341. #define RBMAP_SSR_BIT_LED_LAN2 1
  342. #define RBMAP_SSR_BIT_LED_POEO 2
  343. #define RBMAP_SSR_BIT_LED_USER 3
  344. #define RBMAP_SSR_BIT_LED_WLAN 4
  345. #define RBMAP_SSR_BIT_USB_POWER 5
  346. #define RBMAP_SSR_BIT_LED_APCAP 6
  347. #define RBMAP_GPIO_BTN_RESET 16
  348. #define RBMAP_GPIO_SSR_CS 11
  349. #define RBMAP_GPIO_LED_POWER 4
  350. #define RBMAP_GPIO_POE_POWER 14
  351. #define RBMAP_GPIO_POE_STATUS 12
  352. #define RBMAP_GPIO_USB_PWROFF RBSPI_SSR_GPIO(RBMAP_SSR_BIT_USB_POWER)
  353. #define RBMAP_GPIO_LED_LAN1 RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN1)
  354. #define RBMAP_GPIO_LED_LAN2 RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN2)
  355. #define RBMAP_GPIO_LED_POEO RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_POEO)
  356. #define RBMAP_GPIO_LED_USER RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_USER)
  357. #define RBMAP_GPIO_LED_WLAN RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_WLAN)
  358. #define RBMAP_GPIO_LED_APCAP RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_APCAP)
  359. static struct gpio_led rbmap_leds[] __initdata = {
  360. {
  361. .name = "rb:green:power",
  362. .gpio = RBMAP_GPIO_LED_POWER,
  363. .active_low = 1,
  364. .default_state = LEDS_GPIO_DEFSTATE_ON,
  365. }, {
  366. .name = "rb:green:eth1",
  367. .gpio = RBMAP_GPIO_LED_LAN1,
  368. .active_low = 1,
  369. }, {
  370. .name = "rb:green:eth2",
  371. .gpio = RBMAP_GPIO_LED_LAN2,
  372. .active_low = 1,
  373. }, {
  374. .name = "rb:red:poe_out",
  375. .gpio = RBMAP_GPIO_LED_POEO,
  376. .active_low = 1,
  377. }, {
  378. .name = "rb:green:user",
  379. .gpio = RBMAP_GPIO_LED_USER,
  380. .active_low = 1,
  381. }, {
  382. .name = "rb:green:wlan",
  383. .gpio = RBMAP_GPIO_LED_WLAN,
  384. .active_low = 1,
  385. }, {
  386. .name = "rb:green:ap_cap",
  387. .gpio = RBMAP_GPIO_LED_APCAP,
  388. .active_low = 1,
  389. },
  390. };
  391. /* RB LHG 5nD gpios */
  392. #define RBLHG_GPIO_LED_0 13
  393. #define RBLHG_GPIO_LED_1 12
  394. #define RBLHG_GPIO_LED_2 4
  395. #define RBLHG_GPIO_LED_3 21
  396. #define RBLHG_GPIO_LED_4 18
  397. #define RBLHG_GPIO_LED_ETH 14
  398. #define RBLHG_GPIO_LED_POWER 11
  399. #define RBLHG_GPIO_LED_USER 20
  400. #define RBLHG_GPIO_BTN_RESET 15
  401. static struct gpio_led rblhg_leds[] __initdata = {
  402. {
  403. .name = "rb:green:rssi0",
  404. .gpio = RBLHG_GPIO_LED_0,
  405. .active_low = 1,
  406. }, {
  407. .name = "rb:green:rssi1",
  408. .gpio = RBLHG_GPIO_LED_1,
  409. .active_low = 1,
  410. }, {
  411. .name = "rb:green:rssi2",
  412. .gpio = RBLHG_GPIO_LED_2,
  413. .active_low = 1,
  414. }, {
  415. .name = "rb:green:rssi3",
  416. .gpio = RBLHG_GPIO_LED_3,
  417. .active_low = 1,
  418. }, {
  419. .name = "rb:green:rssi4",
  420. .gpio = RBLHG_GPIO_LED_4,
  421. .active_low = 1,
  422. }, {
  423. .name = "rb:green:eth",
  424. .gpio = RBLHG_GPIO_LED_ETH,
  425. .active_low = 1,
  426. }, {
  427. .name = "rb:green:user",
  428. .gpio = RBLHG_GPIO_LED_USER,
  429. .active_low = 1,
  430. }, {
  431. .name = "rb:blue:power",
  432. .gpio = RBLHG_GPIO_LED_POWER,
  433. .active_low = 0,
  434. .default_state = LEDS_GPIO_DEFSTATE_ON,
  435. },
  436. };
  437. /* RB w APG-5HacT2HnD (wAP AC) gpios*/
  438. #define RBWAPGSC_WIFI_LED_1 1
  439. #define RBWAPGSC_WIFI_LED_2 8
  440. #define RBWAPGSC_WIFI_LED_3 9
  441. #define RBWAPGSC_GPIO_LED_POWER 16
  442. #define RBWAPGSC_GPIO_BTN_RESET 1
  443. #define RBWAPGSC_GPIO_MDIO_MDC 12
  444. #define RBWAPGSC_GPIO_MDIO_DATA 11
  445. #define RBWAPGSC_MDIO_PHYADDR 0
  446. static struct gpio_led rbwapgsc_leds[] __initdata = {
  447. {
  448. .name = "rb:green:power",
  449. .gpio = RBWAPGSC_GPIO_LED_POWER,
  450. .active_low = 1,
  451. .default_state = LEDS_GPIO_DEFSTATE_ON,
  452. },
  453. };
  454. static struct mdio_gpio_platform_data rbwapgsc_mdio_data = {
  455. .mdc = RBWAPGSC_GPIO_MDIO_MDC,
  456. .mdio = RBWAPGSC_GPIO_MDIO_DATA,
  457. .phy_mask = ~BIT(RBWAPGSC_MDIO_PHYADDR),
  458. };
  459. static struct platform_device rbwapgsc_phy_device = {
  460. .name = "mdio-gpio",
  461. .id = 1,
  462. .dev = {
  463. .platform_data = &rbwapgsc_mdio_data
  464. },
  465. };
  466. /* RB911L GPIOs */
  467. #define RB911L_GPIO_BTN_RESET 15
  468. #define RB911L_GPIO_LED_1 13
  469. #define RB911L_GPIO_LED_2 12
  470. #define RB911L_GPIO_LED_3 4
  471. #define RB911L_GPIO_LED_4 21
  472. #define RB911L_GPIO_LED_5 18
  473. #define RB911L_GPIO_LED_ETH 20
  474. #define RB911L_GPIO_LED_POWER 11
  475. #define RB911L_GPIO_LED_USER 3
  476. #define RB911L_GPIO_PIN_HOLE 14 /* for reference, active low */
  477. static struct gpio_led rb911l_leds[] __initdata = {
  478. {
  479. .name = "rb:green:eth",
  480. .gpio = RB911L_GPIO_LED_ETH,
  481. .active_low = 1,
  482. }, {
  483. .name = "rb:green:led1",
  484. .gpio = RB911L_GPIO_LED_1,
  485. .active_low = 1,
  486. }, {
  487. .name = "rb:green:led2",
  488. .gpio = RB911L_GPIO_LED_2,
  489. .active_low = 1,
  490. }, {
  491. .name = "rb:green:led3",
  492. .gpio = RB911L_GPIO_LED_3,
  493. .active_low = 1,
  494. }, {
  495. .name = "rb:green:led4",
  496. .gpio = RB911L_GPIO_LED_4,
  497. .active_low = 1,
  498. }, {
  499. .name = "rb:green:led5",
  500. .gpio = RB911L_GPIO_LED_5,
  501. .active_low = 1,
  502. }, {
  503. .name = "rb:green:power",
  504. .gpio = RB911L_GPIO_LED_POWER,
  505. .default_state = LEDS_GPIO_DEFSTATE_ON,
  506. .active_low = 1,
  507. .open_drain = 1,
  508. }, {
  509. .name = "rb:green:user",
  510. .gpio = RB911L_GPIO_LED_USER,
  511. .active_low = 1,
  512. .open_drain = 1,
  513. },
  514. };
  515. /* RB 931-2nD gpios */
  516. #define RB931_GPIO_BTN_RESET 0
  517. #define RB931_GPIO_BTN_MODE 9
  518. #define RB931_GPIO_LED_USER 1
  519. static struct gpio_keys_button rb931_gpio_keys[] __initdata = {
  520. {
  521. .desc = "Reset button",
  522. .type = EV_KEY,
  523. .code = KEY_RESTART,
  524. .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
  525. .gpio = RB931_GPIO_BTN_RESET,
  526. .active_low = 1,
  527. }, {
  528. .desc = "Mode button",
  529. .type = EV_KEY,
  530. .code = BTN_0,
  531. .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
  532. .gpio = RB931_GPIO_BTN_MODE,
  533. .active_low = 1,
  534. }
  535. };
  536. static struct gpio_led rb931_leds[] __initdata = {
  537. {
  538. .name = "rb:green:user",
  539. .gpio = RB931_GPIO_LED_USER,
  540. .active_low = 1,
  541. },
  542. };
  543. /* RB wAP R-2nD (wAP R) gpios*/
  544. #define RBWAPR_GPIO_LED_USER 14
  545. #define RBWAPR_GPIO_LED1 12
  546. #define RBWAPR_GPIO_LED2 13
  547. #define RBWAPR_GPIO_LED3 3
  548. #define RBWAPR_GPIO_PCIE_PWROFF 15
  549. #define RBWAPR_GPIO_CONTROL 10
  550. #define RBWAPR_GPIO_BTN_RESET 16
  551. static struct gpio_led rbwapr_leds[] __initdata = {
  552. {
  553. .name = "rb:green:user",
  554. .gpio = RBWAPR_GPIO_LED_USER,
  555. .active_low = 0,
  556. },{
  557. .name = "rb:green:led1",
  558. .gpio = RBWAPR_GPIO_LED1,
  559. .active_low = 1,
  560. },{
  561. .name = "rb:green:led2",
  562. .gpio = RBWAPR_GPIO_LED2,
  563. .active_low = 1,
  564. },{
  565. .name = "rb:green:led3",
  566. .gpio = RBWAPR_GPIO_LED3,
  567. .active_low = 0,
  568. },
  569. };
  570. static struct gen_74x164_chip_platform_data rbspi_ssr_data = {
  571. .base = RBSPI_SSR_GPIO_BASE,
  572. .num_registers = 1,
  573. };
  574. /* the spi-ath79 driver can only natively handle CS0. Other CS are bit-banged */
  575. static int rbspi_spi_cs_gpios[] = {
  576. -ENOENT, /* CS0 is always -ENOENT: natively handled */
  577. -ENOENT, /* CS1 can be updated by the code as necessary */
  578. };
  579. static struct ath79_spi_platform_data rbspi_ath79_spi_data = {
  580. .bus_num = 0,
  581. .cs_gpios = rbspi_spi_cs_gpios,
  582. };
  583. /*
  584. * Global spi_board_info: devices that don't have an SSR only have the SPI NOR
  585. * flash on bus0 CS0, while devices that have an SSR add it on the same bus CS1
  586. */
  587. static struct spi_board_info rbspi_spi_info[] = {
  588. {
  589. .bus_num = 0,
  590. .chip_select = 0,
  591. .max_speed_hz = 25000000,
  592. .modalias = "m25p80",
  593. .platform_data = &rbspi_spi_flash_data,
  594. }, {
  595. .bus_num = 0,
  596. .chip_select = 1,
  597. .max_speed_hz = 25000000,
  598. .modalias = "74x164",
  599. .platform_data = &rbspi_ssr_data,
  600. }
  601. };
  602. void __init rbspi_wlan_init(u16 id, int wmac_offset)
  603. {
  604. char *art_buf;
  605. u8 wlan_mac[ETH_ALEN];
  606. art_buf = rb_get_ext_wlan_data(id);
  607. if (!art_buf)
  608. return;
  609. ath79_init_mac(wlan_mac, ath79_mac_base, wmac_offset);
  610. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  611. kfree(art_buf);
  612. }
  613. #define RBSPI_MACH_BUFLEN 64
  614. /*
  615. * Common platform init routine for all SPI NOR devices.
  616. */
  617. static __init const struct rb_info *rbspi_platform_setup(void)
  618. {
  619. const struct rb_info *info;
  620. char buf[RBSPI_MACH_BUFLEN] = "MikroTik ";
  621. char *str;
  622. int len = RBSPI_MACH_BUFLEN - strlen(buf) - 1;
  623. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
  624. if (!info)
  625. return NULL;
  626. if (info->board_name) {
  627. str = "RouterBOARD ";
  628. if (strncmp(info->board_name, str, strlen(str))) {
  629. strncat(buf, str, len);
  630. len -= strlen(str);
  631. }
  632. strncat(buf, info->board_name, len);
  633. }
  634. else
  635. strncat(buf, "UNKNOWN", len);
  636. mips_set_machine_name(buf);
  637. /* fix partitions based on flash parsing */
  638. rbspi_init_partitions(info);
  639. return info;
  640. }
  641. /*
  642. * Common peripherals init routine for all SPI NOR devices.
  643. * Sets SPI and USB.
  644. */
  645. static void __init rbspi_peripherals_setup(u32 flags)
  646. {
  647. unsigned spi_n;
  648. if (flags & RBSPI_HAS_SSR)
  649. spi_n = ARRAY_SIZE(rbspi_spi_info);
  650. else
  651. spi_n = 1; /* only one device on bus0 */
  652. rbspi_ath79_spi_data.num_chipselect = spi_n;
  653. rbspi_ath79_spi_data.cs_gpios = rbspi_spi_cs_gpios;
  654. ath79_register_spi(&rbspi_ath79_spi_data, rbspi_spi_info, spi_n);
  655. if (flags & RBSPI_HAS_USB)
  656. ath79_register_usb();
  657. if (flags & RBSPI_HAS_PCI)
  658. ath79_register_pci();
  659. }
  660. /*
  661. * Common network init routine for all SPI NOR devices.
  662. * Sets LAN/WAN/WLAN.
  663. */
  664. static void __init rbspi_network_setup(u32 flags, int gmac1_offset,
  665. int wmac0_offset, int wmac1_offset)
  666. {
  667. /* for QCA953x that will init mdio1_device/data */
  668. ath79_register_mdio(0, 0x0);
  669. if (flags & RBSPI_HAS_MDIO1)
  670. ath79_register_mdio(1, 0x0);
  671. if (flags & RBSPI_HAS_WAN4) {
  672. ath79_setup_ar934x_eth_cfg(0);
  673. /* set switch to oper mode 1, PHY4 connected to CPU */
  674. ath79_switch_data.phy4_mii_en = 1;
  675. ath79_switch_data.phy_poll_mask |= BIT(4);
  676. /* init GMAC0 connected to PHY4 at 100M */
  677. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  678. ath79_eth0_data.phy_mask = BIT(4);
  679. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  680. ath79_register_eth(0);
  681. } else {
  682. /* set the SoC to SW_ONLY_MODE, which connects all PHYs
  683. * to the internal switch.
  684. * We hijack ath79_setup_ar934x_eth_cfg() to set the switch in
  685. * the QCA953x, this works because this configuration bit is
  686. * the same as the AR934x. There's no equivalent function for
  687. * QCA953x for now. */
  688. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  689. }
  690. /* init GMAC1 */
  691. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, gmac1_offset);
  692. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  693. ath79_register_eth(1);
  694. if (flags & RBSPI_HAS_WLAN0)
  695. rbspi_wlan_init(0, wmac0_offset);
  696. if (flags & RBSPI_HAS_WLAN1)
  697. rbspi_wlan_init(1, wmac1_offset);
  698. }
  699. static __init void rbspi_register_reset_button(int gpio)
  700. {
  701. rbspi_gpio_keys_reset[0].gpio = gpio;
  702. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  703. ARRAY_SIZE(rbspi_gpio_keys_reset),
  704. rbspi_gpio_keys_reset);
  705. }
  706. /*
  707. * Init the mAP lite hardware (QCA953x).
  708. * The mAP L-2nD (mAP lite) has a single ethernet port, connected to PHY0.
  709. * Trying to use GMAC0 in direct mode was unsucessful, so we're
  710. * using SW_ONLY_MODE, which connects PHY0 to MAC1 on the internal
  711. * switch, which is connected to GMAC1 on the SoC. GMAC0 is unused.
  712. */
  713. static void __init rbmapl_setup(void)
  714. {
  715. u32 flags = RBSPI_HAS_WLAN0;
  716. if (!rbspi_platform_setup())
  717. return;
  718. rbspi_peripherals_setup(flags);
  719. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  720. rbspi_network_setup(flags, 0, 1, 0);
  721. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmapl_leds), rbmapl_leds);
  722. /* mAP lite has a single reset button as gpio 16 */
  723. rbspi_register_reset_button(RBMAPL_GPIO_BTN_RESET);
  724. /* clear internal multiplexing */
  725. ath79_gpio_output_select(RBMAPL_GPIO_LED_ETH, AR934X_GPIO_OUT_GPIO);
  726. ath79_gpio_output_select(RBMAPL_GPIO_LED_POWER, AR934X_GPIO_OUT_GPIO);
  727. }
  728. /*
  729. * Init the hAP lite hardware (QCA953x).
  730. * The 941-2nD (hAP lite) has 4 ethernet ports, with port 2-4
  731. * being assigned to LAN on the casing, and port 1 being assigned
  732. * to "internet" (WAN) on the casing. Port 1 is connected to PHY3.
  733. * Since WAN is neither PHY0 nor PHY4, we cannot use GMAC0 with this device.
  734. */
  735. static void __init rbhapl_setup(void)
  736. {
  737. u32 flags = RBSPI_HAS_WLAN0;
  738. if (!rbspi_platform_setup())
  739. return;
  740. rbspi_peripherals_setup(flags);
  741. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 4 */
  742. rbspi_network_setup(flags, 0, 4, 0);
  743. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbhapl_leds), rbhapl_leds);
  744. /* hAP lite has a single reset button as gpio 16 */
  745. rbspi_register_reset_button(RBHAPL_GPIO_BTN_RESET);
  746. }
  747. /*
  748. * The hAP, hAP ac lite, hEX lite and hEX PoE lite share the same platform
  749. */
  750. static void __init rbspi_952_750r2_setup(u32 flags)
  751. {
  752. if (flags & RBSPI_HAS_SSR)
  753. rbspi_spi_cs_gpios[1] = RB952_GPIO_SSR_CS;
  754. rbspi_peripherals_setup(flags);
  755. /*
  756. * GMAC1 is HW MAC + 1, WLAN0 MAC IS HW MAC + 5 (hAP),
  757. * WLAN1 MAC IS HW MAC + 6 (hAP ac lite)
  758. */
  759. rbspi_network_setup(flags, 1, 5, 6);
  760. if (flags & RBSPI_HAS_USB)
  761. gpio_request_one(RB952_GPIO_USB_PWROFF, GPIOF_ACTIVE_LOW |
  762. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  763. "USB power off");
  764. if (flags & RBSPI_HAS_POE)
  765. gpio_request_one(RB952_GPIO_POE_POWER,
  766. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  767. "POE power");
  768. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb952_leds), rb952_leds);
  769. /* These devices have a single reset button as gpio 16 */
  770. rbspi_register_reset_button(RB952_GPIO_BTN_RESET);
  771. }
  772. /*
  773. * Init the hAP (ac lite) hardware (QCA953x).
  774. * The 951Ui-2nD (hAP) has 5 ethernet ports, with ports 2-5 being assigned
  775. * to LAN on the casing, and port 1 being assigned to "internet" (WAN).
  776. * Port 1 is connected to PHY4 (the ports are labelled in reverse physical
  777. * number), so the SoC can be set to connect GMAC0 to PHY4 and GMAC1 to the
  778. * internal switch for the LAN ports.
  779. * The device also has USB, PoE output and an SSR used for LED multiplexing.
  780. * The 952Ui-5ac2nD (hAP ac lite) is nearly identical to the hAP, it adds a
  781. * QCA9887 5GHz radio via PCI and moves 2.4GHz from WLAN0 to WLAN1.
  782. */
  783. static void __init rb952_setup(void)
  784. {
  785. u32 flags = RBSPI_HAS_WAN4 | RBSPI_HAS_USB |
  786. RBSPI_HAS_SSR | RBSPI_HAS_POE;
  787. if (!rbspi_platform_setup())
  788. return;
  789. /* differentiate the hAP from the hAP ac lite */
  790. if (strstr(mips_get_machine_name(), "952Ui-5ac2nD"))
  791. flags |= RBSPI_HAS_WLAN1 | RBSPI_HAS_PCI;
  792. else
  793. flags |= RBSPI_HAS_WLAN0;
  794. rbspi_952_750r2_setup(flags);
  795. }
  796. /*
  797. * Init the hEX (PoE) lite hardware (QCA953x).
  798. * The 750UP r2 (hEX PoE lite) is nearly identical to the hAP, only without
  799. * WLAN. The 750 r2 (hEX lite) is nearly identical to the 750UP r2, only
  800. * without USB and POE. The 750P Pbr2 (Powerbox) is nearly identical to hEX PoE
  801. * lite, only without USB. It shares the same bootloader board identifier.
  802. */
  803. static void __init rb750upr2_setup(void)
  804. {
  805. u32 flags = RBSPI_HAS_WAN4 | RBSPI_HAS_SSR;
  806. if (!rbspi_platform_setup())
  807. return;
  808. /* differentiate the hEX lite from the hEX PoE lite */
  809. if (strstr(mips_get_machine_name(), "750UP r2"))
  810. flags |= RBSPI_HAS_USB | RBSPI_HAS_POE;
  811. /* differentiate the Powerbox from the hEX lite */
  812. else if (strstr(mips_get_machine_name(), "750P r2"))
  813. flags |= RBSPI_HAS_POE;
  814. rbspi_952_750r2_setup(flags);
  815. }
  816. /*
  817. * Init the hAP ac / 962UiGS-5HacT2HnT hardware (QCA9558).
  818. * The hAP ac has 5 ethernet ports provided by an AR8337 switch. Port 1 is
  819. * assigned to WAN, ports 2-5 are assigned to LAN. Port 0 is connected to the
  820. * SoC, ports 1-5 of the switch are connected to physical ports 1-5 in order.
  821. * The SFP cage is not assigned by default on RouterOS. Extra work is required
  822. * to support this interface as it is directly connected to the SoC (eth1).
  823. * Wireless is provided by a 2.4GHz radio on the SoC (WLAN1) and a 5GHz radio
  824. * attached via PCI (QCA9880). Red and green WLAN LEDs are populated however
  825. * they are not attached to GPIOs, extra work is required to support these.
  826. * PoE and USB output power control is supported.
  827. */
  828. static void __init rb962_setup(void)
  829. {
  830. u32 flags = RBSPI_HAS_USB | RBSPI_HAS_POE | RBSPI_HAS_PCI;
  831. if (!rbspi_platform_setup())
  832. return;
  833. rbspi_peripherals_setup(flags);
  834. /* Do not call rbspi_network_setup as we have a discrete switch chip */
  835. ath79_eth0_pll_data.pll_1000 = 0xae000000;
  836. ath79_eth0_pll_data.pll_100 = 0xa0000101;
  837. ath79_eth0_pll_data.pll_10 = 0xa0001313;
  838. ath79_register_mdio(0, 0x0);
  839. mdiobus_register_board_info(rb962_mdio0_info,
  840. ARRAY_SIZE(rb962_mdio0_info));
  841. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  842. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  843. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  844. ath79_eth0_data.phy_mask = BIT(0);
  845. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  846. ath79_register_eth(0);
  847. /* WLAN1 MAC is HW MAC + 7 */
  848. rbspi_wlan_init(1, 7);
  849. if (flags & RBSPI_HAS_USB)
  850. gpio_request_one(RB962_GPIO_USB_PWROFF, GPIOF_ACTIVE_LOW |
  851. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  852. "USB power off");
  853. /* PoE output GPIO is inverted, set GPIOF_ACTIVE_LOW for consistency */
  854. if (flags & RBSPI_HAS_POE)
  855. gpio_request_one(RB962_GPIO_POE_POWER,
  856. GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW |
  857. GPIOF_EXPORT_DIR_FIXED,
  858. "POE power");
  859. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb962_leds_gpio),
  860. rb962_leds_gpio);
  861. /* This device has a single reset button as gpio 20 */
  862. rbspi_register_reset_button(RB962_GPIO_BTN_RESET);
  863. }
  864. /*
  865. * Init the LHG hardware (AR9344).
  866. * The LHG 5nD has a single ethernet port connected to PHY0.
  867. * Wireless is provided via 5GHz WLAN1.
  868. */
  869. static void __init rblhg_setup(void)
  870. {
  871. u32 flags = RBSPI_HAS_WLAN1 | RBSPI_HAS_MDIO1;
  872. if (!rbspi_platform_setup())
  873. return;
  874. rbspi_peripherals_setup(flags);
  875. /* GMAC1 is HW MAC, WLAN1 MAC is HW MAC + 1 */
  876. rbspi_network_setup(flags, 0, 0, 1);
  877. ath79_register_leds_gpio(-1, ARRAY_SIZE(rblhg_leds), rblhg_leds);
  878. rbspi_register_reset_button(RBLHG_GPIO_BTN_RESET);
  879. }
  880. /*
  881. * Init the wAP hardware.
  882. * The wAP 2nD has a single ethernet port.
  883. */
  884. static void __init rbwap_setup(void)
  885. {
  886. u32 flags = RBSPI_HAS_WLAN0;
  887. if (!rbspi_platform_setup())
  888. return;
  889. rbspi_peripherals_setup(flags);
  890. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  891. rbspi_network_setup(flags, 0, 1, 0);
  892. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwap_leds), rbwap_leds);
  893. /* wAP has a single reset button as GPIO 16 */
  894. rbspi_register_reset_button(RBWAP_GPIO_BTN_RESET);
  895. }
  896. /*
  897. * Init the cAP hardware (EXPERIMENTAL).
  898. * The cAP 2nD has a single ethernet port, and a global LED switch.
  899. */
  900. static void __init rbcap_setup(void)
  901. {
  902. u32 flags = RBSPI_HAS_WLAN0;
  903. if (!rbspi_platform_setup())
  904. return;
  905. rbspi_peripherals_setup(flags);
  906. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  907. rbspi_network_setup(flags, 0, 1, 0);
  908. gpio_request_one(RBCAP_GPIO_LED_ALL,
  909. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  910. "LEDs enable");
  911. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbcap_leds), rbcap_leds);
  912. }
  913. /*
  914. * Init the mAP hardware.
  915. * The mAP 2nD has two ethernet ports, PoE output, SSR for LED
  916. * multiplexing and USB port.
  917. */
  918. static void __init rbmap_setup(void)
  919. {
  920. u32 flags = RBSPI_HAS_USB | RBSPI_HAS_WLAN0 |
  921. RBSPI_HAS_SSR | RBSPI_HAS_POE;
  922. if (!rbspi_platform_setup())
  923. return;
  924. rbspi_spi_cs_gpios[1] = RBMAP_GPIO_SSR_CS;
  925. rbspi_peripherals_setup(flags);
  926. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 2 */
  927. rbspi_network_setup(flags, 0, 2, 0);
  928. if (flags & RBSPI_HAS_POE)
  929. gpio_request_one(RBMAP_GPIO_POE_POWER,
  930. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
  931. "POE power");
  932. if (flags & RBSPI_HAS_USB)
  933. gpio_request_one(RBMAP_GPIO_USB_PWROFF,
  934. GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW |
  935. GPIOF_EXPORT_DIR_FIXED,
  936. "USB power off");
  937. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmap_leds), rbmap_leds);
  938. /* mAP 2nD has a single reset button as gpio 16 */
  939. rbspi_register_reset_button(RBMAP_GPIO_BTN_RESET);
  940. }
  941. /*
  942. * Init the wAPGSC (RB wAPG-5HacT2HnD // wAP AC) hardware.
  943. * The wAPGSC has one Ethernet port via AR8033 with PoE input, dual radio (SoC
  944. * 2.4 GHz and external QCA9880) and a ZT2046Q temperature and voltage sensor
  945. * (currently not supported).
  946. */
  947. static void __init rbwapgsc_setup(void)
  948. {
  949. u32 flags = RBSPI_HAS_PCI;
  950. if (!rbspi_platform_setup())
  951. return;
  952. rbspi_peripherals_setup(flags);
  953. platform_device_register(&rbwapgsc_phy_device);
  954. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  955. ath79_eth1_data.mii_bus_dev = &rbwapgsc_phy_device.dev;
  956. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  957. ath79_eth1_data.phy_mask = BIT(RBWAPGSC_MDIO_PHYADDR);
  958. ath79_eth1_pll_data.pll_1000 = 0x03000101;
  959. ath79_eth1_pll_data.pll_100 = 0x80000101;
  960. ath79_eth1_pll_data.pll_10 = 0x80001313;
  961. ath79_eth1_data.speed = SPEED_1000;
  962. ath79_eth1_data.duplex = DUPLEX_FULL;
  963. ath79_register_eth(1);
  964. rbspi_wlan_init(1, 2);
  965. rbspi_register_reset_button(RBWAPGSC_GPIO_BTN_RESET);
  966. ath79_gpio_function_enable(QCA955X_GPIO_FUNC_JTAG_DISABLE|
  967. QCA955X_GPIO_REG_OUT_FUNC4|
  968. QCA955X_GPIO_REG_OUT_FUNC3);
  969. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwapgsc_leds),
  970. rbwapgsc_leds);
  971. }
  972. /*
  973. * Setup the 911L hardware (AR9344).
  974. */
  975. static void __init rb911l_setup(void)
  976. {
  977. const struct rb_info *info;
  978. info = rbspi_platform_setup();
  979. if (!info)
  980. return;
  981. if (!rb_has_hw_option(info, RB_HW_OPT_NO_NAND)) {
  982. /*
  983. * Old hardware revisions might be equipped with a NAND flash
  984. * chip instead of the 16MiB SPI NOR device. Those boards are
  985. * not supported at the moment, so throw a warning and skip
  986. * the peripheral setup to avoid messing up the data in the
  987. * flash chip.
  988. */
  989. WARN(1, "The NAND flash on this board is not supported.\n");
  990. } else {
  991. rbspi_peripherals_setup(0);
  992. }
  993. ath79_register_mdio(1, 0x0);
  994. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  995. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  996. ath79_eth1_data.speed = SPEED_1000;
  997. ath79_eth1_data.duplex = DUPLEX_FULL;
  998. ath79_register_eth(1);
  999. rbspi_wlan_init(0, 1);
  1000. rbspi_register_reset_button(RB911L_GPIO_BTN_RESET);
  1001. /* Make the eth LED controllable by software. */
  1002. ath79_gpio_output_select(RB911L_GPIO_LED_ETH, AR934X_GPIO_OUT_GPIO);
  1003. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb911l_leds), rb911l_leds);
  1004. }
  1005. /*
  1006. * Init the hAP mini hardware (QCA953x).
  1007. * The 931-2nD (hAP mini) has 3 ethernet ports, with port 2-3
  1008. * being assigned to LAN on the casing, and port 1 being assigned
  1009. * to "internet" (WAN) on the casing. Port 1 is connected to PHY2.
  1010. * Since WAN is neither PHY0 nor PHY4, we cannot use GMAC0 with this device.
  1011. */
  1012. static void __init rb931_setup(void)
  1013. {
  1014. u32 flags = RBSPI_HAS_WLAN0;
  1015. if (!rbspi_platform_setup())
  1016. return;
  1017. rbspi_peripherals_setup(flags);
  1018. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 3 */
  1019. rbspi_network_setup(flags, 0, 3, 0);
  1020. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb931_leds), rb931_leds);
  1021. /* hAP mini has two buttons */
  1022. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  1023. ARRAY_SIZE(rb931_gpio_keys),
  1024. rb931_gpio_keys);
  1025. }
  1026. /*
  1027. * Init the wAP R hardware.
  1028. * The wAP R-2nD has a single ethernet port and a mini PCIe slot.
  1029. * The OEM source shows it has usb (used over PCIe for LTE devices),
  1030. * and the 'control' GPIO is assumed to be an output pin not tied to an LED.
  1031. */
  1032. static void __init rbwapr_setup(void)
  1033. {
  1034. u32 flags = RBSPI_HAS_WLAN0 | RBSPI_HAS_USB | RBSPI_HAS_PCI;
  1035. if (!rbspi_platform_setup())
  1036. return;
  1037. rbspi_peripherals_setup(flags);
  1038. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  1039. rbspi_network_setup(flags, 0, 1, 0);
  1040. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwapr_leds), rbwapr_leds);
  1041. gpio_request_one(RBWAPR_GPIO_PCIE_PWROFF, GPIOF_OUT_INIT_HIGH |
  1042. GPIOF_ACTIVE_LOW | GPIOF_EXPORT_DIR_FIXED,
  1043. "PCIE power off");
  1044. gpio_request_one(RBWAPR_GPIO_CONTROL, GPIOF_OUT_INIT_LOW |
  1045. GPIOF_ACTIVE_LOW | GPIOF_EXPORT_DIR_FIXED,
  1046. "control");
  1047. rbspi_register_reset_button(RBWAPR_GPIO_BTN_RESET);
  1048. }
  1049. MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAPL, "map-hb", rbmapl_setup);
  1050. MIPS_MACHINE_NONAME(ATH79_MACH_RB_941, "H951L", rbhapl_setup);
  1051. MIPS_MACHINE_NONAME(ATH79_MACH_RB_911L, "911L", rb911l_setup);
  1052. MIPS_MACHINE_NONAME(ATH79_MACH_RB_952, "952-hb", rb952_setup);
  1053. MIPS_MACHINE_NONAME(ATH79_MACH_RB_962, "962", rb962_setup);
  1054. MIPS_MACHINE_NONAME(ATH79_MACH_RB_750UPR2, "750-hb", rb750upr2_setup);
  1055. MIPS_MACHINE_NONAME(ATH79_MACH_RB_LHG5, "lhg", rblhg_setup);
  1056. MIPS_MACHINE_NONAME(ATH79_MACH_RB_WAP, "wap-hb", rbwap_setup);
  1057. MIPS_MACHINE_NONAME(ATH79_MACH_RB_WAPR, "wap-lte", rbwapr_setup);
  1058. MIPS_MACHINE_NONAME(ATH79_MACH_RB_CAP, "cap-hb", rbcap_setup);
  1059. MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAP, "map2-hb", rbmap_setup);
  1060. MIPS_MACHINE_NONAME(ATH79_MACH_RB_WAPAC, "wapg-sc", rbwapgsc_setup);
  1061. MIPS_MACHINE_NONAME(ATH79_MACH_RB_931, "931", rb931_setup);