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
7 Move device registration code into its own file to allow sharing it
8 between board implementations.
10 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
12 arch/mips/bcm63xx/boards/Makefile | 1 +
13 arch/mips/bcm63xx/boards/board_bcm963xx.c | 188 +-------------------------
14 arch/mips/bcm63xx/boards/board_common.c | 215 ++++++++++++++++++++++++++++++
15 arch/mips/bcm63xx/boards/board_common.h | 8 ++
16 4 files changed, 223 insertions(+), 183 deletions(-)
17 create mode 100644 arch/mips/bcm63xx/boards/board_common.c
18 create mode 100644 arch/mips/bcm63xx/boards/board_common.h
20 --- a/arch/mips/bcm63xx/boards/Makefile
21 +++ b/arch/mips/bcm63xx/boards/Makefile
23 +obj-y += board_common.o
24 obj-$(CONFIG_BOARD_BCM963XX) += board_bcm963xx.o
25 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
26 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/string.h>
31 -#include <linux/platform_device.h>
32 -#include <linux/ssb/ssb.h>
33 #include <asm/addrspace.h>
34 #include <bcm63xx_board.h>
35 #include <bcm63xx_cpu.h>
36 -#include <bcm63xx_dev_uart.h>
37 #include <bcm63xx_regs.h>
38 #include <bcm63xx_io.h>
39 #include <bcm63xx_nvram.h>
40 -#include <bcm63xx_dev_pci.h>
41 -#include <bcm63xx_dev_enet.h>
42 -#include <bcm63xx_dev_flash.h>
43 -#include <bcm63xx_dev_hsspi.h>
44 -#include <bcm63xx_dev_pcmcia.h>
45 -#include <bcm63xx_dev_spi.h>
46 -#include <bcm63xx_dev_usb_ehci.h>
47 -#include <bcm63xx_dev_usb_ohci.h>
48 -#include <bcm63xx_dev_usb_usbd.h>
49 #include <board_bcm963xx.h>
51 +#include "board_common.h"
53 #include <uapi/linux/bcm933xx_hcs.h>
56 #define HCS_OFFSET_128K 0x20000
58 -static struct board_info board;
63 @@ -695,52 +683,6 @@ static const struct board_info __initcon
67 - * Register a sane SPROMv2 to make the on-board
70 -#ifdef CONFIG_SSB_PCIHOST
71 -static struct ssb_sprom bcm63xx_sprom = {
74 - .country_code = 0x0,
75 - .ant_available_bg = 0x3,
86 - .maxpwr_bg = 0x004c,
88 - .boardflags_lo = 0x2848,
89 - .boardflags_hi = 0x0000,
92 -int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
94 - if (bus->bustype == SSB_BUSTYPE_PCI) {
95 - memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
98 - pr_err("unable to fill SPROM for given bustype\n");
105 - * return board name for /proc/cpuinfo
107 -const char *board_get_name(void)
113 * early init callback, read nvram data from flash and checksum it
115 void __init board_prom_init(void)
116 @@ -785,137 +727,15 @@ void __init board_prom_init(void)
117 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
119 /* copy, board desc array is marked initdata */
120 - memcpy(&board, bcm963xx_boards[i], sizeof(board));
121 + board_early_setup(bcm963xx_boards[i]);
125 - /* bail out if board is not found, will complain later */
126 - if (!board.name[0]) {
127 + /* warn if board is not found, will complain later */
128 + if (i == ARRAY_SIZE(bcm963xx_boards)) {
130 memcpy(name, board_name, 16);
132 pr_err("unknown bcm963xx board: %s\n", name);
136 - /* setup pin multiplexing depending on board enabled device,
137 - * this has to be done this early since PCI init is done
138 - * inside arch_initcall */
142 - if (board.has_pci) {
143 - bcm63xx_pci_enabled = 1;
144 - if (BCMCPU_IS_6348())
145 - val |= GPIO_MODE_6348_G2_PCI;
149 - if (board.has_pccard) {
150 - if (BCMCPU_IS_6348())
151 - val |= GPIO_MODE_6348_G1_MII_PCCARD;
154 - if (board.has_enet0 && !board.enet0.use_internal_phy) {
155 - if (BCMCPU_IS_6348())
156 - val |= GPIO_MODE_6348_G3_EXT_MII |
157 - GPIO_MODE_6348_G0_EXT_MII;
160 - if (board.has_enet1 && !board.enet1.use_internal_phy) {
161 - if (BCMCPU_IS_6348())
162 - val |= GPIO_MODE_6348_G3_EXT_MII |
163 - GPIO_MODE_6348_G0_EXT_MII;
166 - bcm_gpio_writel(val, GPIO_MODE_REG);
170 - * second stage init callback, good time to panic if we couldn't
171 - * identify on which board we're running since early printk is working
173 -void __init board_setup(void)
175 - if (!board.name[0])
176 - panic("unable to detect bcm963xx board");
177 - pr_info("board name: %s\n", board.name);
179 - /* make sure we're running on expected cpu */
180 - if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
181 - panic("unexpected CPU for bcm963xx board");
184 -static struct gpio_led_platform_data bcm63xx_led_data;
186 -static struct platform_device bcm63xx_gpio_leds = {
187 - .name = "leds-gpio",
189 - .dev.platform_data = &bcm63xx_led_data,
193 - * third stage init callback, register all board devices.
195 -int __init board_register_devices(void)
197 - if (board.has_uart0)
198 - bcm63xx_uart_register(0);
200 - if (board.has_uart1)
201 - bcm63xx_uart_register(1);
203 - if (board.has_pccard)
204 - bcm63xx_pcmcia_register();
206 - if (board.has_enet0 &&
207 - !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
208 - bcm63xx_enet_register(0, &board.enet0);
210 - if (board.has_enet1 &&
211 - !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
212 - bcm63xx_enet_register(1, &board.enet1);
214 - if (board.has_enetsw &&
215 - !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
216 - bcm63xx_enetsw_register(&board.enetsw);
218 - if (board.has_usbd)
219 - bcm63xx_usbd_register(&board.usbd);
221 - if (board.has_ehci0)
222 - bcm63xx_ehci_register();
224 - if (board.has_ohci0)
225 - bcm63xx_ohci_register();
227 - /* Generate MAC address for WLAN and register our SPROM,
228 - * do this after registering enet devices
230 -#ifdef CONFIG_SSB_PCIHOST
231 - if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
232 - memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
233 - memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
234 - if (ssb_arch_register_fallback_sprom(
235 - &bcm63xx_get_fallback_sprom) < 0)
236 - pr_err("failed to register fallback SPROM\n");
240 - bcm63xx_spi_register();
242 - bcm63xx_hsspi_register();
244 - bcm63xx_flash_register();
246 - bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
247 - bcm63xx_led_data.leds = board.leds;
249 - platform_device_register(&bcm63xx_gpio_leds);
251 - if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
252 - gpio_request_one(board.ephy_reset_gpio,
253 - board.ephy_reset_gpio_flags, "ephy-reset");
258 +++ b/arch/mips/bcm63xx/boards/board_common.c
261 + * This file is subject to the terms and conditions of the GNU General Public
262 + * License. See the file "COPYING" in the main directory of this archive
263 + * for more details.
265 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
266 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
269 +#include <linux/init.h>
270 +#include <linux/kernel.h>
271 +#include <linux/string.h>
272 +#include <linux/platform_device.h>
273 +#include <linux/ssb/ssb.h>
274 +#include <asm/addrspace.h>
275 +#include <bcm63xx_board.h>
276 +#include <bcm63xx_cpu.h>
277 +#include <bcm63xx_dev_uart.h>
278 +#include <bcm63xx_regs.h>
279 +#include <bcm63xx_io.h>
280 +#include <bcm63xx_nvram.h>
281 +#include <bcm63xx_gpio.h>
282 +#include <bcm63xx_dev_pci.h>
283 +#include <bcm63xx_dev_enet.h>
284 +#include <bcm63xx_dev_flash.h>
285 +#include <bcm63xx_dev_hsspi.h>
286 +#include <bcm63xx_dev_pcmcia.h>
287 +#include <bcm63xx_dev_spi.h>
288 +#include <bcm63xx_dev_usb_ehci.h>
289 +#include <bcm63xx_dev_usb_ohci.h>
290 +#include <bcm63xx_dev_usb_usbd.h>
291 +#include <board_bcm963xx.h>
293 +#define PFX "board: "
295 +static struct board_info board;
298 + * Register a sane SPROMv2 to make the on-board
299 + * bcm4318 WLAN work
301 +#ifdef CONFIG_SSB_PCIHOST
302 +static struct ssb_sprom bcm63xx_sprom = {
305 + .country_code = 0x0,
306 + .ant_available_bg = 0x3,
317 + .maxpwr_bg = 0x004c,
319 + .boardflags_lo = 0x2848,
320 + .boardflags_hi = 0x0000,
323 +int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
325 + if (bus->bustype == SSB_BUSTYPE_PCI) {
326 + memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
329 + printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
336 + * return board name for /proc/cpuinfo
338 +const char *board_get_name(void)
344 + * setup board for device registration
346 +void __init board_early_setup(const struct board_info *target)
350 + memcpy(&board, target, sizeof(board));
352 + /* setup pin multiplexing depending on board enabled device,
353 + * this has to be done this early since PCI init is done
354 + * inside arch_initcall */
358 + if (board.has_pci) {
359 + bcm63xx_pci_enabled = 1;
360 + if (BCMCPU_IS_6348())
361 + val |= GPIO_MODE_6348_G2_PCI;
365 + if (board.has_pccard) {
366 + if (BCMCPU_IS_6348())
367 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
370 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
371 + if (BCMCPU_IS_6348())
372 + val |= GPIO_MODE_6348_G3_EXT_MII |
373 + GPIO_MODE_6348_G0_EXT_MII;
376 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
377 + if (BCMCPU_IS_6348())
378 + val |= GPIO_MODE_6348_G3_EXT_MII |
379 + GPIO_MODE_6348_G0_EXT_MII;
382 + bcm_gpio_writel(val, GPIO_MODE_REG);
387 + * second stage init callback, good time to panic if we couldn't
388 + * identify on which board we're running since early printk is working
390 +void __init board_setup(void)
392 + if (!board.name[0])
393 + panic("unable to detect bcm963xx board");
394 + printk(KERN_INFO PFX "board name: %s\n", board.name);
396 + /* make sure we're running on expected cpu */
397 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
398 + panic("unexpected CPU for bcm963xx board");
401 +static struct gpio_led_platform_data bcm63xx_led_data;
403 +static struct platform_device bcm63xx_gpio_leds = {
404 + .name = "leds-gpio",
406 + .dev.platform_data = &bcm63xx_led_data,
410 + * third stage init callback, register all board devices.
412 +int __init board_register_devices(void)
414 + if (board.has_uart0)
415 + bcm63xx_uart_register(0);
417 + if (board.has_uart1)
418 + bcm63xx_uart_register(1);
420 + if (board.has_pccard)
421 + bcm63xx_pcmcia_register();
423 + if (board.has_enet0 &&
424 + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
425 + bcm63xx_enet_register(0, &board.enet0);
427 + if (board.has_enet1 &&
428 + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
429 + bcm63xx_enet_register(1, &board.enet1);
431 + if (board.has_enetsw &&
432 + !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
433 + bcm63xx_enetsw_register(&board.enetsw);
435 + if (board.has_usbd)
436 + bcm63xx_usbd_register(&board.usbd);
438 + if (board.has_ehci0)
439 + bcm63xx_ehci_register();
441 + if (board.has_ohci0)
442 + bcm63xx_ohci_register();
444 + /* Generate MAC address for WLAN and register our SPROM,
445 + * do this after registering enet devices
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");
457 + bcm63xx_spi_register();
459 + bcm63xx_hsspi_register();
461 + bcm63xx_flash_register();
463 + bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
464 + bcm63xx_led_data.leds = board.leds;
466 + platform_device_register(&bcm63xx_gpio_leds);
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");
475 +++ b/arch/mips/bcm63xx/boards/board_common.h
477 +#ifndef __BOARD_COMMON_H
478 +#define __BOARD_COMMON_H
480 +#include <board_bcm963xx.h>
482 +void board_early_setup(const struct board_info *board);
484 +#endif /* __BOARD_COMMON_H */