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

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