Lines Matching full:host
3 * linux/drivers/mmc/host/wbsd.c - Winbond W83L51xD SD/MMC driver
30 #include <linux/mmc/host.h>
84 static inline void wbsd_unlock_config(struct wbsd_host *host) in wbsd_unlock_config() argument
86 BUG_ON(host->config == 0); in wbsd_unlock_config()
88 outb(host->unlock_code, host->config); in wbsd_unlock_config()
89 outb(host->unlock_code, host->config); in wbsd_unlock_config()
92 static inline void wbsd_lock_config(struct wbsd_host *host) in wbsd_lock_config() argument
94 BUG_ON(host->config == 0); in wbsd_lock_config()
96 outb(LOCK_CODE, host->config); in wbsd_lock_config()
99 static inline void wbsd_write_config(struct wbsd_host *host, u8 reg, u8 value) in wbsd_write_config() argument
101 BUG_ON(host->config == 0); in wbsd_write_config()
103 outb(reg, host->config); in wbsd_write_config()
104 outb(value, host->config + 1); in wbsd_write_config()
107 static inline u8 wbsd_read_config(struct wbsd_host *host, u8 reg) in wbsd_read_config() argument
109 BUG_ON(host->config == 0); in wbsd_read_config()
111 outb(reg, host->config); in wbsd_read_config()
112 return inb(host->config + 1); in wbsd_read_config()
115 static inline void wbsd_write_index(struct wbsd_host *host, u8 index, u8 value) in wbsd_write_index() argument
117 outb(index, host->base + WBSD_IDXR); in wbsd_write_index()
118 outb(value, host->base + WBSD_DATAR); in wbsd_write_index()
121 static inline u8 wbsd_read_index(struct wbsd_host *host, u8 index) in wbsd_read_index() argument
123 outb(index, host->base + WBSD_IDXR); in wbsd_read_index()
124 return inb(host->base + WBSD_DATAR); in wbsd_read_index()
131 static void wbsd_init_device(struct wbsd_host *host) in wbsd_init_device() argument
138 setup = wbsd_read_index(host, WBSD_IDX_SETUP); in wbsd_init_device()
140 wbsd_write_index(host, WBSD_IDX_SETUP, setup); in wbsd_init_device()
146 wbsd_write_index(host, WBSD_IDX_SETUP, setup); in wbsd_init_device()
147 host->flags &= ~WBSD_FIGNORE_DETECT; in wbsd_init_device()
152 host->clk = wbsd_read_index(host, WBSD_IDX_CLK); in wbsd_init_device()
157 outb(WBSD_POWER_N, host->base + WBSD_CSR); in wbsd_init_device()
162 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F); in wbsd_init_device()
167 if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT) in wbsd_init_device()
168 host->flags |= WBSD_FCARD_PRESENT; in wbsd_init_device()
170 host->flags &= ~WBSD_FCARD_PRESENT; in wbsd_init_device()
182 outb(ier, host->base + WBSD_EIR); in wbsd_init_device()
187 inb(host->base + WBSD_ISR); in wbsd_init_device()
190 static void wbsd_reset(struct wbsd_host *host) in wbsd_reset() argument
194 pr_err("%s: Resetting chip\n", mmc_hostname(host->mmc)); in wbsd_reset()
199 setup = wbsd_read_index(host, WBSD_IDX_SETUP); in wbsd_reset()
201 wbsd_write_index(host, WBSD_IDX_SETUP, setup); in wbsd_reset()
204 static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq) in wbsd_request_end() argument
208 if (host->dma >= 0) { in wbsd_request_end()
213 disable_dma(host->dma); in wbsd_request_end()
214 clear_dma_ff(host->dma); in wbsd_request_end()
218 * Disable DMA on host. in wbsd_request_end()
220 wbsd_write_index(host, WBSD_IDX_DMA, 0); in wbsd_request_end()
223 host->mrq = NULL; in wbsd_request_end()
228 spin_unlock(&host->lock); in wbsd_request_end()
229 mmc_request_done(host->mmc, mrq); in wbsd_request_end()
230 spin_lock(&host->lock); in wbsd_request_end()
237 static inline void wbsd_init_sg(struct wbsd_host *host, struct mmc_data *data) in wbsd_init_sg() argument
242 host->cur_sg = data->sg; in wbsd_init_sg()
243 host->num_sg = data->sg_len; in wbsd_init_sg()
245 host->offset = 0; in wbsd_init_sg()
246 host->remain = host->cur_sg->length; in wbsd_init_sg()
249 static inline int wbsd_next_sg(struct wbsd_host *host) in wbsd_next_sg() argument
254 host->cur_sg++; in wbsd_next_sg()
255 host->num_sg--; in wbsd_next_sg()
260 if (host->num_sg > 0) { in wbsd_next_sg()
261 host->offset = 0; in wbsd_next_sg()
262 host->remain = host->cur_sg->length; in wbsd_next_sg()
265 return host->num_sg; in wbsd_next_sg()
268 static inline char *wbsd_map_sg(struct wbsd_host *host) in wbsd_map_sg() argument
270 return kmap_local_page(sg_page(host->cur_sg)) + host->cur_sg->offset; in wbsd_map_sg()
273 static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data) in wbsd_sg_to_dma() argument
280 sg_copy_to_buffer(data->sg, data->sg_len, host->dma_buffer, len); in wbsd_sg_to_dma()
283 static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data) in wbsd_dma_to_sg() argument
290 sg_copy_from_buffer(data->sg, data->sg_len, host->dma_buffer, len); in wbsd_dma_to_sg()
297 static inline void wbsd_get_short_reply(struct wbsd_host *host, in wbsd_get_short_reply() argument
303 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) { in wbsd_get_short_reply()
308 cmd->resp[0] = wbsd_read_index(host, WBSD_IDX_RESP12) << 24; in wbsd_get_short_reply()
309 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP13) << 16; in wbsd_get_short_reply()
310 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP14) << 8; in wbsd_get_short_reply()
311 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP15) << 0; in wbsd_get_short_reply()
312 cmd->resp[1] = wbsd_read_index(host, WBSD_IDX_RESP16) << 24; in wbsd_get_short_reply()
315 static inline void wbsd_get_long_reply(struct wbsd_host *host, in wbsd_get_long_reply() argument
323 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) { in wbsd_get_long_reply()
330 wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24; in wbsd_get_long_reply()
332 wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16; in wbsd_get_long_reply()
334 wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8; in wbsd_get_long_reply()
336 wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0; in wbsd_get_long_reply()
340 static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd) in wbsd_send_command() argument
350 host->isr = 0; in wbsd_send_command()
353 * Send the command (CRC calculated by host). in wbsd_send_command()
355 outb(cmd->opcode, host->base + WBSD_CMDR); in wbsd_send_command()
357 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR); in wbsd_send_command()
365 status = wbsd_read_index(host, WBSD_IDX_STATUS); in wbsd_send_command()
375 isr = host->isr; in wbsd_send_command()
389 wbsd_get_long_reply(host, cmd); in wbsd_send_command()
391 wbsd_get_short_reply(host, cmd); in wbsd_send_command()
400 static void wbsd_empty_fifo(struct wbsd_host *host) in wbsd_empty_fifo() argument
402 struct mmc_data *data = host->mrq->cmd->data; in wbsd_empty_fifo()
409 if (host->num_sg == 0) in wbsd_empty_fifo()
412 buffer = wbsd_map_sg(host) + host->offset; in wbsd_empty_fifo()
419 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY)) { in wbsd_empty_fifo()
432 buffer[idx++] = inb(host->base + WBSD_DFR); in wbsd_empty_fifo()
433 host->offset++; in wbsd_empty_fifo()
434 host->remain--; in wbsd_empty_fifo()
441 if (host->remain == 0) { in wbsd_empty_fifo()
446 if (!wbsd_next_sg(host)) in wbsd_empty_fifo()
449 buffer = wbsd_map_sg(host); in wbsd_empty_fifo()
462 queue_work(system_bh_wq, &host->fifo_bh_work); in wbsd_empty_fifo()
465 static void wbsd_fill_fifo(struct wbsd_host *host) in wbsd_fill_fifo() argument
467 struct mmc_data *data = host->mrq->cmd->data; in wbsd_fill_fifo()
475 if (host->num_sg == 0) in wbsd_fill_fifo()
478 buffer = wbsd_map_sg(host) + host->offset; in wbsd_fill_fifo()
485 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL)) { in wbsd_fill_fifo()
498 outb(buffer[idx], host->base + WBSD_DFR); in wbsd_fill_fifo()
499 host->offset++; in wbsd_fill_fifo()
500 host->remain--; in wbsd_fill_fifo()
507 if (host->remain == 0) { in wbsd_fill_fifo()
512 if (!wbsd_next_sg(host)) in wbsd_fill_fifo()
515 buffer = wbsd_map_sg(host); in wbsd_fill_fifo()
527 queue_work(system_bh_wq, &host->fifo_bh_work); in wbsd_fill_fifo()
530 static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data) in wbsd_prepare_data() argument
547 wbsd_write_index(host, WBSD_IDX_TAAC, 127); in wbsd_prepare_data()
549 wbsd_write_index(host, WBSD_IDX_TAAC, in wbsd_prepare_data()
554 wbsd_write_index(host, WBSD_IDX_NSAC, 255); in wbsd_prepare_data()
556 wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks); in wbsd_prepare_data()
566 if (host->bus_width == MMC_BUS_WIDTH_1) { in wbsd_prepare_data()
569 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0); in wbsd_prepare_data()
570 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); in wbsd_prepare_data()
571 } else if (host->bus_width == MMC_BUS_WIDTH_4) { in wbsd_prepare_data()
574 wbsd_write_index(host, WBSD_IDX_PBSMSB, in wbsd_prepare_data()
576 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); in wbsd_prepare_data()
587 setup = wbsd_read_index(host, WBSD_IDX_SETUP); in wbsd_prepare_data()
589 wbsd_write_index(host, WBSD_IDX_SETUP, setup); in wbsd_prepare_data()
594 if (host->dma >= 0) { in wbsd_prepare_data()
609 wbsd_sg_to_dma(host, data); in wbsd_prepare_data()
615 disable_dma(host->dma); in wbsd_prepare_data()
616 clear_dma_ff(host->dma); in wbsd_prepare_data()
618 set_dma_mode(host->dma, DMA_MODE_READ & ~0x40); in wbsd_prepare_data()
620 set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40); in wbsd_prepare_data()
621 set_dma_addr(host->dma, host->dma_addr); in wbsd_prepare_data()
622 set_dma_count(host->dma, size); in wbsd_prepare_data()
624 enable_dma(host->dma); in wbsd_prepare_data()
628 * Enable DMA on the host. in wbsd_prepare_data()
630 wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE); in wbsd_prepare_data()
636 host->firsterr = 1; in wbsd_prepare_data()
641 wbsd_init_sg(host, data); in wbsd_prepare_data()
646 wbsd_write_index(host, WBSD_IDX_DMA, 0); in wbsd_prepare_data()
653 wbsd_write_index(host, WBSD_IDX_FIFOEN, in wbsd_prepare_data()
656 wbsd_write_index(host, WBSD_IDX_FIFOEN, in wbsd_prepare_data()
658 wbsd_fill_fifo(host); in wbsd_prepare_data()
665 static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data) in wbsd_finish_data() argument
671 WARN_ON(host->mrq == NULL); in wbsd_finish_data()
677 wbsd_send_command(host, data->stop); in wbsd_finish_data()
684 status = wbsd_read_index(host, WBSD_IDX_STATUS); in wbsd_finish_data()
690 if (host->dma >= 0) { in wbsd_finish_data()
692 * Disable DMA on the host. in wbsd_finish_data()
694 wbsd_write_index(host, WBSD_IDX_DMA, 0); in wbsd_finish_data()
700 disable_dma(host->dma); in wbsd_finish_data()
701 clear_dma_ff(host->dma); in wbsd_finish_data()
702 count = get_dma_residue(host->dma); in wbsd_finish_data()
705 data->bytes_xfered = host->mrq->data->blocks * in wbsd_finish_data()
706 host->mrq->data->blksz - count; in wbsd_finish_data()
715 mmc_hostname(host->mmc), count); in wbsd_finish_data()
725 wbsd_dma_to_sg(host, data); in wbsd_finish_data()
734 wbsd_request_end(host, host->mrq); in wbsd_finish_data()
745 struct wbsd_host *host = mmc_priv(mmc); in wbsd_request() local
751 spin_lock_bh(&host->lock); in wbsd_request()
753 BUG_ON(host->mrq != NULL); in wbsd_request()
757 host->mrq = mrq; in wbsd_request()
762 if (!(host->flags & WBSD_FCARD_PRESENT)) { in wbsd_request()
795 mmc_hostname(host->mmc), cmd->opcode); in wbsd_request()
806 wbsd_prepare_data(host, cmd->data); in wbsd_request()
812 wbsd_send_command(host, cmd); in wbsd_request()
823 if (host->dma == -1) in wbsd_request()
824 queue_work(system_bh_wq, &host->fifo_bh_work); in wbsd_request()
826 spin_unlock_bh(&host->lock); in wbsd_request()
832 wbsd_request_end(host, mrq); in wbsd_request()
834 spin_unlock_bh(&host->lock); in wbsd_request()
839 struct wbsd_host *host = mmc_priv(mmc); in wbsd_set_ios() local
842 spin_lock_bh(&host->lock); in wbsd_set_ios()
849 wbsd_init_device(host); in wbsd_set_ios()
864 if (clk != host->clk) { in wbsd_set_ios()
865 wbsd_write_index(host, WBSD_IDX_CLK, clk); in wbsd_set_ios()
866 host->clk = clk; in wbsd_set_ios()
873 pwr = inb(host->base + WBSD_CSR); in wbsd_set_ios()
875 outb(pwr, host->base + WBSD_CSR); in wbsd_set_ios()
883 setup = wbsd_read_index(host, WBSD_IDX_SETUP); in wbsd_set_ios()
887 host->flags |= WBSD_FIGNORE_DETECT; in wbsd_set_ios()
896 mod_timer(&host->ignore_timer, jiffies + HZ / 100); in wbsd_set_ios()
899 wbsd_write_index(host, WBSD_IDX_SETUP, setup); in wbsd_set_ios()
905 host->bus_width = ios->bus_width; in wbsd_set_ios()
907 spin_unlock_bh(&host->lock); in wbsd_set_ios()
912 struct wbsd_host *host = mmc_priv(mmc); in wbsd_get_ro() local
915 spin_lock_bh(&host->lock); in wbsd_get_ro()
917 csr = inb(host->base + WBSD_CSR); in wbsd_get_ro()
919 outb(csr, host->base + WBSD_CSR); in wbsd_get_ro()
923 csr = inb(host->base + WBSD_CSR); in wbsd_get_ro()
925 outb(csr, host->base + WBSD_CSR); in wbsd_get_ro()
927 spin_unlock_bh(&host->lock); in wbsd_get_ro()
950 struct wbsd_host *host = from_timer(host, t, ignore_timer); in wbsd_reset_ignore() local
952 BUG_ON(host == NULL); in wbsd_reset_ignore()
956 spin_lock_bh(&host->lock); in wbsd_reset_ignore()
958 host->flags &= ~WBSD_FIGNORE_DETECT; in wbsd_reset_ignore()
964 queue_work(system_bh_wq, &host->card_bh_work); in wbsd_reset_ignore()
966 spin_unlock_bh(&host->lock); in wbsd_reset_ignore()
973 static inline struct mmc_data *wbsd_get_data(struct wbsd_host *host) in wbsd_get_data() argument
975 WARN_ON(!host->mrq); in wbsd_get_data()
976 if (!host->mrq) in wbsd_get_data()
979 WARN_ON(!host->mrq->cmd); in wbsd_get_data()
980 if (!host->mrq->cmd) in wbsd_get_data()
983 WARN_ON(!host->mrq->cmd->data); in wbsd_get_data()
984 if (!host->mrq->cmd->data) in wbsd_get_data()
987 return host->mrq->cmd->data; in wbsd_get_data()
992 struct wbsd_host *host = from_work(host, t, card_bh_work); in wbsd_card_bh_work() local
996 spin_lock(&host->lock); in wbsd_card_bh_work()
998 if (host->flags & WBSD_FIGNORE_DETECT) { in wbsd_card_bh_work()
999 spin_unlock(&host->lock); in wbsd_card_bh_work()
1003 csr = inb(host->base + WBSD_CSR); in wbsd_card_bh_work()
1007 if (!(host->flags & WBSD_FCARD_PRESENT)) { in wbsd_card_bh_work()
1009 host->flags |= WBSD_FCARD_PRESENT; in wbsd_card_bh_work()
1013 } else if (host->flags & WBSD_FCARD_PRESENT) { in wbsd_card_bh_work()
1015 host->flags &= ~WBSD_FCARD_PRESENT; in wbsd_card_bh_work()
1017 if (host->mrq) { in wbsd_card_bh_work()
1019 mmc_hostname(host->mmc)); in wbsd_card_bh_work()
1020 wbsd_reset(host); in wbsd_card_bh_work()
1022 host->mrq->cmd->error = -ENOMEDIUM; in wbsd_card_bh_work()
1023 queue_work(system_bh_wq, &host->finish_bh_work); in wbsd_card_bh_work()
1033 spin_unlock(&host->lock); in wbsd_card_bh_work()
1036 mmc_detect_change(host->mmc, msecs_to_jiffies(delay)); in wbsd_card_bh_work()
1041 struct wbsd_host *host = from_work(host, t, fifo_bh_work); in wbsd_fifo_bh_work() local
1044 spin_lock(&host->lock); in wbsd_fifo_bh_work()
1046 if (!host->mrq) in wbsd_fifo_bh_work()
1049 data = wbsd_get_data(host); in wbsd_fifo_bh_work()
1054 wbsd_fill_fifo(host); in wbsd_fifo_bh_work()
1056 wbsd_empty_fifo(host); in wbsd_fifo_bh_work()
1061 if (host->num_sg == 0) { in wbsd_fifo_bh_work()
1062 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0); in wbsd_fifo_bh_work()
1063 queue_work(system_bh_wq, &host->finish_bh_work); in wbsd_fifo_bh_work()
1067 spin_unlock(&host->lock); in wbsd_fifo_bh_work()
1072 struct wbsd_host *host = from_work(host, t, crc_bh_work); in wbsd_crc_bh_work() local
1075 spin_lock(&host->lock); in wbsd_crc_bh_work()
1077 if (!host->mrq) in wbsd_crc_bh_work()
1080 data = wbsd_get_data(host); in wbsd_crc_bh_work()
1088 queue_work(system_bh_wq, &host->finish_bh_work); in wbsd_crc_bh_work()
1091 spin_unlock(&host->lock); in wbsd_crc_bh_work()
1096 struct wbsd_host *host = from_work(host, t, timeout_bh_work); in wbsd_timeout_bh_work() local
1099 spin_lock(&host->lock); in wbsd_timeout_bh_work()
1101 if (!host->mrq) in wbsd_timeout_bh_work()
1104 data = wbsd_get_data(host); in wbsd_timeout_bh_work()
1112 queue_work(system_bh_wq, &host->finish_bh_work); in wbsd_timeout_bh_work()
1115 spin_unlock(&host->lock); in wbsd_timeout_bh_work()
1120 struct wbsd_host *host = from_work(host, t, finish_bh_work); in wbsd_finish_bh_work() local
1123 spin_lock(&host->lock); in wbsd_finish_bh_work()
1125 WARN_ON(!host->mrq); in wbsd_finish_bh_work()
1126 if (!host->mrq) in wbsd_finish_bh_work()
1129 data = wbsd_get_data(host); in wbsd_finish_bh_work()
1133 wbsd_finish_data(host, data); in wbsd_finish_bh_work()
1136 spin_unlock(&host->lock); in wbsd_finish_bh_work()
1145 struct wbsd_host *host = dev_id; in wbsd_irq() local
1148 isr = inb(host->base + WBSD_ISR); in wbsd_irq()
1156 host->isr |= isr; in wbsd_irq()
1162 queue_work(system_bh_wq, &host->card_bh_work); in wbsd_irq()
1164 queue_work(system_bh_wq, &host->fifo_bh_work); in wbsd_irq()
1166 queue_work(system_bh_highpri_wq, &host->crc_bh_work); in wbsd_irq()
1168 queue_work(system_bh_highpri_wq, &host->timeout_bh_work); in wbsd_irq()
1170 queue_work(system_bh_wq, &host->finish_bh_work); in wbsd_irq()
1188 struct wbsd_host *host; in wbsd_alloc_mmc() local
1197 host = mmc_priv(mmc); in wbsd_alloc_mmc()
1198 host->mmc = mmc; in wbsd_alloc_mmc()
1200 host->dma = -1; in wbsd_alloc_mmc()
1203 * Set host parameters. in wbsd_alloc_mmc()
1211 spin_lock_init(&host->lock); in wbsd_alloc_mmc()
1216 timer_setup(&host->ignore_timer, wbsd_reset_ignore, 0); in wbsd_alloc_mmc()
1255 struct wbsd_host *host; in wbsd_free_mmc() local
1261 host = mmc_priv(mmc); in wbsd_free_mmc()
1262 BUG_ON(host == NULL); in wbsd_free_mmc()
1264 del_timer_sync(&host->ignore_timer); in wbsd_free_mmc()
1273 static int wbsd_scan(struct wbsd_host *host) in wbsd_scan() argument
1287 host->config = config_ports[i]; in wbsd_scan()
1288 host->unlock_code = unlock_codes[j]; in wbsd_scan()
1290 wbsd_unlock_config(host); in wbsd_scan()
1298 wbsd_lock_config(host); in wbsd_scan()
1302 host->chip_id = id; in wbsd_scan()
1317 host->config = 0; in wbsd_scan()
1318 host->unlock_code = 0; in wbsd_scan()
1327 static int wbsd_request_region(struct wbsd_host *host, int base) in wbsd_request_region() argument
1335 host->base = base; in wbsd_request_region()
1340 static void wbsd_release_regions(struct wbsd_host *host) in wbsd_release_regions() argument
1342 if (host->base) in wbsd_release_regions()
1343 release_region(host->base, 8); in wbsd_release_regions()
1345 host->base = 0; in wbsd_release_regions()
1347 if (host->config) in wbsd_release_regions()
1348 release_region(host->config, 2); in wbsd_release_regions()
1350 host->config = 0; in wbsd_release_regions()
1357 static void wbsd_request_dma(struct wbsd_host *host, int dma) in wbsd_request_dma() argument
1369 host->dma_buffer = kmalloc(WBSD_DMA_SIZE, in wbsd_request_dma()
1371 if (!host->dma_buffer) in wbsd_request_dma()
1377 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer, in wbsd_request_dma()
1379 if (dma_mapping_error(mmc_dev(host->mmc), host->dma_addr)) in wbsd_request_dma()
1385 if ((host->dma_addr & 0xffff) != 0) in wbsd_request_dma()
1390 else if (host->dma_addr >= 0x1000000) in wbsd_request_dma()
1393 host->dma = dma; in wbsd_request_dma()
1403 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, in wbsd_request_dma()
1405 host->dma_addr = 0; in wbsd_request_dma()
1408 kfree(host->dma_buffer); in wbsd_request_dma()
1409 host->dma_buffer = NULL; in wbsd_request_dma()
1419 static void wbsd_release_dma(struct wbsd_host *host) in wbsd_release_dma() argument
1422 * host->dma_addr is valid here iff host->dma_buffer is not NULL. in wbsd_release_dma()
1424 if (host->dma_buffer) { in wbsd_release_dma()
1425 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, in wbsd_release_dma()
1427 kfree(host->dma_buffer); in wbsd_release_dma()
1429 if (host->dma >= 0) in wbsd_release_dma()
1430 free_dma(host->dma); in wbsd_release_dma()
1432 host->dma = -1; in wbsd_release_dma()
1433 host->dma_buffer = NULL; in wbsd_release_dma()
1434 host->dma_addr = 0; in wbsd_release_dma()
1441 static int wbsd_request_irq(struct wbsd_host *host, int irq) in wbsd_request_irq() argument
1448 INIT_WORK(&host->card_bh_work, wbsd_card_bh_work); in wbsd_request_irq()
1449 INIT_WORK(&host->fifo_bh_work, wbsd_fifo_bh_work); in wbsd_request_irq()
1450 INIT_WORK(&host->crc_bh_work, wbsd_crc_bh_work); in wbsd_request_irq()
1451 INIT_WORK(&host->timeout_bh_work, wbsd_timeout_bh_work); in wbsd_request_irq()
1452 INIT_WORK(&host->finish_bh_work, wbsd_finish_bh_work); in wbsd_request_irq()
1457 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host); in wbsd_request_irq()
1461 host->irq = irq; in wbsd_request_irq()
1466 static void wbsd_release_irq(struct wbsd_host *host) in wbsd_release_irq() argument
1468 if (!host->irq) in wbsd_release_irq()
1471 free_irq(host->irq, host); in wbsd_release_irq()
1473 host->irq = 0; in wbsd_release_irq()
1475 cancel_work_sync(&host->card_bh_work); in wbsd_release_irq()
1476 cancel_work_sync(&host->fifo_bh_work); in wbsd_release_irq()
1477 cancel_work_sync(&host->crc_bh_work); in wbsd_release_irq()
1478 cancel_work_sync(&host->timeout_bh_work); in wbsd_release_irq()
1479 cancel_work_sync(&host->finish_bh_work); in wbsd_release_irq()
1483 * Allocate all resources for the host.
1486 static int wbsd_request_resources(struct wbsd_host *host, in wbsd_request_resources() argument
1494 ret = wbsd_request_region(host, base); in wbsd_request_resources()
1501 ret = wbsd_request_irq(host, irq); in wbsd_request_resources()
1508 wbsd_request_dma(host, dma); in wbsd_request_resources()
1514 * Release all resources for the host.
1517 static void wbsd_release_resources(struct wbsd_host *host) in wbsd_release_resources() argument
1519 wbsd_release_dma(host); in wbsd_release_resources()
1520 wbsd_release_irq(host); in wbsd_release_resources()
1521 wbsd_release_regions(host); in wbsd_release_resources()
1528 static void wbsd_chip_config(struct wbsd_host *host) in wbsd_chip_config() argument
1530 wbsd_unlock_config(host); in wbsd_chip_config()
1535 wbsd_write_config(host, WBSD_CONF_SWRST, 1); in wbsd_chip_config()
1536 wbsd_write_config(host, WBSD_CONF_SWRST, 0); in wbsd_chip_config()
1541 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_config()
1546 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11); in wbsd_chip_config()
1551 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8); in wbsd_chip_config()
1552 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff); in wbsd_chip_config()
1554 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq); in wbsd_chip_config()
1556 if (host->dma >= 0) in wbsd_chip_config()
1557 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma); in wbsd_chip_config()
1562 wbsd_write_config(host, WBSD_CONF_ENABLE, 1); in wbsd_chip_config()
1563 wbsd_write_config(host, WBSD_CONF_POWER, 0x20); in wbsd_chip_config()
1565 wbsd_lock_config(host); in wbsd_chip_config()
1572 static int wbsd_chip_validate(struct wbsd_host *host) in wbsd_chip_validate() argument
1576 wbsd_unlock_config(host); in wbsd_chip_validate()
1581 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_validate()
1586 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8; in wbsd_chip_validate()
1587 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO); in wbsd_chip_validate()
1589 irq = wbsd_read_config(host, WBSD_CONF_IRQ); in wbsd_chip_validate()
1591 dma = wbsd_read_config(host, WBSD_CONF_DRQ); in wbsd_chip_validate()
1593 wbsd_lock_config(host); in wbsd_chip_validate()
1598 if (base != host->base) in wbsd_chip_validate()
1600 if (irq != host->irq) in wbsd_chip_validate()
1602 if ((dma != host->dma) && (host->dma != -1)) in wbsd_chip_validate()
1612 static void wbsd_chip_poweroff(struct wbsd_host *host) in wbsd_chip_poweroff() argument
1614 wbsd_unlock_config(host); in wbsd_chip_poweroff()
1616 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_poweroff()
1617 wbsd_write_config(host, WBSD_CONF_ENABLE, 0); in wbsd_chip_poweroff()
1619 wbsd_lock_config(host); in wbsd_chip_poweroff()
1631 struct wbsd_host *host = NULL; in wbsd_init() local
1640 host = mmc_priv(mmc); in wbsd_init()
1645 ret = wbsd_scan(host); in wbsd_init()
1658 ret = wbsd_request_resources(host, base, irq, dma); in wbsd_init()
1660 wbsd_release_resources(host); in wbsd_init()
1669 if ((host->config != 0) && !wbsd_chip_validate(host)) { in wbsd_init()
1671 wbsd_chip_config(host); in wbsd_init()
1674 wbsd_chip_config(host); in wbsd_init()
1681 if (host->config) { in wbsd_init()
1682 wbsd_unlock_config(host); in wbsd_init()
1683 wbsd_write_config(host, WBSD_CONF_PME, 0xA0); in wbsd_init()
1684 wbsd_lock_config(host); in wbsd_init()
1695 wbsd_init_device(host); in wbsd_init()
1700 wbsd_chip_poweroff(host); in wbsd_init()
1702 wbsd_release_resources(host); in wbsd_init()
1708 if (host->chip_id != 0) in wbsd_init()
1709 printk(" id %x", (int)host->chip_id); in wbsd_init()
1710 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq); in wbsd_init()
1711 if (host->dma >= 0) in wbsd_init()
1712 printk(" dma %d", (int)host->dma); in wbsd_init()
1725 struct wbsd_host *host; in wbsd_shutdown() local
1730 host = mmc_priv(mmc); in wbsd_shutdown()
1738 wbsd_chip_poweroff(host); in wbsd_shutdown()
1740 wbsd_release_resources(host); in wbsd_shutdown()
1803 struct wbsd_host *host; in wbsd_platform_suspend() local
1810 host = mmc_priv(mmc); in wbsd_platform_suspend()
1812 wbsd_chip_poweroff(host); in wbsd_platform_suspend()
1819 struct wbsd_host *host; in wbsd_platform_resume() local
1826 host = mmc_priv(mmc); in wbsd_platform_resume()
1828 wbsd_chip_config(host); in wbsd_platform_resume()
1835 wbsd_init_device(host); in wbsd_platform_resume()
1855 struct wbsd_host *host; in wbsd_pnp_resume() local
1862 host = mmc_priv(mmc); in wbsd_pnp_resume()
1867 if (host->config != 0) { in wbsd_pnp_resume()
1868 if (!wbsd_chip_validate(host)) { in wbsd_pnp_resume()
1870 wbsd_chip_config(host); in wbsd_pnp_resume()
1879 wbsd_init_device(host); in wbsd_pnp_resume()