Lines Matching +full:sr +full:- +full:idle +full:- +full:ns
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2008 Atmel Corporation
12 #include <linux/dma-mapping.h>
33 #include <linux/atmel-mci.h>
62 #define ATMCI_MR_PDCMODE BIT(15) /* PDC-oriented Mode */
71 #define ATMCI_SDCBUS_1BIT (0 << 6) /* 1-bit data bus */
72 #define ATMCI_SDCBUS_4BIT (2 << 6) /* 4-bit data bus */
73 #define ATMCI_SDCBUS_8BIT (3 << 6) /* 8-bit data bus[2] */
79 #define ATMCI_CMDR_RSPTYP_48BIT (1 << 6) /* 48-bit response */
80 #define ATMCI_CMDR_RSPTYP_136BIT (2 << 6) /* 136-bit response */
92 #define ATMCI_CMDR_BLOCK (0 << 19) /* Single-block transfer */
93 #define ATMCI_CMDR_MULTI_BLOCK (1 << 19) /* Multi-block transfer */
126 #define ATMCI_CSRCV BIT(13) /* CE-ATA Completion Signal Received */
133 #define ATMCI_RTOE BIT(20) /* Response Time-Out Error */
135 #define ATMCI_DTOE BIT(22) /* Data Time-Out Error */
136 #define ATMCI_CSTOE BIT(23) /* Completion Signal Time-out Error */
168 __raw_readl((port)->regs + reg)
170 __raw_writel((value), (port)->regs + reg)
224 * struct atmel_mci - MMC controller state shared between all slots
237 * or NULL if the controller is idle.
241 * @data_size: just data->blocks * data->blksz.
245 * @cmd_status: Snapshot of SR taken upon completion of the current
247 * @data_status: Snapshot of SR taken upon completion of the current
281 * @lock is a softirq-safe spinlock protecting @queue as well as
298 * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
300 * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
302 * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
357 * struct atmel_mci_slot - MMC slot state
363 * processed, or NULL when the slot is idle.
366 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
399 test_and_clear_bit(event, &host->pending_events)
401 set_bit(event, &host->completed_events)
403 set_bit(event, &host->pending_events)
411 struct atmel_mci_slot *slot = s->private; in atmci_req_show()
418 spin_lock_bh(&slot->host->lock); in atmci_req_show()
419 mrq = slot->mrq; in atmci_req_show()
422 cmd = mrq->cmd; in atmci_req_show()
423 data = mrq->data; in atmci_req_show()
424 stop = mrq->stop; in atmci_req_show()
429 cmd->opcode, cmd->arg, cmd->flags, in atmci_req_show()
430 cmd->resp[0], cmd->resp[1], cmd->resp[2], in atmci_req_show()
431 cmd->resp[3], cmd->error); in atmci_req_show()
434 data->bytes_xfered, data->blocks, in atmci_req_show()
435 data->blksz, data->flags, data->error); in atmci_req_show()
439 stop->opcode, stop->arg, stop->flags, in atmci_req_show()
440 stop->resp[0], stop->resp[1], stop->resp[2], in atmci_req_show()
441 stop->resp[3], stop->error); in atmci_req_show()
444 spin_unlock_bh(&slot->host->lock); in atmci_req_show()
499 struct atmel_mci *host = s->private; in atmci_regs_show()
506 return -ENOMEM; in atmci_regs_show()
508 pm_runtime_get_sync(&host->pdev->dev); in atmci_regs_show()
512 * not disabling interrupts, so IMR and SR may not be in atmci_regs_show()
515 spin_lock_bh(&host->lock); in atmci_regs_show()
516 memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE); in atmci_regs_show()
517 spin_unlock_bh(&host->lock); in atmci_regs_show()
519 pm_runtime_mark_last_busy(&host->pdev->dev); in atmci_regs_show()
520 pm_runtime_put_autosuspend(&host->pdev->dev); in atmci_regs_show()
526 if (host->caps.has_odd_clk_div) in atmci_regs_show()
540 if (host->caps.has_cstor_reg) in atmci_regs_show()
545 atmci_show_status_reg(s, "SR", buf[ATMCI_SR / 4]); in atmci_regs_show()
548 if (host->caps.has_dma_conf_reg) { in atmci_regs_show()
558 if (host->caps.has_cfg_reg) { in atmci_regs_show()
579 struct mmc_host *mmc = slot->mmc; in atmci_init_debugfs()
580 struct atmel_mci *host = slot->host; in atmci_init_debugfs()
583 root = mmc->debugfs_root; in atmci_init_debugfs()
589 debugfs_create_u32("state", S_IRUSR, root, &host->state); in atmci_init_debugfs()
591 &host->pending_events); in atmci_init_debugfs()
593 &host->completed_events); in atmci_init_debugfs()
607 struct device_node *np = pdev->dev.of_node; in atmci_of_init()
613 dev_err(&pdev->dev, "device node not found\n"); in atmci_of_init()
614 return ERR_PTR(-EINVAL); in atmci_of_init()
617 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in atmci_of_init()
619 return ERR_PTR(-ENOMEM); in atmci_of_init()
623 dev_warn(&pdev->dev, "reg property is missing for %pOF\n", in atmci_of_init()
629 dev_warn(&pdev->dev, "can't have more than %d slots\n", in atmci_of_init()
635 if (of_property_read_u32(cnp, "bus-width", in atmci_of_init()
636 &pdata->slot[slot_id].bus_width)) in atmci_of_init()
637 pdata->slot[slot_id].bus_width = 1; in atmci_of_init()
639 pdata->slot[slot_id].detect_pin = in atmci_of_init()
640 of_get_named_gpio(cnp, "cd-gpios", 0); in atmci_of_init()
642 pdata->slot[slot_id].detect_is_active_high = in atmci_of_init()
643 of_property_read_bool(cnp, "cd-inverted"); in atmci_of_init()
645 pdata->slot[slot_id].non_removable = in atmci_of_init()
646 of_property_read_bool(cnp, "non-removable"); in atmci_of_init()
648 pdata->slot[slot_id].wp_pin = in atmci_of_init()
649 of_get_named_gpio(cnp, "wp-gpios", 0); in atmci_of_init()
658 return ERR_PTR(-EINVAL); in atmci_of_init()
669 * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
670 * With version 0x600, we need to convert them as: 1 -> 0, 2 -> 1, 4 -> 2,
671 * 8 -> 3, 16 -> 4.
685 return fls(maxburst) - offset; in atmci_convert_chksize()
696 dev_dbg(&host->pdev->dev, "software timeout\n"); in atmci_timeout_timer()
698 if (host->mrq->cmd->data) { in atmci_timeout_timer()
699 host->mrq->cmd->data->error = -ETIMEDOUT; in atmci_timeout_timer()
700 host->data = NULL; in atmci_timeout_timer()
706 if (host->state == STATE_DATA_XFER) in atmci_timeout_timer()
707 host->stop_transfer(host); in atmci_timeout_timer()
709 host->mrq->cmd->error = -ETIMEDOUT; in atmci_timeout_timer()
710 host->cmd = NULL; in atmci_timeout_timer()
712 host->need_reset = 1; in atmci_timeout_timer()
713 host->state = STATE_END_REQUEST; in atmci_timeout_timer()
715 tasklet_schedule(&host->tasklet); in atmci_timeout_timer()
719 unsigned int ns) in atmci_ns_to_clocks() argument
722 * It is easier here to use us instead of ns for the timeout, in atmci_ns_to_clocks()
725 unsigned int us = DIV_ROUND_UP(ns, 1000); in atmci_ns_to_clocks()
727 /* Maximum clock frequency is host->bus_hz/2 */ in atmci_ns_to_clocks()
728 return us * (DIV_ROUND_UP(host->bus_hz, 2000000)); in atmci_ns_to_clocks()
741 timeout = atmci_ns_to_clocks(host, data->timeout_ns) in atmci_set_timeout()
742 + data->timeout_clks; in atmci_set_timeout()
746 dtocyc = (timeout + (1 << shift) - 1) >> shift; in atmci_set_timeout()
756 dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n", in atmci_set_timeout()
770 cmd->error = -EINPROGRESS; in atmci_prepare_command()
772 cmdr = ATMCI_CMDR_CMDNB(cmd->opcode); in atmci_prepare_command()
774 if (cmd->flags & MMC_RSP_PRESENT) { in atmci_prepare_command()
775 if (cmd->flags & MMC_RSP_136) in atmci_prepare_command()
788 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN) in atmci_prepare_command()
791 data = cmd->data; in atmci_prepare_command()
795 if (cmd->opcode == SD_IO_RW_EXTENDED) { in atmci_prepare_command()
798 if (data->blocks > 1) in atmci_prepare_command()
804 if (data->flags & MMC_DATA_READ) in atmci_prepare_command()
814 unsigned int timeout_ms = cmd->busy_timeout ? cmd->busy_timeout : in atmci_send_command()
817 WARN_ON(host->cmd); in atmci_send_command()
818 host->cmd = cmd; in atmci_send_command()
820 dev_vdbg(&host->pdev->dev, in atmci_send_command()
822 cmd->arg, cmd_flags); in atmci_send_command()
824 atmci_writel(host, ATMCI_ARGR, cmd->arg); in atmci_send_command()
827 mod_timer(&host->timer, jiffies + msecs_to_jiffies(timeout_ms)); in atmci_send_command()
832 dev_dbg(&host->pdev->dev, "send stop command\n"); in atmci_send_stop_cmd()
833 atmci_send_command(host, data->stop, host->stop_cmdr); in atmci_send_stop_cmd()
839 * Update host->data_size and host->sg.
860 if (!host->caps.has_rwproof) { in atmci_pdc_set_single_buf()
861 buf_size = host->buf_size; in atmci_pdc_set_single_buf()
862 atmci_writel(host, pointer_reg, host->buf_phys_addr); in atmci_pdc_set_single_buf()
864 buf_size = sg_dma_len(host->sg); in atmci_pdc_set_single_buf()
865 atmci_writel(host, pointer_reg, sg_dma_address(host->sg)); in atmci_pdc_set_single_buf()
868 if (host->data_size <= buf_size) { in atmci_pdc_set_single_buf()
869 if (host->data_size & 0x3) { in atmci_pdc_set_single_buf()
871 atmci_writel(host, counter_reg, host->data_size); in atmci_pdc_set_single_buf()
872 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCFBYTE); in atmci_pdc_set_single_buf()
874 /* Else transfer 32-bits words */ in atmci_pdc_set_single_buf()
875 atmci_writel(host, counter_reg, host->data_size / 4); in atmci_pdc_set_single_buf()
877 host->data_size = 0; in atmci_pdc_set_single_buf()
879 /* We assume the size of a page is 32-bits aligned */ in atmci_pdc_set_single_buf()
880 atmci_writel(host, counter_reg, sg_dma_len(host->sg) / 4); in atmci_pdc_set_single_buf()
881 host->data_size -= sg_dma_len(host->sg); in atmci_pdc_set_single_buf()
882 if (host->data_size) in atmci_pdc_set_single_buf()
883 host->sg = sg_next(host->sg); in atmci_pdc_set_single_buf()
895 if (host->data_size) in atmci_pdc_set_both_buf()
904 struct mmc_data *data = host->data; in atmci_pdc_cleanup()
907 dma_unmap_sg(&host->pdev->dev, in atmci_pdc_cleanup()
908 data->sg, data->sg_len, in atmci_pdc_cleanup()
919 int transfer_size = host->data->blocks * host->data->blksz; in atmci_pdc_complete()
924 if ((!host->caps.has_rwproof) in atmci_pdc_complete()
925 && (host->data->flags & MMC_DATA_READ)) { in atmci_pdc_complete()
926 if (host->caps.has_bad_data_ordering) in atmci_pdc_complete()
928 host->buffer[i] = swab32(host->buffer[i]); in atmci_pdc_complete()
929 sg_copy_from_buffer(host->data->sg, host->data->sg_len, in atmci_pdc_complete()
930 host->buffer, transfer_size); in atmci_pdc_complete()
935 dev_dbg(&host->pdev->dev, "(%s) set pending xfer complete\n", __func__); in atmci_pdc_complete()
937 tasklet_schedule(&host->tasklet); in atmci_pdc_complete()
942 struct mmc_data *data = host->data; in atmci_dma_cleanup()
945 dma_unmap_sg(host->dma.chan->device->dev, in atmci_dma_cleanup()
946 data->sg, data->sg_len, in atmci_dma_cleanup()
956 struct mmc_data *data = host->data; in atmci_dma_complete()
958 dev_vdbg(&host->pdev->dev, "DMA complete\n"); in atmci_dma_complete()
960 if (host->caps.has_dma_conf_reg) in atmci_dma_complete()
971 dev_dbg(&host->pdev->dev, in atmci_dma_complete()
974 tasklet_schedule(&host->tasklet); in atmci_dma_complete()
1008 data->error = -EINPROGRESS; in atmci_prepare_data()
1010 host->sg = data->sg; in atmci_prepare_data()
1011 host->sg_len = data->sg_len; in atmci_prepare_data()
1012 host->data = data; in atmci_prepare_data()
1013 host->data_chan = NULL; in atmci_prepare_data()
1024 if (data->blocks * data->blksz < 12 in atmci_prepare_data()
1025 || (data->blocks * data->blksz) & 3) in atmci_prepare_data()
1026 host->need_reset = true; in atmci_prepare_data()
1028 host->pio_offset = 0; in atmci_prepare_data()
1029 if (data->flags & MMC_DATA_READ) in atmci_prepare_data()
1049 data->error = -EINPROGRESS; in atmci_prepare_data_pdc()
1051 host->data = data; in atmci_prepare_data_pdc()
1052 host->sg = data->sg; in atmci_prepare_data_pdc()
1056 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCMODE); in atmci_prepare_data_pdc()
1058 if (data->flags & MMC_DATA_READ) in atmci_prepare_data_pdc()
1066 tmp |= ATMCI_BLKLEN(data->blksz); in atmci_prepare_data_pdc()
1070 host->data_size = data->blocks * data->blksz; in atmci_prepare_data_pdc()
1071 dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, in atmci_prepare_data_pdc()
1074 if ((!host->caps.has_rwproof) in atmci_prepare_data_pdc()
1075 && (host->data->flags & MMC_DATA_WRITE)) { in atmci_prepare_data_pdc()
1076 sg_copy_to_buffer(host->data->sg, host->data->sg_len, in atmci_prepare_data_pdc()
1077 host->buffer, host->data_size); in atmci_prepare_data_pdc()
1078 if (host->caps.has_bad_data_ordering) in atmci_prepare_data_pdc()
1079 for (i = 0; i < host->data_size; i++) in atmci_prepare_data_pdc()
1080 host->buffer[i] = swab32(host->buffer[i]); in atmci_prepare_data_pdc()
1083 if (host->data_size) in atmci_prepare_data_pdc()
1084 atmci_pdc_set_both_buf(host, data->flags & MMC_DATA_READ ? in atmci_prepare_data_pdc()
1101 data->error = -EINPROGRESS; in atmci_prepare_data_dma()
1103 WARN_ON(host->data); in atmci_prepare_data_dma()
1104 host->sg = NULL; in atmci_prepare_data_dma()
1105 host->data = data; in atmci_prepare_data_dma()
1111 * non-word-aligned buffers or lengths. Also, we don't bother in atmci_prepare_data_dma()
1114 if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD) in atmci_prepare_data_dma()
1116 if (data->blksz & 3) in atmci_prepare_data_dma()
1119 for_each_sg(data->sg, sg, data->sg_len, i) { in atmci_prepare_data_dma()
1120 if (sg->offset & 3 || sg->length & 3) in atmci_prepare_data_dma()
1125 chan = host->dma.chan; in atmci_prepare_data_dma()
1127 host->data_chan = chan; in atmci_prepare_data_dma()
1130 return -ENODEV; in atmci_prepare_data_dma()
1132 if (data->flags & MMC_DATA_READ) { in atmci_prepare_data_dma()
1133 host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; in atmci_prepare_data_dma()
1135 host->dma_conf.src_maxburst); in atmci_prepare_data_dma()
1137 host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; in atmci_prepare_data_dma()
1139 host->dma_conf.dst_maxburst); in atmci_prepare_data_dma()
1142 if (host->caps.has_dma_conf_reg) in atmci_prepare_data_dma()
1146 sglen = dma_map_sg(chan->device->dev, data->sg, in atmci_prepare_data_dma()
1147 data->sg_len, mmc_get_dma_dir(data)); in atmci_prepare_data_dma()
1149 dmaengine_slave_config(chan, &host->dma_conf); in atmci_prepare_data_dma()
1151 data->sg, sglen, slave_dirn, in atmci_prepare_data_dma()
1156 host->dma.data_desc = desc; in atmci_prepare_data_dma()
1157 desc->callback = atmci_dma_complete; in atmci_prepare_data_dma()
1158 desc->callback_param = host; in atmci_prepare_data_dma()
1162 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, in atmci_prepare_data_dma()
1164 return -ENOMEM; in atmci_prepare_data_dma()
1179 if (data->flags & MMC_DATA_READ) in atmci_submit_data_pdc()
1188 struct dma_chan *chan = host->data_chan; in atmci_submit_data_dma()
1189 struct dma_async_tx_descriptor *desc = host->dma.data_desc; in atmci_submit_data_dma()
1199 dev_dbg(&host->pdev->dev, in atmci_stop_transfer()
1215 struct dma_chan *chan = host->data_chan; in atmci_stop_transfer_dma()
1222 dev_dbg(&host->pdev->dev, in atmci_stop_transfer_dma()
1242 mrq = slot->mrq; in atmci_start_request()
1243 host->cur_slot = slot; in atmci_start_request()
1244 host->mrq = mrq; in atmci_start_request()
1246 host->pending_events = 0; in atmci_start_request()
1247 host->completed_events = 0; in atmci_start_request()
1248 host->cmd_status = 0; in atmci_start_request()
1249 host->data_status = 0; in atmci_start_request()
1251 dev_dbg(&host->pdev->dev, "start request: cmd %u\n", mrq->cmd->opcode); in atmci_start_request()
1253 if (host->need_reset || host->caps.need_reset_after_xfer) { in atmci_start_request()
1258 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_start_request()
1259 if (host->caps.has_cfg_reg) in atmci_start_request()
1260 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_start_request()
1262 host->need_reset = false; in atmci_start_request()
1264 atmci_writel(host, ATMCI_SDCR, slot->sdc_reg); in atmci_start_request()
1268 dev_dbg(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n", in atmci_start_request()
1271 if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) { in atmci_start_request()
1278 data = mrq->data; in atmci_start_request()
1283 atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks) in atmci_start_request()
1284 | ATMCI_BLKLEN(data->blksz)); in atmci_start_request()
1285 dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n", in atmci_start_request()
1286 ATMCI_BCNT(data->blocks) | ATMCI_BLKLEN(data->blksz)); in atmci_start_request()
1288 iflags |= host->prepare_data(host, data); in atmci_start_request()
1292 cmd = mrq->cmd; in atmci_start_request()
1293 cmdflags = atmci_prepare_command(slot->mmc, cmd); in atmci_start_request()
1301 if (host->submit_data != &atmci_submit_data_dma) in atmci_start_request()
1305 host->submit_data(host, data); in atmci_start_request()
1307 if (host->submit_data == &atmci_submit_data_dma) in atmci_start_request()
1310 if (mrq->stop) { in atmci_start_request()
1311 host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop); in atmci_start_request()
1312 host->stop_cmdr |= ATMCI_CMDR_STOP_XFER; in atmci_start_request()
1313 if (!(data->flags & MMC_DATA_WRITE)) in atmci_start_request()
1314 host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ; in atmci_start_request()
1315 host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK; in atmci_start_request()
1330 dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n", in atmci_queue_request()
1331 host->state); in atmci_queue_request()
1333 spin_lock_bh(&host->lock); in atmci_queue_request()
1334 slot->mrq = mrq; in atmci_queue_request()
1335 if (host->state == STATE_IDLE) { in atmci_queue_request()
1336 host->state = STATE_SENDING_CMD; in atmci_queue_request()
1339 dev_dbg(&host->pdev->dev, "queue request\n"); in atmci_queue_request()
1340 list_add_tail(&slot->queue_node, &host->queue); in atmci_queue_request()
1342 spin_unlock_bh(&host->lock); in atmci_queue_request()
1348 struct atmel_mci *host = slot->host; in atmci_request()
1351 WARN_ON(slot->mrq); in atmci_request()
1352 dev_dbg(&host->pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode); in atmci_request()
1362 if (!test_bit(ATMCI_CARD_PRESENT, &slot->flags)) { in atmci_request()
1363 mrq->cmd->error = -ENOMEDIUM; in atmci_request()
1369 data = mrq->data; in atmci_request()
1370 if (data && data->blocks > 1 && data->blksz & 3) { in atmci_request()
1371 mrq->cmd->error = -EINVAL; in atmci_request()
1381 struct atmel_mci *host = slot->host; in atmci_set_ios()
1384 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK; in atmci_set_ios()
1385 switch (ios->bus_width) { in atmci_set_ios()
1387 slot->sdc_reg |= ATMCI_SDCBUS_1BIT; in atmci_set_ios()
1390 slot->sdc_reg |= ATMCI_SDCBUS_4BIT; in atmci_set_ios()
1393 slot->sdc_reg |= ATMCI_SDCBUS_8BIT; in atmci_set_ios()
1397 if (ios->clock) { in atmci_set_ios()
1401 spin_lock_bh(&host->lock); in atmci_set_ios()
1402 if (!host->mode_reg) { in atmci_set_ios()
1405 if (host->caps.has_cfg_reg) in atmci_set_ios()
1406 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_set_ios()
1410 * Use mirror of ios->clock to prevent race with mmc in atmci_set_ios()
1413 slot->clock = ios->clock; in atmci_set_ios()
1415 if (host->slot[i] && host->slot[i]->clock in atmci_set_ios()
1416 && host->slot[i]->clock < clock_min) in atmci_set_ios()
1417 clock_min = host->slot[i]->clock; in atmci_set_ios()
1421 if (host->caps.has_odd_clk_div) { in atmci_set_ios()
1422 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; in atmci_set_ios()
1424 dev_warn(&mmc->class_dev, in atmci_set_ios()
1426 clock_min, host->bus_hz / 2); in atmci_set_ios()
1429 dev_warn(&mmc->class_dev, in atmci_set_ios()
1431 clock_min, host->bus_hz / (511 + 2)); in atmci_set_ios()
1434 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv >> 1) in atmci_set_ios()
1437 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; in atmci_set_ios()
1439 dev_warn(&mmc->class_dev, in atmci_set_ios()
1441 clock_min, host->bus_hz / (2 * 256)); in atmci_set_ios()
1444 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv); in atmci_set_ios()
1452 if (host->caps.has_rwproof) in atmci_set_ios()
1453 host->mode_reg |= (ATMCI_MR_WRPROOF | ATMCI_MR_RDPROOF); in atmci_set_ios()
1455 if (host->caps.has_cfg_reg) { in atmci_set_ios()
1457 if (ios->timing == MMC_TIMING_SD_HS) in atmci_set_ios()
1458 host->cfg_reg |= ATMCI_CFG_HSMODE; in atmci_set_ios()
1460 host->cfg_reg &= ~ATMCI_CFG_HSMODE; in atmci_set_ios()
1463 if (list_empty(&host->queue)) { in atmci_set_ios()
1464 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_set_ios()
1465 if (host->caps.has_cfg_reg) in atmci_set_ios()
1466 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_set_ios()
1468 host->need_clock_update = true; in atmci_set_ios()
1471 spin_unlock_bh(&host->lock); in atmci_set_ios()
1475 spin_lock_bh(&host->lock); in atmci_set_ios()
1476 slot->clock = 0; in atmci_set_ios()
1478 if (host->slot[i] && host->slot[i]->clock) { in atmci_set_ios()
1485 if (host->mode_reg) { in atmci_set_ios()
1488 host->mode_reg = 0; in atmci_set_ios()
1490 spin_unlock_bh(&host->lock); in atmci_set_ios()
1493 switch (ios->power_mode) { in atmci_set_ios()
1495 if (!IS_ERR(mmc->supply.vmmc)) in atmci_set_ios()
1496 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); in atmci_set_ios()
1499 set_bit(ATMCI_CARD_NEED_INIT, &slot->flags); in atmci_set_ios()
1500 if (!IS_ERR(mmc->supply.vmmc)) in atmci_set_ios()
1501 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); in atmci_set_ios()
1510 int read_only = -ENOSYS; in atmci_get_ro()
1513 if (gpio_is_valid(slot->wp_pin)) { in atmci_get_ro()
1514 read_only = gpio_get_value(slot->wp_pin); in atmci_get_ro()
1515 dev_dbg(&mmc->class_dev, "card is %s\n", in atmci_get_ro()
1516 read_only ? "read-only" : "read-write"); in atmci_get_ro()
1524 int present = -ENOSYS; in atmci_get_cd()
1527 if (gpio_is_valid(slot->detect_pin)) { in atmci_get_cd()
1528 present = !(gpio_get_value(slot->detect_pin) ^ in atmci_get_cd()
1529 slot->detect_is_active_high); in atmci_get_cd()
1530 dev_dbg(&mmc->class_dev, "card is %spresent\n", in atmci_get_cd()
1540 struct atmel_mci *host = slot->host; in atmci_enable_sdio_irq()
1543 atmci_writel(host, ATMCI_IER, slot->sdio_irq); in atmci_enable_sdio_irq()
1545 atmci_writel(host, ATMCI_IDR, slot->sdio_irq); in atmci_enable_sdio_irq()
1556 /* Called with host->lock held */
1558 __releases(&host->lock) in atmci_request_end()
1559 __acquires(&host->lock) in atmci_request_end()
1562 struct mmc_host *prev_mmc = host->cur_slot->mmc; in atmci_request_end()
1564 WARN_ON(host->cmd || host->data); in atmci_request_end()
1566 del_timer(&host->timer); in atmci_request_end()
1573 if (host->need_clock_update) { in atmci_request_end()
1574 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_request_end()
1575 if (host->caps.has_cfg_reg) in atmci_request_end()
1576 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_request_end()
1579 host->cur_slot->mrq = NULL; in atmci_request_end()
1580 host->mrq = NULL; in atmci_request_end()
1581 if (!list_empty(&host->queue)) { in atmci_request_end()
1582 slot = list_entry(host->queue.next, in atmci_request_end()
1584 list_del(&slot->queue_node); in atmci_request_end()
1585 dev_vdbg(&host->pdev->dev, "list not empty: %s is next\n", in atmci_request_end()
1586 mmc_hostname(slot->mmc)); in atmci_request_end()
1587 host->state = STATE_SENDING_CMD; in atmci_request_end()
1590 dev_vdbg(&host->pdev->dev, "list empty\n"); in atmci_request_end()
1591 host->state = STATE_IDLE; in atmci_request_end()
1594 spin_unlock(&host->lock); in atmci_request_end()
1596 spin_lock(&host->lock); in atmci_request_end()
1602 u32 status = host->cmd_status; in atmci_command_complete()
1605 cmd->resp[0] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1606 cmd->resp[1] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1607 cmd->resp[2] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1608 cmd->resp[3] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1611 cmd->error = -ETIMEDOUT; in atmci_command_complete()
1612 else if ((cmd->flags & MMC_RSP_CRC) && (status & ATMCI_RCRCE)) in atmci_command_complete()
1613 cmd->error = -EILSEQ; in atmci_command_complete()
1615 cmd->error = -EIO; in atmci_command_complete()
1616 else if (host->mrq->data && (host->mrq->data->blksz & 3)) { in atmci_command_complete()
1617 if (host->caps.need_blksz_mul_4) { in atmci_command_complete()
1618 cmd->error = -EINVAL; in atmci_command_complete()
1619 host->need_reset = 1; in atmci_command_complete()
1622 cmd->error = 0; in atmci_command_complete()
1633 * freeing the interrupt. We must not re-enable the interrupt in atmci_detect_change()
1638 if (test_bit(ATMCI_SHUTDOWN, &slot->flags)) in atmci_detect_change()
1641 enable_irq(gpio_to_irq(slot->detect_pin)); in atmci_detect_change()
1642 present = !(gpio_get_value(slot->detect_pin) ^ in atmci_detect_change()
1643 slot->detect_is_active_high); in atmci_detect_change()
1644 present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1646 dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d)\n", in atmci_detect_change()
1650 struct atmel_mci *host = slot->host; in atmci_detect_change()
1653 dev_dbg(&slot->mmc->class_dev, "card %s\n", in atmci_detect_change()
1656 spin_lock(&host->lock); in atmci_detect_change()
1659 clear_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1661 set_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1664 mrq = slot->mrq; in atmci_detect_change()
1666 if (mrq == host->mrq) { in atmci_detect_change()
1673 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_detect_change()
1674 if (host->caps.has_cfg_reg) in atmci_detect_change()
1675 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_detect_change()
1677 host->data = NULL; in atmci_detect_change()
1678 host->cmd = NULL; in atmci_detect_change()
1680 switch (host->state) { in atmci_detect_change()
1684 mrq->cmd->error = -ENOMEDIUM; in atmci_detect_change()
1685 if (mrq->data) in atmci_detect_change()
1686 host->stop_transfer(host); in atmci_detect_change()
1689 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1690 host->stop_transfer(host); in atmci_detect_change()
1693 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1696 mrq->stop->error = -ENOMEDIUM; in atmci_detect_change()
1704 list_del(&slot->queue_node); in atmci_detect_change()
1705 mrq->cmd->error = -ENOMEDIUM; in atmci_detect_change()
1706 if (mrq->data) in atmci_detect_change()
1707 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1708 if (mrq->stop) in atmci_detect_change()
1709 mrq->stop->error = -ENOMEDIUM; in atmci_detect_change()
1711 spin_unlock(&host->lock); in atmci_detect_change()
1712 mmc_request_done(slot->mmc, mrq); in atmci_detect_change()
1713 spin_lock(&host->lock); in atmci_detect_change()
1716 spin_unlock(&host->lock); in atmci_detect_change()
1718 mmc_detect_change(slot->mmc, 0); in atmci_detect_change()
1725 struct mmc_request *mrq = host->mrq; in atmci_tasklet_func()
1726 struct mmc_data *data = host->data; in atmci_tasklet_func()
1727 enum atmel_mci_state state = host->state; in atmci_tasklet_func()
1731 spin_lock(&host->lock); in atmci_tasklet_func()
1733 state = host->state; in atmci_tasklet_func()
1735 dev_vdbg(&host->pdev->dev, in atmci_tasklet_func()
1737 state, host->pending_events, host->completed_events, in atmci_tasklet_func()
1742 dev_dbg(&host->pdev->dev, "FSM: state=%d\n", state); in atmci_tasklet_func()
1755 dev_dbg(&host->pdev->dev, "FSM: cmd ready?\n"); in atmci_tasklet_func()
1760 dev_dbg(&host->pdev->dev, "set completed cmd ready\n"); in atmci_tasklet_func()
1761 host->cmd = NULL; in atmci_tasklet_func()
1763 atmci_command_complete(host, mrq->cmd); in atmci_tasklet_func()
1764 if (mrq->data) { in atmci_tasklet_func()
1765 dev_dbg(&host->pdev->dev, in atmci_tasklet_func()
1771 if (mrq->cmd->error) { in atmci_tasklet_func()
1772 host->stop_transfer(host); in atmci_tasklet_func()
1773 host->data = NULL; in atmci_tasklet_func()
1780 } else if ((!mrq->data) && (mrq->cmd->flags & MMC_RSP_BUSY)) { in atmci_tasklet_func()
1781 dev_dbg(&host->pdev->dev, in atmci_tasklet_func()
1793 dev_dbg(&host->pdev->dev, "set completed data error\n"); in atmci_tasklet_func()
1806 dev_dbg(&host->pdev->dev, "FSM: xfer complete?\n"); in atmci_tasklet_func()
1811 dev_dbg(&host->pdev->dev, in atmci_tasklet_func()
1816 if (host->caps.need_notbusy_for_read_ops || in atmci_tasklet_func()
1817 (host->data->flags & MMC_DATA_WRITE)) { in atmci_tasklet_func()
1820 } else if (host->mrq->stop) { in atmci_tasklet_func()
1824 host->data = NULL; in atmci_tasklet_func()
1825 data->bytes_xfered = data->blocks * data->blksz; in atmci_tasklet_func()
1826 data->error = 0; in atmci_tasklet_func()
1838 dev_dbg(&host->pdev->dev, "FSM: not busy?\n"); in atmci_tasklet_func()
1843 dev_dbg(&host->pdev->dev, "set completed not busy\n"); in atmci_tasklet_func()
1846 if (host->data) { in atmci_tasklet_func()
1852 if (host->mrq->stop) { in atmci_tasklet_func()
1856 host->data = NULL; in atmci_tasklet_func()
1857 data->bytes_xfered = data->blocks in atmci_tasklet_func()
1858 * data->blksz; in atmci_tasklet_func()
1859 data->error = 0; in atmci_tasklet_func()
1868 * In this state, it is important to set host->data to in atmci_tasklet_func()
1873 dev_dbg(&host->pdev->dev, "FSM: cmd ready?\n"); in atmci_tasklet_func()
1878 dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); in atmci_tasklet_func()
1879 host->cmd = NULL; in atmci_tasklet_func()
1880 data->bytes_xfered = data->blocks * data->blksz; in atmci_tasklet_func()
1881 data->error = 0; in atmci_tasklet_func()
1882 atmci_command_complete(host, mrq->stop); in atmci_tasklet_func()
1883 if (mrq->stop->error) { in atmci_tasklet_func()
1884 host->stop_transfer(host); in atmci_tasklet_func()
1893 host->data = NULL; in atmci_tasklet_func()
1899 status = host->data_status; in atmci_tasklet_func()
1901 host->stop_transfer(host); in atmci_tasklet_func()
1902 host->data = NULL; in atmci_tasklet_func()
1905 data->error = -ETIMEDOUT; in atmci_tasklet_func()
1907 data->error = -EILSEQ; in atmci_tasklet_func()
1909 data->error = -EIO; in atmci_tasklet_func()
1914 atmci_request_end(host, host->mrq); in atmci_tasklet_func()
1915 goto unlock; /* atmci_request_end() sets host->state */ in atmci_tasklet_func()
1920 host->state = state; in atmci_tasklet_func()
1923 spin_unlock(&host->lock); in atmci_tasklet_func()
1928 struct scatterlist *sg = host->sg; in atmci_read_data_pio()
1929 unsigned int offset = host->pio_offset; in atmci_read_data_pio()
1930 struct mmc_data *data = host->data; in atmci_read_data_pio()
1937 if (likely(offset + 4 <= sg->length)) { in atmci_read_data_pio()
1943 if (offset == sg->length) { in atmci_read_data_pio()
1945 host->sg = sg = sg_next(sg); in atmci_read_data_pio()
1946 host->sg_len--; in atmci_read_data_pio()
1947 if (!sg || !host->sg_len) in atmci_read_data_pio()
1953 unsigned int remaining = sg->length - offset; in atmci_read_data_pio()
1959 host->sg = sg = sg_next(sg); in atmci_read_data_pio()
1960 host->sg_len--; in atmci_read_data_pio()
1961 if (!sg || !host->sg_len) in atmci_read_data_pio()
1964 offset = 4 - remaining; in atmci_read_data_pio()
1974 host->data_status = status; in atmci_read_data_pio()
1975 data->bytes_xfered += nbytes; in atmci_read_data_pio()
1980 host->pio_offset = offset; in atmci_read_data_pio()
1981 data->bytes_xfered += nbytes; in atmci_read_data_pio()
1988 data->bytes_xfered += nbytes; in atmci_read_data_pio()
1995 struct scatterlist *sg = host->sg; in atmci_write_data_pio()
1996 unsigned int offset = host->pio_offset; in atmci_write_data_pio()
1997 struct mmc_data *data = host->data; in atmci_write_data_pio()
2003 if (likely(offset + 4 <= sg->length)) { in atmci_write_data_pio()
2009 if (offset == sg->length) { in atmci_write_data_pio()
2010 host->sg = sg = sg_next(sg); in atmci_write_data_pio()
2011 host->sg_len--; in atmci_write_data_pio()
2012 if (!sg || !host->sg_len) in atmci_write_data_pio()
2018 unsigned int remaining = sg->length - offset; in atmci_write_data_pio()
2024 host->sg = sg = sg_next(sg); in atmci_write_data_pio()
2025 host->sg_len--; in atmci_write_data_pio()
2026 if (!sg || !host->sg_len) { in atmci_write_data_pio()
2031 offset = 4 - remaining; in atmci_write_data_pio()
2042 host->data_status = status; in atmci_write_data_pio()
2043 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2048 host->pio_offset = offset; in atmci_write_data_pio()
2049 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2056 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2066 struct atmel_mci_slot *slot = host->slot[i]; in atmci_sdio_interrupt()
2067 if (slot && (status & slot->sdio_irq)) { in atmci_sdio_interrupt()
2068 mmc_signal_sdio_irq(slot->mmc); in atmci_sdio_interrupt()
2088 dev_dbg(&host->pdev->dev, "IRQ: data error\n"); in atmci_interrupt()
2094 host->data_status = status; in atmci_interrupt()
2095 dev_dbg(&host->pdev->dev, "set pending data error\n"); in atmci_interrupt()
2098 tasklet_schedule(&host->tasklet); in atmci_interrupt()
2102 dev_dbg(&host->pdev->dev, "IRQ: tx buffer empty\n"); in atmci_interrupt()
2110 if (host->data_size) { in atmci_interrupt()
2118 dev_dbg(&host->pdev->dev, "IRQ: end of tx buffer\n"); in atmci_interrupt()
2121 if (host->data_size) { in atmci_interrupt()
2129 dev_dbg(&host->pdev->dev, "IRQ: rx buffer full\n"); in atmci_interrupt()
2137 if (host->data_size) { in atmci_interrupt()
2145 dev_dbg(&host->pdev->dev, "IRQ: end of rx buffer\n"); in atmci_interrupt()
2148 if (host->data_size) { in atmci_interrupt()
2162 dev_dbg(&host->pdev->dev, "IRQ: blke\n"); in atmci_interrupt()
2165 dev_dbg(&host->pdev->dev, "set pending notbusy\n"); in atmci_interrupt()
2167 tasklet_schedule(&host->tasklet); in atmci_interrupt()
2171 dev_dbg(&host->pdev->dev, "IRQ: not_busy\n"); in atmci_interrupt()
2174 dev_dbg(&host->pdev->dev, "set pending notbusy\n"); in atmci_interrupt()
2176 tasklet_schedule(&host->tasklet); in atmci_interrupt()
2185 dev_dbg(&host->pdev->dev, "IRQ: cmd ready\n"); in atmci_interrupt()
2187 host->cmd_status = status; in atmci_interrupt()
2189 dev_dbg(&host->pdev->dev, "set pending cmd rdy\n"); in atmci_interrupt()
2191 tasklet_schedule(&host->tasklet); in atmci_interrupt()
2212 mod_timer(&slot->detect_timer, jiffies + msecs_to_jiffies(20)); in atmci_detect_interrupt()
2225 mmc = mmc_alloc_host(sizeof(struct atmel_mci_slot), &host->pdev->dev); in atmci_init_slot()
2227 return -ENOMEM; in atmci_init_slot()
2230 slot->mmc = mmc; in atmci_init_slot()
2231 slot->host = host; in atmci_init_slot()
2232 slot->detect_pin = slot_data->detect_pin; in atmci_init_slot()
2233 slot->wp_pin = slot_data->wp_pin; in atmci_init_slot()
2234 slot->detect_is_active_high = slot_data->detect_is_active_high; in atmci_init_slot()
2235 slot->sdc_reg = sdc_reg; in atmci_init_slot()
2236 slot->sdio_irq = sdio_irq; in atmci_init_slot()
2238 dev_dbg(&mmc->class_dev, in atmci_init_slot()
2241 id, slot_data->bus_width, slot_data->detect_pin, in atmci_init_slot()
2242 slot_data->detect_is_active_high ? "true" : "false", in atmci_init_slot()
2243 slot_data->wp_pin); in atmci_init_slot()
2245 mmc->ops = &atmci_ops; in atmci_init_slot()
2246 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); in atmci_init_slot()
2247 mmc->f_max = host->bus_hz / 2; in atmci_init_slot()
2248 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; in atmci_init_slot()
2250 mmc->caps |= MMC_CAP_SDIO_IRQ; in atmci_init_slot()
2251 if (host->caps.has_highspeed) in atmci_init_slot()
2252 mmc->caps |= MMC_CAP_SD_HIGHSPEED; in atmci_init_slot()
2258 if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) { in atmci_init_slot()
2259 mmc->caps |= MMC_CAP_4_BIT_DATA; in atmci_init_slot()
2260 if (slot_data->bus_width >= 8) in atmci_init_slot()
2261 mmc->caps |= MMC_CAP_8_BIT_DATA; in atmci_init_slot()
2265 mmc->max_segs = 256; in atmci_init_slot()
2266 mmc->max_blk_size = 4095; in atmci_init_slot()
2267 mmc->max_blk_count = 256; in atmci_init_slot()
2268 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; in atmci_init_slot()
2269 mmc->max_seg_size = mmc->max_blk_size * mmc->max_segs; in atmci_init_slot()
2271 mmc->max_segs = 64; in atmci_init_slot()
2272 mmc->max_req_size = 32768 * 512; in atmci_init_slot()
2273 mmc->max_blk_size = 32768; in atmci_init_slot()
2274 mmc->max_blk_count = 512; in atmci_init_slot()
2278 set_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_init_slot()
2279 if (gpio_is_valid(slot->detect_pin)) { in atmci_init_slot()
2280 if (devm_gpio_request(&host->pdev->dev, slot->detect_pin, in atmci_init_slot()
2282 dev_dbg(&mmc->class_dev, "no detect pin available\n"); in atmci_init_slot()
2283 slot->detect_pin = -EBUSY; in atmci_init_slot()
2284 } else if (gpio_get_value(slot->detect_pin) ^ in atmci_init_slot()
2285 slot->detect_is_active_high) { in atmci_init_slot()
2286 clear_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_init_slot()
2290 if (!gpio_is_valid(slot->detect_pin)) { in atmci_init_slot()
2291 if (slot_data->non_removable) in atmci_init_slot()
2292 mmc->caps |= MMC_CAP_NONREMOVABLE; in atmci_init_slot()
2294 mmc->caps |= MMC_CAP_NEEDS_POLL; in atmci_init_slot()
2297 if (gpio_is_valid(slot->wp_pin)) { in atmci_init_slot()
2298 if (devm_gpio_request(&host->pdev->dev, slot->wp_pin, in atmci_init_slot()
2300 dev_dbg(&mmc->class_dev, "no WP pin available\n"); in atmci_init_slot()
2301 slot->wp_pin = -EBUSY; in atmci_init_slot()
2305 host->slot[id] = slot; in atmci_init_slot()
2313 if (gpio_is_valid(slot->detect_pin)) { in atmci_init_slot()
2314 timer_setup(&slot->detect_timer, atmci_detect_change, 0); in atmci_init_slot()
2316 ret = request_irq(gpio_to_irq(slot->detect_pin), in atmci_init_slot()
2319 "mmc-detect", slot); in atmci_init_slot()
2321 dev_dbg(&mmc->class_dev, in atmci_init_slot()
2323 gpio_to_irq(slot->detect_pin)); in atmci_init_slot()
2324 slot->detect_pin = -EBUSY; in atmci_init_slot()
2338 set_bit(ATMCI_SHUTDOWN, &slot->flags); in atmci_cleanup_slot()
2341 mmc_remove_host(slot->mmc); in atmci_cleanup_slot()
2343 if (gpio_is_valid(slot->detect_pin)) { in atmci_cleanup_slot()
2344 int pin = slot->detect_pin; in atmci_cleanup_slot()
2347 del_timer_sync(&slot->detect_timer); in atmci_cleanup_slot()
2350 slot->host->slot[id] = NULL; in atmci_cleanup_slot()
2351 mmc_free_host(slot->mmc); in atmci_cleanup_slot()
2356 host->dma.chan = dma_request_chan(&host->pdev->dev, "rxtx"); in atmci_configure_dma()
2358 if (PTR_ERR(host->dma.chan) == -ENODEV) { in atmci_configure_dma()
2359 struct mci_platform_data *pdata = host->pdev->dev.platform_data; in atmci_configure_dma()
2362 if (!pdata || !pdata->dma_filter) in atmci_configure_dma()
2363 return -ENODEV; in atmci_configure_dma()
2368 host->dma.chan = dma_request_channel(mask, pdata->dma_filter, in atmci_configure_dma()
2369 pdata->dma_slave); in atmci_configure_dma()
2370 if (!host->dma.chan) in atmci_configure_dma()
2371 host->dma.chan = ERR_PTR(-ENODEV); in atmci_configure_dma()
2374 if (IS_ERR(host->dma.chan)) in atmci_configure_dma()
2375 return PTR_ERR(host->dma.chan); in atmci_configure_dma()
2377 dev_info(&host->pdev->dev, "using %s for DMA transfers\n", in atmci_configure_dma()
2378 dma_chan_name(host->dma.chan)); in atmci_configure_dma()
2380 host->dma_conf.src_addr = host->mapbase + ATMCI_RDR; in atmci_configure_dma()
2381 host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in atmci_configure_dma()
2382 host->dma_conf.src_maxburst = 1; in atmci_configure_dma()
2383 host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR; in atmci_configure_dma()
2384 host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in atmci_configure_dma()
2385 host->dma_conf.dst_maxburst = 1; in atmci_configure_dma()
2386 host->dma_conf.device_fc = false; in atmci_configure_dma()
2401 dev_info(&host->pdev->dev, in atmci_get_cap()
2404 host->caps.has_dma_conf_reg = 0; in atmci_get_cap()
2405 host->caps.has_pdc = 1; in atmci_get_cap()
2406 host->caps.has_cfg_reg = 0; in atmci_get_cap()
2407 host->caps.has_cstor_reg = 0; in atmci_get_cap()
2408 host->caps.has_highspeed = 0; in atmci_get_cap()
2409 host->caps.has_rwproof = 0; in atmci_get_cap()
2410 host->caps.has_odd_clk_div = 0; in atmci_get_cap()
2411 host->caps.has_bad_data_ordering = 1; in atmci_get_cap()
2412 host->caps.need_reset_after_xfer = 1; in atmci_get_cap()
2413 host->caps.need_blksz_mul_4 = 1; in atmci_get_cap()
2414 host->caps.need_notbusy_for_read_ops = 0; in atmci_get_cap()
2420 host->caps.has_odd_clk_div = 1; in atmci_get_cap()
2424 host->caps.has_dma_conf_reg = 1; in atmci_get_cap()
2425 host->caps.has_pdc = 0; in atmci_get_cap()
2426 host->caps.has_cfg_reg = 1; in atmci_get_cap()
2427 host->caps.has_cstor_reg = 1; in atmci_get_cap()
2428 host->caps.has_highspeed = 1; in atmci_get_cap()
2431 host->caps.has_rwproof = 1; in atmci_get_cap()
2432 host->caps.need_blksz_mul_4 = 0; in atmci_get_cap()
2433 host->caps.need_notbusy_for_read_ops = 1; in atmci_get_cap()
2436 host->caps.has_bad_data_ordering = 0; in atmci_get_cap()
2437 host->caps.need_reset_after_xfer = 0; in atmci_get_cap()
2442 host->caps.has_pdc = 0; in atmci_get_cap()
2443 dev_warn(&host->pdev->dev, in atmci_get_cap()
2460 return -ENXIO; in atmci_probe()
2461 pdata = pdev->dev.platform_data; in atmci_probe()
2465 dev_err(&pdev->dev, "platform data not available\n"); in atmci_probe()
2474 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); in atmci_probe()
2476 return -ENOMEM; in atmci_probe()
2478 host->pdev = pdev; in atmci_probe()
2479 spin_lock_init(&host->lock); in atmci_probe()
2480 INIT_LIST_HEAD(&host->queue); in atmci_probe()
2482 host->mck = devm_clk_get(&pdev->dev, "mci_clk"); in atmci_probe()
2483 if (IS_ERR(host->mck)) in atmci_probe()
2484 return PTR_ERR(host->mck); in atmci_probe()
2486 host->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); in atmci_probe()
2487 if (!host->regs) in atmci_probe()
2488 return -ENOMEM; in atmci_probe()
2490 ret = clk_prepare_enable(host->mck); in atmci_probe()
2495 host->bus_hz = clk_get_rate(host->mck); in atmci_probe()
2497 host->mapbase = regs->start; in atmci_probe()
2499 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host); in atmci_probe()
2501 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host); in atmci_probe()
2503 clk_disable_unprepare(host->mck); in atmci_probe()
2510 if (ret == -EPROBE_DEFER) in atmci_probe()
2513 host->prepare_data = &atmci_prepare_data_dma; in atmci_probe()
2514 host->submit_data = &atmci_submit_data_dma; in atmci_probe()
2515 host->stop_transfer = &atmci_stop_transfer_dma; in atmci_probe()
2516 } else if (host->caps.has_pdc) { in atmci_probe()
2517 dev_info(&pdev->dev, "using PDC\n"); in atmci_probe()
2518 host->prepare_data = &atmci_prepare_data_pdc; in atmci_probe()
2519 host->submit_data = &atmci_submit_data_pdc; in atmci_probe()
2520 host->stop_transfer = &atmci_stop_transfer_pdc; in atmci_probe()
2522 dev_info(&pdev->dev, "using PIO\n"); in atmci_probe()
2523 host->prepare_data = &atmci_prepare_data; in atmci_probe()
2524 host->submit_data = &atmci_submit_data; in atmci_probe()
2525 host->stop_transfer = &atmci_stop_transfer; in atmci_probe()
2530 timer_setup(&host->timer, atmci_timeout_timer, 0); in atmci_probe()
2532 pm_runtime_get_noresume(&pdev->dev); in atmci_probe()
2533 pm_runtime_set_active(&pdev->dev); in atmci_probe()
2534 pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_DELAY); in atmci_probe()
2535 pm_runtime_use_autosuspend(&pdev->dev); in atmci_probe()
2536 pm_runtime_enable(&pdev->dev); in atmci_probe()
2540 ret = -ENODEV; in atmci_probe()
2541 if (pdata->slot[0].bus_width) { in atmci_probe()
2542 ret = atmci_init_slot(host, &pdata->slot[0], in atmci_probe()
2546 host->buf_size = host->slot[0]->mmc->max_req_size; in atmci_probe()
2549 if (pdata->slot[1].bus_width) { in atmci_probe()
2550 ret = atmci_init_slot(host, &pdata->slot[1], in atmci_probe()
2554 if (host->slot[1]->mmc->max_req_size > host->buf_size) in atmci_probe()
2555 host->buf_size = in atmci_probe()
2556 host->slot[1]->mmc->max_req_size; in atmci_probe()
2561 dev_err(&pdev->dev, "init failed: no slot defined\n"); in atmci_probe()
2565 if (!host->caps.has_rwproof) { in atmci_probe()
2566 host->buffer = dma_alloc_coherent(&pdev->dev, host->buf_size, in atmci_probe()
2567 &host->buf_phys_addr, in atmci_probe()
2569 if (!host->buffer) { in atmci_probe()
2570 ret = -ENOMEM; in atmci_probe()
2571 dev_err(&pdev->dev, "buffer allocation failed\n"); in atmci_probe()
2576 dev_info(&pdev->dev, in atmci_probe()
2578 host->mapbase, irq, nr_slots); in atmci_probe()
2580 pm_runtime_mark_last_busy(&host->pdev->dev); in atmci_probe()
2581 pm_runtime_put_autosuspend(&pdev->dev); in atmci_probe()
2587 if (host->slot[i]) in atmci_probe()
2588 atmci_cleanup_slot(host->slot[i], i); in atmci_probe()
2591 clk_disable_unprepare(host->mck); in atmci_probe()
2593 pm_runtime_disable(&pdev->dev); in atmci_probe()
2594 pm_runtime_put_noidle(&pdev->dev); in atmci_probe()
2596 del_timer_sync(&host->timer); in atmci_probe()
2597 if (!IS_ERR(host->dma.chan)) in atmci_probe()
2598 dma_release_channel(host->dma.chan); in atmci_probe()
2609 pm_runtime_get_sync(&pdev->dev); in atmci_remove()
2611 if (host->buffer) in atmci_remove()
2612 dma_free_coherent(&pdev->dev, host->buf_size, in atmci_remove()
2613 host->buffer, host->buf_phys_addr); in atmci_remove()
2616 if (host->slot[i]) in atmci_remove()
2617 atmci_cleanup_slot(host->slot[i], i); in atmci_remove()
2624 del_timer_sync(&host->timer); in atmci_remove()
2625 if (!IS_ERR(host->dma.chan)) in atmci_remove()
2626 dma_release_channel(host->dma.chan); in atmci_remove()
2630 clk_disable_unprepare(host->mck); in atmci_remove()
2632 pm_runtime_disable(&pdev->dev); in atmci_remove()
2633 pm_runtime_put_noidle(&pdev->dev); in atmci_remove()
2643 clk_disable_unprepare(host->mck); in atmci_runtime_suspend()
2656 return clk_prepare_enable(host->mck); in atmci_runtime_resume()