207-MIPS-BCM63XX-move-device-registration-code-into-its-.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. From 5a50cb0d53344a2429831b00925d6183d4d332e1 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <[email protected]>
  3. Date: Sun, 9 Mar 2014 03:54:05 +0100
  4. Subject: [PATCH 40/44] MIPS: BCM63XX: move device registration code into its
  5. own file
  6. Move device registration code into its own file to allow sharing it
  7. between board implementations.
  8. Signed-off-by: Jonas Gorski <[email protected]>
  9. ---
  10. arch/mips/bcm63xx/boards/Makefile | 1 +
  11. arch/mips/bcm63xx/boards/board_bcm963xx.c | 188 +-------------------------
  12. arch/mips/bcm63xx/boards/board_common.c | 215 ++++++++++++++++++++++++++++++
  13. arch/mips/bcm63xx/boards/board_common.h | 8 ++
  14. 4 files changed, 223 insertions(+), 183 deletions(-)
  15. create mode 100644 arch/mips/bcm63xx/boards/board_common.c
  16. create mode 100644 arch/mips/bcm63xx/boards/board_common.h
  17. --- a/arch/mips/bcm63xx/boards/Makefile
  18. +++ b/arch/mips/bcm63xx/boards/Makefile
  19. @@ -1 +1,2 @@
  20. +obj-y += board_common.o
  21. obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
  22. --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
  23. +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
  24. @@ -12,33 +12,21 @@
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/string.h>
  28. -#include <linux/platform_device.h>
  29. -#include <linux/ssb/ssb.h>
  30. #include <asm/addrspace.h>
  31. #include <bcm63xx_board.h>
  32. #include <bcm63xx_cpu.h>
  33. -#include <bcm63xx_dev_uart.h>
  34. #include <bcm63xx_regs.h>
  35. #include <bcm63xx_io.h>
  36. #include <bcm63xx_nvram.h>
  37. -#include <bcm63xx_dev_pci.h>
  38. -#include <bcm63xx_dev_enet.h>
  39. -#include <bcm63xx_dev_flash.h>
  40. -#include <bcm63xx_dev_hsspi.h>
  41. -#include <bcm63xx_dev_pcmcia.h>
  42. -#include <bcm63xx_dev_spi.h>
  43. -#include <bcm63xx_dev_usb_ehci.h>
  44. -#include <bcm63xx_dev_usb_ohci.h>
  45. -#include <bcm63xx_dev_usb_usbd.h>
  46. #include <board_bcm963xx.h>
  47. +#include "board_common.h"
  48. +
  49. #include <uapi/linux/bcm933xx_hcs.h>
  50. #define HCS_OFFSET_128K 0x20000
  51. -static struct board_info board;
  52. -
  53. /*
  54. * known 3368 boards
  55. */
  56. @@ -695,52 +683,6 @@ static const struct board_info __initcon
  57. };
  58. /*
  59. - * Register a sane SPROMv2 to make the on-board
  60. - * bcm4318 WLAN work
  61. - */
  62. -#ifdef CONFIG_SSB_PCIHOST
  63. -static struct ssb_sprom bcm63xx_sprom = {
  64. - .revision = 0x02,
  65. - .board_rev = 0x17,
  66. - .country_code = 0x0,
  67. - .ant_available_bg = 0x3,
  68. - .pa0b0 = 0x15ae,
  69. - .pa0b1 = 0xfa85,
  70. - .pa0b2 = 0xfe8d,
  71. - .pa1b0 = 0xffff,
  72. - .pa1b1 = 0xffff,
  73. - .pa1b2 = 0xffff,
  74. - .gpio0 = 0xff,
  75. - .gpio1 = 0xff,
  76. - .gpio2 = 0xff,
  77. - .gpio3 = 0xff,
  78. - .maxpwr_bg = 0x004c,
  79. - .itssi_bg = 0x00,
  80. - .boardflags_lo = 0x2848,
  81. - .boardflags_hi = 0x0000,
  82. -};
  83. -
  84. -int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
  85. -{
  86. - if (bus->bustype == SSB_BUSTYPE_PCI) {
  87. - memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
  88. - return 0;
  89. - } else {
  90. - pr_err("unable to fill SPROM for given bustype\n");
  91. - return -EINVAL;
  92. - }
  93. -}
  94. -#endif
  95. -
  96. -/*
  97. - * return board name for /proc/cpuinfo
  98. - */
  99. -const char *board_get_name(void)
  100. -{
  101. - return board.name;
  102. -}
  103. -
  104. -/*
  105. * early init callback, read nvram data from flash and checksum it
  106. */
  107. void __init board_prom_init(void)
  108. @@ -785,137 +727,15 @@ void __init board_prom_init(void)
  109. if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
  110. continue;
  111. /* copy, board desc array is marked initdata */
  112. - memcpy(&board, bcm963xx_boards[i], sizeof(board));
  113. + board_early_setup(bcm963xx_boards[i]);
  114. break;
  115. }
  116. - /* bail out if board is not found, will complain later */
  117. - if (!board.name[0]) {
  118. + /* warn if board is not found, will complain later */
  119. + if (i == ARRAY_SIZE(bcm963xx_boards)) {
  120. char name[17];
  121. memcpy(name, board_name, 16);
  122. name[16] = 0;
  123. pr_err("unknown bcm963xx board: %s\n", name);
  124. - return;
  125. - }
  126. -
  127. - /* setup pin multiplexing depending on board enabled device,
  128. - * this has to be done this early since PCI init is done
  129. - * inside arch_initcall */
  130. - val = 0;
  131. -
  132. -#ifdef CONFIG_PCI
  133. - if (board.has_pci) {
  134. - bcm63xx_pci_enabled = 1;
  135. - if (BCMCPU_IS_6348())
  136. - val |= GPIO_MODE_6348_G2_PCI;
  137. }
  138. -#endif
  139. -
  140. - if (board.has_pccard) {
  141. - if (BCMCPU_IS_6348())
  142. - val |= GPIO_MODE_6348_G1_MII_PCCARD;
  143. - }
  144. -
  145. - if (board.has_enet0 && !board.enet0.use_internal_phy) {
  146. - if (BCMCPU_IS_6348())
  147. - val |= GPIO_MODE_6348_G3_EXT_MII |
  148. - GPIO_MODE_6348_G0_EXT_MII;
  149. - }
  150. -
  151. - if (board.has_enet1 && !board.enet1.use_internal_phy) {
  152. - if (BCMCPU_IS_6348())
  153. - val |= GPIO_MODE_6348_G3_EXT_MII |
  154. - GPIO_MODE_6348_G0_EXT_MII;
  155. - }
  156. -
  157. - bcm_gpio_writel(val, GPIO_MODE_REG);
  158. -}
  159. -
  160. -/*
  161. - * second stage init callback, good time to panic if we couldn't
  162. - * identify on which board we're running since early printk is working
  163. - */
  164. -void __init board_setup(void)
  165. -{
  166. - if (!board.name[0])
  167. - panic("unable to detect bcm963xx board");
  168. - pr_info("board name: %s\n", board.name);
  169. -
  170. - /* make sure we're running on expected cpu */
  171. - if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
  172. - panic("unexpected CPU for bcm963xx board");
  173. -}
  174. -
  175. -static struct gpio_led_platform_data bcm63xx_led_data;
  176. -
  177. -static struct platform_device bcm63xx_gpio_leds = {
  178. - .name = "leds-gpio",
  179. - .id = 0,
  180. - .dev.platform_data = &bcm63xx_led_data,
  181. -};
  182. -
  183. -/*
  184. - * third stage init callback, register all board devices.
  185. - */
  186. -int __init board_register_devices(void)
  187. -{
  188. - if (board.has_uart0)
  189. - bcm63xx_uart_register(0);
  190. -
  191. - if (board.has_uart1)
  192. - bcm63xx_uart_register(1);
  193. -
  194. - if (board.has_pccard)
  195. - bcm63xx_pcmcia_register();
  196. -
  197. - if (board.has_enet0 &&
  198. - !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
  199. - bcm63xx_enet_register(0, &board.enet0);
  200. -
  201. - if (board.has_enet1 &&
  202. - !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
  203. - bcm63xx_enet_register(1, &board.enet1);
  204. -
  205. - if (board.has_enetsw &&
  206. - !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
  207. - bcm63xx_enetsw_register(&board.enetsw);
  208. -
  209. - if (board.has_usbd)
  210. - bcm63xx_usbd_register(&board.usbd);
  211. -
  212. - if (board.has_ehci0)
  213. - bcm63xx_ehci_register();
  214. -
  215. - if (board.has_ohci0)
  216. - bcm63xx_ohci_register();
  217. -
  218. - /* Generate MAC address for WLAN and register our SPROM,
  219. - * do this after registering enet devices
  220. - */
  221. -#ifdef CONFIG_SSB_PCIHOST
  222. - if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
  223. - memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  224. - memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  225. - if (ssb_arch_register_fallback_sprom(
  226. - &bcm63xx_get_fallback_sprom) < 0)
  227. - pr_err("failed to register fallback SPROM\n");
  228. - }
  229. -#endif
  230. -
  231. - bcm63xx_spi_register();
  232. -
  233. - bcm63xx_hsspi_register();
  234. -
  235. - bcm63xx_flash_register();
  236. -
  237. - bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
  238. - bcm63xx_led_data.leds = board.leds;
  239. -
  240. - platform_device_register(&bcm63xx_gpio_leds);
  241. -
  242. - if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
  243. - gpio_request_one(board.ephy_reset_gpio,
  244. - board.ephy_reset_gpio_flags, "ephy-reset");
  245. -
  246. - return 0;
  247. }
  248. --- /dev/null
  249. +++ b/arch/mips/bcm63xx/boards/board_common.c
  250. @@ -0,0 +1,214 @@
  251. +/*
  252. + * This file is subject to the terms and conditions of the GNU General Public
  253. + * License. See the file "COPYING" in the main directory of this archive
  254. + * for more details.
  255. + *
  256. + * Copyright (C) 2008 Maxime Bizon <[email protected]>
  257. + * Copyright (C) 2008 Florian Fainelli <[email protected]>
  258. + */
  259. +
  260. +#include <linux/init.h>
  261. +#include <linux/kernel.h>
  262. +#include <linux/string.h>
  263. +#include <linux/platform_device.h>
  264. +#include <linux/ssb/ssb.h>
  265. +#include <asm/addrspace.h>
  266. +#include <bcm63xx_board.h>
  267. +#include <bcm63xx_cpu.h>
  268. +#include <bcm63xx_dev_uart.h>
  269. +#include <bcm63xx_regs.h>
  270. +#include <bcm63xx_io.h>
  271. +#include <bcm63xx_nvram.h>
  272. +#include <bcm63xx_gpio.h>
  273. +#include <bcm63xx_dev_pci.h>
  274. +#include <bcm63xx_dev_enet.h>
  275. +#include <bcm63xx_dev_flash.h>
  276. +#include <bcm63xx_dev_hsspi.h>
  277. +#include <bcm63xx_dev_pcmcia.h>
  278. +#include <bcm63xx_dev_spi.h>
  279. +#include <bcm63xx_dev_usb_ehci.h>
  280. +#include <bcm63xx_dev_usb_ohci.h>
  281. +#include <bcm63xx_dev_usb_usbd.h>
  282. +#include <board_bcm963xx.h>
  283. +
  284. +#define PFX "board: "
  285. +
  286. +static struct board_info board;
  287. +
  288. +/*
  289. + * Register a sane SPROMv2 to make the on-board
  290. + * bcm4318 WLAN work
  291. + */
  292. +#ifdef CONFIG_SSB_PCIHOST
  293. +static struct ssb_sprom bcm63xx_sprom = {
  294. + .revision = 0x02,
  295. + .board_rev = 0x17,
  296. + .country_code = 0x0,
  297. + .ant_available_bg = 0x3,
  298. + .pa0b0 = 0x15ae,
  299. + .pa0b1 = 0xfa85,
  300. + .pa0b2 = 0xfe8d,
  301. + .pa1b0 = 0xffff,
  302. + .pa1b1 = 0xffff,
  303. + .pa1b2 = 0xffff,
  304. + .gpio0 = 0xff,
  305. + .gpio1 = 0xff,
  306. + .gpio2 = 0xff,
  307. + .gpio3 = 0xff,
  308. + .maxpwr_bg = 0x004c,
  309. + .itssi_bg = 0x00,
  310. + .boardflags_lo = 0x2848,
  311. + .boardflags_hi = 0x0000,
  312. +};
  313. +
  314. +int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
  315. +{
  316. + if (bus->bustype == SSB_BUSTYPE_PCI) {
  317. + memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
  318. + return 0;
  319. + } else {
  320. + printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
  321. + return -EINVAL;
  322. + }
  323. +}
  324. +#endif
  325. +
  326. +/*
  327. + * return board name for /proc/cpuinfo
  328. + */
  329. +const char *board_get_name(void)
  330. +{
  331. + return board.name;
  332. +}
  333. +
  334. +/*
  335. + * setup board for device registration
  336. + */
  337. +void __init board_early_setup(const struct board_info *target)
  338. +{
  339. + u32 val;
  340. +
  341. + memcpy(&board, target, sizeof(board));
  342. +
  343. + /* setup pin multiplexing depending on board enabled device,
  344. + * this has to be done this early since PCI init is done
  345. + * inside arch_initcall */
  346. + val = 0;
  347. +
  348. +#ifdef CONFIG_PCI
  349. + if (board.has_pci) {
  350. + bcm63xx_pci_enabled = 1;
  351. + if (BCMCPU_IS_6348())
  352. + val |= GPIO_MODE_6348_G2_PCI;
  353. + }
  354. +#endif
  355. +
  356. + if (board.has_pccard) {
  357. + if (BCMCPU_IS_6348())
  358. + val |= GPIO_MODE_6348_G1_MII_PCCARD;
  359. + }
  360. +
  361. + if (board.has_enet0 && !board.enet0.use_internal_phy) {
  362. + if (BCMCPU_IS_6348())
  363. + val |= GPIO_MODE_6348_G3_EXT_MII |
  364. + GPIO_MODE_6348_G0_EXT_MII;
  365. + }
  366. +
  367. + if (board.has_enet1 && !board.enet1.use_internal_phy) {
  368. + if (BCMCPU_IS_6348())
  369. + val |= GPIO_MODE_6348_G3_EXT_MII |
  370. + GPIO_MODE_6348_G0_EXT_MII;
  371. + }
  372. +
  373. + bcm_gpio_writel(val, GPIO_MODE_REG);
  374. +}
  375. +
  376. +
  377. +/*
  378. + * second stage init callback, good time to panic if we couldn't
  379. + * identify on which board we're running since early printk is working
  380. + */
  381. +void __init board_setup(void)
  382. +{
  383. + if (!board.name[0])
  384. + panic("unable to detect bcm963xx board");
  385. + printk(KERN_INFO PFX "board name: %s\n", board.name);
  386. +
  387. + /* make sure we're running on expected cpu */
  388. + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
  389. + panic("unexpected CPU for bcm963xx board");
  390. +}
  391. +
  392. +static struct gpio_led_platform_data bcm63xx_led_data;
  393. +
  394. +static struct platform_device bcm63xx_gpio_leds = {
  395. + .name = "leds-gpio",
  396. + .id = 0,
  397. + .dev.platform_data = &bcm63xx_led_data,
  398. +};
  399. +
  400. +/*
  401. + * third stage init callback, register all board devices.
  402. + */
  403. +int __init board_register_devices(void)
  404. +{
  405. + if (board.has_uart0)
  406. + bcm63xx_uart_register(0);
  407. +
  408. + if (board.has_uart1)
  409. + bcm63xx_uart_register(1);
  410. +
  411. + if (board.has_pccard)
  412. + bcm63xx_pcmcia_register();
  413. +
  414. + if (board.has_enet0 &&
  415. + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
  416. + bcm63xx_enet_register(0, &board.enet0);
  417. +
  418. + if (board.has_enet1 &&
  419. + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
  420. + bcm63xx_enet_register(1, &board.enet1);
  421. +
  422. + if (board.has_enetsw &&
  423. + !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
  424. + bcm63xx_enetsw_register(&board.enetsw);
  425. +
  426. + if (board.has_usbd)
  427. + bcm63xx_usbd_register(&board.usbd);
  428. +
  429. + if (board.has_ehci0)
  430. + bcm63xx_ehci_register();
  431. +
  432. + if (board.has_ohci0)
  433. + bcm63xx_ohci_register();
  434. +
  435. + /* Generate MAC address for WLAN and register our SPROM,
  436. + * do this after registering enet devices
  437. + */
  438. +#ifdef CONFIG_SSB_PCIHOST
  439. + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
  440. + memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  441. + memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  442. + if (ssb_arch_register_fallback_sprom(
  443. + &bcm63xx_get_fallback_sprom) < 0)
  444. + pr_err(PFX "failed to register fallback SPROM\n");
  445. + }
  446. +#endif
  447. +
  448. + bcm63xx_spi_register();
  449. +
  450. + bcm63xx_hsspi_register();
  451. +
  452. + bcm63xx_flash_register();
  453. +
  454. + bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
  455. + bcm63xx_led_data.leds = board.leds;
  456. +
  457. + platform_device_register(&bcm63xx_gpio_leds);
  458. +
  459. + if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
  460. + gpio_request_one(board.ephy_reset_gpio,
  461. + board.ephy_reset_gpio_flags, "ephy-reset");
  462. +
  463. + return 0;
  464. +}
  465. --- /dev/null
  466. +++ b/arch/mips/bcm63xx/boards/board_common.h
  467. @@ -0,0 +1,8 @@
  468. +#ifndef __BOARD_COMMON_H
  469. +#define __BOARD_COMMON_H
  470. +
  471. +#include <board_bcm963xx.h>
  472. +
  473. +void board_early_setup(const struct board_info *board);
  474. +
  475. +#endif /* __BOARD_COMMON_H */