Lines Matching +full:mmc +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/mmc/host/omap.c
18 #include <linux/dma-mapping.h>
23 #include <linux/mmc/host.h>
24 #include <linux/mmc/card.h>
25 #include <linux/mmc/mmc.h>
29 #include <linux/platform_data/mmc-omap.h>
72 #define mmc_omap7xx() (host->features & MMC_OMAP7XX)
73 #define mmc_omap15xx() (host->features & MMC_OMAP15XX)
74 #define mmc_omap16xx() (host->features & MMC_OMAP16XX)
76 #define mmc_omap1() (host->features & MMC_OMAP1_MASK)
79 #define OMAP_MMC_REG(host, reg) (OMAP_MMC_REG_##reg << (host)->reg_shift)
80 #define OMAP_MMC_READ(host, reg) __raw_readw((host)->virt_base + OMAP_MMC_REG(host, reg))
81 #define OMAP_MMC_WRITE(host, reg, val) __raw_writew((val), (host)->virt_base + OMAP_MMC_REG(host, r…
91 #define DRIVER_NAME "mmci-omap"
113 struct mmc_host *mmc; member
122 struct mmc_host * mmc; member
124 unsigned char id; /* 16xx chips have 2 MMC blocks */
176 if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) { in mmc_omap_fclk_offdelay()
177 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, slot->fclk_freq); in mmc_omap_fclk_offdelay()
186 spin_lock_irqsave(&host->clk_lock, flags); in mmc_omap_fclk_enable()
187 if (host->fclk_enabled != enable) { in mmc_omap_fclk_enable()
188 host->fclk_enabled = enable; in mmc_omap_fclk_enable()
190 clk_enable(host->fclk); in mmc_omap_fclk_enable()
192 clk_disable(host->fclk); in mmc_omap_fclk_enable()
194 spin_unlock_irqrestore(&host->clk_lock, flags); in mmc_omap_fclk_enable()
199 struct mmc_omap_host *host = slot->host; in mmc_omap_select_slot()
204 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_select_slot()
205 while (host->mmc != NULL) { in mmc_omap_select_slot()
206 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_select_slot()
207 wait_event(host->slot_wq, host->mmc == NULL); in mmc_omap_select_slot()
208 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_select_slot()
210 host->mmc = slot->mmc; in mmc_omap_select_slot()
211 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_select_slot()
213 del_timer(&host->clk_timer); in mmc_omap_select_slot()
214 if (host->current_slot != slot || !claimed) in mmc_omap_select_slot()
215 mmc_omap_fclk_offdelay(host->current_slot); in mmc_omap_select_slot()
217 if (host->current_slot != slot) { in mmc_omap_select_slot()
218 OMAP_MMC_WRITE(host, CON, slot->saved_con & 0xFC00); in mmc_omap_select_slot()
219 if (host->pdata->switch_slot != NULL) in mmc_omap_select_slot()
220 host->pdata->switch_slot(mmc_dev(slot->mmc), slot->id); in mmc_omap_select_slot()
221 host->current_slot = slot; in mmc_omap_select_slot()
232 OMAP_MMC_WRITE(host, CON, slot->saved_con); in mmc_omap_select_slot()
244 struct mmc_omap_slot *next_slot = host->next_slot; in mmc_omap_slot_release_work()
247 host->next_slot = NULL; in mmc_omap_slot_release_work()
250 rq = next_slot->mrq; in mmc_omap_slot_release_work()
251 next_slot->mrq = NULL; in mmc_omap_slot_release_work()
257 struct mmc_omap_host *host = slot->host; in mmc_omap_release_slot()
261 BUG_ON(slot == NULL || host->mmc == NULL); in mmc_omap_release_slot()
265 mod_timer(&host->clk_timer, jiffies + HZ/10); in mmc_omap_release_slot()
267 del_timer(&host->clk_timer); in mmc_omap_release_slot()
272 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_release_slot()
274 for (i = 0; i < host->nr_slots; i++) { in mmc_omap_release_slot()
277 if (host->slots[i] == NULL || host->slots[i]->mrq == NULL) in mmc_omap_release_slot()
280 BUG_ON(host->next_slot != NULL); in mmc_omap_release_slot()
281 new_slot = host->slots[i]; in mmc_omap_release_slot()
283 BUG_ON(new_slot == host->current_slot); in mmc_omap_release_slot()
285 host->next_slot = new_slot; in mmc_omap_release_slot()
286 host->mmc = new_slot->mmc; in mmc_omap_release_slot()
287 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_release_slot()
288 queue_work(host->mmc_omap_wq, &host->slot_release_work); in mmc_omap_release_slot()
292 host->mmc = NULL; in mmc_omap_release_slot()
293 wake_up(&host->slot_wq); in mmc_omap_release_slot()
294 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_release_slot()
300 if (slot->pdata->get_cover_state) in mmc_omap_cover_is_open()
301 return slot->pdata->get_cover_state(mmc_dev(slot->mmc), in mmc_omap_cover_is_open()
302 slot->id); in mmc_omap_cover_is_open()
310 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); in mmc_omap_show_cover_switch() local
311 struct mmc_omap_slot *slot = mmc_priv(mmc); in mmc_omap_show_cover_switch()
323 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); in mmc_omap_show_slot_name() local
324 struct mmc_omap_slot *slot = mmc_priv(mmc); in mmc_omap_show_slot_name()
326 return sprintf(buf, "%s\n", slot->pdata->name); in mmc_omap_show_slot_name()
339 host->cmd = cmd; in mmc_omap_start_command()
360 dev_err(mmc_dev(host->mmc), "Invalid response type: %04x\n", mmc_resp_type(cmd)); in mmc_omap_start_command()
374 cmdreg = cmd->opcode | (resptype << 8) | (cmdtype << 12); in mmc_omap_start_command()
376 if (host->current_slot->bus_mode == MMC_BUSMODE_OPENDRAIN) in mmc_omap_start_command()
379 if (cmd->flags & MMC_RSP_BUSY) in mmc_omap_start_command()
382 if (host->data && !(host->data->flags & MMC_DATA_WRITE)) in mmc_omap_start_command()
385 mod_timer(&host->cmd_abort_timer, jiffies + HZ/2); in mmc_omap_start_command()
388 OMAP_MMC_WRITE(host, ARGL, cmd->arg & 0xffff); in mmc_omap_start_command()
389 OMAP_MMC_WRITE(host, ARGH, cmd->arg >> 16); in mmc_omap_start_command()
395 if (cmd->opcode == MMC_ERASE) in mmc_omap_start_command()
406 struct device *dev = mmc_dev(host->mmc); in mmc_omap_release_dma()
409 if (data->flags & MMC_DATA_WRITE) { in mmc_omap_release_dma()
411 c = host->dma_tx; in mmc_omap_release_dma()
414 c = host->dma_rx; in mmc_omap_release_dma()
417 if (data->error) { in mmc_omap_release_dma()
420 data->bytes_xfered = 0; in mmc_omap_release_dma()
422 dev = c->device->dev; in mmc_omap_release_dma()
424 dma_unmap_sg(dev, data->sg, host->sg_len, dma_data_dir); in mmc_omap_release_dma()
431 struct mmc_omap_slot *slot = host->current_slot; in mmc_omap_send_stop_work()
432 struct mmc_data *data = host->stop_data; in mmc_omap_send_stop_work()
435 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, slot->fclk_freq); in mmc_omap_send_stop_work()
438 mmc_omap_start_command(host, data->stop); in mmc_omap_send_stop_work()
444 if (host->dma_in_use) in mmc_omap_xfer_done()
445 mmc_omap_release_dma(host, data, data->error); in mmc_omap_xfer_done()
447 host->data = NULL; in mmc_omap_xfer_done()
448 host->sg_len = 0; in mmc_omap_xfer_done()
450 /* NOTE: MMC layer will sometimes poll-wait CMD13 next, issuing in mmc_omap_xfer_done()
455 if (!data->stop) { in mmc_omap_xfer_done()
456 struct mmc_host *mmc; in mmc_omap_xfer_done() local
458 host->mrq = NULL; in mmc_omap_xfer_done()
459 mmc = host->mmc; in mmc_omap_xfer_done()
460 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_xfer_done()
461 mmc_request_done(mmc, data->mrq); in mmc_omap_xfer_done()
465 host->stop_data = data; in mmc_omap_xfer_done()
466 queue_work(host->mmc_omap_wq, &host->send_stop_work); in mmc_omap_xfer_done()
472 struct mmc_omap_slot *slot = host->current_slot; in mmc_omap_send_abort()
477 timeout = DIV_ROUND_UP(120 * USEC_PER_SEC, slot->fclk_freq); in mmc_omap_send_abort()
501 if (host->dma_in_use) in mmc_omap_abort_xfer()
504 host->data = NULL; in mmc_omap_abort_xfer()
505 host->sg_len = 0; in mmc_omap_abort_xfer()
516 if (!host->dma_in_use) { in mmc_omap_end_of_data()
521 spin_lock_irqsave(&host->dma_lock, flags); in mmc_omap_end_of_data()
522 if (host->dma_done) in mmc_omap_end_of_data()
525 host->brs_received = 1; in mmc_omap_end_of_data()
526 spin_unlock_irqrestore(&host->dma_lock, flags); in mmc_omap_end_of_data()
538 spin_lock_irqsave(&host->dma_lock, flags); in mmc_omap_dma_done()
539 if (host->brs_received) in mmc_omap_dma_done()
542 host->dma_done = 1; in mmc_omap_dma_done()
543 spin_unlock_irqrestore(&host->dma_lock, flags); in mmc_omap_dma_done()
551 host->cmd = NULL; in mmc_omap_cmd_done()
553 del_timer(&host->cmd_abort_timer); in mmc_omap_cmd_done()
555 if (cmd->flags & MMC_RSP_PRESENT) { in mmc_omap_cmd_done()
556 if (cmd->flags & MMC_RSP_136) { in mmc_omap_cmd_done()
558 cmd->resp[3] = in mmc_omap_cmd_done()
561 cmd->resp[2] = in mmc_omap_cmd_done()
564 cmd->resp[1] = in mmc_omap_cmd_done()
567 cmd->resp[0] = in mmc_omap_cmd_done()
572 cmd->resp[0] = in mmc_omap_cmd_done()
578 if (host->data == NULL || cmd->error) { in mmc_omap_cmd_done()
579 struct mmc_host *mmc; in mmc_omap_cmd_done() local
581 if (host->data != NULL) in mmc_omap_cmd_done()
582 mmc_omap_abort_xfer(host, host->data); in mmc_omap_cmd_done()
583 host->mrq = NULL; in mmc_omap_cmd_done()
584 mmc = host->mmc; in mmc_omap_cmd_done()
585 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_cmd_done()
586 mmc_request_done(mmc, cmd->mrq); in mmc_omap_cmd_done()
598 BUG_ON(!host->cmd); in mmc_omap_abort_command()
600 dev_dbg(mmc_dev(host->mmc), "Aborting stuck command CMD%d\n", in mmc_omap_abort_command()
601 host->cmd->opcode); in mmc_omap_abort_command()
603 if (host->cmd->error == 0) in mmc_omap_abort_command()
604 host->cmd->error = -ETIMEDOUT; in mmc_omap_abort_command()
606 if (host->data == NULL) { in mmc_omap_abort_command()
608 struct mmc_host *mmc; in mmc_omap_abort_command() local
610 cmd = host->cmd; in mmc_omap_abort_command()
611 host->cmd = NULL; in mmc_omap_abort_command()
614 host->mrq = NULL; in mmc_omap_abort_command()
615 mmc = host->mmc; in mmc_omap_abort_command()
616 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_abort_command()
617 mmc_request_done(mmc, cmd->mrq); in mmc_omap_abort_command()
619 mmc_omap_cmd_done(host, host->cmd); in mmc_omap_abort_command()
621 host->abort = 0; in mmc_omap_abort_command()
622 enable_irq(host->irq); in mmc_omap_abort_command()
631 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_cmd_timer()
632 if (host->cmd != NULL && !host->abort) { in mmc_omap_cmd_timer()
634 disable_irq(host->irq); in mmc_omap_cmd_timer()
635 host->abort = 1; in mmc_omap_cmd_timer()
636 queue_work(host->mmc_omap_wq, &host->cmd_abort_work); in mmc_omap_cmd_timer()
638 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_cmd_timer()
647 sg = host->data->sg + host->sg_idx; in mmc_omap_sg_to_buf()
648 host->buffer_bytes_left = sg->length; in mmc_omap_sg_to_buf()
649 host->buffer = sg_virt(sg); in mmc_omap_sg_to_buf()
650 if (host->buffer_bytes_left > host->total_bytes_left) in mmc_omap_sg_to_buf()
651 host->buffer_bytes_left = host->total_bytes_left; in mmc_omap_sg_to_buf()
668 if (host->buffer_bytes_left == 0) { in mmc_omap_xfer_data()
669 host->sg_idx++; in mmc_omap_xfer_data()
670 BUG_ON(host->sg_idx == host->sg_len); in mmc_omap_xfer_data()
674 if (n > host->buffer_bytes_left) in mmc_omap_xfer_data()
675 n = host->buffer_bytes_left; in mmc_omap_xfer_data()
680 host->buffer_bytes_left -= n; in mmc_omap_xfer_data()
681 host->total_bytes_left -= n; in mmc_omap_xfer_data()
682 host->data->bytes_xfered += n; in mmc_omap_xfer_data()
685 __raw_writesw(host->virt_base + OMAP_MMC_REG(host, DATA), in mmc_omap_xfer_data()
686 host->buffer, nwords); in mmc_omap_xfer_data()
688 __raw_readsw(host->virt_base + OMAP_MMC_REG(host, DATA), in mmc_omap_xfer_data()
689 host->buffer, nwords); in mmc_omap_xfer_data()
692 host->buffer += nwords; in mmc_omap_xfer_data()
705 buf += sprintf(buf, "MMC IRQ 0x%x:", status); in mmc_omap_report_irq()
710 dev_vdbg(mmc_dev(host->mmc), "%s\n", res); in mmc_omap_report_irq()
727 if (host->cmd == NULL && host->data == NULL) { in mmc_omap_irq()
729 dev_info(mmc_dev(host->slots[0]->mmc), in mmc_omap_irq()
747 if (host->cmd != NULL) in mmc_omap_irq()
748 cmd = host->cmd->opcode; in mmc_omap_irq()
750 cmd = -1; in mmc_omap_irq()
751 dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ", in mmc_omap_irq()
755 if (host->total_bytes_left) { in mmc_omap_irq()
767 dev_dbg(mmc_dev(host->mmc), "data timeout (CMD%d)\n", in mmc_omap_irq()
769 if (host->data) { in mmc_omap_irq()
770 host->data->error = -ETIMEDOUT; in mmc_omap_irq()
776 if (host->data) { in mmc_omap_irq()
777 host->data->error = -EILSEQ; in mmc_omap_irq()
778 dev_dbg(mmc_dev(host->mmc), in mmc_omap_irq()
780 host->total_bytes_left); in mmc_omap_irq()
783 dev_dbg(mmc_dev(host->mmc), "data CRC error\n"); in mmc_omap_irq()
789 if (host->cmd) { in mmc_omap_irq()
791 host->current_slot; in mmc_omap_irq()
794 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
797 host->cmd->error = -ETIMEDOUT; in mmc_omap_irq()
804 if (host->cmd) { in mmc_omap_irq()
805 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
807 cmd, host->cmd->arg); in mmc_omap_irq()
808 host->cmd->error = -EILSEQ; in mmc_omap_irq()
812 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
817 dev_dbg(mmc_dev(host->mmc), in mmc_omap_irq()
833 if (cmd_error && host->data) { in mmc_omap_irq()
834 del_timer(&host->cmd_abort_timer); in mmc_omap_irq()
835 host->abort = 1; in mmc_omap_irq()
837 disable_irq_nosync(host->irq); in mmc_omap_irq()
838 queue_work(host->mmc_omap_wq, &host->cmd_abort_work); in mmc_omap_irq()
842 if (end_command && host->cmd) in mmc_omap_irq()
843 mmc_omap_cmd_done(host, host->cmd); in mmc_omap_irq()
844 if (host->data != NULL) { in mmc_omap_irq()
846 mmc_omap_xfer_done(host, host->data); in mmc_omap_irq()
848 mmc_omap_end_of_data(host, host->data); in mmc_omap_irq()
858 struct mmc_omap_slot *slot = host->slots[num]; in omap_mmc_notify_cover_event()
860 BUG_ON(num >= host->nr_slots); in omap_mmc_notify_cover_event()
863 if (host->nr_slots == 0 || !host->slots[num]) in omap_mmc_notify_cover_event()
867 if (cover_open != slot->cover_open) { in omap_mmc_notify_cover_event()
868 slot->cover_open = cover_open; in omap_mmc_notify_cover_event()
869 sysfs_notify(&slot->mmc->class_dev.kobj, NULL, "cover_switch"); in omap_mmc_notify_cover_event()
872 tasklet_hi_schedule(&slot->cover_tasklet); in omap_mmc_notify_cover_event()
878 tasklet_schedule(&slot->cover_tasklet); in mmc_omap_cover_timer()
886 mmc_detect_change(slot->mmc, 0); in mmc_omap_cover_handler()
894 if (slot->mmc->card == NULL) in mmc_omap_cover_handler()
897 mod_timer(&slot->cover_timer, in mmc_omap_cover_handler()
904 struct mmc_data *data = host->data; in mmc_omap_dma_callback()
907 data->bytes_xfered += data->blocks * data->blksz; in mmc_omap_dma_callback()
928 cycle_ns = 1000000000 / host->current_slot->fclk_freq; in set_data_timeout()
929 timeout = req->data->timeout_ns / cycle_ns; in set_data_timeout()
930 timeout += req->data->timeout_clks; in set_data_timeout()
946 struct mmc_data *data = req->data; in mmc_omap_prepare_data()
951 host->data = data; in mmc_omap_prepare_data()
956 host->dma_in_use = 0; in mmc_omap_prepare_data()
961 block_size = data->blksz; in mmc_omap_prepare_data()
963 OMAP_MMC_WRITE(host, NBLK, data->blocks - 1); in mmc_omap_prepare_data()
964 OMAP_MMC_WRITE(host, BLEN, block_size - 1); in mmc_omap_prepare_data()
968 * block" writes using multi-block scatterlists. in mmc_omap_prepare_data()
970 sg_len = (data->blocks == 1) ? 1 : data->sg_len; in mmc_omap_prepare_data()
973 for_each_sg(data->sg, sg, sg_len, i) { in mmc_omap_prepare_data()
974 if ((sg->length % block_size) != 0) { in mmc_omap_prepare_data()
980 host->sg_idx = 0; in mmc_omap_prepare_data()
995 if (burst > data->blksz) in mmc_omap_prepare_data()
996 burst = data->blksz; in mmc_omap_prepare_data()
1000 if (data->flags & MMC_DATA_WRITE) { in mmc_omap_prepare_data()
1001 c = host->dma_tx; in mmc_omap_prepare_data()
1002 bp = &host->dma_tx_burst; in mmc_omap_prepare_data()
1003 buf = 0x0f80 | (burst - 1) << 0; in mmc_omap_prepare_data()
1006 c = host->dma_rx; in mmc_omap_prepare_data()
1007 bp = &host->dma_rx_burst; in mmc_omap_prepare_data()
1008 buf = 0x800f | (burst - 1) << 8; in mmc_omap_prepare_data()
1018 .src_addr = host->phys_base + in mmc_omap_prepare_data()
1020 .dst_addr = host->phys_base + in mmc_omap_prepare_data()
1034 host->sg_len = dma_map_sg(c->device->dev, data->sg, sg_len, in mmc_omap_prepare_data()
1036 if (host->sg_len == 0) in mmc_omap_prepare_data()
1039 tx = dmaengine_prep_slave_sg(c, data->sg, host->sg_len, in mmc_omap_prepare_data()
1040 data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, in mmc_omap_prepare_data()
1047 tx->callback = mmc_omap_dma_callback; in mmc_omap_prepare_data()
1048 tx->callback_param = host; in mmc_omap_prepare_data()
1050 host->brs_received = 0; in mmc_omap_prepare_data()
1051 host->dma_done = 0; in mmc_omap_prepare_data()
1052 host->dma_in_use = 1; in mmc_omap_prepare_data()
1059 host->total_bytes_left = data->blocks * block_size; in mmc_omap_prepare_data()
1060 host->sg_len = sg_len; in mmc_omap_prepare_data()
1062 host->dma_in_use = 0; in mmc_omap_prepare_data()
1068 BUG_ON(host->mrq != NULL); in mmc_omap_start_request()
1070 host->mrq = req; in mmc_omap_start_request()
1074 mmc_omap_start_command(host, req->cmd); in mmc_omap_start_request()
1075 if (host->dma_in_use) { in mmc_omap_start_request()
1076 struct dma_chan *c = host->data->flags & MMC_DATA_WRITE ? in mmc_omap_start_request()
1077 host->dma_tx : host->dma_rx; in mmc_omap_start_request()
1083 static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req) in mmc_omap_request() argument
1085 struct mmc_omap_slot *slot = mmc_priv(mmc); in mmc_omap_request()
1086 struct mmc_omap_host *host = slot->host; in mmc_omap_request()
1089 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_request()
1090 if (host->mmc != NULL) { in mmc_omap_request()
1091 BUG_ON(slot->mrq != NULL); in mmc_omap_request()
1092 slot->mrq = req; in mmc_omap_request()
1093 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_request()
1096 host->mmc = mmc; in mmc_omap_request()
1097 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_request()
1107 host = slot->host; in mmc_omap_set_power()
1109 if (slot->pdata->set_power != NULL) in mmc_omap_set_power()
1110 slot->pdata->set_power(mmc_dev(slot->mmc), slot->id, power_on, in mmc_omap_set_power()
1125 static int mmc_omap_calc_divisor(struct mmc_host *mmc, struct mmc_ios *ios) in mmc_omap_calc_divisor() argument
1127 struct mmc_omap_slot *slot = mmc_priv(mmc); in mmc_omap_calc_divisor()
1128 struct mmc_omap_host *host = slot->host; in mmc_omap_calc_divisor()
1129 int func_clk_rate = clk_get_rate(host->fclk); in mmc_omap_calc_divisor()
1132 if (ios->clock == 0) in mmc_omap_calc_divisor()
1135 dsor = func_clk_rate / ios->clock; in mmc_omap_calc_divisor()
1139 if (func_clk_rate / dsor > ios->clock) in mmc_omap_calc_divisor()
1145 slot->fclk_freq = func_clk_rate / dsor; in mmc_omap_calc_divisor()
1147 if (ios->bus_width == MMC_BUS_WIDTH_4) in mmc_omap_calc_divisor()
1153 static void mmc_omap_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) in mmc_omap_set_ios() argument
1155 struct mmc_omap_slot *slot = mmc_priv(mmc); in mmc_omap_set_ios()
1156 struct mmc_omap_host *host = slot->host; in mmc_omap_set_ios()
1162 dsor = mmc_omap_calc_divisor(mmc, ios); in mmc_omap_set_ios()
1164 if (ios->vdd != slot->vdd) in mmc_omap_set_ios()
1165 slot->vdd = ios->vdd; in mmc_omap_set_ios()
1169 switch (ios->power_mode) { in mmc_omap_set_ios()
1171 mmc_omap_set_power(slot, 0, ios->vdd); in mmc_omap_set_ios()
1174 /* Cannot touch dsor yet, just power up MMC */ in mmc_omap_set_ios()
1175 mmc_omap_set_power(slot, 1, ios->vdd); in mmc_omap_set_ios()
1176 slot->power_mode = ios->power_mode; in mmc_omap_set_ios()
1182 if (slot->power_mode != MMC_POWER_ON) in mmc_omap_set_ios()
1186 slot->power_mode = ios->power_mode; in mmc_omap_set_ios()
1188 if (slot->bus_mode != ios->bus_mode) { in mmc_omap_set_ios()
1189 if (slot->pdata->set_bus_mode != NULL) in mmc_omap_set_ios()
1190 slot->pdata->set_bus_mode(mmc_dev(mmc), slot->id, in mmc_omap_set_ios()
1191 ios->bus_mode); in mmc_omap_set_ios()
1192 slot->bus_mode = ios->bus_mode; in mmc_omap_set_ios()
1201 slot->saved_con = dsor; in mmc_omap_set_ios()
1212 usecs--; in mmc_omap_set_ios()
1229 struct mmc_host *mmc; in mmc_omap_new_slot() local
1232 mmc = mmc_alloc_host(sizeof(struct mmc_omap_slot), host->dev); in mmc_omap_new_slot()
1233 if (mmc == NULL) in mmc_omap_new_slot()
1234 return -ENOMEM; in mmc_omap_new_slot()
1236 slot = mmc_priv(mmc); in mmc_omap_new_slot()
1237 slot->host = host; in mmc_omap_new_slot()
1238 slot->mmc = mmc; in mmc_omap_new_slot()
1239 slot->id = id; in mmc_omap_new_slot()
1240 slot->power_mode = MMC_POWER_UNDEFINED; in mmc_omap_new_slot()
1241 slot->pdata = &host->pdata->slots[id]; in mmc_omap_new_slot()
1243 host->slots[id] = slot; in mmc_omap_new_slot()
1245 mmc->caps = 0; in mmc_omap_new_slot()
1246 if (host->pdata->slots[id].wires >= 4) in mmc_omap_new_slot()
1247 mmc->caps |= MMC_CAP_4_BIT_DATA; in mmc_omap_new_slot()
1249 mmc->ops = &mmc_omap_ops; in mmc_omap_new_slot()
1250 mmc->f_min = 400000; in mmc_omap_new_slot()
1253 mmc->f_max = 48000000; in mmc_omap_new_slot()
1255 mmc->f_max = 24000000; in mmc_omap_new_slot()
1256 if (host->pdata->max_freq) in mmc_omap_new_slot()
1257 mmc->f_max = min(host->pdata->max_freq, mmc->f_max); in mmc_omap_new_slot()
1258 mmc->ocr_avail = slot->pdata->ocr_mask; in mmc_omap_new_slot()
1260 /* Use scatterlist DMA to reduce per-transfer costs. in mmc_omap_new_slot()
1264 mmc->max_segs = 32; in mmc_omap_new_slot()
1265 mmc->max_blk_size = 2048; /* BLEN is 11 bits (+1) */ in mmc_omap_new_slot()
1266 mmc->max_blk_count = 2048; /* NBLK is 11 bits (+1) */ in mmc_omap_new_slot()
1267 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; in mmc_omap_new_slot()
1268 mmc->max_seg_size = mmc->max_req_size; in mmc_omap_new_slot()
1270 if (slot->pdata->get_cover_state != NULL) { in mmc_omap_new_slot()
1271 timer_setup(&slot->cover_timer, mmc_omap_cover_timer, 0); in mmc_omap_new_slot()
1272 tasklet_init(&slot->cover_tasklet, mmc_omap_cover_handler, in mmc_omap_new_slot()
1276 r = mmc_add_host(mmc); in mmc_omap_new_slot()
1280 if (slot->pdata->name != NULL) { in mmc_omap_new_slot()
1281 r = device_create_file(&mmc->class_dev, in mmc_omap_new_slot()
1287 if (slot->pdata->get_cover_state != NULL) { in mmc_omap_new_slot()
1288 r = device_create_file(&mmc->class_dev, in mmc_omap_new_slot()
1292 tasklet_schedule(&slot->cover_tasklet); in mmc_omap_new_slot()
1298 if (slot->pdata->name != NULL) in mmc_omap_new_slot()
1299 device_remove_file(&mmc->class_dev, &dev_attr_slot_name); in mmc_omap_new_slot()
1301 mmc_remove_host(mmc); in mmc_omap_new_slot()
1302 mmc_free_host(mmc); in mmc_omap_new_slot()
1308 struct mmc_host *mmc = slot->mmc; in mmc_omap_remove_slot() local
1310 if (slot->pdata->name != NULL) in mmc_omap_remove_slot()
1311 device_remove_file(&mmc->class_dev, &dev_attr_slot_name); in mmc_omap_remove_slot()
1312 if (slot->pdata->get_cover_state != NULL) in mmc_omap_remove_slot()
1313 device_remove_file(&mmc->class_dev, &dev_attr_cover_switch); in mmc_omap_remove_slot()
1315 tasklet_kill(&slot->cover_tasklet); in mmc_omap_remove_slot()
1316 del_timer_sync(&slot->cover_timer); in mmc_omap_remove_slot()
1317 flush_workqueue(slot->host->mmc_omap_wq); in mmc_omap_remove_slot()
1319 mmc_remove_host(mmc); in mmc_omap_remove_slot()
1320 mmc_free_host(mmc); in mmc_omap_remove_slot()
1325 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; in mmc_omap_probe()
1332 dev_err(&pdev->dev, "platform data missing\n"); in mmc_omap_probe()
1333 return -ENXIO; in mmc_omap_probe()
1335 if (pdata->nr_slots == 0) { in mmc_omap_probe()
1336 dev_err(&pdev->dev, "no slots\n"); in mmc_omap_probe()
1337 return -EPROBE_DEFER; in mmc_omap_probe()
1340 host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host), in mmc_omap_probe()
1343 return -ENOMEM; in mmc_omap_probe()
1347 return -ENXIO; in mmc_omap_probe()
1350 host->virt_base = devm_ioremap_resource(&pdev->dev, res); in mmc_omap_probe()
1351 if (IS_ERR(host->virt_base)) in mmc_omap_probe()
1352 return PTR_ERR(host->virt_base); in mmc_omap_probe()
1354 INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work); in mmc_omap_probe()
1355 INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work); in mmc_omap_probe()
1357 INIT_WORK(&host->cmd_abort_work, mmc_omap_abort_command); in mmc_omap_probe()
1358 timer_setup(&host->cmd_abort_timer, mmc_omap_cmd_timer, 0); in mmc_omap_probe()
1360 spin_lock_init(&host->clk_lock); in mmc_omap_probe()
1361 timer_setup(&host->clk_timer, mmc_omap_clk_timer, 0); in mmc_omap_probe()
1363 spin_lock_init(&host->dma_lock); in mmc_omap_probe()
1364 spin_lock_init(&host->slot_lock); in mmc_omap_probe()
1365 init_waitqueue_head(&host->slot_wq); in mmc_omap_probe()
1367 host->pdata = pdata; in mmc_omap_probe()
1368 host->features = host->pdata->slots[0].features; in mmc_omap_probe()
1369 host->dev = &pdev->dev; in mmc_omap_probe()
1372 host->id = pdev->id; in mmc_omap_probe()
1373 host->irq = irq; in mmc_omap_probe()
1374 host->phys_base = res->start; in mmc_omap_probe()
1375 host->iclk = clk_get(&pdev->dev, "ick"); in mmc_omap_probe()
1376 if (IS_ERR(host->iclk)) in mmc_omap_probe()
1377 return PTR_ERR(host->iclk); in mmc_omap_probe()
1378 clk_enable(host->iclk); in mmc_omap_probe()
1380 host->fclk = clk_get(&pdev->dev, "fck"); in mmc_omap_probe()
1381 if (IS_ERR(host->fclk)) { in mmc_omap_probe()
1382 ret = PTR_ERR(host->fclk); in mmc_omap_probe()
1386 host->dma_tx_burst = -1; in mmc_omap_probe()
1387 host->dma_rx_burst = -1; in mmc_omap_probe()
1389 host->dma_tx = dma_request_chan(&pdev->dev, "tx"); in mmc_omap_probe()
1390 if (IS_ERR(host->dma_tx)) { in mmc_omap_probe()
1391 ret = PTR_ERR(host->dma_tx); in mmc_omap_probe()
1392 if (ret == -EPROBE_DEFER) { in mmc_omap_probe()
1393 clk_put(host->fclk); in mmc_omap_probe()
1397 host->dma_tx = NULL; in mmc_omap_probe()
1398 dev_warn(host->dev, "TX DMA channel request failed\n"); in mmc_omap_probe()
1401 host->dma_rx = dma_request_chan(&pdev->dev, "rx"); in mmc_omap_probe()
1402 if (IS_ERR(host->dma_rx)) { in mmc_omap_probe()
1403 ret = PTR_ERR(host->dma_rx); in mmc_omap_probe()
1404 if (ret == -EPROBE_DEFER) { in mmc_omap_probe()
1405 if (host->dma_tx) in mmc_omap_probe()
1406 dma_release_channel(host->dma_tx); in mmc_omap_probe()
1407 clk_put(host->fclk); in mmc_omap_probe()
1411 host->dma_rx = NULL; in mmc_omap_probe()
1412 dev_warn(host->dev, "RX DMA channel request failed\n"); in mmc_omap_probe()
1415 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); in mmc_omap_probe()
1419 if (pdata->init != NULL) { in mmc_omap_probe()
1420 ret = pdata->init(&pdev->dev); in mmc_omap_probe()
1425 host->nr_slots = pdata->nr_slots; in mmc_omap_probe()
1426 host->reg_shift = (mmc_omap7xx() ? 1 : 2); in mmc_omap_probe()
1428 host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0); in mmc_omap_probe()
1429 if (!host->mmc_omap_wq) { in mmc_omap_probe()
1430 ret = -ENOMEM; in mmc_omap_probe()
1434 for (i = 0; i < pdata->nr_slots; i++) { in mmc_omap_probe()
1437 while (--i >= 0) in mmc_omap_probe()
1438 mmc_omap_remove_slot(host->slots[i]); in mmc_omap_probe()
1447 destroy_workqueue(host->mmc_omap_wq); in mmc_omap_probe()
1449 if (pdata->cleanup) in mmc_omap_probe()
1450 pdata->cleanup(&pdev->dev); in mmc_omap_probe()
1452 free_irq(host->irq, host); in mmc_omap_probe()
1454 if (host->dma_tx) in mmc_omap_probe()
1455 dma_release_channel(host->dma_tx); in mmc_omap_probe()
1456 if (host->dma_rx) in mmc_omap_probe()
1457 dma_release_channel(host->dma_rx); in mmc_omap_probe()
1458 clk_put(host->fclk); in mmc_omap_probe()
1460 clk_disable(host->iclk); in mmc_omap_probe()
1461 clk_put(host->iclk); in mmc_omap_probe()
1472 for (i = 0; i < host->nr_slots; i++) in mmc_omap_remove()
1473 mmc_omap_remove_slot(host->slots[i]); in mmc_omap_remove()
1475 if (host->pdata->cleanup) in mmc_omap_remove()
1476 host->pdata->cleanup(&pdev->dev); in mmc_omap_remove()
1479 free_irq(host->irq, host); in mmc_omap_remove()
1480 clk_put(host->fclk); in mmc_omap_remove()
1481 clk_disable(host->iclk); in mmc_omap_remove()
1482 clk_put(host->iclk); in mmc_omap_remove()
1484 if (host->dma_tx) in mmc_omap_remove()
1485 dma_release_channel(host->dma_tx); in mmc_omap_remove()
1486 if (host->dma_rx) in mmc_omap_remove()
1487 dma_release_channel(host->dma_rx); in mmc_omap_remove()
1489 destroy_workqueue(host->mmc_omap_wq); in mmc_omap_remove()
1496 { .compatible = "ti,omap2420-mmc", },