Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Synopsys DesignWare Multimedia Card Interface driver |
| 3 | * (Based on NXP driver for lpc 31xx) |
| 4 | * |
| 5 | * Copyright (C) 2009 NXP Semiconductors |
| 6 | * Copyright (C) 2009, 2010 Imagination Technologies Ltd. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/blkdev.h> |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/debugfs.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/dma-mapping.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/ioport.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/platform_device.h> |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 25 | #include <linux/seq_file.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/stat.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/irq.h> |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 30 | #include <linux/mmc/card.h> |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 31 | #include <linux/mmc/host.h> |
| 32 | #include <linux/mmc/mmc.h> |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 33 | #include <linux/mmc/sd.h> |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 34 | #include <linux/mmc/sdio.h> |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 35 | #include <linux/mmc/dw_mmc.h> |
| 36 | #include <linux/bitops.h> |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 37 | #include <linux/regulator/consumer.h> |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 38 | #include <linux/of.h> |
Doug Anderson | 55a6ceb | 2013-01-11 17:03:53 +0000 | [diff] [blame] | 39 | #include <linux/of_gpio.h> |
Zhangfei Gao | bf626e5 | 2014-01-09 22:35:10 +0800 | [diff] [blame] | 40 | #include <linux/mmc/slot-gpio.h> |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 41 | |
| 42 | #include "dw_mmc.h" |
| 43 | |
| 44 | /* Common flag combinations */ |
Jaehoon Chung | 3f7eec6 | 2013-05-27 13:47:57 +0900 | [diff] [blame] | 45 | #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 46 | SDMMC_INT_HTO | SDMMC_INT_SBE | \ |
| 47 | SDMMC_INT_EBE) |
| 48 | #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \ |
| 49 | SDMMC_INT_RESP_ERR) |
| 50 | #define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \ |
| 51 | DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE) |
| 52 | #define DW_MCI_SEND_STATUS 1 |
| 53 | #define DW_MCI_RECV_STATUS 2 |
| 54 | #define DW_MCI_DMA_THRESHOLD 16 |
| 55 | |
Seungwon Jeon | 1f44a2a | 2013-08-31 00:13:31 +0900 | [diff] [blame] | 56 | #define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */ |
| 57 | #define DW_MCI_FREQ_MIN 400000 /* unit: HZ */ |
| 58 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 59 | #ifdef CONFIG_MMC_DW_IDMAC |
Joonyoung Shim | fc79a4d | 2013-04-26 15:35:22 +0900 | [diff] [blame] | 60 | #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \ |
| 61 | SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \ |
| 62 | SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \ |
| 63 | SDMMC_IDMAC_INT_TI) |
| 64 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 65 | struct idmac_desc_64addr { |
| 66 | u32 des0; /* Control Descriptor */ |
| 67 | |
| 68 | u32 des1; /* Reserved */ |
| 69 | |
| 70 | u32 des2; /*Buffer sizes */ |
| 71 | #define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \ |
| 72 | ((d)->des2 = ((d)->des2 & 0x03ffe000) | ((s) & 0x1fff)) |
| 73 | |
| 74 | u32 des3; /* Reserved */ |
| 75 | |
| 76 | u32 des4; /* Lower 32-bits of Buffer Address Pointer 1*/ |
| 77 | u32 des5; /* Upper 32-bits of Buffer Address Pointer 1*/ |
| 78 | |
| 79 | u32 des6; /* Lower 32-bits of Next Descriptor Address */ |
| 80 | u32 des7; /* Upper 32-bits of Next Descriptor Address */ |
| 81 | }; |
| 82 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 83 | struct idmac_desc { |
| 84 | u32 des0; /* Control Descriptor */ |
| 85 | #define IDMAC_DES0_DIC BIT(1) |
| 86 | #define IDMAC_DES0_LD BIT(2) |
| 87 | #define IDMAC_DES0_FD BIT(3) |
| 88 | #define IDMAC_DES0_CH BIT(4) |
| 89 | #define IDMAC_DES0_ER BIT(5) |
| 90 | #define IDMAC_DES0_CES BIT(30) |
| 91 | #define IDMAC_DES0_OWN BIT(31) |
| 92 | |
| 93 | u32 des1; /* Buffer sizes */ |
| 94 | #define IDMAC_SET_BUFFER1_SIZE(d, s) \ |
Shashidhar Hiremath | 9b7bbe1 | 2011-07-29 08:49:50 -0400 | [diff] [blame] | 95 | ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 96 | |
| 97 | u32 des2; /* buffer 1 physical address */ |
| 98 | |
| 99 | u32 des3; /* buffer 2 physical address */ |
| 100 | }; |
| 101 | #endif /* CONFIG_MMC_DW_IDMAC */ |
| 102 | |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 103 | static bool dw_mci_reset(struct dw_mci *host); |
Sonny Rao | 536f6b9 | 2014-10-16 09:58:05 -0700 | [diff] [blame] | 104 | static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset); |
Doug Anderson | 0bdbd0e | 2015-02-20 12:31:56 -0800 | [diff] [blame] | 105 | static int dw_mci_card_busy(struct mmc_host *mmc); |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 106 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 107 | #if defined(CONFIG_DEBUG_FS) |
| 108 | static int dw_mci_req_show(struct seq_file *s, void *v) |
| 109 | { |
| 110 | struct dw_mci_slot *slot = s->private; |
| 111 | struct mmc_request *mrq; |
| 112 | struct mmc_command *cmd; |
| 113 | struct mmc_command *stop; |
| 114 | struct mmc_data *data; |
| 115 | |
| 116 | /* Make sure we get a consistent snapshot */ |
| 117 | spin_lock_bh(&slot->host->lock); |
| 118 | mrq = slot->mrq; |
| 119 | |
| 120 | if (mrq) { |
| 121 | cmd = mrq->cmd; |
| 122 | data = mrq->data; |
| 123 | stop = mrq->stop; |
| 124 | |
| 125 | if (cmd) |
| 126 | seq_printf(s, |
| 127 | "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n", |
| 128 | cmd->opcode, cmd->arg, cmd->flags, |
| 129 | cmd->resp[0], cmd->resp[1], cmd->resp[2], |
| 130 | cmd->resp[2], cmd->error); |
| 131 | if (data) |
| 132 | seq_printf(s, "DATA %u / %u * %u flg %x err %d\n", |
| 133 | data->bytes_xfered, data->blocks, |
| 134 | data->blksz, data->flags, data->error); |
| 135 | if (stop) |
| 136 | seq_printf(s, |
| 137 | "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n", |
| 138 | stop->opcode, stop->arg, stop->flags, |
| 139 | stop->resp[0], stop->resp[1], stop->resp[2], |
| 140 | stop->resp[2], stop->error); |
| 141 | } |
| 142 | |
| 143 | spin_unlock_bh(&slot->host->lock); |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static int dw_mci_req_open(struct inode *inode, struct file *file) |
| 149 | { |
| 150 | return single_open(file, dw_mci_req_show, inode->i_private); |
| 151 | } |
| 152 | |
| 153 | static const struct file_operations dw_mci_req_fops = { |
| 154 | .owner = THIS_MODULE, |
| 155 | .open = dw_mci_req_open, |
| 156 | .read = seq_read, |
| 157 | .llseek = seq_lseek, |
| 158 | .release = single_release, |
| 159 | }; |
| 160 | |
| 161 | static int dw_mci_regs_show(struct seq_file *s, void *v) |
| 162 | { |
| 163 | seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS); |
| 164 | seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS); |
| 165 | seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD); |
| 166 | seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL); |
| 167 | seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK); |
| 168 | seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int dw_mci_regs_open(struct inode *inode, struct file *file) |
| 174 | { |
| 175 | return single_open(file, dw_mci_regs_show, inode->i_private); |
| 176 | } |
| 177 | |
| 178 | static const struct file_operations dw_mci_regs_fops = { |
| 179 | .owner = THIS_MODULE, |
| 180 | .open = dw_mci_regs_open, |
| 181 | .read = seq_read, |
| 182 | .llseek = seq_lseek, |
| 183 | .release = single_release, |
| 184 | }; |
| 185 | |
| 186 | static void dw_mci_init_debugfs(struct dw_mci_slot *slot) |
| 187 | { |
| 188 | struct mmc_host *mmc = slot->mmc; |
| 189 | struct dw_mci *host = slot->host; |
| 190 | struct dentry *root; |
| 191 | struct dentry *node; |
| 192 | |
| 193 | root = mmc->debugfs_root; |
| 194 | if (!root) |
| 195 | return; |
| 196 | |
| 197 | node = debugfs_create_file("regs", S_IRUSR, root, host, |
| 198 | &dw_mci_regs_fops); |
| 199 | if (!node) |
| 200 | goto err; |
| 201 | |
| 202 | node = debugfs_create_file("req", S_IRUSR, root, slot, |
| 203 | &dw_mci_req_fops); |
| 204 | if (!node) |
| 205 | goto err; |
| 206 | |
| 207 | node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state); |
| 208 | if (!node) |
| 209 | goto err; |
| 210 | |
| 211 | node = debugfs_create_x32("pending_events", S_IRUSR, root, |
| 212 | (u32 *)&host->pending_events); |
| 213 | if (!node) |
| 214 | goto err; |
| 215 | |
| 216 | node = debugfs_create_x32("completed_events", S_IRUSR, root, |
| 217 | (u32 *)&host->completed_events); |
| 218 | if (!node) |
| 219 | goto err; |
| 220 | |
| 221 | return; |
| 222 | |
| 223 | err: |
| 224 | dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n"); |
| 225 | } |
| 226 | #endif /* defined(CONFIG_DEBUG_FS) */ |
| 227 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 228 | static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg); |
| 229 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 230 | static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) |
| 231 | { |
| 232 | struct mmc_data *data; |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 233 | struct dw_mci_slot *slot = mmc_priv(mmc); |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 234 | struct dw_mci *host = slot->host; |
Arnd Bergmann | e95baf1 | 2012-11-08 14:26:11 +0000 | [diff] [blame] | 235 | const struct dw_mci_drv_data *drv_data = slot->host->drv_data; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 236 | u32 cmdr; |
| 237 | cmd->error = -EINPROGRESS; |
| 238 | |
| 239 | cmdr = cmd->opcode; |
| 240 | |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 241 | if (cmd->opcode == MMC_STOP_TRANSMISSION || |
| 242 | cmd->opcode == MMC_GO_IDLE_STATE || |
| 243 | cmd->opcode == MMC_GO_INACTIVE_STATE || |
| 244 | (cmd->opcode == SD_IO_RW_DIRECT && |
| 245 | ((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 246 | cmdr |= SDMMC_CMD_STOP; |
Jaehoon Chung | 4a1b27a | 2014-03-03 11:36:44 +0900 | [diff] [blame] | 247 | else if (cmd->opcode != MMC_SEND_STATUS && cmd->data) |
| 248 | cmdr |= SDMMC_CMD_PRV_DAT_WAIT; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 249 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 250 | if (cmd->opcode == SD_SWITCH_VOLTAGE) { |
| 251 | u32 clk_en_a; |
| 252 | |
| 253 | /* Special bit makes CMD11 not die */ |
| 254 | cmdr |= SDMMC_CMD_VOLT_SWITCH; |
| 255 | |
| 256 | /* Change state to continue to handle CMD11 weirdness */ |
| 257 | WARN_ON(slot->host->state != STATE_SENDING_CMD); |
| 258 | slot->host->state = STATE_SENDING_CMD11; |
| 259 | |
| 260 | /* |
| 261 | * We need to disable low power mode (automatic clock stop) |
| 262 | * while doing voltage switch so we don't confuse the card, |
| 263 | * since stopping the clock is a specific part of the UHS |
| 264 | * voltage change dance. |
| 265 | * |
| 266 | * Note that low power mode (SDMMC_CLKEN_LOW_PWR) will be |
| 267 | * unconditionally turned back on in dw_mci_setup_bus() if it's |
| 268 | * ever called with a non-zero clock. That shouldn't happen |
| 269 | * until the voltage change is all done. |
| 270 | */ |
| 271 | clk_en_a = mci_readl(host, CLKENA); |
| 272 | clk_en_a &= ~(SDMMC_CLKEN_LOW_PWR << slot->id); |
| 273 | mci_writel(host, CLKENA, clk_en_a); |
| 274 | mci_send_cmd(slot, SDMMC_CMD_UPD_CLK | |
| 275 | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 276 | } |
| 277 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 278 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 279 | /* We expect a response, so set this bit */ |
| 280 | cmdr |= SDMMC_CMD_RESP_EXP; |
| 281 | if (cmd->flags & MMC_RSP_136) |
| 282 | cmdr |= SDMMC_CMD_RESP_LONG; |
| 283 | } |
| 284 | |
| 285 | if (cmd->flags & MMC_RSP_CRC) |
| 286 | cmdr |= SDMMC_CMD_RESP_CRC; |
| 287 | |
| 288 | data = cmd->data; |
| 289 | if (data) { |
| 290 | cmdr |= SDMMC_CMD_DAT_EXP; |
| 291 | if (data->flags & MMC_DATA_STREAM) |
| 292 | cmdr |= SDMMC_CMD_STRM_MODE; |
| 293 | if (data->flags & MMC_DATA_WRITE) |
| 294 | cmdr |= SDMMC_CMD_DAT_WR; |
| 295 | } |
| 296 | |
James Hogan | cb27a84 | 2012-10-16 09:43:08 +0100 | [diff] [blame] | 297 | if (drv_data && drv_data->prepare_command) |
| 298 | drv_data->prepare_command(slot->host, &cmdr); |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 299 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 300 | return cmdr; |
| 301 | } |
| 302 | |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 303 | static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd) |
| 304 | { |
| 305 | struct mmc_command *stop; |
| 306 | u32 cmdr; |
| 307 | |
| 308 | if (!cmd->data) |
| 309 | return 0; |
| 310 | |
| 311 | stop = &host->stop_abort; |
| 312 | cmdr = cmd->opcode; |
| 313 | memset(stop, 0, sizeof(struct mmc_command)); |
| 314 | |
| 315 | if (cmdr == MMC_READ_SINGLE_BLOCK || |
| 316 | cmdr == MMC_READ_MULTIPLE_BLOCK || |
| 317 | cmdr == MMC_WRITE_BLOCK || |
Ulf Hansson | 6c2c650 | 2014-12-01 16:13:39 +0100 | [diff] [blame] | 318 | cmdr == MMC_WRITE_MULTIPLE_BLOCK || |
| 319 | cmdr == MMC_SEND_TUNING_BLOCK || |
| 320 | cmdr == MMC_SEND_TUNING_BLOCK_HS200) { |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 321 | stop->opcode = MMC_STOP_TRANSMISSION; |
| 322 | stop->arg = 0; |
| 323 | stop->flags = MMC_RSP_R1B | MMC_CMD_AC; |
| 324 | } else if (cmdr == SD_IO_RW_EXTENDED) { |
| 325 | stop->opcode = SD_IO_RW_DIRECT; |
| 326 | stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) | |
| 327 | ((cmd->arg >> 28) & 0x7); |
| 328 | stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC; |
| 329 | } else { |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | cmdr = stop->opcode | SDMMC_CMD_STOP | |
| 334 | SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP; |
| 335 | |
| 336 | return cmdr; |
| 337 | } |
| 338 | |
Doug Anderson | 0bdbd0e | 2015-02-20 12:31:56 -0800 | [diff] [blame] | 339 | static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags) |
| 340 | { |
| 341 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
| 342 | |
| 343 | /* |
| 344 | * Databook says that before issuing a new data transfer command |
| 345 | * we need to check to see if the card is busy. Data transfer commands |
| 346 | * all have SDMMC_CMD_PRV_DAT_WAIT set, so we'll key off that. |
| 347 | * |
| 348 | * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is |
| 349 | * expected. |
| 350 | */ |
| 351 | if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) && |
| 352 | !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) { |
| 353 | while (mci_readl(host, STATUS) & SDMMC_STATUS_BUSY) { |
| 354 | if (time_after(jiffies, timeout)) { |
| 355 | /* Command will fail; we'll pass error then */ |
| 356 | dev_err(host->dev, "Busy; trying anyway\n"); |
| 357 | break; |
| 358 | } |
| 359 | udelay(10); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 364 | static void dw_mci_start_command(struct dw_mci *host, |
| 365 | struct mmc_command *cmd, u32 cmd_flags) |
| 366 | { |
| 367 | host->cmd = cmd; |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 368 | dev_vdbg(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 369 | "start command: ARGR=0x%08x CMDR=0x%08x\n", |
| 370 | cmd->arg, cmd_flags); |
| 371 | |
| 372 | mci_writel(host, CMDARG, cmd->arg); |
| 373 | wmb(); |
Doug Anderson | 0bdbd0e | 2015-02-20 12:31:56 -0800 | [diff] [blame] | 374 | dw_mci_wait_while_busy(host, cmd_flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 375 | |
| 376 | mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START); |
| 377 | } |
| 378 | |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 379 | static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 380 | { |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 381 | struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort; |
| 382 | dw_mci_start_command(host, stop, host->stop_cmdr); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* DMA interface functions */ |
| 386 | static void dw_mci_stop_dma(struct dw_mci *host) |
| 387 | { |
James Hogan | 03e8cb5 | 2011-06-29 09:28:43 +0100 | [diff] [blame] | 388 | if (host->using_dma) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 389 | host->dma_ops->stop(host); |
| 390 | host->dma_ops->cleanup(host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 391 | } |
Seungwon Jeon | aa50f25 | 2013-08-31 00:14:38 +0900 | [diff] [blame] | 392 | |
| 393 | /* Data transfer was stopped by the interrupt handler */ |
| 394 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 395 | } |
| 396 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 397 | static int dw_mci_get_dma_dir(struct mmc_data *data) |
| 398 | { |
| 399 | if (data->flags & MMC_DATA_WRITE) |
| 400 | return DMA_TO_DEVICE; |
| 401 | else |
| 402 | return DMA_FROM_DEVICE; |
| 403 | } |
| 404 | |
Jaehoon Chung | 9beee91 | 2012-02-16 11:19:38 +0900 | [diff] [blame] | 405 | #ifdef CONFIG_MMC_DW_IDMAC |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 406 | static void dw_mci_dma_cleanup(struct dw_mci *host) |
| 407 | { |
| 408 | struct mmc_data *data = host->data; |
| 409 | |
| 410 | if (data) |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 411 | if (!data->host_cookie) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 412 | dma_unmap_sg(host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 413 | data->sg, |
| 414 | data->sg_len, |
| 415 | dw_mci_get_dma_dir(data)); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 416 | } |
| 417 | |
Seungwon Jeon | 5ce9d96 | 2013-08-31 00:14:33 +0900 | [diff] [blame] | 418 | static void dw_mci_idmac_reset(struct dw_mci *host) |
| 419 | { |
| 420 | u32 bmod = mci_readl(host, BMOD); |
| 421 | /* Software reset of DMA */ |
| 422 | bmod |= SDMMC_IDMAC_SWRESET; |
| 423 | mci_writel(host, BMOD, bmod); |
| 424 | } |
| 425 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 426 | static void dw_mci_idmac_stop_dma(struct dw_mci *host) |
| 427 | { |
| 428 | u32 temp; |
| 429 | |
| 430 | /* Disable and reset the IDMAC interface */ |
| 431 | temp = mci_readl(host, CTRL); |
| 432 | temp &= ~SDMMC_CTRL_USE_IDMAC; |
| 433 | temp |= SDMMC_CTRL_DMA_RESET; |
| 434 | mci_writel(host, CTRL, temp); |
| 435 | |
| 436 | /* Stop the IDMAC running */ |
| 437 | temp = mci_readl(host, BMOD); |
Jaehoon Chung | a5289a4 | 2011-02-25 11:08:13 +0900 | [diff] [blame] | 438 | temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB); |
Seungwon Jeon | 5ce9d96 | 2013-08-31 00:14:33 +0900 | [diff] [blame] | 439 | temp |= SDMMC_IDMAC_SWRESET; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 440 | mci_writel(host, BMOD, temp); |
| 441 | } |
| 442 | |
| 443 | static void dw_mci_idmac_complete_dma(struct dw_mci *host) |
| 444 | { |
| 445 | struct mmc_data *data = host->data; |
| 446 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 447 | dev_vdbg(host->dev, "DMA complete\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 448 | |
| 449 | host->dma_ops->cleanup(host); |
| 450 | |
| 451 | /* |
| 452 | * If the card was removed, data will be NULL. No point in trying to |
| 453 | * send the stop command or waiting for NBUSY in this case. |
| 454 | */ |
| 455 | if (data) { |
| 456 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 457 | tasklet_schedule(&host->tasklet); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data, |
| 462 | unsigned int sg_len) |
| 463 | { |
| 464 | int i; |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 465 | if (host->dma_64bit_address == 1) { |
| 466 | struct idmac_desc_64addr *desc = host->sg_cpu; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 467 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 468 | for (i = 0; i < sg_len; i++, desc++) { |
| 469 | unsigned int length = sg_dma_len(&data->sg[i]); |
| 470 | u64 mem_addr = sg_dma_address(&data->sg[i]); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 471 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 472 | /* |
| 473 | * Set the OWN bit and disable interrupts for this |
| 474 | * descriptor |
| 475 | */ |
| 476 | desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | |
| 477 | IDMAC_DES0_CH; |
| 478 | /* Buffer length */ |
| 479 | IDMAC_64ADDR_SET_BUFFER1_SIZE(desc, length); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 480 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 481 | /* Physical address to DMA to/from */ |
| 482 | desc->des4 = mem_addr & 0xffffffff; |
| 483 | desc->des5 = mem_addr >> 32; |
| 484 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 485 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 486 | /* Set first descriptor */ |
| 487 | desc = host->sg_cpu; |
| 488 | desc->des0 |= IDMAC_DES0_FD; |
| 489 | |
| 490 | /* Set last descriptor */ |
| 491 | desc = host->sg_cpu + (i - 1) * |
| 492 | sizeof(struct idmac_desc_64addr); |
| 493 | desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC); |
| 494 | desc->des0 |= IDMAC_DES0_LD; |
| 495 | |
| 496 | } else { |
| 497 | struct idmac_desc *desc = host->sg_cpu; |
| 498 | |
| 499 | for (i = 0; i < sg_len; i++, desc++) { |
| 500 | unsigned int length = sg_dma_len(&data->sg[i]); |
| 501 | u32 mem_addr = sg_dma_address(&data->sg[i]); |
| 502 | |
| 503 | /* |
| 504 | * Set the OWN bit and disable interrupts for this |
| 505 | * descriptor |
| 506 | */ |
| 507 | desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | |
| 508 | IDMAC_DES0_CH; |
| 509 | /* Buffer length */ |
| 510 | IDMAC_SET_BUFFER1_SIZE(desc, length); |
| 511 | |
| 512 | /* Physical address to DMA to/from */ |
| 513 | desc->des2 = mem_addr; |
| 514 | } |
| 515 | |
| 516 | /* Set first descriptor */ |
| 517 | desc = host->sg_cpu; |
| 518 | desc->des0 |= IDMAC_DES0_FD; |
| 519 | |
| 520 | /* Set last descriptor */ |
| 521 | desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc); |
| 522 | desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC); |
| 523 | desc->des0 |= IDMAC_DES0_LD; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 526 | wmb(); |
| 527 | } |
| 528 | |
| 529 | static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len) |
| 530 | { |
| 531 | u32 temp; |
| 532 | |
| 533 | dw_mci_translate_sglist(host, host->data, sg_len); |
| 534 | |
Sonny Rao | 536f6b9 | 2014-10-16 09:58:05 -0700 | [diff] [blame] | 535 | /* Make sure to reset DMA in case we did PIO before this */ |
| 536 | dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET); |
| 537 | dw_mci_idmac_reset(host); |
| 538 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 539 | /* Select IDMAC interface */ |
| 540 | temp = mci_readl(host, CTRL); |
| 541 | temp |= SDMMC_CTRL_USE_IDMAC; |
| 542 | mci_writel(host, CTRL, temp); |
| 543 | |
| 544 | wmb(); |
| 545 | |
| 546 | /* Enable the IDMAC */ |
| 547 | temp = mci_readl(host, BMOD); |
Jaehoon Chung | a5289a4 | 2011-02-25 11:08:13 +0900 | [diff] [blame] | 548 | temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 549 | mci_writel(host, BMOD, temp); |
| 550 | |
| 551 | /* Start it running */ |
| 552 | mci_writel(host, PLDMND, 1); |
| 553 | } |
| 554 | |
| 555 | static int dw_mci_idmac_init(struct dw_mci *host) |
| 556 | { |
Seungwon Jeon | 897b69e | 2012-09-19 13:58:31 +0800 | [diff] [blame] | 557 | int i; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 558 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 559 | if (host->dma_64bit_address == 1) { |
| 560 | struct idmac_desc_64addr *p; |
| 561 | /* Number of descriptors in the ring buffer */ |
| 562 | host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc_64addr); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 563 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 564 | /* Forward link the descriptor list */ |
| 565 | for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; |
| 566 | i++, p++) { |
| 567 | p->des6 = (host->sg_dma + |
| 568 | (sizeof(struct idmac_desc_64addr) * |
| 569 | (i + 1))) & 0xffffffff; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 570 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 571 | p->des7 = (u64)(host->sg_dma + |
| 572 | (sizeof(struct idmac_desc_64addr) * |
| 573 | (i + 1))) >> 32; |
| 574 | /* Initialize reserved and buffer size fields to "0" */ |
| 575 | p->des1 = 0; |
| 576 | p->des2 = 0; |
| 577 | p->des3 = 0; |
| 578 | } |
| 579 | |
| 580 | /* Set the last descriptor as the end-of-ring descriptor */ |
| 581 | p->des6 = host->sg_dma & 0xffffffff; |
| 582 | p->des7 = (u64)host->sg_dma >> 32; |
| 583 | p->des0 = IDMAC_DES0_ER; |
| 584 | |
| 585 | } else { |
| 586 | struct idmac_desc *p; |
| 587 | /* Number of descriptors in the ring buffer */ |
| 588 | host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); |
| 589 | |
| 590 | /* Forward link the descriptor list */ |
| 591 | for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) |
| 592 | p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * |
| 593 | (i + 1)); |
| 594 | |
| 595 | /* Set the last descriptor as the end-of-ring descriptor */ |
| 596 | p->des3 = host->sg_dma; |
| 597 | p->des0 = IDMAC_DES0_ER; |
| 598 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 599 | |
Seungwon Jeon | 5ce9d96 | 2013-08-31 00:14:33 +0900 | [diff] [blame] | 600 | dw_mci_idmac_reset(host); |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 601 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 602 | if (host->dma_64bit_address == 1) { |
| 603 | /* Mask out interrupts - get Tx & Rx complete only */ |
| 604 | mci_writel(host, IDSTS64, IDMAC_INT_CLR); |
| 605 | mci_writel(host, IDINTEN64, SDMMC_IDMAC_INT_NI | |
| 606 | SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 607 | |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 608 | /* Set the descriptor base address */ |
| 609 | mci_writel(host, DBADDRL, host->sg_dma & 0xffffffff); |
| 610 | mci_writel(host, DBADDRU, (u64)host->sg_dma >> 32); |
| 611 | |
| 612 | } else { |
| 613 | /* Mask out interrupts - get Tx & Rx complete only */ |
| 614 | mci_writel(host, IDSTS, IDMAC_INT_CLR); |
| 615 | mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | |
| 616 | SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI); |
| 617 | |
| 618 | /* Set the descriptor base address */ |
| 619 | mci_writel(host, DBADDR, host->sg_dma); |
| 620 | } |
| 621 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
Arnd Bergmann | 8e2b36e | 2012-11-06 22:55:31 +0100 | [diff] [blame] | 625 | static const struct dw_mci_dma_ops dw_mci_idmac_ops = { |
Seungwon Jeon | 885c3e8 | 2012-02-20 11:01:43 +0900 | [diff] [blame] | 626 | .init = dw_mci_idmac_init, |
| 627 | .start = dw_mci_idmac_start_dma, |
| 628 | .stop = dw_mci_idmac_stop_dma, |
| 629 | .complete = dw_mci_idmac_complete_dma, |
| 630 | .cleanup = dw_mci_dma_cleanup, |
| 631 | }; |
| 632 | #endif /* CONFIG_MMC_DW_IDMAC */ |
| 633 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 634 | static int dw_mci_pre_dma_transfer(struct dw_mci *host, |
| 635 | struct mmc_data *data, |
| 636 | bool next) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 637 | { |
| 638 | struct scatterlist *sg; |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 639 | unsigned int i, sg_len; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 640 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 641 | if (!next && data->host_cookie) |
| 642 | return data->host_cookie; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * We don't do DMA on "complex" transfers, i.e. with |
| 646 | * non-word-aligned buffers or lengths. Also, we don't bother |
| 647 | * with all the DMA setup overhead for short transfers. |
| 648 | */ |
| 649 | if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD) |
| 650 | return -EINVAL; |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 651 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 652 | if (data->blksz & 3) |
| 653 | return -EINVAL; |
| 654 | |
| 655 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 656 | if (sg->offset & 3 || sg->length & 3) |
| 657 | return -EINVAL; |
| 658 | } |
| 659 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 660 | sg_len = dma_map_sg(host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 661 | data->sg, |
| 662 | data->sg_len, |
| 663 | dw_mci_get_dma_dir(data)); |
| 664 | if (sg_len == 0) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | if (next) |
| 668 | data->host_cookie = sg_len; |
| 669 | |
| 670 | return sg_len; |
| 671 | } |
| 672 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 673 | static void dw_mci_pre_req(struct mmc_host *mmc, |
| 674 | struct mmc_request *mrq, |
| 675 | bool is_first_req) |
| 676 | { |
| 677 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 678 | struct mmc_data *data = mrq->data; |
| 679 | |
| 680 | if (!slot->host->use_dma || !data) |
| 681 | return; |
| 682 | |
| 683 | if (data->host_cookie) { |
| 684 | data->host_cookie = 0; |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0) |
| 689 | data->host_cookie = 0; |
| 690 | } |
| 691 | |
| 692 | static void dw_mci_post_req(struct mmc_host *mmc, |
| 693 | struct mmc_request *mrq, |
| 694 | int err) |
| 695 | { |
| 696 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 697 | struct mmc_data *data = mrq->data; |
| 698 | |
| 699 | if (!slot->host->use_dma || !data) |
| 700 | return; |
| 701 | |
| 702 | if (data->host_cookie) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 703 | dma_unmap_sg(slot->host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 704 | data->sg, |
| 705 | data->sg_len, |
| 706 | dw_mci_get_dma_dir(data)); |
| 707 | data->host_cookie = 0; |
| 708 | } |
| 709 | |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 710 | static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data) |
| 711 | { |
| 712 | #ifdef CONFIG_MMC_DW_IDMAC |
| 713 | unsigned int blksz = data->blksz; |
| 714 | const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256}; |
| 715 | u32 fifo_width = 1 << host->data_shift; |
| 716 | u32 blksz_depth = blksz / fifo_width, fifoth_val; |
| 717 | u32 msize = 0, rx_wmark = 1, tx_wmark, tx_wmark_invers; |
| 718 | int idx = (sizeof(mszs) / sizeof(mszs[0])) - 1; |
| 719 | |
| 720 | tx_wmark = (host->fifo_depth) / 2; |
| 721 | tx_wmark_invers = host->fifo_depth - tx_wmark; |
| 722 | |
| 723 | /* |
| 724 | * MSIZE is '1', |
| 725 | * if blksz is not a multiple of the FIFO width |
| 726 | */ |
| 727 | if (blksz % fifo_width) { |
| 728 | msize = 0; |
| 729 | rx_wmark = 1; |
| 730 | goto done; |
| 731 | } |
| 732 | |
| 733 | do { |
| 734 | if (!((blksz_depth % mszs[idx]) || |
| 735 | (tx_wmark_invers % mszs[idx]))) { |
| 736 | msize = idx; |
| 737 | rx_wmark = mszs[idx] - 1; |
| 738 | break; |
| 739 | } |
| 740 | } while (--idx > 0); |
| 741 | /* |
| 742 | * If idx is '0', it won't be tried |
| 743 | * Thus, initial values are uesed |
| 744 | */ |
| 745 | done: |
| 746 | fifoth_val = SDMMC_SET_FIFOTH(msize, rx_wmark, tx_wmark); |
| 747 | mci_writel(host, FIFOTH, fifoth_val); |
| 748 | #endif |
| 749 | } |
| 750 | |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 751 | static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data) |
| 752 | { |
| 753 | unsigned int blksz = data->blksz; |
| 754 | u32 blksz_depth, fifo_depth; |
| 755 | u16 thld_size; |
| 756 | |
| 757 | WARN_ON(!(data->flags & MMC_DATA_READ)); |
| 758 | |
James Hogan | 66dfd10 | 2014-11-17 17:49:05 +0000 | [diff] [blame] | 759 | /* |
| 760 | * CDTHRCTL doesn't exist prior to 240A (in fact that register offset is |
| 761 | * in the FIFO region, so we really shouldn't access it). |
| 762 | */ |
| 763 | if (host->verid < DW_MMC_240A) |
| 764 | return; |
| 765 | |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 766 | if (host->timing != MMC_TIMING_MMC_HS200 && |
Jaehoon Chung | 488b8d6 | 2015-03-05 19:45:21 +0900 | [diff] [blame] | 767 | host->timing != MMC_TIMING_MMC_HS400 && |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 768 | host->timing != MMC_TIMING_UHS_SDR104) |
| 769 | goto disable; |
| 770 | |
| 771 | blksz_depth = blksz / (1 << host->data_shift); |
| 772 | fifo_depth = host->fifo_depth; |
| 773 | |
| 774 | if (blksz_depth > fifo_depth) |
| 775 | goto disable; |
| 776 | |
| 777 | /* |
| 778 | * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz' |
| 779 | * If (blksz_depth) < (fifo_depth >> 1), should be thld_size = blksz |
| 780 | * Currently just choose blksz. |
| 781 | */ |
| 782 | thld_size = blksz; |
| 783 | mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(thld_size, 1)); |
| 784 | return; |
| 785 | |
| 786 | disable: |
| 787 | mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(0, 0)); |
| 788 | } |
| 789 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 790 | static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data) |
| 791 | { |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 792 | unsigned long irqflags; |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 793 | int sg_len; |
| 794 | u32 temp; |
| 795 | |
| 796 | host->using_dma = 0; |
| 797 | |
| 798 | /* If we don't have a channel, we can't do DMA */ |
| 799 | if (!host->use_dma) |
| 800 | return -ENODEV; |
| 801 | |
| 802 | sg_len = dw_mci_pre_dma_transfer(host, data, 0); |
Seungwon Jeon | a99aa9b | 2012-04-10 09:53:32 +0900 | [diff] [blame] | 803 | if (sg_len < 0) { |
| 804 | host->dma_ops->stop(host); |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 805 | return sg_len; |
Seungwon Jeon | a99aa9b | 2012-04-10 09:53:32 +0900 | [diff] [blame] | 806 | } |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 807 | |
James Hogan | 03e8cb5 | 2011-06-29 09:28:43 +0100 | [diff] [blame] | 808 | host->using_dma = 1; |
| 809 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 810 | dev_vdbg(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 811 | "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n", |
| 812 | (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma, |
| 813 | sg_len); |
| 814 | |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 815 | /* |
| 816 | * Decide the MSIZE and RX/TX Watermark. |
| 817 | * If current block size is same with previous size, |
| 818 | * no need to update fifoth. |
| 819 | */ |
| 820 | if (host->prev_blksz != data->blksz) |
| 821 | dw_mci_adjust_fifoth(host, data); |
| 822 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 823 | /* Enable the DMA interface */ |
| 824 | temp = mci_readl(host, CTRL); |
| 825 | temp |= SDMMC_CTRL_DMA_ENABLE; |
| 826 | mci_writel(host, CTRL, temp); |
| 827 | |
| 828 | /* Disable RX/TX IRQs, let DMA handle it */ |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 829 | spin_lock_irqsave(&host->irq_lock, irqflags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 830 | temp = mci_readl(host, INTMASK); |
| 831 | temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR); |
| 832 | mci_writel(host, INTMASK, temp); |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 833 | spin_unlock_irqrestore(&host->irq_lock, irqflags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 834 | |
| 835 | host->dma_ops->start(host, sg_len); |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data) |
| 841 | { |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 842 | unsigned long irqflags; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 843 | u32 temp; |
| 844 | |
| 845 | data->error = -EINPROGRESS; |
| 846 | |
| 847 | WARN_ON(host->data); |
| 848 | host->sg = NULL; |
| 849 | host->data = data; |
| 850 | |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 851 | if (data->flags & MMC_DATA_READ) { |
James Hogan | 55c5efbc | 2011-06-29 09:29:58 +0100 | [diff] [blame] | 852 | host->dir_status = DW_MCI_RECV_STATUS; |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 853 | dw_mci_ctrl_rd_thld(host, data); |
| 854 | } else { |
James Hogan | 55c5efbc | 2011-06-29 09:29:58 +0100 | [diff] [blame] | 855 | host->dir_status = DW_MCI_SEND_STATUS; |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 856 | } |
James Hogan | 55c5efbc | 2011-06-29 09:29:58 +0100 | [diff] [blame] | 857 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 858 | if (dw_mci_submit_data_dma(host, data)) { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 859 | int flags = SG_MITER_ATOMIC; |
| 860 | if (host->data->flags & MMC_DATA_READ) |
| 861 | flags |= SG_MITER_TO_SG; |
| 862 | else |
| 863 | flags |= SG_MITER_FROM_SG; |
| 864 | |
| 865 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 866 | host->sg = data->sg; |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 867 | host->part_buf_start = 0; |
| 868 | host->part_buf_count = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 869 | |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 870 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR); |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 871 | |
| 872 | spin_lock_irqsave(&host->irq_lock, irqflags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 873 | temp = mci_readl(host, INTMASK); |
| 874 | temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR; |
| 875 | mci_writel(host, INTMASK, temp); |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 876 | spin_unlock_irqrestore(&host->irq_lock, irqflags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 877 | |
| 878 | temp = mci_readl(host, CTRL); |
| 879 | temp &= ~SDMMC_CTRL_DMA_ENABLE; |
| 880 | mci_writel(host, CTRL, temp); |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 881 | |
| 882 | /* |
| 883 | * Use the initial fifoth_val for PIO mode. |
| 884 | * If next issued data may be transfered by DMA mode, |
| 885 | * prev_blksz should be invalidated. |
| 886 | */ |
| 887 | mci_writel(host, FIFOTH, host->fifoth_val); |
| 888 | host->prev_blksz = 0; |
| 889 | } else { |
| 890 | /* |
| 891 | * Keep the current block size. |
| 892 | * It will be used to decide whether to update |
| 893 | * fifoth register next time. |
| 894 | */ |
| 895 | host->prev_blksz = data->blksz; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
| 899 | static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg) |
| 900 | { |
| 901 | struct dw_mci *host = slot->host; |
| 902 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
| 903 | unsigned int cmd_status = 0; |
| 904 | |
| 905 | mci_writel(host, CMDARG, arg); |
| 906 | wmb(); |
Doug Anderson | 0bdbd0e | 2015-02-20 12:31:56 -0800 | [diff] [blame] | 907 | dw_mci_wait_while_busy(host, cmd); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 908 | mci_writel(host, CMD, SDMMC_CMD_START | cmd); |
| 909 | |
| 910 | while (time_before(jiffies, timeout)) { |
| 911 | cmd_status = mci_readl(host, CMD); |
| 912 | if (!(cmd_status & SDMMC_CMD_START)) |
| 913 | return; |
| 914 | } |
| 915 | dev_err(&slot->mmc->class_dev, |
| 916 | "Timeout sending command (cmd %#x arg %#x status %#x)\n", |
| 917 | cmd, arg, cmd_status); |
| 918 | } |
| 919 | |
Abhilash Kesavan | ab26912 | 2012-11-19 10:26:21 +0530 | [diff] [blame] | 920 | static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 921 | { |
| 922 | struct dw_mci *host = slot->host; |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 923 | unsigned int clock = slot->clock; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 924 | u32 div; |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 925 | u32 clk_en_a; |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 926 | u32 sdmmc_cmd_bits = SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT; |
| 927 | |
| 928 | /* We must continue to set bit 28 in CMD until the change is complete */ |
| 929 | if (host->state == STATE_WAITING_CMD11_DONE) |
| 930 | sdmmc_cmd_bits |= SDMMC_CMD_VOLT_SWITCH; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 931 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 932 | if (!clock) { |
| 933 | mci_writel(host, CLKENA, 0); |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 934 | mci_send_cmd(slot, sdmmc_cmd_bits, 0); |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 935 | } else if (clock != host->current_speed || force_clkinit) { |
| 936 | div = host->bus_hz / clock; |
| 937 | if (host->bus_hz % clock && host->bus_hz > clock) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 938 | /* |
| 939 | * move the + 1 after the divide to prevent |
| 940 | * over-clocking the card. |
| 941 | */ |
Seungwon Jeon | e419990 | 2012-05-22 13:01:21 +0900 | [diff] [blame] | 942 | div += 1; |
| 943 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 944 | div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 945 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 946 | if ((clock << div) != slot->__clk_old || force_clkinit) |
| 947 | dev_info(&slot->mmc->class_dev, |
| 948 | "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n", |
| 949 | slot->id, host->bus_hz, clock, |
| 950 | div ? ((host->bus_hz / div) >> 1) : |
| 951 | host->bus_hz, div); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 952 | |
| 953 | /* disable clock */ |
| 954 | mci_writel(host, CLKENA, 0); |
| 955 | mci_writel(host, CLKSRC, 0); |
| 956 | |
| 957 | /* inform CIU */ |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 958 | mci_send_cmd(slot, sdmmc_cmd_bits, 0); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 959 | |
| 960 | /* set clock to desired speed */ |
| 961 | mci_writel(host, CLKDIV, div); |
| 962 | |
| 963 | /* inform CIU */ |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 964 | mci_send_cmd(slot, sdmmc_cmd_bits, 0); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 965 | |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 966 | /* enable clock; only low power if no SDIO */ |
| 967 | clk_en_a = SDMMC_CLKEN_ENABLE << slot->id; |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 968 | if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags)) |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 969 | clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id; |
| 970 | mci_writel(host, CLKENA, clk_en_a); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 971 | |
| 972 | /* inform CIU */ |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 973 | mci_send_cmd(slot, sdmmc_cmd_bits, 0); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 974 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 975 | /* keep the clock with reflecting clock dividor */ |
| 976 | slot->__clk_old = clock << div; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 977 | } |
| 978 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 979 | host->current_speed = clock; |
| 980 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 981 | /* Set the current slot bus width */ |
Seungwon Jeon | 1d56c45 | 2011-06-20 17:23:53 +0900 | [diff] [blame] | 982 | mci_writel(host, CTYPE, (slot->ctype << slot->id)); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 983 | } |
| 984 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 985 | static void __dw_mci_start_request(struct dw_mci *host, |
| 986 | struct dw_mci_slot *slot, |
| 987 | struct mmc_command *cmd) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 988 | { |
| 989 | struct mmc_request *mrq; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 990 | struct mmc_data *data; |
| 991 | u32 cmdflags; |
| 992 | |
| 993 | mrq = slot->mrq; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 994 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 995 | host->cur_slot = slot; |
| 996 | host->mrq = mrq; |
| 997 | |
| 998 | host->pending_events = 0; |
| 999 | host->completed_events = 0; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1000 | host->cmd_status = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1001 | host->data_status = 0; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1002 | host->dir_status = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1003 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1004 | data = cmd->data; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1005 | if (data) { |
Jaehoon Chung | f16afa8 | 2014-03-03 11:36:45 +0900 | [diff] [blame] | 1006 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1007 | mci_writel(host, BYTCNT, data->blksz*data->blocks); |
| 1008 | mci_writel(host, BLKSIZ, data->blksz); |
| 1009 | } |
| 1010 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1011 | cmdflags = dw_mci_prepare_command(slot->mmc, cmd); |
| 1012 | |
| 1013 | /* this is the first command, send the initialization clock */ |
| 1014 | if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags)) |
| 1015 | cmdflags |= SDMMC_CMD_INIT; |
| 1016 | |
| 1017 | if (data) { |
| 1018 | dw_mci_submit_data(host, data); |
| 1019 | wmb(); |
| 1020 | } |
| 1021 | |
| 1022 | dw_mci_start_command(host, cmd, cmdflags); |
| 1023 | |
Doug Anderson | 5c93516 | 2015-03-09 16:18:21 -0700 | [diff] [blame^] | 1024 | if (cmd->opcode == SD_SWITCH_VOLTAGE) { |
| 1025 | /* |
| 1026 | * Databook says to fail after 2ms w/ no response; give an |
| 1027 | * extra jiffy just in case we're about to roll over. |
| 1028 | */ |
| 1029 | mod_timer(&host->cmd11_timer, |
| 1030 | jiffies + msecs_to_jiffies(2) + 1); |
| 1031 | } |
| 1032 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1033 | if (mrq->stop) |
| 1034 | host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop); |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1035 | else |
| 1036 | host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1039 | static void dw_mci_start_request(struct dw_mci *host, |
| 1040 | struct dw_mci_slot *slot) |
| 1041 | { |
| 1042 | struct mmc_request *mrq = slot->mrq; |
| 1043 | struct mmc_command *cmd; |
| 1044 | |
| 1045 | cmd = mrq->sbc ? mrq->sbc : mrq->cmd; |
| 1046 | __dw_mci_start_request(host, slot, cmd); |
| 1047 | } |
| 1048 | |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 1049 | /* must be called with host->lock held */ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1050 | static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot, |
| 1051 | struct mmc_request *mrq) |
| 1052 | { |
| 1053 | dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n", |
| 1054 | host->state); |
| 1055 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1056 | slot->mrq = mrq; |
| 1057 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1058 | if (host->state == STATE_WAITING_CMD11_DONE) { |
| 1059 | dev_warn(&slot->mmc->class_dev, |
| 1060 | "Voltage change didn't complete\n"); |
| 1061 | /* |
| 1062 | * this case isn't expected to happen, so we can |
| 1063 | * either crash here or just try to continue on |
| 1064 | * in the closest possible state |
| 1065 | */ |
| 1066 | host->state = STATE_IDLE; |
| 1067 | } |
| 1068 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1069 | if (host->state == STATE_IDLE) { |
| 1070 | host->state = STATE_SENDING_CMD; |
| 1071 | dw_mci_start_request(host, slot); |
| 1072 | } else { |
| 1073 | list_add_tail(&slot->queue_node, &host->queue); |
| 1074 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 1078 | { |
| 1079 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1080 | struct dw_mci *host = slot->host; |
| 1081 | |
| 1082 | WARN_ON(slot->mrq); |
| 1083 | |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 1084 | /* |
| 1085 | * The check for card presence and queueing of the request must be |
| 1086 | * atomic, otherwise the card could be removed in between and the |
| 1087 | * request wouldn't fail until another card was inserted. |
| 1088 | */ |
| 1089 | spin_lock_bh(&host->lock); |
| 1090 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1091 | if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) { |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 1092 | spin_unlock_bh(&host->lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1093 | mrq->cmd->error = -ENOMEDIUM; |
| 1094 | mmc_request_done(mmc, mrq); |
| 1095 | return; |
| 1096 | } |
| 1097 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1098 | dw_mci_queue_request(host, slot, mrq); |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 1099 | |
| 1100 | spin_unlock_bh(&host->lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1104 | { |
| 1105 | struct dw_mci_slot *slot = mmc_priv(mmc); |
Arnd Bergmann | e95baf1 | 2012-11-08 14:26:11 +0000 | [diff] [blame] | 1106 | const struct dw_mci_drv_data *drv_data = slot->host->drv_data; |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 1107 | u32 regs; |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1108 | int ret; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1109 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1110 | switch (ios->bus_width) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1111 | case MMC_BUS_WIDTH_4: |
| 1112 | slot->ctype = SDMMC_CTYPE_4BIT; |
| 1113 | break; |
Jaehoon Chung | c9b2a06 | 2011-02-17 16:12:38 +0900 | [diff] [blame] | 1114 | case MMC_BUS_WIDTH_8: |
| 1115 | slot->ctype = SDMMC_CTYPE_8BIT; |
| 1116 | break; |
Jaehoon Chung | b2f7cb4 | 2012-11-08 17:35:31 +0900 | [diff] [blame] | 1117 | default: |
| 1118 | /* set default 1 bit mode */ |
| 1119 | slot->ctype = SDMMC_CTYPE_1BIT; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1120 | } |
| 1121 | |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 1122 | regs = mci_readl(slot->host, UHS_REG); |
| 1123 | |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 1124 | /* DDR mode set */ |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 1125 | if (ios->timing == MMC_TIMING_MMC_DDR52 || |
| 1126 | ios->timing == MMC_TIMING_MMC_HS400) |
Hyeonsu Kim | c69042a | 2013-02-22 09:32:46 +0900 | [diff] [blame] | 1127 | regs |= ((0x1 << slot->id) << 16); |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 1128 | else |
Hyeonsu Kim | c69042a | 2013-02-22 09:32:46 +0900 | [diff] [blame] | 1129 | regs &= ~((0x1 << slot->id) << 16); |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 1130 | |
| 1131 | mci_writel(slot->host, UHS_REG, regs); |
Seungwon Jeon | f1d2736 | 2013-08-31 00:13:55 +0900 | [diff] [blame] | 1132 | slot->host->timing = ios->timing; |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 1133 | |
Doug Anderson | fdf492a | 2013-08-31 00:11:43 +0900 | [diff] [blame] | 1134 | /* |
| 1135 | * Use mirror of ios->clock to prevent race with mmc |
| 1136 | * core ios update when finding the minimum. |
| 1137 | */ |
| 1138 | slot->clock = ios->clock; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1139 | |
James Hogan | cb27a84 | 2012-10-16 09:43:08 +0100 | [diff] [blame] | 1140 | if (drv_data && drv_data->set_ios) |
| 1141 | drv_data->set_ios(slot->host, ios); |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 1142 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1143 | switch (ios->power_mode) { |
| 1144 | case MMC_POWER_UP: |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1145 | if (!IS_ERR(mmc->supply.vmmc)) { |
| 1146 | ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, |
| 1147 | ios->vdd); |
| 1148 | if (ret) { |
| 1149 | dev_err(slot->host->dev, |
| 1150 | "failed to enable vmmc regulator\n"); |
| 1151 | /*return, if failed turn on vmmc*/ |
| 1152 | return; |
| 1153 | } |
| 1154 | } |
Doug Anderson | 29d0d16 | 2015-01-13 15:58:44 -0800 | [diff] [blame] | 1155 | set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags); |
| 1156 | regs = mci_readl(slot->host, PWREN); |
| 1157 | regs |= (1 << slot->id); |
| 1158 | mci_writel(slot->host, PWREN, regs); |
| 1159 | break; |
| 1160 | case MMC_POWER_ON: |
Doug Anderson | d1f1dd8 | 2015-02-20 10:57:19 -0800 | [diff] [blame] | 1161 | if (!slot->host->vqmmc_enabled) { |
| 1162 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1163 | ret = regulator_enable(mmc->supply.vqmmc); |
| 1164 | if (ret < 0) |
| 1165 | dev_err(slot->host->dev, |
| 1166 | "failed to enable vqmmc\n"); |
| 1167 | else |
| 1168 | slot->host->vqmmc_enabled = true; |
| 1169 | |
| 1170 | } else { |
| 1171 | /* Keep track so we don't reset again */ |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1172 | slot->host->vqmmc_enabled = true; |
Doug Anderson | d1f1dd8 | 2015-02-20 10:57:19 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /* Reset our state machine after powering on */ |
| 1176 | dw_mci_ctrl_reset(slot->host, |
| 1177 | SDMMC_CTRL_ALL_RESET_FLAGS); |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1178 | } |
Doug Anderson | 655babb | 2015-02-20 10:57:18 -0800 | [diff] [blame] | 1179 | |
| 1180 | /* Adjust clock / bus width after power is up */ |
| 1181 | dw_mci_setup_bus(slot, false); |
| 1182 | |
James Hogan | e6f34e2 | 2013-03-12 10:43:32 +0000 | [diff] [blame] | 1183 | break; |
| 1184 | case MMC_POWER_OFF: |
Doug Anderson | 655babb | 2015-02-20 10:57:18 -0800 | [diff] [blame] | 1185 | /* Turn clock off before power goes down */ |
| 1186 | dw_mci_setup_bus(slot, false); |
| 1187 | |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1188 | if (!IS_ERR(mmc->supply.vmmc)) |
| 1189 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); |
| 1190 | |
Doug Anderson | d1f1dd8 | 2015-02-20 10:57:19 -0800 | [diff] [blame] | 1191 | if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled) |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1192 | regulator_disable(mmc->supply.vqmmc); |
Doug Anderson | d1f1dd8 | 2015-02-20 10:57:19 -0800 | [diff] [blame] | 1193 | slot->host->vqmmc_enabled = false; |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 1194 | |
Jaehoon Chung | 4366dcc | 2013-03-26 21:36:14 +0900 | [diff] [blame] | 1195 | regs = mci_readl(slot->host, PWREN); |
| 1196 | regs &= ~(1 << slot->id); |
| 1197 | mci_writel(slot->host, PWREN, regs); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1198 | break; |
| 1199 | default: |
| 1200 | break; |
| 1201 | } |
Doug Anderson | 655babb | 2015-02-20 10:57:18 -0800 | [diff] [blame] | 1202 | |
| 1203 | if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0) |
| 1204 | slot->host->state = STATE_IDLE; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1205 | } |
| 1206 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1207 | static int dw_mci_card_busy(struct mmc_host *mmc) |
| 1208 | { |
| 1209 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1210 | u32 status; |
| 1211 | |
| 1212 | /* |
| 1213 | * Check the busy bit which is low when DAT[3:0] |
| 1214 | * (the data lines) are 0000 |
| 1215 | */ |
| 1216 | status = mci_readl(slot->host, STATUS); |
| 1217 | |
| 1218 | return !!(status & SDMMC_STATUS_BUSY); |
| 1219 | } |
| 1220 | |
| 1221 | static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1222 | { |
| 1223 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1224 | struct dw_mci *host = slot->host; |
| 1225 | u32 uhs; |
| 1226 | u32 v18 = SDMMC_UHS_18V << slot->id; |
| 1227 | int min_uv, max_uv; |
| 1228 | int ret; |
| 1229 | |
| 1230 | /* |
| 1231 | * Program the voltage. Note that some instances of dw_mmc may use |
| 1232 | * the UHS_REG for this. For other instances (like exynos) the UHS_REG |
| 1233 | * does no harm but you need to set the regulator directly. Try both. |
| 1234 | */ |
| 1235 | uhs = mci_readl(host, UHS_REG); |
| 1236 | if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { |
| 1237 | min_uv = 2700000; |
| 1238 | max_uv = 3600000; |
| 1239 | uhs &= ~v18; |
| 1240 | } else { |
| 1241 | min_uv = 1700000; |
| 1242 | max_uv = 1950000; |
| 1243 | uhs |= v18; |
| 1244 | } |
| 1245 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1246 | ret = regulator_set_voltage(mmc->supply.vqmmc, min_uv, max_uv); |
| 1247 | |
| 1248 | if (ret) { |
Doug Anderson | b19caf3 | 2014-10-10 21:16:16 -0700 | [diff] [blame] | 1249 | dev_dbg(&mmc->class_dev, |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1250 | "Regulator set error %d: %d - %d\n", |
| 1251 | ret, min_uv, max_uv); |
| 1252 | return ret; |
| 1253 | } |
| 1254 | } |
| 1255 | mci_writel(host, UHS_REG, uhs); |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1260 | static int dw_mci_get_ro(struct mmc_host *mmc) |
| 1261 | { |
| 1262 | int read_only; |
| 1263 | struct dw_mci_slot *slot = mmc_priv(mmc); |
Jaehoon Chung | 9795a84 | 2014-03-03 11:36:46 +0900 | [diff] [blame] | 1264 | int gpio_ro = mmc_gpio_get_ro(mmc); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1265 | |
| 1266 | /* Use platform get_ro function, else try on board write protect */ |
Jaehoon Chung | 26375b5 | 2014-08-07 16:37:58 +0900 | [diff] [blame] | 1267 | if ((slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT) || |
| 1268 | (slot->host->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT)) |
Thomas Abraham | b4967aa | 2012-09-17 18:16:39 +0000 | [diff] [blame] | 1269 | read_only = 0; |
Jaehoon Chung | 9795a84 | 2014-03-03 11:36:46 +0900 | [diff] [blame] | 1270 | else if (!IS_ERR_VALUE(gpio_ro)) |
| 1271 | read_only = gpio_ro; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1272 | else |
| 1273 | read_only = |
| 1274 | mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0; |
| 1275 | |
| 1276 | dev_dbg(&mmc->class_dev, "card is %s\n", |
| 1277 | read_only ? "read-only" : "read-write"); |
| 1278 | |
| 1279 | return read_only; |
| 1280 | } |
| 1281 | |
| 1282 | static int dw_mci_get_cd(struct mmc_host *mmc) |
| 1283 | { |
| 1284 | int present; |
| 1285 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1286 | struct dw_mci_board *brd = slot->host->pdata; |
Zhangfei Gao | 7cf347b | 2014-01-16 20:48:47 +0800 | [diff] [blame] | 1287 | struct dw_mci *host = slot->host; |
| 1288 | int gpio_cd = mmc_gpio_get_cd(mmc); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1289 | |
| 1290 | /* Use platform get_cd function, else try onboard card detect */ |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 1291 | if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) |
| 1292 | present = 1; |
Zhangfei Gao | bf626e5 | 2014-01-09 22:35:10 +0800 | [diff] [blame] | 1293 | else if (!IS_ERR_VALUE(gpio_cd)) |
Zhangfei Gao | 7cf347b | 2014-01-16 20:48:47 +0800 | [diff] [blame] | 1294 | present = gpio_cd; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1295 | else |
| 1296 | present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) |
| 1297 | == 0 ? 1 : 0; |
| 1298 | |
Zhangfei Gao | 7cf347b | 2014-01-16 20:48:47 +0800 | [diff] [blame] | 1299 | spin_lock_bh(&host->lock); |
Zhangfei Gao | bf626e5 | 2014-01-09 22:35:10 +0800 | [diff] [blame] | 1300 | if (present) { |
| 1301 | set_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1302 | dev_dbg(&mmc->class_dev, "card is present\n"); |
Zhangfei Gao | bf626e5 | 2014-01-09 22:35:10 +0800 | [diff] [blame] | 1303 | } else { |
| 1304 | clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1305 | dev_dbg(&mmc->class_dev, "card is not present\n"); |
Zhangfei Gao | bf626e5 | 2014-01-09 22:35:10 +0800 | [diff] [blame] | 1306 | } |
Zhangfei Gao | 7cf347b | 2014-01-16 20:48:47 +0800 | [diff] [blame] | 1307 | spin_unlock_bh(&host->lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1308 | |
| 1309 | return present; |
| 1310 | } |
| 1311 | |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1312 | static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card) |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 1313 | { |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1314 | struct dw_mci_slot *slot = mmc_priv(mmc); |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 1315 | struct dw_mci *host = slot->host; |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 1316 | |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1317 | /* |
| 1318 | * Low power mode will stop the card clock when idle. According to the |
| 1319 | * description of the CLKENA register we should disable low power mode |
| 1320 | * for SDIO cards if we need SDIO interrupts to work. |
| 1321 | */ |
| 1322 | if (mmc->caps & MMC_CAP_SDIO_IRQ) { |
| 1323 | const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id; |
| 1324 | u32 clk_en_a_old; |
| 1325 | u32 clk_en_a; |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 1326 | |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1327 | clk_en_a_old = mci_readl(host, CLKENA); |
| 1328 | |
| 1329 | if (card->type == MMC_TYPE_SDIO || |
| 1330 | card->type == MMC_TYPE_SD_COMBO) { |
| 1331 | set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); |
| 1332 | clk_en_a = clk_en_a_old & ~clken_low_pwr; |
| 1333 | } else { |
| 1334 | clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); |
| 1335 | clk_en_a = clk_en_a_old | clken_low_pwr; |
| 1336 | } |
| 1337 | |
| 1338 | if (clk_en_a != clk_en_a_old) { |
| 1339 | mci_writel(host, CLKENA, clk_en_a); |
| 1340 | mci_send_cmd(slot, SDMMC_CMD_UPD_CLK | |
| 1341 | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 1342 | } |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1346 | static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) |
| 1347 | { |
| 1348 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1349 | struct dw_mci *host = slot->host; |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 1350 | unsigned long irqflags; |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1351 | u32 int_mask; |
| 1352 | |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 1353 | spin_lock_irqsave(&host->irq_lock, irqflags); |
| 1354 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1355 | /* Enable/disable Slot Specific SDIO interrupt */ |
| 1356 | int_mask = mci_readl(host, INTMASK); |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1357 | if (enb) |
| 1358 | int_mask |= SDMMC_INT_SDIO(slot->sdio_id); |
| 1359 | else |
| 1360 | int_mask &= ~SDMMC_INT_SDIO(slot->sdio_id); |
| 1361 | mci_writel(host, INTMASK, int_mask); |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 1362 | |
| 1363 | spin_unlock_irqrestore(&host->irq_lock, irqflags); |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1364 | } |
| 1365 | |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 1366 | static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode) |
| 1367 | { |
| 1368 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1369 | struct dw_mci *host = slot->host; |
| 1370 | const struct dw_mci_drv_data *drv_data = host->drv_data; |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 1371 | int err = -ENOSYS; |
| 1372 | |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 1373 | if (drv_data && drv_data->execute_tuning) |
Ulf Hansson | 6c2c650 | 2014-12-01 16:13:39 +0100 | [diff] [blame] | 1374 | err = drv_data->execute_tuning(slot); |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 1375 | return err; |
| 1376 | } |
| 1377 | |
Wu Fengguang | c22f5e1 | 2015-03-05 18:02:54 +0800 | [diff] [blame] | 1378 | static int dw_mci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios) |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 1379 | { |
| 1380 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 1381 | struct dw_mci *host = slot->host; |
| 1382 | const struct dw_mci_drv_data *drv_data = host->drv_data; |
| 1383 | |
| 1384 | if (drv_data && drv_data->prepare_hs400_tuning) |
| 1385 | return drv_data->prepare_hs400_tuning(host, ios); |
| 1386 | |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1390 | static const struct mmc_host_ops dw_mci_ops = { |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1391 | .request = dw_mci_request, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 1392 | .pre_req = dw_mci_pre_req, |
| 1393 | .post_req = dw_mci_post_req, |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1394 | .set_ios = dw_mci_set_ios, |
| 1395 | .get_ro = dw_mci_get_ro, |
| 1396 | .get_cd = dw_mci_get_cd, |
| 1397 | .enable_sdio_irq = dw_mci_enable_sdio_irq, |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 1398 | .execute_tuning = dw_mci_execute_tuning, |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1399 | .card_busy = dw_mci_card_busy, |
| 1400 | .start_signal_voltage_switch = dw_mci_switch_voltage, |
Doug Anderson | b24c8b2 | 2014-12-02 15:42:46 -0800 | [diff] [blame] | 1401 | .init_card = dw_mci_init_card, |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 1402 | .prepare_hs400_tuning = dw_mci_prepare_hs400_tuning, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1403 | }; |
| 1404 | |
| 1405 | static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) |
| 1406 | __releases(&host->lock) |
| 1407 | __acquires(&host->lock) |
| 1408 | { |
| 1409 | struct dw_mci_slot *slot; |
| 1410 | struct mmc_host *prev_mmc = host->cur_slot->mmc; |
| 1411 | |
| 1412 | WARN_ON(host->cmd || host->data); |
| 1413 | |
| 1414 | host->cur_slot->mrq = NULL; |
| 1415 | host->mrq = NULL; |
| 1416 | if (!list_empty(&host->queue)) { |
| 1417 | slot = list_entry(host->queue.next, |
| 1418 | struct dw_mci_slot, queue_node); |
| 1419 | list_del(&slot->queue_node); |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1420 | dev_vdbg(host->dev, "list not empty: %s is next\n", |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1421 | mmc_hostname(slot->mmc)); |
| 1422 | host->state = STATE_SENDING_CMD; |
| 1423 | dw_mci_start_request(host, slot); |
| 1424 | } else { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1425 | dev_vdbg(host->dev, "list empty\n"); |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1426 | |
| 1427 | if (host->state == STATE_SENDING_CMD11) |
| 1428 | host->state = STATE_WAITING_CMD11_DONE; |
| 1429 | else |
| 1430 | host->state = STATE_IDLE; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | spin_unlock(&host->lock); |
| 1434 | mmc_request_done(prev_mmc, mrq); |
| 1435 | spin_lock(&host->lock); |
| 1436 | } |
| 1437 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1438 | static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1439 | { |
| 1440 | u32 status = host->cmd_status; |
| 1441 | |
| 1442 | host->cmd_status = 0; |
| 1443 | |
| 1444 | /* Read the response from the card (up to 16 bytes) */ |
| 1445 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 1446 | if (cmd->flags & MMC_RSP_136) { |
| 1447 | cmd->resp[3] = mci_readl(host, RESP0); |
| 1448 | cmd->resp[2] = mci_readl(host, RESP1); |
| 1449 | cmd->resp[1] = mci_readl(host, RESP2); |
| 1450 | cmd->resp[0] = mci_readl(host, RESP3); |
| 1451 | } else { |
| 1452 | cmd->resp[0] = mci_readl(host, RESP0); |
| 1453 | cmd->resp[1] = 0; |
| 1454 | cmd->resp[2] = 0; |
| 1455 | cmd->resp[3] = 0; |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | if (status & SDMMC_INT_RTO) |
| 1460 | cmd->error = -ETIMEDOUT; |
| 1461 | else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC)) |
| 1462 | cmd->error = -EILSEQ; |
| 1463 | else if (status & SDMMC_INT_RESP_ERR) |
| 1464 | cmd->error = -EIO; |
| 1465 | else |
| 1466 | cmd->error = 0; |
| 1467 | |
| 1468 | if (cmd->error) { |
| 1469 | /* newer ip versions need a delay between retries */ |
| 1470 | if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY) |
| 1471 | mdelay(20); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1472 | } |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1473 | |
| 1474 | return cmd->error; |
| 1475 | } |
| 1476 | |
| 1477 | static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data) |
| 1478 | { |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 1479 | u32 status = host->data_status; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1480 | |
| 1481 | if (status & DW_MCI_DATA_ERROR_FLAGS) { |
| 1482 | if (status & SDMMC_INT_DRTO) { |
| 1483 | data->error = -ETIMEDOUT; |
| 1484 | } else if (status & SDMMC_INT_DCRC) { |
| 1485 | data->error = -EILSEQ; |
| 1486 | } else if (status & SDMMC_INT_EBE) { |
| 1487 | if (host->dir_status == |
| 1488 | DW_MCI_SEND_STATUS) { |
| 1489 | /* |
| 1490 | * No data CRC status was returned. |
| 1491 | * The number of bytes transferred |
| 1492 | * will be exaggerated in PIO mode. |
| 1493 | */ |
| 1494 | data->bytes_xfered = 0; |
| 1495 | data->error = -ETIMEDOUT; |
| 1496 | } else if (host->dir_status == |
| 1497 | DW_MCI_RECV_STATUS) { |
| 1498 | data->error = -EIO; |
| 1499 | } |
| 1500 | } else { |
| 1501 | /* SDMMC_INT_SBE is included */ |
| 1502 | data->error = -EIO; |
| 1503 | } |
| 1504 | |
Doug Anderson | e6cc012 | 2014-04-22 16:51:21 -0700 | [diff] [blame] | 1505 | dev_dbg(host->dev, "data error, status 0x%08x\n", status); |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1506 | |
| 1507 | /* |
| 1508 | * After an error, there may be data lingering |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 1509 | * in the FIFO |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1510 | */ |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 1511 | dw_mci_reset(host); |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1512 | } else { |
| 1513 | data->bytes_xfered = data->blocks * data->blksz; |
| 1514 | data->error = 0; |
| 1515 | } |
| 1516 | |
| 1517 | return data->error; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static void dw_mci_tasklet_func(unsigned long priv) |
| 1521 | { |
| 1522 | struct dw_mci *host = (struct dw_mci *)priv; |
| 1523 | struct mmc_data *data; |
| 1524 | struct mmc_command *cmd; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1525 | struct mmc_request *mrq; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1526 | enum dw_mci_state state; |
| 1527 | enum dw_mci_state prev_state; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1528 | unsigned int err; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1529 | |
| 1530 | spin_lock(&host->lock); |
| 1531 | |
| 1532 | state = host->state; |
| 1533 | data = host->data; |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1534 | mrq = host->mrq; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1535 | |
| 1536 | do { |
| 1537 | prev_state = state; |
| 1538 | |
| 1539 | switch (state) { |
| 1540 | case STATE_IDLE: |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1541 | case STATE_WAITING_CMD11_DONE: |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1542 | break; |
| 1543 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 1544 | case STATE_SENDING_CMD11: |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1545 | case STATE_SENDING_CMD: |
| 1546 | if (!test_and_clear_bit(EVENT_CMD_COMPLETE, |
| 1547 | &host->pending_events)) |
| 1548 | break; |
| 1549 | |
| 1550 | cmd = host->cmd; |
| 1551 | host->cmd = NULL; |
| 1552 | set_bit(EVENT_CMD_COMPLETE, &host->completed_events); |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1553 | err = dw_mci_command_complete(host, cmd); |
| 1554 | if (cmd == mrq->sbc && !err) { |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1555 | prev_state = state = STATE_SENDING_CMD; |
| 1556 | __dw_mci_start_request(host, host->cur_slot, |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1557 | mrq->cmd); |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1558 | goto unlock; |
| 1559 | } |
| 1560 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1561 | if (cmd->data && err) { |
Seungwon Jeon | 71abb13 | 2013-08-31 00:13:59 +0900 | [diff] [blame] | 1562 | dw_mci_stop_dma(host); |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1563 | send_stop_abort(host, data); |
| 1564 | state = STATE_SENDING_STOP; |
| 1565 | break; |
Seungwon Jeon | 71abb13 | 2013-08-31 00:13:59 +0900 | [diff] [blame] | 1566 | } |
| 1567 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1568 | if (!cmd->data || err) { |
| 1569 | dw_mci_request_end(host, mrq); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1570 | goto unlock; |
| 1571 | } |
| 1572 | |
| 1573 | prev_state = state = STATE_SENDING_DATA; |
| 1574 | /* fall through */ |
| 1575 | |
| 1576 | case STATE_SENDING_DATA: |
Doug Anderson | 2aa3546 | 2014-08-13 08:13:43 -0700 | [diff] [blame] | 1577 | /* |
| 1578 | * We could get a data error and never a transfer |
| 1579 | * complete so we'd better check for it here. |
| 1580 | * |
| 1581 | * Note that we don't really care if we also got a |
| 1582 | * transfer complete; stopping the DMA and sending an |
| 1583 | * abort won't hurt. |
| 1584 | */ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1585 | if (test_and_clear_bit(EVENT_DATA_ERROR, |
| 1586 | &host->pending_events)) { |
| 1587 | dw_mci_stop_dma(host); |
addy ke | bdb9a90 | 2015-02-20 10:55:25 +0800 | [diff] [blame] | 1588 | if (data->stop || |
| 1589 | !(host->data_status & (SDMMC_INT_DRTO | |
| 1590 | SDMMC_INT_EBE))) |
| 1591 | send_stop_abort(host, data); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1592 | state = STATE_DATA_ERROR; |
| 1593 | break; |
| 1594 | } |
| 1595 | |
| 1596 | if (!test_and_clear_bit(EVENT_XFER_COMPLETE, |
| 1597 | &host->pending_events)) |
| 1598 | break; |
| 1599 | |
| 1600 | set_bit(EVENT_XFER_COMPLETE, &host->completed_events); |
Doug Anderson | 2aa3546 | 2014-08-13 08:13:43 -0700 | [diff] [blame] | 1601 | |
| 1602 | /* |
| 1603 | * Handle an EVENT_DATA_ERROR that might have shown up |
| 1604 | * before the transfer completed. This might not have |
| 1605 | * been caught by the check above because the interrupt |
| 1606 | * could have gone off between the previous check and |
| 1607 | * the check for transfer complete. |
| 1608 | * |
| 1609 | * Technically this ought not be needed assuming we |
| 1610 | * get a DATA_COMPLETE eventually (we'll notice the |
| 1611 | * error and end the request), but it shouldn't hurt. |
| 1612 | * |
| 1613 | * This has the advantage of sending the stop command. |
| 1614 | */ |
| 1615 | if (test_and_clear_bit(EVENT_DATA_ERROR, |
| 1616 | &host->pending_events)) { |
| 1617 | dw_mci_stop_dma(host); |
addy ke | bdb9a90 | 2015-02-20 10:55:25 +0800 | [diff] [blame] | 1618 | if (data->stop || |
| 1619 | !(host->data_status & (SDMMC_INT_DRTO | |
| 1620 | SDMMC_INT_EBE))) |
| 1621 | send_stop_abort(host, data); |
Doug Anderson | 2aa3546 | 2014-08-13 08:13:43 -0700 | [diff] [blame] | 1622 | state = STATE_DATA_ERROR; |
| 1623 | break; |
| 1624 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1625 | prev_state = state = STATE_DATA_BUSY; |
Doug Anderson | 2aa3546 | 2014-08-13 08:13:43 -0700 | [diff] [blame] | 1626 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1627 | /* fall through */ |
| 1628 | |
| 1629 | case STATE_DATA_BUSY: |
| 1630 | if (!test_and_clear_bit(EVENT_DATA_COMPLETE, |
| 1631 | &host->pending_events)) |
| 1632 | break; |
| 1633 | |
| 1634 | host->data = NULL; |
| 1635 | set_bit(EVENT_DATA_COMPLETE, &host->completed_events); |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1636 | err = dw_mci_data_complete(host, data); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1637 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1638 | if (!err) { |
| 1639 | if (!data->stop || mrq->sbc) { |
Sachin Kamat | 17c8bc8 | 2014-02-25 15:18:28 +0530 | [diff] [blame] | 1640 | if (mrq->sbc && data->stop) |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1641 | data->stop->error = 0; |
| 1642 | dw_mci_request_end(host, mrq); |
| 1643 | goto unlock; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1644 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1645 | |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1646 | /* stop command for open-ended transfer*/ |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1647 | if (data->stop) |
| 1648 | send_stop_abort(host, data); |
Doug Anderson | 2aa3546 | 2014-08-13 08:13:43 -0700 | [diff] [blame] | 1649 | } else { |
| 1650 | /* |
| 1651 | * If we don't have a command complete now we'll |
| 1652 | * never get one since we just reset everything; |
| 1653 | * better end the request. |
| 1654 | * |
| 1655 | * If we do have a command complete we'll fall |
| 1656 | * through to the SENDING_STOP command and |
| 1657 | * everything will be peachy keen. |
| 1658 | */ |
| 1659 | if (!test_bit(EVENT_CMD_COMPLETE, |
| 1660 | &host->pending_events)) { |
| 1661 | host->cmd = NULL; |
| 1662 | dw_mci_request_end(host, mrq); |
| 1663 | goto unlock; |
| 1664 | } |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1665 | } |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1666 | |
| 1667 | /* |
| 1668 | * If err has non-zero, |
| 1669 | * stop-abort command has been already issued. |
| 1670 | */ |
| 1671 | prev_state = state = STATE_SENDING_STOP; |
| 1672 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1673 | /* fall through */ |
| 1674 | |
| 1675 | case STATE_SENDING_STOP: |
| 1676 | if (!test_and_clear_bit(EVENT_CMD_COMPLETE, |
| 1677 | &host->pending_events)) |
| 1678 | break; |
| 1679 | |
Seungwon Jeon | 71abb13 | 2013-08-31 00:13:59 +0900 | [diff] [blame] | 1680 | /* CMD error in data command */ |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 1681 | if (mrq->cmd->error && mrq->data) |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 1682 | dw_mci_reset(host); |
Seungwon Jeon | 71abb13 | 2013-08-31 00:13:59 +0900 | [diff] [blame] | 1683 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1684 | host->cmd = NULL; |
Seungwon Jeon | 71abb13 | 2013-08-31 00:13:59 +0900 | [diff] [blame] | 1685 | host->data = NULL; |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1686 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1687 | if (mrq->stop) |
| 1688 | dw_mci_command_complete(host, mrq->stop); |
Seungwon Jeon | 90c2143 | 2013-08-31 00:14:05 +0900 | [diff] [blame] | 1689 | else |
| 1690 | host->cmd_status = 0; |
| 1691 | |
Seungwon Jeon | e352c81 | 2013-08-31 00:14:17 +0900 | [diff] [blame] | 1692 | dw_mci_request_end(host, mrq); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1693 | goto unlock; |
| 1694 | |
| 1695 | case STATE_DATA_ERROR: |
| 1696 | if (!test_and_clear_bit(EVENT_XFER_COMPLETE, |
| 1697 | &host->pending_events)) |
| 1698 | break; |
| 1699 | |
| 1700 | state = STATE_DATA_BUSY; |
| 1701 | break; |
| 1702 | } |
| 1703 | } while (state != prev_state); |
| 1704 | |
| 1705 | host->state = state; |
| 1706 | unlock: |
| 1707 | spin_unlock(&host->lock); |
| 1708 | |
| 1709 | } |
| 1710 | |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1711 | /* push final bytes to part_buf, only use during push */ |
| 1712 | static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1713 | { |
| 1714 | memcpy((void *)&host->part_buf, buf, cnt); |
| 1715 | host->part_buf_count = cnt; |
| 1716 | } |
| 1717 | |
| 1718 | /* append bytes to part_buf, only use during push */ |
| 1719 | static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1720 | { |
| 1721 | cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count); |
| 1722 | memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt); |
| 1723 | host->part_buf_count += cnt; |
| 1724 | return cnt; |
| 1725 | } |
| 1726 | |
| 1727 | /* pull first bytes from part_buf, only use during pull */ |
| 1728 | static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1729 | { |
| 1730 | cnt = min(cnt, (int)host->part_buf_count); |
| 1731 | if (cnt) { |
| 1732 | memcpy(buf, (void *)&host->part_buf + host->part_buf_start, |
| 1733 | cnt); |
| 1734 | host->part_buf_count -= cnt; |
| 1735 | host->part_buf_start += cnt; |
| 1736 | } |
| 1737 | return cnt; |
| 1738 | } |
| 1739 | |
| 1740 | /* pull final bytes from the part_buf, assuming it's just been filled */ |
| 1741 | static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1742 | { |
| 1743 | memcpy(buf, &host->part_buf, cnt); |
| 1744 | host->part_buf_start = cnt; |
| 1745 | host->part_buf_count = (1 << host->data_shift) - cnt; |
| 1746 | } |
| 1747 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1748 | static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt) |
| 1749 | { |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1750 | struct mmc_data *data = host->data; |
| 1751 | int init_cnt = cnt; |
| 1752 | |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1753 | /* try and push anything in the part_buf */ |
| 1754 | if (unlikely(host->part_buf_count)) { |
| 1755 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1756 | buf += len; |
| 1757 | cnt -= len; |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1758 | if (host->part_buf_count == 2) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1759 | mci_writew(host, DATA(host->data_offset), |
| 1760 | host->part_buf16); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1761 | host->part_buf_count = 0; |
| 1762 | } |
| 1763 | } |
| 1764 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1765 | if (unlikely((unsigned long)buf & 0x1)) { |
| 1766 | while (cnt >= 2) { |
| 1767 | u16 aligned_buf[64]; |
| 1768 | int len = min(cnt & -2, (int)sizeof(aligned_buf)); |
| 1769 | int items = len >> 1; |
| 1770 | int i; |
| 1771 | /* memcpy from input buffer into aligned buffer */ |
| 1772 | memcpy(aligned_buf, buf, len); |
| 1773 | buf += len; |
| 1774 | cnt -= len; |
| 1775 | /* push data from aligned buffer into fifo */ |
| 1776 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1777 | mci_writew(host, DATA(host->data_offset), |
| 1778 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1779 | } |
| 1780 | } else |
| 1781 | #endif |
| 1782 | { |
| 1783 | u16 *pdata = buf; |
| 1784 | for (; cnt >= 2; cnt -= 2) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1785 | mci_writew(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1786 | buf = pdata; |
| 1787 | } |
| 1788 | /* put anything remaining in the part_buf */ |
| 1789 | if (cnt) { |
| 1790 | dw_mci_set_part_bytes(host, buf, cnt); |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1791 | /* Push data if we have reached the expected data length */ |
| 1792 | if ((data->bytes_xfered + init_cnt) == |
| 1793 | (data->blksz * data->blocks)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1794 | mci_writew(host, DATA(host->data_offset), |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1795 | host->part_buf16); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt) |
| 1800 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1801 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1802 | if (unlikely((unsigned long)buf & 0x1)) { |
| 1803 | while (cnt >= 2) { |
| 1804 | /* pull data from fifo into aligned buffer */ |
| 1805 | u16 aligned_buf[64]; |
| 1806 | int len = min(cnt & -2, (int)sizeof(aligned_buf)); |
| 1807 | int items = len >> 1; |
| 1808 | int i; |
| 1809 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1810 | aligned_buf[i] = mci_readw(host, |
| 1811 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1812 | /* memcpy from aligned buffer into output buffer */ |
| 1813 | memcpy(buf, aligned_buf, len); |
| 1814 | buf += len; |
| 1815 | cnt -= len; |
| 1816 | } |
| 1817 | } else |
| 1818 | #endif |
| 1819 | { |
| 1820 | u16 *pdata = buf; |
| 1821 | for (; cnt >= 2; cnt -= 2) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1822 | *pdata++ = mci_readw(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1823 | buf = pdata; |
| 1824 | } |
| 1825 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1826 | host->part_buf16 = mci_readw(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1827 | dw_mci_pull_final_bytes(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt) |
| 1832 | { |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1833 | struct mmc_data *data = host->data; |
| 1834 | int init_cnt = cnt; |
| 1835 | |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1836 | /* try and push anything in the part_buf */ |
| 1837 | if (unlikely(host->part_buf_count)) { |
| 1838 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1839 | buf += len; |
| 1840 | cnt -= len; |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1841 | if (host->part_buf_count == 4) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1842 | mci_writel(host, DATA(host->data_offset), |
| 1843 | host->part_buf32); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1844 | host->part_buf_count = 0; |
| 1845 | } |
| 1846 | } |
| 1847 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1848 | if (unlikely((unsigned long)buf & 0x3)) { |
| 1849 | while (cnt >= 4) { |
| 1850 | u32 aligned_buf[32]; |
| 1851 | int len = min(cnt & -4, (int)sizeof(aligned_buf)); |
| 1852 | int items = len >> 2; |
| 1853 | int i; |
| 1854 | /* memcpy from input buffer into aligned buffer */ |
| 1855 | memcpy(aligned_buf, buf, len); |
| 1856 | buf += len; |
| 1857 | cnt -= len; |
| 1858 | /* push data from aligned buffer into fifo */ |
| 1859 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1860 | mci_writel(host, DATA(host->data_offset), |
| 1861 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1862 | } |
| 1863 | } else |
| 1864 | #endif |
| 1865 | { |
| 1866 | u32 *pdata = buf; |
| 1867 | for (; cnt >= 4; cnt -= 4) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1868 | mci_writel(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1869 | buf = pdata; |
| 1870 | } |
| 1871 | /* put anything remaining in the part_buf */ |
| 1872 | if (cnt) { |
| 1873 | dw_mci_set_part_bytes(host, buf, cnt); |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1874 | /* Push data if we have reached the expected data length */ |
| 1875 | if ((data->bytes_xfered + init_cnt) == |
| 1876 | (data->blksz * data->blocks)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1877 | mci_writel(host, DATA(host->data_offset), |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1878 | host->part_buf32); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt) |
| 1883 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1884 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1885 | if (unlikely((unsigned long)buf & 0x3)) { |
| 1886 | while (cnt >= 4) { |
| 1887 | /* pull data from fifo into aligned buffer */ |
| 1888 | u32 aligned_buf[32]; |
| 1889 | int len = min(cnt & -4, (int)sizeof(aligned_buf)); |
| 1890 | int items = len >> 2; |
| 1891 | int i; |
| 1892 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1893 | aligned_buf[i] = mci_readl(host, |
| 1894 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1895 | /* memcpy from aligned buffer into output buffer */ |
| 1896 | memcpy(buf, aligned_buf, len); |
| 1897 | buf += len; |
| 1898 | cnt -= len; |
| 1899 | } |
| 1900 | } else |
| 1901 | #endif |
| 1902 | { |
| 1903 | u32 *pdata = buf; |
| 1904 | for (; cnt >= 4; cnt -= 4) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1905 | *pdata++ = mci_readl(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1906 | buf = pdata; |
| 1907 | } |
| 1908 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1909 | host->part_buf32 = mci_readl(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1910 | dw_mci_pull_final_bytes(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt) |
| 1915 | { |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1916 | struct mmc_data *data = host->data; |
| 1917 | int init_cnt = cnt; |
| 1918 | |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1919 | /* try and push anything in the part_buf */ |
| 1920 | if (unlikely(host->part_buf_count)) { |
| 1921 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1922 | buf += len; |
| 1923 | cnt -= len; |
Seungwon Jeon | c09fbd7 | 2013-03-25 16:28:22 +0900 | [diff] [blame] | 1924 | |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1925 | if (host->part_buf_count == 8) { |
Seungwon Jeon | c09fbd7 | 2013-03-25 16:28:22 +0900 | [diff] [blame] | 1926 | mci_writeq(host, DATA(host->data_offset), |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1927 | host->part_buf); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1928 | host->part_buf_count = 0; |
| 1929 | } |
| 1930 | } |
| 1931 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1932 | if (unlikely((unsigned long)buf & 0x7)) { |
| 1933 | while (cnt >= 8) { |
| 1934 | u64 aligned_buf[16]; |
| 1935 | int len = min(cnt & -8, (int)sizeof(aligned_buf)); |
| 1936 | int items = len >> 3; |
| 1937 | int i; |
| 1938 | /* memcpy from input buffer into aligned buffer */ |
| 1939 | memcpy(aligned_buf, buf, len); |
| 1940 | buf += len; |
| 1941 | cnt -= len; |
| 1942 | /* push data from aligned buffer into fifo */ |
| 1943 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1944 | mci_writeq(host, DATA(host->data_offset), |
| 1945 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1946 | } |
| 1947 | } else |
| 1948 | #endif |
| 1949 | { |
| 1950 | u64 *pdata = buf; |
| 1951 | for (; cnt >= 8; cnt -= 8) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1952 | mci_writeq(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1953 | buf = pdata; |
| 1954 | } |
| 1955 | /* put anything remaining in the part_buf */ |
| 1956 | if (cnt) { |
| 1957 | dw_mci_set_part_bytes(host, buf, cnt); |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1958 | /* Push data if we have reached the expected data length */ |
| 1959 | if ((data->bytes_xfered + init_cnt) == |
| 1960 | (data->blksz * data->blocks)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1961 | mci_writeq(host, DATA(host->data_offset), |
Markos Chandras | cfbeb59c | 2013-03-12 10:53:13 +0000 | [diff] [blame] | 1962 | host->part_buf); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt) |
| 1967 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1968 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1969 | if (unlikely((unsigned long)buf & 0x7)) { |
| 1970 | while (cnt >= 8) { |
| 1971 | /* pull data from fifo into aligned buffer */ |
| 1972 | u64 aligned_buf[16]; |
| 1973 | int len = min(cnt & -8, (int)sizeof(aligned_buf)); |
| 1974 | int items = len >> 3; |
| 1975 | int i; |
| 1976 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1977 | aligned_buf[i] = mci_readq(host, |
| 1978 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1979 | /* memcpy from aligned buffer into output buffer */ |
| 1980 | memcpy(buf, aligned_buf, len); |
| 1981 | buf += len; |
| 1982 | cnt -= len; |
| 1983 | } |
| 1984 | } else |
| 1985 | #endif |
| 1986 | { |
| 1987 | u64 *pdata = buf; |
| 1988 | for (; cnt >= 8; cnt -= 8) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1989 | *pdata++ = mci_readq(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1990 | buf = pdata; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1991 | } |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1992 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1993 | host->part_buf = mci_readq(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1994 | dw_mci_pull_final_bytes(host, buf, cnt); |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt) |
| 1999 | { |
| 2000 | int len; |
| 2001 | |
| 2002 | /* get remaining partial bytes */ |
| 2003 | len = dw_mci_pull_part_bytes(host, buf, cnt); |
| 2004 | if (unlikely(len == cnt)) |
| 2005 | return; |
| 2006 | buf += len; |
| 2007 | cnt -= len; |
| 2008 | |
| 2009 | /* get the rest of the data */ |
| 2010 | host->pull_data(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2011 | } |
| 2012 | |
Kyoungil Kim | 87a74d3 | 2013-01-22 16:46:30 +0900 | [diff] [blame] | 2013 | static void dw_mci_read_data_pio(struct dw_mci *host, bool dto) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2014 | { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2015 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
| 2016 | void *buf; |
| 2017 | unsigned int offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2018 | struct mmc_data *data = host->data; |
| 2019 | int shift = host->data_shift; |
| 2020 | u32 status; |
Markos Chandras | 3e4b0d8 | 2013-03-22 12:50:05 -0400 | [diff] [blame] | 2021 | unsigned int len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2022 | unsigned int remain, fcnt; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2023 | |
| 2024 | do { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2025 | if (!sg_miter_next(sg_miter)) |
| 2026 | goto done; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2027 | |
Imre Deak | 4225fc8 | 2013-02-27 17:02:57 -0800 | [diff] [blame] | 2028 | host->sg = sg_miter->piter.sg; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2029 | buf = sg_miter->addr; |
| 2030 | remain = sg_miter->length; |
| 2031 | offset = 0; |
| 2032 | |
| 2033 | do { |
| 2034 | fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS)) |
| 2035 | << shift) + host->part_buf_count; |
| 2036 | len = min(remain, fcnt); |
| 2037 | if (!len) |
| 2038 | break; |
| 2039 | dw_mci_pull_data(host, (void *)(buf + offset), len); |
Markos Chandras | 3e4b0d8 | 2013-03-22 12:50:05 -0400 | [diff] [blame] | 2040 | data->bytes_xfered += len; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2041 | offset += len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2042 | remain -= len; |
| 2043 | } while (remain); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2044 | |
Seungwon Jeon | e74f3a9 | 2012-08-01 09:30:46 +0900 | [diff] [blame] | 2045 | sg_miter->consumed = offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2046 | status = mci_readl(host, MINTSTS); |
| 2047 | mci_writel(host, RINTSTS, SDMMC_INT_RXDR); |
Kyoungil Kim | 87a74d3 | 2013-01-22 16:46:30 +0900 | [diff] [blame] | 2048 | /* if the RXDR is ready read again */ |
| 2049 | } while ((status & SDMMC_INT_RXDR) || |
| 2050 | (dto && SDMMC_GET_FCNT(mci_readl(host, STATUS)))); |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2051 | |
| 2052 | if (!remain) { |
| 2053 | if (!sg_miter_next(sg_miter)) |
| 2054 | goto done; |
| 2055 | sg_miter->consumed = 0; |
| 2056 | } |
| 2057 | sg_miter_stop(sg_miter); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2058 | return; |
| 2059 | |
| 2060 | done: |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2061 | sg_miter_stop(sg_miter); |
| 2062 | host->sg = NULL; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2063 | smp_wmb(); |
| 2064 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 2065 | } |
| 2066 | |
| 2067 | static void dw_mci_write_data_pio(struct dw_mci *host) |
| 2068 | { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2069 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
| 2070 | void *buf; |
| 2071 | unsigned int offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2072 | struct mmc_data *data = host->data; |
| 2073 | int shift = host->data_shift; |
| 2074 | u32 status; |
Markos Chandras | 3e4b0d8 | 2013-03-22 12:50:05 -0400 | [diff] [blame] | 2075 | unsigned int len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2076 | unsigned int fifo_depth = host->fifo_depth; |
| 2077 | unsigned int remain, fcnt; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2078 | |
| 2079 | do { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2080 | if (!sg_miter_next(sg_miter)) |
| 2081 | goto done; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2082 | |
Imre Deak | 4225fc8 | 2013-02-27 17:02:57 -0800 | [diff] [blame] | 2083 | host->sg = sg_miter->piter.sg; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2084 | buf = sg_miter->addr; |
| 2085 | remain = sg_miter->length; |
| 2086 | offset = 0; |
| 2087 | |
| 2088 | do { |
| 2089 | fcnt = ((fifo_depth - |
| 2090 | SDMMC_GET_FCNT(mci_readl(host, STATUS))) |
| 2091 | << shift) - host->part_buf_count; |
| 2092 | len = min(remain, fcnt); |
| 2093 | if (!len) |
| 2094 | break; |
| 2095 | host->push_data(host, (void *)(buf + offset), len); |
Markos Chandras | 3e4b0d8 | 2013-03-22 12:50:05 -0400 | [diff] [blame] | 2096 | data->bytes_xfered += len; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2097 | offset += len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2098 | remain -= len; |
| 2099 | } while (remain); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2100 | |
Seungwon Jeon | e74f3a9 | 2012-08-01 09:30:46 +0900 | [diff] [blame] | 2101 | sg_miter->consumed = offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2102 | status = mci_readl(host, MINTSTS); |
| 2103 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2104 | } while (status & SDMMC_INT_TXDR); /* if TXDR write again */ |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2105 | |
| 2106 | if (!remain) { |
| 2107 | if (!sg_miter_next(sg_miter)) |
| 2108 | goto done; |
| 2109 | sg_miter->consumed = 0; |
| 2110 | } |
| 2111 | sg_miter_stop(sg_miter); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2112 | return; |
| 2113 | |
| 2114 | done: |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 2115 | sg_miter_stop(sg_miter); |
| 2116 | host->sg = NULL; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2117 | smp_wmb(); |
| 2118 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 2119 | } |
| 2120 | |
| 2121 | static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status) |
| 2122 | { |
| 2123 | if (!host->cmd_status) |
| 2124 | host->cmd_status = status; |
| 2125 | |
| 2126 | smp_wmb(); |
| 2127 | |
| 2128 | set_bit(EVENT_CMD_COMPLETE, &host->pending_events); |
| 2129 | tasklet_schedule(&host->tasklet); |
| 2130 | } |
| 2131 | |
Doug Anderson | 6130e7a | 2014-10-14 09:33:09 -0700 | [diff] [blame] | 2132 | static void dw_mci_handle_cd(struct dw_mci *host) |
| 2133 | { |
| 2134 | int i; |
| 2135 | |
| 2136 | for (i = 0; i < host->num_slots; i++) { |
| 2137 | struct dw_mci_slot *slot = host->slot[i]; |
| 2138 | |
| 2139 | if (!slot) |
| 2140 | continue; |
| 2141 | |
| 2142 | if (slot->mmc->ops->card_event) |
| 2143 | slot->mmc->ops->card_event(slot->mmc); |
| 2144 | mmc_detect_change(slot->mmc, |
| 2145 | msecs_to_jiffies(host->pdata->detect_delay_ms)); |
| 2146 | } |
| 2147 | } |
| 2148 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2149 | static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) |
| 2150 | { |
| 2151 | struct dw_mci *host = dev_id; |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 2152 | u32 pending; |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 2153 | int i; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2154 | |
Markos Chandras | 1fb5f68 | 2013-03-12 10:53:11 +0000 | [diff] [blame] | 2155 | pending = mci_readl(host, MINTSTS); /* read-only mask reg */ |
| 2156 | |
Doug Anderson | 476d79f | 2013-07-09 13:04:40 -0700 | [diff] [blame] | 2157 | /* |
| 2158 | * DTO fix - version 2.10a and below, and only if internal DMA |
| 2159 | * is configured. |
| 2160 | */ |
| 2161 | if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) { |
| 2162 | if (!pending && |
| 2163 | ((mci_readl(host, STATUS) >> 17) & 0x1fff)) |
| 2164 | pending |= SDMMC_INT_DATA_OVER; |
| 2165 | } |
| 2166 | |
Markos Chandras | 1fb5f68 | 2013-03-12 10:53:11 +0000 | [diff] [blame] | 2167 | if (pending) { |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 2168 | /* Check volt switch first, since it can look like an error */ |
| 2169 | if ((host->state == STATE_SENDING_CMD11) && |
| 2170 | (pending & SDMMC_INT_VOLT_SWITCH)) { |
Doug Anderson | 5c93516 | 2015-03-09 16:18:21 -0700 | [diff] [blame^] | 2171 | del_timer(&host->cmd11_timer); |
| 2172 | |
Doug Anderson | 0173055 | 2014-08-22 19:17:51 +0530 | [diff] [blame] | 2173 | mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH); |
| 2174 | pending &= ~SDMMC_INT_VOLT_SWITCH; |
| 2175 | dw_mci_cmd_interrupt(host, pending); |
| 2176 | } |
| 2177 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2178 | if (pending & DW_MCI_CMD_ERROR_FLAGS) { |
| 2179 | mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 2180 | host->cmd_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2181 | smp_wmb(); |
| 2182 | set_bit(EVENT_CMD_COMPLETE, &host->pending_events); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | if (pending & DW_MCI_DATA_ERROR_FLAGS) { |
| 2186 | /* if there is an error report DATA_ERROR */ |
| 2187 | mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 2188 | host->data_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2189 | smp_wmb(); |
| 2190 | set_bit(EVENT_DATA_ERROR, &host->pending_events); |
Seungwon Jeon | 9b2026a | 2012-08-01 09:30:40 +0900 | [diff] [blame] | 2191 | tasklet_schedule(&host->tasklet); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | if (pending & SDMMC_INT_DATA_OVER) { |
| 2195 | mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER); |
| 2196 | if (!host->data_status) |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 2197 | host->data_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2198 | smp_wmb(); |
| 2199 | if (host->dir_status == DW_MCI_RECV_STATUS) { |
| 2200 | if (host->sg != NULL) |
Kyoungil Kim | 87a74d3 | 2013-01-22 16:46:30 +0900 | [diff] [blame] | 2201 | dw_mci_read_data_pio(host, true); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2202 | } |
| 2203 | set_bit(EVENT_DATA_COMPLETE, &host->pending_events); |
| 2204 | tasklet_schedule(&host->tasklet); |
| 2205 | } |
| 2206 | |
| 2207 | if (pending & SDMMC_INT_RXDR) { |
| 2208 | mci_writel(host, RINTSTS, SDMMC_INT_RXDR); |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 2209 | if (host->dir_status == DW_MCI_RECV_STATUS && host->sg) |
Kyoungil Kim | 87a74d3 | 2013-01-22 16:46:30 +0900 | [diff] [blame] | 2210 | dw_mci_read_data_pio(host, false); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | if (pending & SDMMC_INT_TXDR) { |
| 2214 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR); |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 2215 | if (host->dir_status == DW_MCI_SEND_STATUS && host->sg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2216 | dw_mci_write_data_pio(host); |
| 2217 | } |
| 2218 | |
| 2219 | if (pending & SDMMC_INT_CMD_DONE) { |
| 2220 | mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 2221 | dw_mci_cmd_interrupt(host, pending); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | if (pending & SDMMC_INT_CD) { |
| 2225 | mci_writel(host, RINTSTS, SDMMC_INT_CD); |
Doug Anderson | 6130e7a | 2014-10-14 09:33:09 -0700 | [diff] [blame] | 2226 | dw_mci_handle_cd(host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2227 | } |
| 2228 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 2229 | /* Handle SDIO Interrupts */ |
| 2230 | for (i = 0; i < host->num_slots; i++) { |
| 2231 | struct dw_mci_slot *slot = host->slot[i]; |
Doug Anderson | ed2540e | 2015-02-25 10:11:52 -0800 | [diff] [blame] | 2232 | |
| 2233 | if (!slot) |
| 2234 | continue; |
| 2235 | |
Addy Ke | 7675623 | 2014-11-04 22:03:09 +0800 | [diff] [blame] | 2236 | if (pending & SDMMC_INT_SDIO(slot->sdio_id)) { |
| 2237 | mci_writel(host, RINTSTS, |
| 2238 | SDMMC_INT_SDIO(slot->sdio_id)); |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 2239 | mmc_signal_sdio_irq(slot->mmc); |
| 2240 | } |
| 2241 | } |
| 2242 | |
Markos Chandras | 1fb5f68 | 2013-03-12 10:53:11 +0000 | [diff] [blame] | 2243 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2244 | |
| 2245 | #ifdef CONFIG_MMC_DW_IDMAC |
| 2246 | /* Handle DMA interrupts */ |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 2247 | if (host->dma_64bit_address == 1) { |
| 2248 | pending = mci_readl(host, IDSTS64); |
| 2249 | if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { |
| 2250 | mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI | |
| 2251 | SDMMC_IDMAC_INT_RI); |
| 2252 | mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI); |
| 2253 | host->dma_ops->complete(host); |
| 2254 | } |
| 2255 | } else { |
| 2256 | pending = mci_readl(host, IDSTS); |
| 2257 | if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { |
| 2258 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | |
| 2259 | SDMMC_IDMAC_INT_RI); |
| 2260 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); |
| 2261 | host->dma_ops->complete(host); |
| 2262 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2263 | } |
| 2264 | #endif |
| 2265 | |
| 2266 | return IRQ_HANDLED; |
| 2267 | } |
| 2268 | |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2269 | #ifdef CONFIG_OF |
| 2270 | /* given a slot id, find out the device node representing that slot */ |
| 2271 | static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) |
| 2272 | { |
| 2273 | struct device_node *np; |
| 2274 | const __be32 *addr; |
| 2275 | int len; |
| 2276 | |
| 2277 | if (!dev || !dev->of_node) |
| 2278 | return NULL; |
| 2279 | |
| 2280 | for_each_child_of_node(dev->of_node, np) { |
| 2281 | addr = of_get_property(np, "reg", &len); |
| 2282 | if (!addr || (len < sizeof(int))) |
| 2283 | continue; |
| 2284 | if (be32_to_cpup(addr) == slot) |
| 2285 | return np; |
| 2286 | } |
| 2287 | return NULL; |
| 2288 | } |
| 2289 | |
Doug Anderson | a70aaa6 | 2013-01-11 17:03:50 +0000 | [diff] [blame] | 2290 | static struct dw_mci_of_slot_quirks { |
| 2291 | char *quirk; |
| 2292 | int id; |
| 2293 | } of_slot_quirks[] = { |
| 2294 | { |
| 2295 | .quirk = "disable-wp", |
| 2296 | .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT, |
| 2297 | }, |
| 2298 | }; |
| 2299 | |
| 2300 | static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) |
| 2301 | { |
| 2302 | struct device_node *np = dw_mci_of_find_slot_node(dev, slot); |
| 2303 | int quirks = 0; |
| 2304 | int idx; |
| 2305 | |
| 2306 | /* get quirks */ |
| 2307 | for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++) |
Jaehoon Chung | 26375b5 | 2014-08-07 16:37:58 +0900 | [diff] [blame] | 2308 | if (of_get_property(np, of_slot_quirks[idx].quirk, NULL)) { |
| 2309 | dev_warn(dev, "Slot quirk %s is deprecated\n", |
| 2310 | of_slot_quirks[idx].quirk); |
Doug Anderson | a70aaa6 | 2013-01-11 17:03:50 +0000 | [diff] [blame] | 2311 | quirks |= of_slot_quirks[idx].id; |
Jaehoon Chung | 26375b5 | 2014-08-07 16:37:58 +0900 | [diff] [blame] | 2312 | } |
Doug Anderson | a70aaa6 | 2013-01-11 17:03:50 +0000 | [diff] [blame] | 2313 | |
| 2314 | return quirks; |
| 2315 | } |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2316 | #else /* CONFIG_OF */ |
Doug Anderson | a70aaa6 | 2013-01-11 17:03:50 +0000 | [diff] [blame] | 2317 | static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) |
| 2318 | { |
| 2319 | return 0; |
| 2320 | } |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2321 | #endif /* CONFIG_OF */ |
| 2322 | |
Jaehoon Chung | 36c179a | 2012-08-23 20:31:48 +0900 | [diff] [blame] | 2323 | static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2324 | { |
| 2325 | struct mmc_host *mmc; |
| 2326 | struct dw_mci_slot *slot; |
Arnd Bergmann | e95baf1 | 2012-11-08 14:26:11 +0000 | [diff] [blame] | 2327 | const struct dw_mci_drv_data *drv_data = host->drv_data; |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2328 | int ctrl_id, ret; |
Seungwon Jeon | 1f44a2a | 2013-08-31 00:13:31 +0900 | [diff] [blame] | 2329 | u32 freq[2]; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2330 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2331 | mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2332 | if (!mmc) |
| 2333 | return -ENOMEM; |
| 2334 | |
| 2335 | slot = mmc_priv(mmc); |
| 2336 | slot->id = id; |
Addy Ke | 7675623 | 2014-11-04 22:03:09 +0800 | [diff] [blame] | 2337 | slot->sdio_id = host->sdio_id0 + id; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2338 | slot->mmc = mmc; |
| 2339 | slot->host = host; |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2340 | host->slot[id] = slot; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2341 | |
Doug Anderson | a70aaa6 | 2013-01-11 17:03:50 +0000 | [diff] [blame] | 2342 | slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id); |
| 2343 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2344 | mmc->ops = &dw_mci_ops; |
Seungwon Jeon | 1f44a2a | 2013-08-31 00:13:31 +0900 | [diff] [blame] | 2345 | if (of_property_read_u32_array(host->dev->of_node, |
| 2346 | "clock-freq-min-max", freq, 2)) { |
| 2347 | mmc->f_min = DW_MCI_FREQ_MIN; |
| 2348 | mmc->f_max = DW_MCI_FREQ_MAX; |
| 2349 | } else { |
| 2350 | mmc->f_min = freq[0]; |
| 2351 | mmc->f_max = freq[1]; |
| 2352 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2353 | |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 2354 | /*if there are external regulators, get them*/ |
| 2355 | ret = mmc_regulator_get_supply(mmc); |
| 2356 | if (ret == -EPROBE_DEFER) |
Doug Anderson | 3cf890f | 2014-08-25 11:19:04 -0700 | [diff] [blame] | 2357 | goto err_host_allocated; |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 2358 | |
| 2359 | if (!mmc->ocr_avail) |
| 2360 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2361 | |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 2362 | if (host->pdata->caps) |
| 2363 | mmc->caps = host->pdata->caps; |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 2364 | |
Abhilash Kesavan | ab26912 | 2012-11-19 10:26:21 +0530 | [diff] [blame] | 2365 | if (host->pdata->pm_caps) |
| 2366 | mmc->pm_caps = host->pdata->pm_caps; |
| 2367 | |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2368 | if (host->dev->of_node) { |
| 2369 | ctrl_id = of_alias_get_id(host->dev->of_node, "mshc"); |
| 2370 | if (ctrl_id < 0) |
| 2371 | ctrl_id = 0; |
| 2372 | } else { |
| 2373 | ctrl_id = to_platform_device(host->dev)->id; |
| 2374 | } |
James Hogan | cb27a84 | 2012-10-16 09:43:08 +0100 | [diff] [blame] | 2375 | if (drv_data && drv_data->caps) |
| 2376 | mmc->caps |= drv_data->caps[ctrl_id]; |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2377 | |
Seungwon Jeon | 4f408cc | 2011-12-09 14:55:52 +0900 | [diff] [blame] | 2378 | if (host->pdata->caps2) |
| 2379 | mmc->caps2 = host->pdata->caps2; |
Seungwon Jeon | 4f408cc | 2011-12-09 14:55:52 +0900 | [diff] [blame] | 2380 | |
Doug Anderson | 3cf890f | 2014-08-25 11:19:04 -0700 | [diff] [blame] | 2381 | ret = mmc_of_parse(mmc); |
| 2382 | if (ret) |
| 2383 | goto err_host_allocated; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2384 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2385 | if (host->pdata->blk_settings) { |
| 2386 | mmc->max_segs = host->pdata->blk_settings->max_segs; |
| 2387 | mmc->max_blk_size = host->pdata->blk_settings->max_blk_size; |
| 2388 | mmc->max_blk_count = host->pdata->blk_settings->max_blk_count; |
| 2389 | mmc->max_req_size = host->pdata->blk_settings->max_req_size; |
| 2390 | mmc->max_seg_size = host->pdata->blk_settings->max_seg_size; |
| 2391 | } else { |
| 2392 | /* Useful defaults if platform data is unset. */ |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 2393 | #ifdef CONFIG_MMC_DW_IDMAC |
| 2394 | mmc->max_segs = host->ring_size; |
| 2395 | mmc->max_blk_size = 65536; |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 2396 | mmc->max_seg_size = 0x1000; |
Seungwon Jeon | 1a25b1b | 2014-12-22 17:42:02 +0530 | [diff] [blame] | 2397 | mmc->max_req_size = mmc->max_seg_size * host->ring_size; |
| 2398 | mmc->max_blk_count = mmc->max_req_size / 512; |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 2399 | #else |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2400 | mmc->max_segs = 64; |
| 2401 | mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */ |
| 2402 | mmc->max_blk_count = 512; |
| 2403 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
| 2404 | mmc->max_seg_size = mmc->max_req_size; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2405 | #endif /* CONFIG_MMC_DW_IDMAC */ |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 2406 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2407 | |
Jaehoon Chung | ae0eb34 | 2014-03-03 11:36:48 +0900 | [diff] [blame] | 2408 | if (dw_mci_get_cd(mmc)) |
| 2409 | set_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
| 2410 | else |
| 2411 | clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
| 2412 | |
Jaehoon Chung | 0cea529 | 2013-02-15 23:45:45 +0900 | [diff] [blame] | 2413 | ret = mmc_add_host(mmc); |
| 2414 | if (ret) |
Doug Anderson | 3cf890f | 2014-08-25 11:19:04 -0700 | [diff] [blame] | 2415 | goto err_host_allocated; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2416 | |
| 2417 | #if defined(CONFIG_DEBUG_FS) |
| 2418 | dw_mci_init_debugfs(slot); |
| 2419 | #endif |
| 2420 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2421 | return 0; |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2422 | |
Doug Anderson | 3cf890f | 2014-08-25 11:19:04 -0700 | [diff] [blame] | 2423 | err_host_allocated: |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2424 | mmc_free_host(mmc); |
Yuvaraj CD | 51da224 | 2014-08-22 19:17:50 +0530 | [diff] [blame] | 2425 | return ret; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id) |
| 2429 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2430 | /* Debugfs stuff is cleaned up by mmc core */ |
| 2431 | mmc_remove_host(slot->mmc); |
| 2432 | slot->host->slot[id] = NULL; |
| 2433 | mmc_free_host(slot->mmc); |
| 2434 | } |
| 2435 | |
| 2436 | static void dw_mci_init_dma(struct dw_mci *host) |
| 2437 | { |
Prabu Thangamuthu | 69d99fd | 2014-10-20 07:12:33 +0000 | [diff] [blame] | 2438 | int addr_config; |
| 2439 | /* Check ADDR_CONFIG bit in HCON to find IDMAC address bus width */ |
| 2440 | addr_config = (mci_readl(host, HCON) >> 27) & 0x01; |
| 2441 | |
| 2442 | if (addr_config == 1) { |
| 2443 | /* host supports IDMAC in 64-bit address mode */ |
| 2444 | host->dma_64bit_address = 1; |
| 2445 | dev_info(host->dev, "IDMAC supports 64-bit address mode.\n"); |
| 2446 | if (!dma_set_mask(host->dev, DMA_BIT_MASK(64))) |
| 2447 | dma_set_coherent_mask(host->dev, DMA_BIT_MASK(64)); |
| 2448 | } else { |
| 2449 | /* host supports IDMAC in 32-bit address mode */ |
| 2450 | host->dma_64bit_address = 0; |
| 2451 | dev_info(host->dev, "IDMAC supports 32-bit address mode.\n"); |
| 2452 | } |
| 2453 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2454 | /* Alloc memory for sg translation */ |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2455 | host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2456 | &host->sg_dma, GFP_KERNEL); |
| 2457 | if (!host->sg_cpu) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2458 | dev_err(host->dev, "%s: could not alloc DMA memory\n", |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2459 | __func__); |
| 2460 | goto no_dma; |
| 2461 | } |
| 2462 | |
| 2463 | /* Determine which DMA interface to use */ |
| 2464 | #ifdef CONFIG_MMC_DW_IDMAC |
| 2465 | host->dma_ops = &dw_mci_idmac_ops; |
Seungwon Jeon | 00956ea | 2012-09-28 19:13:11 +0900 | [diff] [blame] | 2466 | dev_info(host->dev, "Using internal DMA controller.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2467 | #endif |
| 2468 | |
| 2469 | if (!host->dma_ops) |
| 2470 | goto no_dma; |
| 2471 | |
Jaehoon Chung | e1631f9 | 2012-04-18 15:42:31 +0900 | [diff] [blame] | 2472 | if (host->dma_ops->init && host->dma_ops->start && |
| 2473 | host->dma_ops->stop && host->dma_ops->cleanup) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2474 | if (host->dma_ops->init(host)) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2475 | dev_err(host->dev, "%s: Unable to initialize " |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2476 | "DMA Controller.\n", __func__); |
| 2477 | goto no_dma; |
| 2478 | } |
| 2479 | } else { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2480 | dev_err(host->dev, "DMA initialization not found.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2481 | goto no_dma; |
| 2482 | } |
| 2483 | |
| 2484 | host->use_dma = 1; |
| 2485 | return; |
| 2486 | |
| 2487 | no_dma: |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2488 | dev_info(host->dev, "Using PIO mode.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2489 | host->use_dma = 0; |
| 2490 | return; |
| 2491 | } |
| 2492 | |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2493 | static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2494 | { |
| 2495 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2496 | u32 ctrl; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2497 | |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2498 | ctrl = mci_readl(host, CTRL); |
| 2499 | ctrl |= reset; |
| 2500 | mci_writel(host, CTRL, ctrl); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2501 | |
| 2502 | /* wait till resets clear */ |
| 2503 | do { |
| 2504 | ctrl = mci_readl(host, CTRL); |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2505 | if (!(ctrl & reset)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2506 | return true; |
| 2507 | } while (time_before(jiffies, timeout)); |
| 2508 | |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2509 | dev_err(host->dev, |
| 2510 | "Timeout resetting block (ctrl reset %#x)\n", |
| 2511 | ctrl & reset); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2512 | |
| 2513 | return false; |
| 2514 | } |
| 2515 | |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2516 | static bool dw_mci_reset(struct dw_mci *host) |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2517 | { |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2518 | u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET; |
| 2519 | bool ret = false; |
| 2520 | |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2521 | /* |
| 2522 | * Reseting generates a block interrupt, hence setting |
| 2523 | * the scatter-gather pointer to NULL. |
| 2524 | */ |
| 2525 | if (host->sg) { |
| 2526 | sg_miter_stop(&host->sg_miter); |
| 2527 | host->sg = NULL; |
| 2528 | } |
| 2529 | |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2530 | if (host->use_dma) |
| 2531 | flags |= SDMMC_CTRL_DMA_RESET; |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2532 | |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2533 | if (dw_mci_ctrl_reset(host, flags)) { |
| 2534 | /* |
| 2535 | * In all cases we clear the RAWINTS register to clear any |
| 2536 | * interrupts. |
| 2537 | */ |
| 2538 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2539 | |
| 2540 | /* if using dma we wait for dma_req to clear */ |
| 2541 | if (host->use_dma) { |
| 2542 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
| 2543 | u32 status; |
| 2544 | do { |
| 2545 | status = mci_readl(host, STATUS); |
| 2546 | if (!(status & SDMMC_STATUS_DMA_REQ)) |
| 2547 | break; |
| 2548 | cpu_relax(); |
| 2549 | } while (time_before(jiffies, timeout)); |
| 2550 | |
| 2551 | if (status & SDMMC_STATUS_DMA_REQ) { |
| 2552 | dev_err(host->dev, |
| 2553 | "%s: Timeout waiting for dma_req to " |
| 2554 | "clear during reset\n", __func__); |
| 2555 | goto ciu_out; |
| 2556 | } |
| 2557 | |
| 2558 | /* when using DMA next we reset the fifo again */ |
| 2559 | if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET)) |
| 2560 | goto ciu_out; |
| 2561 | } |
| 2562 | } else { |
| 2563 | /* if the controller reset bit did clear, then set clock regs */ |
| 2564 | if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) { |
| 2565 | dev_err(host->dev, "%s: fifo/dma reset bits didn't " |
| 2566 | "clear but ciu was reset, doing clock update\n", |
| 2567 | __func__); |
| 2568 | goto ciu_out; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | #if IS_ENABLED(CONFIG_MMC_DW_IDMAC) |
| 2573 | /* It is also recommended that we reset and reprogram idmac */ |
| 2574 | dw_mci_idmac_reset(host); |
| 2575 | #endif |
| 2576 | |
| 2577 | ret = true; |
| 2578 | |
| 2579 | ciu_out: |
| 2580 | /* After a CTRL reset we need to have CIU set clock registers */ |
| 2581 | mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0); |
| 2582 | |
| 2583 | return ret; |
Seungwon Jeon | 31bff45 | 2013-08-31 00:14:23 +0900 | [diff] [blame] | 2584 | } |
| 2585 | |
Doug Anderson | 5c93516 | 2015-03-09 16:18:21 -0700 | [diff] [blame^] | 2586 | static void dw_mci_cmd11_timer(unsigned long arg) |
| 2587 | { |
| 2588 | struct dw_mci *host = (struct dw_mci *)arg; |
| 2589 | |
| 2590 | if (host->state != STATE_SENDING_CMD11) |
| 2591 | dev_info(host->dev, "Unexpected CMD11 timeout\n"); |
| 2592 | |
| 2593 | host->cmd_status = SDMMC_INT_RTO; |
| 2594 | set_bit(EVENT_CMD_COMPLETE, &host->pending_events); |
| 2595 | tasklet_schedule(&host->tasklet); |
| 2596 | } |
| 2597 | |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2598 | #ifdef CONFIG_OF |
| 2599 | static struct dw_mci_of_quirks { |
| 2600 | char *quirk; |
| 2601 | int id; |
| 2602 | } of_quirks[] = { |
| 2603 | { |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2604 | .quirk = "broken-cd", |
| 2605 | .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION, |
Jaehoon Chung | 26375b5 | 2014-08-07 16:37:58 +0900 | [diff] [blame] | 2606 | }, { |
| 2607 | .quirk = "disable-wp", |
| 2608 | .id = DW_MCI_QUIRK_NO_WRITE_PROTECT, |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2609 | }, |
| 2610 | }; |
| 2611 | |
| 2612 | static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) |
| 2613 | { |
| 2614 | struct dw_mci_board *pdata; |
| 2615 | struct device *dev = host->dev; |
| 2616 | struct device_node *np = dev->of_node; |
Arnd Bergmann | e95baf1 | 2012-11-08 14:26:11 +0000 | [diff] [blame] | 2617 | const struct dw_mci_drv_data *drv_data = host->drv_data; |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2618 | int idx, ret; |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2619 | u32 clock_frequency; |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2620 | |
| 2621 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
Beomho Seo | bf3707e | 2014-12-23 21:07:33 +0900 | [diff] [blame] | 2622 | if (!pdata) |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2623 | return ERR_PTR(-ENOMEM); |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2624 | |
| 2625 | /* find out number of slots supported */ |
| 2626 | if (of_property_read_u32(dev->of_node, "num-slots", |
| 2627 | &pdata->num_slots)) { |
| 2628 | dev_info(dev, "num-slots property not found, " |
| 2629 | "assuming 1 slot is available\n"); |
| 2630 | pdata->num_slots = 1; |
| 2631 | } |
| 2632 | |
| 2633 | /* get quirks */ |
| 2634 | for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++) |
| 2635 | if (of_get_property(np, of_quirks[idx].quirk, NULL)) |
| 2636 | pdata->quirks |= of_quirks[idx].id; |
| 2637 | |
| 2638 | if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth)) |
| 2639 | dev_info(dev, "fifo-depth property not found, using " |
| 2640 | "value of FIFOTH register as default\n"); |
| 2641 | |
| 2642 | of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms); |
| 2643 | |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2644 | if (!of_property_read_u32(np, "clock-frequency", &clock_frequency)) |
| 2645 | pdata->bus_hz = clock_frequency; |
| 2646 | |
James Hogan | cb27a84 | 2012-10-16 09:43:08 +0100 | [diff] [blame] | 2647 | if (drv_data && drv_data->parse_dt) { |
| 2648 | ret = drv_data->parse_dt(host); |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2649 | if (ret) |
| 2650 | return ERR_PTR(ret); |
| 2651 | } |
| 2652 | |
Seungwon Jeon | 10b4984 | 2013-08-31 00:13:22 +0900 | [diff] [blame] | 2653 | if (of_find_property(np, "supports-highspeed", NULL)) |
| 2654 | pdata->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; |
| 2655 | |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2656 | return pdata; |
| 2657 | } |
| 2658 | |
| 2659 | #else /* CONFIG_OF */ |
| 2660 | static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) |
| 2661 | { |
| 2662 | return ERR_PTR(-EINVAL); |
| 2663 | } |
| 2664 | #endif /* CONFIG_OF */ |
| 2665 | |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 2666 | static void dw_mci_enable_cd(struct dw_mci *host) |
| 2667 | { |
| 2668 | struct dw_mci_board *brd = host->pdata; |
| 2669 | unsigned long irqflags; |
| 2670 | u32 temp; |
| 2671 | int i; |
| 2672 | |
| 2673 | /* No need for CD if broken card detection */ |
| 2674 | if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) |
| 2675 | return; |
| 2676 | |
| 2677 | /* No need for CD if all slots have a non-error GPIO */ |
| 2678 | for (i = 0; i < host->num_slots; i++) { |
| 2679 | struct dw_mci_slot *slot = host->slot[i]; |
| 2680 | |
| 2681 | if (IS_ERR_VALUE(mmc_gpio_get_cd(slot->mmc))) |
| 2682 | break; |
| 2683 | } |
| 2684 | if (i == host->num_slots) |
| 2685 | return; |
| 2686 | |
| 2687 | spin_lock_irqsave(&host->irq_lock, irqflags); |
| 2688 | temp = mci_readl(host, INTMASK); |
| 2689 | temp |= SDMMC_INT_CD; |
| 2690 | mci_writel(host, INTMASK, temp); |
| 2691 | spin_unlock_irqrestore(&host->irq_lock, irqflags); |
| 2692 | } |
| 2693 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2694 | int dw_mci_probe(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2695 | { |
Arnd Bergmann | e95baf1 | 2012-11-08 14:26:11 +0000 | [diff] [blame] | 2696 | const struct dw_mci_drv_data *drv_data = host->drv_data; |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2697 | int width, i, ret = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2698 | u32 fifo_size; |
Thomas Abraham | 1c2215b | 2012-09-17 18:16:37 +0000 | [diff] [blame] | 2699 | int init_slots = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2700 | |
Thomas Abraham | c91eab4 | 2012-09-17 18:16:40 +0000 | [diff] [blame] | 2701 | if (!host->pdata) { |
| 2702 | host->pdata = dw_mci_parse_dt(host); |
| 2703 | if (IS_ERR(host->pdata)) { |
| 2704 | dev_err(host->dev, "platform data not available\n"); |
| 2705 | return -EINVAL; |
| 2706 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2707 | } |
| 2708 | |
Jaehoon Chung | 907abd5 | 2014-03-03 11:36:43 +0900 | [diff] [blame] | 2709 | if (host->pdata->num_slots > 1) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2710 | dev_err(host->dev, |
Jaehoon Chung | 907abd5 | 2014-03-03 11:36:43 +0900 | [diff] [blame] | 2711 | "Platform data must supply num_slots.\n"); |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2712 | return -ENODEV; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2713 | } |
| 2714 | |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2715 | host->biu_clk = devm_clk_get(host->dev, "biu"); |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2716 | if (IS_ERR(host->biu_clk)) { |
| 2717 | dev_dbg(host->dev, "biu clock not available\n"); |
| 2718 | } else { |
| 2719 | ret = clk_prepare_enable(host->biu_clk); |
| 2720 | if (ret) { |
| 2721 | dev_err(host->dev, "failed to enable biu clock\n"); |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2722 | return ret; |
| 2723 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2724 | } |
| 2725 | |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2726 | host->ciu_clk = devm_clk_get(host->dev, "ciu"); |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2727 | if (IS_ERR(host->ciu_clk)) { |
| 2728 | dev_dbg(host->dev, "ciu clock not available\n"); |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2729 | host->bus_hz = host->pdata->bus_hz; |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2730 | } else { |
| 2731 | ret = clk_prepare_enable(host->ciu_clk); |
| 2732 | if (ret) { |
| 2733 | dev_err(host->dev, "failed to enable ciu clock\n"); |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2734 | goto err_clk_biu; |
| 2735 | } |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2736 | |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2737 | if (host->pdata->bus_hz) { |
| 2738 | ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz); |
| 2739 | if (ret) |
| 2740 | dev_warn(host->dev, |
Jaehoon Chung | 612de4c | 2014-03-03 11:36:42 +0900 | [diff] [blame] | 2741 | "Unable to set bus rate to %uHz\n", |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2742 | host->pdata->bus_hz); |
| 2743 | } |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2744 | host->bus_hz = clk_get_rate(host->ciu_clk); |
Doug Anderson | 3c6d89e | 2013-06-07 10:28:30 -0700 | [diff] [blame] | 2745 | } |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2746 | |
Jaehoon Chung | 612de4c | 2014-03-03 11:36:42 +0900 | [diff] [blame] | 2747 | if (!host->bus_hz) { |
| 2748 | dev_err(host->dev, |
| 2749 | "Platform data must supply bus speed\n"); |
| 2750 | ret = -ENODEV; |
| 2751 | goto err_clk_ciu; |
| 2752 | } |
| 2753 | |
Yuvaraj Kumar C D | 002f0d5 | 2013-08-31 00:12:19 +0900 | [diff] [blame] | 2754 | if (drv_data && drv_data->init) { |
| 2755 | ret = drv_data->init(host); |
| 2756 | if (ret) { |
| 2757 | dev_err(host->dev, |
| 2758 | "implementation specific init failed\n"); |
| 2759 | goto err_clk_ciu; |
| 2760 | } |
| 2761 | } |
| 2762 | |
James Hogan | cb27a84 | 2012-10-16 09:43:08 +0100 | [diff] [blame] | 2763 | if (drv_data && drv_data->setup_clock) { |
| 2764 | ret = drv_data->setup_clock(host); |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 2765 | if (ret) { |
| 2766 | dev_err(host->dev, |
| 2767 | "implementation specific clock setup failed\n"); |
| 2768 | goto err_clk_ciu; |
| 2769 | } |
| 2770 | } |
| 2771 | |
Doug Anderson | 5c93516 | 2015-03-09 16:18:21 -0700 | [diff] [blame^] | 2772 | setup_timer(&host->cmd11_timer, |
| 2773 | dw_mci_cmd11_timer, (unsigned long)host); |
| 2774 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2775 | host->quirks = host->pdata->quirks; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2776 | |
| 2777 | spin_lock_init(&host->lock); |
Doug Anderson | f8c58c1 | 2014-12-02 15:42:47 -0800 | [diff] [blame] | 2778 | spin_lock_init(&host->irq_lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2779 | INIT_LIST_HEAD(&host->queue); |
| 2780 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2781 | /* |
| 2782 | * Get the host data width - this assumes that HCON has been set with |
| 2783 | * the correct values. |
| 2784 | */ |
| 2785 | i = (mci_readl(host, HCON) >> 7) & 0x7; |
| 2786 | if (!i) { |
| 2787 | host->push_data = dw_mci_push_data16; |
| 2788 | host->pull_data = dw_mci_pull_data16; |
| 2789 | width = 16; |
| 2790 | host->data_shift = 1; |
| 2791 | } else if (i == 2) { |
| 2792 | host->push_data = dw_mci_push_data64; |
| 2793 | host->pull_data = dw_mci_pull_data64; |
| 2794 | width = 64; |
| 2795 | host->data_shift = 3; |
| 2796 | } else { |
| 2797 | /* Check for a reserved value, and warn if it is */ |
| 2798 | WARN((i != 1), |
| 2799 | "HCON reports a reserved host data width!\n" |
| 2800 | "Defaulting to 32-bit access.\n"); |
| 2801 | host->push_data = dw_mci_push_data32; |
| 2802 | host->pull_data = dw_mci_pull_data32; |
| 2803 | width = 32; |
| 2804 | host->data_shift = 2; |
| 2805 | } |
| 2806 | |
| 2807 | /* Reset all blocks */ |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2808 | if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 2809 | return -ENODEV; |
| 2810 | |
| 2811 | host->dma_ops = host->pdata->dma_ops; |
| 2812 | dw_mci_init_dma(host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2813 | |
| 2814 | /* Clear the interrupts for the host controller */ |
| 2815 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2816 | mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ |
| 2817 | |
| 2818 | /* Put in max timeout */ |
| 2819 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
| 2820 | |
| 2821 | /* |
| 2822 | * FIFO threshold settings RxMark = fifo_size / 2 - 1, |
| 2823 | * Tx Mark = fifo_size / 2 DMA Size = 8 |
| 2824 | */ |
James Hogan | b86d825 | 2011-06-24 13:57:18 +0100 | [diff] [blame] | 2825 | if (!host->pdata->fifo_depth) { |
| 2826 | /* |
| 2827 | * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may |
| 2828 | * have been overwritten by the bootloader, just like we're |
| 2829 | * about to do, so if you know the value for your hardware, you |
| 2830 | * should put it in the platform data. |
| 2831 | */ |
| 2832 | fifo_size = mci_readl(host, FIFOTH); |
Jaehoon Chung | 8234e86 | 2012-01-11 09:28:21 +0000 | [diff] [blame] | 2833 | fifo_size = 1 + ((fifo_size >> 16) & 0xfff); |
James Hogan | b86d825 | 2011-06-24 13:57:18 +0100 | [diff] [blame] | 2834 | } else { |
| 2835 | fifo_size = host->pdata->fifo_depth; |
| 2836 | } |
| 2837 | host->fifo_depth = fifo_size; |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 2838 | host->fifoth_val = |
| 2839 | SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2); |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2840 | mci_writel(host, FIFOTH, host->fifoth_val); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2841 | |
| 2842 | /* disable clock to CIU */ |
| 2843 | mci_writel(host, CLKENA, 0); |
| 2844 | mci_writel(host, CLKSRC, 0); |
| 2845 | |
James Hogan | 6300876 | 2013-03-12 10:43:54 +0000 | [diff] [blame] | 2846 | /* |
| 2847 | * In 2.40a spec, Data offset is changed. |
| 2848 | * Need to check the version-id and set data-offset for DATA register. |
| 2849 | */ |
| 2850 | host->verid = SDMMC_GET_VERID(mci_readl(host, VERID)); |
| 2851 | dev_info(host->dev, "Version ID is %04x\n", host->verid); |
| 2852 | |
| 2853 | if (host->verid < DW_MMC_240A) |
| 2854 | host->data_offset = DATA_OFFSET; |
| 2855 | else |
| 2856 | host->data_offset = DATA_240A_OFFSET; |
| 2857 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2858 | tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2859 | ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt, |
| 2860 | host->irq_flags, "dw-mci", host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2861 | if (ret) |
Doug Anderson | 6130e7a | 2014-10-14 09:33:09 -0700 | [diff] [blame] | 2862 | goto err_dmaunmap; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2863 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2864 | if (host->pdata->num_slots) |
| 2865 | host->num_slots = host->pdata->num_slots; |
| 2866 | else |
| 2867 | host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1; |
| 2868 | |
Yuvaraj CD | 2da1d7f | 2012-10-08 14:29:51 +0530 | [diff] [blame] | 2869 | /* |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 2870 | * Enable interrupts for command done, data over, data empty, |
Yuvaraj CD | 2da1d7f | 2012-10-08 14:29:51 +0530 | [diff] [blame] | 2871 | * receive ready and error such as transmit, receive timeout, crc error |
| 2872 | */ |
| 2873 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2874 | mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | |
| 2875 | SDMMC_INT_TXDR | SDMMC_INT_RXDR | |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 2876 | DW_MCI_ERROR_FLAGS); |
Yuvaraj CD | 2da1d7f | 2012-10-08 14:29:51 +0530 | [diff] [blame] | 2877 | mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */ |
| 2878 | |
| 2879 | dev_info(host->dev, "DW MMC controller at irq %d, " |
| 2880 | "%d bit host data width, " |
| 2881 | "%u deep fifo\n", |
| 2882 | host->irq, width, fifo_size); |
| 2883 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2884 | /* We need at least one slot to succeed */ |
| 2885 | for (i = 0; i < host->num_slots; i++) { |
| 2886 | ret = dw_mci_init_slot(host, i); |
Thomas Abraham | 1c2215b | 2012-09-17 18:16:37 +0000 | [diff] [blame] | 2887 | if (ret) |
| 2888 | dev_dbg(host->dev, "slot %d init failed\n", i); |
| 2889 | else |
| 2890 | init_slots++; |
| 2891 | } |
| 2892 | |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 2893 | /* Now that slots are all setup, we can enable card detect */ |
| 2894 | dw_mci_enable_cd(host); |
| 2895 | |
Thomas Abraham | 1c2215b | 2012-09-17 18:16:37 +0000 | [diff] [blame] | 2896 | if (init_slots) { |
| 2897 | dev_info(host->dev, "%d slots initialized\n", init_slots); |
| 2898 | } else { |
| 2899 | dev_dbg(host->dev, "attempted to initialize %d slots, " |
| 2900 | "but failed on all\n", host->num_slots); |
Doug Anderson | 6130e7a | 2014-10-14 09:33:09 -0700 | [diff] [blame] | 2901 | goto err_dmaunmap; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2902 | } |
| 2903 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2904 | if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2905 | dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2906 | |
| 2907 | return 0; |
| 2908 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2909 | err_dmaunmap: |
| 2910 | if (host->use_dma && host->dma_ops->exit) |
| 2911 | host->dma_ops->exit(host); |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2912 | |
| 2913 | err_clk_ciu: |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2914 | if (!IS_ERR(host->ciu_clk)) |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2915 | clk_disable_unprepare(host->ciu_clk); |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2916 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2917 | err_clk_biu: |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2918 | if (!IS_ERR(host->biu_clk)) |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2919 | clk_disable_unprepare(host->biu_clk); |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2920 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2921 | return ret; |
| 2922 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2923 | EXPORT_SYMBOL(dw_mci_probe); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2924 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2925 | void dw_mci_remove(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2926 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2927 | int i; |
| 2928 | |
| 2929 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2930 | mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ |
| 2931 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2932 | for (i = 0; i < host->num_slots; i++) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2933 | dev_dbg(host->dev, "remove slot %d\n", i); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2934 | if (host->slot[i]) |
| 2935 | dw_mci_cleanup_slot(host->slot[i], i); |
| 2936 | } |
| 2937 | |
| 2938 | /* disable clock to CIU */ |
| 2939 | mci_writel(host, CLKENA, 0); |
| 2940 | mci_writel(host, CLKSRC, 0); |
| 2941 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2942 | if (host->use_dma && host->dma_ops->exit) |
| 2943 | host->dma_ops->exit(host); |
| 2944 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2945 | if (!IS_ERR(host->ciu_clk)) |
| 2946 | clk_disable_unprepare(host->ciu_clk); |
Seungwon Jeon | 780f22a | 2012-11-28 19:26:03 +0900 | [diff] [blame] | 2947 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2948 | if (!IS_ERR(host->biu_clk)) |
| 2949 | clk_disable_unprepare(host->biu_clk); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2950 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2951 | EXPORT_SYMBOL(dw_mci_remove); |
| 2952 | |
| 2953 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2954 | |
Jaehoon Chung | 6fe8890 | 2011-12-08 19:23:03 +0900 | [diff] [blame] | 2955 | #ifdef CONFIG_PM_SLEEP |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2956 | /* |
| 2957 | * TODO: we should probably disable the clock to the card in the suspend path. |
| 2958 | */ |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2959 | int dw_mci_suspend(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2960 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2961 | return 0; |
| 2962 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2963 | EXPORT_SYMBOL(dw_mci_suspend); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2964 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2965 | int dw_mci_resume(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2966 | { |
| 2967 | int i, ret; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2968 | |
Sonny Rao | 3a33a94 | 2014-08-04 18:19:50 -0700 | [diff] [blame] | 2969 | if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) { |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2970 | ret = -ENODEV; |
| 2971 | return ret; |
| 2972 | } |
| 2973 | |
Jonathan Kliegman | 3bfe619 | 2012-06-14 13:31:55 -0400 | [diff] [blame] | 2974 | if (host->use_dma && host->dma_ops->init) |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 2975 | host->dma_ops->init(host); |
| 2976 | |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 2977 | /* |
| 2978 | * Restore the initial value at FIFOTH register |
| 2979 | * And Invalidate the prev_blksz with zero |
| 2980 | */ |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2981 | mci_writel(host, FIFOTH, host->fifoth_val); |
Seungwon Jeon | 5242689 | 2013-08-31 00:13:42 +0900 | [diff] [blame] | 2982 | host->prev_blksz = 0; |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2983 | |
Doug Anderson | 2eb2944 | 2013-08-31 00:11:49 +0900 | [diff] [blame] | 2984 | /* Put in max timeout */ |
| 2985 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
| 2986 | |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2987 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2988 | mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | |
| 2989 | SDMMC_INT_TXDR | SDMMC_INT_RXDR | |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 2990 | DW_MCI_ERROR_FLAGS); |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2991 | mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); |
| 2992 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2993 | for (i = 0; i < host->num_slots; i++) { |
| 2994 | struct dw_mci_slot *slot = host->slot[i]; |
| 2995 | if (!slot) |
| 2996 | continue; |
Abhilash Kesavan | ab26912 | 2012-11-19 10:26:21 +0530 | [diff] [blame] | 2997 | if (slot->mmc->pm_flags & MMC_PM_KEEP_POWER) { |
| 2998 | dw_mci_set_ios(slot->mmc, &slot->mmc->ios); |
| 2999 | dw_mci_setup_bus(slot, true); |
| 3000 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 3001 | } |
Doug Anderson | fa0c328 | 2015-02-25 10:11:51 -0800 | [diff] [blame] | 3002 | |
| 3003 | /* Now that slots are all setup, we can enable card detect */ |
| 3004 | dw_mci_enable_cd(host); |
| 3005 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 3006 | return 0; |
| 3007 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 3008 | EXPORT_SYMBOL(dw_mci_resume); |
Jaehoon Chung | 6fe8890 | 2011-12-08 19:23:03 +0900 | [diff] [blame] | 3009 | #endif /* CONFIG_PM_SLEEP */ |
| 3010 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 3011 | static int __init dw_mci_init(void) |
| 3012 | { |
Sachin Kamat | 8e1c4e4 | 2013-04-04 11:25:11 +0530 | [diff] [blame] | 3013 | pr_info("Synopsys Designware Multimedia Card Interface Driver\n"); |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 3014 | return 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | static void __exit dw_mci_exit(void) |
| 3018 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | module_init(dw_mci_init); |
| 3022 | module_exit(dw_mci_exit); |
| 3023 | |
| 3024 | MODULE_DESCRIPTION("DW Multimedia Card Interface driver"); |
| 3025 | MODULE_AUTHOR("NXP Semiconductor VietNam"); |
| 3026 | MODULE_AUTHOR("Imagination Technologies Ltd"); |
| 3027 | MODULE_LICENSE("GPL v2"); |