Lines Matching +full:clkdiv +full:- +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2008 Atmel Corporation
12 #include <linux/dma-mapping.h>
63 #define ATMCI_MR_PDCMODE BIT(15) /* PDC-oriented Mode */
72 #define ATMCI_SDCBUS_1BIT (0 << 6) /* 1-bit data bus */
73 #define ATMCI_SDCBUS_4BIT (2 << 6) /* 4-bit data bus */
74 #define ATMCI_SDCBUS_8BIT (3 << 6) /* 8-bit data bus[2] */
80 #define ATMCI_CMDR_RSPTYP_48BIT (1 << 6) /* 48-bit response */
81 #define ATMCI_CMDR_RSPTYP_136BIT (2 << 6) /* 136-bit response */
93 #define ATMCI_CMDR_BLOCK (0 << 19) /* Single-block transfer */
94 #define ATMCI_CMDR_MULTI_BLOCK (1 << 19) /* Multi-block transfer */
127 #define ATMCI_CSRCV BIT(13) /* CE-ATA Completion Signal Received */
134 #define ATMCI_RTOE BIT(20) /* Response Time-Out Error */
136 #define ATMCI_DTOE BIT(22) /* Data Time-Out Error */
137 #define ATMCI_CSTOE BIT(23) /* Completion Signal Time-out Error */
169 __raw_readl((port)->regs + reg)
171 __raw_writel((value), (port)->regs + reg)
206 * struct mci_slot_pdata - board-specific per-slot configuration
217 * Note that support for multiple slots is experimental -- some cards
248 * struct atmel_mci - MMC controller state shared between all slots
265 * @data_size: just data->blocks * data->blksz.
293 * @pdata: Per-slot configuration data.
306 * @lock is a softirq-safe spinlock protecting @queue as well as
323 * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
383 * struct atmel_mci_slot - MMC slot state
392 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
423 test_and_clear_bit(event, &host->pending_events)
425 set_bit(event, &host->completed_events)
427 set_bit(event, &host->pending_events)
435 struct atmel_mci_slot *slot = s->private; in atmci_req_show()
442 spin_lock_bh(&slot->host->lock); in atmci_req_show()
443 mrq = slot->mrq; in atmci_req_show()
446 cmd = mrq->cmd; in atmci_req_show()
447 data = mrq->data; in atmci_req_show()
448 stop = mrq->stop; in atmci_req_show()
453 cmd->opcode, cmd->arg, cmd->flags, in atmci_req_show()
454 cmd->resp[0], cmd->resp[1], cmd->resp[2], in atmci_req_show()
455 cmd->resp[3], cmd->error); in atmci_req_show()
458 data->bytes_xfered, data->blocks, in atmci_req_show()
459 data->blksz, data->flags, data->error); in atmci_req_show()
463 stop->opcode, stop->arg, stop->flags, in atmci_req_show()
464 stop->resp[0], stop->resp[1], stop->resp[2], in atmci_req_show()
465 stop->resp[3], stop->error); in atmci_req_show()
468 spin_unlock_bh(&slot->host->lock); in atmci_req_show()
523 struct atmel_mci *host = s->private; in atmci_regs_show()
524 struct device *dev = host->dev; in atmci_regs_show()
531 return -ENOMEM; in atmci_regs_show()
540 spin_lock_bh(&host->lock); in atmci_regs_show()
541 memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE); in atmci_regs_show()
542 spin_unlock_bh(&host->lock); in atmci_regs_show()
551 if (host->caps.has_odd_clk_div) in atmci_regs_show()
552 seq_printf(s, "{CLKDIV,CLKODD}=%u\n", in atmci_regs_show()
556 seq_printf(s, "CLKDIV=%u\n", in atmci_regs_show()
565 if (host->caps.has_cstor_reg) in atmci_regs_show()
573 if (host->caps.has_dma_conf_reg) { in atmci_regs_show()
583 if (host->caps.has_cfg_reg) { in atmci_regs_show()
604 struct mmc_host *mmc = slot->mmc; in atmci_init_debugfs()
605 struct atmel_mci *host = slot->host; in atmci_init_debugfs()
608 root = mmc->debugfs_root; in atmci_init_debugfs()
614 debugfs_create_u32("state", S_IRUSR, root, &host->state); in atmci_init_debugfs()
616 &host->pending_events); in atmci_init_debugfs()
618 &host->completed_events); in atmci_init_debugfs()
630 struct device *dev = host->dev; in atmci_of_init()
631 struct device_node *np = dev->of_node; in atmci_of_init()
637 return dev_err_probe(dev, -EINVAL, "device node not found\n"); in atmci_of_init()
652 if (of_property_read_u32(cnp, "bus-width", in atmci_of_init()
653 &host->pdata[slot_id].bus_width)) in atmci_of_init()
654 host->pdata[slot_id].bus_width = 1; in atmci_of_init()
656 host->pdata[slot_id].detect_pin = in atmci_of_init()
658 "cd", GPIOD_IN, "cd-gpios"); in atmci_of_init()
659 err = PTR_ERR_OR_ZERO(host->pdata[slot_id].detect_pin); in atmci_of_init()
661 if (err != -ENOENT) { in atmci_of_init()
665 host->pdata[slot_id].detect_pin = NULL; in atmci_of_init()
668 host->pdata[slot_id].non_removable = in atmci_of_init()
669 of_property_read_bool(cnp, "non-removable"); in atmci_of_init()
671 host->pdata[slot_id].wp_pin = in atmci_of_init()
673 "wp", GPIOD_IN, "wp-gpios"); in atmci_of_init()
674 err = PTR_ERR_OR_ZERO(host->pdata[slot_id].wp_pin); in atmci_of_init()
676 if (err != -ENOENT) { in atmci_of_init()
680 host->pdata[slot_id].wp_pin = NULL; in atmci_of_init()
694 * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
695 * With version 0x600, we need to convert them as: 1 -> 0, 2 -> 1, 4 -> 2,
696 * 8 -> 3, 16 -> 4.
710 return fls(maxburst) - offset; in atmci_convert_chksize()
718 struct device *dev = host->dev; in atmci_timeout_timer()
722 if (host->mrq->cmd->data) { in atmci_timeout_timer()
723 host->mrq->cmd->data->error = -ETIMEDOUT; in atmci_timeout_timer()
724 host->data = NULL; in atmci_timeout_timer()
730 if (host->state == STATE_DATA_XFER) in atmci_timeout_timer()
731 host->stop_transfer(host); in atmci_timeout_timer()
733 host->mrq->cmd->error = -ETIMEDOUT; in atmci_timeout_timer()
734 host->cmd = NULL; in atmci_timeout_timer()
736 host->need_reset = 1; in atmci_timeout_timer()
737 host->state = STATE_END_REQUEST; in atmci_timeout_timer()
739 queue_work(system_bh_wq, &host->bh_work); in atmci_timeout_timer()
751 /* Maximum clock frequency is host->bus_hz/2 */ in atmci_ns_to_clocks()
752 return us * (DIV_ROUND_UP(host->bus_hz, 2000000)); in atmci_ns_to_clocks()
765 timeout = atmci_ns_to_clocks(host, data->timeout_ns) in atmci_set_timeout()
766 + data->timeout_clks; in atmci_set_timeout()
770 dtocyc = (timeout + (1 << shift) - 1) >> shift; in atmci_set_timeout()
780 dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n", in atmci_set_timeout()
794 cmd->error = -EINPROGRESS; in atmci_prepare_command()
796 cmdr = ATMCI_CMDR_CMDNB(cmd->opcode); in atmci_prepare_command()
798 if (cmd->flags & MMC_RSP_PRESENT) { in atmci_prepare_command()
799 if (cmd->flags & MMC_RSP_136) in atmci_prepare_command()
812 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN) in atmci_prepare_command()
815 data = cmd->data; in atmci_prepare_command()
819 if (cmd->opcode == SD_IO_RW_EXTENDED) { in atmci_prepare_command()
822 if (data->blocks > 1) in atmci_prepare_command()
828 if (data->flags & MMC_DATA_READ) in atmci_prepare_command()
838 struct device *dev = host->dev; in atmci_send_command()
839 unsigned int timeout_ms = cmd->busy_timeout ? cmd->busy_timeout : in atmci_send_command()
842 WARN_ON(host->cmd); in atmci_send_command()
843 host->cmd = cmd; in atmci_send_command()
845 dev_vdbg(dev, "start command: ARGR=0x%08x CMDR=0x%08x\n", cmd->arg, cmd_flags); in atmci_send_command()
847 atmci_writel(host, ATMCI_ARGR, cmd->arg); in atmci_send_command()
850 mod_timer(&host->timer, jiffies + msecs_to_jiffies(timeout_ms)); in atmci_send_command()
855 struct device *dev = host->dev; in atmci_send_stop_cmd()
858 atmci_send_command(host, data->stop, host->stop_cmdr); in atmci_send_stop_cmd()
864 * Update host->data_size and host->sg.
885 if (!host->caps.has_rwproof) { in atmci_pdc_set_single_buf()
886 buf_size = host->buf_size; in atmci_pdc_set_single_buf()
887 atmci_writel(host, pointer_reg, host->buf_phys_addr); in atmci_pdc_set_single_buf()
889 buf_size = sg_dma_len(host->sg); in atmci_pdc_set_single_buf()
890 atmci_writel(host, pointer_reg, sg_dma_address(host->sg)); in atmci_pdc_set_single_buf()
893 if (host->data_size <= buf_size) { in atmci_pdc_set_single_buf()
894 if (host->data_size & 0x3) { in atmci_pdc_set_single_buf()
896 atmci_writel(host, counter_reg, host->data_size); in atmci_pdc_set_single_buf()
897 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCFBYTE); in atmci_pdc_set_single_buf()
899 /* Else transfer 32-bits words */ in atmci_pdc_set_single_buf()
900 atmci_writel(host, counter_reg, host->data_size / 4); in atmci_pdc_set_single_buf()
902 host->data_size = 0; in atmci_pdc_set_single_buf()
904 /* We assume the size of a page is 32-bits aligned */ in atmci_pdc_set_single_buf()
905 atmci_writel(host, counter_reg, sg_dma_len(host->sg) / 4); in atmci_pdc_set_single_buf()
906 host->data_size -= sg_dma_len(host->sg); in atmci_pdc_set_single_buf()
907 if (host->data_size) in atmci_pdc_set_single_buf()
908 host->sg = sg_next(host->sg); in atmci_pdc_set_single_buf()
920 if (host->data_size) in atmci_pdc_set_both_buf()
929 struct mmc_data *data = host->data; in atmci_pdc_cleanup()
930 struct device *dev = host->dev; in atmci_pdc_cleanup()
933 dma_unmap_sg(dev, data->sg, data->sg_len, mmc_get_dma_dir(data)); in atmci_pdc_cleanup()
943 struct device *dev = host->dev; in atmci_pdc_complete()
944 int transfer_size = host->data->blocks * host->data->blksz; in atmci_pdc_complete()
949 if ((!host->caps.has_rwproof) in atmci_pdc_complete()
950 && (host->data->flags & MMC_DATA_READ)) { in atmci_pdc_complete()
951 if (host->caps.has_bad_data_ordering) in atmci_pdc_complete()
953 host->buffer[i] = swab32(host->buffer[i]); in atmci_pdc_complete()
954 sg_copy_from_buffer(host->data->sg, host->data->sg_len, in atmci_pdc_complete()
955 host->buffer, transfer_size); in atmci_pdc_complete()
962 queue_work(system_bh_wq, &host->bh_work); in atmci_pdc_complete()
967 struct mmc_data *data = host->data; in atmci_dma_cleanup()
970 dma_unmap_sg(host->dma.chan->device->dev, in atmci_dma_cleanup()
971 data->sg, data->sg_len, in atmci_dma_cleanup()
981 struct mmc_data *data = host->data; in atmci_dma_complete()
982 struct device *dev = host->dev; in atmci_dma_complete()
986 if (host->caps.has_dma_conf_reg) in atmci_dma_complete()
999 queue_work(system_bh_wq, &host->bh_work); in atmci_dma_complete()
1033 data->error = -EINPROGRESS; in atmci_prepare_data()
1035 host->sg = data->sg; in atmci_prepare_data()
1036 host->sg_len = data->sg_len; in atmci_prepare_data()
1037 host->data = data; in atmci_prepare_data()
1038 host->data_chan = NULL; in atmci_prepare_data()
1049 if (data->blocks * data->blksz < 12 in atmci_prepare_data()
1050 || (data->blocks * data->blksz) & 3) in atmci_prepare_data()
1051 host->need_reset = true; in atmci_prepare_data()
1053 host->pio_offset = 0; in atmci_prepare_data()
1054 if (data->flags & MMC_DATA_READ) in atmci_prepare_data()
1071 struct device *dev = host->dev; in atmci_prepare_data_pdc()
1075 data->error = -EINPROGRESS; in atmci_prepare_data_pdc()
1077 host->data = data; in atmci_prepare_data_pdc()
1078 host->sg = data->sg; in atmci_prepare_data_pdc()
1082 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCMODE); in atmci_prepare_data_pdc()
1084 if (data->flags & MMC_DATA_READ) in atmci_prepare_data_pdc()
1092 tmp |= ATMCI_BLKLEN(data->blksz); in atmci_prepare_data_pdc()
1096 host->data_size = data->blocks * data->blksz; in atmci_prepare_data_pdc()
1097 dma_map_sg(dev, data->sg, data->sg_len, mmc_get_dma_dir(data)); in atmci_prepare_data_pdc()
1099 if ((!host->caps.has_rwproof) in atmci_prepare_data_pdc()
1100 && (host->data->flags & MMC_DATA_WRITE)) { in atmci_prepare_data_pdc()
1101 sg_copy_to_buffer(host->data->sg, host->data->sg_len, in atmci_prepare_data_pdc()
1102 host->buffer, host->data_size); in atmci_prepare_data_pdc()
1103 if (host->caps.has_bad_data_ordering) in atmci_prepare_data_pdc()
1104 for (i = 0; i < host->data_size; i++) in atmci_prepare_data_pdc()
1105 host->buffer[i] = swab32(host->buffer[i]); in atmci_prepare_data_pdc()
1108 if (host->data_size) in atmci_prepare_data_pdc()
1109 atmci_pdc_set_both_buf(host, data->flags & MMC_DATA_READ ? in atmci_prepare_data_pdc()
1126 data->error = -EINPROGRESS; in atmci_prepare_data_dma()
1128 WARN_ON(host->data); in atmci_prepare_data_dma()
1129 host->sg = NULL; in atmci_prepare_data_dma()
1130 host->data = data; in atmci_prepare_data_dma()
1136 * non-word-aligned buffers or lengths. Also, we don't bother in atmci_prepare_data_dma()
1139 if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD) in atmci_prepare_data_dma()
1141 if (data->blksz & 3) in atmci_prepare_data_dma()
1144 for_each_sg(data->sg, sg, data->sg_len, i) { in atmci_prepare_data_dma()
1145 if (sg->offset & 3 || sg->length & 3) in atmci_prepare_data_dma()
1150 if (!host->dma.chan) in atmci_prepare_data_dma()
1151 return -ENODEV; in atmci_prepare_data_dma()
1153 chan = host->dma.chan; in atmci_prepare_data_dma()
1154 host->data_chan = chan; in atmci_prepare_data_dma()
1156 if (data->flags & MMC_DATA_READ) { in atmci_prepare_data_dma()
1157 host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; in atmci_prepare_data_dma()
1159 host->dma_conf.src_maxburst); in atmci_prepare_data_dma()
1161 host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; in atmci_prepare_data_dma()
1163 host->dma_conf.dst_maxburst); in atmci_prepare_data_dma()
1166 if (host->caps.has_dma_conf_reg) in atmci_prepare_data_dma()
1170 sglen = dma_map_sg(chan->device->dev, data->sg, in atmci_prepare_data_dma()
1171 data->sg_len, mmc_get_dma_dir(data)); in atmci_prepare_data_dma()
1173 dmaengine_slave_config(chan, &host->dma_conf); in atmci_prepare_data_dma()
1175 data->sg, sglen, slave_dirn, in atmci_prepare_data_dma()
1180 host->dma.data_desc = desc; in atmci_prepare_data_dma()
1181 desc->callback = atmci_dma_complete; in atmci_prepare_data_dma()
1182 desc->callback_param = host; in atmci_prepare_data_dma()
1186 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, in atmci_prepare_data_dma()
1188 return -ENOMEM; in atmci_prepare_data_dma()
1203 if (data->flags & MMC_DATA_READ) in atmci_submit_data_pdc()
1212 struct dma_chan *chan = host->data_chan; in atmci_submit_data_dma()
1213 struct dma_async_tx_descriptor *desc = host->dma.data_desc; in atmci_submit_data_dma()
1223 struct device *dev = host->dev; in atmci_stop_transfer()
1240 struct dma_chan *chan = host->data_chan; in atmci_stop_transfer_dma()
1241 struct device *dev = host->dev; in atmci_stop_transfer_dma()
1261 struct device *dev = host->dev; in atmci_start_request()
1268 mrq = slot->mrq; in atmci_start_request()
1269 host->cur_slot = slot; in atmci_start_request()
1270 host->mrq = mrq; in atmci_start_request()
1272 host->pending_events = 0; in atmci_start_request()
1273 host->completed_events = 0; in atmci_start_request()
1274 host->cmd_status = 0; in atmci_start_request()
1275 host->data_status = 0; in atmci_start_request()
1277 dev_dbg(dev, "start request: cmd %u\n", mrq->cmd->opcode); in atmci_start_request()
1279 if (host->need_reset || host->caps.need_reset_after_xfer) { in atmci_start_request()
1284 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_start_request()
1285 if (host->caps.has_cfg_reg) in atmci_start_request()
1286 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_start_request()
1288 host->need_reset = false; in atmci_start_request()
1290 atmci_writel(host, ATMCI_SDCR, slot->sdc_reg); in atmci_start_request()
1294 dev_dbg(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n", in atmci_start_request()
1297 if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) { in atmci_start_request()
1304 data = mrq->data; in atmci_start_request()
1309 atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks) in atmci_start_request()
1310 | ATMCI_BLKLEN(data->blksz)); in atmci_start_request()
1311 dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n", in atmci_start_request()
1312 ATMCI_BCNT(data->blocks) | ATMCI_BLKLEN(data->blksz)); in atmci_start_request()
1314 iflags |= host->prepare_data(host, data); in atmci_start_request()
1318 cmd = mrq->cmd; in atmci_start_request()
1319 cmdflags = atmci_prepare_command(slot->mmc, cmd); in atmci_start_request()
1327 if (host->submit_data != &atmci_submit_data_dma) in atmci_start_request()
1331 host->submit_data(host, data); in atmci_start_request()
1333 if (host->submit_data == &atmci_submit_data_dma) in atmci_start_request()
1336 if (mrq->stop) { in atmci_start_request()
1337 host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop); in atmci_start_request()
1338 host->stop_cmdr |= ATMCI_CMDR_STOP_XFER; in atmci_start_request()
1339 if (!(data->flags & MMC_DATA_WRITE)) in atmci_start_request()
1340 host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ; in atmci_start_request()
1341 host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK; in atmci_start_request()
1356 struct device *dev = host->dev; in atmci_queue_request()
1358 dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n", in atmci_queue_request()
1359 host->state); in atmci_queue_request()
1361 spin_lock_bh(&host->lock); in atmci_queue_request()
1362 slot->mrq = mrq; in atmci_queue_request()
1363 if (host->state == STATE_IDLE) { in atmci_queue_request()
1364 host->state = STATE_SENDING_CMD; in atmci_queue_request()
1368 list_add_tail(&slot->queue_node, &host->queue); in atmci_queue_request()
1370 spin_unlock_bh(&host->lock); in atmci_queue_request()
1376 struct atmel_mci *host = slot->host; in atmci_request()
1377 struct device *dev = host->dev; in atmci_request()
1380 WARN_ON(slot->mrq); in atmci_request()
1381 dev_dbg(dev, "MRQ: cmd %u\n", mrq->cmd->opcode); in atmci_request()
1391 if (!test_bit(ATMCI_CARD_PRESENT, &slot->flags)) { in atmci_request()
1392 mrq->cmd->error = -ENOMEDIUM; in atmci_request()
1398 data = mrq->data; in atmci_request()
1399 if (data && data->blocks > 1 && data->blksz & 3) { in atmci_request()
1400 mrq->cmd->error = -EINVAL; in atmci_request()
1410 struct atmel_mci *host = slot->host; in atmci_set_ios()
1413 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK; in atmci_set_ios()
1414 switch (ios->bus_width) { in atmci_set_ios()
1416 slot->sdc_reg |= ATMCI_SDCBUS_1BIT; in atmci_set_ios()
1419 slot->sdc_reg |= ATMCI_SDCBUS_4BIT; in atmci_set_ios()
1422 slot->sdc_reg |= ATMCI_SDCBUS_8BIT; in atmci_set_ios()
1426 if (ios->clock) { in atmci_set_ios()
1428 int clkdiv; in atmci_set_ios() local
1430 spin_lock_bh(&host->lock); in atmci_set_ios()
1431 if (!host->mode_reg) { in atmci_set_ios()
1434 if (host->caps.has_cfg_reg) in atmci_set_ios()
1435 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_set_ios()
1439 * Use mirror of ios->clock to prevent race with mmc in atmci_set_ios()
1442 slot->clock = ios->clock; in atmci_set_ios()
1444 if (host->slot[i] && host->slot[i]->clock in atmci_set_ios()
1445 && host->slot[i]->clock < clock_min) in atmci_set_ios()
1446 clock_min = host->slot[i]->clock; in atmci_set_ios()
1450 if (host->caps.has_odd_clk_div) { in atmci_set_ios()
1451 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; in atmci_set_ios()
1452 if (clkdiv < 0) { in atmci_set_ios()
1453 dev_warn(&mmc->class_dev, in atmci_set_ios()
1455 clock_min, host->bus_hz / 2); in atmci_set_ios()
1456 clkdiv = 0; in atmci_set_ios()
1457 } else if (clkdiv > 511) { in atmci_set_ios()
1458 dev_warn(&mmc->class_dev, in atmci_set_ios()
1460 clock_min, host->bus_hz / (511 + 2)); in atmci_set_ios()
1461 clkdiv = 511; in atmci_set_ios()
1463 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv >> 1) in atmci_set_ios()
1464 | ATMCI_MR_CLKODD(clkdiv & 1); in atmci_set_ios()
1466 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; in atmci_set_ios()
1467 if (clkdiv > 255) { in atmci_set_ios()
1468 dev_warn(&mmc->class_dev, in atmci_set_ios()
1470 clock_min, host->bus_hz / (2 * 256)); in atmci_set_ios()
1471 clkdiv = 255; in atmci_set_ios()
1473 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv); in atmci_set_ios()
1481 if (host->caps.has_rwproof) in atmci_set_ios()
1482 host->mode_reg |= (ATMCI_MR_WRPROOF | ATMCI_MR_RDPROOF); in atmci_set_ios()
1484 if (host->caps.has_cfg_reg) { in atmci_set_ios()
1486 if (ios->timing == MMC_TIMING_SD_HS) in atmci_set_ios()
1487 host->cfg_reg |= ATMCI_CFG_HSMODE; in atmci_set_ios()
1489 host->cfg_reg &= ~ATMCI_CFG_HSMODE; in atmci_set_ios()
1492 if (list_empty(&host->queue)) { in atmci_set_ios()
1493 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_set_ios()
1494 if (host->caps.has_cfg_reg) in atmci_set_ios()
1495 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_set_ios()
1497 host->need_clock_update = true; in atmci_set_ios()
1500 spin_unlock_bh(&host->lock); in atmci_set_ios()
1504 spin_lock_bh(&host->lock); in atmci_set_ios()
1505 slot->clock = 0; in atmci_set_ios()
1507 if (host->slot[i] && host->slot[i]->clock) { in atmci_set_ios()
1514 if (host->mode_reg) { in atmci_set_ios()
1517 host->mode_reg = 0; in atmci_set_ios()
1519 spin_unlock_bh(&host->lock); in atmci_set_ios()
1522 switch (ios->power_mode) { in atmci_set_ios()
1524 if (!IS_ERR(mmc->supply.vmmc)) in atmci_set_ios()
1525 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); in atmci_set_ios()
1528 set_bit(ATMCI_CARD_NEED_INIT, &slot->flags); in atmci_set_ios()
1529 if (!IS_ERR(mmc->supply.vmmc)) in atmci_set_ios()
1530 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); in atmci_set_ios()
1539 int read_only = -ENOSYS; in atmci_get_ro()
1542 if (slot->wp_pin) { in atmci_get_ro()
1543 read_only = gpiod_get_value(slot->wp_pin); in atmci_get_ro()
1544 dev_dbg(&mmc->class_dev, "card is %s\n", in atmci_get_ro()
1545 read_only ? "read-only" : "read-write"); in atmci_get_ro()
1553 int present = -ENOSYS; in atmci_get_cd()
1556 if (slot->detect_pin) { in atmci_get_cd()
1557 present = gpiod_get_value_cansleep(slot->detect_pin); in atmci_get_cd()
1558 dev_dbg(&mmc->class_dev, "card is %spresent\n", in atmci_get_cd()
1568 struct atmel_mci *host = slot->host; in atmci_enable_sdio_irq()
1571 atmci_writel(host, ATMCI_IER, slot->sdio_irq); in atmci_enable_sdio_irq()
1573 atmci_writel(host, ATMCI_IDR, slot->sdio_irq); in atmci_enable_sdio_irq()
1584 /* Called with host->lock held */
1586 __releases(&host->lock) in atmci_request_end()
1587 __acquires(&host->lock) in atmci_request_end()
1590 struct mmc_host *prev_mmc = host->cur_slot->mmc; in atmci_request_end()
1591 struct device *dev = host->dev; in atmci_request_end()
1593 WARN_ON(host->cmd || host->data); in atmci_request_end()
1595 del_timer(&host->timer); in atmci_request_end()
1602 if (host->need_clock_update) { in atmci_request_end()
1603 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_request_end()
1604 if (host->caps.has_cfg_reg) in atmci_request_end()
1605 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_request_end()
1608 host->cur_slot->mrq = NULL; in atmci_request_end()
1609 host->mrq = NULL; in atmci_request_end()
1610 if (!list_empty(&host->queue)) { in atmci_request_end()
1611 slot = list_entry(host->queue.next, in atmci_request_end()
1613 list_del(&slot->queue_node); in atmci_request_end()
1614 dev_vdbg(dev, "list not empty: %s is next\n", mmc_hostname(slot->mmc)); in atmci_request_end()
1615 host->state = STATE_SENDING_CMD; in atmci_request_end()
1619 host->state = STATE_IDLE; in atmci_request_end()
1622 spin_unlock(&host->lock); in atmci_request_end()
1624 spin_lock(&host->lock); in atmci_request_end()
1630 u32 status = host->cmd_status; in atmci_command_complete()
1633 cmd->resp[0] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1634 cmd->resp[1] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1635 cmd->resp[2] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1636 cmd->resp[3] = atmci_readl(host, ATMCI_RSPR); in atmci_command_complete()
1639 cmd->error = -ETIMEDOUT; in atmci_command_complete()
1640 else if ((cmd->flags & MMC_RSP_CRC) && (status & ATMCI_RCRCE)) in atmci_command_complete()
1641 cmd->error = -EILSEQ; in atmci_command_complete()
1643 cmd->error = -EIO; in atmci_command_complete()
1644 else if (host->mrq->data && (host->mrq->data->blksz & 3)) { in atmci_command_complete()
1645 if (host->caps.need_blksz_mul_4) { in atmci_command_complete()
1646 cmd->error = -EINVAL; in atmci_command_complete()
1647 host->need_reset = 1; in atmci_command_complete()
1650 cmd->error = 0; in atmci_command_complete()
1661 * freeing the interrupt. We must not re-enable the interrupt in atmci_detect_change()
1666 if (test_bit(ATMCI_SHUTDOWN, &slot->flags)) in atmci_detect_change()
1669 enable_irq(gpiod_to_irq(slot->detect_pin)); in atmci_detect_change()
1670 present = gpiod_get_value_cansleep(slot->detect_pin); in atmci_detect_change()
1671 present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1673 dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d)\n", in atmci_detect_change()
1677 struct atmel_mci *host = slot->host; in atmci_detect_change()
1680 dev_dbg(&slot->mmc->class_dev, "card %s\n", in atmci_detect_change()
1683 spin_lock(&host->lock); in atmci_detect_change()
1686 clear_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1688 set_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_detect_change()
1691 mrq = slot->mrq; in atmci_detect_change()
1693 if (mrq == host->mrq) { in atmci_detect_change()
1700 atmci_writel(host, ATMCI_MR, host->mode_reg); in atmci_detect_change()
1701 if (host->caps.has_cfg_reg) in atmci_detect_change()
1702 atmci_writel(host, ATMCI_CFG, host->cfg_reg); in atmci_detect_change()
1704 host->data = NULL; in atmci_detect_change()
1705 host->cmd = NULL; in atmci_detect_change()
1707 switch (host->state) { in atmci_detect_change()
1711 mrq->cmd->error = -ENOMEDIUM; in atmci_detect_change()
1712 if (mrq->data) in atmci_detect_change()
1713 host->stop_transfer(host); in atmci_detect_change()
1716 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1717 host->stop_transfer(host); in atmci_detect_change()
1720 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1723 mrq->stop->error = -ENOMEDIUM; in atmci_detect_change()
1731 list_del(&slot->queue_node); in atmci_detect_change()
1732 mrq->cmd->error = -ENOMEDIUM; in atmci_detect_change()
1733 if (mrq->data) in atmci_detect_change()
1734 mrq->data->error = -ENOMEDIUM; in atmci_detect_change()
1735 if (mrq->stop) in atmci_detect_change()
1736 mrq->stop->error = -ENOMEDIUM; in atmci_detect_change()
1738 spin_unlock(&host->lock); in atmci_detect_change()
1739 mmc_request_done(slot->mmc, mrq); in atmci_detect_change()
1740 spin_lock(&host->lock); in atmci_detect_change()
1743 spin_unlock(&host->lock); in atmci_detect_change()
1745 mmc_detect_change(slot->mmc, 0); in atmci_detect_change()
1752 struct mmc_request *mrq = host->mrq; in atmci_work_func()
1753 struct mmc_data *data = host->data; in atmci_work_func()
1754 struct device *dev = host->dev; in atmci_work_func()
1755 enum atmel_mci_state state = host->state; in atmci_work_func()
1759 spin_lock(&host->lock); in atmci_work_func()
1761 state = host->state; in atmci_work_func()
1764 state, host->pending_events, host->completed_events, in atmci_work_func()
1788 host->cmd = NULL; in atmci_work_func()
1790 atmci_command_complete(host, mrq->cmd); in atmci_work_func()
1791 if (mrq->data) { in atmci_work_func()
1797 if (mrq->cmd->error) { in atmci_work_func()
1798 host->stop_transfer(host); in atmci_work_func()
1799 host->data = NULL; in atmci_work_func()
1806 } else if ((!mrq->data) && (mrq->cmd->flags & MMC_RSP_BUSY)) { in atmci_work_func()
1839 if (host->caps.need_notbusy_for_read_ops || in atmci_work_func()
1840 (host->data->flags & MMC_DATA_WRITE)) { in atmci_work_func()
1843 } else if (host->mrq->stop) { in atmci_work_func()
1847 host->data = NULL; in atmci_work_func()
1848 data->bytes_xfered = data->blocks * data->blksz; in atmci_work_func()
1849 data->error = 0; in atmci_work_func()
1869 if (host->data) { in atmci_work_func()
1875 if (host->mrq->stop) { in atmci_work_func()
1879 host->data = NULL; in atmci_work_func()
1880 data->bytes_xfered = data->blocks in atmci_work_func()
1881 * data->blksz; in atmci_work_func()
1882 data->error = 0; in atmci_work_func()
1891 * In this state, it is important to set host->data to in atmci_work_func()
1902 host->cmd = NULL; in atmci_work_func()
1903 data->bytes_xfered = data->blocks * data->blksz; in atmci_work_func()
1904 data->error = 0; in atmci_work_func()
1905 atmci_command_complete(host, mrq->stop); in atmci_work_func()
1906 if (mrq->stop->error) { in atmci_work_func()
1907 host->stop_transfer(host); in atmci_work_func()
1916 host->data = NULL; in atmci_work_func()
1922 status = host->data_status; in atmci_work_func()
1924 host->stop_transfer(host); in atmci_work_func()
1925 host->data = NULL; in atmci_work_func()
1928 data->error = -ETIMEDOUT; in atmci_work_func()
1930 data->error = -EILSEQ; in atmci_work_func()
1932 data->error = -EIO; in atmci_work_func()
1937 atmci_request_end(host, host->mrq); in atmci_work_func()
1938 goto unlock; /* atmci_request_end() sets host->state */ in atmci_work_func()
1943 host->state = state; in atmci_work_func()
1946 spin_unlock(&host->lock); in atmci_work_func()
1951 struct scatterlist *sg = host->sg; in atmci_read_data_pio()
1952 unsigned int offset = host->pio_offset; in atmci_read_data_pio()
1953 struct mmc_data *data = host->data; in atmci_read_data_pio()
1960 if (likely(offset + 4 <= sg->length)) { in atmci_read_data_pio()
1966 if (offset == sg->length) { in atmci_read_data_pio()
1968 host->sg = sg = sg_next(sg); in atmci_read_data_pio()
1969 host->sg_len--; in atmci_read_data_pio()
1970 if (!sg || !host->sg_len) in atmci_read_data_pio()
1976 unsigned int remaining = sg->length - offset; in atmci_read_data_pio()
1982 host->sg = sg = sg_next(sg); in atmci_read_data_pio()
1983 host->sg_len--; in atmci_read_data_pio()
1984 if (!sg || !host->sg_len) in atmci_read_data_pio()
1987 offset = 4 - remaining; in atmci_read_data_pio()
1997 host->data_status = status; in atmci_read_data_pio()
1998 data->bytes_xfered += nbytes; in atmci_read_data_pio()
2003 host->pio_offset = offset; in atmci_read_data_pio()
2004 data->bytes_xfered += nbytes; in atmci_read_data_pio()
2011 data->bytes_xfered += nbytes; in atmci_read_data_pio()
2018 struct scatterlist *sg = host->sg; in atmci_write_data_pio()
2019 unsigned int offset = host->pio_offset; in atmci_write_data_pio()
2020 struct mmc_data *data = host->data; in atmci_write_data_pio()
2026 if (likely(offset + 4 <= sg->length)) { in atmci_write_data_pio()
2032 if (offset == sg->length) { in atmci_write_data_pio()
2033 host->sg = sg = sg_next(sg); in atmci_write_data_pio()
2034 host->sg_len--; in atmci_write_data_pio()
2035 if (!sg || !host->sg_len) in atmci_write_data_pio()
2041 unsigned int remaining = sg->length - offset; in atmci_write_data_pio()
2047 host->sg = sg = sg_next(sg); in atmci_write_data_pio()
2048 host->sg_len--; in atmci_write_data_pio()
2049 if (!sg || !host->sg_len) { in atmci_write_data_pio()
2054 offset = 4 - remaining; in atmci_write_data_pio()
2065 host->data_status = status; in atmci_write_data_pio()
2066 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2071 host->pio_offset = offset; in atmci_write_data_pio()
2072 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2079 data->bytes_xfered += nbytes; in atmci_write_data_pio()
2089 struct atmel_mci_slot *slot = host->slot[i]; in atmci_sdio_interrupt()
2090 if (slot && (status & slot->sdio_irq)) { in atmci_sdio_interrupt()
2091 mmc_signal_sdio_irq(slot->mmc); in atmci_sdio_interrupt()
2100 struct device *dev = host->dev; in atmci_interrupt()
2118 host->data_status = status; in atmci_interrupt()
2122 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2134 if (host->data_size) { in atmci_interrupt()
2145 if (host->data_size) { in atmci_interrupt()
2161 if (host->data_size) { in atmci_interrupt()
2172 if (host->data_size) { in atmci_interrupt()
2191 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2200 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2211 host->cmd_status = status; in atmci_interrupt()
2215 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2236 mod_timer(&slot->detect_timer, jiffies + msecs_to_jiffies(20)); in atmci_detect_interrupt()
2245 struct device *dev = host->dev; in atmci_init_slot()
2252 return -ENOMEM; in atmci_init_slot()
2255 slot->mmc = mmc; in atmci_init_slot()
2256 slot->host = host; in atmci_init_slot()
2257 slot->detect_pin = slot_data->detect_pin; in atmci_init_slot()
2258 slot->wp_pin = slot_data->wp_pin; in atmci_init_slot()
2259 slot->sdc_reg = sdc_reg; in atmci_init_slot()
2260 slot->sdio_irq = sdio_irq; in atmci_init_slot()
2262 dev_dbg(&mmc->class_dev, in atmci_init_slot()
2265 id, slot_data->bus_width, desc_to_gpio(slot_data->detect_pin), in atmci_init_slot()
2266 !gpiod_is_active_low(slot_data->detect_pin) ? "true" : "false", in atmci_init_slot()
2267 desc_to_gpio(slot_data->wp_pin)); in atmci_init_slot()
2269 mmc->ops = &atmci_ops; in atmci_init_slot()
2270 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); in atmci_init_slot()
2271 mmc->f_max = host->bus_hz / 2; in atmci_init_slot()
2272 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; in atmci_init_slot()
2274 mmc->caps |= MMC_CAP_SDIO_IRQ; in atmci_init_slot()
2275 if (host->caps.has_highspeed) in atmci_init_slot()
2276 mmc->caps |= MMC_CAP_SD_HIGHSPEED; in atmci_init_slot()
2282 if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) { in atmci_init_slot()
2283 mmc->caps |= MMC_CAP_4_BIT_DATA; in atmci_init_slot()
2284 if (slot_data->bus_width >= 8) in atmci_init_slot()
2285 mmc->caps |= MMC_CAP_8_BIT_DATA; in atmci_init_slot()
2289 mmc->max_segs = 256; in atmci_init_slot()
2290 mmc->max_blk_size = 4095; in atmci_init_slot()
2291 mmc->max_blk_count = 256; in atmci_init_slot()
2292 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; in atmci_init_slot()
2293 mmc->max_seg_size = mmc->max_blk_size * mmc->max_segs; in atmci_init_slot()
2295 mmc->max_segs = 64; in atmci_init_slot()
2296 mmc->max_req_size = 32768 * 512; in atmci_init_slot()
2297 mmc->max_blk_size = 32768; in atmci_init_slot()
2298 mmc->max_blk_count = 512; in atmci_init_slot()
2302 set_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_init_slot()
2303 if (slot->detect_pin) { in atmci_init_slot()
2304 if (!gpiod_get_value_cansleep(slot->detect_pin)) in atmci_init_slot()
2305 clear_bit(ATMCI_CARD_PRESENT, &slot->flags); in atmci_init_slot()
2307 dev_dbg(&mmc->class_dev, "no detect pin available\n"); in atmci_init_slot()
2310 if (!slot->detect_pin) { in atmci_init_slot()
2311 if (slot_data->non_removable) in atmci_init_slot()
2312 mmc->caps |= MMC_CAP_NONREMOVABLE; in atmci_init_slot()
2314 mmc->caps |= MMC_CAP_NEEDS_POLL; in atmci_init_slot()
2317 if (!slot->wp_pin) in atmci_init_slot()
2318 dev_dbg(&mmc->class_dev, "no WP pin available\n"); in atmci_init_slot()
2320 host->slot[id] = slot; in atmci_init_slot()
2328 if (slot->detect_pin) { in atmci_init_slot()
2329 timer_setup(&slot->detect_timer, atmci_detect_change, 0); in atmci_init_slot()
2331 ret = request_irq(gpiod_to_irq(slot->detect_pin), in atmci_init_slot()
2334 "mmc-detect", slot); in atmci_init_slot()
2336 dev_dbg(&mmc->class_dev, in atmci_init_slot()
2338 gpiod_to_irq(slot->detect_pin)); in atmci_init_slot()
2339 slot->detect_pin = NULL; in atmci_init_slot()
2353 set_bit(ATMCI_SHUTDOWN, &slot->flags); in atmci_cleanup_slot()
2356 mmc_remove_host(slot->mmc); in atmci_cleanup_slot()
2358 if (slot->detect_pin) { in atmci_cleanup_slot()
2359 free_irq(gpiod_to_irq(slot->detect_pin), slot); in atmci_cleanup_slot()
2360 del_timer_sync(&slot->detect_timer); in atmci_cleanup_slot()
2363 slot->host->slot[id] = NULL; in atmci_cleanup_slot()
2364 mmc_free_host(slot->mmc); in atmci_cleanup_slot()
2369 struct device *dev = host->dev; in atmci_configure_dma()
2371 host->dma.chan = dma_request_chan(dev, "rxtx"); in atmci_configure_dma()
2372 if (IS_ERR(host->dma.chan)) in atmci_configure_dma()
2373 return PTR_ERR(host->dma.chan); in atmci_configure_dma()
2375 dev_info(dev, "using %s for DMA transfers\n", dma_chan_name(host->dma.chan)); in atmci_configure_dma()
2377 host->dma_conf.src_addr = host->mapbase + ATMCI_RDR; in atmci_configure_dma()
2378 host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in atmci_configure_dma()
2379 host->dma_conf.src_maxburst = 1; in atmci_configure_dma()
2380 host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR; in atmci_configure_dma()
2381 host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in atmci_configure_dma()
2382 host->dma_conf.dst_maxburst = 1; in atmci_configure_dma()
2383 host->dma_conf.device_fc = false; in atmci_configure_dma()
2395 struct device *dev = host->dev; in atmci_get_cap()
2401 host->caps.has_dma_conf_reg = false; in atmci_get_cap()
2402 host->caps.has_pdc = true; in atmci_get_cap()
2403 host->caps.has_cfg_reg = false; in atmci_get_cap()
2404 host->caps.has_cstor_reg = false; in atmci_get_cap()
2405 host->caps.has_highspeed = false; in atmci_get_cap()
2406 host->caps.has_rwproof = false; in atmci_get_cap()
2407 host->caps.has_odd_clk_div = false; in atmci_get_cap()
2408 host->caps.has_bad_data_ordering = true; in atmci_get_cap()
2409 host->caps.need_reset_after_xfer = true; in atmci_get_cap()
2410 host->caps.need_blksz_mul_4 = true; in atmci_get_cap()
2411 host->caps.need_notbusy_for_read_ops = false; in atmci_get_cap()
2417 host->caps.has_odd_clk_div = true; in atmci_get_cap()
2421 host->caps.has_dma_conf_reg = true; in atmci_get_cap()
2422 host->caps.has_pdc = false; in atmci_get_cap()
2423 host->caps.has_cfg_reg = true; in atmci_get_cap()
2424 host->caps.has_cstor_reg = true; in atmci_get_cap()
2425 host->caps.has_highspeed = true; in atmci_get_cap()
2428 host->caps.has_rwproof = true; in atmci_get_cap()
2429 host->caps.need_blksz_mul_4 = false; in atmci_get_cap()
2430 host->caps.need_notbusy_for_read_ops = true; in atmci_get_cap()
2433 host->caps.has_bad_data_ordering = false; in atmci_get_cap()
2434 host->caps.need_reset_after_xfer = false; in atmci_get_cap()
2439 host->caps.has_pdc = false; in atmci_get_cap()
2447 struct device *dev = &pdev->dev; in atmci_probe()
2456 return -ENXIO; in atmci_probe()
2464 return -ENOMEM; in atmci_probe()
2466 host->dev = dev; in atmci_probe()
2467 spin_lock_init(&host->lock); in atmci_probe()
2468 INIT_LIST_HEAD(&host->queue); in atmci_probe()
2474 host->mck = devm_clk_get(dev, "mci_clk"); in atmci_probe()
2475 if (IS_ERR(host->mck)) in atmci_probe()
2476 return PTR_ERR(host->mck); in atmci_probe()
2478 host->regs = devm_ioremap(dev, regs->start, resource_size(regs)); in atmci_probe()
2479 if (!host->regs) in atmci_probe()
2480 return -ENOMEM; in atmci_probe()
2482 ret = clk_prepare_enable(host->mck); in atmci_probe()
2487 host->bus_hz = clk_get_rate(host->mck); in atmci_probe()
2489 host->mapbase = regs->start; in atmci_probe()
2491 INIT_WORK(&host->bh_work, atmci_work_func); in atmci_probe()
2495 clk_disable_unprepare(host->mck); in atmci_probe()
2502 if (ret == -EPROBE_DEFER) in atmci_probe()
2505 host->prepare_data = &atmci_prepare_data_dma; in atmci_probe()
2506 host->submit_data = &atmci_submit_data_dma; in atmci_probe()
2507 host->stop_transfer = &atmci_stop_transfer_dma; in atmci_probe()
2508 } else if (host->caps.has_pdc) { in atmci_probe()
2510 host->prepare_data = &atmci_prepare_data_pdc; in atmci_probe()
2511 host->submit_data = &atmci_submit_data_pdc; in atmci_probe()
2512 host->stop_transfer = &atmci_stop_transfer_pdc; in atmci_probe()
2515 host->prepare_data = &atmci_prepare_data; in atmci_probe()
2516 host->submit_data = &atmci_submit_data; in atmci_probe()
2517 host->stop_transfer = &atmci_stop_transfer; in atmci_probe()
2522 timer_setup(&host->timer, atmci_timeout_timer, 0); in atmci_probe()
2532 ret = -ENODEV; in atmci_probe()
2533 if (host->pdata[0].bus_width) { in atmci_probe()
2534 ret = atmci_init_slot(host, &host->pdata[0], in atmci_probe()
2538 host->buf_size = host->slot[0]->mmc->max_req_size; in atmci_probe()
2541 if (host->pdata[1].bus_width) { in atmci_probe()
2542 ret = atmci_init_slot(host, &host->pdata[1], in atmci_probe()
2546 if (host->slot[1]->mmc->max_req_size > host->buf_size) in atmci_probe()
2547 host->buf_size = in atmci_probe()
2548 host->slot[1]->mmc->max_req_size; in atmci_probe()
2557 if (!host->caps.has_rwproof) { in atmci_probe()
2558 host->buffer = dma_alloc_coherent(dev, host->buf_size, in atmci_probe()
2559 &host->buf_phys_addr, in atmci_probe()
2561 if (!host->buffer) { in atmci_probe()
2562 ret = dev_err_probe(dev, -ENOMEM, "buffer allocation failed\n"); in atmci_probe()
2568 host->mapbase, irq, nr_slots); in atmci_probe()
2577 if (host->slot[i]) in atmci_probe()
2578 atmci_cleanup_slot(host->slot[i], i); in atmci_probe()
2581 clk_disable_unprepare(host->mck); in atmci_probe()
2586 del_timer_sync(&host->timer); in atmci_probe()
2587 if (!IS_ERR(host->dma.chan)) in atmci_probe()
2588 dma_release_channel(host->dma.chan); in atmci_probe()
2597 struct device *dev = &pdev->dev; in atmci_remove()
2602 if (host->buffer) in atmci_remove()
2603 dma_free_coherent(dev, host->buf_size, host->buffer, host->buf_phys_addr); in atmci_remove()
2606 if (host->slot[i]) in atmci_remove()
2607 atmci_cleanup_slot(host->slot[i], i); in atmci_remove()
2614 del_timer_sync(&host->timer); in atmci_remove()
2615 if (!IS_ERR(host->dma.chan)) in atmci_remove()
2616 dma_release_channel(host->dma.chan); in atmci_remove()
2620 clk_disable_unprepare(host->mck); in atmci_remove()
2631 clk_disable_unprepare(host->mck); in atmci_runtime_suspend()
2644 return clk_prepare_enable(host->mck); in atmci_runtime_resume()