Lines Matching defs:host

3  *  linux/drivers/mmc/host/pxa.c - PXA MMCI driver
26 #include <linux/mmc/host.h>
77 static int pxamci_init_ocr(struct pxamci_host *host)
79 struct mmc_host *mmc = host->mmc;
88 mmc->ocr_avail = host->pdata ?
89 host->pdata->ocr_mask :
96 static inline int pxamci_set_power(struct pxamci_host *host,
100 struct mmc_host *mmc = host->mmc;
106 if (host->power) {
107 bool on = !!((1 << vdd) & host->pdata->ocr_mask);
108 gpiod_set_value(host->power, on);
111 if (host->pdata && host->pdata->setpower)
112 return host->pdata->setpower(mmc_dev(host->mmc), vdd);
117 static void pxamci_stop_clock(struct pxamci_host *host)
119 if (readl(host->base + MMC_STAT) & STAT_CLK_EN) {
123 writel(STOP_CLOCK, host->base + MMC_STRPCL);
126 v = readl(host->base + MMC_STAT);
133 dev_err(mmc_dev(host->mmc), "unable to stop clock\n");
137 static void pxamci_enable_irq(struct pxamci_host *host, unsigned int mask)
141 spin_lock_irqsave(&host->lock, flags);
142 host->imask &= ~mask;
143 writel(host->imask, host->base + MMC_I_MASK);
144 spin_unlock_irqrestore(&host->lock, flags);
147 static void pxamci_disable_irq(struct pxamci_host *host, unsigned int mask)
151 spin_lock_irqsave(&host->lock, flags);
152 host->imask |= mask;
153 writel(host->imask, host->base + MMC_I_MASK);
154 spin_unlock_irqrestore(&host->lock, flags);
159 static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
170 host->data = data;
172 writel(nob, host->base + MMC_NOB);
173 writel(data->blksz, host->base + MMC_BLKLEN);
175 clks = (unsigned long long)data->timeout_ns * host->clkrate;
177 timeout = (unsigned int)clks + (data->timeout_clks << host->clkrt);
178 writel((timeout + 255) / 256, host->base + MMC_RDTO);
183 config.src_addr = host->res->start + MMC_RXFIFO;
184 config.dst_addr = host->res->start + MMC_TXFIFO;
189 host->dma_dir = DMA_FROM_DEVICE;
191 chan = host->dma_chan_rx;
193 host->dma_dir = DMA_TO_DEVICE;
195 chan = host->dma_chan_tx;
202 dev_err(mmc_dev(host->mmc), "dma slave config failed\n");
206 host->dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len,
207 host->dma_dir);
209 tx = dmaengine_prep_slave_sg(chan, data->sg, host->dma_len, direction,
212 dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n");
218 tx->callback_param = host;
221 host->dma_cookie = dmaengine_submit(tx);
233 static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd, unsigned int cmdat)
235 WARN_ON(host->cmd != NULL);
236 host->cmd = cmd;
256 writel(cmd->opcode, host->base + MMC_CMD);
257 writel(cmd->arg >> 16, host->base + MMC_ARGH);
258 writel(cmd->arg & 0xffff, host->base + MMC_ARGL);
259 writel(cmdat, host->base + MMC_CMDAT);
260 writel(host->clkrt, host->base + MMC_CLKRT);
262 writel(START_CLOCK, host->base + MMC_STRPCL);
264 pxamci_enable_irq(host, END_CMD_RES);
267 static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq)
269 host->mrq = NULL;
270 host->cmd = NULL;
271 host->data = NULL;
272 mmc_request_done(host->mmc, mrq);
275 static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
277 struct mmc_command *cmd = host->cmd;
284 host->cmd = NULL;
290 v = readl(host->base + MMC_RES) & 0xffff;
292 u32 w1 = readl(host->base + MMC_RES) & 0xffff;
293 u32 w2 = readl(host->base + MMC_RES) & 0xffff;
314 pxamci_disable_irq(host, END_CMD_RES);
315 if (host->data && !cmd->error) {
316 pxamci_enable_irq(host, DATA_TRAN_DONE);
321 if (cpu_is_pxa27x() && host->data->flags & MMC_DATA_WRITE)
322 dma_async_issue_pending(host->dma_chan_tx);
324 pxamci_finish_request(host, host->mrq);
330 static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
332 struct mmc_data *data = host->data;
339 chan = host->dma_chan_rx;
341 chan = host->dma_chan_tx;
343 data->sg, data->sg_len, host->dma_dir);
361 pxamci_disable_irq(host, DATA_TRAN_DONE);
363 host->data = NULL;
364 if (host->mrq->stop) {
365 pxamci_stop_clock(host);
366 pxamci_start_cmd(host, host->mrq->stop, host->cmdat);
368 pxamci_finish_request(host, host->mrq);
376 struct pxamci_host *host = devid;
380 ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
383 unsigned stat = readl(host->base + MMC_STAT);
388 handled |= pxamci_cmd_done(host, stat);
390 handled |= pxamci_data_done(host, stat);
392 mmc_signal_sdio_irq(host->mmc);
402 struct pxamci_host *host = mmc_priv(mmc);
405 WARN_ON(host->mrq != NULL);
407 host->mrq = mrq;
409 pxamci_stop_clock(host);
411 cmdat = host->cmdat;
412 host->cmdat &= ~CMDAT_INIT;
415 pxamci_setup_data(host, mrq->data);
423 pxamci_start_cmd(host, mrq->cmd, cmdat);
428 struct pxamci_host *host = mmc_priv(mmc);
430 if (host->use_ro_gpio)
432 if (host->pdata && host->pdata->get_ro)
433 return !!host->pdata->get_ro(mmc_dev(mmc));
443 struct pxamci_host *host = mmc_priv(mmc);
446 unsigned long rate = host->clkrate;
449 if (host->clkrt == CLKRT_OFF)
450 clk_prepare_enable(host->clk);
454 host->clkrt = 7;
467 host->clkrt = fls(clk) - 1;
474 pxamci_stop_clock(host);
475 if (host->clkrt != CLKRT_OFF) {
476 host->clkrt = CLKRT_OFF;
477 clk_disable_unprepare(host->clk);
481 if (host->power_mode != ios->power_mode) {
484 host->power_mode = ios->power_mode;
486 ret = pxamci_set_power(host, ios->power_mode, ios->vdd);
499 host->cmdat |= CMDAT_INIT;
503 host->cmdat |= CMDAT_SD_4DAT;
505 host->cmdat &= ~CMDAT_SD_4DAT;
508 host->clkrt, host->cmdat);
511 static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
513 struct pxamci_host *pxa_host = mmc_priv(host);
531 struct pxamci_host *host = param;
537 spin_lock_irqsave(&host->lock, flags);
539 if (!host->data)
542 if (host->data->flags & MMC_DATA_READ)
543 chan = host->dma_chan_rx;
545 chan = host->dma_chan_tx;
547 status = dmaengine_tx_status(chan, host->dma_cookie, &state);
550 writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
552 pr_err("%s: DMA error on %s channel\n", mmc_hostname(host->mmc),
553 host->data->flags & MMC_DATA_READ ? "rx" : "tx");
554 host->data->error = -EIO;
555 pxamci_data_done(host, 0);
559 spin_unlock_irqrestore(&host->lock, flags);
564 struct pxamci_host *host = mmc_priv(devid);
566 mmc_detect_change(devid, msecs_to_jiffies(host->detect_delay_ms));
582 struct pxamci_host *host = mmc_priv(mmc);
591 host->detect_delay_ms = tmp;
610 struct pxamci_host *host = NULL;
653 host = mmc_priv(mmc);
654 host->mmc = mmc;
655 host->pdata = pdev->dev.platform_data;
656 host->clkrt = CLKRT_OFF;
658 host->clk = devm_clk_get(dev, NULL);
659 if (IS_ERR(host->clk)) {
660 ret = PTR_ERR(host->clk);
661 host->clk = NULL;
665 host->clkrate = clk_get_rate(host->clk);
670 mmc->f_min = (host->clkrate + 63) / 64;
671 mmc->f_max = (mmc_has_26MHz()) ? 26000000 : host->clkrate;
673 ret = pxamci_init_ocr(host);
678 host->cmdat = 0;
681 host->cmdat |= CMDAT_SDIO_INT_EN;
687 spin_lock_init(&host->lock);
688 host->res = r;
689 host->imask = MMC_I_MASK_ALL;
691 host->base = devm_ioremap_resource(dev, r);
692 if (IS_ERR(host->base)) {
693 ret = PTR_ERR(host->base);
698 * Ensure that the host controller is shut down, and setup
701 pxamci_stop_clock(host);
702 writel(0, host->base + MMC_SPI);
703 writel(64, host->base + MMC_RESTO);
704 writel(host->imask, host->base + MMC_I_MASK);
707 DRIVER_NAME, host);
713 host->dma_chan_rx = dma_request_chan(dev, "rx");
714 if (IS_ERR(host->dma_chan_rx)) {
716 ret = PTR_ERR(host->dma_chan_rx);
717 host->dma_chan_rx = NULL;
721 host->dma_chan_tx = dma_request_chan(dev, "tx");
722 if (IS_ERR(host->dma_chan_tx)) {
724 ret = PTR_ERR(host->dma_chan_tx);
725 host->dma_chan_tx = NULL;
729 if (host->pdata) {
730 host->detect_delay_ms = host->pdata->detect_delay_ms;
732 host->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
733 if (IS_ERR(host->power)) {
734 ret = PTR_ERR(host->power);
746 if (!host->pdata->gpio_card_ro_invert)
755 host->use_ro_gpio = true;
757 if (host->pdata->init)
758 host->pdata->init(dev, pxamci_detect_irq, mmc);
760 if (host->power && host->pdata->setpower)
762 if (host->use_ro_gpio && host->pdata->get_ro)
768 if (host->pdata && host->pdata->exit)
769 host->pdata->exit(dev, mmc);
776 if (host) {
777 if (host->dma_chan_rx)
778 dma_release_channel(host->dma_chan_rx);
779 if (host->dma_chan_tx)
780 dma_release_channel(host->dma_chan_tx);
792 struct pxamci_host *host = mmc_priv(mmc);
796 if (host->pdata && host->pdata->exit)
797 host->pdata->exit(&pdev->dev, mmc);
799 pxamci_stop_clock(host);
802 host->base + MMC_I_MASK);
804 dmaengine_terminate_all(host->dma_chan_rx);
805 dmaengine_terminate_all(host->dma_chan_tx);
806 dma_release_channel(host->dma_chan_rx);
807 dma_release_channel(host->dma_chan_tx);