12 #include <linux/module.h>
26 #include <asm/sizes.h>
27 #include <asm/unaligned.h>
32 #define DRIVER_NAME "mvsdio"
60 #define mvsd_write(offs, val) writel(val, iobase + (offs))
61 #define mvsd_read(offs) readl(iobase + (offs))
80 unsigned int hw_state,
count = 0;
88 }
while (!(hw_state & (1 << 13)));
89 dev_dbg(host->
dev,
"*** wait for FIFO_EMPTY bit "
90 "(hw=0x%04x, count=%d, jiffies=%ld)\n",
91 hw_state, count,
jiffies - (t - HZ));
97 tmout_index = fls(tmout - 1) - 12;
103 dev_dbg(host->
dev,
"data %s at 0x%08x: blocks=%d blksz=%d tmout=%u (%d)\n",
114 if (nodma || (data->
blksz | data->
sg->offset) & 3) {
122 pr_debug(
"%s: fallback to PIO for data "
145 u32 cmdreg = 0, xfer = 0,
intr = 0;
151 dev_dbg(host->
dev,
"cmd %d (hw state 0x%04x)\n",
185 pio = mvsd_setup_data(host, data);
240 spin_unlock_irqrestore(&host->
lock, flags);
250 for (i = 0; i < 8; i++)
252 cmd->
resp[0] = ((response[0] & 0x03ff) << 22) |
253 ((response[1] & 0xffff) << 6) |
254 ((response[2] & 0xfc00) >> 10);
255 cmd->
resp[1] = ((response[2] & 0x03ff) << 22) |
256 ((response[3] & 0xffff) << 6) |
257 ((response[4] & 0xfc00) >> 10);
258 cmd->
resp[2] = ((response[4] & 0x03ff) << 22) |
259 ((response[5] & 0xffff) << 6) |
260 ((response[6] & 0xfc00) >> 10);
261 cmd->
resp[3] = ((response[6] & 0x03ff) << 22) |
262 ((response[7] & 0x3fff) << 8);
264 unsigned int response[3],
i;
265 for (i = 0; i < 3; i++)
267 cmd->
resp[0] = ((response[2] & 0x003f) << (8 - 8)) |
268 ((response[1] & 0xffff) << (14 - 8)) |
269 ((response[0] & 0x03ff) << (30 - 8));
270 cmd->
resp[1] = ((response[0] & 0xfc00) >> 10);
311 dev_dbg(host->
dev,
"data done: blocks_left=%d, bytes_left=%d\n",
321 unsigned int response[3],
i;
322 for (i = 0; i < 3; i++)
324 data->
stop->resp[0] = ((response[2] & 0x003f) << (8 - 8)) |
325 ((response[1] & 0xffff) << (14 - 8)) |
326 ((response[0] & 0x03ff) << (30 - 8));
327 data->
stop->resp[1] = ((response[0] & 0xfc00) >> 10);
328 data->
stop->resp[2] = 0;
329 data->
stop->resp[3] = 0;
333 dev_dbg(host->
dev,
"c12err 0x%04x\n", err_cmd12);
340 err_status &= ~MVSD_ERR_AUTOCMD12;
351 u32 intr_status, intr_done_mask;
355 dev_dbg(host->
dev,
"intr 0x%04x intr_en 0x%04x hw_state 0x%04x\n",
359 spin_lock(&host->
lock);
385 if (s && s < 4 && (intr_status & MVSD_NOR_RX_READY)) {
389 memcpy(p, ((
void *)&val) + 4 - s, s);
397 }
else if (host->
intr_en & MVSD_NOR_RX_FIFO_8W) {
398 host->
intr_en &= ~MVSD_NOR_RX_FIFO_8W;
403 dev_dbg(host->
dev,
"pio %d intr 0x%04x hw_state 0x%04x\n",
426 if (s && (intr_status & MVSD_NOR_TX_AVAIL)) {
428 memcpy(((
void *)&val) + 4 - s, p, s);
440 dev_dbg(host->
dev,
"pio %d intr 0x%04x hw_state 0x%04x\n",
451 if (intr_status & host->
intr_en & ~intr_done_mask) {
463 spin_unlock(&host->
lock);
469 dev_dbg(host->
dev,
"err 0x%04x\n", err_status);
472 err_status = mvsd_finish_cmd(host, cmd, err_status);
474 err_status = mvsd_finish_data(host, mrq->
data, err_status);
476 pr_err(
"%s: unhandled error status %#04x\n",
484 spin_unlock(&host->
lock);
487 mmc_signal_sdio_irq(host->
mmc);
494 pr_err(
"%s: unhandled interrupt status=0x%04x en=0x%04x "
500 static void mvsd_timeout_timer(
unsigned long data)
510 pr_err(
"%s: Timeout waiting for hardware interrupt.\n",
512 pr_err(
"%s: hw_state=0x%04x, intr_status=0x%04x "
531 mvsd_finish_cmd(host, mrq->
cmd, 0);
534 mvsd_finish_data(host, mrq->
data, 0);
537 spin_unlock_irqrestore(&host->
lock, flags);
543 static irqreturn_t mvsd_card_detect_irq(
int irq,
void *dev)
550 static void mvsd_enable_sdio_irq(
struct mmc_host *mmc,
int enable)
562 host->
intr_en &= ~MVSD_NOR_CARD_INT;
566 spin_unlock_irqrestore(&host->
lock, flags);
569 static int mvsd_get_ro(
struct mmc_host *mmc)
583 static void mvsd_power_up(
struct mvsd_host *host)
597 static void mvsd_power_down(
struct mvsd_host *host)
620 if (ios->
clock == 0) {
632 dev_dbg(host->
dev,
"clock=%d (%d), div=0x%04x\n",
663 host->
ctrl = ctrl_reg;
665 dev_dbg(host->
dev,
"ctrl 0x%04x: %s %s %s\n", ctrl_reg,
667 "push-pull" :
"open-drain",
669 "4bit-width" :
"1bit-width",
674 mvsd_power_down(host);
678 .request = mvsd_request,
679 .get_ro = mvsd_get_ro,
680 .set_ios = mvsd_set_ios,
681 .enable_sdio_irq = mvsd_enable_sdio_irq,
685 mv_conf_mbus_windows(
struct mvsd_host *host,
691 for (i = 0; i < 4; i++) {
696 for (i = 0; i < dram->
num_cs; i++) {
697 const struct mbus_dram_window *
cs = dram->
cs +
i;
698 writel(((cs->size - 1) & 0xffff0000) |
699 (cs->mbus_attr << 8) |
717 mvsd_data = pdev->
dev.platform_data;
718 if (!r || irq < 0 || !mvsd_data)
731 host = mmc_priv(mmc);
737 mmc->
ops = &mvsd_ops;
744 mmc->
f_max = maxfreq;
764 mv_conf_mbus_windows(host, dram);
766 mvsd_power_down(host);
778 if (!IS_ERR(host->
clk)) {
779 clk_prepare_enable(host->
clk);
812 platform_set_drvdata(pdev, mmc);
820 printk(
"using GPIO %d for card detection\n",
823 printk(
"lacking card detect (fall back to polling)\n");
842 if (!IS_ERR_OR_NULL(host->
clk)) {
843 clk_disable_unprepare(host->
clk);
853 struct mmc_host *mmc = platform_get_drvdata(pdev);
867 mvsd_power_down(host);
871 if (!IS_ERR(host->
clk)) {
872 clk_disable_unprepare(host->
clk);
877 platform_set_drvdata(pdev,
NULL);
884 struct mmc_host *mmc = platform_get_drvdata(dev);
895 struct mmc_host *mmc = platform_get_drvdata(dev);
904 #define mvsd_suspend NULL
905 #define mvsd_resume NULL
917 static int __init mvsd_init(
void)
922 static void __exit mvsd_exit(
void)