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