Lines Matching +full:memcpy +full:- +full:bus +full:- +full:width

3  * SDIO-Hostbus related functions
9 * Copyright 2007-2008 Michael Buesch <m@bues.ch>
60 #define SBSDIO_FUNC1_SBADDRMID 0x1000b /* SB Address window Mid (b23-b16) */
61 #define SBSDIO_FUNC1_SBADDRHIGH 0x1000c /* SB Address window High (b24-b31) */
71 #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x8000 /* forces 32-bit SB access */
78 * ------- ------- ------------------------------------------
85 * In order to access the contents of a 32-bit Silicon Backplane address
94 * a 32-bit access flag
104 static inline struct device *ssb_sdio_dev(struct ssb_bus *bus) in ssb_sdio_dev() argument
106 return &bus->host_sdio->dev; in ssb_sdio_dev()
110 static int ssb_sdio_writeb(struct ssb_bus *bus, unsigned int addr, u8 val) in ssb_sdio_writeb() argument
114 sdio_writeb(bus->host_sdio, val, addr, &error); in ssb_sdio_writeb()
116 dev_dbg(ssb_sdio_dev(bus), "%08X <- %02x, error %d\n", in ssb_sdio_writeb()
124 static u8 ssb_sdio_readb(struct ssb_bus *bus, unsigned int addr)
129 val = sdio_readb(bus->host_sdio, addr, &error);
131 dev_dbg(ssb_sdio_dev(bus), "%08X -> %02x, error %d\n",
140 static int ssb_sdio_set_sbaddr_window(struct ssb_bus *bus, u32 address) in ssb_sdio_set_sbaddr_window() argument
144 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRLOW, in ssb_sdio_set_sbaddr_window()
148 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRMID, in ssb_sdio_set_sbaddr_window()
152 error = ssb_sdio_writeb(bus, SBSDIO_FUNC1_SBADDRHIGH, in ssb_sdio_set_sbaddr_window()
156 bus->sdio_sbaddr = address; in ssb_sdio_set_sbaddr_window()
159 dev_dbg(ssb_sdio_dev(bus), "failed to set address window" in ssb_sdio_set_sbaddr_window()
167 u32 ssb_sdio_scan_read32(struct ssb_bus *bus, u16 offset) in ssb_sdio_scan_read32() argument
172 sdio_claim_host(bus->host_sdio); in ssb_sdio_scan_read32()
173 val = sdio_readl(bus->host_sdio, offset, &error); in ssb_sdio_scan_read32()
174 sdio_release_host(bus->host_sdio); in ssb_sdio_scan_read32()
176 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %08x, error %d\n", in ssb_sdio_scan_read32()
177 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_scan_read32()
184 int ssb_sdio_scan_switch_coreidx(struct ssb_bus *bus, u8 coreidx) in ssb_sdio_scan_switch_coreidx() argument
190 sdio_claim_host(bus->host_sdio); in ssb_sdio_scan_switch_coreidx()
191 error = ssb_sdio_set_sbaddr_window(bus, sbaddr); in ssb_sdio_scan_switch_coreidx()
192 sdio_release_host(bus->host_sdio); in ssb_sdio_scan_switch_coreidx()
194 dev_err(ssb_sdio_dev(bus), "failed to switch to core %u," in ssb_sdio_scan_switch_coreidx()
203 static int ssb_sdio_switch_core(struct ssb_bus *bus, struct ssb_device *dev) in ssb_sdio_switch_core() argument
205 u8 coreidx = dev->core_index; in ssb_sdio_switch_core()
210 if (unlikely(bus->sdio_sbaddr != sbaddr)) { in ssb_sdio_switch_core()
212 dev_info(ssb_sdio_dev(bus), in ssb_sdio_switch_core()
214 ssb_core_name(dev->id.coreid), coreidx); in ssb_sdio_switch_core()
216 error = ssb_sdio_set_sbaddr_window(bus, sbaddr); in ssb_sdio_switch_core()
218 dev_dbg(ssb_sdio_dev(bus), "failed to switch to" in ssb_sdio_switch_core()
222 bus->mapped_device = dev; in ssb_sdio_switch_core()
231 struct ssb_bus *bus = dev->bus; in ssb_sdio_read8() local
235 sdio_claim_host(bus->host_sdio); in ssb_sdio_read8()
236 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_read8()
238 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_read8()
240 val = sdio_readb(bus->host_sdio, offset, &error); in ssb_sdio_read8()
242 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %02x, error %d\n", in ssb_sdio_read8()
243 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_read8()
246 sdio_release_host(bus->host_sdio); in ssb_sdio_read8()
253 struct ssb_bus *bus = dev->bus; in ssb_sdio_read16() local
257 sdio_claim_host(bus->host_sdio); in ssb_sdio_read16()
258 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_read16()
260 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_read16()
262 val = sdio_readw(bus->host_sdio, offset, &error); in ssb_sdio_read16()
264 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %04x, error %d\n", in ssb_sdio_read16()
265 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_read16()
268 sdio_release_host(bus->host_sdio); in ssb_sdio_read16()
275 struct ssb_bus *bus = dev->bus; in ssb_sdio_read32() local
279 sdio_claim_host(bus->host_sdio); in ssb_sdio_read32()
280 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_read32()
282 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_read32()
285 val = sdio_readl(bus->host_sdio, offset, &error); in ssb_sdio_read32()
287 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X > %08x, error %d\n", in ssb_sdio_read32()
288 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_read32()
291 sdio_release_host(bus->host_sdio); in ssb_sdio_read32()
301 struct ssb_bus *bus = dev->bus; in ssb_sdio_block_read() local
304 sdio_claim_host(bus->host_sdio); in ssb_sdio_block_read()
305 if (unlikely(ssb_sdio_switch_core(bus, dev))) { in ssb_sdio_block_read()
306 error = -EIO; in ssb_sdio_block_read()
310 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_block_read()
315 error = sdio_readsb(bus->host_sdio, buffer, offset, count); in ssb_sdio_block_read()
320 error = sdio_readsb(bus->host_sdio, buffer, offset, count); in ssb_sdio_block_read()
326 error = sdio_readsb(bus->host_sdio, buffer, offset, count); in ssb_sdio_block_read()
336 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X (width=%u, len=%zu), error %d\n", in ssb_sdio_block_read()
337 bus->sdio_sbaddr >> 16, offset, reg_width, saved_count, error); in ssb_sdio_block_read()
339 sdio_release_host(bus->host_sdio); in ssb_sdio_block_read()
345 struct ssb_bus *bus = dev->bus; in ssb_sdio_write8() local
348 sdio_claim_host(bus->host_sdio); in ssb_sdio_write8()
349 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_write8()
351 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_write8()
353 sdio_writeb(bus->host_sdio, val, offset, &error); in ssb_sdio_write8()
355 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %02x, error %d\n", in ssb_sdio_write8()
356 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_write8()
359 sdio_release_host(bus->host_sdio); in ssb_sdio_write8()
364 struct ssb_bus *bus = dev->bus; in ssb_sdio_write16() local
367 sdio_claim_host(bus->host_sdio); in ssb_sdio_write16()
368 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_write16()
370 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_write16()
372 sdio_writew(bus->host_sdio, val, offset, &error); in ssb_sdio_write16()
374 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %04x, error %d\n", in ssb_sdio_write16()
375 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_write16()
378 sdio_release_host(bus->host_sdio); in ssb_sdio_write16()
383 struct ssb_bus *bus = dev->bus; in ssb_sdio_write32() local
386 sdio_claim_host(bus->host_sdio); in ssb_sdio_write32()
387 if (unlikely(ssb_sdio_switch_core(bus, dev))) in ssb_sdio_write32()
389 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_write32()
392 sdio_writel(bus->host_sdio, val, offset, &error); in ssb_sdio_write32()
394 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X < %08x, error %d\n", in ssb_sdio_write32()
395 bus->sdio_sbaddr >> 16, offset, val, error); in ssb_sdio_write32()
397 if (bus->quirks & SSB_QUIRK_SDIO_READ_AFTER_WRITE32) in ssb_sdio_write32()
398 sdio_readl(bus->host_sdio, 0, &error); in ssb_sdio_write32()
400 sdio_release_host(bus->host_sdio); in ssb_sdio_write32()
408 struct ssb_bus *bus = dev->bus; in ssb_sdio_block_write() local
411 sdio_claim_host(bus->host_sdio); in ssb_sdio_block_write()
412 if (unlikely(ssb_sdio_switch_core(bus, dev))) { in ssb_sdio_block_write()
413 error = -EIO; in ssb_sdio_block_write()
416 offset |= bus->sdio_sbaddr & 0xffff; in ssb_sdio_block_write()
421 error = sdio_writesb(bus->host_sdio, offset, in ssb_sdio_block_write()
426 error = sdio_writesb(bus->host_sdio, offset, in ssb_sdio_block_write()
432 error = sdio_writesb(bus->host_sdio, offset, in ssb_sdio_block_write()
442 dev_dbg(ssb_sdio_dev(bus), "%04X:%04X (width=%u, len=%zu), error %d\n", in ssb_sdio_block_write()
443 bus->sdio_sbaddr >> 16, offset, reg_width, saved_count, error); in ssb_sdio_block_write()
445 sdio_release_host(bus->host_sdio); in ssb_sdio_block_write()
471 int ssb_sdio_get_invariants(struct ssb_bus *bus, in ssb_sdio_get_invariants() argument
474 struct ssb_sprom *sprom = &iv->sprom; in ssb_sdio_get_invariants()
475 struct ssb_boardinfo *bi = &iv->boardinfo; in ssb_sdio_get_invariants()
481 sprom->boardflags_lo = 0; in ssb_sdio_get_invariants()
482 sprom->boardflags_hi = 0; in ssb_sdio_get_invariants()
484 tuple = bus->host_sdio->tuples; in ssb_sdio_get_invariants()
486 switch (tuple->code) { in ssb_sdio_get_invariants()
488 switch (tuple->data[0]) { in ssb_sdio_get_invariants()
490 GOTO_ERROR_ON((tuple->size != 7) && in ssb_sdio_get_invariants()
491 (tuple->data[1] != 6), in ssb_sdio_get_invariants()
494 mac = tuple->data + 2; in ssb_sdio_get_invariants()
495 memcpy(sprom->il0mac, mac, ETH_ALEN); in ssb_sdio_get_invariants()
496 memcpy(sprom->et1mac, mac, ETH_ALEN); in ssb_sdio_get_invariants()
503 switch (tuple->data[0]) { in ssb_sdio_get_invariants()
505 GOTO_ERROR_ON(tuple->size != 2, in ssb_sdio_get_invariants()
507 sprom->revision = tuple->data[1]; in ssb_sdio_get_invariants()
510 GOTO_ERROR_ON((tuple->size != 5) && in ssb_sdio_get_invariants()
511 (tuple->size != 7), in ssb_sdio_get_invariants()
513 bi->vendor = tuple->data[1] | in ssb_sdio_get_invariants()
514 (tuple->data[2]<<8); in ssb_sdio_get_invariants()
517 GOTO_ERROR_ON(tuple->size != 2, in ssb_sdio_get_invariants()
519 sprom->board_rev = tuple->data[1]; in ssb_sdio_get_invariants()
522 GOTO_ERROR_ON((tuple->size != 9) && in ssb_sdio_get_invariants()
523 (tuple->size != 10), in ssb_sdio_get_invariants()
525 sprom->pa0b0 = tuple->data[1] | in ssb_sdio_get_invariants()
526 ((u16)tuple->data[2] << 8); in ssb_sdio_get_invariants()
527 sprom->pa0b1 = tuple->data[3] | in ssb_sdio_get_invariants()
528 ((u16)tuple->data[4] << 8); in ssb_sdio_get_invariants()
529 sprom->pa0b2 = tuple->data[5] | in ssb_sdio_get_invariants()
530 ((u16)tuple->data[6] << 8); in ssb_sdio_get_invariants()
531 sprom->itssi_a = tuple->data[7]; in ssb_sdio_get_invariants()
532 sprom->itssi_bg = tuple->data[7]; in ssb_sdio_get_invariants()
533 sprom->maxpwr_a = tuple->data[8]; in ssb_sdio_get_invariants()
534 sprom->maxpwr_bg = tuple->data[8]; in ssb_sdio_get_invariants()
540 GOTO_ERROR_ON(tuple->size != 2, in ssb_sdio_get_invariants()
542 sprom->country_code = tuple->data[1]; in ssb_sdio_get_invariants()
545 GOTO_ERROR_ON(tuple->size != 2, in ssb_sdio_get_invariants()
547 sprom->ant_available_a = tuple->data[1]; in ssb_sdio_get_invariants()
548 sprom->ant_available_bg = tuple->data[1]; in ssb_sdio_get_invariants()
551 GOTO_ERROR_ON(tuple->size != 2, in ssb_sdio_get_invariants()
553 sprom->antenna_gain.a0 = tuple->data[1]; in ssb_sdio_get_invariants()
554 sprom->antenna_gain.a1 = tuple->data[1]; in ssb_sdio_get_invariants()
555 sprom->antenna_gain.a2 = tuple->data[1]; in ssb_sdio_get_invariants()
556 sprom->antenna_gain.a3 = tuple->data[1]; in ssb_sdio_get_invariants()
559 GOTO_ERROR_ON((tuple->size != 3) && in ssb_sdio_get_invariants()
560 (tuple->size != 5), in ssb_sdio_get_invariants()
562 sprom->boardflags_lo = tuple->data[1] | in ssb_sdio_get_invariants()
563 ((u16)tuple->data[2] << 8); in ssb_sdio_get_invariants()
566 GOTO_ERROR_ON(tuple->size != 5, in ssb_sdio_get_invariants()
568 sprom->gpio0 = tuple->data[1]; in ssb_sdio_get_invariants()
569 sprom->gpio1 = tuple->data[2]; in ssb_sdio_get_invariants()
570 sprom->gpio2 = tuple->data[3]; in ssb_sdio_get_invariants()
571 sprom->gpio3 = tuple->data[4]; in ssb_sdio_get_invariants()
580 tuple = tuple->next; in ssb_sdio_get_invariants()
585 dev_err(ssb_sdio_dev(bus), "failed to fetch device invariants: %s\n", in ssb_sdio_get_invariants()
587 return -ENODEV; in ssb_sdio_get_invariants()
590 void ssb_sdio_exit(struct ssb_bus *bus) in ssb_sdio_exit() argument
592 if (bus->bustype != SSB_BUSTYPE_SDIO) in ssb_sdio_exit()
597 int ssb_sdio_init(struct ssb_bus *bus) in ssb_sdio_init() argument
599 if (bus->bustype != SSB_BUSTYPE_SDIO) in ssb_sdio_init()
602 bus->sdio_sbaddr = ~0; in ssb_sdio_init()