Lines Matching refs:host

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()
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()
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 tasklet_schedule(&host->fifo_tasklet); 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 tasklet_schedule(&host->fifo_tasklet); 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()
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()
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 tasklet_schedule(&host->fifo_tasklet); 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 tasklet_schedule(&host->card_tasklet); 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_tasklet(host, t, card_tasklet); in wbsd_tasklet_card() local
996 spin_lock(&host->lock); in wbsd_tasklet_card()
998 if (host->flags & WBSD_FIGNORE_DETECT) { in wbsd_tasklet_card()
999 spin_unlock(&host->lock); in wbsd_tasklet_card()
1003 csr = inb(host->base + WBSD_CSR); in wbsd_tasklet_card()
1007 if (!(host->flags & WBSD_FCARD_PRESENT)) { in wbsd_tasklet_card()
1009 host->flags |= WBSD_FCARD_PRESENT; in wbsd_tasklet_card()
1013 } else if (host->flags & WBSD_FCARD_PRESENT) { in wbsd_tasklet_card()
1015 host->flags &= ~WBSD_FCARD_PRESENT; in wbsd_tasklet_card()
1017 if (host->mrq) { in wbsd_tasklet_card()
1019 mmc_hostname(host->mmc)); in wbsd_tasklet_card()
1020 wbsd_reset(host); in wbsd_tasklet_card()
1022 host->mrq->cmd->error = -ENOMEDIUM; in wbsd_tasklet_card()
1023 tasklet_schedule(&host->finish_tasklet); in wbsd_tasklet_card()
1033 spin_unlock(&host->lock); in wbsd_tasklet_card()
1036 mmc_detect_change(host->mmc, msecs_to_jiffies(delay)); in wbsd_tasklet_card()
1041 struct wbsd_host *host = from_tasklet(host, t, fifo_tasklet); in wbsd_tasklet_fifo() local
1044 spin_lock(&host->lock); in wbsd_tasklet_fifo()
1046 if (!host->mrq) in wbsd_tasklet_fifo()
1049 data = wbsd_get_data(host); in wbsd_tasklet_fifo()
1054 wbsd_fill_fifo(host); in wbsd_tasklet_fifo()
1056 wbsd_empty_fifo(host); in wbsd_tasklet_fifo()
1061 if (host->num_sg == 0) { in wbsd_tasklet_fifo()
1062 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0); in wbsd_tasklet_fifo()
1063 tasklet_schedule(&host->finish_tasklet); in wbsd_tasklet_fifo()
1067 spin_unlock(&host->lock); in wbsd_tasklet_fifo()
1072 struct wbsd_host *host = from_tasklet(host, t, crc_tasklet); in wbsd_tasklet_crc() local
1075 spin_lock(&host->lock); in wbsd_tasklet_crc()
1077 if (!host->mrq) in wbsd_tasklet_crc()
1080 data = wbsd_get_data(host); in wbsd_tasklet_crc()
1088 tasklet_schedule(&host->finish_tasklet); in wbsd_tasklet_crc()
1091 spin_unlock(&host->lock); in wbsd_tasklet_crc()
1096 struct wbsd_host *host = from_tasklet(host, t, timeout_tasklet); in wbsd_tasklet_timeout() local
1099 spin_lock(&host->lock); in wbsd_tasklet_timeout()
1101 if (!host->mrq) in wbsd_tasklet_timeout()
1104 data = wbsd_get_data(host); in wbsd_tasklet_timeout()
1112 tasklet_schedule(&host->finish_tasklet); in wbsd_tasklet_timeout()
1115 spin_unlock(&host->lock); in wbsd_tasklet_timeout()
1120 struct wbsd_host *host = from_tasklet(host, t, finish_tasklet); in wbsd_tasklet_finish() local
1123 spin_lock(&host->lock); in wbsd_tasklet_finish()
1125 WARN_ON(!host->mrq); in wbsd_tasklet_finish()
1126 if (!host->mrq) in wbsd_tasklet_finish()
1129 data = wbsd_get_data(host); in wbsd_tasklet_finish()
1133 wbsd_finish_data(host, data); in wbsd_tasklet_finish()
1136 spin_unlock(&host->lock); in wbsd_tasklet_finish()
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 tasklet_schedule(&host->card_tasklet); in wbsd_irq()
1164 tasklet_schedule(&host->fifo_tasklet); in wbsd_irq()
1166 tasklet_hi_schedule(&host->crc_tasklet); in wbsd_irq()
1168 tasklet_hi_schedule(&host->timeout_tasklet); in wbsd_irq()
1170 tasklet_schedule(&host->finish_tasklet); 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()
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
1289 host->config = config_ports[i]; in wbsd_scan()
1290 host->unlock_code = unlock_codes[j]; in wbsd_scan()
1292 wbsd_unlock_config(host); in wbsd_scan()
1300 wbsd_lock_config(host); in wbsd_scan()
1304 host->chip_id = id; in wbsd_scan()
1319 host->config = 0; in wbsd_scan()
1320 host->unlock_code = 0; in wbsd_scan()
1329 static int wbsd_request_region(struct wbsd_host *host, int base) in wbsd_request_region() argument
1337 host->base = base; in wbsd_request_region()
1342 static void wbsd_release_regions(struct wbsd_host *host) in wbsd_release_regions() argument
1344 if (host->base) in wbsd_release_regions()
1345 release_region(host->base, 8); in wbsd_release_regions()
1347 host->base = 0; in wbsd_release_regions()
1349 if (host->config) in wbsd_release_regions()
1350 release_region(host->config, 2); in wbsd_release_regions()
1352 host->config = 0; in wbsd_release_regions()
1359 static void wbsd_request_dma(struct wbsd_host *host, int dma) in wbsd_request_dma() argument
1371 host->dma_buffer = kmalloc(WBSD_DMA_SIZE, in wbsd_request_dma()
1373 if (!host->dma_buffer) in wbsd_request_dma()
1379 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer, in wbsd_request_dma()
1381 if (dma_mapping_error(mmc_dev(host->mmc), host->dma_addr)) in wbsd_request_dma()
1387 if ((host->dma_addr & 0xffff) != 0) in wbsd_request_dma()
1392 else if (host->dma_addr >= 0x1000000) in wbsd_request_dma()
1395 host->dma = dma; in wbsd_request_dma()
1405 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, in wbsd_request_dma()
1407 host->dma_addr = 0; in wbsd_request_dma()
1410 kfree(host->dma_buffer); in wbsd_request_dma()
1411 host->dma_buffer = NULL; in wbsd_request_dma()
1421 static void wbsd_release_dma(struct wbsd_host *host) in wbsd_release_dma() argument
1426 if (host->dma_buffer) { in wbsd_release_dma()
1427 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, in wbsd_release_dma()
1429 kfree(host->dma_buffer); in wbsd_release_dma()
1431 if (host->dma >= 0) in wbsd_release_dma()
1432 free_dma(host->dma); in wbsd_release_dma()
1434 host->dma = -1; in wbsd_release_dma()
1435 host->dma_buffer = NULL; in wbsd_release_dma()
1436 host->dma_addr = 0; in wbsd_release_dma()
1443 static int wbsd_request_irq(struct wbsd_host *host, int irq) in wbsd_request_irq() argument
1450 tasklet_setup(&host->card_tasklet, wbsd_tasklet_card); in wbsd_request_irq()
1451 tasklet_setup(&host->fifo_tasklet, wbsd_tasklet_fifo); in wbsd_request_irq()
1452 tasklet_setup(&host->crc_tasklet, wbsd_tasklet_crc); in wbsd_request_irq()
1453 tasklet_setup(&host->timeout_tasklet, wbsd_tasklet_timeout); in wbsd_request_irq()
1454 tasklet_setup(&host->finish_tasklet, wbsd_tasklet_finish); in wbsd_request_irq()
1459 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host); in wbsd_request_irq()
1463 host->irq = irq; in wbsd_request_irq()
1468 static void wbsd_release_irq(struct wbsd_host *host) in wbsd_release_irq() argument
1470 if (!host->irq) in wbsd_release_irq()
1473 free_irq(host->irq, host); in wbsd_release_irq()
1475 host->irq = 0; in wbsd_release_irq()
1477 tasklet_kill(&host->card_tasklet); in wbsd_release_irq()
1478 tasklet_kill(&host->fifo_tasklet); in wbsd_release_irq()
1479 tasklet_kill(&host->crc_tasklet); in wbsd_release_irq()
1480 tasklet_kill(&host->timeout_tasklet); in wbsd_release_irq()
1481 tasklet_kill(&host->finish_tasklet); in wbsd_release_irq()
1488 static int wbsd_request_resources(struct wbsd_host *host, in wbsd_request_resources() argument
1496 ret = wbsd_request_region(host, base); in wbsd_request_resources()
1503 ret = wbsd_request_irq(host, irq); in wbsd_request_resources()
1510 wbsd_request_dma(host, dma); in wbsd_request_resources()
1519 static void wbsd_release_resources(struct wbsd_host *host) in wbsd_release_resources() argument
1521 wbsd_release_dma(host); in wbsd_release_resources()
1522 wbsd_release_irq(host); in wbsd_release_resources()
1523 wbsd_release_regions(host); in wbsd_release_resources()
1530 static void wbsd_chip_config(struct wbsd_host *host) in wbsd_chip_config() argument
1532 wbsd_unlock_config(host); in wbsd_chip_config()
1537 wbsd_write_config(host, WBSD_CONF_SWRST, 1); in wbsd_chip_config()
1538 wbsd_write_config(host, WBSD_CONF_SWRST, 0); in wbsd_chip_config()
1543 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_config()
1548 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11); in wbsd_chip_config()
1553 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8); in wbsd_chip_config()
1554 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff); in wbsd_chip_config()
1556 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq); in wbsd_chip_config()
1558 if (host->dma >= 0) in wbsd_chip_config()
1559 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma); in wbsd_chip_config()
1564 wbsd_write_config(host, WBSD_CONF_ENABLE, 1); in wbsd_chip_config()
1565 wbsd_write_config(host, WBSD_CONF_POWER, 0x20); in wbsd_chip_config()
1567 wbsd_lock_config(host); in wbsd_chip_config()
1574 static int wbsd_chip_validate(struct wbsd_host *host) in wbsd_chip_validate() argument
1578 wbsd_unlock_config(host); in wbsd_chip_validate()
1583 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_validate()
1588 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8; in wbsd_chip_validate()
1589 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO); in wbsd_chip_validate()
1591 irq = wbsd_read_config(host, WBSD_CONF_IRQ); in wbsd_chip_validate()
1593 dma = wbsd_read_config(host, WBSD_CONF_DRQ); in wbsd_chip_validate()
1595 wbsd_lock_config(host); in wbsd_chip_validate()
1600 if (base != host->base) in wbsd_chip_validate()
1602 if (irq != host->irq) in wbsd_chip_validate()
1604 if ((dma != host->dma) && (host->dma != -1)) in wbsd_chip_validate()
1614 static void wbsd_chip_poweroff(struct wbsd_host *host) in wbsd_chip_poweroff() argument
1616 wbsd_unlock_config(host); in wbsd_chip_poweroff()
1618 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); in wbsd_chip_poweroff()
1619 wbsd_write_config(host, WBSD_CONF_ENABLE, 0); in wbsd_chip_poweroff()
1621 wbsd_lock_config(host); in wbsd_chip_poweroff()
1633 struct wbsd_host *host = NULL; in wbsd_init() local
1642 host = mmc_priv(mmc); in wbsd_init()
1647 ret = wbsd_scan(host); in wbsd_init()
1660 ret = wbsd_request_resources(host, base, irq, dma); in wbsd_init()
1662 wbsd_release_resources(host); in wbsd_init()
1671 if ((host->config != 0) && !wbsd_chip_validate(host)) { in wbsd_init()
1673 wbsd_chip_config(host); in wbsd_init()
1676 wbsd_chip_config(host); in wbsd_init()
1683 if (host->config) { in wbsd_init()
1684 wbsd_unlock_config(host); in wbsd_init()
1685 wbsd_write_config(host, WBSD_CONF_PME, 0xA0); in wbsd_init()
1686 wbsd_lock_config(host); in wbsd_init()
1697 wbsd_init_device(host); in wbsd_init()
1702 wbsd_chip_poweroff(host); in wbsd_init()
1704 wbsd_release_resources(host); in wbsd_init()
1710 if (host->chip_id != 0) in wbsd_init()
1711 printk(" id %x", (int)host->chip_id); in wbsd_init()
1712 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq); in wbsd_init()
1713 if (host->dma >= 0) in wbsd_init()
1714 printk(" dma %d", (int)host->dma); in wbsd_init()
1727 struct wbsd_host *host; in wbsd_shutdown() local
1732 host = mmc_priv(mmc); in wbsd_shutdown()
1740 wbsd_chip_poweroff(host); in wbsd_shutdown()
1742 wbsd_release_resources(host); in wbsd_shutdown()
1805 struct wbsd_host *host; in wbsd_platform_suspend() local
1812 host = mmc_priv(mmc); in wbsd_platform_suspend()
1814 wbsd_chip_poweroff(host); in wbsd_platform_suspend()
1821 struct wbsd_host *host; in wbsd_platform_resume() local
1828 host = mmc_priv(mmc); in wbsd_platform_resume()
1830 wbsd_chip_config(host); in wbsd_platform_resume()
1837 wbsd_init_device(host); in wbsd_platform_resume()
1857 struct wbsd_host *host; in wbsd_pnp_resume() local
1864 host = mmc_priv(mmc); in wbsd_pnp_resume()
1869 if (host->config != 0) { in wbsd_pnp_resume()
1870 if (!wbsd_chip_validate(host)) { in wbsd_pnp_resume()
1872 wbsd_chip_config(host); in wbsd_pnp_resume()
1881 wbsd_init_device(host); in wbsd_pnp_resume()