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_dsp.h>
43 -#include <bcm63xx_dev_flash.h>
44 -#include <bcm63xx_dev_hsspi.h>
45 -#include <bcm63xx_dev_pcmcia.h>
46 -#include <bcm63xx_dev_spi.h>
47 -#include <bcm63xx_dev_usb_ehci.h>
48 -#include <bcm63xx_dev_usb_ohci.h>
49 -#include <bcm63xx_dev_usb_usbd.h>
50 #include <board_bcm963xx.h>
52 +#include "board_common.h"
54 #include <uapi/linux/bcm933xx_hcs.h>
57 #define HCS_OFFSET_128K 0x20000
59 -static struct board_info board;
64 @@ -712,52 +699,6 @@ static const struct board_info __initcon
68 - * Register a sane SPROMv2 to make the on-board
71 -#ifdef CONFIG_SSB_PCIHOST
72 -static struct ssb_sprom bcm63xx_sprom = {
75 - .country_code = 0x0,
76 - .ant_available_bg = 0x3,
87 - .maxpwr_bg = 0x004c,
89 - .boardflags_lo = 0x2848,
90 - .boardflags_hi = 0x0000,
93 -int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
95 - if (bus->bustype == SSB_BUSTYPE_PCI) {
96 - memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
99 - pr_err("unable to fill SPROM for given bustype\n");
106 - * return board name for /proc/cpuinfo
108 -const char *board_get_name(void)
114 * early init callback, read nvram data from flash and checksum it
116 void __init board_prom_init(void)
117 @@ -802,140 +743,15 @@ void __init board_prom_init(void)
118 if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
120 /* copy, board desc array is marked initdata */
121 - memcpy(&board, bcm963xx_boards[i], sizeof(board));
122 + board_early_setup(bcm963xx_boards[i]);
126 - /* bail out if board is not found, will complain later */
127 - if (!board.name[0]) {
128 + /* warn if board is not found, will complain later */
129 + if (i == ARRAY_SIZE(bcm963xx_boards)) {
131 memcpy(name, board_name, 16);
133 pr_err("unknown bcm963xx board: %s\n", name);
137 - /* setup pin multiplexing depending on board enabled device,
138 - * this has to be done this early since PCI init is done
139 - * inside arch_initcall */
143 - if (board.has_pci) {
144 - bcm63xx_pci_enabled = 1;
145 - if (BCMCPU_IS_6348())
146 - val |= GPIO_MODE_6348_G2_PCI;
150 - if (board.has_pccard) {
151 - if (BCMCPU_IS_6348())
152 - val |= GPIO_MODE_6348_G1_MII_PCCARD;
155 - if (board.has_enet0 && !board.enet0.use_internal_phy) {
156 - if (BCMCPU_IS_6348())
157 - val |= GPIO_MODE_6348_G3_EXT_MII |
158 - GPIO_MODE_6348_G0_EXT_MII;
161 - if (board.has_enet1 && !board.enet1.use_internal_phy) {
162 - if (BCMCPU_IS_6348())
163 - val |= GPIO_MODE_6348_G3_EXT_MII |
164 - GPIO_MODE_6348_G0_EXT_MII;
167 - bcm_gpio_writel(val, GPIO_MODE_REG);
171 - * second stage init callback, good time to panic if we couldn't
172 - * identify on which board we're running since early printk is working
174 -void __init board_setup(void)
176 - if (!board.name[0])
177 - panic("unable to detect bcm963xx board");
178 - pr_info("board name: %s\n", board.name);
180 - /* make sure we're running on expected cpu */
181 - if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
182 - panic("unexpected CPU for bcm963xx board");
185 -static struct gpio_led_platform_data bcm63xx_led_data;
187 -static struct platform_device bcm63xx_gpio_leds = {
188 - .name = "leds-gpio",
190 - .dev.platform_data = &bcm63xx_led_data,
194 - * third stage init callback, register all board devices.
196 -int __init board_register_devices(void)
198 - if (board.has_uart0)
199 - bcm63xx_uart_register(0);
201 - if (board.has_uart1)
202 - bcm63xx_uart_register(1);
204 - if (board.has_pccard)
205 - bcm63xx_pcmcia_register();
207 - if (board.has_enet0 &&
208 - !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
209 - bcm63xx_enet_register(0, &board.enet0);
211 - if (board.has_enet1 &&
212 - !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
213 - bcm63xx_enet_register(1, &board.enet1);
215 - if (board.has_enetsw &&
216 - !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
217 - bcm63xx_enetsw_register(&board.enetsw);
219 - if (board.has_usbd)
220 - bcm63xx_usbd_register(&board.usbd);
222 - if (board.has_ehci0)
223 - bcm63xx_ehci_register();
225 - if (board.has_ohci0)
226 - bcm63xx_ohci_register();
229 - bcm63xx_dsp_register(&board.dsp);
231 - /* Generate MAC address for WLAN and register our SPROM,
232 - * do this after registering enet devices
234 -#ifdef CONFIG_SSB_PCIHOST
235 - if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
236 - memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
237 - memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
238 - if (ssb_arch_register_fallback_sprom(
239 - &bcm63xx_get_fallback_sprom) < 0)
240 - pr_err("failed to register fallback SPROM\n");
244 - bcm63xx_spi_register();
246 - bcm63xx_hsspi_register();
248 - bcm63xx_flash_register();
250 - bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
251 - bcm63xx_led_data.leds = board.leds;
253 - platform_device_register(&bcm63xx_gpio_leds);
255 - if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
256 - gpio_request_one(board.ephy_reset_gpio,
257 - board.ephy_reset_gpio_flags, "ephy-reset");
262 +++ b/arch/mips/bcm63xx/boards/board_common.c
265 + * This file is subject to the terms and conditions of the GNU General Public
266 + * License. See the file "COPYING" in the main directory of this archive
267 + * for more details.
269 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
270 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
273 +#include <linux/init.h>
274 +#include <linux/kernel.h>
275 +#include <linux/string.h>
276 +#include <linux/platform_device.h>
277 +#include <linux/ssb/ssb.h>
278 +#include <asm/addrspace.h>
279 +#include <bcm63xx_board.h>
280 +#include <bcm63xx_cpu.h>
281 +#include <bcm63xx_dev_uart.h>
282 +#include <bcm63xx_regs.h>
283 +#include <bcm63xx_io.h>
284 +#include <bcm63xx_nvram.h>
285 +#include <bcm63xx_gpio.h>
286 +#include <bcm63xx_dev_pci.h>
287 +#include <bcm63xx_dev_enet.h>
288 +#include <bcm63xx_dev_dsp.h>
289 +#include <bcm63xx_dev_flash.h>
290 +#include <bcm63xx_dev_hsspi.h>
291 +#include <bcm63xx_dev_pcmcia.h>
292 +#include <bcm63xx_dev_spi.h>
293 +#include <bcm63xx_dev_usb_ehci.h>
294 +#include <bcm63xx_dev_usb_ohci.h>
295 +#include <bcm63xx_dev_usb_usbd.h>
296 +#include <board_bcm963xx.h>
298 +#define PFX "board: "
300 +static struct board_info board;
303 + * Register a sane SPROMv2 to make the on-board
304 + * bcm4318 WLAN work
306 +#ifdef CONFIG_SSB_PCIHOST
307 +static struct ssb_sprom bcm63xx_sprom = {
310 + .country_code = 0x0,
311 + .ant_available_bg = 0x3,
322 + .maxpwr_bg = 0x004c,
324 + .boardflags_lo = 0x2848,
325 + .boardflags_hi = 0x0000,
328 +int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
330 + if (bus->bustype == SSB_BUSTYPE_PCI) {
331 + memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
334 + printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
341 + * return board name for /proc/cpuinfo
343 +const char *board_get_name(void)
349 + * setup board for device registration
351 +void __init board_early_setup(const struct board_info *target)
355 + memcpy(&board, target, sizeof(board));
357 + /* setup pin multiplexing depending on board enabled device,
358 + * this has to be done this early since PCI init is done
359 + * inside arch_initcall */
363 + if (board.has_pci) {
364 + bcm63xx_pci_enabled = 1;
365 + if (BCMCPU_IS_6348())
366 + val |= GPIO_MODE_6348_G2_PCI;
370 + if (board.has_pccard) {
371 + if (BCMCPU_IS_6348())
372 + val |= GPIO_MODE_6348_G1_MII_PCCARD;
375 + if (board.has_enet0 && !board.enet0.use_internal_phy) {
376 + if (BCMCPU_IS_6348())
377 + val |= GPIO_MODE_6348_G3_EXT_MII |
378 + GPIO_MODE_6348_G0_EXT_MII;
381 + if (board.has_enet1 && !board.enet1.use_internal_phy) {
382 + if (BCMCPU_IS_6348())
383 + val |= GPIO_MODE_6348_G3_EXT_MII |
384 + GPIO_MODE_6348_G0_EXT_MII;
387 + bcm_gpio_writel(val, GPIO_MODE_REG);
392 + * second stage init callback, good time to panic if we couldn't
393 + * identify on which board we're running since early printk is working
395 +void __init board_setup(void)
397 + if (!board.name[0])
398 + panic("unable to detect bcm963xx board");
399 + printk(KERN_INFO PFX "board name: %s\n", board.name);
401 + /* make sure we're running on expected cpu */
402 + if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
403 + panic("unexpected CPU for bcm963xx board");
406 +static struct gpio_led_platform_data bcm63xx_led_data;
408 +static struct platform_device bcm63xx_gpio_leds = {
409 + .name = "leds-gpio",
411 + .dev.platform_data = &bcm63xx_led_data,
415 + * third stage init callback, register all board devices.
417 +int __init board_register_devices(void)
419 + if (board.has_uart0)
420 + bcm63xx_uart_register(0);
422 + if (board.has_uart1)
423 + bcm63xx_uart_register(1);
425 + if (board.has_pccard)
426 + bcm63xx_pcmcia_register();
428 + if (board.has_enet0 &&
429 + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
430 + bcm63xx_enet_register(0, &board.enet0);
432 + if (board.has_enet1 &&
433 + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
434 + bcm63xx_enet_register(1, &board.enet1);
436 + if (board.has_enetsw &&
437 + !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
438 + bcm63xx_enetsw_register(&board.enetsw);
440 + if (board.has_usbd)
441 + bcm63xx_usbd_register(&board.usbd);
443 + if (board.has_ehci0)
444 + bcm63xx_ehci_register();
446 + if (board.has_ohci0)
447 + bcm63xx_ohci_register();
450 + bcm63xx_dsp_register(&board.dsp);
452 + /* Generate MAC address for WLAN and register our SPROM,
453 + * do this after registering enet devices
455 +#ifdef CONFIG_SSB_PCIHOST
456 + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
457 + memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
458 + memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
459 + if (ssb_arch_register_fallback_sprom(
460 + &bcm63xx_get_fallback_sprom) < 0)
461 + pr_err(PFX "failed to register fallback SPROM\n");
465 + bcm63xx_spi_register();
467 + bcm63xx_hsspi_register();
469 + bcm63xx_flash_register();
471 + bcm63xx_led_data.num_leds = ARRAY_SIZE(board.leds);
472 + bcm63xx_led_data.leds = board.leds;
474 + platform_device_register(&bcm63xx_gpio_leds);
476 + if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
477 + gpio_request_one(board.ephy_reset_gpio,
478 + board.ephy_reset_gpio_flags, "ephy-reset");
483 +++ b/arch/mips/bcm63xx/boards/board_common.h
485 +#ifndef __BOARD_COMMON_H
486 +#define __BOARD_COMMON_H
488 +#include <board_bcm963xx.h>
490 +void board_early_setup(const struct board_info *board);
492 +#endif /* __BOARD_COMMON_H */