Skip to content

Commit 08ccf57

Browse files
haukelinvjw
authored andcommitted
bcm47xx: prepare to support different buses
Prepare bcm47xx to support different System buses. Before adding support for bcma it should be possible to build bcm47xx without the need of ssb. With this patch bcm47xx does not directly contain a ssb_bus, but a union contain all the supported system buses. As a SoC just uses one system bus a union is a good choice. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Acked-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 908debc commit 08ccf57

9 files changed

Lines changed: 160 additions & 61 deletions

File tree

‎arch/mips/bcm47xx/gpio.c‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,54 @@ static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES);
2020

2121
int gpio_request(unsigned gpio, const char *tag)
2222
{
23-
if (ssb_chipco_available(&ssb_bcm47xx.chipco) &&
24-
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
25-
return -EINVAL;
23+
switch (bcm47xx_bus_type) {
24+
case BCM47XX_BUS_TYPE_SSB:
25+
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
26+
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
27+
return -EINVAL;
2628

27-
if (ssb_extif_available(&ssb_bcm47xx.extif) &&
28-
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
29-
return -EINVAL;
29+
if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
30+
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
31+
return -EINVAL;
3032

31-
if (test_and_set_bit(gpio, gpio_in_use))
32-
return -EBUSY;
33+
if (test_and_set_bit(gpio, gpio_in_use))
34+
return -EBUSY;
3335

34-
return 0;
36+
return 0;
37+
}
38+
return -EINVAL;
3539
}
3640
EXPORT_SYMBOL(gpio_request);
3741

3842
void gpio_free(unsigned gpio)
3943
{
40-
if (ssb_chipco_available(&ssb_bcm47xx.chipco) &&
41-
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
42-
return;
44+
switch (bcm47xx_bus_type) {
45+
case BCM47XX_BUS_TYPE_SSB:
46+
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
47+
((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
48+
return;
4349

44-
if (ssb_extif_available(&ssb_bcm47xx.extif) &&
45-
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
46-
return;
50+
if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
51+
((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
52+
return;
4753

48-
clear_bit(gpio, gpio_in_use);
54+
clear_bit(gpio, gpio_in_use);
55+
return;
56+
}
4957
}
5058
EXPORT_SYMBOL(gpio_free);
5159

5260
int gpio_to_irq(unsigned gpio)
5361
{
54-
if (ssb_chipco_available(&ssb_bcm47xx.chipco))
55-
return ssb_mips_irq(ssb_bcm47xx.chipco.dev) + 2;
56-
else if (ssb_extif_available(&ssb_bcm47xx.extif))
57-
return ssb_mips_irq(ssb_bcm47xx.extif.dev) + 2;
58-
else
59-
return -EINVAL;
62+
switch (bcm47xx_bus_type) {
63+
case BCM47XX_BUS_TYPE_SSB:
64+
if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco))
65+
return ssb_mips_irq(bcm47xx_bus.ssb.chipco.dev) + 2;
66+
else if (ssb_extif_available(&bcm47xx_bus.ssb.extif))
67+
return ssb_mips_irq(bcm47xx_bus.ssb.extif.dev) + 2;
68+
else
69+
return -EINVAL;
70+
}
71+
return -EINVAL;
6072
}
6173
EXPORT_SYMBOL_GPL(gpio_to_irq);

‎arch/mips/bcm47xx/nvram.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ static char nvram_buf[NVRAM_SPACE];
2626
/* Probe for NVRAM header */
2727
static void early_nvram_init(void)
2828
{
29-
struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore;
29+
struct ssb_mipscore *mcore_ssb;
3030
struct nvram_header *header;
3131
int i;
32-
u32 base, lim, off;
32+
u32 base = 0;
33+
u32 lim = 0;
34+
u32 off;
3335
u32 *src, *dst;
3436

35-
base = mcore->flash_window;
36-
lim = mcore->flash_window_size;
37+
switch (bcm47xx_bus_type) {
38+
case BCM47XX_BUS_TYPE_SSB:
39+
mcore_ssb = &bcm47xx_bus.ssb.mipscore;
40+
base = mcore_ssb->flash_window;
41+
lim = mcore_ssb->flash_window_size;
42+
break;
43+
}
3744

3845
off = FLASH_MIN;
3946
while (off <= lim) {

‎arch/mips/bcm47xx/serial.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ static struct platform_device uart8250_device = {
2323
},
2424
};
2525

26-
static int __init uart8250_init(void)
26+
static int __init uart8250_init_ssb(void)
2727
{
2828
int i;
29-
struct ssb_mipscore *mcore = &(ssb_bcm47xx.mipscore);
29+
struct ssb_mipscore *mcore = &(bcm47xx_bus.ssb.mipscore);
3030

3131
memset(&uart8250_data, 0, sizeof(uart8250_data));
3232

@@ -45,6 +45,15 @@ static int __init uart8250_init(void)
4545
return platform_device_register(&uart8250_device);
4646
}
4747

48+
static int __init uart8250_init(void)
49+
{
50+
switch (bcm47xx_bus_type) {
51+
case BCM47XX_BUS_TYPE_SSB:
52+
return uart8250_init_ssb();
53+
}
54+
return -EINVAL;
55+
}
56+
4857
module_init(uart8250_init);
4958

5059
MODULE_AUTHOR("Aurelien Jarno <aurelien@aurel32.net>");

‎arch/mips/bcm47xx/setup.c‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,22 @@
3535
#include <bcm47xx.h>
3636
#include <asm/mach-bcm47xx/nvram.h>
3737

38-
struct ssb_bus ssb_bcm47xx;
39-
EXPORT_SYMBOL(ssb_bcm47xx);
38+
union bcm47xx_bus bcm47xx_bus;
39+
EXPORT_SYMBOL(bcm47xx_bus);
40+
41+
enum bcm47xx_bus_type bcm47xx_bus_type;
42+
EXPORT_SYMBOL(bcm47xx_bus_type);
4043

4144
static void bcm47xx_machine_restart(char *command)
4245
{
4346
printk(KERN_ALERT "Please stand by while rebooting the system...\n");
4447
local_irq_disable();
4548
/* Set the watchdog timer to reset immediately */
46-
ssb_watchdog_timer_set(&ssb_bcm47xx, 1);
49+
switch (bcm47xx_bus_type) {
50+
case BCM47XX_BUS_TYPE_SSB:
51+
ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
52+
break;
53+
}
4754
while (1)
4855
cpu_relax();
4956
}
@@ -52,7 +59,11 @@ static void bcm47xx_machine_halt(void)
5259
{
5360
/* Disable interrupts and watchdog and spin forever */
5461
local_irq_disable();
55-
ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
62+
switch (bcm47xx_bus_type) {
63+
case BCM47XX_BUS_TYPE_SSB:
64+
ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
65+
break;
66+
}
5667
while (1)
5768
cpu_relax();
5869
}
@@ -247,7 +258,7 @@ static int bcm47xx_get_invariants(struct ssb_bus *bus,
247258
return 0;
248259
}
249260

250-
void __init plat_mem_setup(void)
261+
static void __init bcm47xx_register_ssb(void)
251262
{
252263
int err;
253264
char buf[100];
@@ -258,12 +269,12 @@ void __init plat_mem_setup(void)
258269
printk(KERN_WARNING "bcm47xx: someone else already registered"
259270
" a ssb SPROM callback handler (err %d)\n", err);
260271

261-
err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
272+
err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
262273
bcm47xx_get_invariants);
263274
if (err)
264275
panic("Failed to initialize SSB bus (err %d)\n", err);
265276

266-
mcore = &ssb_bcm47xx.mipscore;
277+
mcore = &bcm47xx_bus.ssb.mipscore;
267278
if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
268279
if (strstr(buf, "console=ttyS1")) {
269280
struct ssb_serial_port port;
@@ -276,6 +287,14 @@ void __init plat_mem_setup(void)
276287
memcpy(&mcore->serial_ports[1], &port, sizeof(port));
277288
}
278289
}
290+
}
291+
292+
void __init plat_mem_setup(void)
293+
{
294+
struct cpuinfo_mips *c = &current_cpu_data;
295+
296+
bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
297+
bcm47xx_register_ssb();
279298

280299
_machine_restart = bcm47xx_machine_restart;
281300
_machine_halt = bcm47xx_machine_halt;

‎arch/mips/bcm47xx/time.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
void __init plat_time_init(void)
3232
{
33-
unsigned long hz;
33+
unsigned long hz = 0;
3434

3535
/*
3636
* Use deterministic values for initial counter interrupt
@@ -39,7 +39,12 @@ void __init plat_time_init(void)
3939
write_c0_count(0);
4040
write_c0_compare(0xffff);
4141

42-
hz = ssb_cpu_clock(&ssb_bcm47xx.mipscore) / 2;
42+
switch (bcm47xx_bus_type) {
43+
case BCM47XX_BUS_TYPE_SSB:
44+
hz = ssb_cpu_clock(&bcm47xx_bus.ssb.mipscore) / 2;
45+
break;
46+
}
47+
4348
if (!hz)
4449
hz = 100000000;
4550

‎arch/mips/bcm47xx/wgt634u.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static irqreturn_t gpio_interrupt(int irq, void *ignored)
108108

109109
/* Interrupts are shared, check if the current one is
110110
a GPIO interrupt. */
111-
if (!ssb_chipco_irq_status(&ssb_bcm47xx.chipco,
111+
if (!ssb_chipco_irq_status(&bcm47xx_bus.ssb.chipco,
112112
SSB_CHIPCO_IRQ_GPIO))
113113
return IRQ_NONE;
114114

@@ -132,22 +132,26 @@ static int __init wgt634u_init(void)
132132
* machine. Use the MAC address as an heuristic. Netgear Inc. has
133133
* been allocated ranges 00:09:5b:xx:xx:xx and 00:0f:b5:xx:xx:xx.
134134
*/
135+
u8 *et0mac;
135136

136-
u8 *et0mac = ssb_bcm47xx.sprom.et0mac;
137+
if (bcm47xx_bus_type != BCM47XX_BUS_TYPE_SSB)
138+
return -ENODEV;
139+
140+
et0mac = bcm47xx_bus.ssb.sprom.et0mac;
137141

138142
if (et0mac[0] == 0x00 &&
139143
((et0mac[1] == 0x09 && et0mac[2] == 0x5b) ||
140144
(et0mac[1] == 0x0f && et0mac[2] == 0xb5))) {
141-
struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore;
145+
struct ssb_mipscore *mcore = &bcm47xx_bus.ssb.mipscore;
142146

143147
printk(KERN_INFO "WGT634U machine detected.\n");
144148

145149
if (!request_irq(gpio_to_irq(WGT634U_GPIO_RESET),
146150
gpio_interrupt, IRQF_SHARED,
147-
"WGT634U GPIO", &ssb_bcm47xx.chipco)) {
151+
"WGT634U GPIO", &bcm47xx_bus.ssb.chipco)) {
148152
gpio_direction_input(WGT634U_GPIO_RESET);
149153
gpio_intmask(WGT634U_GPIO_RESET, 1);
150-
ssb_chipco_irq_mask(&ssb_bcm47xx.chipco,
154+
ssb_chipco_irq_mask(&bcm47xx_bus.ssb.chipco,
151155
SSB_CHIPCO_IRQ_GPIO,
152156
SSB_CHIPCO_IRQ_GPIO);
153157
}

‎arch/mips/include/asm/mach-bcm47xx/bcm47xx.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
#ifndef __ASM_BCM47XX_H
2020
#define __ASM_BCM47XX_H
2121

22-
/* SSB bus */
23-
extern struct ssb_bus ssb_bcm47xx;
22+
#include <linux/ssb/ssb.h>
23+
24+
enum bcm47xx_bus_type {
25+
BCM47XX_BUS_TYPE_SSB,
26+
};
27+
28+
union bcm47xx_bus {
29+
struct ssb_bus ssb;
30+
};
31+
32+
extern union bcm47xx_bus bcm47xx_bus;
33+
extern enum bcm47xx_bus_type bcm47xx_bus_type;
2434

2535
#endif /* __ASM_BCM47XX_H */

‎arch/mips/include/asm/mach-bcm47xx/gpio.h‎

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,66 @@ extern int gpio_to_irq(unsigned gpio);
2121

2222
static inline int gpio_get_value(unsigned gpio)
2323
{
24-
return ssb_gpio_in(&ssb_bcm47xx, 1 << gpio);
24+
switch (bcm47xx_bus_type) {
25+
case BCM47XX_BUS_TYPE_SSB:
26+
return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
27+
}
28+
return -EINVAL;
2529
}
2630

2731
static inline void gpio_set_value(unsigned gpio, int value)
2832
{
29-
ssb_gpio_out(&ssb_bcm47xx, 1 << gpio, value ? 1 << gpio : 0);
33+
switch (bcm47xx_bus_type) {
34+
case BCM47XX_BUS_TYPE_SSB:
35+
ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
36+
value ? 1 << gpio : 0);
37+
}
3038
}
3139

3240
static inline int gpio_direction_input(unsigned gpio)
3341
{
34-
ssb_gpio_outen(&ssb_bcm47xx, 1 << gpio, 0);
35-
return 0;
42+
switch (bcm47xx_bus_type) {
43+
case BCM47XX_BUS_TYPE_SSB:
44+
ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
45+
return 0;
46+
}
47+
return -EINVAL;
3648
}
3749

3850
static inline int gpio_direction_output(unsigned gpio, int value)
3951
{
40-
/* first set the gpio out value */
41-
ssb_gpio_out(&ssb_bcm47xx, 1 << gpio, value ? 1 << gpio : 0);
42-
/* then set the gpio mode */
43-
ssb_gpio_outen(&ssb_bcm47xx, 1 << gpio, 1 << gpio);
44-
return 0;
52+
switch (bcm47xx_bus_type) {
53+
case BCM47XX_BUS_TYPE_SSB:
54+
/* first set the gpio out value */
55+
ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
56+
value ? 1 << gpio : 0);
57+
/* then set the gpio mode */
58+
ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
59+
return 0;
60+
}
61+
return -EINVAL;
4562
}
4663

4764
static inline int gpio_intmask(unsigned gpio, int value)
4865
{
49-
ssb_gpio_intmask(&ssb_bcm47xx, 1 << gpio,
50-
value ? 1 << gpio : 0);
51-
return 0;
66+
switch (bcm47xx_bus_type) {
67+
case BCM47XX_BUS_TYPE_SSB:
68+
ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
69+
value ? 1 << gpio : 0);
70+
return 0;
71+
}
72+
return -EINVAL;
5273
}
5374

5475
static inline int gpio_polarity(unsigned gpio, int value)
5576
{
56-
ssb_gpio_polarity(&ssb_bcm47xx, 1 << gpio,
57-
value ? 1 << gpio : 0);
58-
return 0;
77+
switch (bcm47xx_bus_type) {
78+
case BCM47XX_BUS_TYPE_SSB:
79+
ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
80+
value ? 1 << gpio : 0);
81+
return 0;
82+
}
83+
return -EINVAL;
5984
}
6085

6186

‎drivers/watchdog/bcm47xx_wdt.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ static atomic_t ticks;
5454
static inline void bcm47xx_wdt_hw_start(void)
5555
{
5656
/* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
57-
ssb_watchdog_timer_set(&ssb_bcm47xx, 0xfffffff);
57+
switch (bcm47xx_bus_type) {
58+
case BCM47XX_BUS_TYPE_SSB:
59+
ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0xfffffff);
60+
break;
61+
}
5862
}
5963

6064
static inline int bcm47xx_wdt_hw_stop(void)
6165
{
62-
return ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
66+
switch (bcm47xx_bus_type) {
67+
case BCM47XX_BUS_TYPE_SSB:
68+
return ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
69+
}
70+
return -EINVAL;
6371
}
6472

6573
static void bcm47xx_timer_tick(unsigned long unused)

0 commit comments

Comments
 (0)