Lines Matching refs:host
130 #define dbg(host, channels, args...) \ argument
133 dev_err(&host->pdev->dev, args); \
135 dev_info(&host->pdev->dev, args); \
137 dev_dbg(&host->pdev->dev, args); \
140 static void finalize_request(struct s3cmci_host *host);
142 static void s3cmci_reset(struct s3cmci_host *host);
146 static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) in dbg_dumpregs() argument
151 con = readl(host->base + S3C2410_SDICON); in dbg_dumpregs()
152 pre = readl(host->base + S3C2410_SDIPRE); in dbg_dumpregs()
153 cmdarg = readl(host->base + S3C2410_SDICMDARG); in dbg_dumpregs()
154 cmdcon = readl(host->base + S3C2410_SDICMDCON); in dbg_dumpregs()
155 cmdsta = readl(host->base + S3C2410_SDICMDSTAT); in dbg_dumpregs()
156 r0 = readl(host->base + S3C2410_SDIRSP0); in dbg_dumpregs()
157 r1 = readl(host->base + S3C2410_SDIRSP1); in dbg_dumpregs()
158 r2 = readl(host->base + S3C2410_SDIRSP2); in dbg_dumpregs()
159 r3 = readl(host->base + S3C2410_SDIRSP3); in dbg_dumpregs()
160 timer = readl(host->base + S3C2410_SDITIMER); in dbg_dumpregs()
161 datcon = readl(host->base + S3C2410_SDIDCON); in dbg_dumpregs()
162 datcnt = readl(host->base + S3C2410_SDIDCNT); in dbg_dumpregs()
163 datsta = readl(host->base + S3C2410_SDIDSTA); in dbg_dumpregs()
164 fsta = readl(host->base + S3C2410_SDIFSTA); in dbg_dumpregs()
166 dbg(host, dbg_debug, "%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n", in dbg_dumpregs()
169 dbg(host, dbg_debug, "%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n", in dbg_dumpregs()
172 dbg(host, dbg_debug, "%s DCON:[%08x] FSTA:[%08x]" in dbg_dumpregs()
176 dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]" in dbg_dumpregs()
181 static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd, in prepare_dbgmsg() argument
184 snprintf(host->dbgmsg_cmd, 300, in prepare_dbgmsg()
186 host->ccnt, (stop ? " (STOP)" : ""), in prepare_dbgmsg()
190 snprintf(host->dbgmsg_dat, 300, in prepare_dbgmsg()
192 host->dcnt, cmd->data->blksz, in prepare_dbgmsg()
196 host->dbgmsg_dat[0] = '\0'; in prepare_dbgmsg()
200 static void dbg_dumpcmd(struct s3cmci_host *host, struct mmc_command *cmd, in dbg_dumpcmd() argument
209 dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n", in dbg_dumpcmd()
210 host->dbgmsg_cmd, cmd->resp[0]); in dbg_dumpcmd()
212 dbg(host, dbglvl, "CMD[ERR %i] %s Status:%s\n", in dbg_dumpcmd()
213 cmd->error, host->dbgmsg_cmd, host->status); in dbg_dumpcmd()
220 dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat); in dbg_dumpcmd()
222 dbg(host, dbglvl, "DAT[ERR %i] %s DCNT:0x%08x\n", in dbg_dumpcmd()
223 cmd->data->error, host->dbgmsg_dat, in dbg_dumpcmd()
224 readl(host->base + S3C2410_SDIDCNT)); in dbg_dumpcmd()
228 static void dbg_dumpcmd(struct s3cmci_host *host, in dbg_dumpcmd() argument
231 static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd, in prepare_dbgmsg() argument
234 static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) { } in dbg_dumpregs() argument
246 static inline bool s3cmci_host_usedma(struct s3cmci_host *host) in s3cmci_host_usedma() argument
255 static inline u32 enable_imask(struct s3cmci_host *host, u32 imask) in enable_imask() argument
259 newmask = readl(host->base + host->sdiimsk); in enable_imask()
262 writel(newmask, host->base + host->sdiimsk); in enable_imask()
267 static inline u32 disable_imask(struct s3cmci_host *host, u32 imask) in disable_imask() argument
271 newmask = readl(host->base + host->sdiimsk); in disable_imask()
274 writel(newmask, host->base + host->sdiimsk); in disable_imask()
279 static inline void clear_imask(struct s3cmci_host *host) in clear_imask() argument
281 u32 mask = readl(host->base + host->sdiimsk); in clear_imask()
285 writel(mask, host->base + host->sdiimsk); in clear_imask()
300 static void s3cmci_check_sdio_irq(struct s3cmci_host *host) in s3cmci_check_sdio_irq() argument
302 if (host->sdio_irqen) { in s3cmci_check_sdio_irq()
303 if (host->pdata->bus[3] && in s3cmci_check_sdio_irq()
304 gpiod_get_value(host->pdata->bus[3]) == 0) { in s3cmci_check_sdio_irq()
306 mmc_signal_sdio_irq(host->mmc); in s3cmci_check_sdio_irq()
311 static inline int get_data_buffer(struct s3cmci_host *host, in get_data_buffer() argument
316 if (host->pio_active == XFER_NONE) in get_data_buffer()
319 if ((!host->mrq) || (!host->mrq->data)) in get_data_buffer()
322 if (host->pio_sgptr >= host->mrq->data->sg_len) { in get_data_buffer()
323 dbg(host, dbg_debug, "no more buffers (%i/%i)\n", in get_data_buffer()
324 host->pio_sgptr, host->mrq->data->sg_len); in get_data_buffer()
327 sg = &host->mrq->data->sg[host->pio_sgptr]; in get_data_buffer()
332 host->pio_sgptr++; in get_data_buffer()
334 dbg(host, dbg_sg, "new buffer (%i/%i)\n", in get_data_buffer()
335 host->pio_sgptr, host->mrq->data->sg_len); in get_data_buffer()
340 static inline u32 fifo_count(struct s3cmci_host *host) in fifo_count() argument
342 u32 fifostat = readl(host->base + S3C2410_SDIFSTA); in fifo_count()
348 static inline u32 fifo_free(struct s3cmci_host *host) in fifo_free() argument
350 u32 fifostat = readl(host->base + S3C2410_SDIFSTA); in fifo_free()
369 static void s3cmci_enable_irq(struct s3cmci_host *host, bool more) in s3cmci_enable_irq() argument
376 host->irq_enabled = more; in s3cmci_enable_irq()
377 host->irq_disabled = false; in s3cmci_enable_irq()
379 enable = more | host->sdio_irqen; in s3cmci_enable_irq()
381 if (host->irq_state != enable) { in s3cmci_enable_irq()
382 host->irq_state = enable; in s3cmci_enable_irq()
385 enable_irq(host->irq); in s3cmci_enable_irq()
387 disable_irq(host->irq); in s3cmci_enable_irq()
393 static void s3cmci_disable_irq(struct s3cmci_host *host, bool transfer) in s3cmci_disable_irq() argument
401 host->irq_disabled = transfer; in s3cmci_disable_irq()
403 if (transfer && host->irq_state) { in s3cmci_disable_irq()
404 host->irq_state = false; in s3cmci_disable_irq()
405 disable_irq(host->irq); in s3cmci_disable_irq()
411 static void do_pio_read(struct s3cmci_host *host) in do_pio_read() argument
420 writel(host->prescaler, host->base + S3C2410_SDIPRE); in do_pio_read()
422 from_ptr = host->base + host->sdidata; in do_pio_read()
424 while ((fifo = fifo_count(host))) { in do_pio_read()
425 if (!host->pio_bytes) { in do_pio_read()
426 res = get_data_buffer(host, &host->pio_bytes, in do_pio_read()
427 &host->pio_ptr); in do_pio_read()
429 host->pio_active = XFER_NONE; in do_pio_read()
430 host->complete_what = COMPLETION_FINALIZE; in do_pio_read()
432 dbg(host, dbg_pio, "pio_read(): " in do_pio_read()
437 dbg(host, dbg_pio, in do_pio_read()
439 host->pio_bytes, host->pio_ptr); in do_pio_read()
442 dbg(host, dbg_pio, in do_pio_read()
444 fifo, host->pio_bytes, in do_pio_read()
445 readl(host->base + S3C2410_SDIDCNT)); in do_pio_read()
452 if (fifo >= host->pio_bytes) in do_pio_read()
453 fifo = host->pio_bytes; in do_pio_read()
457 host->pio_bytes -= fifo; in do_pio_read()
458 host->pio_count += fifo; in do_pio_read()
461 ptr = host->pio_ptr; in do_pio_read()
464 host->pio_ptr = ptr; in do_pio_read()
469 u8 *p = (u8 *)host->pio_ptr; in do_pio_read()
478 if (!host->pio_bytes) { in do_pio_read()
479 res = get_data_buffer(host, &host->pio_bytes, &host->pio_ptr); in do_pio_read()
481 dbg(host, dbg_pio, in do_pio_read()
483 host->pio_active = XFER_NONE; in do_pio_read()
484 host->complete_what = COMPLETION_FINALIZE; in do_pio_read()
490 enable_imask(host, in do_pio_read()
494 static void do_pio_write(struct s3cmci_host *host) in do_pio_write() argument
501 to_ptr = host->base + host->sdidata; in do_pio_write()
503 while ((fifo = fifo_free(host)) > 3) { in do_pio_write()
504 if (!host->pio_bytes) { in do_pio_write()
505 res = get_data_buffer(host, &host->pio_bytes, in do_pio_write()
506 &host->pio_ptr); in do_pio_write()
508 dbg(host, dbg_pio, in do_pio_write()
510 host->pio_active = XFER_NONE; in do_pio_write()
515 dbg(host, dbg_pio, in do_pio_write()
517 host->pio_bytes, host->pio_ptr); in do_pio_write()
525 if (fifo >= host->pio_bytes) in do_pio_write()
526 fifo = host->pio_bytes; in do_pio_write()
530 host->pio_bytes -= fifo; in do_pio_write()
531 host->pio_count += fifo; in do_pio_write()
534 ptr = host->pio_ptr; in do_pio_write()
537 host->pio_ptr = ptr; in do_pio_write()
540 enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); in do_pio_write()
545 struct s3cmci_host *host = from_tasklet(host, t, pio_tasklet); in pio_tasklet() local
547 s3cmci_disable_irq(host, true); in pio_tasklet()
549 if (host->pio_active == XFER_WRITE) in pio_tasklet()
550 do_pio_write(host); in pio_tasklet()
552 if (host->pio_active == XFER_READ) in pio_tasklet()
553 do_pio_read(host); in pio_tasklet()
555 if (host->complete_what == COMPLETION_FINALIZE) { in pio_tasklet()
556 clear_imask(host); in pio_tasklet()
557 if (host->pio_active != XFER_NONE) { in pio_tasklet()
558 dbg(host, dbg_err, "unfinished %s " in pio_tasklet()
560 (host->pio_active == XFER_READ) ? "read" : "write", in pio_tasklet()
561 host->pio_count, host->pio_bytes); in pio_tasklet()
563 if (host->mrq->data) in pio_tasklet()
564 host->mrq->data->error = -EINVAL; in pio_tasklet()
567 s3cmci_enable_irq(host, false); in pio_tasklet()
568 finalize_request(host); in pio_tasklet()
570 s3cmci_enable_irq(host, true); in pio_tasklet()
602 struct s3cmci_host *host = dev_id; in s3cmci_irq() local
608 mci_dsta = readl(host->base + S3C2410_SDIDSTA); in s3cmci_irq()
609 mci_imsk = readl(host->base + host->sdiimsk); in s3cmci_irq()
614 writel(mci_dclear, host->base + S3C2410_SDIDSTA); in s3cmci_irq()
616 mmc_signal_sdio_irq(host->mmc); in s3cmci_irq()
621 spin_lock_irqsave(&host->complete_lock, iflags); in s3cmci_irq()
623 mci_csta = readl(host->base + S3C2410_SDICMDSTAT); in s3cmci_irq()
624 mci_dcnt = readl(host->base + S3C2410_SDIDCNT); in s3cmci_irq()
625 mci_fsta = readl(host->base + S3C2410_SDIFSTA); in s3cmci_irq()
628 if ((host->complete_what == COMPLETION_NONE) || in s3cmci_irq()
629 (host->complete_what == COMPLETION_FINALIZE)) { in s3cmci_irq()
630 host->status = "nothing to complete"; in s3cmci_irq()
631 clear_imask(host); in s3cmci_irq()
635 if (!host->mrq) { in s3cmci_irq()
636 host->status = "no active mrq"; in s3cmci_irq()
637 clear_imask(host); in s3cmci_irq()
641 cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd; in s3cmci_irq()
644 host->status = "no active cmd"; in s3cmci_irq()
645 clear_imask(host); in s3cmci_irq()
649 if (!s3cmci_host_usedma(host)) { in s3cmci_irq()
650 if ((host->pio_active == XFER_WRITE) && in s3cmci_irq()
653 disable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); in s3cmci_irq()
654 tasklet_schedule(&host->pio_tasklet); in s3cmci_irq()
655 host->status = "pio tx"; in s3cmci_irq()
658 if ((host->pio_active == XFER_READ) && in s3cmci_irq()
661 disable_imask(host, in s3cmci_irq()
665 tasklet_schedule(&host->pio_tasklet); in s3cmci_irq()
666 host->status = "pio rx"; in s3cmci_irq()
671 dbg(host, dbg_err, "CMDSTAT: error CMDTIMEOUT\n"); in s3cmci_irq()
673 host->status = "error: command timeout"; in s3cmci_irq()
678 if (host->complete_what == COMPLETION_CMDSENT) { in s3cmci_irq()
679 host->status = "ok: command sent"; in s3cmci_irq()
688 if (host->mrq->cmd->flags & MMC_RSP_136) { in s3cmci_irq()
689 dbg(host, dbg_irq, in s3cmci_irq()
707 if (host->complete_what == COMPLETION_RSPFIN) { in s3cmci_irq()
708 host->status = "ok: command response received"; in s3cmci_irq()
712 if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN) in s3cmci_irq()
713 host->complete_what = COMPLETION_XFERFINISH; in s3cmci_irq()
725 if (host->is2440) { in s3cmci_irq()
727 dbg(host, dbg_err, "FIFO failure\n"); in s3cmci_irq()
728 host->mrq->data->error = -EILSEQ; in s3cmci_irq()
729 host->status = "error: 2440 fifo failure"; in s3cmci_irq()
734 dbg(host, dbg_err, "FIFO failure\n"); in s3cmci_irq()
736 host->status = "error: fifo failure"; in s3cmci_irq()
742 dbg(host, dbg_err, "bad data crc (outgoing)\n"); in s3cmci_irq()
744 host->status = "error: bad data crc (outgoing)"; in s3cmci_irq()
749 dbg(host, dbg_err, "bad data crc (incoming)\n"); in s3cmci_irq()
751 host->status = "error: bad data crc (incoming)"; in s3cmci_irq()
756 dbg(host, dbg_err, "data timeout\n"); in s3cmci_irq()
758 host->status = "error: data timeout"; in s3cmci_irq()
763 if (host->complete_what == COMPLETION_XFERFINISH) { in s3cmci_irq()
764 host->status = "ok: data transfer completed"; in s3cmci_irq()
768 if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN) in s3cmci_irq()
769 host->complete_what = COMPLETION_RSPFIN; in s3cmci_irq()
775 writel(mci_cclear, host->base + S3C2410_SDICMDSTAT); in s3cmci_irq()
776 writel(mci_dclear, host->base + S3C2410_SDIDSTA); in s3cmci_irq()
781 host->pio_active = XFER_NONE; in s3cmci_irq()
784 host->complete_what = COMPLETION_FINALIZE; in s3cmci_irq()
786 clear_imask(host); in s3cmci_irq()
787 tasklet_schedule(&host->pio_tasklet); in s3cmci_irq()
792 dbg(host, dbg_irq, in s3cmci_irq()
794 mci_csta, mci_dsta, mci_fsta, mci_dcnt, host->status); in s3cmci_irq()
796 spin_unlock_irqrestore(&host->complete_lock, iflags); in s3cmci_irq()
803 struct s3cmci_host *host = arg; in s3cmci_dma_done_callback() local
806 BUG_ON(!host->mrq); in s3cmci_dma_done_callback()
807 BUG_ON(!host->mrq->data); in s3cmci_dma_done_callback()
809 spin_lock_irqsave(&host->complete_lock, iflags); in s3cmci_dma_done_callback()
811 dbg(host, dbg_dma, "DMA FINISHED\n"); in s3cmci_dma_done_callback()
813 host->dma_complete = 1; in s3cmci_dma_done_callback()
814 host->complete_what = COMPLETION_FINALIZE; in s3cmci_dma_done_callback()
816 tasklet_schedule(&host->pio_tasklet); in s3cmci_dma_done_callback()
817 spin_unlock_irqrestore(&host->complete_lock, iflags); in s3cmci_dma_done_callback()
821 static void finalize_request(struct s3cmci_host *host) in finalize_request() argument
823 struct mmc_request *mrq = host->mrq; in finalize_request()
827 if (host->complete_what != COMPLETION_FINALIZE) in finalize_request()
832 cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd; in finalize_request()
836 if (s3cmci_host_usedma(host) && (!host->dma_complete)) { in finalize_request()
837 dbg(host, dbg_dma, "DMA Missing (%d)!\n", in finalize_request()
838 host->dma_complete); in finalize_request()
844 cmd->resp[0] = readl(host->base + S3C2410_SDIRSP0); in finalize_request()
845 cmd->resp[1] = readl(host->base + S3C2410_SDIRSP1); in finalize_request()
846 cmd->resp[2] = readl(host->base + S3C2410_SDIRSP2); in finalize_request()
847 cmd->resp[3] = readl(host->base + S3C2410_SDIRSP3); in finalize_request()
849 writel(host->prescaler, host->base + S3C2410_SDIPRE); in finalize_request()
857 dbg_dumpcmd(host, cmd, debug_as_failure); in finalize_request()
860 writel(0, host->base + S3C2410_SDICMDARG); in finalize_request()
861 writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON); in finalize_request()
862 writel(0, host->base + S3C2410_SDICMDCON); in finalize_request()
863 clear_imask(host); in finalize_request()
868 if (cmd->data && cmd->data->stop && (!host->cmd_is_stop)) { in finalize_request()
869 host->cmd_is_stop = 1; in finalize_request()
870 s3cmci_send_request(host->mmc); in finalize_request()
889 if (s3cmci_host_usedma(host)) in finalize_request()
890 dmaengine_terminate_all(host->dma); in finalize_request()
892 if (host->is2440) { in finalize_request()
896 host->base + S3C2410_SDIFSTA); in finalize_request()
901 mci_con = readl(host->base + S3C2410_SDICON); in finalize_request()
904 writel(mci_con, host->base + S3C2410_SDICON); in finalize_request()
909 host->complete_what = COMPLETION_NONE; in finalize_request()
910 host->mrq = NULL; in finalize_request()
912 s3cmci_check_sdio_irq(host); in finalize_request()
913 mmc_request_done(host->mmc, mrq); in finalize_request()
916 static void s3cmci_send_command(struct s3cmci_host *host, in s3cmci_send_command() argument
925 enable_imask(host, imsk); in s3cmci_send_command()
928 host->complete_what = COMPLETION_XFERFINISH_RSPFIN; in s3cmci_send_command()
930 host->complete_what = COMPLETION_RSPFIN; in s3cmci_send_command()
932 host->complete_what = COMPLETION_CMDSENT; in s3cmci_send_command()
934 writel(cmd->arg, host->base + S3C2410_SDICMDARG); in s3cmci_send_command()
945 writel(ccon, host->base + S3C2410_SDICMDCON); in s3cmci_send_command()
948 static int s3cmci_setup_data(struct s3cmci_host *host, struct mmc_data *data) in s3cmci_setup_data() argument
963 while (readl(host->base + S3C2410_SDIDSTA) & in s3cmci_setup_data()
966 dbg(host, dbg_err, in s3cmci_setup_data()
969 writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON); in s3cmci_setup_data()
970 s3cmci_reset(host); in s3cmci_setup_data()
973 dbg_dumpregs(host, "DRF"); in s3cmci_setup_data()
980 if (s3cmci_host_usedma(host)) in s3cmci_setup_data()
983 if (host->bus_width == MMC_BUS_WIDTH_4) in s3cmci_setup_data()
998 if (host->is2440) { in s3cmci_setup_data()
1003 writel(dcon, host->base + S3C2410_SDIDCON); in s3cmci_setup_data()
1007 writel(data->blksz, host->base + S3C2410_SDIBSIZE); in s3cmci_setup_data()
1013 enable_imask(host, imsk); in s3cmci_setup_data()
1017 if (host->is2440) { in s3cmci_setup_data()
1018 writel(0x007FFFFF, host->base + S3C2410_SDITIMER); in s3cmci_setup_data()
1020 writel(0x0000FFFF, host->base + S3C2410_SDITIMER); in s3cmci_setup_data()
1024 writel(0xFF, host->base + S3C2410_SDIPRE); in s3cmci_setup_data()
1032 static int s3cmci_prepare_pio(struct s3cmci_host *host, struct mmc_data *data) in s3cmci_prepare_pio() argument
1038 host->pio_sgptr = 0; in s3cmci_prepare_pio()
1039 host->pio_bytes = 0; in s3cmci_prepare_pio()
1040 host->pio_count = 0; in s3cmci_prepare_pio()
1041 host->pio_active = rw ? XFER_WRITE : XFER_READ; in s3cmci_prepare_pio()
1044 do_pio_write(host); in s3cmci_prepare_pio()
1045 enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); in s3cmci_prepare_pio()
1047 enable_imask(host, S3C2410_SDIIMSK_RXFIFOHALF in s3cmci_prepare_pio()
1054 static int s3cmci_prepare_dma(struct s3cmci_host *host, struct mmc_data *data) in s3cmci_prepare_dma() argument
1059 .src_addr = host->mem->start + host->sdidata, in s3cmci_prepare_dma()
1060 .dst_addr = host->mem->start + host->sdidata, in s3cmci_prepare_dma()
1068 writel(host->prescaler, host->base + S3C2410_SDIPRE); in s3cmci_prepare_dma()
1075 dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, in s3cmci_prepare_dma()
1078 dmaengine_slave_config(host->dma, &conf); in s3cmci_prepare_dma()
1079 desc = dmaengine_prep_slave_sg(host->dma, data->sg, data->sg_len, in s3cmci_prepare_dma()
1085 desc->callback_param = host; in s3cmci_prepare_dma()
1087 dma_async_issue_pending(host->dma); in s3cmci_prepare_dma()
1092 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, in s3cmci_prepare_dma()
1099 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_send_request() local
1100 struct mmc_request *mrq = host->mrq; in s3cmci_send_request()
1101 struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd; in s3cmci_send_request()
1103 host->ccnt++; in s3cmci_send_request()
1104 prepare_dbgmsg(host, cmd, host->cmd_is_stop); in s3cmci_send_request()
1109 writel(0xFFFFFFFF, host->base + S3C2410_SDICMDSTAT); in s3cmci_send_request()
1110 writel(0xFFFFFFFF, host->base + S3C2410_SDIDSTA); in s3cmci_send_request()
1111 writel(0xFFFFFFFF, host->base + S3C2410_SDIFSTA); in s3cmci_send_request()
1114 int res = s3cmci_setup_data(host, cmd->data); in s3cmci_send_request()
1116 host->dcnt++; in s3cmci_send_request()
1119 dbg(host, dbg_err, "setup data error %d\n", res); in s3cmci_send_request()
1127 if (s3cmci_host_usedma(host)) in s3cmci_send_request()
1128 res = s3cmci_prepare_dma(host, cmd->data); in s3cmci_send_request()
1130 res = s3cmci_prepare_pio(host, cmd->data); in s3cmci_send_request()
1133 dbg(host, dbg_err, "data prepare error %d\n", res); in s3cmci_send_request()
1143 s3cmci_send_command(host, cmd); in s3cmci_send_request()
1146 s3cmci_enable_irq(host, true); in s3cmci_send_request()
1151 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_request() local
1153 host->status = "mmc request"; in s3cmci_request()
1154 host->cmd_is_stop = 0; in s3cmci_request()
1155 host->mrq = mrq; in s3cmci_request()
1158 dbg(host, dbg_err, "%s: no medium present\n", __func__); in s3cmci_request()
1159 host->mrq->cmd->error = -ENOMEDIUM; in s3cmci_request()
1165 static void s3cmci_set_clk(struct s3cmci_host *host, struct mmc_ios *ios) in s3cmci_set_clk() argument
1171 host->real_rate = host->clk_rate / (host->clk_div*(mci_psc+1)); in s3cmci_set_clk()
1173 if (host->real_rate <= ios->clock) in s3cmci_set_clk()
1180 host->prescaler = mci_psc; in s3cmci_set_clk()
1181 writel(host->prescaler, host->base + S3C2410_SDIPRE); in s3cmci_set_clk()
1185 host->real_rate = 0; in s3cmci_set_clk()
1190 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_set_ios() local
1195 mci_con = readl(host->base + S3C2410_SDICON); in s3cmci_set_ios()
1200 if (!host->is2440) in s3cmci_set_ios()
1206 if (host->is2440) in s3cmci_set_ios()
1211 if (host->pdata->set_power) in s3cmci_set_ios()
1212 host->pdata->set_power(ios->power_mode, ios->vdd); in s3cmci_set_ios()
1214 s3cmci_set_clk(host, ios); in s3cmci_set_ios()
1222 writel(mci_con, host->base + S3C2410_SDICON); in s3cmci_set_ios()
1226 dbg(host, dbg_conf, "running at %lukHz (requested: %ukHz).\n", in s3cmci_set_ios()
1227 host->real_rate/1000, ios->clock/1000); in s3cmci_set_ios()
1229 dbg(host, dbg_conf, "powered down.\n"); in s3cmci_set_ios()
1232 host->bus_width = ios->bus_width; in s3cmci_set_ios()
1235 static void s3cmci_reset(struct s3cmci_host *host) in s3cmci_reset() argument
1237 u32 con = readl(host->base + S3C2410_SDICON); in s3cmci_reset()
1240 writel(con, host->base + S3C2410_SDICON); in s3cmci_reset()
1245 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_enable_sdio_irq() local
1251 con = readl(host->base + S3C2410_SDICON); in s3cmci_enable_sdio_irq()
1252 host->sdio_irqen = enable; in s3cmci_enable_sdio_irq()
1254 if (enable == host->sdio_irqen) in s3cmci_enable_sdio_irq()
1259 enable_imask(host, S3C2410_SDIIMSK_SDIOIRQ); in s3cmci_enable_sdio_irq()
1261 if (!host->irq_state && !host->irq_disabled) { in s3cmci_enable_sdio_irq()
1262 host->irq_state = true; in s3cmci_enable_sdio_irq()
1263 enable_irq(host->irq); in s3cmci_enable_sdio_irq()
1266 disable_imask(host, S3C2410_SDIIMSK_SDIOIRQ); in s3cmci_enable_sdio_irq()
1269 if (!host->irq_enabled && host->irq_state) { in s3cmci_enable_sdio_irq()
1270 disable_irq_nosync(host->irq); in s3cmci_enable_sdio_irq()
1271 host->irq_state = false; in s3cmci_enable_sdio_irq()
1275 writel(con, host->base + S3C2410_SDICON); in s3cmci_enable_sdio_irq()
1280 s3cmci_check_sdio_irq(host); in s3cmci_enable_sdio_irq()
1296 struct s3cmci_host *host; in s3cmci_cpufreq_transition() local
1301 host = container_of(nb, struct s3cmci_host, freq_transition); in s3cmci_cpufreq_transition()
1302 newclk = clk_get_rate(host->clk); in s3cmci_cpufreq_transition()
1303 mmc = host->mmc; in s3cmci_cpufreq_transition()
1305 if ((val == CPUFREQ_PRECHANGE && newclk > host->clk_rate) || in s3cmci_cpufreq_transition()
1306 (val == CPUFREQ_POSTCHANGE && newclk < host->clk_rate)) { in s3cmci_cpufreq_transition()
1309 host->clk_rate = newclk; in s3cmci_cpufreq_transition()
1313 s3cmci_set_clk(host, &mmc->ios); in s3cmci_cpufreq_transition()
1321 static inline int s3cmci_cpufreq_register(struct s3cmci_host *host) in s3cmci_cpufreq_register() argument
1323 host->freq_transition.notifier_call = s3cmci_cpufreq_transition; in s3cmci_cpufreq_register()
1325 return cpufreq_register_notifier(&host->freq_transition, in s3cmci_cpufreq_register()
1329 static inline void s3cmci_cpufreq_deregister(struct s3cmci_host *host) in s3cmci_cpufreq_deregister() argument
1331 cpufreq_unregister_notifier(&host->freq_transition, in s3cmci_cpufreq_deregister()
1336 static inline int s3cmci_cpufreq_register(struct s3cmci_host *host) in s3cmci_cpufreq_register() argument
1341 static inline void s3cmci_cpufreq_deregister(struct s3cmci_host *host) in s3cmci_cpufreq_deregister() argument
1351 struct s3cmci_host *host = seq->private; in s3cmci_state_show() local
1353 seq_printf(seq, "Register base = 0x%p\n", host->base); in s3cmci_state_show()
1354 seq_printf(seq, "Clock rate = %ld\n", host->clk_rate); in s3cmci_state_show()
1355 seq_printf(seq, "Prescale = %d\n", host->prescaler); in s3cmci_state_show()
1356 seq_printf(seq, "is2440 = %d\n", host->is2440); in s3cmci_state_show()
1357 seq_printf(seq, "IRQ = %d\n", host->irq); in s3cmci_state_show()
1358 seq_printf(seq, "IRQ enabled = %d\n", host->irq_enabled); in s3cmci_state_show()
1359 seq_printf(seq, "IRQ disabled = %d\n", host->irq_disabled); in s3cmci_state_show()
1360 seq_printf(seq, "IRQ state = %d\n", host->irq_state); in s3cmci_state_show()
1361 seq_printf(seq, "CD IRQ = %d\n", host->irq_cd); in s3cmci_state_show()
1362 seq_printf(seq, "Do DMA = %d\n", s3cmci_host_usedma(host)); in s3cmci_state_show()
1363 seq_printf(seq, "SDIIMSK at %d\n", host->sdiimsk); in s3cmci_state_show()
1364 seq_printf(seq, "SDIDATA at %d\n", host->sdidata); in s3cmci_state_show()
1399 struct s3cmci_host *host = seq->private; in s3cmci_regs_show() local
1404 readl(host->base + rptr->addr)); in s3cmci_regs_show()
1406 seq_printf(seq, "SDIIMSK\t=0x%08x\n", readl(host->base + host->sdiimsk)); in s3cmci_regs_show()
1413 static void s3cmci_debugfs_attach(struct s3cmci_host *host) in s3cmci_debugfs_attach() argument
1415 struct device *dev = &host->pdev->dev; in s3cmci_debugfs_attach()
1419 host->debug_root = root; in s3cmci_debugfs_attach()
1421 debugfs_create_file("state", 0444, root, host, &s3cmci_state_fops); in s3cmci_debugfs_attach()
1422 debugfs_create_file("regs", 0444, root, host, &s3cmci_regs_fops); in s3cmci_debugfs_attach()
1425 static void s3cmci_debugfs_remove(struct s3cmci_host *host) in s3cmci_debugfs_remove() argument
1427 debugfs_remove_recursive(host->debug_root); in s3cmci_debugfs_remove()
1431 static inline void s3cmci_debugfs_attach(struct s3cmci_host *host) { } in s3cmci_debugfs_attach() argument
1432 static inline void s3cmci_debugfs_remove(struct s3cmci_host *host) { } in s3cmci_debugfs_remove() argument
1436 static int s3cmci_probe_pdata(struct s3cmci_host *host) in s3cmci_probe_pdata() argument
1438 struct platform_device *pdev = host->pdev; in s3cmci_probe_pdata()
1439 struct mmc_host *mmc = host->mmc; in s3cmci_probe_pdata()
1443 host->is2440 = platform_get_device_id(pdev)->driver_data; in s3cmci_probe_pdata()
1476 ret = mmc_gpiod_request_ro(host->mmc, "wp", 0, 0); in s3cmci_probe_pdata()
1486 static int s3cmci_probe_dt(struct s3cmci_host *host) in s3cmci_probe_dt() argument
1488 struct platform_device *pdev = host->pdev; in s3cmci_probe_dt()
1490 struct mmc_host *mmc = host->mmc; in s3cmci_probe_dt()
1493 host->is2440 = (long) of_device_get_match_data(&pdev->dev); in s3cmci_probe_dt()
1510 struct s3cmci_host *host; in s3cmci_probe() local
1520 host = mmc_priv(mmc); in s3cmci_probe()
1521 host->mmc = mmc; in s3cmci_probe()
1522 host->pdev = pdev; in s3cmci_probe()
1525 ret = s3cmci_probe_dt(host); in s3cmci_probe()
1527 ret = s3cmci_probe_pdata(host); in s3cmci_probe()
1532 host->pdata = pdev->dev.platform_data; in s3cmci_probe()
1534 spin_lock_init(&host->complete_lock); in s3cmci_probe()
1535 tasklet_setup(&host->pio_tasklet, pio_tasklet); in s3cmci_probe()
1537 if (host->is2440) { in s3cmci_probe()
1538 host->sdiimsk = S3C2440_SDIIMSK; in s3cmci_probe()
1539 host->sdidata = S3C2440_SDIDATA; in s3cmci_probe()
1540 host->clk_div = 1; in s3cmci_probe()
1542 host->sdiimsk = S3C2410_SDIIMSK; in s3cmci_probe()
1543 host->sdidata = S3C2410_SDIDATA; in s3cmci_probe()
1544 host->clk_div = 2; in s3cmci_probe()
1547 host->complete_what = COMPLETION_NONE; in s3cmci_probe()
1548 host->pio_active = XFER_NONE; in s3cmci_probe()
1550 host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); in s3cmci_probe()
1551 if (!host->mem) { in s3cmci_probe()
1559 host->mem = request_mem_region(host->mem->start, in s3cmci_probe()
1560 resource_size(host->mem), pdev->name); in s3cmci_probe()
1562 if (!host->mem) { in s3cmci_probe()
1568 host->base = ioremap(host->mem->start, resource_size(host->mem)); in s3cmci_probe()
1569 if (!host->base) { in s3cmci_probe()
1575 host->irq = platform_get_irq(pdev, 0); in s3cmci_probe()
1576 if (host->irq <= 0) { in s3cmci_probe()
1581 if (request_irq(host->irq, s3cmci_irq, IRQF_NO_AUTOEN, DRIVER_NAME, host)) { in s3cmci_probe()
1587 host->irq_state = false; in s3cmci_probe()
1591 if (s3cmci_host_usedma(host)) { in s3cmci_probe()
1592 host->dma = dma_request_chan(&pdev->dev, "rx-tx"); in s3cmci_probe()
1593 ret = PTR_ERR_OR_ZERO(host->dma); in s3cmci_probe()
1600 host->clk = clk_get(&pdev->dev, "sdi"); in s3cmci_probe()
1601 if (IS_ERR(host->clk)) { in s3cmci_probe()
1603 ret = PTR_ERR(host->clk); in s3cmci_probe()
1604 host->clk = NULL; in s3cmci_probe()
1608 ret = clk_prepare_enable(host->clk); in s3cmci_probe()
1614 host->clk_rate = clk_get_rate(host->clk); in s3cmci_probe()
1623 mmc->f_min = host->clk_rate / (host->clk_div * 256); in s3cmci_probe()
1624 mmc->f_max = host->clk_rate / host->clk_div; in s3cmci_probe()
1626 if (host->pdata->ocr_avail) in s3cmci_probe()
1627 mmc->ocr_avail = host->pdata->ocr_avail; in s3cmci_probe()
1636 dbg(host, dbg_debug, in s3cmci_probe()
1638 (host->is2440?"2440":""), in s3cmci_probe()
1639 host->base, host->irq, host->irq_cd, host->dma); in s3cmci_probe()
1641 ret = s3cmci_cpufreq_register(host); in s3cmci_probe()
1653 s3cmci_debugfs_attach(host); in s3cmci_probe()
1657 s3cmci_host_usedma(host) ? "dma" : "pio", in s3cmci_probe()
1663 s3cmci_cpufreq_deregister(host); in s3cmci_probe()
1666 clk_disable_unprepare(host->clk); in s3cmci_probe()
1669 clk_put(host->clk); in s3cmci_probe()
1672 if (s3cmci_host_usedma(host)) in s3cmci_probe()
1673 dma_release_channel(host->dma); in s3cmci_probe()
1676 free_irq(host->irq, host); in s3cmci_probe()
1679 iounmap(host->base); in s3cmci_probe()
1682 release_mem_region(host->mem->start, resource_size(host->mem)); in s3cmci_probe()
1694 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_shutdown() local
1696 if (host->irq_cd >= 0) in s3cmci_shutdown()
1697 free_irq(host->irq_cd, host); in s3cmci_shutdown()
1699 s3cmci_debugfs_remove(host); in s3cmci_shutdown()
1700 s3cmci_cpufreq_deregister(host); in s3cmci_shutdown()
1702 clk_disable_unprepare(host->clk); in s3cmci_shutdown()
1708 struct s3cmci_host *host = mmc_priv(mmc); in s3cmci_remove() local
1712 clk_put(host->clk); in s3cmci_remove()
1714 tasklet_disable(&host->pio_tasklet); in s3cmci_remove()
1716 if (s3cmci_host_usedma(host)) in s3cmci_remove()
1717 dma_release_channel(host->dma); in s3cmci_remove()
1719 free_irq(host->irq, host); in s3cmci_remove()
1721 iounmap(host->base); in s3cmci_remove()
1722 release_mem_region(host->mem->start, resource_size(host->mem)); in s3cmci_remove()