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> |
| 30 | #include <linux/mmc/host.h> |
| 31 | #include <linux/mmc/mmc.h> |
| 32 | #include <linux/mmc/dw_mmc.h> |
| 33 | #include <linux/bitops.h> |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 34 | #include <linux/regulator/consumer.h> |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 36 | |
| 37 | #include "dw_mmc.h" |
| 38 | |
| 39 | /* Common flag combinations */ |
| 40 | #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DTO | SDMMC_INT_DCRC | \ |
| 41 | SDMMC_INT_HTO | SDMMC_INT_SBE | \ |
| 42 | SDMMC_INT_EBE) |
| 43 | #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \ |
| 44 | SDMMC_INT_RESP_ERR) |
| 45 | #define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \ |
| 46 | DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE) |
| 47 | #define DW_MCI_SEND_STATUS 1 |
| 48 | #define DW_MCI_RECV_STATUS 2 |
| 49 | #define DW_MCI_DMA_THRESHOLD 16 |
| 50 | |
| 51 | #ifdef CONFIG_MMC_DW_IDMAC |
| 52 | struct idmac_desc { |
| 53 | u32 des0; /* Control Descriptor */ |
| 54 | #define IDMAC_DES0_DIC BIT(1) |
| 55 | #define IDMAC_DES0_LD BIT(2) |
| 56 | #define IDMAC_DES0_FD BIT(3) |
| 57 | #define IDMAC_DES0_CH BIT(4) |
| 58 | #define IDMAC_DES0_ER BIT(5) |
| 59 | #define IDMAC_DES0_CES BIT(30) |
| 60 | #define IDMAC_DES0_OWN BIT(31) |
| 61 | |
| 62 | u32 des1; /* Buffer sizes */ |
| 63 | #define IDMAC_SET_BUFFER1_SIZE(d, s) \ |
Shashidhar Hiremath | 9b7bbe1 | 2011-07-29 08:49:50 -0400 | [diff] [blame] | 64 | ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 65 | |
| 66 | u32 des2; /* buffer 1 physical address */ |
| 67 | |
| 68 | u32 des3; /* buffer 2 physical address */ |
| 69 | }; |
| 70 | #endif /* CONFIG_MMC_DW_IDMAC */ |
| 71 | |
| 72 | /** |
| 73 | * struct dw_mci_slot - MMC slot state |
| 74 | * @mmc: The mmc_host representing this slot. |
| 75 | * @host: The MMC controller this slot is using. |
| 76 | * @ctype: Card type for this slot. |
| 77 | * @mrq: mmc_request currently being processed or waiting to be |
| 78 | * processed, or NULL when the slot is idle. |
| 79 | * @queue_node: List node for placing this node in the @queue list of |
| 80 | * &struct dw_mci. |
| 81 | * @clock: Clock rate configured by set_ios(). Protected by host->lock. |
| 82 | * @flags: Random state bits associated with the slot. |
| 83 | * @id: Number of this slot. |
| 84 | * @last_detect_state: Most recently observed card detect state. |
| 85 | */ |
| 86 | struct dw_mci_slot { |
| 87 | struct mmc_host *mmc; |
| 88 | struct dw_mci *host; |
| 89 | |
| 90 | u32 ctype; |
| 91 | |
| 92 | struct mmc_request *mrq; |
| 93 | struct list_head queue_node; |
| 94 | |
| 95 | unsigned int clock; |
| 96 | unsigned long flags; |
| 97 | #define DW_MMC_CARD_PRESENT 0 |
| 98 | #define DW_MMC_CARD_NEED_INIT 1 |
| 99 | int id; |
| 100 | int last_detect_state; |
| 101 | }; |
| 102 | |
| 103 | #if defined(CONFIG_DEBUG_FS) |
| 104 | static int dw_mci_req_show(struct seq_file *s, void *v) |
| 105 | { |
| 106 | struct dw_mci_slot *slot = s->private; |
| 107 | struct mmc_request *mrq; |
| 108 | struct mmc_command *cmd; |
| 109 | struct mmc_command *stop; |
| 110 | struct mmc_data *data; |
| 111 | |
| 112 | /* Make sure we get a consistent snapshot */ |
| 113 | spin_lock_bh(&slot->host->lock); |
| 114 | mrq = slot->mrq; |
| 115 | |
| 116 | if (mrq) { |
| 117 | cmd = mrq->cmd; |
| 118 | data = mrq->data; |
| 119 | stop = mrq->stop; |
| 120 | |
| 121 | if (cmd) |
| 122 | seq_printf(s, |
| 123 | "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n", |
| 124 | cmd->opcode, cmd->arg, cmd->flags, |
| 125 | cmd->resp[0], cmd->resp[1], cmd->resp[2], |
| 126 | cmd->resp[2], cmd->error); |
| 127 | if (data) |
| 128 | seq_printf(s, "DATA %u / %u * %u flg %x err %d\n", |
| 129 | data->bytes_xfered, data->blocks, |
| 130 | data->blksz, data->flags, data->error); |
| 131 | if (stop) |
| 132 | seq_printf(s, |
| 133 | "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n", |
| 134 | stop->opcode, stop->arg, stop->flags, |
| 135 | stop->resp[0], stop->resp[1], stop->resp[2], |
| 136 | stop->resp[2], stop->error); |
| 137 | } |
| 138 | |
| 139 | spin_unlock_bh(&slot->host->lock); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static int dw_mci_req_open(struct inode *inode, struct file *file) |
| 145 | { |
| 146 | return single_open(file, dw_mci_req_show, inode->i_private); |
| 147 | } |
| 148 | |
| 149 | static const struct file_operations dw_mci_req_fops = { |
| 150 | .owner = THIS_MODULE, |
| 151 | .open = dw_mci_req_open, |
| 152 | .read = seq_read, |
| 153 | .llseek = seq_lseek, |
| 154 | .release = single_release, |
| 155 | }; |
| 156 | |
| 157 | static int dw_mci_regs_show(struct seq_file *s, void *v) |
| 158 | { |
| 159 | seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS); |
| 160 | seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS); |
| 161 | seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD); |
| 162 | seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL); |
| 163 | seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK); |
| 164 | seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int dw_mci_regs_open(struct inode *inode, struct file *file) |
| 170 | { |
| 171 | return single_open(file, dw_mci_regs_show, inode->i_private); |
| 172 | } |
| 173 | |
| 174 | static const struct file_operations dw_mci_regs_fops = { |
| 175 | .owner = THIS_MODULE, |
| 176 | .open = dw_mci_regs_open, |
| 177 | .read = seq_read, |
| 178 | .llseek = seq_lseek, |
| 179 | .release = single_release, |
| 180 | }; |
| 181 | |
| 182 | static void dw_mci_init_debugfs(struct dw_mci_slot *slot) |
| 183 | { |
| 184 | struct mmc_host *mmc = slot->mmc; |
| 185 | struct dw_mci *host = slot->host; |
| 186 | struct dentry *root; |
| 187 | struct dentry *node; |
| 188 | |
| 189 | root = mmc->debugfs_root; |
| 190 | if (!root) |
| 191 | return; |
| 192 | |
| 193 | node = debugfs_create_file("regs", S_IRUSR, root, host, |
| 194 | &dw_mci_regs_fops); |
| 195 | if (!node) |
| 196 | goto err; |
| 197 | |
| 198 | node = debugfs_create_file("req", S_IRUSR, root, slot, |
| 199 | &dw_mci_req_fops); |
| 200 | if (!node) |
| 201 | goto err; |
| 202 | |
| 203 | node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state); |
| 204 | if (!node) |
| 205 | goto err; |
| 206 | |
| 207 | node = debugfs_create_x32("pending_events", S_IRUSR, root, |
| 208 | (u32 *)&host->pending_events); |
| 209 | if (!node) |
| 210 | goto err; |
| 211 | |
| 212 | node = debugfs_create_x32("completed_events", S_IRUSR, root, |
| 213 | (u32 *)&host->completed_events); |
| 214 | if (!node) |
| 215 | goto err; |
| 216 | |
| 217 | return; |
| 218 | |
| 219 | err: |
| 220 | dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n"); |
| 221 | } |
| 222 | #endif /* defined(CONFIG_DEBUG_FS) */ |
| 223 | |
| 224 | static void dw_mci_set_timeout(struct dw_mci *host) |
| 225 | { |
| 226 | /* timeout (maximum) */ |
| 227 | mci_writel(host, TMOUT, 0xffffffff); |
| 228 | } |
| 229 | |
| 230 | static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) |
| 231 | { |
| 232 | struct mmc_data *data; |
| 233 | u32 cmdr; |
| 234 | cmd->error = -EINPROGRESS; |
| 235 | |
| 236 | cmdr = cmd->opcode; |
| 237 | |
| 238 | if (cmdr == MMC_STOP_TRANSMISSION) |
| 239 | cmdr |= SDMMC_CMD_STOP; |
| 240 | else |
| 241 | cmdr |= SDMMC_CMD_PRV_DAT_WAIT; |
| 242 | |
| 243 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 244 | /* We expect a response, so set this bit */ |
| 245 | cmdr |= SDMMC_CMD_RESP_EXP; |
| 246 | if (cmd->flags & MMC_RSP_136) |
| 247 | cmdr |= SDMMC_CMD_RESP_LONG; |
| 248 | } |
| 249 | |
| 250 | if (cmd->flags & MMC_RSP_CRC) |
| 251 | cmdr |= SDMMC_CMD_RESP_CRC; |
| 252 | |
| 253 | data = cmd->data; |
| 254 | if (data) { |
| 255 | cmdr |= SDMMC_CMD_DAT_EXP; |
| 256 | if (data->flags & MMC_DATA_STREAM) |
| 257 | cmdr |= SDMMC_CMD_STRM_MODE; |
| 258 | if (data->flags & MMC_DATA_WRITE) |
| 259 | cmdr |= SDMMC_CMD_DAT_WR; |
| 260 | } |
| 261 | |
| 262 | return cmdr; |
| 263 | } |
| 264 | |
| 265 | static void dw_mci_start_command(struct dw_mci *host, |
| 266 | struct mmc_command *cmd, u32 cmd_flags) |
| 267 | { |
| 268 | host->cmd = cmd; |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 269 | dev_vdbg(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 270 | "start command: ARGR=0x%08x CMDR=0x%08x\n", |
| 271 | cmd->arg, cmd_flags); |
| 272 | |
| 273 | mci_writel(host, CMDARG, cmd->arg); |
| 274 | wmb(); |
| 275 | |
| 276 | mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START); |
| 277 | } |
| 278 | |
| 279 | static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data) |
| 280 | { |
| 281 | dw_mci_start_command(host, data->stop, host->stop_cmdr); |
| 282 | } |
| 283 | |
| 284 | /* DMA interface functions */ |
| 285 | static void dw_mci_stop_dma(struct dw_mci *host) |
| 286 | { |
James Hogan | 03e8cb53 | 2011-06-29 09:28:43 +0100 | [diff] [blame] | 287 | if (host->using_dma) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 288 | host->dma_ops->stop(host); |
| 289 | host->dma_ops->cleanup(host); |
| 290 | } else { |
| 291 | /* Data transfer was stopped by the interrupt handler */ |
| 292 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 293 | } |
| 294 | } |
| 295 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 296 | static int dw_mci_get_dma_dir(struct mmc_data *data) |
| 297 | { |
| 298 | if (data->flags & MMC_DATA_WRITE) |
| 299 | return DMA_TO_DEVICE; |
| 300 | else |
| 301 | return DMA_FROM_DEVICE; |
| 302 | } |
| 303 | |
Jaehoon Chung | 9beee91 | 2012-02-16 11:19:38 +0900 | [diff] [blame] | 304 | #ifdef CONFIG_MMC_DW_IDMAC |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 305 | static void dw_mci_dma_cleanup(struct dw_mci *host) |
| 306 | { |
| 307 | struct mmc_data *data = host->data; |
| 308 | |
| 309 | if (data) |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 310 | if (!data->host_cookie) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 311 | dma_unmap_sg(host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 312 | data->sg, |
| 313 | data->sg_len, |
| 314 | dw_mci_get_dma_dir(data)); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static void dw_mci_idmac_stop_dma(struct dw_mci *host) |
| 318 | { |
| 319 | u32 temp; |
| 320 | |
| 321 | /* Disable and reset the IDMAC interface */ |
| 322 | temp = mci_readl(host, CTRL); |
| 323 | temp &= ~SDMMC_CTRL_USE_IDMAC; |
| 324 | temp |= SDMMC_CTRL_DMA_RESET; |
| 325 | mci_writel(host, CTRL, temp); |
| 326 | |
| 327 | /* Stop the IDMAC running */ |
| 328 | temp = mci_readl(host, BMOD); |
Jaehoon Chung | a5289a4 | 2011-02-25 11:08:13 +0900 | [diff] [blame] | 329 | temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 330 | mci_writel(host, BMOD, temp); |
| 331 | } |
| 332 | |
| 333 | static void dw_mci_idmac_complete_dma(struct dw_mci *host) |
| 334 | { |
| 335 | struct mmc_data *data = host->data; |
| 336 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 337 | dev_vdbg(host->dev, "DMA complete\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 338 | |
| 339 | host->dma_ops->cleanup(host); |
| 340 | |
| 341 | /* |
| 342 | * If the card was removed, data will be NULL. No point in trying to |
| 343 | * send the stop command or waiting for NBUSY in this case. |
| 344 | */ |
| 345 | if (data) { |
| 346 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 347 | tasklet_schedule(&host->tasklet); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data, |
| 352 | unsigned int sg_len) |
| 353 | { |
| 354 | int i; |
| 355 | struct idmac_desc *desc = host->sg_cpu; |
| 356 | |
| 357 | for (i = 0; i < sg_len; i++, desc++) { |
| 358 | unsigned int length = sg_dma_len(&data->sg[i]); |
| 359 | u32 mem_addr = sg_dma_address(&data->sg[i]); |
| 360 | |
| 361 | /* Set the OWN bit and disable interrupts for this descriptor */ |
| 362 | desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH; |
| 363 | |
| 364 | /* Buffer length */ |
| 365 | IDMAC_SET_BUFFER1_SIZE(desc, length); |
| 366 | |
| 367 | /* Physical address to DMA to/from */ |
| 368 | desc->des2 = mem_addr; |
| 369 | } |
| 370 | |
| 371 | /* Set first descriptor */ |
| 372 | desc = host->sg_cpu; |
| 373 | desc->des0 |= IDMAC_DES0_FD; |
| 374 | |
| 375 | /* Set last descriptor */ |
| 376 | desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc); |
| 377 | desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC); |
| 378 | desc->des0 |= IDMAC_DES0_LD; |
| 379 | |
| 380 | wmb(); |
| 381 | } |
| 382 | |
| 383 | static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len) |
| 384 | { |
| 385 | u32 temp; |
| 386 | |
| 387 | dw_mci_translate_sglist(host, host->data, sg_len); |
| 388 | |
| 389 | /* Select IDMAC interface */ |
| 390 | temp = mci_readl(host, CTRL); |
| 391 | temp |= SDMMC_CTRL_USE_IDMAC; |
| 392 | mci_writel(host, CTRL, temp); |
| 393 | |
| 394 | wmb(); |
| 395 | |
| 396 | /* Enable the IDMAC */ |
| 397 | temp = mci_readl(host, BMOD); |
Jaehoon Chung | a5289a4 | 2011-02-25 11:08:13 +0900 | [diff] [blame] | 398 | temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 399 | mci_writel(host, BMOD, temp); |
| 400 | |
| 401 | /* Start it running */ |
| 402 | mci_writel(host, PLDMND, 1); |
| 403 | } |
| 404 | |
| 405 | static int dw_mci_idmac_init(struct dw_mci *host) |
| 406 | { |
| 407 | struct idmac_desc *p; |
Girish K S | 94c6cee | 2012-06-12 15:28:22 +0530 | [diff] [blame] | 408 | int i, dma_support; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 409 | |
| 410 | /* Number of descriptors in the ring buffer */ |
| 411 | host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); |
| 412 | |
Girish K S | 94c6cee | 2012-06-12 15:28:22 +0530 | [diff] [blame] | 413 | /* Check if Hardware Configuration Register has support for DMA */ |
| 414 | dma_support = (mci_readl(host, HCON) >> 16) & 0x3; |
| 415 | |
| 416 | if (!dma_support || dma_support > 2) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 417 | dev_err(host->dev, |
Girish K S | 94c6cee | 2012-06-12 15:28:22 +0530 | [diff] [blame] | 418 | "Host Controller does not support IDMA Tx.\n"); |
| 419 | host->dma_ops = NULL; |
| 420 | return -ENODEV; |
| 421 | } |
| 422 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 423 | dev_info(host->dev, "Using internal DMA controller.\n"); |
Girish K S | 94c6cee | 2012-06-12 15:28:22 +0530 | [diff] [blame] | 424 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 425 | /* Forward link the descriptor list */ |
| 426 | for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) |
| 427 | p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); |
| 428 | |
| 429 | /* Set the last descriptor as the end-of-ring descriptor */ |
| 430 | p->des3 = host->sg_dma; |
| 431 | p->des0 = IDMAC_DES0_ER; |
| 432 | |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 433 | mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET); |
| 434 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 435 | /* Mask out interrupts - get Tx & Rx complete only */ |
| 436 | mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | |
| 437 | SDMMC_IDMAC_INT_TI); |
| 438 | |
| 439 | /* Set the descriptor base address */ |
| 440 | mci_writel(host, DBADDR, host->sg_dma); |
| 441 | return 0; |
| 442 | } |
| 443 | |
Seungwon Jeon | 885c3e8 | 2012-02-20 11:01:43 +0900 | [diff] [blame] | 444 | static struct dw_mci_dma_ops dw_mci_idmac_ops = { |
| 445 | .init = dw_mci_idmac_init, |
| 446 | .start = dw_mci_idmac_start_dma, |
| 447 | .stop = dw_mci_idmac_stop_dma, |
| 448 | .complete = dw_mci_idmac_complete_dma, |
| 449 | .cleanup = dw_mci_dma_cleanup, |
| 450 | }; |
| 451 | #endif /* CONFIG_MMC_DW_IDMAC */ |
| 452 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 453 | static int dw_mci_pre_dma_transfer(struct dw_mci *host, |
| 454 | struct mmc_data *data, |
| 455 | bool next) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 456 | { |
| 457 | struct scatterlist *sg; |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 458 | unsigned int i, sg_len; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 459 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 460 | if (!next && data->host_cookie) |
| 461 | return data->host_cookie; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * We don't do DMA on "complex" transfers, i.e. with |
| 465 | * non-word-aligned buffers or lengths. Also, we don't bother |
| 466 | * with all the DMA setup overhead for short transfers. |
| 467 | */ |
| 468 | if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD) |
| 469 | return -EINVAL; |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 470 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 471 | if (data->blksz & 3) |
| 472 | return -EINVAL; |
| 473 | |
| 474 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 475 | if (sg->offset & 3 || sg->length & 3) |
| 476 | return -EINVAL; |
| 477 | } |
| 478 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 479 | sg_len = dma_map_sg(host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 480 | data->sg, |
| 481 | data->sg_len, |
| 482 | dw_mci_get_dma_dir(data)); |
| 483 | if (sg_len == 0) |
| 484 | return -EINVAL; |
| 485 | |
| 486 | if (next) |
| 487 | data->host_cookie = sg_len; |
| 488 | |
| 489 | return sg_len; |
| 490 | } |
| 491 | |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 492 | static void dw_mci_pre_req(struct mmc_host *mmc, |
| 493 | struct mmc_request *mrq, |
| 494 | bool is_first_req) |
| 495 | { |
| 496 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 497 | struct mmc_data *data = mrq->data; |
| 498 | |
| 499 | if (!slot->host->use_dma || !data) |
| 500 | return; |
| 501 | |
| 502 | if (data->host_cookie) { |
| 503 | data->host_cookie = 0; |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0) |
| 508 | data->host_cookie = 0; |
| 509 | } |
| 510 | |
| 511 | static void dw_mci_post_req(struct mmc_host *mmc, |
| 512 | struct mmc_request *mrq, |
| 513 | int err) |
| 514 | { |
| 515 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 516 | struct mmc_data *data = mrq->data; |
| 517 | |
| 518 | if (!slot->host->use_dma || !data) |
| 519 | return; |
| 520 | |
| 521 | if (data->host_cookie) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 522 | dma_unmap_sg(slot->host->dev, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 523 | data->sg, |
| 524 | data->sg_len, |
| 525 | dw_mci_get_dma_dir(data)); |
| 526 | data->host_cookie = 0; |
| 527 | } |
| 528 | |
| 529 | static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data) |
| 530 | { |
| 531 | int sg_len; |
| 532 | u32 temp; |
| 533 | |
| 534 | host->using_dma = 0; |
| 535 | |
| 536 | /* If we don't have a channel, we can't do DMA */ |
| 537 | if (!host->use_dma) |
| 538 | return -ENODEV; |
| 539 | |
| 540 | sg_len = dw_mci_pre_dma_transfer(host, data, 0); |
Seungwon Jeon | a99aa9b | 2012-04-10 09:53:32 +0900 | [diff] [blame] | 541 | if (sg_len < 0) { |
| 542 | host->dma_ops->stop(host); |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 543 | return sg_len; |
Seungwon Jeon | a99aa9b | 2012-04-10 09:53:32 +0900 | [diff] [blame] | 544 | } |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 545 | |
James Hogan | 03e8cb53 | 2011-06-29 09:28:43 +0100 | [diff] [blame] | 546 | host->using_dma = 1; |
| 547 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 548 | dev_vdbg(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 549 | "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n", |
| 550 | (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma, |
| 551 | sg_len); |
| 552 | |
| 553 | /* Enable the DMA interface */ |
| 554 | temp = mci_readl(host, CTRL); |
| 555 | temp |= SDMMC_CTRL_DMA_ENABLE; |
| 556 | mci_writel(host, CTRL, temp); |
| 557 | |
| 558 | /* Disable RX/TX IRQs, let DMA handle it */ |
| 559 | temp = mci_readl(host, INTMASK); |
| 560 | temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR); |
| 561 | mci_writel(host, INTMASK, temp); |
| 562 | |
| 563 | host->dma_ops->start(host, sg_len); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data) |
| 569 | { |
| 570 | u32 temp; |
| 571 | |
| 572 | data->error = -EINPROGRESS; |
| 573 | |
| 574 | WARN_ON(host->data); |
| 575 | host->sg = NULL; |
| 576 | host->data = data; |
| 577 | |
James Hogan | 55c5efbc | 2011-06-29 09:29:58 +0100 | [diff] [blame] | 578 | if (data->flags & MMC_DATA_READ) |
| 579 | host->dir_status = DW_MCI_RECV_STATUS; |
| 580 | else |
| 581 | host->dir_status = DW_MCI_SEND_STATUS; |
| 582 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 583 | if (dw_mci_submit_data_dma(host, data)) { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 584 | int flags = SG_MITER_ATOMIC; |
| 585 | if (host->data->flags & MMC_DATA_READ) |
| 586 | flags |= SG_MITER_TO_SG; |
| 587 | else |
| 588 | flags |= SG_MITER_FROM_SG; |
| 589 | |
| 590 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 591 | host->sg = data->sg; |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 592 | host->part_buf_start = 0; |
| 593 | host->part_buf_count = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 594 | |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 595 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 596 | temp = mci_readl(host, INTMASK); |
| 597 | temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR; |
| 598 | mci_writel(host, INTMASK, temp); |
| 599 | |
| 600 | temp = mci_readl(host, CTRL); |
| 601 | temp &= ~SDMMC_CTRL_DMA_ENABLE; |
| 602 | mci_writel(host, CTRL, temp); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg) |
| 607 | { |
| 608 | struct dw_mci *host = slot->host; |
| 609 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
| 610 | unsigned int cmd_status = 0; |
| 611 | |
| 612 | mci_writel(host, CMDARG, arg); |
| 613 | wmb(); |
| 614 | mci_writel(host, CMD, SDMMC_CMD_START | cmd); |
| 615 | |
| 616 | while (time_before(jiffies, timeout)) { |
| 617 | cmd_status = mci_readl(host, CMD); |
| 618 | if (!(cmd_status & SDMMC_CMD_START)) |
| 619 | return; |
| 620 | } |
| 621 | dev_err(&slot->mmc->class_dev, |
| 622 | "Timeout sending command (cmd %#x arg %#x status %#x)\n", |
| 623 | cmd, arg, cmd_status); |
| 624 | } |
| 625 | |
| 626 | static void dw_mci_setup_bus(struct dw_mci_slot *slot) |
| 627 | { |
| 628 | struct dw_mci *host = slot->host; |
| 629 | u32 div; |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 630 | u32 clk_en_a; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 631 | |
| 632 | if (slot->clock != host->current_speed) { |
Seungwon Jeon | e419990 | 2012-05-22 13:01:21 +0900 | [diff] [blame] | 633 | div = host->bus_hz / slot->clock; |
| 634 | if (host->bus_hz % slot->clock && host->bus_hz > slot->clock) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 635 | /* |
| 636 | * move the + 1 after the divide to prevent |
| 637 | * over-clocking the card. |
| 638 | */ |
Seungwon Jeon | e419990 | 2012-05-22 13:01:21 +0900 | [diff] [blame] | 639 | div += 1; |
| 640 | |
| 641 | div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 642 | |
| 643 | dev_info(&slot->mmc->class_dev, |
| 644 | "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" |
| 645 | " div = %d)\n", slot->id, host->bus_hz, slot->clock, |
| 646 | div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div); |
| 647 | |
| 648 | /* disable clock */ |
| 649 | mci_writel(host, CLKENA, 0); |
| 650 | mci_writel(host, CLKSRC, 0); |
| 651 | |
| 652 | /* inform CIU */ |
| 653 | mci_send_cmd(slot, |
| 654 | SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 655 | |
| 656 | /* set clock to desired speed */ |
| 657 | mci_writel(host, CLKDIV, div); |
| 658 | |
| 659 | /* inform CIU */ |
| 660 | mci_send_cmd(slot, |
| 661 | SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 662 | |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 663 | /* enable clock; only low power if no SDIO */ |
| 664 | clk_en_a = SDMMC_CLKEN_ENABLE << slot->id; |
| 665 | if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->id))) |
| 666 | clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id; |
| 667 | mci_writel(host, CLKENA, clk_en_a); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 668 | |
| 669 | /* inform CIU */ |
| 670 | mci_send_cmd(slot, |
| 671 | SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 672 | |
| 673 | host->current_speed = slot->clock; |
| 674 | } |
| 675 | |
| 676 | /* Set the current slot bus width */ |
Seungwon Jeon | 1d56c45 | 2011-06-20 17:23:53 +0900 | [diff] [blame] | 677 | mci_writel(host, CTYPE, (slot->ctype << slot->id)); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 678 | } |
| 679 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 680 | static void __dw_mci_start_request(struct dw_mci *host, |
| 681 | struct dw_mci_slot *slot, |
| 682 | struct mmc_command *cmd) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 683 | { |
| 684 | struct mmc_request *mrq; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 685 | struct mmc_data *data; |
| 686 | u32 cmdflags; |
| 687 | |
| 688 | mrq = slot->mrq; |
| 689 | if (host->pdata->select_slot) |
| 690 | host->pdata->select_slot(slot->id); |
| 691 | |
| 692 | /* Slot specific timing and width adjustment */ |
| 693 | dw_mci_setup_bus(slot); |
| 694 | |
| 695 | host->cur_slot = slot; |
| 696 | host->mrq = mrq; |
| 697 | |
| 698 | host->pending_events = 0; |
| 699 | host->completed_events = 0; |
| 700 | host->data_status = 0; |
| 701 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 702 | data = cmd->data; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 703 | if (data) { |
| 704 | dw_mci_set_timeout(host); |
| 705 | mci_writel(host, BYTCNT, data->blksz*data->blocks); |
| 706 | mci_writel(host, BLKSIZ, data->blksz); |
| 707 | } |
| 708 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 709 | cmdflags = dw_mci_prepare_command(slot->mmc, cmd); |
| 710 | |
| 711 | /* this is the first command, send the initialization clock */ |
| 712 | if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags)) |
| 713 | cmdflags |= SDMMC_CMD_INIT; |
| 714 | |
| 715 | if (data) { |
| 716 | dw_mci_submit_data(host, data); |
| 717 | wmb(); |
| 718 | } |
| 719 | |
| 720 | dw_mci_start_command(host, cmd, cmdflags); |
| 721 | |
| 722 | if (mrq->stop) |
| 723 | host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop); |
| 724 | } |
| 725 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 726 | static void dw_mci_start_request(struct dw_mci *host, |
| 727 | struct dw_mci_slot *slot) |
| 728 | { |
| 729 | struct mmc_request *mrq = slot->mrq; |
| 730 | struct mmc_command *cmd; |
| 731 | |
| 732 | cmd = mrq->sbc ? mrq->sbc : mrq->cmd; |
| 733 | __dw_mci_start_request(host, slot, cmd); |
| 734 | } |
| 735 | |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 736 | /* must be called with host->lock held */ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 737 | static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot, |
| 738 | struct mmc_request *mrq) |
| 739 | { |
| 740 | dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n", |
| 741 | host->state); |
| 742 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 743 | slot->mrq = mrq; |
| 744 | |
| 745 | if (host->state == STATE_IDLE) { |
| 746 | host->state = STATE_SENDING_CMD; |
| 747 | dw_mci_start_request(host, slot); |
| 748 | } else { |
| 749 | list_add_tail(&slot->queue_node, &host->queue); |
| 750 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 754 | { |
| 755 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 756 | struct dw_mci *host = slot->host; |
| 757 | |
| 758 | WARN_ON(slot->mrq); |
| 759 | |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 760 | /* |
| 761 | * The check for card presence and queueing of the request must be |
| 762 | * atomic, otherwise the card could be removed in between and the |
| 763 | * request wouldn't fail until another card was inserted. |
| 764 | */ |
| 765 | spin_lock_bh(&host->lock); |
| 766 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 767 | if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) { |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 768 | spin_unlock_bh(&host->lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 769 | mrq->cmd->error = -ENOMEDIUM; |
| 770 | mmc_request_done(mmc, mrq); |
| 771 | return; |
| 772 | } |
| 773 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 774 | dw_mci_queue_request(host, slot, mrq); |
James Hogan | 7456caa | 2011-06-24 13:55:10 +0100 | [diff] [blame] | 775 | |
| 776 | spin_unlock_bh(&host->lock); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 780 | { |
| 781 | struct dw_mci_slot *slot = mmc_priv(mmc); |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 782 | u32 regs; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 783 | |
| 784 | /* set default 1 bit mode */ |
| 785 | slot->ctype = SDMMC_CTYPE_1BIT; |
| 786 | |
| 787 | switch (ios->bus_width) { |
| 788 | case MMC_BUS_WIDTH_1: |
| 789 | slot->ctype = SDMMC_CTYPE_1BIT; |
| 790 | break; |
| 791 | case MMC_BUS_WIDTH_4: |
| 792 | slot->ctype = SDMMC_CTYPE_4BIT; |
| 793 | break; |
Jaehoon Chung | c9b2a06 | 2011-02-17 16:12:38 +0900 | [diff] [blame] | 794 | case MMC_BUS_WIDTH_8: |
| 795 | slot->ctype = SDMMC_CTYPE_8BIT; |
| 796 | break; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 797 | } |
| 798 | |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 799 | regs = mci_readl(slot->host, UHS_REG); |
| 800 | |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 801 | /* DDR mode set */ |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 802 | if (ios->timing == MMC_TIMING_UHS_DDR50) |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 803 | regs |= (0x1 << slot->id) << 16; |
Seungwon Jeon | 3f51429 | 2012-01-02 16:00:02 +0900 | [diff] [blame] | 804 | else |
| 805 | regs &= ~(0x1 << slot->id) << 16; |
| 806 | |
| 807 | mci_writel(slot->host, UHS_REG, regs); |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 808 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 809 | if (ios->clock) { |
| 810 | /* |
| 811 | * Use mirror of ios->clock to prevent race with mmc |
| 812 | * core ios update when finding the minimum. |
| 813 | */ |
| 814 | slot->clock = ios->clock; |
| 815 | } |
| 816 | |
| 817 | switch (ios->power_mode) { |
| 818 | case MMC_POWER_UP: |
| 819 | set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags); |
| 820 | break; |
| 821 | default: |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | static int dw_mci_get_ro(struct mmc_host *mmc) |
| 827 | { |
| 828 | int read_only; |
| 829 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 830 | struct dw_mci_board *brd = slot->host->pdata; |
| 831 | |
| 832 | /* Use platform get_ro function, else try on board write protect */ |
Thomas Abraham | b4967aa | 2012-09-17 18:16:39 +0000 | [diff] [blame^] | 833 | if (brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) |
| 834 | read_only = 0; |
| 835 | else if (brd->get_ro) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 836 | read_only = brd->get_ro(slot->id); |
| 837 | else |
| 838 | read_only = |
| 839 | mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0; |
| 840 | |
| 841 | dev_dbg(&mmc->class_dev, "card is %s\n", |
| 842 | read_only ? "read-only" : "read-write"); |
| 843 | |
| 844 | return read_only; |
| 845 | } |
| 846 | |
| 847 | static int dw_mci_get_cd(struct mmc_host *mmc) |
| 848 | { |
| 849 | int present; |
| 850 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 851 | struct dw_mci_board *brd = slot->host->pdata; |
| 852 | |
| 853 | /* Use platform get_cd function, else try onboard card detect */ |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 854 | if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) |
| 855 | present = 1; |
| 856 | else if (brd->get_cd) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 857 | present = !brd->get_cd(slot->id); |
| 858 | else |
| 859 | present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) |
| 860 | == 0 ? 1 : 0; |
| 861 | |
| 862 | if (present) |
| 863 | dev_dbg(&mmc->class_dev, "card is present\n"); |
| 864 | else |
| 865 | dev_dbg(&mmc->class_dev, "card is not present\n"); |
| 866 | |
| 867 | return present; |
| 868 | } |
| 869 | |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 870 | /* |
| 871 | * Disable lower power mode. |
| 872 | * |
| 873 | * Low power mode will stop the card clock when idle. According to the |
| 874 | * description of the CLKENA register we should disable low power mode |
| 875 | * for SDIO cards if we need SDIO interrupts to work. |
| 876 | * |
| 877 | * This function is fast if low power mode is already disabled. |
| 878 | */ |
| 879 | static void dw_mci_disable_low_power(struct dw_mci_slot *slot) |
| 880 | { |
| 881 | struct dw_mci *host = slot->host; |
| 882 | u32 clk_en_a; |
| 883 | const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id; |
| 884 | |
| 885 | clk_en_a = mci_readl(host, CLKENA); |
| 886 | |
| 887 | if (clk_en_a & clken_low_pwr) { |
| 888 | mci_writel(host, CLKENA, clk_en_a & ~clken_low_pwr); |
| 889 | mci_send_cmd(slot, SDMMC_CMD_UPD_CLK | |
| 890 | SDMMC_CMD_PRV_DAT_WAIT, 0); |
| 891 | } |
| 892 | } |
| 893 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 894 | static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb) |
| 895 | { |
| 896 | struct dw_mci_slot *slot = mmc_priv(mmc); |
| 897 | struct dw_mci *host = slot->host; |
| 898 | u32 int_mask; |
| 899 | |
| 900 | /* Enable/disable Slot Specific SDIO interrupt */ |
| 901 | int_mask = mci_readl(host, INTMASK); |
| 902 | if (enb) { |
Doug Anderson | 9623b5b | 2012-07-25 08:33:17 -0700 | [diff] [blame] | 903 | /* |
| 904 | * Turn off low power mode if it was enabled. This is a bit of |
| 905 | * a heavy operation and we disable / enable IRQs a lot, so |
| 906 | * we'll leave low power mode disabled and it will get |
| 907 | * re-enabled again in dw_mci_setup_bus(). |
| 908 | */ |
| 909 | dw_mci_disable_low_power(slot); |
| 910 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 911 | mci_writel(host, INTMASK, |
Kyoungil Kim | 705ad04 | 2012-05-14 17:38:48 +0900 | [diff] [blame] | 912 | (int_mask | SDMMC_INT_SDIO(slot->id))); |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 913 | } else { |
| 914 | mci_writel(host, INTMASK, |
Kyoungil Kim | 705ad04 | 2012-05-14 17:38:48 +0900 | [diff] [blame] | 915 | (int_mask & ~SDMMC_INT_SDIO(slot->id))); |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 919 | static const struct mmc_host_ops dw_mci_ops = { |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 920 | .request = dw_mci_request, |
Seungwon Jeon | 9aa5140 | 2012-02-06 16:55:07 +0900 | [diff] [blame] | 921 | .pre_req = dw_mci_pre_req, |
| 922 | .post_req = dw_mci_post_req, |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 923 | .set_ios = dw_mci_set_ios, |
| 924 | .get_ro = dw_mci_get_ro, |
| 925 | .get_cd = dw_mci_get_cd, |
| 926 | .enable_sdio_irq = dw_mci_enable_sdio_irq, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 927 | }; |
| 928 | |
| 929 | static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) |
| 930 | __releases(&host->lock) |
| 931 | __acquires(&host->lock) |
| 932 | { |
| 933 | struct dw_mci_slot *slot; |
| 934 | struct mmc_host *prev_mmc = host->cur_slot->mmc; |
| 935 | |
| 936 | WARN_ON(host->cmd || host->data); |
| 937 | |
| 938 | host->cur_slot->mrq = NULL; |
| 939 | host->mrq = NULL; |
| 940 | if (!list_empty(&host->queue)) { |
| 941 | slot = list_entry(host->queue.next, |
| 942 | struct dw_mci_slot, queue_node); |
| 943 | list_del(&slot->queue_node); |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 944 | dev_vdbg(host->dev, "list not empty: %s is next\n", |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 945 | mmc_hostname(slot->mmc)); |
| 946 | host->state = STATE_SENDING_CMD; |
| 947 | dw_mci_start_request(host, slot); |
| 948 | } else { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 949 | dev_vdbg(host->dev, "list empty\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 950 | host->state = STATE_IDLE; |
| 951 | } |
| 952 | |
| 953 | spin_unlock(&host->lock); |
| 954 | mmc_request_done(prev_mmc, mrq); |
| 955 | spin_lock(&host->lock); |
| 956 | } |
| 957 | |
| 958 | static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd) |
| 959 | { |
| 960 | u32 status = host->cmd_status; |
| 961 | |
| 962 | host->cmd_status = 0; |
| 963 | |
| 964 | /* Read the response from the card (up to 16 bytes) */ |
| 965 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 966 | if (cmd->flags & MMC_RSP_136) { |
| 967 | cmd->resp[3] = mci_readl(host, RESP0); |
| 968 | cmd->resp[2] = mci_readl(host, RESP1); |
| 969 | cmd->resp[1] = mci_readl(host, RESP2); |
| 970 | cmd->resp[0] = mci_readl(host, RESP3); |
| 971 | } else { |
| 972 | cmd->resp[0] = mci_readl(host, RESP0); |
| 973 | cmd->resp[1] = 0; |
| 974 | cmd->resp[2] = 0; |
| 975 | cmd->resp[3] = 0; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | if (status & SDMMC_INT_RTO) |
| 980 | cmd->error = -ETIMEDOUT; |
| 981 | else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC)) |
| 982 | cmd->error = -EILSEQ; |
| 983 | else if (status & SDMMC_INT_RESP_ERR) |
| 984 | cmd->error = -EIO; |
| 985 | else |
| 986 | cmd->error = 0; |
| 987 | |
| 988 | if (cmd->error) { |
| 989 | /* newer ip versions need a delay between retries */ |
| 990 | if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY) |
| 991 | mdelay(20); |
| 992 | |
| 993 | if (cmd->data) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 994 | dw_mci_stop_dma(host); |
Seungwon Jeon | fda5f73 | 2012-05-22 13:01:13 +0900 | [diff] [blame] | 995 | host->data = NULL; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | static void dw_mci_tasklet_func(unsigned long priv) |
| 1001 | { |
| 1002 | struct dw_mci *host = (struct dw_mci *)priv; |
| 1003 | struct mmc_data *data; |
| 1004 | struct mmc_command *cmd; |
| 1005 | enum dw_mci_state state; |
| 1006 | enum dw_mci_state prev_state; |
James Hogan | 94dd5b3 | 2011-06-29 09:30:47 +0100 | [diff] [blame] | 1007 | u32 status, ctrl; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1008 | |
| 1009 | spin_lock(&host->lock); |
| 1010 | |
| 1011 | state = host->state; |
| 1012 | data = host->data; |
| 1013 | |
| 1014 | do { |
| 1015 | prev_state = state; |
| 1016 | |
| 1017 | switch (state) { |
| 1018 | case STATE_IDLE: |
| 1019 | break; |
| 1020 | |
| 1021 | case STATE_SENDING_CMD: |
| 1022 | if (!test_and_clear_bit(EVENT_CMD_COMPLETE, |
| 1023 | &host->pending_events)) |
| 1024 | break; |
| 1025 | |
| 1026 | cmd = host->cmd; |
| 1027 | host->cmd = NULL; |
| 1028 | set_bit(EVENT_CMD_COMPLETE, &host->completed_events); |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1029 | dw_mci_command_complete(host, cmd); |
| 1030 | if (cmd == host->mrq->sbc && !cmd->error) { |
| 1031 | prev_state = state = STATE_SENDING_CMD; |
| 1032 | __dw_mci_start_request(host, host->cur_slot, |
| 1033 | host->mrq->cmd); |
| 1034 | goto unlock; |
| 1035 | } |
| 1036 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1037 | if (!host->mrq->data || cmd->error) { |
| 1038 | dw_mci_request_end(host, host->mrq); |
| 1039 | goto unlock; |
| 1040 | } |
| 1041 | |
| 1042 | prev_state = state = STATE_SENDING_DATA; |
| 1043 | /* fall through */ |
| 1044 | |
| 1045 | case STATE_SENDING_DATA: |
| 1046 | if (test_and_clear_bit(EVENT_DATA_ERROR, |
| 1047 | &host->pending_events)) { |
| 1048 | dw_mci_stop_dma(host); |
| 1049 | if (data->stop) |
| 1050 | send_stop_cmd(host, data); |
| 1051 | state = STATE_DATA_ERROR; |
| 1052 | break; |
| 1053 | } |
| 1054 | |
| 1055 | if (!test_and_clear_bit(EVENT_XFER_COMPLETE, |
| 1056 | &host->pending_events)) |
| 1057 | break; |
| 1058 | |
| 1059 | set_bit(EVENT_XFER_COMPLETE, &host->completed_events); |
| 1060 | prev_state = state = STATE_DATA_BUSY; |
| 1061 | /* fall through */ |
| 1062 | |
| 1063 | case STATE_DATA_BUSY: |
| 1064 | if (!test_and_clear_bit(EVENT_DATA_COMPLETE, |
| 1065 | &host->pending_events)) |
| 1066 | break; |
| 1067 | |
| 1068 | host->data = NULL; |
| 1069 | set_bit(EVENT_DATA_COMPLETE, &host->completed_events); |
| 1070 | status = host->data_status; |
| 1071 | |
| 1072 | if (status & DW_MCI_DATA_ERROR_FLAGS) { |
| 1073 | if (status & SDMMC_INT_DTO) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1074 | data->error = -ETIMEDOUT; |
| 1075 | } else if (status & SDMMC_INT_DCRC) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1076 | data->error = -EILSEQ; |
James Hogan | 55c5efbc | 2011-06-29 09:29:58 +0100 | [diff] [blame] | 1077 | } else if (status & SDMMC_INT_EBE && |
| 1078 | host->dir_status == |
| 1079 | DW_MCI_SEND_STATUS) { |
| 1080 | /* |
| 1081 | * No data CRC status was returned. |
| 1082 | * The number of bytes transferred will |
| 1083 | * be exaggerated in PIO mode. |
| 1084 | */ |
| 1085 | data->bytes_xfered = 0; |
| 1086 | data->error = -ETIMEDOUT; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1087 | } else { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1088 | dev_err(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1089 | "data FIFO error " |
| 1090 | "(status=%08x)\n", |
| 1091 | status); |
| 1092 | data->error = -EIO; |
| 1093 | } |
James Hogan | 94dd5b3 | 2011-06-29 09:30:47 +0100 | [diff] [blame] | 1094 | /* |
| 1095 | * After an error, there may be data lingering |
| 1096 | * in the FIFO, so reset it - doing so |
| 1097 | * generates a block interrupt, hence setting |
| 1098 | * the scatter-gather pointer to NULL. |
| 1099 | */ |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1100 | sg_miter_stop(&host->sg_miter); |
James Hogan | 94dd5b3 | 2011-06-29 09:30:47 +0100 | [diff] [blame] | 1101 | host->sg = NULL; |
| 1102 | ctrl = mci_readl(host, CTRL); |
| 1103 | ctrl |= SDMMC_CTRL_FIFO_RESET; |
| 1104 | mci_writel(host, CTRL, ctrl); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1105 | } else { |
| 1106 | data->bytes_xfered = data->blocks * data->blksz; |
| 1107 | data->error = 0; |
| 1108 | } |
| 1109 | |
| 1110 | if (!data->stop) { |
| 1111 | dw_mci_request_end(host, host->mrq); |
| 1112 | goto unlock; |
| 1113 | } |
| 1114 | |
Seungwon Jeon | 053b3ce | 2011-12-22 18:01:29 +0900 | [diff] [blame] | 1115 | if (host->mrq->sbc && !data->error) { |
| 1116 | data->stop->error = 0; |
| 1117 | dw_mci_request_end(host, host->mrq); |
| 1118 | goto unlock; |
| 1119 | } |
| 1120 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1121 | prev_state = state = STATE_SENDING_STOP; |
| 1122 | if (!data->error) |
| 1123 | send_stop_cmd(host, data); |
| 1124 | /* fall through */ |
| 1125 | |
| 1126 | case STATE_SENDING_STOP: |
| 1127 | if (!test_and_clear_bit(EVENT_CMD_COMPLETE, |
| 1128 | &host->pending_events)) |
| 1129 | break; |
| 1130 | |
| 1131 | host->cmd = NULL; |
| 1132 | dw_mci_command_complete(host, host->mrq->stop); |
| 1133 | dw_mci_request_end(host, host->mrq); |
| 1134 | goto unlock; |
| 1135 | |
| 1136 | case STATE_DATA_ERROR: |
| 1137 | if (!test_and_clear_bit(EVENT_XFER_COMPLETE, |
| 1138 | &host->pending_events)) |
| 1139 | break; |
| 1140 | |
| 1141 | state = STATE_DATA_BUSY; |
| 1142 | break; |
| 1143 | } |
| 1144 | } while (state != prev_state); |
| 1145 | |
| 1146 | host->state = state; |
| 1147 | unlock: |
| 1148 | spin_unlock(&host->lock); |
| 1149 | |
| 1150 | } |
| 1151 | |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1152 | /* push final bytes to part_buf, only use during push */ |
| 1153 | static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1154 | { |
| 1155 | memcpy((void *)&host->part_buf, buf, cnt); |
| 1156 | host->part_buf_count = cnt; |
| 1157 | } |
| 1158 | |
| 1159 | /* append bytes to part_buf, only use during push */ |
| 1160 | static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1161 | { |
| 1162 | cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count); |
| 1163 | memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt); |
| 1164 | host->part_buf_count += cnt; |
| 1165 | return cnt; |
| 1166 | } |
| 1167 | |
| 1168 | /* pull first bytes from part_buf, only use during pull */ |
| 1169 | static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1170 | { |
| 1171 | cnt = min(cnt, (int)host->part_buf_count); |
| 1172 | if (cnt) { |
| 1173 | memcpy(buf, (void *)&host->part_buf + host->part_buf_start, |
| 1174 | cnt); |
| 1175 | host->part_buf_count -= cnt; |
| 1176 | host->part_buf_start += cnt; |
| 1177 | } |
| 1178 | return cnt; |
| 1179 | } |
| 1180 | |
| 1181 | /* pull final bytes from the part_buf, assuming it's just been filled */ |
| 1182 | static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt) |
| 1183 | { |
| 1184 | memcpy(buf, &host->part_buf, cnt); |
| 1185 | host->part_buf_start = cnt; |
| 1186 | host->part_buf_count = (1 << host->data_shift) - cnt; |
| 1187 | } |
| 1188 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1189 | static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt) |
| 1190 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1191 | /* try and push anything in the part_buf */ |
| 1192 | if (unlikely(host->part_buf_count)) { |
| 1193 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1194 | buf += len; |
| 1195 | cnt -= len; |
| 1196 | if (!sg_next(host->sg) || host->part_buf_count == 2) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1197 | mci_writew(host, DATA(host->data_offset), |
| 1198 | host->part_buf16); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1199 | host->part_buf_count = 0; |
| 1200 | } |
| 1201 | } |
| 1202 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1203 | if (unlikely((unsigned long)buf & 0x1)) { |
| 1204 | while (cnt >= 2) { |
| 1205 | u16 aligned_buf[64]; |
| 1206 | int len = min(cnt & -2, (int)sizeof(aligned_buf)); |
| 1207 | int items = len >> 1; |
| 1208 | int i; |
| 1209 | /* memcpy from input buffer into aligned buffer */ |
| 1210 | memcpy(aligned_buf, buf, len); |
| 1211 | buf += len; |
| 1212 | cnt -= len; |
| 1213 | /* push data from aligned buffer into fifo */ |
| 1214 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1215 | mci_writew(host, DATA(host->data_offset), |
| 1216 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1217 | } |
| 1218 | } else |
| 1219 | #endif |
| 1220 | { |
| 1221 | u16 *pdata = buf; |
| 1222 | for (; cnt >= 2; cnt -= 2) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1223 | mci_writew(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1224 | buf = pdata; |
| 1225 | } |
| 1226 | /* put anything remaining in the part_buf */ |
| 1227 | if (cnt) { |
| 1228 | dw_mci_set_part_bytes(host, buf, cnt); |
| 1229 | if (!sg_next(host->sg)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1230 | mci_writew(host, DATA(host->data_offset), |
| 1231 | host->part_buf16); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt) |
| 1236 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1237 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1238 | if (unlikely((unsigned long)buf & 0x1)) { |
| 1239 | while (cnt >= 2) { |
| 1240 | /* pull data from fifo into aligned buffer */ |
| 1241 | u16 aligned_buf[64]; |
| 1242 | int len = min(cnt & -2, (int)sizeof(aligned_buf)); |
| 1243 | int items = len >> 1; |
| 1244 | int i; |
| 1245 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1246 | aligned_buf[i] = mci_readw(host, |
| 1247 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1248 | /* memcpy from aligned buffer into output buffer */ |
| 1249 | memcpy(buf, aligned_buf, len); |
| 1250 | buf += len; |
| 1251 | cnt -= len; |
| 1252 | } |
| 1253 | } else |
| 1254 | #endif |
| 1255 | { |
| 1256 | u16 *pdata = buf; |
| 1257 | for (; cnt >= 2; cnt -= 2) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1258 | *pdata++ = mci_readw(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1259 | buf = pdata; |
| 1260 | } |
| 1261 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1262 | host->part_buf16 = mci_readw(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1263 | dw_mci_pull_final_bytes(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt) |
| 1268 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1269 | /* try and push anything in the part_buf */ |
| 1270 | if (unlikely(host->part_buf_count)) { |
| 1271 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1272 | buf += len; |
| 1273 | cnt -= len; |
| 1274 | if (!sg_next(host->sg) || host->part_buf_count == 4) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1275 | mci_writel(host, DATA(host->data_offset), |
| 1276 | host->part_buf32); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1277 | host->part_buf_count = 0; |
| 1278 | } |
| 1279 | } |
| 1280 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1281 | if (unlikely((unsigned long)buf & 0x3)) { |
| 1282 | while (cnt >= 4) { |
| 1283 | u32 aligned_buf[32]; |
| 1284 | int len = min(cnt & -4, (int)sizeof(aligned_buf)); |
| 1285 | int items = len >> 2; |
| 1286 | int i; |
| 1287 | /* memcpy from input buffer into aligned buffer */ |
| 1288 | memcpy(aligned_buf, buf, len); |
| 1289 | buf += len; |
| 1290 | cnt -= len; |
| 1291 | /* push data from aligned buffer into fifo */ |
| 1292 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1293 | mci_writel(host, DATA(host->data_offset), |
| 1294 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1295 | } |
| 1296 | } else |
| 1297 | #endif |
| 1298 | { |
| 1299 | u32 *pdata = buf; |
| 1300 | for (; cnt >= 4; cnt -= 4) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1301 | mci_writel(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1302 | buf = pdata; |
| 1303 | } |
| 1304 | /* put anything remaining in the part_buf */ |
| 1305 | if (cnt) { |
| 1306 | dw_mci_set_part_bytes(host, buf, cnt); |
| 1307 | if (!sg_next(host->sg)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1308 | mci_writel(host, DATA(host->data_offset), |
| 1309 | host->part_buf32); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt) |
| 1314 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1315 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1316 | if (unlikely((unsigned long)buf & 0x3)) { |
| 1317 | while (cnt >= 4) { |
| 1318 | /* pull data from fifo into aligned buffer */ |
| 1319 | u32 aligned_buf[32]; |
| 1320 | int len = min(cnt & -4, (int)sizeof(aligned_buf)); |
| 1321 | int items = len >> 2; |
| 1322 | int i; |
| 1323 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1324 | aligned_buf[i] = mci_readl(host, |
| 1325 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1326 | /* memcpy from aligned buffer into output buffer */ |
| 1327 | memcpy(buf, aligned_buf, len); |
| 1328 | buf += len; |
| 1329 | cnt -= len; |
| 1330 | } |
| 1331 | } else |
| 1332 | #endif |
| 1333 | { |
| 1334 | u32 *pdata = buf; |
| 1335 | for (; cnt >= 4; cnt -= 4) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1336 | *pdata++ = mci_readl(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1337 | buf = pdata; |
| 1338 | } |
| 1339 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1340 | host->part_buf32 = mci_readl(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1341 | dw_mci_pull_final_bytes(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt) |
| 1346 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1347 | /* try and push anything in the part_buf */ |
| 1348 | if (unlikely(host->part_buf_count)) { |
| 1349 | int len = dw_mci_push_part_bytes(host, buf, cnt); |
| 1350 | buf += len; |
| 1351 | cnt -= len; |
| 1352 | if (!sg_next(host->sg) || host->part_buf_count == 8) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1353 | mci_writew(host, DATA(host->data_offset), |
| 1354 | host->part_buf); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1355 | host->part_buf_count = 0; |
| 1356 | } |
| 1357 | } |
| 1358 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1359 | if (unlikely((unsigned long)buf & 0x7)) { |
| 1360 | while (cnt >= 8) { |
| 1361 | u64 aligned_buf[16]; |
| 1362 | int len = min(cnt & -8, (int)sizeof(aligned_buf)); |
| 1363 | int items = len >> 3; |
| 1364 | int i; |
| 1365 | /* memcpy from input buffer into aligned buffer */ |
| 1366 | memcpy(aligned_buf, buf, len); |
| 1367 | buf += len; |
| 1368 | cnt -= len; |
| 1369 | /* push data from aligned buffer into fifo */ |
| 1370 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1371 | mci_writeq(host, DATA(host->data_offset), |
| 1372 | aligned_buf[i]); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1373 | } |
| 1374 | } else |
| 1375 | #endif |
| 1376 | { |
| 1377 | u64 *pdata = buf; |
| 1378 | for (; cnt >= 8; cnt -= 8) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1379 | mci_writeq(host, DATA(host->data_offset), *pdata++); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1380 | buf = pdata; |
| 1381 | } |
| 1382 | /* put anything remaining in the part_buf */ |
| 1383 | if (cnt) { |
| 1384 | dw_mci_set_part_bytes(host, buf, cnt); |
| 1385 | if (!sg_next(host->sg)) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1386 | mci_writeq(host, DATA(host->data_offset), |
| 1387 | host->part_buf); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt) |
| 1392 | { |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1393 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 1394 | if (unlikely((unsigned long)buf & 0x7)) { |
| 1395 | while (cnt >= 8) { |
| 1396 | /* pull data from fifo into aligned buffer */ |
| 1397 | u64 aligned_buf[16]; |
| 1398 | int len = min(cnt & -8, (int)sizeof(aligned_buf)); |
| 1399 | int items = len >> 3; |
| 1400 | int i; |
| 1401 | for (i = 0; i < items; ++i) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1402 | aligned_buf[i] = mci_readq(host, |
| 1403 | DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1404 | /* memcpy from aligned buffer into output buffer */ |
| 1405 | memcpy(buf, aligned_buf, len); |
| 1406 | buf += len; |
| 1407 | cnt -= len; |
| 1408 | } |
| 1409 | } else |
| 1410 | #endif |
| 1411 | { |
| 1412 | u64 *pdata = buf; |
| 1413 | for (; cnt >= 8; cnt -= 8) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1414 | *pdata++ = mci_readq(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1415 | buf = pdata; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1416 | } |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1417 | if (cnt) { |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 1418 | host->part_buf = mci_readq(host, DATA(host->data_offset)); |
James Hogan | 34b664a | 2011-06-24 13:57:56 +0100 | [diff] [blame] | 1419 | dw_mci_pull_final_bytes(host, buf, cnt); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt) |
| 1424 | { |
| 1425 | int len; |
| 1426 | |
| 1427 | /* get remaining partial bytes */ |
| 1428 | len = dw_mci_pull_part_bytes(host, buf, cnt); |
| 1429 | if (unlikely(len == cnt)) |
| 1430 | return; |
| 1431 | buf += len; |
| 1432 | cnt -= len; |
| 1433 | |
| 1434 | /* get the rest of the data */ |
| 1435 | host->pull_data(host, buf, cnt); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | static void dw_mci_read_data_pio(struct dw_mci *host) |
| 1439 | { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1440 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
| 1441 | void *buf; |
| 1442 | unsigned int offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1443 | struct mmc_data *data = host->data; |
| 1444 | int shift = host->data_shift; |
| 1445 | u32 status; |
Chris Ball | ba6a902 | 2011-02-28 16:45:10 -0500 | [diff] [blame] | 1446 | unsigned int nbytes = 0, len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1447 | unsigned int remain, fcnt; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1448 | |
| 1449 | do { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1450 | if (!sg_miter_next(sg_miter)) |
| 1451 | goto done; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1452 | |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1453 | host->sg = sg_miter->__sg; |
| 1454 | buf = sg_miter->addr; |
| 1455 | remain = sg_miter->length; |
| 1456 | offset = 0; |
| 1457 | |
| 1458 | do { |
| 1459 | fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS)) |
| 1460 | << shift) + host->part_buf_count; |
| 1461 | len = min(remain, fcnt); |
| 1462 | if (!len) |
| 1463 | break; |
| 1464 | dw_mci_pull_data(host, (void *)(buf + offset), len); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1465 | offset += len; |
| 1466 | nbytes += len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1467 | remain -= len; |
| 1468 | } while (remain); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1469 | |
Seungwon Jeon | e74f3a9 | 2012-08-01 09:30:46 +0900 | [diff] [blame] | 1470 | sg_miter->consumed = offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1471 | status = mci_readl(host, MINTSTS); |
| 1472 | mci_writel(host, RINTSTS, SDMMC_INT_RXDR); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1473 | } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1474 | data->bytes_xfered += nbytes; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1475 | |
| 1476 | if (!remain) { |
| 1477 | if (!sg_miter_next(sg_miter)) |
| 1478 | goto done; |
| 1479 | sg_miter->consumed = 0; |
| 1480 | } |
| 1481 | sg_miter_stop(sg_miter); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1482 | return; |
| 1483 | |
| 1484 | done: |
| 1485 | data->bytes_xfered += nbytes; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1486 | sg_miter_stop(sg_miter); |
| 1487 | host->sg = NULL; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1488 | smp_wmb(); |
| 1489 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 1490 | } |
| 1491 | |
| 1492 | static void dw_mci_write_data_pio(struct dw_mci *host) |
| 1493 | { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1494 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
| 1495 | void *buf; |
| 1496 | unsigned int offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1497 | struct mmc_data *data = host->data; |
| 1498 | int shift = host->data_shift; |
| 1499 | u32 status; |
| 1500 | unsigned int nbytes = 0, len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1501 | unsigned int fifo_depth = host->fifo_depth; |
| 1502 | unsigned int remain, fcnt; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1503 | |
| 1504 | do { |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1505 | if (!sg_miter_next(sg_miter)) |
| 1506 | goto done; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1507 | |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1508 | host->sg = sg_miter->__sg; |
| 1509 | buf = sg_miter->addr; |
| 1510 | remain = sg_miter->length; |
| 1511 | offset = 0; |
| 1512 | |
| 1513 | do { |
| 1514 | fcnt = ((fifo_depth - |
| 1515 | SDMMC_GET_FCNT(mci_readl(host, STATUS))) |
| 1516 | << shift) - host->part_buf_count; |
| 1517 | len = min(remain, fcnt); |
| 1518 | if (!len) |
| 1519 | break; |
| 1520 | host->push_data(host, (void *)(buf + offset), len); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1521 | offset += len; |
| 1522 | nbytes += len; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1523 | remain -= len; |
| 1524 | } while (remain); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1525 | |
Seungwon Jeon | e74f3a9 | 2012-08-01 09:30:46 +0900 | [diff] [blame] | 1526 | sg_miter->consumed = offset; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1527 | status = mci_readl(host, MINTSTS); |
| 1528 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1529 | } while (status & SDMMC_INT_TXDR); /* if TXDR write again */ |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1530 | data->bytes_xfered += nbytes; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1531 | |
| 1532 | if (!remain) { |
| 1533 | if (!sg_miter_next(sg_miter)) |
| 1534 | goto done; |
| 1535 | sg_miter->consumed = 0; |
| 1536 | } |
| 1537 | sg_miter_stop(sg_miter); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1538 | return; |
| 1539 | |
| 1540 | done: |
| 1541 | data->bytes_xfered += nbytes; |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1542 | sg_miter_stop(sg_miter); |
| 1543 | host->sg = NULL; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1544 | smp_wmb(); |
| 1545 | set_bit(EVENT_XFER_COMPLETE, &host->pending_events); |
| 1546 | } |
| 1547 | |
| 1548 | static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status) |
| 1549 | { |
| 1550 | if (!host->cmd_status) |
| 1551 | host->cmd_status = status; |
| 1552 | |
| 1553 | smp_wmb(); |
| 1554 | |
| 1555 | set_bit(EVENT_CMD_COMPLETE, &host->pending_events); |
| 1556 | tasklet_schedule(&host->tasklet); |
| 1557 | } |
| 1558 | |
| 1559 | static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) |
| 1560 | { |
| 1561 | struct dw_mci *host = dev_id; |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 1562 | u32 pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1563 | unsigned int pass_count = 0; |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1564 | int i; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1565 | |
| 1566 | do { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1567 | pending = mci_readl(host, MINTSTS); /* read-only mask reg */ |
| 1568 | |
| 1569 | /* |
| 1570 | * DTO fix - version 2.10a and below, and only if internal DMA |
| 1571 | * is configured. |
| 1572 | */ |
| 1573 | if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) { |
| 1574 | if (!pending && |
| 1575 | ((mci_readl(host, STATUS) >> 17) & 0x1fff)) |
| 1576 | pending |= SDMMC_INT_DATA_OVER; |
| 1577 | } |
| 1578 | |
| 1579 | if (!pending) |
| 1580 | break; |
| 1581 | |
| 1582 | if (pending & DW_MCI_CMD_ERROR_FLAGS) { |
| 1583 | mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 1584 | host->cmd_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1585 | smp_wmb(); |
| 1586 | set_bit(EVENT_CMD_COMPLETE, &host->pending_events); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | if (pending & DW_MCI_DATA_ERROR_FLAGS) { |
| 1590 | /* if there is an error report DATA_ERROR */ |
| 1591 | mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 1592 | host->data_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1593 | smp_wmb(); |
| 1594 | set_bit(EVENT_DATA_ERROR, &host->pending_events); |
Seungwon Jeon | 9b2026a | 2012-08-01 09:30:40 +0900 | [diff] [blame] | 1595 | tasklet_schedule(&host->tasklet); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | if (pending & SDMMC_INT_DATA_OVER) { |
| 1599 | mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER); |
| 1600 | if (!host->data_status) |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 1601 | host->data_status = pending; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1602 | smp_wmb(); |
| 1603 | if (host->dir_status == DW_MCI_RECV_STATUS) { |
| 1604 | if (host->sg != NULL) |
| 1605 | dw_mci_read_data_pio(host); |
| 1606 | } |
| 1607 | set_bit(EVENT_DATA_COMPLETE, &host->pending_events); |
| 1608 | tasklet_schedule(&host->tasklet); |
| 1609 | } |
| 1610 | |
| 1611 | if (pending & SDMMC_INT_RXDR) { |
| 1612 | mci_writel(host, RINTSTS, SDMMC_INT_RXDR); |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 1613 | if (host->dir_status == DW_MCI_RECV_STATUS && host->sg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1614 | dw_mci_read_data_pio(host); |
| 1615 | } |
| 1616 | |
| 1617 | if (pending & SDMMC_INT_TXDR) { |
| 1618 | mci_writel(host, RINTSTS, SDMMC_INT_TXDR); |
James Hogan | b40af3a | 2011-06-24 13:54:06 +0100 | [diff] [blame] | 1619 | if (host->dir_status == DW_MCI_SEND_STATUS && host->sg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1620 | dw_mci_write_data_pio(host); |
| 1621 | } |
| 1622 | |
| 1623 | if (pending & SDMMC_INT_CMD_DONE) { |
| 1624 | mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE); |
Seungwon Jeon | 182c908 | 2012-08-01 09:30:30 +0900 | [diff] [blame] | 1625 | dw_mci_cmd_interrupt(host, pending); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | if (pending & SDMMC_INT_CD) { |
| 1629 | mci_writel(host, RINTSTS, SDMMC_INT_CD); |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 1630 | queue_work(host->card_workqueue, &host->card_work); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1631 | } |
| 1632 | |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 1633 | /* Handle SDIO Interrupts */ |
| 1634 | for (i = 0; i < host->num_slots; i++) { |
| 1635 | struct dw_mci_slot *slot = host->slot[i]; |
| 1636 | if (pending & SDMMC_INT_SDIO(i)) { |
| 1637 | mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i)); |
| 1638 | mmc_signal_sdio_irq(slot->mmc); |
| 1639 | } |
| 1640 | } |
| 1641 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1642 | } while (pass_count++ < 5); |
| 1643 | |
| 1644 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1645 | /* Handle DMA interrupts */ |
| 1646 | pending = mci_readl(host, IDSTS); |
| 1647 | if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { |
| 1648 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); |
| 1649 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1650 | host->dma_ops->complete(host); |
| 1651 | } |
| 1652 | #endif |
| 1653 | |
| 1654 | return IRQ_HANDLED; |
| 1655 | } |
| 1656 | |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 1657 | static void dw_mci_work_routine_card(struct work_struct *work) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1658 | { |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 1659 | struct dw_mci *host = container_of(work, struct dw_mci, card_work); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1660 | int i; |
| 1661 | |
| 1662 | for (i = 0; i < host->num_slots; i++) { |
| 1663 | struct dw_mci_slot *slot = host->slot[i]; |
| 1664 | struct mmc_host *mmc = slot->mmc; |
| 1665 | struct mmc_request *mrq; |
| 1666 | int present; |
| 1667 | u32 ctrl; |
| 1668 | |
| 1669 | present = dw_mci_get_cd(mmc); |
| 1670 | while (present != slot->last_detect_state) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1671 | dev_dbg(&slot->mmc->class_dev, "card %s\n", |
| 1672 | present ? "inserted" : "removed"); |
| 1673 | |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 1674 | /* Power up slot (before spin_lock, may sleep) */ |
| 1675 | if (present != 0 && host->pdata->setpower) |
| 1676 | host->pdata->setpower(slot->id, mmc->ocr_avail); |
| 1677 | |
| 1678 | spin_lock_bh(&host->lock); |
| 1679 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1680 | /* Card change detected */ |
| 1681 | slot->last_detect_state = present; |
| 1682 | |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 1683 | /* Mark card as present if applicable */ |
| 1684 | if (present != 0) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1685 | set_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1686 | |
| 1687 | /* Clean up queue if present */ |
| 1688 | mrq = slot->mrq; |
| 1689 | if (mrq) { |
| 1690 | if (mrq == host->mrq) { |
| 1691 | host->data = NULL; |
| 1692 | host->cmd = NULL; |
| 1693 | |
| 1694 | switch (host->state) { |
| 1695 | case STATE_IDLE: |
| 1696 | break; |
| 1697 | case STATE_SENDING_CMD: |
| 1698 | mrq->cmd->error = -ENOMEDIUM; |
| 1699 | if (!mrq->data) |
| 1700 | break; |
| 1701 | /* fall through */ |
| 1702 | case STATE_SENDING_DATA: |
| 1703 | mrq->data->error = -ENOMEDIUM; |
| 1704 | dw_mci_stop_dma(host); |
| 1705 | break; |
| 1706 | case STATE_DATA_BUSY: |
| 1707 | case STATE_DATA_ERROR: |
| 1708 | if (mrq->data->error == -EINPROGRESS) |
| 1709 | mrq->data->error = -ENOMEDIUM; |
| 1710 | if (!mrq->stop) |
| 1711 | break; |
| 1712 | /* fall through */ |
| 1713 | case STATE_SENDING_STOP: |
| 1714 | mrq->stop->error = -ENOMEDIUM; |
| 1715 | break; |
| 1716 | } |
| 1717 | |
| 1718 | dw_mci_request_end(host, mrq); |
| 1719 | } else { |
| 1720 | list_del(&slot->queue_node); |
| 1721 | mrq->cmd->error = -ENOMEDIUM; |
| 1722 | if (mrq->data) |
| 1723 | mrq->data->error = -ENOMEDIUM; |
| 1724 | if (mrq->stop) |
| 1725 | mrq->stop->error = -ENOMEDIUM; |
| 1726 | |
| 1727 | spin_unlock(&host->lock); |
| 1728 | mmc_request_done(slot->mmc, mrq); |
| 1729 | spin_lock(&host->lock); |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | /* Power down slot */ |
| 1734 | if (present == 0) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1735 | clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
| 1736 | |
| 1737 | /* |
| 1738 | * Clear down the FIFO - doing so generates a |
| 1739 | * block interrupt, hence setting the |
| 1740 | * scatter-gather pointer to NULL. |
| 1741 | */ |
Seungwon Jeon | f9c2a0d | 2012-02-09 14:32:43 +0900 | [diff] [blame] | 1742 | sg_miter_stop(&host->sg_miter); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1743 | host->sg = NULL; |
| 1744 | |
| 1745 | ctrl = mci_readl(host, CTRL); |
| 1746 | ctrl |= SDMMC_CTRL_FIFO_RESET; |
| 1747 | mci_writel(host, CTRL, ctrl); |
| 1748 | |
| 1749 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1750 | ctrl = mci_readl(host, BMOD); |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 1751 | /* Software reset of DMA */ |
| 1752 | ctrl |= SDMMC_IDMAC_SWRESET; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1753 | mci_writel(host, BMOD, ctrl); |
| 1754 | #endif |
| 1755 | |
| 1756 | } |
| 1757 | |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 1758 | spin_unlock_bh(&host->lock); |
| 1759 | |
| 1760 | /* Power down slot (after spin_unlock, may sleep) */ |
| 1761 | if (present == 0 && host->pdata->setpower) |
| 1762 | host->pdata->setpower(slot->id, 0); |
| 1763 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1764 | present = dw_mci_get_cd(mmc); |
| 1765 | } |
| 1766 | |
| 1767 | mmc_detect_change(slot->mmc, |
| 1768 | msecs_to_jiffies(host->pdata->detect_delay_ms)); |
| 1769 | } |
| 1770 | } |
| 1771 | |
Jaehoon Chung | 36c179a | 2012-08-23 20:31:48 +0900 | [diff] [blame] | 1772 | 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] | 1773 | { |
| 1774 | struct mmc_host *mmc; |
| 1775 | struct dw_mci_slot *slot; |
| 1776 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1777 | mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1778 | if (!mmc) |
| 1779 | return -ENOMEM; |
| 1780 | |
| 1781 | slot = mmc_priv(mmc); |
| 1782 | slot->id = id; |
| 1783 | slot->mmc = mmc; |
| 1784 | slot->host = host; |
| 1785 | |
| 1786 | mmc->ops = &dw_mci_ops; |
| 1787 | mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510); |
| 1788 | mmc->f_max = host->bus_hz; |
| 1789 | |
| 1790 | if (host->pdata->get_ocr) |
| 1791 | mmc->ocr_avail = host->pdata->get_ocr(id); |
| 1792 | else |
| 1793 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
| 1794 | |
| 1795 | /* |
| 1796 | * Start with slot power disabled, it will be enabled when a card |
| 1797 | * is detected. |
| 1798 | */ |
| 1799 | if (host->pdata->setpower) |
| 1800 | host->pdata->setpower(id, 0); |
| 1801 | |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 1802 | if (host->pdata->caps) |
| 1803 | mmc->caps = host->pdata->caps; |
Jaehoon Chung | fc3d772 | 2011-02-25 11:08:15 +0900 | [diff] [blame] | 1804 | |
Seungwon Jeon | 4f408cc | 2011-12-09 14:55:52 +0900 | [diff] [blame] | 1805 | if (host->pdata->caps2) |
| 1806 | mmc->caps2 = host->pdata->caps2; |
Seungwon Jeon | 4f408cc | 2011-12-09 14:55:52 +0900 | [diff] [blame] | 1807 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1808 | if (host->pdata->get_bus_wd) |
| 1809 | if (host->pdata->get_bus_wd(slot->id) >= 4) |
| 1810 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 1811 | |
| 1812 | if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED) |
Seungwon Jeon | 6daa777 | 2011-08-05 12:35:03 +0900 | [diff] [blame] | 1813 | mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1814 | |
Jaehoon Chung | 356ac2c | 2012-01-13 17:31:32 +0900 | [diff] [blame] | 1815 | if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY) |
| 1816 | mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; |
| 1817 | else |
| 1818 | mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE; |
| 1819 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1820 | if (host->pdata->blk_settings) { |
| 1821 | mmc->max_segs = host->pdata->blk_settings->max_segs; |
| 1822 | mmc->max_blk_size = host->pdata->blk_settings->max_blk_size; |
| 1823 | mmc->max_blk_count = host->pdata->blk_settings->max_blk_count; |
| 1824 | mmc->max_req_size = host->pdata->blk_settings->max_req_size; |
| 1825 | mmc->max_seg_size = host->pdata->blk_settings->max_seg_size; |
| 1826 | } else { |
| 1827 | /* Useful defaults if platform data is unset. */ |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 1828 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1829 | mmc->max_segs = host->ring_size; |
| 1830 | mmc->max_blk_size = 65536; |
| 1831 | mmc->max_blk_count = host->ring_size; |
| 1832 | mmc->max_seg_size = 0x1000; |
| 1833 | mmc->max_req_size = mmc->max_seg_size * mmc->max_blk_count; |
| 1834 | #else |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1835 | mmc->max_segs = 64; |
| 1836 | mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */ |
| 1837 | mmc->max_blk_count = 512; |
| 1838 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
| 1839 | mmc->max_seg_size = mmc->max_req_size; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1840 | #endif /* CONFIG_MMC_DW_IDMAC */ |
Jaehoon Chung | a39e574 | 2012-02-04 17:00:27 -0500 | [diff] [blame] | 1841 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1842 | |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 1843 | host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); |
| 1844 | if (IS_ERR(host->vmmc)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1845 | pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 1846 | host->vmmc = NULL; |
| 1847 | } else |
| 1848 | regulator_enable(host->vmmc); |
| 1849 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1850 | if (dw_mci_get_cd(mmc)) |
| 1851 | set_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
| 1852 | else |
| 1853 | clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); |
| 1854 | |
| 1855 | host->slot[id] = slot; |
| 1856 | mmc_add_host(mmc); |
| 1857 | |
| 1858 | #if defined(CONFIG_DEBUG_FS) |
| 1859 | dw_mci_init_debugfs(slot); |
| 1860 | #endif |
| 1861 | |
| 1862 | /* Card initially undetected */ |
| 1863 | slot->last_detect_state = 0; |
| 1864 | |
Will Newton | dd6c4b9 | 2011-02-10 14:37:03 -0500 | [diff] [blame] | 1865 | /* |
| 1866 | * Card may have been plugged in prior to boot so we |
| 1867 | * need to run the detect tasklet |
| 1868 | */ |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 1869 | queue_work(host->card_workqueue, &host->card_work); |
Will Newton | dd6c4b9 | 2011-02-10 14:37:03 -0500 | [diff] [blame] | 1870 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1871 | return 0; |
| 1872 | } |
| 1873 | |
| 1874 | static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id) |
| 1875 | { |
| 1876 | /* Shutdown detect IRQ */ |
| 1877 | if (slot->host->pdata->exit) |
| 1878 | slot->host->pdata->exit(id); |
| 1879 | |
| 1880 | /* Debugfs stuff is cleaned up by mmc core */ |
| 1881 | mmc_remove_host(slot->mmc); |
| 1882 | slot->host->slot[id] = NULL; |
| 1883 | mmc_free_host(slot->mmc); |
| 1884 | } |
| 1885 | |
| 1886 | static void dw_mci_init_dma(struct dw_mci *host) |
| 1887 | { |
| 1888 | /* Alloc memory for sg translation */ |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1889 | host->sg_cpu = dma_alloc_coherent(host->dev, PAGE_SIZE, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1890 | &host->sg_dma, GFP_KERNEL); |
| 1891 | if (!host->sg_cpu) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1892 | dev_err(host->dev, "%s: could not alloc DMA memory\n", |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1893 | __func__); |
| 1894 | goto no_dma; |
| 1895 | } |
| 1896 | |
| 1897 | /* Determine which DMA interface to use */ |
| 1898 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1899 | host->dma_ops = &dw_mci_idmac_ops; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1900 | #endif |
| 1901 | |
| 1902 | if (!host->dma_ops) |
| 1903 | goto no_dma; |
| 1904 | |
Jaehoon Chung | e1631f9 | 2012-04-18 15:42:31 +0900 | [diff] [blame] | 1905 | if (host->dma_ops->init && host->dma_ops->start && |
| 1906 | host->dma_ops->stop && host->dma_ops->cleanup) { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1907 | if (host->dma_ops->init(host)) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1908 | dev_err(host->dev, "%s: Unable to initialize " |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1909 | "DMA Controller.\n", __func__); |
| 1910 | goto no_dma; |
| 1911 | } |
| 1912 | } else { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1913 | dev_err(host->dev, "DMA initialization not found.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1914 | goto no_dma; |
| 1915 | } |
| 1916 | |
| 1917 | host->use_dma = 1; |
| 1918 | return; |
| 1919 | |
| 1920 | no_dma: |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1921 | dev_info(host->dev, "Using PIO mode.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1922 | host->use_dma = 0; |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | static bool mci_wait_reset(struct device *dev, struct dw_mci *host) |
| 1927 | { |
| 1928 | unsigned long timeout = jiffies + msecs_to_jiffies(500); |
| 1929 | unsigned int ctrl; |
| 1930 | |
| 1931 | mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | |
| 1932 | SDMMC_CTRL_DMA_RESET)); |
| 1933 | |
| 1934 | /* wait till resets clear */ |
| 1935 | do { |
| 1936 | ctrl = mci_readl(host, CTRL); |
| 1937 | if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | |
| 1938 | SDMMC_CTRL_DMA_RESET))) |
| 1939 | return true; |
| 1940 | } while (time_before(jiffies, timeout)); |
| 1941 | |
| 1942 | dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl); |
| 1943 | |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1947 | int dw_mci_probe(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1948 | { |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1949 | int width, i, ret = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1950 | u32 fifo_size; |
Thomas Abraham | 1c2215b | 2012-09-17 18:16:37 +0000 | [diff] [blame] | 1951 | int init_slots = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1952 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1953 | if (!host->pdata || !host->pdata->init) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1954 | dev_err(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1955 | "Platform data must supply init function\n"); |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1956 | return -ENODEV; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1957 | } |
| 1958 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1959 | if (!host->pdata->select_slot && host->pdata->num_slots > 1) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 1960 | dev_err(host->dev, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1961 | "Platform data must supply select_slot function\n"); |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 1962 | return -ENODEV; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1963 | } |
| 1964 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 1965 | host->biu_clk = clk_get(host->dev, "biu"); |
| 1966 | if (IS_ERR(host->biu_clk)) { |
| 1967 | dev_dbg(host->dev, "biu clock not available\n"); |
| 1968 | } else { |
| 1969 | ret = clk_prepare_enable(host->biu_clk); |
| 1970 | if (ret) { |
| 1971 | dev_err(host->dev, "failed to enable biu clock\n"); |
| 1972 | clk_put(host->biu_clk); |
| 1973 | return ret; |
| 1974 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1975 | } |
| 1976 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 1977 | host->ciu_clk = clk_get(host->dev, "ciu"); |
| 1978 | if (IS_ERR(host->ciu_clk)) { |
| 1979 | dev_dbg(host->dev, "ciu clock not available\n"); |
| 1980 | } else { |
| 1981 | ret = clk_prepare_enable(host->ciu_clk); |
| 1982 | if (ret) { |
| 1983 | dev_err(host->dev, "failed to enable ciu clock\n"); |
| 1984 | clk_put(host->ciu_clk); |
| 1985 | goto err_clk_biu; |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | if (IS_ERR(host->ciu_clk)) |
| 1990 | host->bus_hz = host->pdata->bus_hz; |
| 1991 | else |
| 1992 | host->bus_hz = clk_get_rate(host->ciu_clk); |
| 1993 | |
| 1994 | if (!host->bus_hz) { |
| 1995 | dev_err(host->dev, |
| 1996 | "Platform data must supply bus speed\n"); |
| 1997 | ret = -ENODEV; |
| 1998 | goto err_clk_ciu; |
| 1999 | } |
| 2000 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2001 | host->quirks = host->pdata->quirks; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2002 | |
| 2003 | spin_lock_init(&host->lock); |
| 2004 | INIT_LIST_HEAD(&host->queue); |
| 2005 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2006 | /* |
| 2007 | * Get the host data width - this assumes that HCON has been set with |
| 2008 | * the correct values. |
| 2009 | */ |
| 2010 | i = (mci_readl(host, HCON) >> 7) & 0x7; |
| 2011 | if (!i) { |
| 2012 | host->push_data = dw_mci_push_data16; |
| 2013 | host->pull_data = dw_mci_pull_data16; |
| 2014 | width = 16; |
| 2015 | host->data_shift = 1; |
| 2016 | } else if (i == 2) { |
| 2017 | host->push_data = dw_mci_push_data64; |
| 2018 | host->pull_data = dw_mci_pull_data64; |
| 2019 | width = 64; |
| 2020 | host->data_shift = 3; |
| 2021 | } else { |
| 2022 | /* Check for a reserved value, and warn if it is */ |
| 2023 | WARN((i != 1), |
| 2024 | "HCON reports a reserved host data width!\n" |
| 2025 | "Defaulting to 32-bit access.\n"); |
| 2026 | host->push_data = dw_mci_push_data32; |
| 2027 | host->pull_data = dw_mci_pull_data32; |
| 2028 | width = 32; |
| 2029 | host->data_shift = 2; |
| 2030 | } |
| 2031 | |
| 2032 | /* Reset all blocks */ |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2033 | if (!mci_wait_reset(host->dev, host)) |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 2034 | return -ENODEV; |
| 2035 | |
| 2036 | host->dma_ops = host->pdata->dma_ops; |
| 2037 | dw_mci_init_dma(host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2038 | |
| 2039 | /* Clear the interrupts for the host controller */ |
| 2040 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2041 | mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ |
| 2042 | |
| 2043 | /* Put in max timeout */ |
| 2044 | mci_writel(host, TMOUT, 0xFFFFFFFF); |
| 2045 | |
| 2046 | /* |
| 2047 | * FIFO threshold settings RxMark = fifo_size / 2 - 1, |
| 2048 | * Tx Mark = fifo_size / 2 DMA Size = 8 |
| 2049 | */ |
James Hogan | b86d825 | 2011-06-24 13:57:18 +0100 | [diff] [blame] | 2050 | if (!host->pdata->fifo_depth) { |
| 2051 | /* |
| 2052 | * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may |
| 2053 | * have been overwritten by the bootloader, just like we're |
| 2054 | * about to do, so if you know the value for your hardware, you |
| 2055 | * should put it in the platform data. |
| 2056 | */ |
| 2057 | fifo_size = mci_readl(host, FIFOTH); |
Jaehoon Chung | 8234e86 | 2012-01-11 09:28:21 +0000 | [diff] [blame] | 2058 | fifo_size = 1 + ((fifo_size >> 16) & 0xfff); |
James Hogan | b86d825 | 2011-06-24 13:57:18 +0100 | [diff] [blame] | 2059 | } else { |
| 2060 | fifo_size = host->pdata->fifo_depth; |
| 2061 | } |
| 2062 | host->fifo_depth = fifo_size; |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2063 | host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) | |
| 2064 | ((fifo_size/2) << 0)); |
| 2065 | mci_writel(host, FIFOTH, host->fifoth_val); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2066 | |
| 2067 | /* disable clock to CIU */ |
| 2068 | mci_writel(host, CLKENA, 0); |
| 2069 | mci_writel(host, CLKSRC, 0); |
| 2070 | |
| 2071 | tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 2072 | host->card_workqueue = alloc_workqueue("dw-mci-card", |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 2073 | WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1); |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 2074 | if (!host->card_workqueue) |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 2075 | goto err_dmaunmap; |
| 2076 | INIT_WORK(&host->card_work, dw_mci_work_routine_card); |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2077 | ret = request_irq(host->irq, dw_mci_interrupt, host->irq_flags, "dw-mci", host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2078 | if (ret) |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 2079 | goto err_workqueue; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2080 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2081 | if (host->pdata->num_slots) |
| 2082 | host->num_slots = host->pdata->num_slots; |
| 2083 | else |
| 2084 | host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1; |
| 2085 | |
| 2086 | /* We need at least one slot to succeed */ |
| 2087 | for (i = 0; i < host->num_slots; i++) { |
| 2088 | ret = dw_mci_init_slot(host, i); |
Thomas Abraham | 1c2215b | 2012-09-17 18:16:37 +0000 | [diff] [blame] | 2089 | if (ret) |
| 2090 | dev_dbg(host->dev, "slot %d init failed\n", i); |
| 2091 | else |
| 2092 | init_slots++; |
| 2093 | } |
| 2094 | |
| 2095 | if (init_slots) { |
| 2096 | dev_info(host->dev, "%d slots initialized\n", init_slots); |
| 2097 | } else { |
| 2098 | dev_dbg(host->dev, "attempted to initialize %d slots, " |
| 2099 | "but failed on all\n", host->num_slots); |
| 2100 | goto err_init_slot; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | /* |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 2104 | * In 2.40a spec, Data offset is changed. |
| 2105 | * Need to check the version-id and set data-offset for DATA register. |
| 2106 | */ |
| 2107 | host->verid = SDMMC_GET_VERID(mci_readl(host, VERID)); |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2108 | dev_info(host->dev, "Version ID is %04x\n", host->verid); |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 2109 | |
| 2110 | if (host->verid < DW_MMC_240A) |
| 2111 | host->data_offset = DATA_OFFSET; |
| 2112 | else |
| 2113 | host->data_offset = DATA_240A_OFFSET; |
| 2114 | |
| 2115 | /* |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2116 | * Enable interrupts for command done, data over, data empty, card det, |
| 2117 | * receive ready and error such as transmit, receive timeout, crc error |
| 2118 | */ |
| 2119 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2120 | mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | |
| 2121 | SDMMC_INT_TXDR | SDMMC_INT_RXDR | |
| 2122 | DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); |
| 2123 | mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */ |
| 2124 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2125 | dev_info(host->dev, "DW MMC controller at irq %d, " |
James Hogan | b86d825 | 2011-06-24 13:57:18 +0100 | [diff] [blame] | 2126 | "%d bit host data width, " |
| 2127 | "%u deep fifo\n", |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2128 | host->irq, width, fifo_size); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2129 | if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2130 | dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n"); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2131 | |
| 2132 | return 0; |
| 2133 | |
| 2134 | err_init_slot: |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2135 | free_irq(host->irq, host); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2136 | |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 2137 | err_workqueue: |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 2138 | destroy_workqueue(host->card_workqueue); |
James Hogan | 1791b13e | 2011-06-24 13:55:55 +0100 | [diff] [blame] | 2139 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2140 | err_dmaunmap: |
| 2141 | if (host->use_dma && host->dma_ops->exit) |
| 2142 | host->dma_ops->exit(host); |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2143 | dma_free_coherent(host->dev, PAGE_SIZE, |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2144 | host->sg_cpu, host->sg_dma); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2145 | |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 2146 | if (host->vmmc) { |
| 2147 | regulator_disable(host->vmmc); |
| 2148 | regulator_put(host->vmmc); |
| 2149 | } |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2150 | |
| 2151 | err_clk_ciu: |
| 2152 | if (!IS_ERR(host->ciu_clk)) { |
| 2153 | clk_disable_unprepare(host->ciu_clk); |
| 2154 | clk_put(host->ciu_clk); |
| 2155 | } |
| 2156 | err_clk_biu: |
| 2157 | if (!IS_ERR(host->biu_clk)) { |
| 2158 | clk_disable_unprepare(host->biu_clk); |
| 2159 | clk_put(host->biu_clk); |
| 2160 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2161 | return ret; |
| 2162 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2163 | EXPORT_SYMBOL(dw_mci_probe); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2164 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2165 | void dw_mci_remove(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2166 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2167 | int i; |
| 2168 | |
| 2169 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2170 | mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ |
| 2171 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2172 | for (i = 0; i < host->num_slots; i++) { |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2173 | dev_dbg(host->dev, "remove slot %d\n", i); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2174 | if (host->slot[i]) |
| 2175 | dw_mci_cleanup_slot(host->slot[i], i); |
| 2176 | } |
| 2177 | |
| 2178 | /* disable clock to CIU */ |
| 2179 | mci_writel(host, CLKENA, 0); |
| 2180 | mci_writel(host, CLKSRC, 0); |
| 2181 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2182 | free_irq(host->irq, host); |
Thomas Abraham | 95dcc2c | 2012-05-01 14:57:36 -0700 | [diff] [blame] | 2183 | destroy_workqueue(host->card_workqueue); |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2184 | dma_free_coherent(host->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2185 | |
| 2186 | if (host->use_dma && host->dma_ops->exit) |
| 2187 | host->dma_ops->exit(host); |
| 2188 | |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 2189 | if (host->vmmc) { |
| 2190 | regulator_disable(host->vmmc); |
| 2191 | regulator_put(host->vmmc); |
| 2192 | } |
| 2193 | |
Thomas Abraham | f90a061 | 2012-09-17 18:16:38 +0000 | [diff] [blame] | 2194 | if (!IS_ERR(host->ciu_clk)) |
| 2195 | clk_disable_unprepare(host->ciu_clk); |
| 2196 | if (!IS_ERR(host->biu_clk)) |
| 2197 | clk_disable_unprepare(host->biu_clk); |
| 2198 | clk_put(host->ciu_clk); |
| 2199 | clk_put(host->biu_clk); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2200 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2201 | EXPORT_SYMBOL(dw_mci_remove); |
| 2202 | |
| 2203 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2204 | |
Jaehoon Chung | 6fe8890 | 2011-12-08 19:23:03 +0900 | [diff] [blame] | 2205 | #ifdef CONFIG_PM_SLEEP |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2206 | /* |
| 2207 | * TODO: we should probably disable the clock to the card in the suspend path. |
| 2208 | */ |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2209 | int dw_mci_suspend(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2210 | { |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2211 | int i, ret = 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2212 | |
| 2213 | for (i = 0; i < host->num_slots; i++) { |
| 2214 | struct dw_mci_slot *slot = host->slot[i]; |
| 2215 | if (!slot) |
| 2216 | continue; |
| 2217 | ret = mmc_suspend_host(slot->mmc); |
| 2218 | if (ret < 0) { |
| 2219 | while (--i >= 0) { |
| 2220 | slot = host->slot[i]; |
| 2221 | if (slot) |
| 2222 | mmc_resume_host(host->slot[i]->mmc); |
| 2223 | } |
| 2224 | return ret; |
| 2225 | } |
| 2226 | } |
| 2227 | |
Jaehoon Chung | c07946a | 2011-02-25 11:08:14 +0900 | [diff] [blame] | 2228 | if (host->vmmc) |
| 2229 | regulator_disable(host->vmmc); |
| 2230 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2231 | return 0; |
| 2232 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2233 | EXPORT_SYMBOL(dw_mci_suspend); |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2234 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2235 | int dw_mci_resume(struct dw_mci *host) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2236 | { |
| 2237 | int i, ret; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2238 | |
Jaehoon Chung | 1d6c4e0 | 2011-05-11 15:52:39 +0900 | [diff] [blame] | 2239 | if (host->vmmc) |
| 2240 | regulator_enable(host->vmmc); |
| 2241 | |
Thomas Abraham | 4a90920 | 2012-09-17 18:16:35 +0000 | [diff] [blame] | 2242 | if (!mci_wait_reset(host->dev, host)) { |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2243 | ret = -ENODEV; |
| 2244 | return ret; |
| 2245 | } |
| 2246 | |
Jonathan Kliegman | 3bfe619 | 2012-06-14 13:31:55 -0400 | [diff] [blame] | 2247 | if (host->use_dma && host->dma_ops->init) |
Seungwon Jeon | 141a712 | 2012-05-22 13:01:03 +0900 | [diff] [blame] | 2248 | host->dma_ops->init(host); |
| 2249 | |
Jaehoon Chung | e61cf11 | 2011-03-17 20:32:33 +0900 | [diff] [blame] | 2250 | /* Restore the old value at FIFOTH register */ |
| 2251 | mci_writel(host, FIFOTH, host->fifoth_val); |
| 2252 | |
| 2253 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| 2254 | mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | |
| 2255 | SDMMC_INT_TXDR | SDMMC_INT_RXDR | |
| 2256 | DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); |
| 2257 | mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); |
| 2258 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2259 | for (i = 0; i < host->num_slots; i++) { |
| 2260 | struct dw_mci_slot *slot = host->slot[i]; |
| 2261 | if (!slot) |
| 2262 | continue; |
| 2263 | ret = mmc_resume_host(host->slot[i]->mmc); |
| 2264 | if (ret < 0) |
| 2265 | return ret; |
| 2266 | } |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2267 | return 0; |
| 2268 | } |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2269 | EXPORT_SYMBOL(dw_mci_resume); |
Jaehoon Chung | 6fe8890 | 2011-12-08 19:23:03 +0900 | [diff] [blame] | 2270 | #endif /* CONFIG_PM_SLEEP */ |
| 2271 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2272 | static int __init dw_mci_init(void) |
| 2273 | { |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 2274 | printk(KERN_INFO "Synopsys Designware Multimedia Card Interface Driver"); |
| 2275 | return 0; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | static void __exit dw_mci_exit(void) |
| 2279 | { |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | module_init(dw_mci_init); |
| 2283 | module_exit(dw_mci_exit); |
| 2284 | |
| 2285 | MODULE_DESCRIPTION("DW Multimedia Card Interface driver"); |
| 2286 | MODULE_AUTHOR("NXP Semiconductor VietNam"); |
| 2287 | MODULE_AUTHOR("Imagination Technologies Ltd"); |
| 2288 | MODULE_LICENSE("GPL v2"); |