Lines Matching +full:host +full:- +full:id
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>
30 #include <linux/platform_data/mmc-omap.h>
74 #define mmc_omap7xx() (host->features & MMC_OMAP7XX)
75 #define mmc_omap15xx() (host->features & MMC_OMAP15XX)
76 #define mmc_omap16xx() (host->features & MMC_OMAP16XX)
78 #define mmc_omap1() (host->features & MMC_OMAP1_MASK)
81 #define OMAP_MMC_REG(host, reg) (OMAP_MMC_REG_##reg << (host)->reg_shift) argument
82 #define OMAP_MMC_READ(host, reg) __raw_readw((host)->virt_base + OMAP_MMC_REG(host, reg)) argument
83 #define OMAP_MMC_WRITE(host, reg, val) __raw_writew((val), (host)->virt_base + OMAP_MMC_REG(host, r… argument
93 #define DRIVER_NAME "mmci-omap"
102 int id; member
114 struct mmc_omap_host *host; member
129 unsigned char id; /* 16xx chips have 2 MMC blocks */ member
180 if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) { in mmc_omap_fclk_offdelay()
181 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, slot->fclk_freq); in mmc_omap_fclk_offdelay()
186 static void mmc_omap_fclk_enable(struct mmc_omap_host *host, unsigned int enable) in mmc_omap_fclk_enable() argument
190 spin_lock_irqsave(&host->clk_lock, flags); in mmc_omap_fclk_enable()
191 if (host->fclk_enabled != enable) { in mmc_omap_fclk_enable()
192 host->fclk_enabled = enable; in mmc_omap_fclk_enable()
194 clk_enable(host->fclk); in mmc_omap_fclk_enable()
196 clk_disable(host->fclk); in mmc_omap_fclk_enable()
198 spin_unlock_irqrestore(&host->clk_lock, flags); in mmc_omap_fclk_enable()
203 struct mmc_omap_host *host = slot->host; in mmc_omap_select_slot() local
208 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_select_slot()
209 while (host->mmc != NULL) { in mmc_omap_select_slot()
210 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_select_slot()
211 wait_event(host->slot_wq, host->mmc == NULL); in mmc_omap_select_slot()
212 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_select_slot()
214 host->mmc = slot->mmc; in mmc_omap_select_slot()
215 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_select_slot()
217 del_timer(&host->clk_timer); in mmc_omap_select_slot()
218 if (host->current_slot != slot || !claimed) in mmc_omap_select_slot()
219 mmc_omap_fclk_offdelay(host->current_slot); in mmc_omap_select_slot()
221 if (host->current_slot != slot) { in mmc_omap_select_slot()
222 OMAP_MMC_WRITE(host, CON, slot->saved_con & 0xFC00); in mmc_omap_select_slot()
223 if (host->slot_switch) in mmc_omap_select_slot()
226 * the GPIO to 0 selects slot ID 0, setting it to 1 in mmc_omap_select_slot()
227 * selects slot ID 1. in mmc_omap_select_slot()
229 gpiod_set_value(host->slot_switch, slot->id); in mmc_omap_select_slot()
230 host->current_slot = slot; in mmc_omap_select_slot()
234 mmc_omap_fclk_enable(host, 1); in mmc_omap_select_slot()
239 OMAP_MMC_READ(host, CON); in mmc_omap_select_slot()
241 OMAP_MMC_WRITE(host, CON, slot->saved_con); in mmc_omap_select_slot()
243 mmc_omap_fclk_enable(host, 0); in mmc_omap_select_slot()
246 static void mmc_omap_start_request(struct mmc_omap_host *host,
251 struct mmc_omap_host *host = container_of(work, struct mmc_omap_host, in mmc_omap_slot_release_work() local
253 struct mmc_omap_slot *next_slot = host->next_slot; in mmc_omap_slot_release_work()
256 host->next_slot = NULL; in mmc_omap_slot_release_work()
259 rq = next_slot->mrq; in mmc_omap_slot_release_work()
260 next_slot->mrq = NULL; in mmc_omap_slot_release_work()
261 mmc_omap_start_request(host, rq); in mmc_omap_slot_release_work()
266 struct mmc_omap_host *host = slot->host; in mmc_omap_release_slot() local
270 BUG_ON(slot == NULL || host->mmc == NULL); in mmc_omap_release_slot()
274 mod_timer(&host->clk_timer, jiffies + HZ/10); in mmc_omap_release_slot()
276 del_timer(&host->clk_timer); in mmc_omap_release_slot()
278 mmc_omap_fclk_enable(host, 0); in mmc_omap_release_slot()
281 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_release_slot()
283 for (i = 0; i < host->nr_slots; i++) { in mmc_omap_release_slot()
286 if (host->slots[i] == NULL || host->slots[i]->mrq == NULL) in mmc_omap_release_slot()
289 BUG_ON(host->next_slot != NULL); in mmc_omap_release_slot()
290 new_slot = host->slots[i]; in mmc_omap_release_slot()
292 BUG_ON(new_slot == host->current_slot); in mmc_omap_release_slot()
294 host->next_slot = new_slot; in mmc_omap_release_slot()
295 host->mmc = new_slot->mmc; in mmc_omap_release_slot()
296 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_release_slot()
297 queue_work(host->mmc_omap_wq, &host->slot_release_work); in mmc_omap_release_slot()
301 host->mmc = NULL; in mmc_omap_release_slot()
302 wake_up(&host->slot_wq); in mmc_omap_release_slot()
303 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_release_slot()
310 if (slot->cover) in mmc_omap_cover_is_open()
311 return gpiod_get_value(slot->cover); in mmc_omap_cover_is_open()
312 if (slot->pdata->get_cover_state) in mmc_omap_cover_is_open()
313 return slot->pdata->get_cover_state(mmc_dev(slot->mmc), in mmc_omap_cover_is_open()
314 slot->id); in mmc_omap_cover_is_open()
338 return sprintf(buf, "%s\n", slot->pdata->name); in mmc_omap_show_slot_name()
344 mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd) in mmc_omap_start_command() argument
351 host->cmd = cmd; in mmc_omap_start_command()
372 dev_err(mmc_dev(host->mmc), "Invalid response type: %04x\n", mmc_resp_type(cmd)); in mmc_omap_start_command()
386 cmdreg = cmd->opcode | (resptype << 8) | (cmdtype << 12); in mmc_omap_start_command()
388 if (host->current_slot->bus_mode == MMC_BUSMODE_OPENDRAIN) in mmc_omap_start_command()
391 if (cmd->flags & MMC_RSP_BUSY) in mmc_omap_start_command()
394 if (host->data && !(host->data->flags & MMC_DATA_WRITE)) in mmc_omap_start_command()
397 mod_timer(&host->cmd_abort_timer, jiffies + HZ/2); in mmc_omap_start_command()
399 OMAP_MMC_WRITE(host, CTO, 200); in mmc_omap_start_command()
400 OMAP_MMC_WRITE(host, ARGL, cmd->arg & 0xffff); in mmc_omap_start_command()
401 OMAP_MMC_WRITE(host, ARGH, cmd->arg >> 16); in mmc_omap_start_command()
407 if (cmd->opcode == MMC_ERASE) in mmc_omap_start_command()
409 OMAP_MMC_WRITE(host, IE, irq_mask); in mmc_omap_start_command()
410 OMAP_MMC_WRITE(host, CMD, cmdreg); in mmc_omap_start_command()
414 mmc_omap_release_dma(struct mmc_omap_host *host, struct mmc_data *data, in mmc_omap_release_dma() argument
418 struct device *dev = mmc_dev(host->mmc); in mmc_omap_release_dma()
421 if (data->flags & MMC_DATA_WRITE) { in mmc_omap_release_dma()
423 c = host->dma_tx; in mmc_omap_release_dma()
426 c = host->dma_rx; in mmc_omap_release_dma()
429 if (data->error) { in mmc_omap_release_dma()
432 data->bytes_xfered = 0; in mmc_omap_release_dma()
434 dev = c->device->dev; in mmc_omap_release_dma()
436 dma_unmap_sg(dev, data->sg, host->sg_len, dma_data_dir); in mmc_omap_release_dma()
441 struct mmc_omap_host *host = container_of(work, struct mmc_omap_host, in mmc_omap_send_stop_work() local
443 struct mmc_omap_slot *slot = host->current_slot; in mmc_omap_send_stop_work()
444 struct mmc_data *data = host->stop_data; in mmc_omap_send_stop_work()
447 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, slot->fclk_freq); in mmc_omap_send_stop_work()
450 mmc_omap_start_command(host, data->stop); in mmc_omap_send_stop_work()
454 mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data) in mmc_omap_xfer_done() argument
456 if (host->dma_in_use) in mmc_omap_xfer_done()
457 mmc_omap_release_dma(host, data, data->error); in mmc_omap_xfer_done()
459 sg_miter_stop(&host->sg_miter); in mmc_omap_xfer_done()
461 host->data = NULL; in mmc_omap_xfer_done()
462 host->sg_len = 0; in mmc_omap_xfer_done()
464 /* NOTE: MMC layer will sometimes poll-wait CMD13 next, issuing in mmc_omap_xfer_done()
469 if (!data->stop) { in mmc_omap_xfer_done()
472 host->mrq = NULL; in mmc_omap_xfer_done()
473 mmc = host->mmc; in mmc_omap_xfer_done()
474 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_xfer_done()
475 mmc_request_done(mmc, data->mrq); in mmc_omap_xfer_done()
479 host->stop_data = data; in mmc_omap_xfer_done()
480 queue_work(host->mmc_omap_wq, &host->send_stop_work); in mmc_omap_xfer_done()
484 mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops) in mmc_omap_send_abort() argument
486 struct mmc_omap_slot *slot = host->current_slot; in mmc_omap_send_abort()
491 timeout = DIV_ROUND_UP(120 * USEC_PER_SEC, slot->fclk_freq); in mmc_omap_send_abort()
494 OMAP_MMC_WRITE(host, STAT, 0xFFFF); in mmc_omap_send_abort()
495 OMAP_MMC_WRITE(host, CMD, (3 << 12) | (1 << 7)); in mmc_omap_send_abort()
499 stat = OMAP_MMC_READ(host, STAT); in mmc_omap_send_abort()
509 OMAP_MMC_WRITE(host, STAT, stat); in mmc_omap_send_abort()
513 mmc_omap_abort_xfer(struct mmc_omap_host *host, struct mmc_data *data) in mmc_omap_abort_xfer() argument
515 if (host->dma_in_use) in mmc_omap_abort_xfer()
516 mmc_omap_release_dma(host, data, 1); in mmc_omap_abort_xfer()
518 host->data = NULL; in mmc_omap_abort_xfer()
519 host->sg_len = 0; in mmc_omap_abort_xfer()
521 mmc_omap_send_abort(host, 10000); in mmc_omap_abort_xfer()
525 mmc_omap_end_of_data(struct mmc_omap_host *host, struct mmc_data *data) in mmc_omap_end_of_data() argument
530 if (!host->dma_in_use) { in mmc_omap_end_of_data()
531 mmc_omap_xfer_done(host, data); in mmc_omap_end_of_data()
535 spin_lock_irqsave(&host->dma_lock, flags); in mmc_omap_end_of_data()
536 if (host->dma_done) in mmc_omap_end_of_data()
539 host->brs_received = 1; in mmc_omap_end_of_data()
540 spin_unlock_irqrestore(&host->dma_lock, flags); in mmc_omap_end_of_data()
542 mmc_omap_xfer_done(host, data); in mmc_omap_end_of_data()
546 mmc_omap_dma_done(struct mmc_omap_host *host, struct mmc_data *data) in mmc_omap_dma_done() argument
552 spin_lock_irqsave(&host->dma_lock, flags); in mmc_omap_dma_done()
553 if (host->brs_received) in mmc_omap_dma_done()
556 host->dma_done = 1; in mmc_omap_dma_done()
557 spin_unlock_irqrestore(&host->dma_lock, flags); in mmc_omap_dma_done()
559 mmc_omap_xfer_done(host, data); in mmc_omap_dma_done()
563 mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd) in mmc_omap_cmd_done() argument
565 host->cmd = NULL; in mmc_omap_cmd_done()
567 del_timer(&host->cmd_abort_timer); in mmc_omap_cmd_done()
569 if (cmd->flags & MMC_RSP_PRESENT) { in mmc_omap_cmd_done()
570 if (cmd->flags & MMC_RSP_136) { in mmc_omap_cmd_done()
572 cmd->resp[3] = in mmc_omap_cmd_done()
573 OMAP_MMC_READ(host, RSP0) | in mmc_omap_cmd_done()
574 (OMAP_MMC_READ(host, RSP1) << 16); in mmc_omap_cmd_done()
575 cmd->resp[2] = in mmc_omap_cmd_done()
576 OMAP_MMC_READ(host, RSP2) | in mmc_omap_cmd_done()
577 (OMAP_MMC_READ(host, RSP3) << 16); in mmc_omap_cmd_done()
578 cmd->resp[1] = in mmc_omap_cmd_done()
579 OMAP_MMC_READ(host, RSP4) | in mmc_omap_cmd_done()
580 (OMAP_MMC_READ(host, RSP5) << 16); in mmc_omap_cmd_done()
581 cmd->resp[0] = in mmc_omap_cmd_done()
582 OMAP_MMC_READ(host, RSP6) | in mmc_omap_cmd_done()
583 (OMAP_MMC_READ(host, RSP7) << 16); in mmc_omap_cmd_done()
586 cmd->resp[0] = in mmc_omap_cmd_done()
587 OMAP_MMC_READ(host, RSP6) | in mmc_omap_cmd_done()
588 (OMAP_MMC_READ(host, RSP7) << 16); in mmc_omap_cmd_done()
592 if (host->data == NULL || cmd->error) { in mmc_omap_cmd_done()
595 if (host->data != NULL) in mmc_omap_cmd_done()
596 mmc_omap_abort_xfer(host, host->data); in mmc_omap_cmd_done()
597 host->mrq = NULL; in mmc_omap_cmd_done()
598 mmc = host->mmc; in mmc_omap_cmd_done()
599 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_cmd_done()
600 mmc_request_done(mmc, cmd->mrq); in mmc_omap_cmd_done()
610 struct mmc_omap_host *host = container_of(work, struct mmc_omap_host, in mmc_omap_abort_command() local
612 BUG_ON(!host->cmd); in mmc_omap_abort_command()
614 dev_dbg(mmc_dev(host->mmc), "Aborting stuck command CMD%d\n", in mmc_omap_abort_command()
615 host->cmd->opcode); in mmc_omap_abort_command()
617 if (host->cmd->error == 0) in mmc_omap_abort_command()
618 host->cmd->error = -ETIMEDOUT; in mmc_omap_abort_command()
620 if (host->data == NULL) { in mmc_omap_abort_command()
624 cmd = host->cmd; in mmc_omap_abort_command()
625 host->cmd = NULL; in mmc_omap_abort_command()
626 mmc_omap_send_abort(host, 10000); in mmc_omap_abort_command()
628 host->mrq = NULL; in mmc_omap_abort_command()
629 mmc = host->mmc; in mmc_omap_abort_command()
630 mmc_omap_release_slot(host->current_slot, 1); in mmc_omap_abort_command()
631 mmc_request_done(mmc, cmd->mrq); in mmc_omap_abort_command()
633 mmc_omap_cmd_done(host, host->cmd); in mmc_omap_abort_command()
635 host->abort = 0; in mmc_omap_abort_command()
636 enable_irq(host->irq); in mmc_omap_abort_command()
642 struct mmc_omap_host *host = from_timer(host, t, cmd_abort_timer); in mmc_omap_cmd_timer() local
645 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_cmd_timer()
646 if (host->cmd != NULL && !host->abort) { in mmc_omap_cmd_timer()
647 OMAP_MMC_WRITE(host, IE, 0); in mmc_omap_cmd_timer()
648 disable_irq(host->irq); in mmc_omap_cmd_timer()
649 host->abort = 1; in mmc_omap_cmd_timer()
650 queue_work(host->mmc_omap_wq, &host->cmd_abort_work); in mmc_omap_cmd_timer()
652 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_cmd_timer()
658 struct mmc_omap_host *host = from_timer(host, t, clk_timer); in mmc_omap_clk_timer() local
660 mmc_omap_fclk_enable(host, 0); in mmc_omap_clk_timer()
665 mmc_omap_xfer_data(struct mmc_omap_host *host, int write) in mmc_omap_xfer_data() argument
667 struct sg_mapping_iter *sgm = &host->sg_miter; in mmc_omap_xfer_data()
673 dev_err(mmc_dev(host->mmc), "ran out of scatterlist prematurely\n"); in mmc_omap_xfer_data()
676 buffer = sgm->addr; in mmc_omap_xfer_data()
679 if (n > sgm->length) in mmc_omap_xfer_data()
680 n = sgm->length; in mmc_omap_xfer_data()
681 if (n > host->total_bytes_left) in mmc_omap_xfer_data()
682 n = host->total_bytes_left; in mmc_omap_xfer_data()
687 sgm->consumed = n; in mmc_omap_xfer_data()
688 host->total_bytes_left -= n; in mmc_omap_xfer_data()
689 host->data->bytes_xfered += n; in mmc_omap_xfer_data()
692 __raw_writesw(host->virt_base + OMAP_MMC_REG(host, DATA), in mmc_omap_xfer_data()
695 __raw_readsw(host->virt_base + OMAP_MMC_REG(host, DATA), in mmc_omap_xfer_data()
701 static void mmc_omap_report_irq(struct mmc_omap_host *host, u16 status) in mmc_omap_report_irq() argument
715 dev_vdbg(mmc_dev(host->mmc), "%s\n", res); in mmc_omap_report_irq()
718 static void mmc_omap_report_irq(struct mmc_omap_host *host, u16 status) in mmc_omap_report_irq() argument
726 struct mmc_omap_host * host = (struct mmc_omap_host *)dev_id; in mmc_omap_irq() local
732 if (host->cmd == NULL && host->data == NULL) { in mmc_omap_irq()
733 status = OMAP_MMC_READ(host, STAT); in mmc_omap_irq()
734 dev_info(mmc_dev(host->slots[0]->mmc), in mmc_omap_irq()
737 OMAP_MMC_WRITE(host, STAT, status); in mmc_omap_irq()
738 OMAP_MMC_WRITE(host, IE, 0); in mmc_omap_irq()
748 while ((status = OMAP_MMC_READ(host, STAT)) != 0) { in mmc_omap_irq()
751 OMAP_MMC_WRITE(host, STAT, status); in mmc_omap_irq()
752 if (host->cmd != NULL) in mmc_omap_irq()
753 cmd = host->cmd->opcode; in mmc_omap_irq()
755 cmd = -1; in mmc_omap_irq()
756 dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ", in mmc_omap_irq()
758 mmc_omap_report_irq(host, status); in mmc_omap_irq()
760 if (host->total_bytes_left) { in mmc_omap_irq()
763 mmc_omap_xfer_data(host, 0); in mmc_omap_irq()
765 mmc_omap_xfer_data(host, 1); in mmc_omap_irq()
772 dev_dbg(mmc_dev(host->mmc), "data timeout (CMD%d)\n", in mmc_omap_irq()
774 if (host->data) { in mmc_omap_irq()
775 host->data->error = -ETIMEDOUT; in mmc_omap_irq()
781 if (host->data) { in mmc_omap_irq()
782 host->data->error = -EILSEQ; in mmc_omap_irq()
783 dev_dbg(mmc_dev(host->mmc), in mmc_omap_irq()
785 host->total_bytes_left); in mmc_omap_irq()
788 dev_dbg(mmc_dev(host->mmc), "data CRC error\n"); in mmc_omap_irq()
794 if (host->cmd) { in mmc_omap_irq()
796 host->current_slot; in mmc_omap_irq()
799 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
802 host->cmd->error = -ETIMEDOUT; in mmc_omap_irq()
809 if (host->cmd) { in mmc_omap_irq()
810 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
812 cmd, host->cmd->arg); in mmc_omap_irq()
813 host->cmd->error = -EILSEQ; in mmc_omap_irq()
817 dev_err(mmc_dev(host->mmc), in mmc_omap_irq()
822 dev_dbg(mmc_dev(host->mmc), in mmc_omap_irq()
838 if (cmd_error && host->data) { in mmc_omap_irq()
839 del_timer(&host->cmd_abort_timer); in mmc_omap_irq()
840 host->abort = 1; in mmc_omap_irq()
841 OMAP_MMC_WRITE(host, IE, 0); in mmc_omap_irq()
842 disable_irq_nosync(host->irq); in mmc_omap_irq()
843 queue_work(host->mmc_omap_wq, &host->cmd_abort_work); in mmc_omap_irq()
847 if (end_command && host->cmd) in mmc_omap_irq()
848 mmc_omap_cmd_done(host, host->cmd); in mmc_omap_irq()
849 if (host->data != NULL) { in mmc_omap_irq()
851 mmc_omap_xfer_done(host, host->data); in mmc_omap_irq()
853 mmc_omap_end_of_data(host, host->data); in mmc_omap_irq()
862 struct mmc_omap_host *host = dev_get_drvdata(dev); in omap_mmc_notify_cover_event() local
863 struct mmc_omap_slot *slot = host->slots[num]; in omap_mmc_notify_cover_event()
865 BUG_ON(num >= host->nr_slots); in omap_mmc_notify_cover_event()
868 if (host->nr_slots == 0 || !host->slots[num]) in omap_mmc_notify_cover_event()
872 if (cover_open != slot->cover_open) { in omap_mmc_notify_cover_event()
873 slot->cover_open = cover_open; in omap_mmc_notify_cover_event()
874 sysfs_notify(&slot->mmc->class_dev.kobj, NULL, "cover_switch"); in omap_mmc_notify_cover_event()
877 queue_work(system_bh_highpri_wq, &slot->cover_bh_work); in omap_mmc_notify_cover_event()
883 queue_work(system_bh_wq, &slot->cover_bh_work); in mmc_omap_cover_timer()
891 mmc_detect_change(slot->mmc, 0); in mmc_omap_cover_bh_handler()
899 if (slot->mmc->card == NULL) in mmc_omap_cover_bh_handler()
902 mod_timer(&slot->cover_timer, in mmc_omap_cover_bh_handler()
908 struct mmc_omap_host *host = priv; in mmc_omap_dma_callback() local
909 struct mmc_data *data = host->data; in mmc_omap_dma_callback()
912 data->bytes_xfered += data->blocks * data->blksz; in mmc_omap_dma_callback()
914 mmc_omap_dma_done(host, data); in mmc_omap_dma_callback()
917 static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req) in set_cmd_timeout() argument
921 reg = OMAP_MMC_READ(host, SDIO); in set_cmd_timeout()
923 OMAP_MMC_WRITE(host, SDIO, reg); in set_cmd_timeout()
925 OMAP_MMC_WRITE(host, CTO, 0xfd); in set_cmd_timeout()
928 static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_request *req) in set_data_timeout() argument
933 cycle_ns = 1000000000 / host->current_slot->fclk_freq; in set_data_timeout()
934 timeout = req->data->timeout_ns / cycle_ns; in set_data_timeout()
935 timeout += req->data->timeout_clks; in set_data_timeout()
938 reg = OMAP_MMC_READ(host, SDIO); in set_data_timeout()
944 OMAP_MMC_WRITE(host, SDIO, reg); in set_data_timeout()
945 OMAP_MMC_WRITE(host, DTO, timeout); in set_data_timeout()
949 mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) in mmc_omap_prepare_data() argument
952 struct mmc_data *data = req->data; in mmc_omap_prepare_data()
957 host->data = data; in mmc_omap_prepare_data()
959 OMAP_MMC_WRITE(host, BLEN, 0); in mmc_omap_prepare_data()
960 OMAP_MMC_WRITE(host, NBLK, 0); in mmc_omap_prepare_data()
961 OMAP_MMC_WRITE(host, BUF, 0); in mmc_omap_prepare_data()
962 host->dma_in_use = 0; in mmc_omap_prepare_data()
963 set_cmd_timeout(host, req); in mmc_omap_prepare_data()
967 block_size = data->blksz; in mmc_omap_prepare_data()
969 OMAP_MMC_WRITE(host, NBLK, data->blocks - 1); in mmc_omap_prepare_data()
970 OMAP_MMC_WRITE(host, BLEN, block_size - 1); in mmc_omap_prepare_data()
971 set_data_timeout(host, req); in mmc_omap_prepare_data()
974 * block" writes using multi-block scatterlists. in mmc_omap_prepare_data()
976 sg_len = (data->blocks == 1) ? 1 : data->sg_len; in mmc_omap_prepare_data()
979 for_each_sg(data->sg, sg, sg_len, i) { in mmc_omap_prepare_data()
980 if ((sg->length % block_size) != 0) { in mmc_omap_prepare_data()
1000 if (burst > data->blksz) in mmc_omap_prepare_data()
1001 burst = data->blksz; in mmc_omap_prepare_data()
1005 if (data->flags & MMC_DATA_WRITE) { in mmc_omap_prepare_data()
1006 c = host->dma_tx; in mmc_omap_prepare_data()
1007 bp = &host->dma_tx_burst; in mmc_omap_prepare_data()
1008 buf = 0x0f80 | (burst - 1) << 0; in mmc_omap_prepare_data()
1011 c = host->dma_rx; in mmc_omap_prepare_data()
1012 bp = &host->dma_rx_burst; in mmc_omap_prepare_data()
1013 buf = 0x800f | (burst - 1) << 8; in mmc_omap_prepare_data()
1023 .src_addr = host->phys_base + in mmc_omap_prepare_data()
1024 OMAP_MMC_REG(host, DATA), in mmc_omap_prepare_data()
1025 .dst_addr = host->phys_base + in mmc_omap_prepare_data()
1026 OMAP_MMC_REG(host, DATA), in mmc_omap_prepare_data()
1039 host->sg_len = dma_map_sg(c->device->dev, data->sg, sg_len, in mmc_omap_prepare_data()
1041 if (host->sg_len == 0) in mmc_omap_prepare_data()
1044 tx = dmaengine_prep_slave_sg(c, data->sg, host->sg_len, in mmc_omap_prepare_data()
1045 data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, in mmc_omap_prepare_data()
1050 OMAP_MMC_WRITE(host, BUF, buf); in mmc_omap_prepare_data()
1052 tx->callback = mmc_omap_dma_callback; in mmc_omap_prepare_data()
1053 tx->callback_param = host; in mmc_omap_prepare_data()
1055 host->brs_received = 0; in mmc_omap_prepare_data()
1056 host->dma_done = 0; in mmc_omap_prepare_data()
1057 host->dma_in_use = 1; in mmc_omap_prepare_data()
1063 OMAP_MMC_WRITE(host, BUF, 0x1f1f); in mmc_omap_prepare_data()
1064 host->total_bytes_left = data->blocks * block_size; in mmc_omap_prepare_data()
1065 host->sg_len = sg_len; in mmc_omap_prepare_data()
1066 if (data->flags & MMC_DATA_READ) in mmc_omap_prepare_data()
1070 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, miter_flags); in mmc_omap_prepare_data()
1071 host->dma_in_use = 0; in mmc_omap_prepare_data()
1074 static void mmc_omap_start_request(struct mmc_omap_host *host, in mmc_omap_start_request() argument
1077 BUG_ON(host->mrq != NULL); in mmc_omap_start_request()
1079 host->mrq = req; in mmc_omap_start_request()
1082 mmc_omap_prepare_data(host, req); in mmc_omap_start_request()
1083 mmc_omap_start_command(host, req->cmd); in mmc_omap_start_request()
1084 if (host->dma_in_use) { in mmc_omap_start_request()
1085 struct dma_chan *c = host->data->flags & MMC_DATA_WRITE ? in mmc_omap_start_request()
1086 host->dma_tx : host->dma_rx; in mmc_omap_start_request()
1095 struct mmc_omap_host *host = slot->host; in mmc_omap_request() local
1098 spin_lock_irqsave(&host->slot_lock, flags); in mmc_omap_request()
1099 if (host->mmc != NULL) { in mmc_omap_request()
1100 BUG_ON(slot->mrq != NULL); in mmc_omap_request()
1101 slot->mrq = req; in mmc_omap_request()
1102 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_request()
1105 host->mmc = mmc; in mmc_omap_request()
1106 spin_unlock_irqrestore(&host->slot_lock, flags); in mmc_omap_request()
1108 mmc_omap_start_request(host, req); in mmc_omap_request()
1114 struct mmc_omap_host *host; in mmc_omap_set_power() local
1116 host = slot->host; in mmc_omap_set_power()
1119 if (slot->vsd) { in mmc_omap_set_power()
1120 gpiod_set_value(slot->vsd, power_on); in mmc_omap_set_power()
1123 if (slot->vio) { in mmc_omap_set_power()
1124 gpiod_set_value(slot->vio, power_on); in mmc_omap_set_power()
1128 if (slot->vio) { in mmc_omap_set_power()
1129 gpiod_set_value(slot->vio, power_on); in mmc_omap_set_power()
1132 if (slot->vsd) { in mmc_omap_set_power()
1133 gpiod_set_value(slot->vsd, power_on); in mmc_omap_set_power()
1138 if (slot->pdata->set_power != NULL) in mmc_omap_set_power()
1139 slot->pdata->set_power(mmc_dev(slot->mmc), slot->id, power_on, in mmc_omap_set_power()
1145 w = OMAP_MMC_READ(host, CON); in mmc_omap_set_power()
1146 OMAP_MMC_WRITE(host, CON, w | (1 << 11)); in mmc_omap_set_power()
1148 w = OMAP_MMC_READ(host, CON); in mmc_omap_set_power()
1149 OMAP_MMC_WRITE(host, CON, w & ~(1 << 11)); in mmc_omap_set_power()
1157 struct mmc_omap_host *host = slot->host; in mmc_omap_calc_divisor() local
1158 int func_clk_rate = clk_get_rate(host->fclk); in mmc_omap_calc_divisor()
1161 if (ios->clock == 0) in mmc_omap_calc_divisor()
1164 dsor = func_clk_rate / ios->clock; in mmc_omap_calc_divisor()
1168 if (func_clk_rate / dsor > ios->clock) in mmc_omap_calc_divisor()
1174 slot->fclk_freq = func_clk_rate / dsor; in mmc_omap_calc_divisor()
1176 if (ios->bus_width == MMC_BUS_WIDTH_4) in mmc_omap_calc_divisor()
1185 struct mmc_omap_host *host = slot->host; in mmc_omap_set_ios() local
1193 if (ios->vdd != slot->vdd) in mmc_omap_set_ios()
1194 slot->vdd = ios->vdd; in mmc_omap_set_ios()
1198 switch (ios->power_mode) { in mmc_omap_set_ios()
1200 mmc_omap_set_power(slot, 0, ios->vdd); in mmc_omap_set_ios()
1204 mmc_omap_set_power(slot, 1, ios->vdd); in mmc_omap_set_ios()
1205 slot->power_mode = ios->power_mode; in mmc_omap_set_ios()
1208 mmc_omap_fclk_enable(host, 1); in mmc_omap_set_ios()
1211 if (slot->power_mode != MMC_POWER_ON) in mmc_omap_set_ios()
1215 slot->power_mode = ios->power_mode; in mmc_omap_set_ios()
1217 if (slot->bus_mode != ios->bus_mode) { in mmc_omap_set_ios()
1218 if (slot->pdata->set_bus_mode != NULL) in mmc_omap_set_ios()
1219 slot->pdata->set_bus_mode(mmc_dev(mmc), slot->id, in mmc_omap_set_ios()
1220 ios->bus_mode); in mmc_omap_set_ios()
1221 slot->bus_mode = ios->bus_mode; in mmc_omap_set_ios()
1229 OMAP_MMC_WRITE(host, CON, dsor); in mmc_omap_set_ios()
1230 slot->saved_con = dsor; in mmc_omap_set_ios()
1236 OMAP_MMC_WRITE(host, IE, 0); in mmc_omap_set_ios()
1237 OMAP_MMC_WRITE(host, STAT, 0xffff); in mmc_omap_set_ios()
1238 OMAP_MMC_WRITE(host, CMD, 1 << 7); in mmc_omap_set_ios()
1239 while (usecs > 0 && (OMAP_MMC_READ(host, STAT) & 1) == 0) { in mmc_omap_set_ios()
1241 usecs--; in mmc_omap_set_ios()
1243 OMAP_MMC_WRITE(host, STAT, 1); in mmc_omap_set_ios()
1255 static int mmc_omap_new_slot(struct mmc_omap_host *host, int id) in mmc_omap_new_slot() argument
1261 mmc = mmc_alloc_host(sizeof(struct mmc_omap_slot), host->dev); in mmc_omap_new_slot()
1263 return -ENOMEM; in mmc_omap_new_slot()
1266 slot->host = host; in mmc_omap_new_slot()
1267 slot->mmc = mmc; in mmc_omap_new_slot()
1268 slot->id = id; in mmc_omap_new_slot()
1269 slot->power_mode = MMC_POWER_UNDEFINED; in mmc_omap_new_slot()
1270 slot->pdata = &host->pdata->slots[id]; in mmc_omap_new_slot()
1273 slot->vsd = devm_gpiod_get_index_optional(host->dev, "vsd", in mmc_omap_new_slot()
1274 id, GPIOD_OUT_LOW); in mmc_omap_new_slot()
1275 if (IS_ERR(slot->vsd)) in mmc_omap_new_slot()
1276 return dev_err_probe(host->dev, PTR_ERR(slot->vsd), in mmc_omap_new_slot()
1278 slot->vio = devm_gpiod_get_index_optional(host->dev, "vio", in mmc_omap_new_slot()
1279 id, GPIOD_OUT_LOW); in mmc_omap_new_slot()
1280 if (IS_ERR(slot->vio)) in mmc_omap_new_slot()
1281 return dev_err_probe(host->dev, PTR_ERR(slot->vio), in mmc_omap_new_slot()
1283 slot->cover = devm_gpiod_get_index_optional(host->dev, "cover", in mmc_omap_new_slot()
1284 id, GPIOD_IN); in mmc_omap_new_slot()
1285 if (IS_ERR(slot->cover)) in mmc_omap_new_slot()
1286 return dev_err_probe(host->dev, PTR_ERR(slot->cover), in mmc_omap_new_slot()
1289 host->slots[id] = slot; in mmc_omap_new_slot()
1291 mmc->caps = 0; in mmc_omap_new_slot()
1292 if (host->pdata->slots[id].wires >= 4) in mmc_omap_new_slot()
1293 mmc->caps |= MMC_CAP_4_BIT_DATA; in mmc_omap_new_slot()
1295 mmc->ops = &mmc_omap_ops; in mmc_omap_new_slot()
1296 mmc->f_min = 400000; in mmc_omap_new_slot()
1299 mmc->f_max = 48000000; in mmc_omap_new_slot()
1301 mmc->f_max = 24000000; in mmc_omap_new_slot()
1302 if (host->pdata->max_freq) in mmc_omap_new_slot()
1303 mmc->f_max = min(host->pdata->max_freq, mmc->f_max); in mmc_omap_new_slot()
1304 mmc->ocr_avail = slot->pdata->ocr_mask; in mmc_omap_new_slot()
1306 /* Use scatterlist DMA to reduce per-transfer costs. in mmc_omap_new_slot()
1310 mmc->max_segs = 32; in mmc_omap_new_slot()
1311 mmc->max_blk_size = 2048; /* BLEN is 11 bits (+1) */ in mmc_omap_new_slot()
1312 mmc->max_blk_count = 2048; /* NBLK is 11 bits (+1) */ in mmc_omap_new_slot()
1313 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; in mmc_omap_new_slot()
1314 mmc->max_seg_size = mmc->max_req_size; in mmc_omap_new_slot()
1316 if (slot->pdata->get_cover_state != NULL) { in mmc_omap_new_slot()
1317 timer_setup(&slot->cover_timer, mmc_omap_cover_timer, 0); in mmc_omap_new_slot()
1318 INIT_WORK(&slot->cover_bh_work, mmc_omap_cover_bh_handler); in mmc_omap_new_slot()
1325 if (slot->pdata->name != NULL) { in mmc_omap_new_slot()
1326 r = device_create_file(&mmc->class_dev, in mmc_omap_new_slot()
1332 if (slot->pdata->get_cover_state != NULL) { in mmc_omap_new_slot()
1333 r = device_create_file(&mmc->class_dev, in mmc_omap_new_slot()
1337 queue_work(system_bh_wq, &slot->cover_bh_work); in mmc_omap_new_slot()
1343 if (slot->pdata->name != NULL) in mmc_omap_new_slot()
1344 device_remove_file(&mmc->class_dev, &dev_attr_slot_name); in mmc_omap_new_slot()
1353 struct mmc_host *mmc = slot->mmc; in mmc_omap_remove_slot()
1355 if (slot->pdata->name != NULL) in mmc_omap_remove_slot()
1356 device_remove_file(&mmc->class_dev, &dev_attr_slot_name); in mmc_omap_remove_slot()
1357 if (slot->pdata->get_cover_state != NULL) in mmc_omap_remove_slot()
1358 device_remove_file(&mmc->class_dev, &dev_attr_cover_switch); in mmc_omap_remove_slot()
1360 cancel_work_sync(&slot->cover_bh_work); in mmc_omap_remove_slot()
1361 del_timer_sync(&slot->cover_timer); in mmc_omap_remove_slot()
1362 flush_workqueue(slot->host->mmc_omap_wq); in mmc_omap_remove_slot()
1370 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; in mmc_omap_probe()
1371 struct mmc_omap_host *host = NULL; in mmc_omap_probe() local
1377 dev_err(&pdev->dev, "platform data missing\n"); in mmc_omap_probe()
1378 return -ENXIO; in mmc_omap_probe()
1380 if (pdata->nr_slots == 0) { in mmc_omap_probe()
1381 dev_err(&pdev->dev, "no slots\n"); in mmc_omap_probe()
1382 return -EPROBE_DEFER; in mmc_omap_probe()
1385 host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host), in mmc_omap_probe()
1387 if (host == NULL) in mmc_omap_probe()
1388 return -ENOMEM; in mmc_omap_probe()
1394 host->virt_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in mmc_omap_probe()
1395 if (IS_ERR(host->virt_base)) in mmc_omap_probe()
1396 return PTR_ERR(host->virt_base); in mmc_omap_probe()
1398 INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work); in mmc_omap_probe()
1399 INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work); in mmc_omap_probe()
1401 INIT_WORK(&host->cmd_abort_work, mmc_omap_abort_command); in mmc_omap_probe()
1402 timer_setup(&host->cmd_abort_timer, mmc_omap_cmd_timer, 0); in mmc_omap_probe()
1404 spin_lock_init(&host->clk_lock); in mmc_omap_probe()
1405 timer_setup(&host->clk_timer, mmc_omap_clk_timer, 0); in mmc_omap_probe()
1407 spin_lock_init(&host->dma_lock); in mmc_omap_probe()
1408 spin_lock_init(&host->slot_lock); in mmc_omap_probe()
1409 init_waitqueue_head(&host->slot_wq); in mmc_omap_probe()
1411 host->pdata = pdata; in mmc_omap_probe()
1412 host->features = host->pdata->slots[0].features; in mmc_omap_probe()
1413 host->dev = &pdev->dev; in mmc_omap_probe()
1414 platform_set_drvdata(pdev, host); in mmc_omap_probe()
1416 host->slot_switch = devm_gpiod_get_optional(host->dev, "switch", in mmc_omap_probe()
1418 if (IS_ERR(host->slot_switch)) in mmc_omap_probe()
1419 return dev_err_probe(host->dev, PTR_ERR(host->slot_switch), in mmc_omap_probe()
1422 host->id = pdev->id; in mmc_omap_probe()
1423 host->irq = irq; in mmc_omap_probe()
1424 host->phys_base = res->start; in mmc_omap_probe()
1425 host->iclk = clk_get(&pdev->dev, "ick"); in mmc_omap_probe()
1426 if (IS_ERR(host->iclk)) in mmc_omap_probe()
1427 return PTR_ERR(host->iclk); in mmc_omap_probe()
1428 clk_prepare_enable(host->iclk); in mmc_omap_probe()
1430 host->fclk = clk_get(&pdev->dev, "fck"); in mmc_omap_probe()
1431 if (IS_ERR(host->fclk)) { in mmc_omap_probe()
1432 ret = PTR_ERR(host->fclk); in mmc_omap_probe()
1436 ret = clk_prepare(host->fclk); in mmc_omap_probe()
1440 host->dma_tx_burst = -1; in mmc_omap_probe()
1441 host->dma_rx_burst = -1; in mmc_omap_probe()
1443 host->dma_tx = dma_request_chan(&pdev->dev, "tx"); in mmc_omap_probe()
1444 if (IS_ERR(host->dma_tx)) { in mmc_omap_probe()
1445 ret = PTR_ERR(host->dma_tx); in mmc_omap_probe()
1446 if (ret == -EPROBE_DEFER) in mmc_omap_probe()
1449 host->dma_tx = NULL; in mmc_omap_probe()
1450 dev_warn(host->dev, "TX DMA channel request failed\n"); in mmc_omap_probe()
1453 host->dma_rx = dma_request_chan(&pdev->dev, "rx"); in mmc_omap_probe()
1454 if (IS_ERR(host->dma_rx)) { in mmc_omap_probe()
1455 ret = PTR_ERR(host->dma_rx); in mmc_omap_probe()
1456 if (ret == -EPROBE_DEFER) { in mmc_omap_probe()
1457 if (host->dma_tx) in mmc_omap_probe()
1458 dma_release_channel(host->dma_tx); in mmc_omap_probe()
1462 host->dma_rx = NULL; in mmc_omap_probe()
1463 dev_warn(host->dev, "RX DMA channel request failed\n"); in mmc_omap_probe()
1466 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); in mmc_omap_probe()
1470 if (pdata->init != NULL) { in mmc_omap_probe()
1471 ret = pdata->init(&pdev->dev); in mmc_omap_probe()
1476 host->nr_slots = pdata->nr_slots; in mmc_omap_probe()
1477 host->reg_shift = (mmc_omap7xx() ? 1 : 2); in mmc_omap_probe()
1479 host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0); in mmc_omap_probe()
1480 if (!host->mmc_omap_wq) { in mmc_omap_probe()
1481 ret = -ENOMEM; in mmc_omap_probe()
1485 for (i = 0; i < pdata->nr_slots; i++) { in mmc_omap_probe()
1486 ret = mmc_omap_new_slot(host, i); in mmc_omap_probe()
1488 while (--i >= 0) in mmc_omap_probe()
1489 mmc_omap_remove_slot(host->slots[i]); in mmc_omap_probe()
1498 destroy_workqueue(host->mmc_omap_wq); in mmc_omap_probe()
1500 if (pdata->cleanup) in mmc_omap_probe()
1501 pdata->cleanup(&pdev->dev); in mmc_omap_probe()
1503 free_irq(host->irq, host); in mmc_omap_probe()
1505 if (host->dma_tx) in mmc_omap_probe()
1506 dma_release_channel(host->dma_tx); in mmc_omap_probe()
1507 if (host->dma_rx) in mmc_omap_probe()
1508 dma_release_channel(host->dma_rx); in mmc_omap_probe()
1510 clk_unprepare(host->fclk); in mmc_omap_probe()
1512 clk_put(host->fclk); in mmc_omap_probe()
1514 clk_disable_unprepare(host->iclk); in mmc_omap_probe()
1515 clk_put(host->iclk); in mmc_omap_probe()
1521 struct mmc_omap_host *host = platform_get_drvdata(pdev); in mmc_omap_remove() local
1524 BUG_ON(host == NULL); in mmc_omap_remove()
1526 for (i = 0; i < host->nr_slots; i++) in mmc_omap_remove()
1527 mmc_omap_remove_slot(host->slots[i]); in mmc_omap_remove()
1529 if (host->pdata->cleanup) in mmc_omap_remove()
1530 host->pdata->cleanup(&pdev->dev); in mmc_omap_remove()
1532 mmc_omap_fclk_enable(host, 0); in mmc_omap_remove()
1533 free_irq(host->irq, host); in mmc_omap_remove()
1534 clk_unprepare(host->fclk); in mmc_omap_remove()
1535 clk_put(host->fclk); in mmc_omap_remove()
1536 clk_disable_unprepare(host->iclk); in mmc_omap_remove()
1537 clk_put(host->iclk); in mmc_omap_remove()
1539 if (host->dma_tx) in mmc_omap_remove()
1540 dma_release_channel(host->dma_tx); in mmc_omap_remove()
1541 if (host->dma_rx) in mmc_omap_remove()
1542 dma_release_channel(host->dma_rx); in mmc_omap_remove()
1544 destroy_workqueue(host->mmc_omap_wq); in mmc_omap_remove()
1549 { .compatible = "ti,omap2420-mmc", },