Lines Matching full:host

29 #include <linux/mmc/host.h>
377 u32 (*prepare_data)(struct atmel_mci *host, struct mmc_data *data);
378 void (*submit_data)(struct atmel_mci *host, struct mmc_data *data);
379 void (*stop_transfer)(struct atmel_mci *host);
385 * @host: The MMC controller this slot is using.
392 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
402 struct atmel_mci *host; member
422 #define atmci_test_and_clear_pending(host, event) \ argument
423 test_and_clear_bit(event, &host->pending_events)
424 #define atmci_set_completed(host, event) \ argument
425 set_bit(event, &host->completed_events)
426 #define atmci_set_pending(host, event) \ argument
427 set_bit(event, &host->pending_events)
442 spin_lock_bh(&slot->host->lock); 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() local
524 struct device *dev = host->dev; 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()
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()
605 struct atmel_mci *host = slot->host; in atmci_init_debugfs() local
612 debugfs_create_file("regs", S_IRUSR, root, host, &atmci_regs_fops); 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()
628 static int atmci_of_init(struct atmel_mci *host) in atmci_of_init() argument
630 struct device *dev = host->dev; 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()
659 err = PTR_ERR_OR_ZERO(host->pdata[slot_id].detect_pin); 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()
671 host->pdata[slot_id].wp_pin = in atmci_of_init()
674 err = PTR_ERR_OR_ZERO(host->pdata[slot_id].wp_pin); in atmci_of_init()
680 host->pdata[slot_id].wp_pin = NULL; in atmci_of_init()
687 static inline unsigned int atmci_get_version(struct atmel_mci *host) in atmci_get_version() argument
689 return atmci_readl(host, ATMCI_VERSION) & 0x00000fff; in atmci_get_version()
700 static inline unsigned int atmci_convert_chksize(struct atmel_mci *host, in atmci_convert_chksize() argument
703 unsigned int version = atmci_get_version(host); in atmci_convert_chksize()
717 struct atmel_mci *host = from_timer(host, t, timer); in atmci_timeout_timer() local
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()
742 static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host, in atmci_ns_to_clocks() argument
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()
755 static void atmci_set_timeout(struct atmel_mci *host, in atmci_set_timeout() argument
765 timeout = atmci_ns_to_clocks(host, data->timeout_ns) in atmci_set_timeout()
782 atmci_writel(host, ATMCI_DTOR, (ATMCI_DTOMUL(dtomul) | ATMCI_DTOCYC(dtocyc))); in atmci_set_timeout()
835 static void atmci_send_command(struct atmel_mci *host, in atmci_send_command() argument
838 struct device *dev = host->dev; in atmci_send_command()
842 WARN_ON(host->cmd); in atmci_send_command()
843 host->cmd = cmd; in atmci_send_command()
847 atmci_writel(host, ATMCI_ARGR, cmd->arg); in atmci_send_command()
848 atmci_writel(host, ATMCI_CMDR, cmd_flags); in atmci_send_command()
850 mod_timer(&host->timer, jiffies + msecs_to_jiffies(timeout_ms)); in atmci_send_command()
853 static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data) in atmci_send_stop_cmd() argument
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()
859 atmci_writel(host, ATMCI_IER, ATMCI_CMDRDY); in atmci_send_stop_cmd()
864 * Update host->data_size and host->sg.
866 static void atmci_pdc_set_single_buf(struct atmel_mci *host, in atmci_pdc_set_single_buf() argument
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()
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()
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()
917 static void atmci_pdc_set_both_buf(struct atmel_mci *host, int dir) in atmci_pdc_set_both_buf() argument
919 atmci_pdc_set_single_buf(host, dir, PDC_FIRST_BUF); in atmci_pdc_set_both_buf()
920 if (host->data_size) in atmci_pdc_set_both_buf()
921 atmci_pdc_set_single_buf(host, dir, PDC_SECOND_BUF); in atmci_pdc_set_both_buf()
927 static void atmci_pdc_cleanup(struct atmel_mci *host) in atmci_pdc_cleanup() argument
929 struct mmc_data *data = host->data; in atmci_pdc_cleanup()
930 struct device *dev = host->dev; in atmci_pdc_cleanup()
941 static void atmci_pdc_complete(struct atmel_mci *host) in atmci_pdc_complete() argument
943 struct device *dev = host->dev; in atmci_pdc_complete()
944 int transfer_size = host->data->blocks * host->data->blksz; in atmci_pdc_complete()
947 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); 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()
958 atmci_pdc_cleanup(host); in atmci_pdc_complete()
961 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_pdc_complete()
962 queue_work(system_bh_wq, &host->bh_work); in atmci_pdc_complete()
965 static void atmci_dma_cleanup(struct atmel_mci *host) in atmci_dma_cleanup() argument
967 struct mmc_data *data = host->data; in atmci_dma_cleanup()
970 dma_unmap_sg(host->dma.chan->device->dev, in atmci_dma_cleanup()
980 struct atmel_mci *host = arg; in atmci_dma_complete() local
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()
988 atmci_writel(host, ATMCI_DMA, atmci_readl(host, ATMCI_DMA) & ~ATMCI_DMAEN); in atmci_dma_complete()
990 atmci_dma_cleanup(host); in atmci_dma_complete()
998 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_dma_complete()
999 queue_work(system_bh_wq, &host->bh_work); in atmci_dma_complete()
1021 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_dma_complete()
1029 static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data) in atmci_prepare_data() argument
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()
1051 host->need_reset = true; in atmci_prepare_data()
1053 host->pio_offset = 0; in atmci_prepare_data()
1069 atmci_prepare_data_pdc(struct atmel_mci *host, struct mmc_data *data) in atmci_prepare_data_pdc() argument
1071 struct device *dev = host->dev; 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()
1090 tmp = atmci_readl(host, ATMCI_MR); in atmci_prepare_data_pdc()
1093 atmci_writel(host, ATMCI_MR, tmp); in atmci_prepare_data_pdc()
1096 host->data_size = data->blocks * data->blksz; 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()
1115 atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data) in atmci_prepare_data_dma() argument
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()
1140 return atmci_prepare_data(host, data); in atmci_prepare_data_dma()
1142 return atmci_prepare_data(host, data); in atmci_prepare_data_dma()
1146 return atmci_prepare_data(host, data); in atmci_prepare_data_dma()
1150 if (!host->dma.chan) 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()
1157 host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; in atmci_prepare_data_dma()
1158 maxburst = atmci_convert_chksize(host, 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()
1162 maxburst = atmci_convert_chksize(host, 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()
1167 atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(maxburst) | in atmci_prepare_data_dma()
1173 dmaengine_slave_config(chan, &host->dma_conf); in atmci_prepare_data_dma()
1180 host->dma.data_desc = desc; in atmci_prepare_data_dma()
1182 desc->callback_param = host; in atmci_prepare_data_dma()
1192 atmci_submit_data(struct atmel_mci *host, struct mmc_data *data) in atmci_submit_data() argument
1201 atmci_submit_data_pdc(struct atmel_mci *host, struct mmc_data *data) in atmci_submit_data_pdc() argument
1204 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN); in atmci_submit_data_pdc()
1206 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); in atmci_submit_data_pdc()
1210 atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data) in atmci_submit_data_dma() argument
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()
1221 static void atmci_stop_transfer(struct atmel_mci *host) in atmci_stop_transfer() argument
1223 struct device *dev = host->dev; in atmci_stop_transfer()
1226 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_stop_transfer()
1227 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_stop_transfer()
1233 static void atmci_stop_transfer_pdc(struct atmel_mci *host) in atmci_stop_transfer_pdc() argument
1235 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); in atmci_stop_transfer_pdc()
1238 static void atmci_stop_transfer_dma(struct atmel_mci *host) in atmci_stop_transfer_dma() argument
1240 struct dma_chan *chan = host->data_chan; in atmci_stop_transfer_dma()
1241 struct device *dev = host->dev; in atmci_stop_transfer_dma()
1245 atmci_dma_cleanup(host); in atmci_stop_transfer_dma()
1249 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_stop_transfer_dma()
1250 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_stop_transfer_dma()
1258 static void atmci_start_request(struct atmel_mci *host, in atmci_start_request() argument
1261 struct device *dev = host->dev; 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()
1279 if (host->need_reset || host->caps.need_reset_after_xfer) { in atmci_start_request()
1280 iflags = atmci_readl(host, ATMCI_IMR); in atmci_start_request()
1282 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); in atmci_start_request()
1283 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); 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()
1287 atmci_writel(host, ATMCI_IER, iflags); 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()
1292 iflags = atmci_readl(host, ATMCI_IMR); in atmci_start_request()
1299 atmci_writel(host, ATMCI_CMDR, ATMCI_CMDR_SPCMD_INIT); in atmci_start_request()
1300 while (!(atmci_readl(host, ATMCI_SR) & ATMCI_CMDRDY)) in atmci_start_request()
1306 atmci_set_timeout(host, slot, data); in atmci_start_request()
1309 atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks) in atmci_start_request()
1314 iflags |= host->prepare_data(host, data); in atmci_start_request()
1327 if (host->submit_data != &atmci_submit_data_dma) in atmci_start_request()
1328 atmci_send_command(host, cmd, cmdflags); 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()
1334 atmci_send_command(host, cmd, cmdflags); 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()
1340 host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ; in atmci_start_request()
1341 host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK; in atmci_start_request()
1350 atmci_writel(host, ATMCI_IER, iflags); in atmci_start_request()
1353 static void atmci_queue_request(struct atmel_mci *host, in atmci_queue_request() argument
1356 struct device *dev = host->dev; in atmci_queue_request()
1359 host->state); in atmci_queue_request()
1361 spin_lock_bh(&host->lock); in atmci_queue_request()
1363 if (host->state == STATE_IDLE) { in atmci_queue_request()
1364 host->state = STATE_SENDING_CMD; in atmci_queue_request()
1365 atmci_start_request(host, slot); 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() local
1377 struct device *dev = host->dev; in atmci_request()
1404 atmci_queue_request(host, slot, mrq); in atmci_request()
1410 struct atmel_mci *host = slot->host; in atmci_set_ios() local
1430 spin_lock_bh(&host->lock); in atmci_set_ios()
1431 if (!host->mode_reg) { in atmci_set_ios()
1432 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); in atmci_set_ios()
1433 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); 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()
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()
1455 clock_min, host->bus_hz / 2); in atmci_set_ios()
1460 clock_min, host->bus_hz / (511 + 2)); in atmci_set_ios()
1463 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv >> 1) in atmci_set_ios()
1466 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; in atmci_set_ios()
1470 clock_min, host->bus_hz / (2 * 256)); 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()
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()
1507 if (host->slot[i] && host->slot[i]->clock) { in atmci_set_ios()
1513 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); in atmci_set_ios()
1514 if (host->mode_reg) { in atmci_set_ios()
1515 atmci_readl(host, ATMCI_MR); in atmci_set_ios()
1517 host->mode_reg = 0; in atmci_set_ios()
1519 spin_unlock_bh(&host->lock); in atmci_set_ios()
1568 struct atmel_mci *host = slot->host; in atmci_enable_sdio_irq() local
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 */
1585 static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq) in atmci_request_end() argument
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()
1615 host->state = STATE_SENDING_CMD; in atmci_request_end()
1616 atmci_start_request(host, slot); 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()
1627 static void atmci_command_complete(struct atmel_mci *host, in atmci_command_complete() argument
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()
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()
1647 host->need_reset = 1; in atmci_command_complete()
1677 struct atmel_mci *host = slot->host; in atmci_detect_change() local
1683 spin_lock(&host->lock); in atmci_detect_change()
1693 if (mrq == host->mrq) { in atmci_detect_change()
1698 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); in atmci_detect_change()
1699 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); 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()
1713 host->stop_transfer(host); in atmci_detect_change()
1717 host->stop_transfer(host); in atmci_detect_change()
1729 atmci_request_end(host, mrq); in atmci_detect_change()
1738 spin_unlock(&host->lock); in atmci_detect_change()
1740 spin_lock(&host->lock); in atmci_detect_change()
1743 spin_unlock(&host->lock); in atmci_detect_change()
1751 struct atmel_mci *host = from_work(host, t, bh_work); in atmci_work_func() local
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()
1765 atmci_readl(host, ATMCI_IMR)); in atmci_work_func()
1783 if (!atmci_test_and_clear_pending(host, in atmci_work_func()
1788 host->cmd = NULL; in atmci_work_func()
1789 atmci_set_completed(host, EVENT_CMD_RDY); in atmci_work_func()
1790 atmci_command_complete(host, mrq->cmd); in atmci_work_func()
1798 host->stop_transfer(host); in atmci_work_func()
1799 host->data = NULL; in atmci_work_func()
1800 atmci_writel(host, ATMCI_IDR, in atmci_work_func()
1808 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_work_func()
1816 if (atmci_test_and_clear_pending(host, in atmci_work_func()
1819 atmci_set_completed(host, EVENT_DATA_ERROR); in atmci_work_func()
1832 if (!atmci_test_and_clear_pending(host, in atmci_work_func()
1837 atmci_set_completed(host, EVENT_XFER_COMPLETE); 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()
1841 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_work_func()
1843 } else if (host->mrq->stop) { in atmci_work_func()
1844 atmci_send_stop_cmd(host, data); in atmci_work_func()
1847 host->data = NULL; in atmci_work_func()
1862 if (!atmci_test_and_clear_pending(host, in atmci_work_func()
1867 atmci_set_completed(host, EVENT_NOTBUSY); in atmci_work_func()
1869 if (host->data) { in atmci_work_func()
1875 if (host->mrq->stop) { in atmci_work_func()
1876 atmci_send_stop_cmd(host, data); in atmci_work_func()
1879 host->data = NULL; in atmci_work_func()
1891 * In this state, it is important to set host->data to in atmci_work_func()
1897 if (!atmci_test_and_clear_pending(host, in atmci_work_func()
1902 host->cmd = NULL; in atmci_work_func()
1905 atmci_command_complete(host, mrq->stop); in atmci_work_func()
1907 host->stop_transfer(host); in atmci_work_func()
1908 atmci_writel(host, ATMCI_IDR, in atmci_work_func()
1913 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_work_func()
1916 host->data = NULL; in atmci_work_func()
1920 atmci_writel(host, ATMCI_IDR, ATMCI_TXRDY | ATMCI_RXRDY 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()
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()
1949 static void atmci_read_data_pio(struct atmel_mci *host) in atmci_read_data_pio() argument
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()
1959 value = atmci_readl(host, ATMCI_RDR); 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()
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()
1993 status = atmci_readl(host, ATMCI_SR); in atmci_read_data_pio()
1995 atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_RXRDY in atmci_read_data_pio()
1997 host->data_status = status; in atmci_read_data_pio()
2003 host->pio_offset = offset; in atmci_read_data_pio()
2009 atmci_writel(host, ATMCI_IDR, ATMCI_RXRDY); in atmci_read_data_pio()
2010 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_read_data_pio()
2013 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_read_data_pio()
2016 static void atmci_write_data_pio(struct atmel_mci *host) in atmci_write_data_pio() argument
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()
2028 atmci_writel(host, ATMCI_TDR, value); 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()
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()
2050 atmci_writel(host, ATMCI_TDR, value); in atmci_write_data_pio()
2057 atmci_writel(host, ATMCI_TDR, value); in atmci_write_data_pio()
2061 status = atmci_readl(host, ATMCI_SR); in atmci_write_data_pio()
2063 atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_TXRDY in atmci_write_data_pio()
2065 host->data_status = status; in atmci_write_data_pio()
2071 host->pio_offset = offset; in atmci_write_data_pio()
2077 atmci_writel(host, ATMCI_IDR, ATMCI_TXRDY); in atmci_write_data_pio()
2078 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); in atmci_write_data_pio()
2081 atmci_set_pending(host, EVENT_XFER_COMPLETE); in atmci_write_data_pio()
2084 static void atmci_sdio_interrupt(struct atmel_mci *host, u32 status) in atmci_sdio_interrupt() argument
2089 struct atmel_mci_slot *slot = host->slot[i]; in atmci_sdio_interrupt()
2099 struct atmel_mci *host = dev_id; in atmci_interrupt() local
2100 struct device *dev = host->dev; in atmci_interrupt()
2105 status = atmci_readl(host, ATMCI_SR); in atmci_interrupt()
2106 mask = atmci_readl(host, ATMCI_IMR); in atmci_interrupt()
2113 atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS in atmci_interrupt()
2118 host->data_status = status; in atmci_interrupt()
2121 atmci_set_pending(host, EVENT_DATA_ERROR); in atmci_interrupt()
2122 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2127 atmci_writel(host, ATMCI_IDR, ATMCI_TXBUFE); in atmci_interrupt()
2128 atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX); in atmci_interrupt()
2134 if (host->data_size) { in atmci_interrupt()
2135 atmci_pdc_set_both_buf(host, XFER_TRANSMIT); in atmci_interrupt()
2136 atmci_writel(host, ATMCI_IER, ATMCI_ENDTX); in atmci_interrupt()
2137 atmci_writel(host, ATMCI_IER, ATMCI_TXBUFE); in atmci_interrupt()
2139 atmci_pdc_complete(host); in atmci_interrupt()
2143 atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX); in atmci_interrupt()
2145 if (host->data_size) { in atmci_interrupt()
2146 atmci_pdc_set_single_buf(host, in atmci_interrupt()
2148 atmci_writel(host, ATMCI_IER, ATMCI_ENDTX); in atmci_interrupt()
2154 atmci_writel(host, ATMCI_IDR, ATMCI_RXBUFF); in atmci_interrupt()
2155 atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX); in atmci_interrupt()
2161 if (host->data_size) { in atmci_interrupt()
2162 atmci_pdc_set_both_buf(host, XFER_RECEIVE); in atmci_interrupt()
2163 atmci_writel(host, ATMCI_IER, ATMCI_ENDRX); in atmci_interrupt()
2164 atmci_writel(host, ATMCI_IER, ATMCI_RXBUFF); in atmci_interrupt()
2166 atmci_pdc_complete(host); in atmci_interrupt()
2170 atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX); in atmci_interrupt()
2172 if (host->data_size) { in atmci_interrupt()
2173 atmci_pdc_set_single_buf(host, in atmci_interrupt()
2175 atmci_writel(host, ATMCI_IER, ATMCI_ENDRX); in atmci_interrupt()
2187 atmci_writel(host, ATMCI_IDR, ATMCI_BLKE); in atmci_interrupt()
2190 atmci_set_pending(host, EVENT_NOTBUSY); in atmci_interrupt()
2191 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2196 atmci_writel(host, ATMCI_IDR, ATMCI_NOTBUSY); in atmci_interrupt()
2199 atmci_set_pending(host, EVENT_NOTBUSY); in atmci_interrupt()
2200 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2204 atmci_read_data_pio(host); in atmci_interrupt()
2206 atmci_write_data_pio(host); in atmci_interrupt()
2210 atmci_writel(host, ATMCI_IDR, ATMCI_CMDRDY); in atmci_interrupt()
2211 host->cmd_status = status; in atmci_interrupt()
2214 atmci_set_pending(host, EVENT_CMD_RDY); in atmci_interrupt()
2215 queue_work(system_bh_wq, &host->bh_work); in atmci_interrupt()
2219 atmci_sdio_interrupt(host, status); in atmci_interrupt()
2241 static int atmci_init_slot(struct atmel_mci *host, in atmci_init_slot() argument
2245 struct device *dev = host->dev; in atmci_init_slot()
2256 slot->host = host; 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()
2275 if (host->caps.has_highspeed) in atmci_init_slot()
2282 if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) { in atmci_init_slot()
2288 if (atmci_get_version(host) < 0x200) { in atmci_init_slot()
2320 host->slot[id] = slot; in atmci_init_slot()
2363 slot->host->slot[id] = NULL; in atmci_cleanup_slot()
2367 static int atmci_configure_dma(struct atmel_mci *host) in atmci_configure_dma() argument
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()
2393 static void atmci_get_cap(struct atmel_mci *host) in atmci_get_cap() argument
2395 struct device *dev = host->dev; in atmci_get_cap()
2398 version = atmci_get_version(host); 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()
2448 struct atmel_mci *host; in atmci_probe() local
2462 host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); in atmci_probe()
2463 if (!host) 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()
2470 ret = atmci_of_init(host); 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()
2482 ret = clk_prepare_enable(host->mck); in atmci_probe()
2486 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); 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()
2493 ret = request_irq(irq, atmci_interrupt, 0, dev_name(dev), host); in atmci_probe()
2495 clk_disable_unprepare(host->mck); in atmci_probe()
2500 atmci_get_cap(host); in atmci_probe()
2501 ret = atmci_configure_dma(host); 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()
2520 platform_set_drvdata(pdev, host); in atmci_probe()
2522 timer_setup(&host->timer, atmci_timeout_timer, 0); 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()
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()
2590 free_irq(irq, host); in atmci_probe()
2596 struct atmel_mci *host = platform_get_drvdata(pdev); in atmci_remove() local
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()
2610 atmci_writel(host, ATMCI_IDR, ~0UL); in atmci_remove()
2611 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); in atmci_remove()
2612 atmci_readl(host, ATMCI_SR); 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()
2618 free_irq(platform_get_irq(pdev, 0), host); in atmci_remove()
2620 clk_disable_unprepare(host->mck); in atmci_remove()
2629 struct atmel_mci *host = dev_get_drvdata(dev); in atmci_runtime_suspend() local
2631 clk_disable_unprepare(host->mck); in atmci_runtime_suspend()
2640 struct atmel_mci *host = dev_get_drvdata(dev); in atmci_runtime_resume() local
2644 return clk_prepare_enable(host->mck); in atmci_runtime_resume()