aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ssb
diff options
context:
space:
mode:
authorAlbert Herranz <albert_herranz@yahoo.es>2009-09-08 13:30:12 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-09-09 11:19:00 -0400
commit24ea602e183ca20a7577ebe253323d0e5d0f9847 (patch)
tree9cd9c0b3832cac2f155e633fbed1ce2bf3331f9a /drivers/ssb
parentf020979d5d7c9816c071d0aedf60a889fa4fae40 (diff)
ssb: Implement SDIO host bus support
Add support for communicating with a Sonics Silicon Backplane through a SDIO interface, as found in the Nintendo Wii WLAN daughter card. The Nintendo Wii WLAN card includes a custom Broadcom 4318 chip with a SDIO host interface. Signed-off-by: Albert Herranz <albert_herranz@yahoo.es> Signed-off-by: Michael Buesch <mb@bu3sch.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/ssb')
-rw-r--r--drivers/ssb/Kconfig14
-rw-r--r--drivers/ssb/Makefile1
-rw-r--r--drivers/ssb/main.c58
-rw-r--r--drivers/ssb/scan.c11
-rw-r--r--drivers/ssb/sdio.c610
-rw-r--r--drivers/ssb/ssb_private.h40
6 files changed, 733 insertions, 1 deletions
diff --git a/drivers/ssb/Kconfig b/drivers/ssb/Kconfig
index 540a2948596..2d8cc455dbc 100644
--- a/drivers/ssb/Kconfig
+++ b/drivers/ssb/Kconfig
@@ -66,6 +66,20 @@ config SSB_PCMCIAHOST
66 66
67 If unsure, say N 67 If unsure, say N
68 68
69config SSB_SDIOHOST_POSSIBLE
70 bool
71 depends on SSB && (MMC = y || MMC = SSB)
72 default y
73
74config SSB_SDIOHOST
75 bool "Support for SSB on SDIO-bus host"
76 depends on SSB_SDIOHOST_POSSIBLE
77 help
78 Support for a Sonics Silicon Backplane on top
79 of a SDIO device.
80
81 If unsure, say N
82
69config SSB_SILENT 83config SSB_SILENT
70 bool "No SSB kernel messages" 84 bool "No SSB kernel messages"
71 depends on SSB && EMBEDDED 85 depends on SSB && EMBEDDED
diff --git a/drivers/ssb/Makefile b/drivers/ssb/Makefile
index cfbb74f2982..656e58b9261 100644
--- a/drivers/ssb/Makefile
+++ b/drivers/ssb/Makefile
@@ -6,6 +6,7 @@ ssb-$(CONFIG_SSB_SPROM) += sprom.o
6# host support 6# host support
7ssb-$(CONFIG_SSB_PCIHOST) += pci.o pcihost_wrapper.o 7ssb-$(CONFIG_SSB_PCIHOST) += pci.o pcihost_wrapper.o
8ssb-$(CONFIG_SSB_PCMCIAHOST) += pcmcia.o 8ssb-$(CONFIG_SSB_PCMCIAHOST) += pcmcia.o
9ssb-$(CONFIG_SSB_SDIOHOST) += sdio.o
9 10
10# built-in drivers 11# built-in drivers
11ssb-y += driver_chipcommon.o 12ssb-y += driver_chipcommon.o
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 8d16cb258cc..579b114be41 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -17,6 +17,7 @@
17#include <linux/ssb/ssb_driver_gige.h> 17#include <linux/ssb/ssb_driver_gige.h>
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/mmc/sdio_func.h>
20 21
21#include <pcmcia/cs_types.h> 22#include <pcmcia/cs_types.h>
22#include <pcmcia/cs.h> 23#include <pcmcia/cs.h>
@@ -88,6 +89,25 @@ found:
88} 89}
89#endif /* CONFIG_SSB_PCMCIAHOST */ 90#endif /* CONFIG_SSB_PCMCIAHOST */
90 91
92#ifdef CONFIG_SSB_SDIOHOST
93struct ssb_bus *ssb_sdio_func_to_bus(struct sdio_func *func)
94{
95 struct ssb_bus *bus;
96
97 ssb_buses_lock();
98 list_for_each_entry(bus, &buses, list) {
99 if (bus->bustype == SSB_BUSTYPE_SDIO &&
100 bus->host_sdio == func)
101 goto found;
102 }
103 bus = NULL;
104found:
105 ssb_buses_unlock();
106
107 return bus;
108}
109#endif /* CONFIG_SSB_SDIOHOST */
110
91int ssb_for_each_bus_call(unsigned long data, 111int ssb_for_each_bus_call(unsigned long data,
92 int (*func)(struct ssb_bus *bus, unsigned long data)) 112 int (*func)(struct ssb_bus *bus, unsigned long data))
93{ 113{
@@ -469,6 +489,12 @@ static int ssb_devices_register(struct ssb_bus *bus)
469 dev->parent = &bus->host_pcmcia->dev; 489 dev->parent = &bus->host_pcmcia->dev;
470#endif 490#endif
471 break; 491 break;
492 case SSB_BUSTYPE_SDIO:
493#ifdef CONFIG_SSB_SDIO
494 sdev->irq = bus->host_sdio->dev.irq;
495 dev->parent = &bus->host_sdio->dev;
496#endif
497 break;
472 case SSB_BUSTYPE_SSB: 498 case SSB_BUSTYPE_SSB:
473 dev->dma_mask = &dev->coherent_dma_mask; 499 dev->dma_mask = &dev->coherent_dma_mask;
474 break; 500 break;
@@ -724,12 +750,18 @@ static int ssb_bus_register(struct ssb_bus *bus,
724 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1); 750 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
725 if (err) 751 if (err)
726 goto out; 752 goto out;
753
754 /* Init SDIO-host device (if any), before the scan */
755 err = ssb_sdio_init(bus);
756 if (err)
757 goto err_disable_xtal;
758
727 ssb_buses_lock(); 759 ssb_buses_lock();
728 bus->busnumber = next_busnumber; 760 bus->busnumber = next_busnumber;
729 /* Scan for devices (cores) */ 761 /* Scan for devices (cores) */
730 err = ssb_bus_scan(bus, baseaddr); 762 err = ssb_bus_scan(bus, baseaddr);
731 if (err) 763 if (err)
732 goto err_disable_xtal; 764 goto err_sdio_exit;
733 765
734 /* Init PCI-host device (if any) */ 766 /* Init PCI-host device (if any) */
735 err = ssb_pci_init(bus); 767 err = ssb_pci_init(bus);
@@ -776,6 +808,8 @@ err_pci_exit:
776 ssb_pci_exit(bus); 808 ssb_pci_exit(bus);
777err_unmap: 809err_unmap:
778 ssb_iounmap(bus); 810 ssb_iounmap(bus);
811err_sdio_exit:
812 ssb_sdio_exit(bus);
779err_disable_xtal: 813err_disable_xtal:
780 ssb_buses_unlock(); 814 ssb_buses_unlock();
781 ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0); 815 ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
@@ -825,6 +859,28 @@ int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
825EXPORT_SYMBOL(ssb_bus_pcmciabus_register); 859EXPORT_SYMBOL(ssb_bus_pcmciabus_register);
826#endif /* CONFIG_SSB_PCMCIAHOST */ 860#endif /* CONFIG_SSB_PCMCIAHOST */
827 861
862#ifdef CONFIG_SSB_SDIOHOST
863int ssb_bus_sdiobus_register(struct ssb_bus *bus, struct sdio_func *func,
864 unsigned int quirks)
865{
866 int err;
867
868 bus->bustype = SSB_BUSTYPE_SDIO;
869 bus->host_sdio = func;
870 bus->ops = &ssb_sdio_ops;
871 bus->quirks = quirks;
872
873 err = ssb_bus_register(bus, ssb_sdio_get_invariants, ~0);
874 if (!err) {
875 ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found on "
876 "SDIO device %s\n", sdio_func_id(func));
877 }
878
879 return err;
880}
881EXPORT_SYMBOL(ssb_bus_sdiobus_register);
882#endif /* CONFIG_SSB_PCMCIAHOST */
883
828int ssb_bus_ssbbus_register(struct ssb_bus *bus, 884int ssb_bus_ssbbus_register(struct ssb_bus *bus,
829 unsigned long baseaddr, 885 unsigned long baseaddr,
830 ssb_invariants_func_t get_invariants) 886 ssb_invariants_func_t get_invariants)
diff --git a/drivers/ssb/scan.c b/drivers/ssb/scan.c
index 63ee5cfbefb..b74212d698c 100644
--- a/drivers/ssb/scan.c
+++ b/drivers/ssb/scan.c
@@ -175,6 +175,9 @@ static u32 scan_read32(struct ssb_bus *bus, u8 current_coreidx,
175 } else 175 } else
176 ssb_pcmcia_switch_segment(bus, 0); 176 ssb_pcmcia_switch_segment(bus, 0);
177 break; 177 break;
178 case SSB_BUSTYPE_SDIO:
179 offset += current_coreidx * SSB_CORE_SIZE;
180 return ssb_sdio_scan_read32(bus, offset);
178 } 181 }
179 return readl(bus->mmio + offset); 182 return readl(bus->mmio + offset);
180} 183}
@@ -188,6 +191,8 @@ static int scan_switchcore(struct ssb_bus *bus, u8 coreidx)
188 return ssb_pci_switch_coreidx(bus, coreidx); 191 return ssb_pci_switch_coreidx(bus, coreidx);
189 case SSB_BUSTYPE_PCMCIA: 192 case SSB_BUSTYPE_PCMCIA:
190 return ssb_pcmcia_switch_coreidx(bus, coreidx); 193 return ssb_pcmcia_switch_coreidx(bus, coreidx);
194 case SSB_BUSTYPE_SDIO:
195 return ssb_sdio_scan_switch_coreidx(bus, coreidx);
191 } 196 }
192 return 0; 197 return 0;
193} 198}
@@ -206,6 +211,8 @@ void ssb_iounmap(struct ssb_bus *bus)
206 SSB_BUG_ON(1); /* Can't reach this code. */ 211 SSB_BUG_ON(1); /* Can't reach this code. */
207#endif 212#endif
208 break; 213 break;
214 case SSB_BUSTYPE_SDIO:
215 break;
209 } 216 }
210 bus->mmio = NULL; 217 bus->mmio = NULL;
211 bus->mapped_device = NULL; 218 bus->mapped_device = NULL;
@@ -230,6 +237,10 @@ static void __iomem *ssb_ioremap(struct ssb_bus *bus,
230 SSB_BUG_ON(1); /* Can't reach this code. */ 237 SSB_BUG_ON(1); /* Can't reach this code. */
231#endif 238#endif
232 break; 239 break;
240 case SSB_BUSTYPE_SDIO:
241 /* Nothing to ioremap in the SDIO case, just fake it */
242 mmio = (void __iomem *)baseaddr;
243 break;
233 } 244 }
234 245
235 return mmio; 246 return mmio;
diff --git a/drivers/ssb/sdio.c b/drivers/ssb/sdio.c
new file mode 100644
index 00000000000..114051056b5
--- /dev/null
+++ b/drivers/ssb/sdio.c
@@ -0,0 +1,610 @@
1/*
2 * Sonics Silicon Backplane
3 * SDIO-Hostbus related functions
4 *
5 * Copyright 2009 Albert Herranz <albert_herranz@yahoo.es>
6 *
7 * Based on drivers/ssb/pcmcia.c
8 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2007-2008 Michael Buesch <mb@bu3sch.de>
10 *
11 * Licensed under the GNU/GPL. See COPYING for details.
12 *
13 */
14
15#include <linux/ssb/ssb.h>
16#include <linux/delay.h>
17#include <linux/io.h>
18#include <linux/etherdevice.h>
19#include <linux/mmc/sdio_func.h>
20
21#include "ssb_private.h"
22
23/* Define the following to 1 to enable a printk on each coreswitch. */
24#define SSB_VERBOSE_SDIOCORESWITCH_DEBUG 1
25
26
27/* Hardware invariants CIS tuples */
28#define SSB_SDIO_CIS 0x80
29#define SSB_SDIO_CIS_SROMREV 0x00
30#define SSB_SDIO_CIS_ID 0x01
31#define SSB_SDIO_CIS_BOARDREV 0x02
32#define SSB_SDIO_CIS_PA 0x03
33#define SSB_SDIO_CIS_PA_PA0B0_LO 0
34#define SSB_SDIO_CIS_PA_PA0B0_HI 1
35#define SSB_SDIO_CIS_PA_PA0B1_LO 2
36#define SSB_SDIO_CIS_PA_PA0B1_HI 3
37#define SSB_SDIO_CIS_PA_PA0B2_LO 4
38#define SSB_SDIO_CIS_PA_PA0B2_HI 5
39#define SSB_SDIO_CIS_PA_ITSSI 6
40#define SSB_SDIO_CIS_PA_MAXPOW 7
41#define SSB_SDIO_CIS_OEMNAME 0x04
42#define SSB_SDIO_CIS_CCODE 0x05
43#define SSB_SDIO_CIS_ANTENNA 0x06
44#define SSB_SDIO_CIS_ANTGAIN 0x07
45#define SSB_SDIO_CIS_BFLAGS 0x08
46#define SSB_SDIO_CIS_LEDS 0x09
47
48#define CISTPL_FUNCE_LAN_NODE_ID 0x04 /* same as in PCMCIA */
49
50
51/*
52 * Function 1 miscellaneous registers.
53 *
54 * Definitions match src/include/sbsdio.h from the
55 * Android Open Source Project
56 * http://android.git.kernel.org/?p=platform/system/wlan/broadcom.git
57 *
58 */
59#define SBSDIO_FUNC1_SBADDRLOW 0x1000a /* SB Address window Low (b15) */
60#define SBSDIO_FUNC1_SBADDRMID 0x1000b /* SB Address window Mid (b23-b16) */
61#define SBSDIO_FUNC1_SBADDRHIGH 0x1000c /* SB Address window High (b24-b31) */
62
63/* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
64#define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid address bits in SBADDRLOW */
65#define SBSDIO_SBADDRMID_MASK 0xff /* Valid address bits in SBADDRMID */
66#define SBSDIO_SBADDRHIGH_MASK 0xff /* Valid address bits in SBADDRHIGH */
67
68#define SBSDIO_SB_OFT_ADDR_MASK 0x7FFF /* sb offset addr is <= 15 bits, 32k */
69
70/* REVISIT: this flag doesn't seem to matter */
71#define SBSDIO_SB_ACCESS_2_4B_FLAG 0x8000 /* forces 32-bit SB access */
72
73
74/*
75 * Address map within the SDIO function address space (128K).
76 *
77 * Start End Description
78 * ------- ------- ------------------------------------------
79 * 0x00000 0x0ffff selected backplane address window (64K)
80 * 0x10000 0x1ffff backplane control registers (max 64K)
81 *
82 * The current address window is configured by writing to registers
83 * SBADDRLOW, SBADDRMID and SBADDRHIGH.
84 *
85 * In order to access the contents of a 32-bit Silicon Backplane address
86 * the backplane address window must be first loaded with the highest
87 * 16 bits of the target address. Then, an access must be done to the
88 * SDIO function address space using the lower 15 bits of the address.
89 * Bit 15 of the address must be set when doing 32 bit accesses.
90 *
91 * 10987654321098765432109876543210
92 * WWWWWWWWWWWWWWWWW SB Address Window
93 * OOOOOOOOOOOOOOOO Offset within SB Address Window
94 * a 32-bit access flag
95 */
96
97
98/*
99 * SSB I/O via SDIO.
100 *
101 * NOTE: SDIO address @addr is 17 bits long (SDIO address space is 128K).
102 */
103
104static inline struct device *ssb_sdio_dev(struct ssb_bus *bus)
105{
106 return &bus->host_sdio->dev;
107}
108
109/* host claimed */
110static int ssb_sdio_writeb(struct ssb_bus *bus, unsigned int addr, u8 val)
111{
112 int error = 0;
113
114 sdio_writeb(bus->host_sdio, val, addr, &error);
115 if (unlikely(error)) {
116 dev_dbg(ssb_sdio_dev(bus), "%08X <- %02x, error %d\n",
117 addr, val, error);
118 }
119
120 return error;
121}
122
123#if 0
124static u8 ssb_sdio_readb(struct ssb_bus *bus, unsigned int addr)
125{
126 u8 val;
127 int error = 0;
128
129 val = sdio_readb(bus->host_sdio, addr, &error);
130 if (unlikely(error)) {
131 dev_dbg(ssb_sdio_dev(bus), "%08X -> %02x, error %d\n",
132 addr, val, error);
133 }
134
135 return val;
136}
137#endif
138
139/* host claimed */
140static int ssb_sdio_set_sbaddr_window(struct ssb_bus *bus, u32 address)
141{
142 int error;
143
144 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRLOW,
145 (address >> 8) & SBSDIO_SBADDRLOW_MASK);
146 if (error)
147 goto out;
148 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRMID,
149 (address >> 16) & SBSDIO_SBADDRMID_MASK);
150 if (error)
151 goto out;
152 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRHIGH,
153 (address >> 24) & SBSDIO_SBADDRHIGH_MASK);
154 if (error)
155 goto out;
156 bus->sdio_sbaddr = address;
157out:
158 if (error) {
159 dev_dbg(ssb_sdio_dev(bus), "failed to set address window"
160 " to 0x%08x, error %d\n", address, error);
161 }
162
163 return error;
164}
165
166/* for enumeration use only */
167u32 ssb_sdio_scan_read32(struct ssb_bus *bus, u16 offset)
168{
169 u32 val;
170 int error;
171
172 sdio_claim_host(bus->host_sdio);
173 val = sdio_readl(bus->host_sdio, offset, &error);
174 sdio_release_host(bus->host_sdio);
175 if (unlikely(error)) {
176 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %08x, error %d\n",
177 bus->sdio_sbaddr >> 16, offset, val, error);
178 }
179
180 return val;
181}
182
183/* for enumeration use only */
184int ssb_sdio_scan_switch_coreidx(struct ssb_bus *bus, u8 coreidx)
185{
186 u32 sbaddr;
187 int error;
188
189 sbaddr = (coreidx * SSB_CORE_SIZE) + SSB_ENUM_BASE;
190 sdio_claim_host(bus->host_sdio);
191 error = ssb_sdio_set_sbaddr_window(bus, sbaddr);
192 sdio_release_host(bus->host_sdio);
193 if (error) {
194 dev_err(ssb_sdio_dev(bus), "failed to switch to core %u,"
195 " error %d\n", coreidx, error);
196 goto out;
197 }
198out:
199 return error;
200}
201
202/* host must be already claimed */
203int ssb_sdio_switch_core(struct ssb_bus *bus, struct ssb_device *dev)
204{
205 u8 coreidx = dev->core_index;
206 u32 sbaddr;
207 int error = 0;
208
209 sbaddr = (coreidx * SSB_CORE_SIZE) + SSB_ENUM_BASE;
210 if (unlikely(bus->sdio_sbaddr != sbaddr)) {
211#if SSB_VERBOSE_SDIOCORESWITCH_DEBUG
212 dev_info(ssb_sdio_dev(bus),
213 "switching to %s core, index %d\n",
214 ssb_core_name(dev->id.coreid), coreidx);
215#endif
216 error = ssb_sdio_set_sbaddr_window(bus, sbaddr);
217 if (error) {
218 dev_dbg(ssb_sdio_dev(bus), "failed to switch to"
219 " core %u, error %d\n", coreidx, error);
220 goto out;
221 }
222 bus->mapped_device = dev;
223 }
224
225out:
226 return error;
227}
228
229static u8 ssb_sdio_read8(struct ssb_device *dev, u16 offset)
230{
231 struct ssb_bus *bus = dev->bus;
232 u8 val = 0xff;
233 int error = 0;
234
235 sdio_claim_host(bus->host_sdio);
236 if (unlikely(ssb_sdio_switch_core(bus, dev)))
237 goto out;
238 offset |= bus->sdio_sbaddr & 0xffff;
239 offset &= SBSDIO_SB_OFT_ADDR_MASK;
240 val = sdio_readb(bus->host_sdio, offset, &error);
241 if (error) {
242 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %02x, error %d\n",
243 bus->sdio_sbaddr >> 16, offset, val, error);
244 }
245out:
246 sdio_release_host(bus->host_sdio);
247
248 return val;
249}
250
251static u16 ssb_sdio_read16(struct ssb_device *dev, u16 offset)
252{
253 struct ssb_bus *bus = dev->bus;
254 u16 val = 0xffff;
255 int error = 0;
256
257 sdio_claim_host(bus->host_sdio);
258 if (unlikely(ssb_sdio_switch_core(bus, dev)))
259 goto out;
260 offset |= bus->sdio_sbaddr & 0xffff;
261 offset &= SBSDIO_SB_OFT_ADDR_MASK;
262 val = sdio_readw(bus->host_sdio, offset, &error);
263 if (error) {
264 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %04x, error %d\n",
265 bus->sdio_sbaddr >> 16, offset, val, error);
266 }
267out:
268 sdio_release_host(bus->host_sdio);
269
270 return val;
271}
272
273static u32 ssb_sdio_read32(struct ssb_device *dev, u16 offset)
274{
275 struct ssb_bus *bus = dev->bus;
276 u32 val = 0xffffffff;
277 int error = 0;
278
279 sdio_claim_host(bus->host_sdio);
280 if (unlikely(ssb_sdio_switch_core(bus, dev)))
281 goto out;
282 offset |= bus->sdio_sbaddr & 0xffff;
283 offset &= SBSDIO_SB_OFT_ADDR_MASK;
284 offset |= SBSDIO_SB_ACCESS_2_4B_FLAG; /* 32 bit data access */
285 val = sdio_readl(bus->host_sdio, offset, &error);
286 if (error) {
287 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %08x, error %d\n",
288 bus->sdio_sbaddr >> 16, offset, val, error);
289 }
290out:
291 sdio_release_host(bus->host_sdio);
292
293 return val;
294}
295
296#ifdef CONFIG_SSB_BLOCKIO
297static void ssb_sdio_block_read(struct ssb_device *dev, void *buffer,
298 size_t count, u16 offset, u8 reg_width)
299{
300 size_t saved_count = count;
301 struct ssb_bus *bus = dev->bus;
302 int error = 0;
303
304 sdio_claim_host(bus->host_sdio);
305 if (unlikely(ssb_sdio_switch_core(bus, dev))) {
306 error = -EIO;
307 memset(buffer, 0xff, count);
308 goto err_out;
309 }
310 offset |= bus->sdio_sbaddr & 0xffff;
311 offset &= SBSDIO_SB_OFT_ADDR_MASK;
312
313 switch (reg_width) {
314 case sizeof(u8): {
315 error = sdio_readsb(bus->host_sdio, buffer, offset, count);
316 break;
317 }
318 case sizeof(u16): {
319 SSB_WARN_ON(count & 1);
320 error = sdio_readsb(bus->host_sdio, buffer, offset, count);
321 break;
322 }
323 case sizeof(u32): {
324 SSB_WARN_ON(count & 3);
325 offset |= SBSDIO_SB_ACCESS_2_4B_FLAG; /* 32 bit data access */
326 error = sdio_readsb(bus->host_sdio, buffer, offset, count);
327 break;
328 }
329 default:
330 SSB_WARN_ON(1);
331 }
332 if (!error)
333 goto out;
334
335err_out:
336 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X (width=%u, len=%u), error %d\n",
337 bus->sdio_sbaddr >> 16, offset, reg_width, saved_count, error);
338out:
339 sdio_release_host(bus->host_sdio);
340}
341#endif /* CONFIG_SSB_BLOCKIO */
342
343static void ssb_sdio_write8(struct ssb_device *dev, u16 offset, u8 val)
344{
345 struct ssb_bus *bus = dev->bus;
346 int error = 0;
347
348 sdio_claim_host(bus->host_sdio);
349 if (unlikely(ssb_sdio_switch_core(bus, dev)))
350 goto out;
351 offset |= bus->sdio_sbaddr & 0xffff;
352 offset &= SBSDIO_SB_OFT_ADDR_MASK;
353 sdio_writeb(bus->host_sdio, val, offset, &error);
354 if (error) {
355 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %02x, error %d\n",
356 bus->sdio_sbaddr >> 16, offset, val, error);
357 }
358out:
359 sdio_release_host(bus->host_sdio);
360}
361
362static void ssb_sdio_write16(struct ssb_device *dev, u16 offset, u16 val)
363{
364 struct ssb_bus *bus = dev->bus;
365 int error = 0;
366
367 sdio_claim_host(bus->host_sdio);
368 if (unlikely(ssb_sdio_switch_core(bus, dev)))
369 goto out;
370 offset |= bus->sdio_sbaddr & 0xffff;
371 offset &= SBSDIO_SB_OFT_ADDR_MASK;
372 sdio_writew(bus->host_sdio, val, offset, &error);
373 if (error) {
374 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %04x, error %d\n",
375 bus->sdio_sbaddr >> 16, offset, val, error);
376 }
377out:
378 sdio_release_host(bus->host_sdio);
379}
380
381static void ssb_sdio_write32(struct ssb_device *dev, u16 offset, u32 val)
382{
383 struct ssb_bus *bus = dev->bus;
384 int error = 0;
385
386 sdio_claim_host(bus->host_sdio);
387 if (unlikely(ssb_sdio_switch_core(bus, dev)))
388 goto out;
389 offset |= bus->sdio_sbaddr & 0xffff;
390 offset &= SBSDIO_SB_OFT_ADDR_MASK;
391 offset |= SBSDIO_SB_ACCESS_2_4B_FLAG; /* 32 bit data access */
392 sdio_writel(bus->host_sdio, val, offset, &error);
393 if (error) {
394 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %08x, error %d\n",
395 bus->sdio_sbaddr >> 16, offset, val, error);
396 }
397 if (bus->quirks & SSB_QUIRK_SDIO_READ_AFTER_WRITE32)
398 sdio_readl(bus->host_sdio, 0, &error);
399out:
400 sdio_release_host(bus->host_sdio);
401}
402
403#ifdef CONFIG_SSB_BLOCKIO
404static void ssb_sdio_block_write(struct ssb_device *dev, const void *buffer,
405 size_t count, u16 offset, u8 reg_width)
406{
407 size_t saved_count = count;
408 struct ssb_bus *bus = dev->bus;
409 int error = 0;
410
411 sdio_claim_host(bus->host_sdio);
412 if (unlikely(ssb_sdio_switch_core(bus, dev))) {
413 error = -EIO;
414 memset((void *)buffer, 0xff, count);
415 goto err_out;
416 }
417 offset |= bus->sdio_sbaddr & 0xffff;
418 offset &= SBSDIO_SB_OFT_ADDR_MASK;
419
420 switch (reg_width) {
421 case sizeof(u8):
422 error = sdio_writesb(bus->host_sdio, offset,
423 (void *)buffer, count);
424 break;
425 case sizeof(u16):
426 SSB_WARN_ON(count & 1);
427 error = sdio_writesb(bus->host_sdio, offset,
428 (void *)buffer, count);
429 break;
430 case sizeof(u32):
431 SSB_WARN_ON(count & 3);
432 offset |= SBSDIO_SB_ACCESS_2_4B_FLAG; /* 32 bit data access */
433 error = sdio_writesb(bus->host_sdio, offset,
434 (void *)buffer, count);
435 break;
436 default:
437 SSB_WARN_ON(1);
438 }
439 if (!error)
440 goto out;
441
442err_out:
443 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X (width=%u, len=%u), error %d\n",
444 bus->sdio_sbaddr >> 16, offset, reg_width, saved_count, error);
445out:
446 sdio_release_host(bus->host_sdio);
447}
448
449#endif /* CONFIG_SSB_BLOCKIO */
450
451/* Not "static", as it's used in main.c */
452const struct ssb_bus_ops ssb_sdio_ops = {
453 .read8 = ssb_sdio_read8,
454 .read16 = ssb_sdio_read16,
455 .read32 = ssb_sdio_read32,
456 .write8 = ssb_sdio_write8,
457 .write16 = ssb_sdio_write16,
458 .write32 = ssb_sdio_write32,
459#ifdef CONFIG_SSB_BLOCKIO
460 .block_read = ssb_sdio_block_read,
461 .block_write = ssb_sdio_block_write,
462#endif
463};
464
465#define GOTO_ERROR_ON(condition, description) do { \
466 if (unlikely(condition)) { \
467 error_description = description; \
468 goto error; \
469 } \
470 } while (0)
471
472int ssb_sdio_get_invariants(struct ssb_bus *bus,
473 struct ssb_init_invariants *iv)
474{
475 struct ssb_sprom *sprom = &iv->sprom;
476 struct ssb_boardinfo *bi = &iv->boardinfo;
477 const char *error_description = "none";
478 struct sdio_func_tuple *tuple;
479 void *mac;
480
481 memset(sprom, 0xFF, sizeof(*sprom));
482 sprom->boardflags_lo = 0;
483 sprom->boardflags_hi = 0;
484
485 tuple = bus->host_sdio->tuples;
486 while (tuple) {
487 switch (tuple->code) {
488 case 0x22: /* extended function */
489 switch (tuple->data[0]) {
490 case CISTPL_FUNCE_LAN_NODE_ID:
491 GOTO_ERROR_ON((tuple->size != 7) &&
492 (tuple->data[1] != 6),
493 "mac tpl size");
494 /* fetch the MAC address. */
495 mac = tuple->data + 2;
496 memcpy(sprom->il0mac, mac, ETH_ALEN);
497 memcpy(sprom->et1mac, mac, ETH_ALEN);
498 break;
499 default:
500 break;
501 }
502 break;
503 case 0x80: /* vendor specific tuple */
504 switch (tuple->data[0]) {
505 case SSB_SDIO_CIS_SROMREV:
506 GOTO_ERROR_ON(tuple->size != 2,
507 "sromrev tpl size");
508 sprom->revision = tuple->data[1];
509 break;
510 case SSB_SDIO_CIS_ID:
511 GOTO_ERROR_ON((tuple->size != 5) &&
512 (tuple->size != 7),
513 "id tpl size");
514 bi->vendor = tuple->data[1] |
515 (tuple->data[2]<<8);
516 break;
517 case SSB_SDIO_CIS_BOARDREV:
518 GOTO_ERROR_ON(tuple->size != 2,
519 "boardrev tpl size");
520 sprom->board_rev = tuple->data[1];
521 break;
522 case SSB_SDIO_CIS_PA:
523 GOTO_ERROR_ON((tuple->size != 9) &&
524 (tuple->size != 10),
525 "pa tpl size");
526 sprom->pa0b0 = tuple->data[1] |
527 ((u16)tuple->data[2] << 8);
528 sprom->pa0b1 = tuple->data[3] |
529 ((u16)tuple->data[4] << 8);
530 sprom->pa0b2 = tuple->data[5] |
531 ((u16)tuple->data[6] << 8);
532 sprom->itssi_a = tuple->data[7];
533 sprom->itssi_bg = tuple->data[7];
534 sprom->maxpwr_a = tuple->data[8];
535 sprom->maxpwr_bg = tuple->data[8];
536 break;
537 case SSB_SDIO_CIS_OEMNAME:
538 /* Not present */
539 break;
540 case SSB_SDIO_CIS_CCODE:
541 GOTO_ERROR_ON(tuple->size != 2,
542 "ccode tpl size");
543 sprom->country_code = tuple->data[1];
544 break;
545 case SSB_SDIO_CIS_ANTENNA:
546 GOTO_ERROR_ON(tuple->size != 2,
547 "ant tpl size");
548 sprom->ant_available_a = tuple->data[1];
549 sprom->ant_available_bg = tuple->data[1];
550 break;
551 case SSB_SDIO_CIS_ANTGAIN:
552 GOTO_ERROR_ON(tuple->size != 2,
553 "antg tpl size");
554 sprom->antenna_gain.ghz24.a0 = tuple->data[1];
555 sprom->antenna_gain.ghz24.a1 = tuple->data[1];
556 sprom->antenna_gain.ghz24.a2 = tuple->data[1];
557 sprom->antenna_gain.ghz24.a3 = tuple->data[1];
558 sprom->antenna_gain.ghz5.a0 = tuple->data[1];
559 sprom->antenna_gain.ghz5.a1 = tuple->data[1];
560 sprom->antenna_gain.ghz5.a2 = tuple->data[1];
561 sprom->antenna_gain.ghz5.a3 = tuple->data[1];
562 break;
563 case SSB_SDIO_CIS_BFLAGS:
564 GOTO_ERROR_ON((tuple->size != 3) &&
565 (tuple->size != 5),
566 "bfl tpl size");
567 sprom->boardflags_lo = tuple->data[1] |
568 ((u16)tuple->data[2] << 8);
569 break;
570 case SSB_SDIO_CIS_LEDS:
571 GOTO_ERROR_ON(tuple->size != 5,
572 "leds tpl size");
573 sprom->gpio0 = tuple->data[1];
574 sprom->gpio1 = tuple->data[2];
575 sprom->gpio2 = tuple->data[3];
576 sprom->gpio3 = tuple->data[4];
577 break;
578 default:
579 break;
580 }
581 break;
582 default:
583 break;
584 }
585 tuple = tuple->next;
586 }
587
588 return 0;
589error:
590 dev_err(ssb_sdio_dev(bus), "failed to fetch device invariants: %s\n",
591 error_description);
592 return -ENODEV;
593}
594
595void ssb_sdio_exit(struct ssb_bus *bus)
596{
597 if (bus->bustype != SSB_BUSTYPE_SDIO)
598 return;
599 /* Nothing to do here. */
600}
601
602int ssb_sdio_init(struct ssb_bus *bus)
603{
604 if (bus->bustype != SSB_BUSTYPE_SDIO)
605 return 0;
606
607 bus->sdio_sbaddr = ~0;
608
609 return 0;
610}
diff --git a/drivers/ssb/ssb_private.h b/drivers/ssb/ssb_private.h
index 57fa482abb9..25433565dfd 100644
--- a/drivers/ssb/ssb_private.h
+++ b/drivers/ssb/ssb_private.h
@@ -114,6 +114,46 @@ static inline int ssb_pcmcia_init(struct ssb_bus *bus)
114} 114}
115#endif /* CONFIG_SSB_PCMCIAHOST */ 115#endif /* CONFIG_SSB_PCMCIAHOST */
116 116
117/* sdio.c */
118#ifdef CONFIG_SSB_SDIOHOST
119extern int ssb_sdio_get_invariants(struct ssb_bus *bus,
120 struct ssb_init_invariants *iv);
121
122extern u32 ssb_sdio_scan_read32(struct ssb_bus *bus, u16 offset);
123extern int ssb_sdio_switch_core(struct ssb_bus *bus, struct ssb_device *dev);
124extern int ssb_sdio_scan_switch_coreidx(struct ssb_bus *bus, u8 coreidx);
125extern int ssb_sdio_hardware_setup(struct ssb_bus *bus);
126extern void ssb_sdio_exit(struct ssb_bus *bus);
127extern int ssb_sdio_init(struct ssb_bus *bus);
128
129extern const struct ssb_bus_ops ssb_sdio_ops;
130#else /* CONFIG_SSB_SDIOHOST */
131static inline u32 ssb_sdio_scan_read32(struct ssb_bus *bus, u16 offset)
132{
133 return 0;
134}
135static inline int ssb_sdio_switch_core(struct ssb_bus *bus,
136 struct ssb_device *dev)
137{
138 return 0;
139}
140static inline int ssb_sdio_scan_switch_coreidx(struct ssb_bus *bus, u8 coreidx)
141{
142 return 0;
143}
144static inline int ssb_sdio_hardware_setup(struct ssb_bus *bus)
145{
146 return 0;
147}
148static inline void ssb_sdio_exit(struct ssb_bus *bus)
149{
150}
151static inline int ssb_sdio_init(struct ssb_bus *bus)
152{
153 return 0;
154}
155#endif /* CONFIG_SSB_SDIOHOST */
156
117 157
118/* scan.c */ 158/* scan.c */
119extern const char *ssb_core_name(u16 coreid); 159extern const char *ssb_core_name(u16 coreid);