[brcm63xx] switch to 2.6.39
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-2.6.37 / 500-ssb-add-callback-for-sprom.patch
1 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
2 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
3 @@ -2128,6 +2128,17 @@ static struct ssb_sprom bcm63xx_sprom =
4 .boardflags_lo = 0x2848,
5 .boardflags_hi = 0x0000,
6 };
7 +
8 +int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
9 +{
10 + if (bus->bustype == SSB_BUSTYPE_PCI) {
11 + memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
12 + return 0;
13 + } else {
14 + printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
15 + return -EINVAL;
16 + }
17 +}
18 #endif
19
20 /*
21 @@ -2328,8 +2339,9 @@ void __init board_prom_init(void)
22 if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
23 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
24 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
25 - if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0)
26 - printk(KERN_ERR "failed to register fallback SPROM\n");
27 + if (ssb_arch_register_fallback_sprom(
28 + &bcm63xx_get_fallback_sprom) < 0)
29 + printk(KERN_ERR PFX "failed to register fallback SPROM\n");
30 }
31 #endif
32 }
33 --- a/drivers/ssb/pci.c
34 +++ b/drivers/ssb/pci.c
35 @@ -662,7 +662,6 @@ static int sprom_extract(struct ssb_bus
36 static int ssb_pci_sprom_get(struct ssb_bus *bus,
37 struct ssb_sprom *sprom)
38 {
39 - const struct ssb_sprom *fallback;
40 int err;
41 u16 *buf;
42
43 @@ -707,10 +706,14 @@ static int ssb_pci_sprom_get(struct ssb_
44 if (err) {
45 /* All CRC attempts failed.
46 * Maybe there is no SPROM on the device?
47 - * If we have a fallback, use that. */
48 - fallback = ssb_get_fallback_sprom();
49 - if (fallback) {
50 - memcpy(sprom, fallback, sizeof(*sprom));
51 + * Now we ask the arch code if there is some sprom
52 + * avaliable for this device in some other storage */
53 + err = ssb_fill_sprom_with_fallback(bus, sprom);
54 + if (err) {
55 + ssb_printk(KERN_WARNING PFX "WARNING: Using"
56 + " fallback SPROM failed (err %d)\n",
57 + err);
58 + } else {
59 err = 0;
60 goto out_free;
61 }
62 --- a/drivers/ssb/sprom.c
63 +++ b/drivers/ssb/sprom.c
64 @@ -17,7 +17,7 @@
65 #include <linux/slab.h>
66
67
68 -static const struct ssb_sprom *fallback_sprom;
69 +static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out);
70
71
72 static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
73 @@ -145,13 +145,14 @@ out:
74 }
75
76 /**
77 - * ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found.
78 + * ssb_arch_register_fallback_sprom - Registers a method providing a fallback
79 + * SPROM if no SPROM is found.
80 *
81 - * @sprom: The SPROM data structure to register.
82 + * @sprom_callback: The callbcak function.
83 *
84 - * With this function the architecture implementation may register a fallback
85 - * SPROM data structure. The fallback is only used for PCI based SSB devices,
86 - * where no valid SPROM can be found in the shadow registers.
87 + * With this function the architecture implementation may register a callback
88 + * handler which wills the SPROM data structure. The fallback is only used for
89 + * PCI based SSB devices, where no valid SPROM can be found in the shadow registers.
90 *
91 * This function is useful for weird architectures that have a half-assed SSB device
92 * hardwired to their PCI bus.
93 @@ -163,18 +164,21 @@ out:
94 *
95 * This function is available for architecture code, only. So it is not exported.
96 */
97 -int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom)
98 +int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus, struct ssb_sprom *out))
99 {
100 - if (fallback_sprom)
101 + if (get_fallback_sprom)
102 return -EEXIST;
103 - fallback_sprom = sprom;
104 + get_fallback_sprom = sprom_callback;
105
106 return 0;
107 }
108
109 -const struct ssb_sprom *ssb_get_fallback_sprom(void)
110 +int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out)
111 {
112 - return fallback_sprom;
113 + if (!get_fallback_sprom)
114 + return -ENOENT;
115 +
116 + return get_fallback_sprom(bus, out);
117 }
118
119 /* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */
120 --- a/drivers/ssb/ssb_private.h
121 +++ b/drivers/ssb/ssb_private.h
122 @@ -171,7 +171,7 @@ ssize_t ssb_attr_sprom_store(struct ssb_
123 const char *buf, size_t count,
124 int (*sprom_check_crc)(const u16 *sprom, size_t size),
125 int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom));
126 -extern const struct ssb_sprom *ssb_get_fallback_sprom(void);
127 +extern int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out);
128
129
130 /* core.c */
131 --- a/include/linux/ssb/ssb.h
132 +++ b/include/linux/ssb/ssb.h
133 @@ -404,7 +404,9 @@ extern bool ssb_is_sprom_available(struc
134
135 /* Set a fallback SPROM.
136 * See kdoc at the function definition for complete documentation. */
137 -extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom);
138 +extern int ssb_arch_register_fallback_sprom(
139 + int (*sprom_callback)(struct ssb_bus *bus,
140 + struct ssb_sprom *out));
141
142 /* Suspend a SSB bus.
143 * Call this from the parent bus suspend routine. */