diff options
author | Michael Buesch <mb@bu3sch.de> | 2009-02-27 10:59:05 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-03-05 14:39:32 -0500 |
commit | e79c1ba84c68de9161d541bd2bcc8ea65c89955c (patch) | |
tree | 9399343651e9d92fb92f0c7bd6280353cb296913 | |
parent | e31ae0508315ebf5d8b1b8a1fca8550737fb3996 (diff) |
ssb: Add SPROM fallback support
This adds SSB functionality to register a fallback SPROM image from the
architecture setup code.
Weird architectures exist that have half-assed SSB devices without SPROM attached to
their PCI busses. The architecture can register a fallback SPROM image that is
used if no SPROM is found on the SSB device.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: Florian Fainelli <florian@openwrt.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/ssb/pci.c | 14 | ||||
-rw-r--r-- | drivers/ssb/sprom.c | 36 | ||||
-rw-r--r-- | drivers/ssb/ssb_private.h | 1 | ||||
-rw-r--r-- | include/linux/ssb/ssb.h | 4 |
4 files changed, 54 insertions, 1 deletions
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c index c958ac16423c..40ea41762247 100644 --- a/drivers/ssb/pci.c +++ b/drivers/ssb/pci.c | |||
@@ -564,6 +564,7 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out, | |||
564 | static int ssb_pci_sprom_get(struct ssb_bus *bus, | 564 | static int ssb_pci_sprom_get(struct ssb_bus *bus, |
565 | struct ssb_sprom *sprom) | 565 | struct ssb_sprom *sprom) |
566 | { | 566 | { |
567 | const struct ssb_sprom *fallback; | ||
567 | int err = -ENOMEM; | 568 | int err = -ENOMEM; |
568 | u16 *buf; | 569 | u16 *buf; |
569 | 570 | ||
@@ -583,12 +584,23 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus, | |||
583 | bus->sprom_size = SSB_SPROMSIZE_WORDS_R4; | 584 | bus->sprom_size = SSB_SPROMSIZE_WORDS_R4; |
584 | sprom_do_read(bus, buf); | 585 | sprom_do_read(bus, buf); |
585 | err = sprom_check_crc(buf, bus->sprom_size); | 586 | err = sprom_check_crc(buf, bus->sprom_size); |
586 | if (err) | 587 | if (err) { |
588 | /* All CRC attempts failed. | ||
589 | * Maybe there is no SPROM on the device? | ||
590 | * If we have a fallback, use that. */ | ||
591 | fallback = ssb_get_fallback_sprom(); | ||
592 | if (fallback) { | ||
593 | memcpy(sprom, fallback, sizeof(*sprom)); | ||
594 | err = 0; | ||
595 | goto out_free; | ||
596 | } | ||
587 | ssb_printk(KERN_WARNING PFX "WARNING: Invalid" | 597 | ssb_printk(KERN_WARNING PFX "WARNING: Invalid" |
588 | " SPROM CRC (corrupt SPROM)\n"); | 598 | " SPROM CRC (corrupt SPROM)\n"); |
599 | } | ||
589 | } | 600 | } |
590 | err = sprom_extract(bus, sprom, buf, bus->sprom_size); | 601 | err = sprom_extract(bus, sprom, buf, bus->sprom_size); |
591 | 602 | ||
603 | out_free: | ||
592 | kfree(buf); | 604 | kfree(buf); |
593 | out: | 605 | out: |
594 | return err; | 606 | return err; |
diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c index 3668edb39315..8943015a3eef 100644 --- a/drivers/ssb/sprom.c +++ b/drivers/ssb/sprom.c | |||
@@ -14,6 +14,9 @@ | |||
14 | #include "ssb_private.h" | 14 | #include "ssb_private.h" |
15 | 15 | ||
16 | 16 | ||
17 | static const struct ssb_sprom *fallback_sprom; | ||
18 | |||
19 | |||
17 | static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, | 20 | static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, |
18 | size_t sprom_size_words) | 21 | size_t sprom_size_words) |
19 | { | 22 | { |
@@ -131,3 +134,36 @@ out: | |||
131 | return res; | 134 | return res; |
132 | return err ? err : count; | 135 | return err ? err : count; |
133 | } | 136 | } |
137 | |||
138 | /** | ||
139 | * ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found. | ||
140 | * | ||
141 | * @sprom: The SPROM data structure to register. | ||
142 | * | ||
143 | * With this function the architecture implementation may register a fallback | ||
144 | * SPROM data structure. The fallback is only used for PCI based SSB devices, | ||
145 | * where no valid SPROM can be found in the shadow registers. | ||
146 | * | ||
147 | * This function is useful for weird architectures that have a half-assed SSB device | ||
148 | * hardwired to their PCI bus. | ||
149 | * | ||
150 | * Note that it does only work with PCI attached SSB devices. PCMCIA devices currently | ||
151 | * don't use this fallback. | ||
152 | * Architectures must provide the SPROM for native SSB devices anyway, | ||
153 | * so the fallback also isn't used for native devices. | ||
154 | * | ||
155 | * This function is available for architecture code, only. So it is not exported. | ||
156 | */ | ||
157 | int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom) | ||
158 | { | ||
159 | if (fallback_sprom) | ||
160 | return -EEXIST; | ||
161 | fallback_sprom = sprom; | ||
162 | |||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | const struct ssb_sprom *ssb_get_fallback_sprom(void) | ||
167 | { | ||
168 | return fallback_sprom; | ||
169 | } | ||
diff --git a/drivers/ssb/ssb_private.h b/drivers/ssb/ssb_private.h index ebc32d8fe15f..57fa482abb94 100644 --- a/drivers/ssb/ssb_private.h +++ b/drivers/ssb/ssb_private.h | |||
@@ -131,6 +131,7 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, | |||
131 | const char *buf, size_t count, | 131 | const char *buf, size_t count, |
132 | int (*sprom_check_crc)(const u16 *sprom, size_t size), | 132 | int (*sprom_check_crc)(const u16 *sprom, size_t size), |
133 | int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); | 133 | int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); |
134 | extern const struct ssb_sprom *ssb_get_fallback_sprom(void); | ||
134 | 135 | ||
135 | 136 | ||
136 | /* core.c */ | 137 | /* core.c */ |
diff --git a/include/linux/ssb/ssb.h b/include/linux/ssb/ssb.h index 17d9b58f6379..5ae8fa22d331 100644 --- a/include/linux/ssb/ssb.h +++ b/include/linux/ssb/ssb.h | |||
@@ -339,6 +339,10 @@ extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus, | |||
339 | 339 | ||
340 | extern void ssb_bus_unregister(struct ssb_bus *bus); | 340 | extern void ssb_bus_unregister(struct ssb_bus *bus); |
341 | 341 | ||
342 | /* Set a fallback SPROM. | ||
343 | * See kdoc at the function definition for complete documentation. */ | ||
344 | extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom); | ||
345 | |||
342 | /* Suspend a SSB bus. | 346 | /* Suspend a SSB bus. |
343 | * Call this from the parent bus suspend routine. */ | 347 | * Call this from the parent bus suspend routine. */ |
344 | extern int ssb_bus_suspend(struct ssb_bus *bus); | 348 | extern int ssb_bus_suspend(struct ssb_bus *bus); |