Lines Matching full:host
2 * MOXA ART MMC host driver.
25 #include <linux/mmc/host.h>
151 static inline void moxart_init_sg(struct moxart_host *host, in moxart_init_sg() argument
154 host->cur_sg = data->sg; in moxart_init_sg()
155 host->num_sg = data->sg_len; in moxart_init_sg()
156 host->data_remain = host->cur_sg->length; in moxart_init_sg()
158 if (host->data_remain > host->data_len) in moxart_init_sg()
159 host->data_remain = host->data_len; in moxart_init_sg()
162 static inline int moxart_next_sg(struct moxart_host *host) in moxart_next_sg() argument
165 struct mmc_data *data = host->mrq->cmd->data; in moxart_next_sg()
167 host->cur_sg++; in moxart_next_sg()
168 host->num_sg--; in moxart_next_sg()
170 if (host->num_sg > 0) { in moxart_next_sg()
171 host->data_remain = host->cur_sg->length; in moxart_next_sg()
172 remain = host->data_len - data->bytes_xfered; in moxart_next_sg()
173 if (remain > 0 && remain < host->data_remain) in moxart_next_sg()
174 host->data_remain = remain; in moxart_next_sg()
177 return host->num_sg; in moxart_next_sg()
180 static int moxart_wait_for_status(struct moxart_host *host, in moxart_wait_for_status() argument
187 *status = readl(host->base + REG_STATUS); in moxart_wait_for_status()
192 writel(*status & mask, host->base + REG_CLEAR); in moxart_wait_for_status()
198 dev_err(mmc_dev(host->mmc), "timed out waiting for status\n"); in moxart_wait_for_status()
204 static void moxart_send_command(struct moxart_host *host, in moxart_send_command() argument
210 RSP_CRC_FAIL | CMD_SENT, host->base + REG_CLEAR); in moxart_send_command()
211 writel(cmd->arg, host->base + REG_ARGUMENT); in moxart_send_command()
225 writel(cmdctrl | CMD_EN, host->base + REG_COMMAND); in moxart_send_command()
227 if (moxart_wait_for_status(host, MASK_RSP, &status) == -ETIMEDOUT) in moxart_send_command()
240 cmd->resp[3] = readl(host->base + REG_RESPONSE0); in moxart_send_command()
241 cmd->resp[2] = readl(host->base + REG_RESPONSE1); in moxart_send_command()
242 cmd->resp[1] = readl(host->base + REG_RESPONSE2); in moxart_send_command()
243 cmd->resp[0] = readl(host->base + REG_RESPONSE3); in moxart_send_command()
245 cmd->resp[0] = readl(host->base + REG_RESPONSE0); in moxart_send_command()
252 struct moxart_host *host = param; in moxart_dma_complete() local
254 complete(&host->dma_complete); in moxart_dma_complete()
257 static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host) in moxart_transfer_dma() argument
263 if (host->data_len == data->bytes_xfered) in moxart_transfer_dma()
267 dma_chan = host->dma_chan_tx; in moxart_transfer_dma()
270 dma_chan = host->dma_chan_rx; in moxart_transfer_dma()
283 dev_err(mmc_dev(host->mmc), "dma_map_sg returned zero length\n"); in moxart_transfer_dma()
287 host->tx_desc = desc; in moxart_transfer_dma()
289 desc->callback_param = host; in moxart_transfer_dma()
294 data->bytes_xfered += host->data_remain; in moxart_transfer_dma()
296 wait_for_completion_interruptible_timeout(&host->dma_complete, in moxart_transfer_dma()
297 host->timeout); in moxart_transfer_dma()
305 static void moxart_transfer_pio(struct moxart_host *host) in moxart_transfer_pio() argument
307 struct mmc_data *data = host->mrq->cmd->data; in moxart_transfer_pio()
310 if (host->data_len == data->bytes_xfered) in moxart_transfer_pio()
313 sgp = sg_virt(host->cur_sg); in moxart_transfer_pio()
314 remain = host->data_remain; in moxart_transfer_pio()
318 if (moxart_wait_for_status(host, FIFO_URUN, &status) in moxart_transfer_pio()
321 complete(&host->pio_complete); in moxart_transfer_pio()
324 for (len = 0; len < remain && len < host->fifo_width;) { in moxart_transfer_pio()
325 iowrite32(*sgp, host->base + REG_DATA_WINDOW); in moxart_transfer_pio()
334 if (moxart_wait_for_status(host, FIFO_ORUN, &status) in moxart_transfer_pio()
337 complete(&host->pio_complete); in moxart_transfer_pio()
340 for (len = 0; len < remain && len < host->fifo_width;) { in moxart_transfer_pio()
343 *sgp = ioread32be(host->base + in moxart_transfer_pio()
346 *sgp = ioread32(host->base + in moxart_transfer_pio()
355 data->bytes_xfered += host->data_remain - remain; in moxart_transfer_pio()
356 host->data_remain = remain; in moxart_transfer_pio()
358 if (host->data_len != data->bytes_xfered) in moxart_transfer_pio()
359 moxart_next_sg(host); in moxart_transfer_pio()
361 complete(&host->pio_complete); in moxart_transfer_pio()
364 static void moxart_prepare_data(struct moxart_host *host) in moxart_prepare_data() argument
366 struct mmc_data *data = host->mrq->cmd->data; in moxart_prepare_data()
373 host->data_len = data->blocks * data->blksz; in moxart_prepare_data()
377 moxart_init_sg(host, data); in moxart_prepare_data()
384 if ((host->data_len > host->fifo_width) && host->have_dma) in moxart_prepare_data()
387 writel(DCR_DATA_FIFO_RESET, host->base + REG_DATA_CONTROL); in moxart_prepare_data()
388 writel(MASK_DATA | FIFO_URUN | FIFO_ORUN, host->base + REG_CLEAR); in moxart_prepare_data()
389 writel(host->rate, host->base + REG_DATA_TIMER); in moxart_prepare_data()
390 writel(host->data_len, host->base + REG_DATA_LENGTH); in moxart_prepare_data()
391 writel(datactrl, host->base + REG_DATA_CONTROL); in moxart_prepare_data()
396 struct moxart_host *host = mmc_priv(mmc); in moxart_request() local
400 spin_lock_irqsave(&host->lock, flags); in moxart_request()
402 init_completion(&host->dma_complete); in moxart_request()
403 init_completion(&host->pio_complete); in moxart_request()
405 host->mrq = mrq; in moxart_request()
407 if (readl(host->base + REG_STATUS) & CARD_DETECT) { in moxart_request()
412 moxart_prepare_data(host); in moxart_request()
413 moxart_send_command(host, host->mrq->cmd); in moxart_request()
416 if ((host->data_len > host->fifo_width) && host->have_dma) { in moxart_request()
418 writel(CARD_CHANGE, host->base + REG_INTERRUPT_MASK); in moxart_request()
420 spin_unlock_irqrestore(&host->lock, flags); in moxart_request()
422 moxart_transfer_dma(mrq->cmd->data, host); in moxart_request()
424 spin_lock_irqsave(&host->lock, flags); in moxart_request()
427 writel(MASK_INTR_PIO, host->base + REG_INTERRUPT_MASK); in moxart_request()
429 spin_unlock_irqrestore(&host->lock, flags); in moxart_request()
432 wait_for_completion_interruptible_timeout(&host->pio_complete, in moxart_request()
433 host->timeout); in moxart_request()
435 spin_lock_irqsave(&host->lock, flags); in moxart_request()
438 if (host->is_removed) { in moxart_request()
439 dev_err(mmc_dev(host->mmc), "card removed\n"); in moxart_request()
444 if (moxart_wait_for_status(host, MASK_DATA, &status) in moxart_request()
454 moxart_send_command(host, mrq->cmd->data->stop); in moxart_request()
458 spin_unlock_irqrestore(&host->lock, flags); in moxart_request()
459 mmc_request_done(host->mmc, mrq); in moxart_request()
464 struct moxart_host *host = (struct moxart_host *)devid; in moxart_irq() local
467 spin_lock(&host->lock); in moxart_irq()
469 status = readl(host->base + REG_STATUS); in moxart_irq()
471 host->is_removed = status & CARD_DETECT; in moxart_irq()
472 if (host->is_removed && host->have_dma) { in moxart_irq()
473 dmaengine_terminate_all(host->dma_chan_tx); in moxart_irq()
474 dmaengine_terminate_all(host->dma_chan_rx); in moxart_irq()
476 host->mrq = NULL; in moxart_irq()
477 writel(MASK_INTR_PIO, host->base + REG_CLEAR); in moxart_irq()
478 writel(CARD_CHANGE, host->base + REG_INTERRUPT_MASK); in moxart_irq()
479 mmc_detect_change(host->mmc, 0); in moxart_irq()
481 if (status & (FIFO_ORUN | FIFO_URUN) && host->mrq) in moxart_irq()
482 moxart_transfer_pio(host); in moxart_irq()
484 spin_unlock(&host->lock); in moxart_irq()
491 struct moxart_host *host = mmc_priv(mmc); in moxart_set_ios() local
496 spin_lock_irqsave(&host->lock, flags); in moxart_set_ios()
500 if (ios->clock >= host->sysclk / (2 * (div + 1))) in moxart_set_ios()
504 host->rate = host->sysclk / (2 * (div + 1)); in moxart_set_ios()
505 if (host->rate > host->sysclk) in moxart_set_ios()
507 writel(ctrl, host->base + REG_CLOCK_CONTROL); in moxart_set_ios()
511 writel(readl(host->base + REG_POWER_CONTROL) & ~SD_POWER_ON, in moxart_set_ios()
512 host->base + REG_POWER_CONTROL); in moxart_set_ios()
520 host->base + REG_POWER_CONTROL); in moxart_set_ios()
525 writel(BUS_WIDTH_4, host->base + REG_BUS_WIDTH); in moxart_set_ios()
528 writel(BUS_WIDTH_1, host->base + REG_BUS_WIDTH); in moxart_set_ios()
532 spin_unlock_irqrestore(&host->lock, flags); in moxart_set_ios()
538 struct moxart_host *host = mmc_priv(mmc); in moxart_get_ro() local
540 return !!(readl(host->base + REG_STATUS) & WRITE_PROT); in moxart_get_ro()
555 struct moxart_host *host = NULL; in moxart_probe() local
598 host = mmc_priv(mmc); in moxart_probe()
599 host->mmc = mmc; in moxart_probe()
600 host->base = reg_mmc; in moxart_probe()
601 host->reg_phys = res_mmc.start; in moxart_probe()
602 host->timeout = msecs_to_jiffies(1000); in moxart_probe()
603 host->sysclk = clk_get_rate(clk); in moxart_probe()
604 host->fifo_width = readl(host->base + REG_FEATURE) << 2; in moxart_probe()
605 host->dma_chan_tx = dma_request_chan(dev, "tx"); in moxart_probe()
606 host->dma_chan_rx = dma_request_chan(dev, "rx"); in moxart_probe()
608 spin_lock_init(&host->lock); in moxart_probe()
611 mmc->f_max = DIV_ROUND_CLOSEST(host->sysclk, 2); in moxart_probe()
612 mmc->f_min = DIV_ROUND_CLOSEST(host->sysclk, CLK_DIV_MASK * 2); in moxart_probe()
615 if (IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) { in moxart_probe()
616 if (PTR_ERR(host->dma_chan_tx) == -EPROBE_DEFER || in moxart_probe()
617 PTR_ERR(host->dma_chan_rx) == -EPROBE_DEFER) { in moxart_probe()
621 if (!IS_ERR(host->dma_chan_tx)) { in moxart_probe()
622 dma_release_channel(host->dma_chan_tx); in moxart_probe()
623 host->dma_chan_tx = NULL; in moxart_probe()
625 if (!IS_ERR(host->dma_chan_rx)) { in moxart_probe()
626 dma_release_channel(host->dma_chan_rx); in moxart_probe()
627 host->dma_chan_rx = NULL; in moxart_probe()
630 host->have_dma = false; in moxart_probe()
633 host->dma_chan_tx, host->dma_chan_rx); in moxart_probe()
634 host->have_dma = true; in moxart_probe()
642 cfg.dst_addr = host->reg_phys + REG_DATA_WINDOW; in moxart_probe()
643 dmaengine_slave_config(host->dma_chan_tx, &cfg); in moxart_probe()
646 cfg.src_addr = host->reg_phys + REG_DATA_WINDOW; in moxart_probe()
648 dmaengine_slave_config(host->dma_chan_rx, &cfg); in moxart_probe()
651 if (readl(host->base + REG_BUS_WIDTH) & BUS_WIDTH_4_SUPPORT) in moxart_probe()
654 writel(0, host->base + REG_INTERRUPT_MASK); in moxart_probe()
656 writel(CMD_SDC_RESET, host->base + REG_COMMAND); in moxart_probe()
658 if (!(readl(host->base + REG_COMMAND) & CMD_SDC_RESET)) in moxart_probe()
663 ret = devm_request_irq(dev, irq, moxart_irq, 0, "moxart-mmc", host); in moxart_probe()
670 dev_dbg(dev, "IRQ=%d, FIFO is %d bytes\n", irq, host->fifo_width); in moxart_probe()
675 if (!IS_ERR_OR_NULL(host->dma_chan_tx)) in moxart_probe()
676 dma_release_channel(host->dma_chan_tx); in moxart_probe()
677 if (!IS_ERR_OR_NULL(host->dma_chan_rx)) in moxart_probe()
678 dma_release_channel(host->dma_chan_rx); in moxart_probe()
688 struct moxart_host *host = mmc_priv(mmc); in moxart_remove() local
692 if (!IS_ERR_OR_NULL(host->dma_chan_tx)) in moxart_remove()
693 dma_release_channel(host->dma_chan_tx); in moxart_remove()
694 if (!IS_ERR_OR_NULL(host->dma_chan_rx)) in moxart_remove()
695 dma_release_channel(host->dma_chan_rx); in moxart_remove()
698 writel(0, host->base + REG_INTERRUPT_MASK); in moxart_remove()
699 writel(0, host->base + REG_POWER_CONTROL); in moxart_remove()
700 writel(readl(host->base + REG_CLOCK_CONTROL) | CLK_OFF, in moxart_remove()
701 host->base + REG_CLOCK_CONTROL); in moxart_remove()