mach-rbspi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * MikroTik SPI-NOR RouterBOARDs support
  3. *
  4. * - MikroTik RouterBOARD mAP L-2nD
  5. * - MikroTik RouterBOARD 941L-2nD
  6. * - MikroTik RouterBOARD 951Ui-2nD
  7. * - MikroTik RouterBOARD 952Ui-5ac2nD
  8. * - MikroTik RouterBOARD 750UP r2
  9. * - MikroTik RouterBOARD 750 r2
  10. * - MikroTik RouterBOARD LHG 5nD
  11. *
  12. * Preliminary support for the following hardware
  13. * - MikroTik RouterBOARD wAP2nD
  14. * - MikroTik RouterBOARD cAP2nD
  15. * - MikroTik RouterBOARD mAP2nD
  16. * Furthermore, the cAP lite (cAPL2nD) appears to feature the exact same
  17. * hardware as the mAP L-2nD. It is unknown if they share the same board
  18. * identifier.
  19. *
  20. * Copyright (C) 2017 Thibaut VARENE <[email protected]>
  21. *
  22. * This program is free software; you can redistribute it and/or modify it
  23. * under the terms of the GNU General Public License version 2 as published
  24. * by the Free Software Foundation.
  25. */
  26. #include <linux/pci.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/phy.h>
  29. #include <linux/routerboot.h>
  30. #include <linux/gpio.h>
  31. #include <linux/spi/spi.h>
  32. #include <linux/spi/74x164.h>
  33. #include <linux/mtd/mtd.h>
  34. #include <linux/mtd/partitions.h>
  35. #include <asm/prom.h>
  36. #include <asm/mach-ath79/ar71xx_regs.h>
  37. #include <asm/mach-ath79/ath79.h>
  38. #include "common.h"
  39. #include "dev-eth.h"
  40. #include "dev-spi.h"
  41. #include "dev-gpio-buttons.h"
  42. #include "dev-leds-gpio.h"
  43. #include "dev-m25p80.h"
  44. #include "dev-usb.h"
  45. #include "dev-wmac.h"
  46. #include "machtypes.h"
  47. #include "pci.h"
  48. #include "routerboot.h"
  49. #define RBSPI_KEYS_POLL_INTERVAL 20 /* msecs */
  50. #define RBSPI_KEYS_DEBOUNCE_INTERVAL (3 * RBSPI_KEYS_POLL_INTERVAL)
  51. #define RBSPI_HAS_USB BIT(0)
  52. #define RBSPI_HAS_WLAN0 BIT(1)
  53. #define RBSPI_HAS_WLAN1 BIT(2)
  54. #define RBSPI_HAS_WAN4 BIT(3) /* has WAN port on PHY4 */
  55. #define RBSPI_HAS_SSR BIT(4) /* has an SSR on SPI bus 0 */
  56. #define RBSPI_HAS_POE BIT(5)
  57. #define RBSPI_HAS_MDIO1 BIT(6)
  58. #define RBSPI_HAS_PCI BIT(7)
  59. #define RB_ROUTERBOOT_OFFSET 0x0000
  60. #define RB_BIOS_SIZE 0x1000
  61. #define RB_SOFT_CFG_SIZE 0x1000
  62. /* Flash partitions indexes */
  63. enum {
  64. RBSPI_PART_RBOOT,
  65. RBSPI_PART_HCONF,
  66. RBSPI_PART_BIOS,
  67. RBSPI_PART_RBOOT2,
  68. RBSPI_PART_SCONF,
  69. RBSPI_PART_FIRMW,
  70. RBSPI_PARTS
  71. };
  72. static struct mtd_partition rbspi_spi_partitions[RBSPI_PARTS];
  73. /*
  74. * Setup the SPI flash partition table based on initial parsing.
  75. * The kernel can be at any aligned position and have any size.
  76. */
  77. static void __init rbspi_init_partitions(const struct rb_info *info)
  78. {
  79. struct mtd_partition *parts = rbspi_spi_partitions;
  80. memset(parts, 0x0, sizeof(*parts));
  81. parts[RBSPI_PART_RBOOT].name = "routerboot";
  82. parts[RBSPI_PART_RBOOT].offset = RB_ROUTERBOOT_OFFSET;
  83. parts[RBSPI_PART_RBOOT].size = info->hard_cfg_offs;
  84. parts[RBSPI_PART_RBOOT].mask_flags = MTD_WRITEABLE;
  85. parts[RBSPI_PART_HCONF].name = "hard_config";
  86. parts[RBSPI_PART_HCONF].offset = info->hard_cfg_offs;
  87. parts[RBSPI_PART_HCONF].size = info->hard_cfg_size;
  88. parts[RBSPI_PART_HCONF].mask_flags = MTD_WRITEABLE;
  89. parts[RBSPI_PART_BIOS].name = "bios";
  90. parts[RBSPI_PART_BIOS].offset = info->hard_cfg_offs
  91. + info->hard_cfg_size;
  92. parts[RBSPI_PART_BIOS].size = RB_BIOS_SIZE;
  93. parts[RBSPI_PART_BIOS].mask_flags = MTD_WRITEABLE;
  94. parts[RBSPI_PART_RBOOT2].name = "routerboot2";
  95. parts[RBSPI_PART_RBOOT2].offset = parts[RBSPI_PART_BIOS].offset
  96. + RB_BIOS_SIZE;
  97. parts[RBSPI_PART_RBOOT2].size = info->soft_cfg_offs
  98. - parts[RBSPI_PART_RBOOT2].offset;
  99. parts[RBSPI_PART_RBOOT2].mask_flags = MTD_WRITEABLE;
  100. parts[RBSPI_PART_SCONF].name = "soft_config";
  101. parts[RBSPI_PART_SCONF].offset = info->soft_cfg_offs;
  102. parts[RBSPI_PART_SCONF].size = RB_SOFT_CFG_SIZE;
  103. parts[RBSPI_PART_FIRMW].name = "firmware";
  104. parts[RBSPI_PART_FIRMW].offset = parts[RBSPI_PART_SCONF].offset
  105. + parts[RBSPI_PART_SCONF].size;
  106. parts[RBSPI_PART_FIRMW].size = MTDPART_SIZ_FULL;
  107. }
  108. static struct flash_platform_data rbspi_spi_flash_data = {
  109. .parts = rbspi_spi_partitions,
  110. .nr_parts = ARRAY_SIZE(rbspi_spi_partitions),
  111. };
  112. /* Several boards only have a single reset button wired to GPIO 16 */
  113. #define RBSPI_GPIO_BTN_RESET16 16
  114. static struct gpio_keys_button rbspi_gpio_keys_reset16[] __initdata = {
  115. {
  116. .desc = "Reset button",
  117. .type = EV_KEY,
  118. .code = KEY_RESTART,
  119. .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
  120. .gpio = RBSPI_GPIO_BTN_RESET16,
  121. .active_low = 1,
  122. },
  123. };
  124. /* RB mAP L-2nD gpios */
  125. #define RBMAPL_GPIO_LED_POWER 17
  126. #define RBMAPL_GPIO_LED_USER 14
  127. #define RBMAPL_GPIO_LED_ETH 4
  128. #define RBMAPL_GPIO_LED_WLAN 11
  129. static struct gpio_led rbmapl_leds[] __initdata = {
  130. {
  131. .name = "rb:green:power",
  132. .gpio = RBMAPL_GPIO_LED_POWER,
  133. .active_low = 0,
  134. .default_state = LEDS_GPIO_DEFSTATE_ON,
  135. }, {
  136. .name = "rb:green:user",
  137. .gpio = RBMAPL_GPIO_LED_USER,
  138. .active_low = 0,
  139. }, {
  140. .name = "rb:green:eth",
  141. .gpio = RBMAPL_GPIO_LED_ETH,
  142. .active_low = 0,
  143. }, {
  144. .name = "rb:green:wlan",
  145. .gpio = RBMAPL_GPIO_LED_WLAN,
  146. .active_low = 0,
  147. },
  148. };
  149. /* RB 941L-2nD gpios */
  150. #define RBHAPL_GPIO_LED_USER 14
  151. static struct gpio_led rbhapl_leds[] __initdata = {
  152. {
  153. .name = "rb:green:user",
  154. .gpio = RBHAPL_GPIO_LED_USER,
  155. .active_low = 1,
  156. },
  157. };
  158. /* common RB SSRs */
  159. #define RBSPI_SSR_GPIO_BASE 40
  160. #define RBSPI_SSR_GPIO(bit) (RBSPI_SSR_GPIO_BASE + (bit))
  161. /* RB 951Ui-2nD gpios */
  162. #define RB952_SSR_BIT_LED_LAN1 0
  163. #define RB952_SSR_BIT_LED_LAN2 1
  164. #define RB952_SSR_BIT_LED_LAN3 2
  165. #define RB952_SSR_BIT_LED_LAN4 3
  166. #define RB952_SSR_BIT_LED_LAN5 4
  167. #define RB952_SSR_BIT_USB_POWER 5
  168. #define RB952_SSR_BIT_LED_WLAN 6
  169. #define RB952_GPIO_SSR_CS 11
  170. #define RB952_GPIO_LED_USER 4
  171. #define RB952_GPIO_POE_POWER 14
  172. #define RB952_GPIO_POE_STATUS 12
  173. #define RB952_GPIO_USB_POWER RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER)
  174. #define RB952_GPIO_LED_LAN1 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN1)
  175. #define RB952_GPIO_LED_LAN2 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN2)
  176. #define RB952_GPIO_LED_LAN3 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN3)
  177. #define RB952_GPIO_LED_LAN4 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN4)
  178. #define RB952_GPIO_LED_LAN5 RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN5)
  179. #define RB952_GPIO_LED_WLAN RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_WLAN)
  180. static struct gpio_led rb952_leds[] __initdata = {
  181. {
  182. .name = "rb:green:user",
  183. .gpio = RB952_GPIO_LED_USER,
  184. .active_low = 0,
  185. }, {
  186. .name = "rb:blue:wlan",
  187. .gpio = RB952_GPIO_LED_WLAN,
  188. .active_low = 1,
  189. }, {
  190. .name = "rb:green:port1",
  191. .gpio = RB952_GPIO_LED_LAN1,
  192. .active_low = 1,
  193. }, {
  194. .name = "rb:green:port2",
  195. .gpio = RB952_GPIO_LED_LAN2,
  196. .active_low = 1,
  197. }, {
  198. .name = "rb:green:port3",
  199. .gpio = RB952_GPIO_LED_LAN3,
  200. .active_low = 1,
  201. }, {
  202. .name = "rb:green:port4",
  203. .gpio = RB952_GPIO_LED_LAN4,
  204. .active_low = 1,
  205. }, {
  206. .name = "rb:green:port5",
  207. .gpio = RB952_GPIO_LED_LAN5,
  208. .active_low = 1,
  209. },
  210. };
  211. /* RB wAP-2nD gpios */
  212. #define RBWAP_GPIO_LED_USER 14
  213. #define RBWAP_GPIO_LED_WLAN 11
  214. static struct gpio_led rbwap_leds[] __initdata = {
  215. {
  216. .name = "rb:green:user",
  217. .gpio = RBWAP_GPIO_LED_USER,
  218. .active_low = 1,
  219. }, {
  220. .name = "rb:green:wlan",
  221. .gpio = RBWAP_GPIO_LED_WLAN,
  222. .active_low = 1,
  223. },
  224. };
  225. /* RB cAP-2nD gpios */
  226. #define RBCAP_GPIO_LED_1 14
  227. #define RBCAP_GPIO_LED_2 12
  228. #define RBCAP_GPIO_LED_3 11
  229. #define RBCAP_GPIO_LED_4 4
  230. #define RBCAP_GPIO_LED_ALL 13
  231. static struct gpio_led rbcap_leds[] __initdata = {
  232. {
  233. .name = "rb:green:rssi1",
  234. .gpio = RBCAP_GPIO_LED_1,
  235. .active_low = 1,
  236. }, {
  237. .name = "rb:green:rssi2",
  238. .gpio = RBCAP_GPIO_LED_2,
  239. .active_low = 1,
  240. }, {
  241. .name = "rb:green:rssi3",
  242. .gpio = RBCAP_GPIO_LED_3,
  243. .active_low = 1,
  244. }, {
  245. .name = "rb:green:rssi4",
  246. .gpio = RBCAP_GPIO_LED_4,
  247. .active_low = 1,
  248. },
  249. };
  250. /* RB mAP-2nD gpios */
  251. #define RBMAP_SSR_BIT_LED_LAN1 0
  252. #define RBMAP_SSR_BIT_LED_LAN2 1
  253. #define RBMAP_SSR_BIT_LED_POEO 2
  254. #define RBMAP_SSR_BIT_LED_USER 3
  255. #define RBMAP_SSR_BIT_LED_WLAN 4
  256. #define RBMAP_SSR_BIT_USB_POWER 5
  257. #define RBMAP_SSR_BIT_LED_APCAP 6
  258. #define RBMAP_GPIO_SSR_CS 11
  259. #define RBMAP_GPIO_LED_POWER 4
  260. #define RBMAP_GPIO_POE_POWER 14
  261. #define RBMAP_GPIO_POE_STATUS 12
  262. #define RBMAP_GPIO_USB_POWER RBSPI_SSR_GPIO(RBMAP_SSR_BIT_USB_POWER)
  263. #define RBMAP_GPIO_LED_LAN1 RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN1)
  264. #define RBMAP_GPIO_LED_LAN2 RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN2)
  265. #define RBMAP_GPIO_LED_POEO RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_POEO)
  266. #define RBMAP_GPIO_LED_USER RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_USER)
  267. #define RBMAP_GPIO_LED_WLAN RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_WLAN)
  268. #define RBMAP_GPIO_LED_APCAP RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_APCAP)
  269. static struct gpio_led rbmap_leds[] __initdata = {
  270. {
  271. .name = "rb:green:power",
  272. .gpio = RBMAP_GPIO_LED_POWER,
  273. .active_low = 1,
  274. .default_state = LEDS_GPIO_DEFSTATE_ON,
  275. }, {
  276. .name = "rb:green:eth1",
  277. .gpio = RBMAP_GPIO_LED_LAN1,
  278. .active_low = 1,
  279. }, {
  280. .name = "rb:green:eth2",
  281. .gpio = RBMAP_GPIO_LED_WLAN,
  282. .active_low = 1,
  283. }, {
  284. .name = "rb:red:poe_out",
  285. .gpio = RBMAP_GPIO_LED_POEO,
  286. .active_low = 1,
  287. }, {
  288. .name = "rb:green:user",
  289. .gpio = RBMAP_GPIO_LED_USER,
  290. .active_low = 1,
  291. }, {
  292. .name = "rb:green:wlan",
  293. .gpio = RBMAP_GPIO_LED_WLAN,
  294. .active_low = 1,
  295. }, {
  296. .name = "rb:green:ap_cap",
  297. .gpio = RBMAP_GPIO_LED_APCAP,
  298. .active_low = 1,
  299. },
  300. };
  301. /* RB LHG 5nD gpios */
  302. #define RBLHG_GPIO_LED_0 13
  303. #define RBLHG_GPIO_LED_1 12
  304. #define RBLHG_GPIO_LED_2 4
  305. #define RBLHG_GPIO_LED_3 21
  306. #define RBLHG_GPIO_LED_4 18
  307. #define RBLHG_GPIO_LED_ETH 14
  308. #define RBLHG_GPIO_LED_POWER 11
  309. #define RBLHG_GPIO_LED_USER 20
  310. #define RBLHG_GPIO_BTN_RESET 15
  311. static struct gpio_led rblhg_leds[] __initdata = {
  312. {
  313. .name = "rb:green:rssi0",
  314. .gpio = RBLHG_GPIO_LED_0,
  315. .active_low = 1,
  316. }, {
  317. .name = "rb:green:rssi1",
  318. .gpio = RBLHG_GPIO_LED_1,
  319. .active_low = 1,
  320. }, {
  321. .name = "rb:green:rssi2",
  322. .gpio = RBLHG_GPIO_LED_2,
  323. .active_low = 1,
  324. }, {
  325. .name = "rb:green:rssi3",
  326. .gpio = RBLHG_GPIO_LED_3,
  327. .active_low = 1,
  328. }, {
  329. .name = "rb:green:rssi4",
  330. .gpio = RBLHG_GPIO_LED_4,
  331. .active_low = 1,
  332. }, {
  333. .name = "rb:green:eth",
  334. .gpio = RBLHG_GPIO_LED_ETH,
  335. .active_low = 1,
  336. }, {
  337. .name = "rb:green:user",
  338. .gpio = RBLHG_GPIO_LED_USER,
  339. .active_low = 1,
  340. }, {
  341. .name = "rb:blue:power",
  342. .gpio = RBLHG_GPIO_LED_POWER,
  343. .active_low = 0,
  344. .default_state = LEDS_GPIO_DEFSTATE_ON,
  345. },
  346. };
  347. static struct gpio_keys_button rblhg_gpio_keys[] __initdata = {
  348. {
  349. .desc = "Reset button",
  350. .type = EV_KEY,
  351. .code = KEY_RESTART,
  352. .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
  353. .gpio = RBLHG_GPIO_BTN_RESET,
  354. .active_low = 1,
  355. },
  356. };
  357. static struct gen_74x164_chip_platform_data rbspi_ssr_data = {
  358. .base = RBSPI_SSR_GPIO_BASE,
  359. };
  360. /* the spi-ath79 driver can only natively handle CS0. Other CS are bit-banged */
  361. static int rbspi_spi_cs_gpios[] = {
  362. -ENOENT, /* CS0 is always -ENOENT: natively handled */
  363. -ENOENT, /* CS1 can be updated by the code as necessary */
  364. };
  365. static struct ath79_spi_platform_data rbspi_ath79_spi_data = {
  366. .bus_num = 0,
  367. .cs_gpios = rbspi_spi_cs_gpios,
  368. };
  369. /*
  370. * Global spi_board_info: devices that don't have an SSR only have the SPI NOR
  371. * flash on bus0 CS0, while devices that have an SSR add it on the same bus CS1
  372. */
  373. static struct spi_board_info rbspi_spi_info[] = {
  374. {
  375. .bus_num = 0,
  376. .chip_select = 0,
  377. .max_speed_hz = 25000000,
  378. .modalias = "m25p80",
  379. .platform_data = &rbspi_spi_flash_data,
  380. }, {
  381. .bus_num = 0,
  382. .chip_select = 1,
  383. .max_speed_hz = 25000000,
  384. .modalias = "74x164",
  385. .platform_data = &rbspi_ssr_data,
  386. }
  387. };
  388. void __init rbspi_wlan_init(u16 id, int wmac_offset)
  389. {
  390. char *art_buf;
  391. u8 wlan_mac[ETH_ALEN];
  392. art_buf = rb_get_ext_wlan_data(id);
  393. if (!art_buf)
  394. return;
  395. ath79_init_mac(wlan_mac, ath79_mac_base, wmac_offset);
  396. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  397. kfree(art_buf);
  398. }
  399. #define RBSPI_MACH_BUFLEN 64
  400. /*
  401. * Common platform init routine for all SPI NOR devices.
  402. */
  403. static int __init rbspi_platform_setup(void)
  404. {
  405. const struct rb_info *info;
  406. char buf[RBSPI_MACH_BUFLEN] = "MikroTik ";
  407. char *str;
  408. int len = RBSPI_MACH_BUFLEN - strlen(buf) - 1;
  409. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
  410. if (!info)
  411. return -ENODEV;
  412. if (info->board_name) {
  413. str = "RouterBOARD ";
  414. if (strncmp(info->board_name, str, strlen(str))) {
  415. strncat(buf, str, len);
  416. len -= strlen(str);
  417. }
  418. strncat(buf, info->board_name, len);
  419. }
  420. else
  421. strncat(buf, "UNKNOWN", len);
  422. mips_set_machine_name(buf);
  423. /* fix partitions based on flash parsing */
  424. rbspi_init_partitions(info);
  425. return 0;
  426. }
  427. /*
  428. * Common peripherals init routine for all SPI NOR devices.
  429. * Sets SPI and USB.
  430. */
  431. static void __init rbspi_peripherals_setup(u32 flags)
  432. {
  433. unsigned spi_n;
  434. if (flags & RBSPI_HAS_SSR)
  435. spi_n = ARRAY_SIZE(rbspi_spi_info);
  436. else
  437. spi_n = 1; /* only one device on bus0 */
  438. rbspi_ath79_spi_data.num_chipselect = spi_n;
  439. rbspi_ath79_spi_data.cs_gpios = rbspi_spi_cs_gpios;
  440. ath79_register_spi(&rbspi_ath79_spi_data, rbspi_spi_info, spi_n);
  441. if (flags & RBSPI_HAS_USB)
  442. ath79_register_usb();
  443. if (flags & RBSPI_HAS_PCI)
  444. ath79_register_pci();
  445. }
  446. /*
  447. * Common network init routine for all SPI NOR devices.
  448. * Sets LAN/WAN/WLAN.
  449. */
  450. static void __init rbspi_network_setup(u32 flags, int gmac1_offset,
  451. int wmac0_offset, int wmac1_offset)
  452. {
  453. /* for QCA953x that will init mdio1_device/data */
  454. ath79_register_mdio(0, 0x0);
  455. if (flags & RBSPI_HAS_MDIO1)
  456. ath79_register_mdio(1, 0x0);
  457. if (flags & RBSPI_HAS_WAN4) {
  458. ath79_setup_ar934x_eth_cfg(0);
  459. /* set switch to oper mode 1, PHY4 connected to CPU */
  460. ath79_switch_data.phy4_mii_en = 1;
  461. ath79_switch_data.phy_poll_mask |= BIT(4);
  462. /* init GMAC0 connected to PHY4 at 100M */
  463. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  464. ath79_eth0_data.phy_mask = BIT(4);
  465. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  466. ath79_register_eth(0);
  467. } else {
  468. /* set the SoC to SW_ONLY_MODE, which connects all PHYs
  469. * to the internal switch.
  470. * We hijack ath79_setup_ar934x_eth_cfg() to set the switch in
  471. * the QCA953x, this works because this configuration bit is
  472. * the same as the AR934x. There's no equivalent function for
  473. * QCA953x for now. */
  474. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  475. }
  476. /* init GMAC1 */
  477. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, gmac1_offset);
  478. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  479. ath79_register_eth(1);
  480. if (flags & RBSPI_HAS_WLAN0)
  481. rbspi_wlan_init(0, wmac0_offset);
  482. if (flags & RBSPI_HAS_WLAN1)
  483. rbspi_wlan_init(1, wmac1_offset);
  484. }
  485. /*
  486. * Init the mAP lite hardware (QCA953x).
  487. * The mAP L-2nD (mAP lite) has a single ethernet port, connected to PHY0.
  488. * Trying to use GMAC0 in direct mode was unsucessful, so we're
  489. * using SW_ONLY_MODE, which connects PHY0 to MAC1 on the internal
  490. * switch, which is connected to GMAC1 on the SoC. GMAC0 is unused.
  491. */
  492. static void __init rbmapl_setup(void)
  493. {
  494. u32 flags = RBSPI_HAS_WLAN0;
  495. if (rbspi_platform_setup())
  496. return;
  497. rbspi_peripherals_setup(flags);
  498. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  499. rbspi_network_setup(flags, 0, 1, 0);
  500. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmapl_leds), rbmapl_leds);
  501. /* mAP lite has a single reset button as gpio 16 */
  502. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  503. ARRAY_SIZE(rbspi_gpio_keys_reset16),
  504. rbspi_gpio_keys_reset16);
  505. /* clear internal multiplexing */
  506. ath79_gpio_output_select(RBMAPL_GPIO_LED_ETH, AR934X_GPIO_OUT_GPIO);
  507. ath79_gpio_output_select(RBMAPL_GPIO_LED_POWER, AR934X_GPIO_OUT_GPIO);
  508. }
  509. /*
  510. * Init the hAP lite hardware (QCA953x).
  511. * The 941-2nD (hAP lite) has 4 ethernet ports, with port 2-4
  512. * being assigned to LAN on the casing, and port 1 being assigned
  513. * to "internet" (WAN) on the casing. Port 1 is connected to PHY3.
  514. * Since WAN is neither PHY0 nor PHY4, we cannot use GMAC0 with this device.
  515. */
  516. static void __init rbhapl_setup(void)
  517. {
  518. u32 flags = RBSPI_HAS_WLAN0;
  519. if (rbspi_platform_setup())
  520. return;
  521. rbspi_peripherals_setup(flags);
  522. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 4 */
  523. rbspi_network_setup(flags, 0, 4, 0);
  524. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbhapl_leds), rbhapl_leds);
  525. /* hAP lite has a single reset button as gpio 16 */
  526. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  527. ARRAY_SIZE(rbspi_gpio_keys_reset16),
  528. rbspi_gpio_keys_reset16);
  529. }
  530. /*
  531. * The hAP, hAP ac lite, hEX lite and hEX PoE lite share the same platform
  532. */
  533. static void __init rbspi_952_750r2_setup(u32 flags)
  534. {
  535. if (flags & RBSPI_HAS_SSR)
  536. rbspi_spi_cs_gpios[1] = RB952_GPIO_SSR_CS;
  537. rbspi_peripherals_setup(flags);
  538. /*
  539. * GMAC1 is HW MAC + 1, WLAN0 MAC IS HW MAC + 5 (hAP),
  540. * WLAN1 MAC IS HW MAC + 6 (hAP ac lite)
  541. */
  542. rbspi_network_setup(flags, 1, 5, 6);
  543. if (flags & RBSPI_HAS_USB)
  544. gpio_request_one(RB952_GPIO_USB_POWER,
  545. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  546. "USB power");
  547. if (flags & RBSPI_HAS_POE)
  548. gpio_request_one(RB952_GPIO_POE_POWER,
  549. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  550. "POE power");
  551. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb952_leds), rb952_leds);
  552. /* These devices have a single reset button as gpio 16 */
  553. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  554. ARRAY_SIZE(rbspi_gpio_keys_reset16),
  555. rbspi_gpio_keys_reset16);
  556. }
  557. /*
  558. * Init the hAP (ac lite) hardware (QCA953x).
  559. * The 951Ui-2nD (hAP) has 5 ethernet ports, with ports 2-5 being assigned
  560. * to LAN on the casing, and port 1 being assigned to "internet" (WAN).
  561. * Port 1 is connected to PHY4 (the ports are labelled in reverse physical
  562. * number), so the SoC can be set to connect GMAC0 to PHY4 and GMAC1 to the
  563. * internal switch for the LAN ports.
  564. * The device also has USB, PoE output and an SSR used for LED multiplexing.
  565. * The 952Ui-5ac2nD (hAP ac lite) is nearly identical to the hAP, it adds a
  566. * QCA9887 5GHz radio via PCI and moves 2.4GHz from WLAN0 to WLAN1.
  567. */
  568. static void __init rb952_setup(void)
  569. {
  570. u32 flags = RBSPI_HAS_WAN4 | RBSPI_HAS_USB |
  571. RBSPI_HAS_SSR | RBSPI_HAS_POE;
  572. if (rbspi_platform_setup())
  573. return;
  574. /* differentiate the hAP from the hAP ac lite */
  575. if (strstr(mips_get_machine_name(), "952Ui-5ac2nD"))
  576. flags |= RBSPI_HAS_WLAN1 | RBSPI_HAS_PCI;
  577. else
  578. flags |= RBSPI_HAS_WLAN0;
  579. rbspi_952_750r2_setup(flags);
  580. }
  581. /*
  582. * Init the hEX (PoE) lite hardware (QCA953x).
  583. * The 750UP r2 (hEX PoE lite) is nearly identical to the hAP, only without
  584. * WLAN. The 750 r2 (hEX lite) is nearly identical to the 750UP r2, only
  585. * without USB and POE. It shares the same bootloader board identifier.
  586. */
  587. static void __init rb750upr2_setup(void)
  588. {
  589. u32 flags = RBSPI_HAS_WAN4 | RBSPI_HAS_SSR;
  590. if (rbspi_platform_setup())
  591. return;
  592. /* differentiate the hEX lite from the hEX PoE lite */
  593. if (strstr(mips_get_machine_name(), "750UP r2"))
  594. flags |= RBSPI_HAS_USB | RBSPI_HAS_POE;
  595. rbspi_952_750r2_setup(flags);
  596. }
  597. /*
  598. * Init the LHG hardware (AR9344).
  599. * The LHG 5nD has a single ethernet port connected to PHY0.
  600. * Wireless is provided via 5GHz WLAN1.
  601. */
  602. static void __init rblhg_setup(void)
  603. {
  604. u32 flags = RBSPI_HAS_WLAN1 | RBSPI_HAS_MDIO1;
  605. if (rbspi_platform_setup())
  606. return;
  607. rbspi_peripherals_setup(flags);
  608. /* GMAC1 is HW MAC, WLAN1 MAC is HW MAC + 1 */
  609. rbspi_network_setup(flags, 0, 0, 1);
  610. ath79_register_leds_gpio(-1, ARRAY_SIZE(rblhg_leds), rblhg_leds);
  611. ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
  612. ARRAY_SIZE(rblhg_gpio_keys),
  613. rblhg_gpio_keys);
  614. }
  615. /*
  616. * Init the wAP hardware (EXPERIMENTAL).
  617. * The wAP 2nD has a single ethernet port.
  618. */
  619. static void __init rbwap_setup(void)
  620. {
  621. u32 flags = RBSPI_HAS_WLAN0;
  622. if (rbspi_platform_setup())
  623. return;
  624. rbspi_peripherals_setup(flags);
  625. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  626. rbspi_network_setup(flags, 0, 1, 0);
  627. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwap_leds), rbwap_leds);
  628. }
  629. /*
  630. * Init the cAP hardware (EXPERIMENTAL).
  631. * The cAP 2nD has a single ethernet port, and a global LED switch.
  632. */
  633. static void __init rbcap_setup(void)
  634. {
  635. u32 flags = RBSPI_HAS_WLAN0;
  636. if (rbspi_platform_setup())
  637. return;
  638. rbspi_peripherals_setup(flags);
  639. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
  640. rbspi_network_setup(flags, 0, 1, 0);
  641. gpio_request_one(RBCAP_GPIO_LED_ALL,
  642. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  643. "LEDs enable");
  644. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbcap_leds), rbcap_leds);
  645. }
  646. /*
  647. * Init the mAP hardware (EXPERIMENTAL).
  648. * The mAP 2nD has two ethernet ports, PoE output and an SSR for LED
  649. * multiplexing.
  650. */
  651. static void __init rbmap_setup(void)
  652. {
  653. u32 flags = RBSPI_HAS_WLAN0 | RBSPI_HAS_SSR | RBSPI_HAS_POE;
  654. if (rbspi_platform_setup())
  655. return;
  656. rbspi_spi_cs_gpios[1] = RBMAP_GPIO_SSR_CS;
  657. rbspi_peripherals_setup(flags);
  658. /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 2 */
  659. rbspi_network_setup(flags, 0, 2, 0);
  660. if (flags & RBSPI_HAS_POE)
  661. gpio_request_one(RBMAP_GPIO_POE_POWER,
  662. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  663. "POE power");
  664. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmap_leds), rbmap_leds);
  665. }
  666. MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAPL, "map-hb", rbmapl_setup);
  667. MIPS_MACHINE_NONAME(ATH79_MACH_RB_941, "H951L", rbhapl_setup);
  668. MIPS_MACHINE_NONAME(ATH79_MACH_RB_952, "952-hb", rb952_setup);
  669. MIPS_MACHINE_NONAME(ATH79_MACH_RB_750UPR2, "750-hb", rb750upr2_setup);
  670. MIPS_MACHINE_NONAME(ATH79_MACH_RB_LHG5, "lhg", rblhg_setup);
  671. MIPS_MACHINE_NONAME(ATH79_MACH_RB_WAP, "wap-hb", rbwap_setup);
  672. MIPS_MACHINE_NONAME(ATH79_MACH_RB_CAP, "cap-hb", rbcap_setup);
  673. MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAP, "map2-hb", rbmap_setup);