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

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