• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/drivers/mmc/host/

Lines Matching refs:host

35 #include <linux/mmc/host.h>
86 static inline void wbsd_unlock_config(struct wbsd_host *host)
88 BUG_ON(host->config == 0);
90 outb(host->unlock_code, host->config);
91 outb(host->unlock_code, host->config);
94 static inline void wbsd_lock_config(struct wbsd_host *host)
96 BUG_ON(host->config == 0);
98 outb(LOCK_CODE, host->config);
101 static inline void wbsd_write_config(struct wbsd_host *host, u8 reg, u8 value)
103 BUG_ON(host->config == 0);
105 outb(reg, host->config);
106 outb(value, host->config + 1);
109 static inline u8 wbsd_read_config(struct wbsd_host *host, u8 reg)
111 BUG_ON(host->config == 0);
113 outb(reg, host->config);
114 return inb(host->config + 1);
117 static inline void wbsd_write_index(struct wbsd_host *host, u8 index, u8 value)
119 outb(index, host->base + WBSD_IDXR);
120 outb(value, host->base + WBSD_DATAR);
123 static inline u8 wbsd_read_index(struct wbsd_host *host, u8 index)
125 outb(index, host->base + WBSD_IDXR);
126 return inb(host->base + WBSD_DATAR);
133 static void wbsd_init_device(struct wbsd_host *host)
140 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
142 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
148 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
149 host->flags &= ~WBSD_FIGNORE_DETECT;
154 host->clk = wbsd_read_index(host, WBSD_IDX_CLK);
159 outb(WBSD_POWER_N, host->base + WBSD_CSR);
164 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F);
169 if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT)
170 host->flags |= WBSD_FCARD_PRESENT;
172 host->flags &= ~WBSD_FCARD_PRESENT;
184 outb(ier, host->base + WBSD_EIR);
189 inb(host->base + WBSD_ISR);
192 static void wbsd_reset(struct wbsd_host *host)
196 printk(KERN_ERR "%s: Resetting chip\n", mmc_hostname(host->mmc));
201 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
203 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
206 static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
212 if (host->dma >= 0) {
217 disable_dma(host->dma);
218 clear_dma_ff(host->dma);
222 * Disable DMA on host.
224 wbsd_write_index(host, WBSD_IDX_DMA, 0);
227 host->mrq = NULL;
232 spin_unlock(&host->lock);
233 mmc_request_done(host->mmc, mrq);
234 spin_lock(&host->lock);
241 static inline void wbsd_init_sg(struct wbsd_host *host, struct mmc_data *data)
246 host->cur_sg = data->sg;
247 host->num_sg = data->sg_len;
249 host->offset = 0;
250 host->remain = host->cur_sg->length;
253 static inline int wbsd_next_sg(struct wbsd_host *host)
258 host->cur_sg++;
259 host->num_sg--;
264 if (host->num_sg > 0) {
265 host->offset = 0;
266 host->remain = host->cur_sg->length;
269 return host->num_sg;
272 static inline char *wbsd_sg_to_buffer(struct wbsd_host *host)
274 return page_address(host->cur_sg->page) + host->cur_sg->offset;
277 static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
281 char *dmabuf = host->dma_buffer;
294 static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data)
298 char *dmabuf = host->dma_buffer;
315 static inline void wbsd_get_short_reply(struct wbsd_host *host,
321 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) {
326 cmd->resp[0] = wbsd_read_index(host, WBSD_IDX_RESP12) << 24;
327 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP13) << 16;
328 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP14) << 8;
329 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP15) << 0;
330 cmd->resp[1] = wbsd_read_index(host, WBSD_IDX_RESP16) << 24;
333 static inline void wbsd_get_long_reply(struct wbsd_host *host,
341 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) {
348 wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24;
350 wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16;
352 wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8;
354 wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0;
358 static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
370 host->isr = 0;
373 * Send the command (CRC calculated by host).
375 outb(cmd->opcode, host->base + WBSD_CMDR);
377 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
385 status = wbsd_read_index(host, WBSD_IDX_STATUS);
395 isr = host->isr;
409 wbsd_get_long_reply(host, cmd);
411 wbsd_get_short_reply(host, cmd);
422 static void wbsd_empty_fifo(struct wbsd_host *host)
424 struct mmc_data *data = host->mrq->cmd->data;
431 if (host->num_sg == 0)
434 buffer = wbsd_sg_to_buffer(host) + host->offset;
440 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY)) {
453 *buffer = inb(host->base + WBSD_DFR);
455 host->offset++;
456 host->remain--;
463 if (host->remain == 0) {
467 if (!wbsd_next_sg(host))
470 buffer = wbsd_sg_to_buffer(host);
481 tasklet_schedule(&host->fifo_tasklet);
484 static void wbsd_fill_fifo(struct wbsd_host *host)
486 struct mmc_data *data = host->mrq->cmd->data;
494 if (host->num_sg == 0)
497 buffer = wbsd_sg_to_buffer(host) + host->offset;
503 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL)) {
516 outb(*buffer, host->base + WBSD_DFR);
518 host->offset++;
519 host->remain--;
526 if (host->remain == 0) {
530 if (!wbsd_next_sg(host))
533 buffer = wbsd_sg_to_buffer(host);
543 tasklet_schedule(&host->fifo_tasklet);
546 static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
568 wbsd_write_index(host, WBSD_IDX_TAAC, 127);
570 wbsd_write_index(host, WBSD_IDX_TAAC,
575 wbsd_write_index(host, WBSD_IDX_NSAC, 255);
577 wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks);
587 if (host->bus_width == MMC_BUS_WIDTH_1) {
590 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0);
591 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
592 } else if (host->bus_width == MMC_BUS_WIDTH_4) {
595 wbsd_write_index(host, WBSD_IDX_PBSMSB,
597 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
608 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
610 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
615 if (host->dma >= 0) {
630 wbsd_sg_to_dma(host, data);
636 disable_dma(host->dma);
637 clear_dma_ff(host->dma);
639 set_dma_mode(host->dma, DMA_MODE_READ & ~0x40);
641 set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40);
642 set_dma_addr(host->dma, host->dma_addr);
643 set_dma_count(host->dma, size);
645 enable_dma(host->dma);
649 * Enable DMA on the host.
651 wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE);
657 host->firsterr = 1;
662 wbsd_init_sg(host, data);
667 wbsd_write_index(host, WBSD_IDX_DMA, 0);
674 wbsd_write_index(host, WBSD_IDX_FIFOEN,
677 wbsd_write_index(host, WBSD_IDX_FIFOEN,
679 wbsd_fill_fifo(host);
686 static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
692 WARN_ON(host->mrq == NULL);
698 wbsd_send_command(host, data->stop);
705 status = wbsd_read_index(host, WBSD_IDX_STATUS);
711 if (host->dma >= 0) {
713 * Disable DMA on the host.
715 wbsd_write_index(host, WBSD_IDX_DMA, 0);
721 disable_dma(host->dma);
722 clear_dma_ff(host->dma);
723 count = get_dma_residue(host->dma);
726 data->bytes_xfered = host->mrq->data->blocks *
727 host->mrq->data->blksz - count;
736 mmc_hostname(host->mmc), count);
746 wbsd_dma_to_sg(host, data);
757 wbsd_request_end(host, host->mrq);
768 struct wbsd_host *host = mmc_priv(mmc);
774 spin_lock_bh(&host->lock);
776 BUG_ON(host->mrq != NULL);
780 host->mrq = mrq;
786 if (!(host->flags & WBSD_FCARD_PRESENT)) {
821 mmc_hostname(host->mmc), cmd->opcode);
833 wbsd_prepare_data(host, cmd->data);
839 wbsd_send_command(host, cmd);
850 if (host->dma == -1)
851 tasklet_schedule(&host->fifo_tasklet);
853 spin_unlock_bh(&host->lock);
859 wbsd_request_end(host, mrq);
861 spin_unlock_bh(&host->lock);
866 struct wbsd_host *host = mmc_priv(mmc);
869 spin_lock_bh(&host->lock);
876 wbsd_init_device(host);
891 if (clk != host->clk) {
892 wbsd_write_index(host, WBSD_IDX_CLK, clk);
893 host->clk = clk;
900 pwr = inb(host->base + WBSD_CSR);
902 outb(pwr, host->base + WBSD_CSR);
910 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
914 host->flags |= WBSD_FIGNORE_DETECT;
923 mod_timer(&host->ignore_timer, jiffies + HZ / 100);
926 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
932 host->bus_width = ios->bus_width;
934 spin_unlock_bh(&host->lock);
939 struct wbsd_host *host = mmc_priv(mmc);
942 spin_lock_bh(&host->lock);
944 csr = inb(host->base + WBSD_CSR);
946 outb(csr, host->base + WBSD_CSR);
950 csr = inb(host->base + WBSD_CSR);
952 outb(csr, host->base + WBSD_CSR);
954 spin_unlock_bh(&host->lock);
977 struct wbsd_host *host = (struct wbsd_host *)data;
979 BUG_ON(host == NULL);
983 spin_lock_bh(&host->lock);
985 host->flags &= ~WBSD_FIGNORE_DETECT;
991 tasklet_schedule(&host->card_tasklet);
993 spin_unlock_bh(&host->lock);
1000 static inline struct mmc_data *wbsd_get_data(struct wbsd_host *host)
1002 WARN_ON(!host->mrq);
1003 if (!host->mrq)
1006 WARN_ON(!host->mrq->cmd);
1007 if (!host->mrq->cmd)
1010 WARN_ON(!host->mrq->cmd->data);
1011 if (!host->mrq->cmd->data)
1014 return host->mrq->cmd->data;
1019 struct wbsd_host *host = (struct wbsd_host *)param;
1023 spin_lock(&host->lock);
1025 if (host->flags & WBSD_FIGNORE_DETECT) {
1026 spin_unlock(&host->lock);
1030 csr = inb(host->base + WBSD_CSR);
1034 if (!(host->flags & WBSD_FCARD_PRESENT)) {
1036 host->flags |= WBSD_FCARD_PRESENT;
1040 } else if (host->flags & WBSD_FCARD_PRESENT) {
1042 host->flags &= ~WBSD_FCARD_PRESENT;
1044 if (host->mrq) {
1046 mmc_hostname(host->mmc));
1047 wbsd_reset(host);
1049 host->mrq->cmd->error = MMC_ERR_FAILED;
1050 tasklet_schedule(&host->finish_tasklet);
1060 spin_unlock(&host->lock);
1063 mmc_detect_change(host->mmc, msecs_to_jiffies(delay));
1068 struct wbsd_host *host = (struct wbsd_host *)param;
1071 spin_lock(&host->lock);
1073 if (!host->mrq)
1076 data = wbsd_get_data(host);
1081 wbsd_fill_fifo(host);
1083 wbsd_empty_fifo(host);
1088 if (host->num_sg == 0) {
1089 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0);
1090 tasklet_schedule(&host->finish_tasklet);
1094 spin_unlock(&host->lock);
1099 struct wbsd_host *host = (struct wbsd_host *)param;
1102 spin_lock(&host->lock);
1104 if (!host->mrq)
1107 data = wbsd_get_data(host);
1115 tasklet_schedule(&host->finish_tasklet);
1118 spin_unlock(&host->lock);
1123 struct wbsd_host *host = (struct wbsd_host *)param;
1126 spin_lock(&host->lock);
1128 if (!host->mrq)
1131 data = wbsd_get_data(host);
1139 tasklet_schedule(&host->finish_tasklet);
1142 spin_unlock(&host->lock);
1147 struct wbsd_host *host = (struct wbsd_host *)param;
1150 spin_lock(&host->lock);
1152 WARN_ON(!host->mrq);
1153 if (!host->mrq)
1156 data = wbsd_get_data(host);
1160 wbsd_finish_data(host, data);
1163 spin_unlock(&host->lock);
1172 struct wbsd_host *host = dev_id;
1175 isr = inb(host->base + WBSD_ISR);
1183 host->isr |= isr;
1189 tasklet_schedule(&host->card_tasklet);
1191 tasklet_schedule(&host->fifo_tasklet);
1193 tasklet_hi_schedule(&host->crc_tasklet);
1195 tasklet_hi_schedule(&host->timeout_tasklet);
1197 tasklet_schedule(&host->finish_tasklet);
1215 struct wbsd_host *host;
1224 host = mmc_priv(mmc);
1225 host->mmc = mmc;
1227 host->dma = -1;
1230 * Set host parameters.
1238 spin_lock_init(&host->lock);
1243 init_timer(&host->ignore_timer);
1244 host->ignore_timer.data = (unsigned long)host;
1245 host->ignore_timer.function = wbsd_reset_ignore;
1285 struct wbsd_host *host;
1291 host = mmc_priv(mmc);
1292 BUG_ON(host == NULL);
1294 del_timer_sync(&host->ignore_timer);
1305 static int __devinit wbsd_scan(struct wbsd_host *host)
1321 host->config = config_ports[i];
1322 host->unlock_code = unlock_codes[j];
1324 wbsd_unlock_config(host);
1332 wbsd_lock_config(host);
1336 host->chip_id = id;
1351 host->config = 0;
1352 host->unlock_code = 0;
1361 static int __devinit wbsd_request_region(struct wbsd_host *host, int base)
1369 host->base = base;
1374 static void __devexit wbsd_release_regions(struct wbsd_host *host)
1376 if (host->base)
1377 release_region(host->base, 8);
1379 host->base = 0;
1381 if (host->config)
1382 release_region(host->config, 2);
1384 host->config = 0;
1391 static void __devinit wbsd_request_dma(struct wbsd_host *host, int dma)
1403 host->dma_buffer = kmalloc(WBSD_DMA_SIZE,
1405 if (!host->dma_buffer)
1411 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer,
1417 if ((host->dma_addr & 0xffff) != 0)
1422 else if (host->dma_addr >= 0x1000000)
1425 host->dma = dma;
1435 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
1437 host->dma_addr = (dma_addr_t)NULL;
1439 kfree(host->dma_buffer);
1440 host->dma_buffer = NULL;
1450 static void __devexit wbsd_release_dma(struct wbsd_host *host)
1452 if (host->dma_addr) {
1453 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
1456 kfree(host->dma_buffer);
1457 if (host->dma >= 0)
1458 free_dma(host->dma);
1460 host->dma = -1;
1461 host->dma_buffer = NULL;
1462 host->dma_addr = (dma_addr_t)NULL;
1469 static int __devinit wbsd_request_irq(struct wbsd_host *host, int irq)
1477 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host);
1481 host->irq = irq;
1486 tasklet_init(&host->card_tasklet, wbsd_tasklet_card,
1487 (unsigned long)host);
1488 tasklet_init(&host->fifo_tasklet, wbsd_tasklet_fifo,
1489 (unsigned long)host);
1490 tasklet_init(&host->crc_tasklet, wbsd_tasklet_crc,
1491 (unsigned long)host);
1492 tasklet_init(&host->timeout_tasklet, wbsd_tasklet_timeout,
1493 (unsigned long)host);
1494 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish,
1495 (unsigned long)host);
1500 static void __devexit wbsd_release_irq(struct wbsd_host *host)
1502 if (!host->irq)
1505 free_irq(host->irq, host);
1507 host->irq = 0;
1509 tasklet_kill(&host->card_tasklet);
1510 tasklet_kill(&host->fifo_tasklet);
1511 tasklet_kill(&host->crc_tasklet);
1512 tasklet_kill(&host->timeout_tasklet);
1513 tasklet_kill(&host->finish_tasklet);
1517 * Allocate all resources for the host.
1520 static int __devinit wbsd_request_resources(struct wbsd_host *host,
1528 ret = wbsd_request_region(host, base);
1535 ret = wbsd_request_irq(host, irq);
1542 wbsd_request_dma(host, dma);
1548 * Release all resources for the host.
1551 static void __devexit wbsd_release_resources(struct wbsd_host *host)
1553 wbsd_release_dma(host);
1554 wbsd_release_irq(host);
1555 wbsd_release_regions(host);
1562 static void wbsd_chip_config(struct wbsd_host *host)
1564 wbsd_unlock_config(host);
1569 wbsd_write_config(host, WBSD_CONF_SWRST, 1);
1570 wbsd_write_config(host, WBSD_CONF_SWRST, 0);
1575 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1580 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11);
1585 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8);
1586 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff);
1588 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq);
1590 if (host->dma >= 0)
1591 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma);
1596 wbsd_write_config(host, WBSD_CONF_ENABLE, 1);
1597 wbsd_write_config(host, WBSD_CONF_POWER, 0x20);
1599 wbsd_lock_config(host);
1606 static int wbsd_chip_validate(struct wbsd_host *host)
1610 wbsd_unlock_config(host);
1615 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1620 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8;
1621 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO);
1623 irq = wbsd_read_config(host, WBSD_CONF_IRQ);
1625 dma = wbsd_read_config(host, WBSD_CONF_DRQ);
1627 wbsd_lock_config(host);
1632 if (base != host->base)
1634 if (irq != host->irq)
1636 if ((dma != host->dma) && (host->dma != -1))
1646 static void wbsd_chip_poweroff(struct wbsd_host *host)
1648 wbsd_unlock_config(host);
1650 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1651 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1653 wbsd_lock_config(host);
1665 struct wbsd_host *host = NULL;
1674 host = mmc_priv(mmc);
1679 ret = wbsd_scan(host);
1694 ret = wbsd_request_resources(host, base, irq, dma);
1696 wbsd_release_resources(host);
1705 if ((host->config != 0) && !wbsd_chip_validate(host)) {
1710 wbsd_chip_config(host);
1713 wbsd_chip_config(host);
1720 if (host->config) {
1721 wbsd_unlock_config(host);
1722 wbsd_write_config(host, WBSD_CONF_PME, 0xA0);
1723 wbsd_lock_config(host);
1734 wbsd_init_device(host);
1739 if (host->chip_id != 0)
1740 printk(" id %x", (int)host->chip_id);
1741 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
1742 if (host->dma >= 0)
1743 printk(" dma %d", (int)host->dma);
1756 struct wbsd_host *host;
1761 host = mmc_priv(mmc);
1769 wbsd_chip_poweroff(host);
1771 wbsd_release_resources(host);
1832 static int wbsd_suspend(struct wbsd_host *host, pm_message_t state)
1834 BUG_ON(host == NULL);
1836 return mmc_suspend_host(host->mmc, state);
1839 static int wbsd_resume(struct wbsd_host *host)
1841 BUG_ON(host == NULL);
1843 wbsd_init_device(host);
1845 return mmc_resume_host(host->mmc);
1852 struct wbsd_host *host;
1860 host = mmc_priv(mmc);
1862 ret = wbsd_suspend(host, state);
1866 wbsd_chip_poweroff(host);
1874 struct wbsd_host *host;
1881 host = mmc_priv(mmc);
1883 wbsd_chip_config(host);
1890 return wbsd_resume(host);
1898 struct wbsd_host *host;
1905 host = mmc_priv(mmc);
1907 return wbsd_suspend(host, state);
1913 struct wbsd_host *host;
1920 host = mmc_priv(mmc);
1925 if (host->config != 0) {
1926 if (!wbsd_chip_validate(host)) {
1931 wbsd_chip_config(host);
1940 return wbsd_resume(host);