diff options
| author | Jeff Garzik <jeff@garzik.org> | 2006-04-12 16:54:16 -0400 |
|---|---|---|
| committer | Jeff Garzik <jeff@garzik.org> | 2006-04-12 16:54:16 -0400 |
| commit | 875999c5539999f61a45620aae0c3e5fb1d2b035 (patch) | |
| tree | 4535032a8a10f5782c0aef6a620b1a624ea9f863 /drivers/mmc | |
| parent | 79072f38909e3d9883317238887460c39ddcc4cb (diff) | |
| parent | 26ec634c31a11a003040e10b4d650495158632fd (diff) | |
Merge branch 'upstream'
Diffstat (limited to 'drivers/mmc')
| -rw-r--r-- | drivers/mmc/Kconfig | 29 | ||||
| -rw-r--r-- | drivers/mmc/Makefile | 7 | ||||
| -rw-r--r-- | drivers/mmc/at91_mci.c | 988 | ||||
| -rw-r--r-- | drivers/mmc/au1xmmc.c | 19 | ||||
| -rw-r--r-- | drivers/mmc/imxmmc.c | 1096 | ||||
| -rw-r--r-- | drivers/mmc/imxmmc.h | 67 | ||||
| -rw-r--r-- | drivers/mmc/mmc.c | 19 | ||||
| -rw-r--r-- | drivers/mmc/mmci.c | 4 | ||||
| -rw-r--r-- | drivers/mmc/omap.c | 1226 | ||||
| -rw-r--r-- | drivers/mmc/omap.h | 55 | ||||
| -rw-r--r-- | drivers/mmc/pxamci.c | 24 | ||||
| -rw-r--r-- | drivers/mmc/sdhci.c | 6 | ||||
| -rw-r--r-- | drivers/mmc/wbsd.c | 9 |
13 files changed, 3496 insertions, 53 deletions
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 3f5d77f633fa..003b077c2324 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig | |||
| @@ -60,6 +60,17 @@ config MMC_SDHCI | |||
| 60 | 60 | ||
| 61 | If unsure, say N. | 61 | If unsure, say N. |
| 62 | 62 | ||
| 63 | config MMC_OMAP | ||
| 64 | tristate "TI OMAP Multimedia Card Interface support" | ||
| 65 | depends on ARCH_OMAP && MMC | ||
| 66 | select TPS65010 if MACH_OMAP_H2 | ||
| 67 | help | ||
| 68 | This selects the TI OMAP Multimedia card Interface. | ||
| 69 | If you have an OMAP board with a Multimedia Card slot, | ||
| 70 | say Y or M here. | ||
| 71 | |||
| 72 | If unsure, say N. | ||
| 73 | |||
| 63 | config MMC_WBSD | 74 | config MMC_WBSD |
| 64 | tristate "Winbond W83L51xD SD/MMC Card Interface support" | 75 | tristate "Winbond W83L51xD SD/MMC Card Interface support" |
| 65 | depends on MMC && ISA_DMA_API | 76 | depends on MMC && ISA_DMA_API |
| @@ -80,4 +91,22 @@ config MMC_AU1X | |||
| 80 | 91 | ||
| 81 | If unsure, say N. | 92 | If unsure, say N. |
| 82 | 93 | ||
| 94 | config MMC_AT91RM9200 | ||
| 95 | tristate "AT91RM9200 SD/MMC Card Interface support" | ||
| 96 | depends on ARCH_AT91RM9200 && MMC | ||
| 97 | help | ||
| 98 | This selects the AT91RM9200 MCI controller. | ||
| 99 | |||
| 100 | If unsure, say N. | ||
| 101 | |||
| 102 | config MMC_IMX | ||
| 103 | tristate "Motorola i.MX Multimedia Card Interface support" | ||
| 104 | depends on ARCH_IMX && MMC | ||
| 105 | help | ||
| 106 | This selects the Motorola i.MX Multimedia card Interface. | ||
| 107 | If you have a i.MX platform with a Multimedia Card slot, | ||
| 108 | say Y or M here. | ||
| 109 | |||
| 110 | If unsure, say N. | ||
| 111 | |||
| 83 | endmenu | 112 | endmenu |
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile index 769d545284a4..d2957e35cc6f 100644 --- a/drivers/mmc/Makefile +++ b/drivers/mmc/Makefile | |||
| @@ -17,8 +17,15 @@ obj-$(CONFIG_MMC_BLOCK) += mmc_block.o | |||
| 17 | # | 17 | # |
| 18 | obj-$(CONFIG_MMC_ARMMMCI) += mmci.o | 18 | obj-$(CONFIG_MMC_ARMMMCI) += mmci.o |
| 19 | obj-$(CONFIG_MMC_PXA) += pxamci.o | 19 | obj-$(CONFIG_MMC_PXA) += pxamci.o |
| 20 | obj-$(CONFIG_MMC_IMX) += imxmmc.o | ||
| 20 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o | 21 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o |
| 21 | obj-$(CONFIG_MMC_WBSD) += wbsd.o | 22 | obj-$(CONFIG_MMC_WBSD) += wbsd.o |
| 22 | obj-$(CONFIG_MMC_AU1X) += au1xmmc.o | 23 | obj-$(CONFIG_MMC_AU1X) += au1xmmc.o |
| 24 | obj-$(CONFIG_MMC_OMAP) += omap.o | ||
| 25 | obj-$(CONFIG_MMC_AT91RM9200) += at91_mci.o | ||
| 23 | 26 | ||
| 24 | mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o | 27 | mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o |
| 28 | |||
| 29 | ifeq ($(CONFIG_MMC_DEBUG),y) | ||
| 30 | EXTRA_CFLAGS += -DDEBUG | ||
| 31 | endif | ||
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c new file mode 100644 index 000000000000..6061c2d101a0 --- /dev/null +++ b/drivers/mmc/at91_mci.c | |||
| @@ -0,0 +1,988 @@ | |||
| 1 | /* | ||
| 2 | * linux/drivers/mmc/at91_mci.c - ATMEL AT91RM9200 MCI Driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved | ||
| 5 | * | ||
| 6 | * Copyright (C) 2006 Malcolm Noyes | ||
| 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 version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | /* | ||
| 14 | This is the AT91RM9200 MCI driver that has been tested with both MMC cards | ||
| 15 | and SD-cards. Boards that support write protect are now supported. | ||
| 16 | The CCAT91SBC001 board does not support SD cards. | ||
| 17 | |||
| 18 | The three entry points are at91_mci_request, at91_mci_set_ios | ||
| 19 | and at91_mci_get_ro. | ||
| 20 | |||
| 21 | SET IOS | ||
| 22 | This configures the device to put it into the correct mode and clock speed | ||
| 23 | required. | ||
| 24 | |||
| 25 | MCI REQUEST | ||
| 26 | MCI request processes the commands sent in the mmc_request structure. This | ||
| 27 | can consist of a processing command and a stop command in the case of | ||
| 28 | multiple block transfers. | ||
| 29 | |||
| 30 | There are three main types of request, commands, reads and writes. | ||
| 31 | |||
| 32 | Commands are straight forward. The command is submitted to the controller and | ||
| 33 | the request function returns. When the controller generates an interrupt to indicate | ||
| 34 | the command is finished, the response to the command are read and the mmc_request_done | ||
| 35 | function called to end the request. | ||
| 36 | |||
| 37 | Reads and writes work in a similar manner to normal commands but involve the PDC (DMA) | ||
| 38 | controller to manage the transfers. | ||
| 39 | |||
| 40 | A read is done from the controller directly to the scatterlist passed in from the request. | ||
| 41 | Due to a bug in the controller, when a read is completed, all the words are byte | ||
| 42 | swapped in the scatterlist buffers. | ||
| 43 | |||
| 44 | The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY | ||
| 45 | |||
| 46 | A write is slightly different in that the bytes to write are read from the scatterlist | ||
| 47 | into a dma memory buffer (this is in case the source buffer should be read only). The | ||
| 48 | entire write buffer is then done from this single dma memory buffer. | ||
| 49 | |||
| 50 | The sequence of write interrupts is: ENDTX, TXBUFE, NOTBUSY, CMDRDY | ||
| 51 | |||
| 52 | GET RO | ||
| 53 | Gets the status of the write protect pin, if available. | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <linux/config.h> | ||
| 57 | #include <linux/module.h> | ||
| 58 | #include <linux/moduleparam.h> | ||
| 59 | #include <linux/init.h> | ||
| 60 | #include <linux/ioport.h> | ||
| 61 | #include <linux/platform_device.h> | ||
| 62 | #include <linux/interrupt.h> | ||
| 63 | #include <linux/blkdev.h> | ||
| 64 | #include <linux/delay.h> | ||
| 65 | #include <linux/err.h> | ||
| 66 | #include <linux/dma-mapping.h> | ||
| 67 | #include <linux/clk.h> | ||
| 68 | |||
| 69 | #include <linux/mmc/host.h> | ||
| 70 | #include <linux/mmc/protocol.h> | ||
| 71 | |||
| 72 | #include <asm/io.h> | ||
| 73 | #include <asm/irq.h> | ||
| 74 | #include <asm/mach/mmc.h> | ||
| 75 | #include <asm/arch/board.h> | ||
| 76 | #include <asm/arch/gpio.h> | ||
| 77 | #include <asm/arch/at91rm9200_mci.h> | ||
| 78 | #include <asm/arch/at91rm9200_pdc.h> | ||
| 79 | |||
| 80 | #define DRIVER_NAME "at91_mci" | ||
| 81 | |||
| 82 | #undef SUPPORT_4WIRE | ||
| 83 | |||
| 84 | #ifdef CONFIG_MMC_DEBUG | ||
| 85 | #define DBG(fmt...) \ | ||
| 86 | printk(fmt) | ||
| 87 | #else | ||
| 88 | #define DBG(fmt...) do { } while (0) | ||
| 89 | #endif | ||
| 90 | |||
| 91 | static struct clk *mci_clk; | ||
| 92 | |||
| 93 | #define FL_SENT_COMMAND (1 << 0) | ||
| 94 | #define FL_SENT_STOP (1 << 1) | ||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | /* | ||
| 99 | * Read from a MCI register. | ||
| 100 | */ | ||
| 101 | static inline unsigned long at91_mci_read(unsigned int reg) | ||
| 102 | { | ||
| 103 | void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI; | ||
| 104 | |||
| 105 | return __raw_readl(mci_base + reg); | ||
| 106 | } | ||
| 107 | |||
| 108 | /* | ||
| 109 | * Write to a MCI register. | ||
| 110 | */ | ||
| 111 | static inline void at91_mci_write(unsigned int reg, unsigned long value) | ||
| 112 | { | ||
| 113 | void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI; | ||
| 114 | |||
| 115 | __raw_writel(value, mci_base + reg); | ||
| 116 | } | ||
| 117 | |||
| 118 | /* | ||
| 119 | * Low level type for this driver | ||
| 120 | */ | ||
| 121 | struct at91mci_host | ||
| 122 | { | ||
| 123 | struct mmc_host *mmc; | ||
| 124 | struct mmc_command *cmd; | ||
| 125 | struct mmc_request *request; | ||
| 126 | |||
| 127 | struct at91_mmc_data *board; | ||
| 128 | int present; | ||
| 129 | |||
| 130 | /* | ||
| 131 | * Flag indicating when the command has been sent. This is used to | ||
| 132 | * work out whether or not to send the stop | ||
| 133 | */ | ||
| 134 | unsigned int flags; | ||
| 135 | /* flag for current bus settings */ | ||
| 136 | u32 bus_mode; | ||
| 137 | |||
| 138 | /* DMA buffer used for transmitting */ | ||
| 139 | unsigned int* buffer; | ||
| 140 | dma_addr_t physical_address; | ||
| 141 | unsigned int total_length; | ||
| 142 | |||
| 143 | /* Latest in the scatterlist that has been enabled for transfer, but not freed */ | ||
| 144 | int in_use_index; | ||
| 145 | |||
| 146 | /* Latest in the scatterlist that has been enabled for transfer */ | ||
| 147 | int transfer_index; | ||
| 148 | }; | ||
| 149 | |||
| 150 | /* | ||
| 151 | * Copy from sg to a dma block - used for transfers | ||
| 152 | */ | ||
| 153 | static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data) | ||
| 154 | { | ||
| 155 | unsigned int len, i, size; | ||
| 156 | unsigned *dmabuf = host->buffer; | ||
| 157 | |||
| 158 | size = host->total_length; | ||
| 159 | len = data->sg_len; | ||
| 160 | |||
| 161 | /* | ||
| 162 | * Just loop through all entries. Size might not | ||
| 163 | * be the entire list though so make sure that | ||
| 164 | * we do not transfer too much. | ||
| 165 | */ | ||
| 166 | for (i = 0; i < len; i++) { | ||
| 167 | struct scatterlist *sg; | ||
| 168 | int amount; | ||
| 169 | int index; | ||
| 170 | unsigned int *sgbuffer; | ||
| 171 | |||
| 172 | sg = &data->sg[i]; | ||
| 173 | |||
| 174 | sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset; | ||
| 175 | amount = min(size, sg->length); | ||
| 176 | size -= amount; | ||
| 177 | amount /= 4; | ||
| 178 | |||
| 179 | for (index = 0; index < amount; index++) | ||
| 180 | *dmabuf++ = swab32(sgbuffer[index]); | ||
| 181 | |||
| 182 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); | ||
| 183 | |||
| 184 | if (size == 0) | ||
| 185 | break; | ||
| 186 | } | ||
| 187 | |||
| 188 | /* | ||
| 189 | * Check that we didn't get a request to transfer | ||
| 190 | * more data than can fit into the SG list. | ||
| 191 | */ | ||
| 192 | BUG_ON(size != 0); | ||
| 193 | } | ||
| 194 | |||
| 195 | /* | ||
| 196 | * Prepare a dma read | ||
| 197 | */ | ||
| 198 | static void at91mci_pre_dma_read(struct at91mci_host *host) | ||
| 199 | { | ||
| 200 | int i; | ||
| 201 | struct scatterlist *sg; | ||
| 202 | struct mmc_command *cmd; | ||
| 203 | struct mmc_data *data; | ||
| 204 | |||
| 205 | DBG("pre dma read\n"); | ||
| 206 | |||
| 207 | cmd = host->cmd; | ||
| 208 | if (!cmd) { | ||
| 209 | DBG("no command\n"); | ||
| 210 | return; | ||
| 211 | } | ||
| 212 | |||
| 213 | data = cmd->data; | ||
| 214 | if (!data) { | ||
| 215 | DBG("no data\n"); | ||
| 216 | return; | ||
| 217 | } | ||
| 218 | |||
| 219 | for (i = 0; i < 2; i++) { | ||
| 220 | /* nothing left to transfer */ | ||
| 221 | if (host->transfer_index >= data->sg_len) { | ||
| 222 | DBG("Nothing left to transfer (index = %d)\n", host->transfer_index); | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | |||
| 226 | /* Check to see if this needs filling */ | ||
| 227 | if (i == 0) { | ||
| 228 | if (at91_mci_read(AT91_PDC_RCR) != 0) { | ||
| 229 | DBG("Transfer active in current\n"); | ||
| 230 | continue; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | else { | ||
| 234 | if (at91_mci_read(AT91_PDC_RNCR) != 0) { | ||
| 235 | DBG("Transfer active in next\n"); | ||
| 236 | continue; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | /* Setup the next transfer */ | ||
| 241 | DBG("Using transfer index %d\n", host->transfer_index); | ||
| 242 | |||
| 243 | sg = &data->sg[host->transfer_index++]; | ||
| 244 | DBG("sg = %p\n", sg); | ||
| 245 | |||
| 246 | sg->dma_address = dma_map_page(NULL, sg->page, sg->offset, sg->length, DMA_FROM_DEVICE); | ||
| 247 | |||
| 248 | DBG("dma address = %08X, length = %d\n", sg->dma_address, sg->length); | ||
| 249 | |||
| 250 | if (i == 0) { | ||
| 251 | at91_mci_write(AT91_PDC_RPR, sg->dma_address); | ||
| 252 | at91_mci_write(AT91_PDC_RCR, sg->length / 4); | ||
| 253 | } | ||
| 254 | else { | ||
| 255 | at91_mci_write(AT91_PDC_RNPR, sg->dma_address); | ||
| 256 | at91_mci_write(AT91_PDC_RNCR, sg->length / 4); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | DBG("pre dma read done\n"); | ||
| 261 | } | ||
| 262 | |||
| 263 | /* | ||
| 264 | * Handle after a dma read | ||
| 265 | */ | ||
| 266 | static void at91mci_post_dma_read(struct at91mci_host *host) | ||
| 267 | { | ||
| 268 | struct mmc_command *cmd; | ||
| 269 | struct mmc_data *data; | ||
| 270 | |||
| 271 | DBG("post dma read\n"); | ||
| 272 | |||
| 273 | cmd = host->cmd; | ||
| 274 | if (!cmd) { | ||
| 275 | DBG("no command\n"); | ||
| 276 | return; | ||
| 277 | } | ||
| 278 | |||
| 279 | data = cmd->data; | ||
| 280 | if (!data) { | ||
| 281 | DBG("no data\n"); | ||
| 282 | return; | ||
| 283 | } | ||
| 284 | |||
| 285 | while (host->in_use_index < host->transfer_index) { | ||
| 286 | unsigned int *buffer; | ||
| 287 | int index; | ||
| 288 | int len; | ||
| 289 | |||
| 290 | struct scatterlist *sg; | ||
| 291 | |||
| 292 | DBG("finishing index %d\n", host->in_use_index); | ||
| 293 | |||
| 294 | sg = &data->sg[host->in_use_index++]; | ||
| 295 | |||
| 296 | DBG("Unmapping page %08X\n", sg->dma_address); | ||
| 297 | |||
| 298 | dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE); | ||
| 299 | |||
| 300 | /* Swap the contents of the buffer */ | ||
| 301 | buffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset; | ||
| 302 | DBG("buffer = %p, length = %d\n", buffer, sg->length); | ||
| 303 | |||
| 304 | data->bytes_xfered += sg->length; | ||
| 305 | |||
| 306 | len = sg->length / 4; | ||
| 307 | |||
| 308 | for (index = 0; index < len; index++) { | ||
| 309 | buffer[index] = swab32(buffer[index]); | ||
| 310 | } | ||
| 311 | kunmap_atomic(buffer, KM_BIO_SRC_IRQ); | ||
| 312 | flush_dcache_page(sg->page); | ||
| 313 | } | ||
| 314 | |||
| 315 | /* Is there another transfer to trigger? */ | ||
| 316 | if (host->transfer_index < data->sg_len) | ||
| 317 | at91mci_pre_dma_read(host); | ||
| 318 | else { | ||
| 319 | at91_mci_write(AT91_MCI_IER, AT91_MCI_RXBUFF); | ||
| 320 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); | ||
| 321 | } | ||
| 322 | |||
| 323 | DBG("post dma read done\n"); | ||
| 324 | } | ||
| 325 | |||
| 326 | /* | ||
| 327 | * Handle transmitted data | ||
| 328 | */ | ||
| 329 | static void at91_mci_handle_transmitted(struct at91mci_host *host) | ||
| 330 | { | ||
| 331 | struct mmc_command *cmd; | ||
| 332 | struct mmc_data *data; | ||
| 333 | |||
| 334 | DBG("Handling the transmit\n"); | ||
| 335 | |||
| 336 | /* Disable the transfer */ | ||
| 337 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); | ||
| 338 | |||
| 339 | /* Now wait for cmd ready */ | ||
| 340 | at91_mci_write(AT91_MCI_IDR, AT91_MCI_TXBUFE); | ||
| 341 | at91_mci_write(AT91_MCI_IER, AT91_MCI_NOTBUSY); | ||
| 342 | |||
| 343 | cmd = host->cmd; | ||
| 344 | if (!cmd) return; | ||
| 345 | |||
| 346 | data = cmd->data; | ||
| 347 | if (!data) return; | ||
| 348 | |||
| 349 | data->bytes_xfered = host->total_length; | ||
| 350 | } | ||
| 351 | |||
| 352 | /* | ||
| 353 | * Enable the controller | ||
| 354 | */ | ||
| 355 | static void at91_mci_enable(void) | ||
| 356 | { | ||
| 357 | at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN); | ||
| 358 | at91_mci_write(AT91_MCI_IDR, 0xFFFFFFFF); | ||
| 359 | at91_mci_write(AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC); | ||
| 360 | at91_mci_write(AT91_MCI_MR, 0x834A); | ||
| 361 | at91_mci_write(AT91_MCI_SDCR, 0x0); | ||
| 362 | } | ||
| 363 | |||
| 364 | /* | ||
| 365 | * Disable the controller | ||
| 366 | */ | ||
| 367 | static void at91_mci_disable(void) | ||
| 368 | { | ||
| 369 | at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST); | ||
| 370 | } | ||
| 371 | |||
| 372 | /* | ||
| 373 | * Send a command | ||
| 374 | * return the interrupts to enable | ||
| 375 | */ | ||
| 376 | static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd) | ||
| 377 | { | ||
| 378 | unsigned int cmdr, mr; | ||
| 379 | unsigned int block_length; | ||
| 380 | struct mmc_data *data = cmd->data; | ||
| 381 | |||
| 382 | unsigned int blocks; | ||
| 383 | unsigned int ier = 0; | ||
| 384 | |||
| 385 | host->cmd = cmd; | ||
| 386 | |||
| 387 | /* Not sure if this is needed */ | ||
| 388 | #if 0 | ||
| 389 | if ((at91_mci_read(AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) { | ||
| 390 | DBG("Clearing timeout\n"); | ||
| 391 | at91_mci_write(AT91_MCI_ARGR, 0); | ||
| 392 | at91_mci_write(AT91_MCI_CMDR, AT91_MCI_OPDCMD); | ||
| 393 | while (!(at91_mci_read(AT91_MCI_SR) & AT91_MCI_CMDRDY)) { | ||
| 394 | /* spin */ | ||
| 395 | DBG("Clearing: SR = %08X\n", at91_mci_read(AT91_MCI_SR)); | ||
| 396 | } | ||
| 397 | } | ||
| 398 | #endif | ||
| 399 | cmdr = cmd->opcode; | ||
| 400 | |||
| 401 | if (mmc_resp_type(cmd) == MMC_RSP_NONE) | ||
| 402 | cmdr |= AT91_MCI_RSPTYP_NONE; | ||
| 403 | else { | ||
| 404 | /* if a response is expected then allow maximum response latancy */ | ||
| 405 | cmdr |= AT91_MCI_MAXLAT; | ||
| 406 | /* set 136 bit response for R2, 48 bit response otherwise */ | ||
| 407 | if (mmc_resp_type(cmd) == MMC_RSP_R2) | ||
| 408 | cmdr |= AT91_MCI_RSPTYP_136; | ||
| 409 | else | ||
| 410 | cmdr |= AT91_MCI_RSPTYP_48; | ||
| 411 | } | ||
| 412 | |||
| 413 | if (data) { | ||
| 414 | block_length = 1 << data->blksz_bits; | ||
| 415 | blocks = data->blocks; | ||
| 416 | |||
| 417 | /* always set data start - also set direction flag for read */ | ||
| 418 | if (data->flags & MMC_DATA_READ) | ||
| 419 | cmdr |= (AT91_MCI_TRDIR | AT91_MCI_TRCMD_START); | ||
| 420 | else if (data->flags & MMC_DATA_WRITE) | ||
| 421 | cmdr |= AT91_MCI_TRCMD_START; | ||
| 422 | |||
| 423 | if (data->flags & MMC_DATA_STREAM) | ||
| 424 | cmdr |= AT91_MCI_TRTYP_STREAM; | ||
| 425 | if (data->flags & MMC_DATA_MULTI) | ||
| 426 | cmdr |= AT91_MCI_TRTYP_MULTIPLE; | ||
| 427 | } | ||
| 428 | else { | ||
| 429 | block_length = 0; | ||
| 430 | blocks = 0; | ||
| 431 | } | ||
| 432 | |||
| 433 | if (cmd->opcode == MMC_STOP_TRANSMISSION) | ||
| 434 | cmdr |= AT91_MCI_TRCMD_STOP; | ||
| 435 | |||
| 436 | if (host->bus_mode == MMC_BUSMODE_OPENDRAIN) | ||
| 437 | cmdr |= AT91_MCI_OPDCMD; | ||
| 438 | |||
| 439 | /* | ||
| 440 | * Set the arguments and send the command | ||
| 441 | */ | ||
| 442 | DBG("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08lX)\n", | ||
| 443 | cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(AT91_MCI_MR)); | ||
| 444 | |||
| 445 | if (!data) { | ||
| 446 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS); | ||
| 447 | at91_mci_write(AT91_PDC_RPR, 0); | ||
| 448 | at91_mci_write(AT91_PDC_RCR, 0); | ||
| 449 | at91_mci_write(AT91_PDC_RNPR, 0); | ||
| 450 | at91_mci_write(AT91_PDC_RNCR, 0); | ||
| 451 | at91_mci_write(AT91_PDC_TPR, 0); | ||
| 452 | at91_mci_write(AT91_PDC_TCR, 0); | ||
| 453 | at91_mci_write(AT91_PDC_TNPR, 0); | ||
| 454 | at91_mci_write(AT91_PDC_TNCR, 0); | ||
| 455 | |||
| 456 | at91_mci_write(AT91_MCI_ARGR, cmd->arg); | ||
| 457 | at91_mci_write(AT91_MCI_CMDR, cmdr); | ||
| 458 | return AT91_MCI_CMDRDY; | ||
| 459 | } | ||
| 460 | |||
| 461 | mr = at91_mci_read(AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */ | ||
| 462 | at91_mci_write(AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE); | ||
| 463 | |||
| 464 | /* | ||
| 465 | * Disable the PDC controller | ||
| 466 | */ | ||
| 467 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); | ||
| 468 | |||
| 469 | if (cmdr & AT91_MCI_TRCMD_START) { | ||
| 470 | data->bytes_xfered = 0; | ||
| 471 | host->transfer_index = 0; | ||
| 472 | host->in_use_index = 0; | ||
| 473 | if (cmdr & AT91_MCI_TRDIR) { | ||
| 474 | /* | ||
| 475 | * Handle a read | ||
| 476 | */ | ||
| 477 | host->buffer = NULL; | ||
| 478 | host->total_length = 0; | ||
| 479 | |||
| 480 | at91mci_pre_dma_read(host); | ||
| 481 | ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */; | ||
| 482 | } | ||
| 483 | else { | ||
| 484 | /* | ||
| 485 | * Handle a write | ||
| 486 | */ | ||
| 487 | host->total_length = block_length * blocks; | ||
| 488 | host->buffer = dma_alloc_coherent(NULL, | ||
| 489 | host->total_length, | ||
| 490 | &host->physical_address, GFP_KERNEL); | ||
| 491 | |||
| 492 | at91mci_sg_to_dma(host, data); | ||
| 493 | |||
| 494 | DBG("Transmitting %d bytes\n", host->total_length); | ||
| 495 | |||
| 496 | at91_mci_write(AT91_PDC_TPR, host->physical_address); | ||
| 497 | at91_mci_write(AT91_PDC_TCR, host->total_length / 4); | ||
| 498 | ier = AT91_MCI_TXBUFE; | ||
| 499 | } | ||
| 500 | } | ||
| 501 | |||
| 502 | /* | ||
| 503 | * Send the command and then enable the PDC - not the other way round as | ||
| 504 | * the data sheet says | ||
| 505 | */ | ||
| 506 | |||
| 507 | at91_mci_write(AT91_MCI_ARGR, cmd->arg); | ||
| 508 | at91_mci_write(AT91_MCI_CMDR, cmdr); | ||
| 509 | |||
| 510 | if (cmdr & AT91_MCI_TRCMD_START) { | ||
| 511 | if (cmdr & AT91_MCI_TRDIR) | ||
| 512 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTEN); | ||
| 513 | else | ||
| 514 | at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTEN); | ||
| 515 | } | ||
| 516 | return ier; | ||
| 517 | } | ||
| 518 | |||
| 519 | /* | ||
| 520 | * Wait for a command to complete | ||
| 521 | */ | ||
| 522 | static void at91mci_process_command(struct at91mci_host *host, struct mmc_command *cmd) | ||
| 523 | { | ||
| 524 | unsigned int ier; | ||
| 525 | |||
| 526 | ier = at91_mci_send_command(host, cmd); | ||
| 527 | |||
| 528 | DBG("setting ier to %08X\n", ier); | ||
| 529 | |||
| 530 | /* Stop on errors or the required value */ | ||
| 531 | at91_mci_write(AT91_MCI_IER, 0xffff0000 | ier); | ||
| 532 | } | ||
| 533 | |||
| 534 | /* | ||
| 535 | * Process the next step in the request | ||
| 536 | */ | ||
| 537 | static void at91mci_process_next(struct at91mci_host *host) | ||
| 538 | { | ||
| 539 | if (!(host->flags & FL_SENT_COMMAND)) { | ||
| 540 | host->flags |= FL_SENT_COMMAND; | ||
| 541 | at91mci_process_command(host, host->request->cmd); | ||
| 542 | } | ||
| 543 | else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) { | ||
| 544 | host->flags |= FL_SENT_STOP; | ||
| 545 | at91mci_process_command(host, host->request->stop); | ||
| 546 | } | ||
| 547 | else | ||
| 548 | mmc_request_done(host->mmc, host->request); | ||
| 549 | } | ||
| 550 | |||
| 551 | /* | ||
| 552 | * Handle a command that has been completed | ||
| 553 | */ | ||
| 554 | static void at91mci_completed_command(struct at91mci_host *host) | ||
| 555 | { | ||
| 556 | struct mmc_command *cmd = host->cmd; | ||
| 557 | unsigned int status; | ||
| 558 | |||
| 559 | at91_mci_write(AT91_MCI_IDR, 0xffffffff); | ||
| 560 | |||
| 561 | cmd->resp[0] = at91_mci_read(AT91_MCI_RSPR(0)); | ||
| 562 | cmd->resp[1] = at91_mci_read(AT91_MCI_RSPR(1)); | ||
| 563 | cmd->resp[2] = at91_mci_read(AT91_MCI_RSPR(2)); | ||
| 564 | cmd->resp[3] = at91_mci_read(AT91_MCI_RSPR(3)); | ||
| 565 | |||
| 566 | if (host->buffer) { | ||
| 567 | dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address); | ||
| 568 | host->buffer = NULL; | ||
| 569 | } | ||
| 570 | |||
| 571 | status = at91_mci_read(AT91_MCI_SR); | ||
| 572 | |||
| 573 | DBG("Status = %08X [%08X %08X %08X %08X]\n", | ||
| 574 | status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); | ||
| 575 | |||
| 576 | if (status & (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE | | ||
| 577 | AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE | | ||
| 578 | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)) { | ||
| 579 | if ((status & AT91_MCI_RCRCE) && | ||
| 580 | ((cmd->opcode == MMC_SEND_OP_COND) || (cmd->opcode == SD_APP_OP_COND))) { | ||
| 581 | cmd->error = MMC_ERR_NONE; | ||
| 582 | } | ||
| 583 | else { | ||
| 584 | if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE)) | ||
| 585 | cmd->error = MMC_ERR_TIMEOUT; | ||
| 586 | else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE)) | ||
| 587 | cmd->error = MMC_ERR_BADCRC; | ||
| 588 | else if (status & (AT91_MCI_OVRE | AT91_MCI_UNRE)) | ||
| 589 | cmd->error = MMC_ERR_FIFO; | ||
| 590 | else | ||
| 591 | cmd->error = MMC_ERR_FAILED; | ||
| 592 | |||
| 593 | DBG("Error detected and set to %d (cmd = %d, retries = %d)\n", | ||
| 594 | cmd->error, cmd->opcode, cmd->retries); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | else | ||
| 598 | cmd->error = MMC_ERR_NONE; | ||
| 599 | |||
| 600 | at91mci_process_next(host); | ||
| 601 | } | ||
| 602 | |||
| 603 | /* | ||
| 604 | * Handle an MMC request | ||
| 605 | */ | ||
| 606 | static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) | ||
| 607 | { | ||
| 608 | struct at91mci_host *host = mmc_priv(mmc); | ||
| 609 | host->request = mrq; | ||
| 610 | host->flags = 0; | ||
| 611 | |||
| 612 | at91mci_process_next(host); | ||
| 613 | } | ||
| 614 | |||
| 615 | /* | ||
| 616 | * Set the IOS | ||
| 617 | */ | ||
| 618 | static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
| 619 | { | ||
| 620 | int clkdiv; | ||
| 621 | struct at91mci_host *host = mmc_priv(mmc); | ||
| 622 | unsigned long at91_master_clock = clk_get_rate(mci_clk); | ||
| 623 | |||
| 624 | DBG("Clock %uHz, busmode %u, powermode %u, Vdd %u\n", | ||
| 625 | ios->clock, ios->bus_mode, ios->power_mode, ios->vdd); | ||
| 626 | |||
| 627 | if (host) | ||
| 628 | host->bus_mode = ios->bus_mode; | ||
| 629 | else | ||
| 630 | printk("MMC: No host for bus_mode\n"); | ||
| 631 | |||
| 632 | if (ios->clock == 0) { | ||
| 633 | /* Disable the MCI controller */ | ||
| 634 | at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS); | ||
| 635 | clkdiv = 0; | ||
| 636 | } | ||
| 637 | else { | ||
| 638 | /* Enable the MCI controller */ | ||
| 639 | at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN); | ||
| 640 | |||
| 641 | if ((at91_master_clock % (ios->clock * 2)) == 0) | ||
| 642 | clkdiv = ((at91_master_clock / ios->clock) / 2) - 1; | ||
| 643 | else | ||
| 644 | clkdiv = (at91_master_clock / ios->clock) / 2; | ||
| 645 | |||
| 646 | DBG("clkdiv = %d. mcck = %ld\n", clkdiv, | ||
| 647 | at91_master_clock / (2 * (clkdiv + 1))); | ||
| 648 | } | ||
| 649 | if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) { | ||
| 650 | DBG("MMC: Setting controller bus width to 4\n"); | ||
| 651 | at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) | AT91_MCI_SDCBUS); | ||
| 652 | } | ||
| 653 | else { | ||
| 654 | DBG("MMC: Setting controller bus width to 1\n"); | ||
| 655 | at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS); | ||
| 656 | } | ||
| 657 | |||
| 658 | /* Set the clock divider */ | ||
| 659 | at91_mci_write(AT91_MCI_MR, (at91_mci_read(AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv); | ||
| 660 | |||
| 661 | /* maybe switch power to the card */ | ||
| 662 | if (host && host->board->vcc_pin) { | ||
| 663 | switch (ios->power_mode) { | ||
| 664 | case MMC_POWER_OFF: | ||
| 665 | at91_set_gpio_output(host->board->vcc_pin, 0); | ||
| 666 | break; | ||
| 667 | case MMC_POWER_UP: | ||
| 668 | case MMC_POWER_ON: | ||
| 669 | at91_set_gpio_output(host->board->vcc_pin, 1); | ||
| 670 | break; | ||
| 671 | } | ||
| 672 | } | ||
| 673 | } | ||
| 674 | |||
| 675 | /* | ||
| 676 | * Handle an interrupt | ||
| 677 | */ | ||
| 678 | static irqreturn_t at91_mci_irq(int irq, void *devid, struct pt_regs *regs) | ||
| 679 | { | ||
| 680 | struct at91mci_host *host = devid; | ||
| 681 | int completed = 0; | ||
| 682 | |||
| 683 | unsigned int int_status; | ||
| 684 | |||
| 685 | if (host == NULL) | ||
| 686 | return IRQ_HANDLED; | ||
| 687 | |||
| 688 | int_status = at91_mci_read(AT91_MCI_SR); | ||
| 689 | DBG("MCI irq: status = %08X, %08lX, %08lX\n", int_status, at91_mci_read(AT91_MCI_IMR), | ||
| 690 | int_status & at91_mci_read(AT91_MCI_IMR)); | ||
| 691 | |||
| 692 | if ((int_status & at91_mci_read(AT91_MCI_IMR)) & 0xffff0000) | ||
| 693 | completed = 1; | ||
| 694 | |||
| 695 | int_status &= at91_mci_read(AT91_MCI_IMR); | ||
| 696 | |||
| 697 | if (int_status & AT91_MCI_UNRE) | ||
| 698 | DBG("MMC: Underrun error\n"); | ||
| 699 | if (int_status & AT91_MCI_OVRE) | ||
| 700 | DBG("MMC: Overrun error\n"); | ||
| 701 | if (int_status & AT91_MCI_DTOE) | ||
| 702 | DBG("MMC: Data timeout\n"); | ||
| 703 | if (int_status & AT91_MCI_DCRCE) | ||
| 704 | DBG("MMC: CRC error in data\n"); | ||
| 705 | if (int_status & AT91_MCI_RTOE) | ||
| 706 | DBG("MMC: Response timeout\n"); | ||
| 707 | if (int_status & AT91_MCI_RENDE) | ||
| 708 | DBG("MMC: Response end bit error\n"); | ||
| 709 | if (int_status & AT91_MCI_RCRCE) | ||
| 710 | DBG("MMC: Response CRC error\n"); | ||
| 711 | if (int_status & AT91_MCI_RDIRE) | ||
| 712 | DBG("MMC: Response direction error\n"); | ||
| 713 | if (int_status & AT91_MCI_RINDE) | ||
| 714 | DBG("MMC: Response index error\n"); | ||
| 715 | |||
| 716 | /* Only continue processing if no errors */ | ||
| 717 | if (!completed) { | ||
| 718 | if (int_status & AT91_MCI_TXBUFE) { | ||
| 719 | DBG("TX buffer empty\n"); | ||
| 720 | at91_mci_handle_transmitted(host); | ||
| 721 | } | ||
| 722 | |||
| 723 | if (int_status & AT91_MCI_RXBUFF) { | ||
| 724 | DBG("RX buffer full\n"); | ||
| 725 | at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY); | ||
| 726 | } | ||
| 727 | |||
| 728 | if (int_status & AT91_MCI_ENDTX) { | ||
| 729 | DBG("Transmit has ended\n"); | ||
| 730 | } | ||
| 731 | |||
| 732 | if (int_status & AT91_MCI_ENDRX) { | ||
| 733 | DBG("Receive has ended\n"); | ||
| 734 | at91mci_post_dma_read(host); | ||
| 735 | } | ||
| 736 | |||
| 737 | if (int_status & AT91_MCI_NOTBUSY) { | ||
| 738 | DBG("Card is ready\n"); | ||
| 739 | at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY); | ||
| 740 | } | ||
| 741 | |||
| 742 | if (int_status & AT91_MCI_DTIP) { | ||
| 743 | DBG("Data transfer in progress\n"); | ||
| 744 | } | ||
| 745 | |||
| 746 | if (int_status & AT91_MCI_BLKE) { | ||
| 747 | DBG("Block transfer has ended\n"); | ||
| 748 | } | ||
| 749 | |||
| 750 | if (int_status & AT91_MCI_TXRDY) { | ||
| 751 | DBG("Ready to transmit\n"); | ||
| 752 | } | ||
| 753 | |||
| 754 | if (int_status & AT91_MCI_RXRDY) { | ||
| 755 | DBG("Ready to receive\n"); | ||
| 756 | } | ||
| 757 | |||
| 758 | if (int_status & AT91_MCI_CMDRDY) { | ||
| 759 | DBG("Command ready\n"); | ||
| 760 | completed = 1; | ||
| 761 | } | ||
| 762 | } | ||
| 763 | at91_mci_write(AT91_MCI_IDR, int_status); | ||
| 764 | |||
| 765 | if (completed) { | ||
| 766 | DBG("Completed command\n"); | ||
| 767 | at91_mci_write(AT91_MCI_IDR, 0xffffffff); | ||
| 768 | at91mci_completed_command(host); | ||
| 769 | } | ||
| 770 | |||
| 771 | return IRQ_HANDLED; | ||
| 772 | } | ||
| 773 | |||
| 774 | static irqreturn_t at91_mmc_det_irq(int irq, void *_host, struct pt_regs *regs) | ||
| 775 | { | ||
| 776 | struct at91mci_host *host = _host; | ||
| 777 | int present = !at91_get_gpio_value(irq); | ||
| 778 | |||
| 779 | /* | ||
| 780 | * we expect this irq on both insert and remove, | ||
| 781 | * and use a short delay to debounce. | ||
| 782 | */ | ||
| 783 | if (present != host->present) { | ||
| 784 | host->present = present; | ||
| 785 | DBG("%s: card %s\n", mmc_hostname(host->mmc), | ||
| 786 | present ? "insert" : "remove"); | ||
| 787 | if (!present) { | ||
| 788 | DBG("****** Resetting SD-card bus width ******\n"); | ||
| 789 | at91_mci_write(AT91_MCI_SDCR, 0); | ||
| 790 | } | ||
| 791 | mmc_detect_change(host->mmc, msecs_to_jiffies(100)); | ||
| 792 | } | ||
| 793 | return IRQ_HANDLED; | ||
| 794 | } | ||
| 795 | |||
| 796 | int at91_mci_get_ro(struct mmc_host *mmc) | ||
| 797 | { | ||
| 798 | int read_only = 0; | ||
| 799 | struct at91mci_host *host = mmc_priv(mmc); | ||
| 800 | |||
| 801 | if (host->board->wp_pin) { | ||
| 802 | read_only = at91_get_gpio_value(host->board->wp_pin); | ||
| 803 | printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc), | ||
| 804 | (read_only ? "read-only" : "read-write") ); | ||
| 805 | } | ||
| 806 | else { | ||
| 807 | printk(KERN_WARNING "%s: host does not support reading read-only " | ||
| 808 | "switch. Assuming write-enable.\n", mmc_hostname(mmc)); | ||
| 809 | } | ||
| 810 | return read_only; | ||
| 811 | } | ||
| 812 | |||
| 813 | static struct mmc_host_ops at91_mci_ops = { | ||
| 814 | .request = at91_mci_request, | ||
| 815 | .set_ios = at91_mci_set_ios, | ||
| 816 | .get_ro = at91_mci_get_ro, | ||
| 817 | }; | ||
| 818 | |||
| 819 | /* | ||
| 820 | * Probe for the device | ||
| 821 | */ | ||
| 822 | static int at91_mci_probe(struct platform_device *pdev) | ||
| 823 | { | ||
| 824 | struct mmc_host *mmc; | ||
| 825 | struct at91mci_host *host; | ||
| 826 | int ret; | ||
| 827 | |||
| 828 | DBG("Probe MCI devices\n"); | ||
| 829 | at91_mci_disable(); | ||
| 830 | at91_mci_enable(); | ||
| 831 | |||
| 832 | mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); | ||
| 833 | if (!mmc) { | ||
| 834 | DBG("Failed to allocate mmc host\n"); | ||
| 835 | return -ENOMEM; | ||
| 836 | } | ||
| 837 | |||
| 838 | mmc->ops = &at91_mci_ops; | ||
| 839 | mmc->f_min = 375000; | ||
| 840 | mmc->f_max = 25000000; | ||
| 841 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | ||
| 842 | |||
| 843 | host = mmc_priv(mmc); | ||
| 844 | host->mmc = mmc; | ||
| 845 | host->buffer = NULL; | ||
| 846 | host->bus_mode = 0; | ||
| 847 | host->board = pdev->dev.platform_data; | ||
| 848 | if (host->board->wire4) { | ||
| 849 | #ifdef SUPPORT_4WIRE | ||
| 850 | mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
| 851 | #else | ||
| 852 | printk("MMC: 4 wire bus mode not supported by this driver - using 1 wire\n"); | ||
| 853 | #endif | ||
| 854 | } | ||
| 855 | |||
| 856 | /* | ||
| 857 | * Get Clock | ||
| 858 | */ | ||
| 859 | mci_clk = clk_get(&pdev->dev, "mci_clk"); | ||
| 860 | if (!mci_clk) { | ||
| 861 | printk(KERN_ERR "AT91 MMC: no clock defined.\n"); | ||
| 862 | return -ENODEV; | ||
| 863 | } | ||
| 864 | clk_enable(mci_clk); /* Enable the peripheral clock */ | ||
| 865 | |||
| 866 | /* | ||
| 867 | * Allocate the MCI interrupt | ||
| 868 | */ | ||
| 869 | ret = request_irq(AT91_ID_MCI, at91_mci_irq, SA_SHIRQ, DRIVER_NAME, host); | ||
| 870 | if (ret) { | ||
| 871 | DBG("Failed to request MCI interrupt\n"); | ||
| 872 | return ret; | ||
| 873 | } | ||
| 874 | |||
| 875 | platform_set_drvdata(pdev, mmc); | ||
| 876 | |||
| 877 | /* | ||
| 878 | * Add host to MMC layer | ||
| 879 | */ | ||
| 880 | if (host->board->det_pin) | ||
| 881 | host->present = !at91_get_gpio_value(host->board->det_pin); | ||
| 882 | else | ||
| 883 | host->present = -1; | ||
| 884 | |||
| 885 | mmc_add_host(mmc); | ||
| 886 | |||
| 887 | /* | ||
| 888 | * monitor card insertion/removal if we can | ||
| 889 | */ | ||
| 890 | if (host->board->det_pin) { | ||
| 891 | ret = request_irq(host->board->det_pin, at91_mmc_det_irq, | ||
| 892 | SA_SAMPLE_RANDOM, DRIVER_NAME, host); | ||
| 893 | if (ret) | ||
| 894 | DBG("couldn't allocate MMC detect irq\n"); | ||
| 895 | } | ||
| 896 | |||
| 897 | DBG(KERN_INFO "Added MCI driver\n"); | ||
| 898 | |||
| 899 | return 0; | ||
| 900 | } | ||
| 901 | |||
| 902 | /* | ||
| 903 | * Remove a device | ||
| 904 | */ | ||
| 905 | static int at91_mci_remove(struct platform_device *pdev) | ||
| 906 | { | ||
| 907 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
| 908 | struct at91mci_host *host; | ||
| 909 | |||
| 910 | if (!mmc) | ||
| 911 | return -1; | ||
| 912 | |||
| 913 | host = mmc_priv(mmc); | ||
| 914 | |||
| 915 | if (host->present != -1) { | ||
| 916 | free_irq(host->board->det_pin, host); | ||
| 917 | cancel_delayed_work(&host->mmc->detect); | ||
| 918 | } | ||
| 919 | |||
| 920 | mmc_remove_host(mmc); | ||
| 921 | at91_mci_disable(); | ||
| 922 | free_irq(AT91_ID_MCI, host); | ||
| 923 | mmc_free_host(mmc); | ||
| 924 | |||
| 925 | clk_disable(mci_clk); /* Disable the peripheral clock */ | ||
| 926 | clk_put(mci_clk); | ||
| 927 | |||
| 928 | platform_set_drvdata(pdev, NULL); | ||
| 929 | |||
| 930 | DBG("Removed\n"); | ||
| 931 | |||
| 932 | return 0; | ||
| 933 | } | ||
| 934 | |||
| 935 | #ifdef CONFIG_PM | ||
| 936 | static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state) | ||
| 937 | { | ||
| 938 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
| 939 | int ret = 0; | ||
| 940 | |||
| 941 | if (mmc) | ||
| 942 | ret = mmc_suspend_host(mmc, state); | ||
| 943 | |||
| 944 | return ret; | ||
| 945 | } | ||
| 946 | |||
| 947 | static int at91_mci_resume(struct platform_device *pdev) | ||
| 948 | { | ||
| 949 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
| 950 | int ret = 0; | ||
| 951 | |||
| 952 | if (mmc) | ||
| 953 | ret = mmc_resume_host(mmc); | ||
| 954 | |||
| 955 | return ret; | ||
| 956 | } | ||
| 957 | #else | ||
| 958 | #define at91_mci_suspend NULL | ||
| 959 | #define at91_mci_resume NULL | ||
| 960 | #endif | ||
| 961 | |||
| 962 | static struct platform_driver at91_mci_driver = { | ||
| 963 | .probe = at91_mci_probe, | ||
| 964 | .remove = at91_mci_remove, | ||
| 965 | .suspend = at91_mci_suspend, | ||
| 966 | .resume = at91_mci_resume, | ||
| 967 | .driver = { | ||
| 968 | .name = DRIVER_NAME, | ||
| 969 | .owner = THIS_MODULE, | ||
| 970 | }, | ||
| 971 | }; | ||
| 972 | |||
| 973 | static int __init at91_mci_init(void) | ||
| 974 | { | ||
| 975 | return platform_driver_register(&at91_mci_driver); | ||
| 976 | } | ||
| 977 | |||
| 978 | static void __exit at91_mci_exit(void) | ||
| 979 | { | ||
| 980 | platform_driver_unregister(&at91_mci_driver); | ||
| 981 | } | ||
| 982 | |||
| 983 | module_init(at91_mci_init); | ||
| 984 | module_exit(at91_mci_exit); | ||
| 985 | |||
| 986 | MODULE_DESCRIPTION("AT91 Multimedia Card Interface driver"); | ||
| 987 | MODULE_AUTHOR("Nick Randell"); | ||
| 988 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c index 85e89c77bdea..c0326bbc5f28 100644 --- a/drivers/mmc/au1xmmc.c +++ b/drivers/mmc/au1xmmc.c | |||
| @@ -56,12 +56,11 @@ | |||
| 56 | #define DRIVER_NAME "au1xxx-mmc" | 56 | #define DRIVER_NAME "au1xxx-mmc" |
| 57 | 57 | ||
| 58 | /* Set this to enable special debugging macros */ | 58 | /* Set this to enable special debugging macros */ |
| 59 | /* #define MMC_DEBUG */ | ||
| 60 | 59 | ||
| 61 | #ifdef MMC_DEBUG | 60 | #ifdef DEBUG |
| 62 | #define DEBUG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args) | 61 | #define DBG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args) |
| 63 | #else | 62 | #else |
| 64 | #define DEBUG(fmt, idx, args...) | 63 | #define DBG(fmt, idx, args...) |
| 65 | #endif | 64 | #endif |
| 66 | 65 | ||
| 67 | const struct { | 66 | const struct { |
| @@ -424,18 +423,18 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host) | |||
| 424 | break; | 423 | break; |
| 425 | 424 | ||
| 426 | if (status & SD_STATUS_RC) { | 425 | if (status & SD_STATUS_RC) { |
| 427 | DEBUG("RX CRC Error [%d + %d].\n", host->id, | 426 | DBG("RX CRC Error [%d + %d].\n", host->id, |
| 428 | host->pio.len, count); | 427 | host->pio.len, count); |
| 429 | break; | 428 | break; |
| 430 | } | 429 | } |
| 431 | 430 | ||
| 432 | if (status & SD_STATUS_RO) { | 431 | if (status & SD_STATUS_RO) { |
| 433 | DEBUG("RX Overrun [%d + %d]\n", host->id, | 432 | DBG("RX Overrun [%d + %d]\n", host->id, |
| 434 | host->pio.len, count); | 433 | host->pio.len, count); |
| 435 | break; | 434 | break; |
| 436 | } | 435 | } |
| 437 | else if (status & SD_STATUS_RU) { | 436 | else if (status & SD_STATUS_RU) { |
| 438 | DEBUG("RX Underrun [%d + %d]\n", host->id, | 437 | DBG("RX Underrun [%d + %d]\n", host->id, |
| 439 | host->pio.len, count); | 438 | host->pio.len, count); |
| 440 | break; | 439 | break; |
| 441 | } | 440 | } |
| @@ -721,7 +720,7 @@ static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) | |||
| 721 | { | 720 | { |
| 722 | struct au1xmmc_host *host = mmc_priv(mmc); | 721 | struct au1xmmc_host *host = mmc_priv(mmc); |
| 723 | 722 | ||
| 724 | DEBUG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n", | 723 | DBG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n", |
| 725 | host->id, ios->power_mode, ios->clock, ios->vdd, | 724 | host->id, ios->power_mode, ios->clock, ios->vdd, |
| 726 | ios->bus_mode); | 725 | ios->bus_mode); |
| 727 | 726 | ||
| @@ -810,7 +809,7 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id, struct pt_regs *regs) | |||
| 810 | au1xmmc_receive_pio(host); | 809 | au1xmmc_receive_pio(host); |
| 811 | } | 810 | } |
| 812 | else if (status & 0x203FBC70) { | 811 | else if (status & 0x203FBC70) { |
| 813 | DEBUG("Unhandled status %8.8x\n", host->id, status); | 812 | DBG("Unhandled status %8.8x\n", host->id, status); |
| 814 | handled = 0; | 813 | handled = 0; |
| 815 | } | 814 | } |
| 816 | 815 | ||
| @@ -839,7 +838,7 @@ static void au1xmmc_poll_event(unsigned long arg) | |||
| 839 | 838 | ||
| 840 | if (host->mrq != NULL) { | 839 | if (host->mrq != NULL) { |
| 841 | u32 status = au_readl(HOST_STATUS(host)); | 840 | u32 status = au_readl(HOST_STATUS(host)); |
| 842 | DEBUG("PENDING - %8.8x\n", host->id, status); | 841 | DBG("PENDING - %8.8x\n", host->id, status); |
| 843 | } | 842 | } |
| 844 | 843 | ||
| 845 | mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT); | 844 | mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT); |
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c new file mode 100644 index 000000000000..ffb7f55d3467 --- /dev/null +++ b/drivers/mmc/imxmmc.c | |||
| @@ -0,0 +1,1096 @@ | |||
| 1 | /* | ||
| 2 | * linux/drivers/mmc/imxmmc.c - Motorola i.MX MMCI driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2004 Sascha Hauer, Pengutronix <sascha@saschahauer.de> | ||
| 5 | * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com> | ||
| 6 | * | ||
| 7 | * derived from pxamci.c by Russell King | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2 as | ||
| 11 | * published by the Free Software Foundation. | ||
| 12 | * | ||
| 13 | * 2005-04-17 Pavel Pisa <pisa@cmp.felk.cvut.cz> | ||
| 14 | * Changed to conform redesigned i.MX scatter gather DMA interface | ||
| 15 | * | ||
| 16 | * 2005-11-04 Pavel Pisa <pisa@cmp.felk.cvut.cz> | ||
| 17 | * Updated for 2.6.14 kernel | ||
| 18 | * | ||
| 19 | * 2005-12-13 Jay Monkman <jtm@smoothsmoothie.com> | ||
| 20 | * Found and corrected problems in the write path | ||
| 21 | * | ||
| 22 | * 2005-12-30 Pavel Pisa <pisa@cmp.felk.cvut.cz> | ||
| 23 | * The event handling rewritten right way in softirq. | ||
| 24 | * Added many ugly hacks and delays to overcome SDHC | ||
| 25 | * deficiencies | ||
| 26 | * | ||
| 27 | */ | ||
| 28 | #include <linux/config.h> | ||
| 29 | |||
| 30 | #ifdef CONFIG_MMC_DEBUG | ||
| 31 | #define DEBUG | ||
| 32 | #else | ||
| 33 | #undef DEBUG | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include <linux/module.h> | ||
| 37 | #include <linux/init.h> | ||
| 38 | #include <linux/ioport.h> | ||
| 39 | #include <linux/platform_device.h> | ||
| 40 | #include <linux/interrupt.h> | ||
| 41 | #include <linux/blkdev.h> | ||
| 42 | #include <linux/dma-mapping.h> | ||
| 43 | #include <linux/mmc/host.h> | ||
| 44 | #include <linux/mmc/card.h> | ||
| 45 | #include <linux/mmc/protocol.h> | ||
| 46 | #include <linux/delay.h> | ||
| 47 | |||
| 48 | #include <asm/dma.h> | ||
| 49 | #include <asm/io.h> | ||
| 50 | #include <asm/irq.h> | ||
| 51 | #include <asm/sizes.h> | ||
| 52 | #include <asm/arch/mmc.h> | ||
| 53 | #include <asm/arch/imx-dma.h> | ||
| 54 | |||
| 55 | #include "imxmmc.h" | ||
| 56 | |||
| 57 | #define DRIVER_NAME "imx-mmc" | ||
| 58 | |||
| 59 | #define IMXMCI_INT_MASK_DEFAULT (INT_MASK_BUF_READY | INT_MASK_DATA_TRAN | \ | ||
| 60 | INT_MASK_WRITE_OP_DONE | INT_MASK_END_CMD_RES | \ | ||
| 61 | INT_MASK_AUTO_CARD_DETECT | INT_MASK_DAT0_EN | INT_MASK_SDIO) | ||
| 62 | |||
| 63 | struct imxmci_host { | ||
| 64 | struct mmc_host *mmc; | ||
| 65 | spinlock_t lock; | ||
| 66 | struct resource *res; | ||
| 67 | int irq; | ||
| 68 | imx_dmach_t dma; | ||
| 69 | unsigned int clkrt; | ||
| 70 | unsigned int cmdat; | ||
| 71 | volatile unsigned int imask; | ||
| 72 | unsigned int power_mode; | ||
| 73 | unsigned int present; | ||
| 74 | struct imxmmc_platform_data *pdata; | ||
| 75 | |||
| 76 | struct mmc_request *req; | ||
| 77 | struct mmc_command *cmd; | ||
| 78 | struct mmc_data *data; | ||
| 79 | |||
| 80 | struct timer_list timer; | ||
| 81 | struct tasklet_struct tasklet; | ||
| 82 | unsigned int status_reg; | ||
| 83 | unsigned long pending_events; | ||
| 84 | /* Next to fields are there for CPU driven transfers to overcome SDHC deficiencies */ | ||
| 85 | u16 *data_ptr; | ||
| 86 | unsigned int data_cnt; | ||
| 87 | atomic_t stuck_timeout; | ||
| 88 | |||
| 89 | unsigned int dma_nents; | ||
| 90 | unsigned int dma_size; | ||
| 91 | unsigned int dma_dir; | ||
| 92 | int dma_allocated; | ||
| 93 | |||
| 94 | unsigned char actual_bus_width; | ||
| 95 | }; | ||
| 96 | |||
| 97 | #define IMXMCI_PEND_IRQ_b 0 | ||
| 98 | #define IMXMCI_PEND_DMA_END_b 1 | ||
| 99 | #define IMXMCI_PEND_DMA_ERR_b 2 | ||
| 100 | #define IMXMCI_PEND_WAIT_RESP_b 3 | ||
| 101 | #define IMXMCI_PEND_DMA_DATA_b 4 | ||
| 102 | #define IMXMCI_PEND_CPU_DATA_b 5 | ||
| 103 | #define IMXMCI_PEND_CARD_XCHG_b 6 | ||
| 104 | #define IMXMCI_PEND_SET_INIT_b 7 | ||
| 105 | |||
| 106 | #define IMXMCI_PEND_IRQ_m (1 << IMXMCI_PEND_IRQ_b) | ||
| 107 | #define IMXMCI_PEND_DMA_END_m (1 << IMXMCI_PEND_DMA_END_b) | ||
| 108 | #define IMXMCI_PEND_DMA_ERR_m (1 << IMXMCI_PEND_DMA_ERR_b) | ||
| 109 | #define IMXMCI_PEND_WAIT_RESP_m (1 << IMXMCI_PEND_WAIT_RESP_b) | ||
| 110 | #define IMXMCI_PEND_DMA_DATA_m (1 << IMXMCI_PEND_DMA_DATA_b) | ||
| 111 | #define IMXMCI_PEND_CPU_DATA_m (1 << IMXMCI_PEND_CPU_DATA_b) | ||
| 112 | #define IMXMCI_PEND_CARD_XCHG_m (1 << IMXMCI_PEND_CARD_XCHG_b) | ||
| 113 | #define IMXMCI_PEND_SET_INIT_m (1 << IMXMCI_PEND_SET_INIT_b) | ||
| 114 | |||
| 115 | static void imxmci_stop_clock(struct imxmci_host *host) | ||
| 116 | { | ||
| 117 | int i = 0; | ||
| 118 | MMC_STR_STP_CLK &= ~STR_STP_CLK_START_CLK; | ||
| 119 | while(i < 0x1000) { | ||
| 120 | if(!(i & 0x7f)) | ||
| 121 | MMC_STR_STP_CLK |= STR_STP_CLK_STOP_CLK; | ||
| 122 | |||
| 123 | if(!(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)) { | ||
| 124 | /* Check twice before cut */ | ||
| 125 | if(!(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)) | ||
| 126 | return; | ||
| 127 | } | ||
| 128 | |||
| 129 | i++; | ||
| 130 | } | ||
| 131 | dev_dbg(mmc_dev(host->mmc), "imxmci_stop_clock blocked, no luck\n"); | ||
| 132 | } | ||
| 133 | |||
| 134 | static void imxmci_start_clock(struct imxmci_host *host) | ||
| 135 | { | ||
| 136 | int i = 0; | ||
| 137 | MMC_STR_STP_CLK &= ~STR_STP_CLK_STOP_CLK; | ||
| 138 | while(i < 0x1000) { | ||
| 139 | if(!(i & 0x7f)) | ||
| 140 | MMC_STR_STP_CLK |= STR_STP_CLK_START_CLK; | ||
| 141 | |||
| 142 | if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN) { | ||
| 143 | /* Check twice before cut */ | ||
| 144 | if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN) | ||
| 145 | return; | ||
| 146 | } | ||
| 147 | |||
| 148 | i++; | ||
| 149 | } | ||
| 150 | dev_dbg(mmc_dev(host->mmc), "imxmci_start_clock blocked, no luck\n"); | ||
| 151 | } | ||
| 152 | |||
| 153 | static void imxmci_softreset(void) | ||
| 154 | { | ||
| 155 | /* reset sequence */ | ||
| 156 | MMC_STR_STP_CLK = 0x8; | ||
| 157 | MMC_STR_STP_CLK = 0xD; | ||
| 158 | MMC_STR_STP_CLK = 0x5; | ||
| 159 | MMC_STR_STP_CLK = 0x5; | ||
| 160 | MMC_STR_STP_CLK = 0x5; | ||
| 161 | MMC_STR_STP_CLK = 0x5; | ||
| 162 | MMC_STR_STP_CLK = 0x5; | ||
| 163 | MMC_STR_STP_CLK = 0x5; | ||
| 164 | MMC_STR_STP_CLK = 0x5; | ||
| 165 | MMC_STR_STP_CLK = 0x5; | ||
| 166 | |||
| 167 | MMC_RES_TO = 0xff; | ||
| 168 | MMC_BLK_LEN = 512; | ||
| 169 | MMC_NOB = 1; | ||
| 170 | } | ||
| 171 | |||
| 172 | static int imxmci_busy_wait_for_status(struct imxmci_host *host, | ||
| 173 | unsigned int *pstat, unsigned int stat_mask, | ||
| 174 | int timeout, const char *where) | ||
| 175 | { | ||
| 176 | int loops=0; | ||
| 177 | while(!(*pstat & stat_mask)) { | ||
| 178 | loops+=2; | ||
| 179 | if(loops >= timeout) { | ||
| 180 | dev_dbg(mmc_dev(host->mmc), "busy wait timeout in %s, STATUS = 0x%x (0x%x)\n", | ||
| 181 | where, *pstat, stat_mask); | ||
| 182 | return -1; | ||
| 183 | } | ||
| 184 | udelay(2); | ||
| 185 | *pstat |= MMC_STATUS; | ||
| 186 | } | ||
| 187 | if(!loops) | ||
| 188 | return 0; | ||
| 189 | |||
| 190 | dev_info(mmc_dev(host->mmc), "busy wait for %d usec in %s, STATUS = 0x%x (0x%x)\n", | ||
| 191 | loops, where, *pstat, stat_mask); | ||
| 192 | return loops; | ||
| 193 | } | ||
| 194 | |||
| 195 | static void imxmci_setup_data(struct imxmci_host *host, struct mmc_data *data) | ||
| 196 | { | ||
| 197 | unsigned int nob = data->blocks; | ||
| 198 | unsigned int blksz = 1 << data->blksz_bits; | ||
| 199 | unsigned int datasz = nob * blksz; | ||
| 200 | int i; | ||
| 201 | |||
| 202 | if (data->flags & MMC_DATA_STREAM) | ||
| 203 | nob = 0xffff; | ||
| 204 | |||
| 205 | host->data = data; | ||
| 206 | data->bytes_xfered = 0; | ||
| 207 | |||
| 208 | MMC_NOB = nob; | ||
| 209 | MMC_BLK_LEN = blksz; | ||
| 210 | |||
| 211 | /* | ||
| 212 | * DMA cannot be used for small block sizes, we have to use CPU driven transfers otherwise. | ||
| 213 | * We are in big troubles for non-512 byte transfers according to note in the paragraph | ||
| 214 | * 20.6.7 of User Manual anyway, but we need to be able to transfer SCR at least. | ||
| 215 | * The situation is even more complex in reality. The SDHC in not able to handle wll | ||
| 216 | * partial FIFO fills and reads. The length has to be rounded up to burst size multiple. | ||
| 217 | * This is required for SCR read at least. | ||
| 218 | */ | ||
| 219 | if (datasz < 64) { | ||
| 220 | host->dma_size = datasz; | ||
| 221 | if (data->flags & MMC_DATA_READ) { | ||
| 222 | host->dma_dir = DMA_FROM_DEVICE; | ||
| 223 | |||
| 224 | /* Hack to enable read SCR */ | ||
| 225 | if(datasz < 16) { | ||
| 226 | MMC_NOB = 1; | ||
| 227 | MMC_BLK_LEN = 16; | ||
| 228 | } | ||
| 229 | } else { | ||
| 230 | host->dma_dir = DMA_TO_DEVICE; | ||
| 231 | } | ||
| 232 | |||
| 233 | /* Convert back to virtual address */ | ||
| 234 | host->data_ptr = (u16*)(page_address(data->sg->page) + data->sg->offset); | ||
| 235 | host->data_cnt = 0; | ||
| 236 | |||
| 237 | clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events); | ||
| 238 | set_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events); | ||
| 239 | |||
| 240 | return; | ||
| 241 | } | ||
| 242 | |||
| 243 | if (data->flags & MMC_DATA_READ) { | ||
| 244 | host->dma_dir = DMA_FROM_DEVICE; | ||
| 245 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | ||
| 246 | data->sg_len, host->dma_dir); | ||
| 247 | |||
| 248 | imx_dma_setup_sg(host->dma, data->sg, data->sg_len, datasz, | ||
| 249 | host->res->start + MMC_BUFFER_ACCESS_OFS, DMA_MODE_READ); | ||
| 250 | |||
| 251 | /*imx_dma_setup_mem2dev_ccr(host->dma, DMA_MODE_READ, IMX_DMA_WIDTH_16, CCR_REN);*/ | ||
| 252 | CCR(host->dma) = CCR_DMOD_LINEAR | CCR_DSIZ_32 | CCR_SMOD_FIFO | CCR_SSIZ_16 | CCR_REN; | ||
| 253 | } else { | ||
| 254 | host->dma_dir = DMA_TO_DEVICE; | ||
| 255 | |||
| 256 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | ||
| 257 | data->sg_len, host->dma_dir); | ||
| 258 | |||
| 259 | imx_dma_setup_sg(host->dma, data->sg, data->sg_len, datasz, | ||
| 260 | host->res->start + MMC_BUFFER_ACCESS_OFS, DMA_MODE_WRITE); | ||
| 261 | |||
| 262 | /*imx_dma_setup_mem2dev_ccr(host->dma, DMA_MODE_WRITE, IMX_DMA_WIDTH_16, CCR_REN);*/ | ||
| 263 | CCR(host->dma) = CCR_SMOD_LINEAR | CCR_SSIZ_32 | CCR_DMOD_FIFO | CCR_DSIZ_16 | CCR_REN; | ||
| 264 | } | ||
| 265 | |||
| 266 | #if 1 /* This code is there only for consistency checking and can be disabled in future */ | ||
| 267 | host->dma_size = 0; | ||
| 268 | for(i=0; i<host->dma_nents; i++) | ||
| 269 | host->dma_size+=data->sg[i].length; | ||
| 270 | |||
| 271 | if (datasz > host->dma_size) { | ||
| 272 | dev_err(mmc_dev(host->mmc), "imxmci_setup_data datasz 0x%x > 0x%x dm_size\n", | ||
| 273 | datasz, host->dma_size); | ||
| 274 | } | ||
| 275 | #endif | ||
| 276 | |||
| 277 | host->dma_size = datasz; | ||
| 278 | |||
| 279 | wmb(); | ||
| 280 | |||
| 281 | if(host->actual_bus_width == MMC_BUS_WIDTH_4) | ||
| 282 | BLR(host->dma) = 0; /* burst 64 byte read / 64 bytes write */ | ||
| 283 | else | ||
| 284 | BLR(host->dma) = 16; /* burst 16 byte read / 16 bytes write */ | ||
| 285 | |||
| 286 | RSSR(host->dma) = DMA_REQ_SDHC; | ||
| 287 | |||
| 288 | set_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events); | ||
| 289 | clear_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events); | ||
| 290 | |||
| 291 | /* start DMA engine for read, write is delayed after initial response */ | ||
| 292 | if (host->dma_dir == DMA_FROM_DEVICE) { | ||
| 293 | imx_dma_enable(host->dma); | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | static void imxmci_start_cmd(struct imxmci_host *host, struct mmc_command *cmd, unsigned int cmdat) | ||
| 298 | { | ||
| 299 | unsigned long flags; | ||
| 300 | u32 imask; | ||
| 301 | |||
| 302 | WARN_ON(host->cmd != NULL); | ||
| 303 | host->cmd = cmd; | ||
| 304 | |||
| 305 | if (cmd->flags & MMC_RSP_BUSY) | ||
| 306 | cmdat |= CMD_DAT_CONT_BUSY; | ||
| 307 | |||
| 308 | switch (mmc_resp_type(cmd)) { | ||
| 309 | case MMC_RSP_R1: /* short CRC, OPCODE */ | ||
| 310 | case MMC_RSP_R1B:/* short CRC, OPCODE, BUSY */ | ||
| 311 | cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R1; | ||
| 312 | break; | ||
| 313 | case MMC_RSP_R2: /* long 136 bit + CRC */ | ||
| 314 | cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R2; | ||
| 315 | break; | ||
| 316 | case MMC_RSP_R3: /* short */ | ||
| 317 | cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3; | ||
| 318 | break; | ||
| 319 | case MMC_RSP_R6: /* short CRC */ | ||
| 320 | cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R6; | ||
| 321 | break; | ||
| 322 | default: | ||
| 323 | break; | ||
| 324 | } | ||
| 325 | |||
| 326 | if ( test_and_clear_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events) ) | ||
| 327 | cmdat |= CMD_DAT_CONT_INIT; /* This command needs init */ | ||
| 328 | |||
| 329 | if ( host->actual_bus_width == MMC_BUS_WIDTH_4 ) | ||
| 330 | cmdat |= CMD_DAT_CONT_BUS_WIDTH_4; | ||
| 331 | |||
| 332 | MMC_CMD = cmd->opcode; | ||
| 333 | MMC_ARGH = cmd->arg >> 16; | ||
| 334 | MMC_ARGL = cmd->arg & 0xffff; | ||
| 335 | MMC_CMD_DAT_CONT = cmdat; | ||
| 336 | |||
| 337 | atomic_set(&host->stuck_timeout, 0); | ||
| 338 | set_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events); | ||
| 339 | |||
| 340 | |||
| 341 | imask = IMXMCI_INT_MASK_DEFAULT; | ||
| 342 | imask &= ~INT_MASK_END_CMD_RES; | ||
| 343 | if ( cmdat & CMD_DAT_CONT_DATA_ENABLE ) { | ||
| 344 | /*imask &= ~INT_MASK_BUF_READY;*/ | ||
| 345 | imask &= ~INT_MASK_DATA_TRAN; | ||
| 346 | if ( cmdat & CMD_DAT_CONT_WRITE ) | ||
| 347 | imask &= ~INT_MASK_WRITE_OP_DONE; | ||
| 348 | if(test_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events)) | ||
| 349 | imask &= ~INT_MASK_BUF_READY; | ||
| 350 | } | ||
| 351 | |||
| 352 | spin_lock_irqsave(&host->lock, flags); | ||
| 353 | host->imask = imask; | ||
| 354 | MMC_INT_MASK = host->imask; | ||
| 355 | spin_unlock_irqrestore(&host->lock, flags); | ||
| 356 | |||
| 357 | dev_dbg(mmc_dev(host->mmc), "CMD%02d (0x%02x) mask set to 0x%04x\n", | ||
| 358 | cmd->opcode, cmd->opcode, imask); | ||
| 359 | |||
| 360 | imxmci_start_clock(host); | ||
| 361 | } | ||
| 362 | |||
| 363 | static void imxmci_finish_request(struct imxmci_host *host, struct mmc_request *req) | ||
| 364 | { | ||
| 365 | unsigned long flags; | ||
| 366 | |||
| 367 | spin_lock_irqsave(&host->lock, flags); | ||
| 368 | |||
| 369 | host->pending_events &= ~(IMXMCI_PEND_WAIT_RESP_m | IMXMCI_PEND_DMA_END_m | | ||
| 370 | IMXMCI_PEND_DMA_DATA_m | IMXMCI_PEND_CPU_DATA_m); | ||
| 371 | |||
| 372 | host->imask = IMXMCI_INT_MASK_DEFAULT; | ||
| 373 | MMC_INT_MASK = host->imask; | ||
| 374 | |||
| 375 | spin_unlock_irqrestore(&host->lock, flags); | ||
| 376 | |||
| 377 | host->req = NULL; | ||
| 378 | host->cmd = NULL; | ||
| 379 | host->data = NULL; | ||
| 380 | mmc_request_done(host->mmc, req); | ||
| 381 | } | ||
| 382 | |||
| 383 | static int imxmci_finish_data(struct imxmci_host *host, unsigned int stat) | ||
| 384 | { | ||
| 385 | struct mmc_data *data = host->data; | ||
| 386 | int data_error; | ||
| 387 | |||
| 388 | if(test_and_clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)){ | ||
| 389 | imx_dma_disable(host->dma); | ||
| 390 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_nents, | ||
| 391 | host->dma_dir); | ||
| 392 | } | ||
| 393 | |||
| 394 | if ( stat & STATUS_ERR_MASK ) { | ||
| 395 | dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",stat); | ||
| 396 | if(stat & (STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR)) | ||
| 397 | data->error = MMC_ERR_BADCRC; | ||
| 398 | else if(stat & STATUS_TIME_OUT_READ) | ||
| 399 | data->error = MMC_ERR_TIMEOUT; | ||
| 400 | else | ||
| 401 | data->error = MMC_ERR_FAILED; | ||
| 402 | } else { | ||
| 403 | data->bytes_xfered = host->dma_size; | ||
| 404 | } | ||
| 405 | |||
| 406 | data_error = data->error; | ||
| 407 | |||
| 408 | host->data = NULL; | ||
| 409 | |||
| 410 | return data_error; | ||
| 411 | } | ||
| 412 | |||
| 413 | static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat) | ||
| 414 | { | ||
| 415 | struct mmc_command *cmd = host->cmd; | ||
| 416 | int i; | ||
| 417 | u32 a,b,c; | ||
| 418 | struct mmc_data *data = host->data; | ||
| 419 | |||
| 420 | if (!cmd) | ||
| 421 | return 0; | ||
| 422 | |||
| 423 | host->cmd = NULL; | ||
| 424 | |||
| 425 | if (stat & STATUS_TIME_OUT_RESP) { | ||
| 426 | dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n"); | ||
| 427 | cmd->error = MMC_ERR_TIMEOUT; | ||
| 428 | } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) { | ||
| 429 | dev_dbg(mmc_dev(host->mmc), "cmd crc error\n"); | ||
| 430 | cmd->error = MMC_ERR_BADCRC; | ||
| 431 | } | ||
| 432 | |||
| 433 | if(cmd->flags & MMC_RSP_PRESENT) { | ||
| 434 | if(cmd->flags & MMC_RSP_136) { | ||
| 435 | for (i = 0; i < 4; i++) { | ||
| 436 | u32 a = MMC_RES_FIFO & 0xffff; | ||
| 437 | u32 b = MMC_RES_FIFO & 0xffff; | ||
| 438 | cmd->resp[i] = a<<16 | b; | ||
| 439 | } | ||
| 440 | } else { | ||
| 441 | a = MMC_RES_FIFO & 0xffff; | ||
| 442 | b = MMC_RES_FIFO & 0xffff; | ||
| 443 | c = MMC_RES_FIFO & 0xffff; | ||
| 444 | cmd->resp[0] = a<<24 | b<<8 | c>>8; | ||
| 445 | } | ||
| 446 | } | ||
| 447 | |||
| 448 | dev_dbg(mmc_dev(host->mmc), "RESP 0x%08x, 0x%08x, 0x%08x, 0x%08x, error %d\n", | ||
| 449 | cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error); | ||
| 450 | |||
| 451 | if (data && (cmd->error == MMC_ERR_NONE) && !(stat & STATUS_ERR_MASK)) { | ||
| 452 | if (host->req->data->flags & MMC_DATA_WRITE) { | ||
| 453 | |||
| 454 | /* Wait for FIFO to be empty before starting DMA write */ | ||
| 455 | |||
| 456 | stat = MMC_STATUS; | ||
| 457 | if(imxmci_busy_wait_for_status(host, &stat, | ||
| 458 | STATUS_APPL_BUFF_FE, | ||
| 459 | 40, "imxmci_cmd_done DMA WR") < 0) { | ||
| 460 | cmd->error = MMC_ERR_FIFO; | ||
| 461 | imxmci_finish_data(host, stat); | ||
| 462 | if(host->req) | ||
| 463 | imxmci_finish_request(host, host->req); | ||
| 464 | dev_warn(mmc_dev(host->mmc), "STATUS = 0x%04x\n", | ||
| 465 | stat); | ||
| 466 | return 0; | ||
| 467 | } | ||
| 468 | |||
| 469 | if(test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) { | ||
| 470 | imx_dma_enable(host->dma); | ||
| 471 | } | ||
| 472 | } | ||
| 473 | } else { | ||
| 474 | struct mmc_request *req; | ||
| 475 | imxmci_stop_clock(host); | ||
| 476 | req = host->req; | ||
| 477 | |||
| 478 | if(data) | ||
| 479 | imxmci_finish_data(host, stat); | ||
| 480 | |||
| 481 | if( req ) { | ||
| 482 | imxmci_finish_request(host, req); | ||
| 483 | } else { | ||
| 484 | dev_warn(mmc_dev(host->mmc), "imxmci_cmd_done: no request to finish\n"); | ||
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 | return 1; | ||
| 489 | } | ||
| 490 | |||
| 491 | static int imxmci_data_done(struct imxmci_host *host, unsigned int stat) | ||
| 492 | { | ||
| 493 | struct mmc_data *data = host->data; | ||
| 494 | int data_error; | ||
| 495 | |||
| 496 | if (!data) | ||
| 497 | return 0; | ||
| 498 | |||
| 499 | data_error = imxmci_finish_data(host, stat); | ||
| 500 | |||
| 501 | if (host->req->stop && (data_error == MMC_ERR_NONE)) { | ||
| 502 | imxmci_stop_clock(host); | ||
| 503 | imxmci_start_cmd(host, host->req->stop, 0); | ||
| 504 | } else { | ||
| 505 | struct mmc_request *req; | ||
| 506 | req = host->req; | ||
| 507 | if( req ) { | ||
| 508 | imxmci_finish_request(host, req); | ||
| 509 | } else { | ||
| 510 | dev_warn(mmc_dev(host->mmc), "imxmci_data_done: no request to finish\n"); | ||
| 511 | } | ||
| 512 | } | ||
| 513 | |||
| 514 | return 1; | ||
| 515 | } | ||
| 516 | |||
| 517 | static int imxmci_cpu_driven_data(struct imxmci_host *host, unsigned int *pstat) | ||
| 518 | { | ||
| 519 | int i; | ||
| 520 | int burst_len; | ||
| 521 | int flush_len; | ||
| 522 | int trans_done = 0; | ||
| 523 | unsigned int stat = *pstat; | ||
| 524 | |||
| 525 | if(host->actual_bus_width == MMC_BUS_WIDTH_4) | ||
| 526 | burst_len = 16; | ||
| 527 | else | ||
| 528 | burst_len = 64; | ||
| 529 | |||
| 530 | /* This is unfortunately required */ | ||
| 531 | dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data running STATUS = 0x%x\n", | ||
| 532 | stat); | ||
| 533 | |||
| 534 | if(host->dma_dir == DMA_FROM_DEVICE) { | ||
| 535 | imxmci_busy_wait_for_status(host, &stat, | ||
| 536 | STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE, | ||
| 537 | 20, "imxmci_cpu_driven_data read"); | ||
| 538 | |||
| 539 | while((stat & (STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE)) && | ||
| 540 | (host->data_cnt < host->dma_size)) { | ||
| 541 | if(burst_len >= host->dma_size - host->data_cnt) { | ||
| 542 | flush_len = burst_len; | ||
| 543 | burst_len = host->dma_size - host->data_cnt; | ||
| 544 | flush_len -= burst_len; | ||
| 545 | host->data_cnt = host->dma_size; | ||
| 546 | trans_done = 1; | ||
| 547 | } else { | ||
| 548 | flush_len = 0; | ||
| 549 | host->data_cnt += burst_len; | ||
| 550 | } | ||
| 551 | |||
| 552 | for(i = burst_len; i>=2 ; i-=2) { | ||
| 553 | *(host->data_ptr++) = MMC_BUFFER_ACCESS; | ||
| 554 | udelay(20); /* required for clocks < 8MHz*/ | ||
| 555 | } | ||
| 556 | |||
| 557 | if(i == 1) | ||
| 558 | *(u8*)(host->data_ptr) = MMC_BUFFER_ACCESS; | ||
| 559 | |||
| 560 | stat = MMC_STATUS; | ||
| 561 | |||
| 562 | /* Flush extra bytes from FIFO */ | ||
| 563 | while(flush_len >= 2){ | ||
| 564 | flush_len -= 2; | ||
| 565 | i = MMC_BUFFER_ACCESS; | ||
| 566 | stat = MMC_STATUS; | ||
| 567 | stat &= ~STATUS_CRC_READ_ERR; /* Stupid but required there */ | ||
| 568 | } | ||
| 569 | |||
| 570 | dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data read burst %d STATUS = 0x%x\n", | ||
| 571 | burst_len, stat); | ||
| 572 | } | ||
| 573 | } else { | ||
| 574 | imxmci_busy_wait_for_status(host, &stat, | ||
| 575 | STATUS_APPL_BUFF_FE, | ||
| 576 | 20, "imxmci_cpu_driven_data write"); | ||
| 577 | |||
| 578 | while((stat & STATUS_APPL_BUFF_FE) && | ||
| 579 | (host->data_cnt < host->dma_size)) { | ||
| 580 | if(burst_len >= host->dma_size - host->data_cnt) { | ||
| 581 | burst_len = host->dma_size - host->data_cnt; | ||
| 582 | host->data_cnt = host->dma_size; | ||
| 583 | trans_done = 1; | ||
| 584 | } else { | ||
| 585 | host->data_cnt += burst_len; | ||
| 586 | } | ||
| 587 | |||
| 588 | for(i = burst_len; i>0 ; i-=2) | ||
| 589 | MMC_BUFFER_ACCESS = *(host->data_ptr++); | ||
| 590 | |||
| 591 | stat = MMC_STATUS; | ||
| 592 | |||
| 593 | dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data write burst %d STATUS = 0x%x\n", | ||
| 594 | burst_len, stat); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 598 | *pstat = stat; | ||
| 599 | |||
| 600 | return trans_done; | ||
| 601 | } | ||
| 602 | |||
| 603 | static void imxmci_dma_irq(int dma, void *devid, struct pt_regs *regs) | ||
| 604 | { | ||
| 605 | struct imxmci_host *host = devid; | ||
| 606 | uint32_t stat = MMC_STATUS; | ||
| 607 | |||
| 608 | atomic_set(&host->stuck_timeout, 0); | ||
| 609 | host->status_reg = stat; | ||
| 610 | set_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events); | ||
| 611 | tasklet_schedule(&host->tasklet); | ||
| 612 | } | ||
| 613 | |||
| 614 | static irqreturn_t imxmci_irq(int irq, void *devid, struct pt_regs *regs) | ||
| 615 | { | ||
| 616 | struct imxmci_host *host = devid; | ||
| 617 | uint32_t stat = MMC_STATUS; | ||
| 618 | int handled = 1; | ||
| 619 | |||
| 620 | MMC_INT_MASK = host->imask | INT_MASK_SDIO | INT_MASK_AUTO_CARD_DETECT; | ||
| 621 | |||
| 622 | atomic_set(&host->stuck_timeout, 0); | ||
| 623 | host->status_reg = stat; | ||
| 624 | set_bit(IMXMCI_PEND_IRQ_b, &host->pending_events); | ||
| 625 | tasklet_schedule(&host->tasklet); | ||
| 626 | |||
| 627 | return IRQ_RETVAL(handled);; | ||
| 628 | } | ||
| 629 | |||
| 630 | static void imxmci_tasklet_fnc(unsigned long data) | ||
| 631 | { | ||
| 632 | struct imxmci_host *host = (struct imxmci_host *)data; | ||
| 633 | u32 stat; | ||
| 634 | unsigned int data_dir_mask = 0; /* STATUS_WR_CRC_ERROR_CODE_MASK */ | ||
| 635 | int timeout = 0; | ||
| 636 | |||
| 637 | if(atomic_read(&host->stuck_timeout) > 4) { | ||
| 638 | char *what; | ||
| 639 | timeout = 1; | ||
| 640 | stat = MMC_STATUS; | ||
| 641 | host->status_reg = stat; | ||
| 642 | if (test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) | ||
| 643 | if (test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) | ||
| 644 | what = "RESP+DMA"; | ||
| 645 | else | ||
| 646 | what = "RESP"; | ||
| 647 | else | ||
| 648 | if (test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) | ||
| 649 | if(test_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events)) | ||
| 650 | what = "DATA"; | ||
| 651 | else | ||
| 652 | what = "DMA"; | ||
| 653 | else | ||
| 654 | what = "???"; | ||
| 655 | |||
| 656 | dev_err(mmc_dev(host->mmc), "%s TIMEOUT, hardware stucked STATUS = 0x%04x IMASK = 0x%04x\n", | ||
| 657 | what, stat, MMC_INT_MASK); | ||
| 658 | dev_err(mmc_dev(host->mmc), "CMD_DAT_CONT = 0x%04x, MMC_BLK_LEN = 0x%04x, MMC_NOB = 0x%04x, DMA_CCR = 0x%08x\n", | ||
| 659 | MMC_CMD_DAT_CONT, MMC_BLK_LEN, MMC_NOB, CCR(host->dma)); | ||
| 660 | dev_err(mmc_dev(host->mmc), "CMD%d, bus %d-bit, dma_size = 0x%x\n", | ||
| 661 | host->cmd?host->cmd->opcode:0, 1<<host->actual_bus_width, host->dma_size); | ||
| 662 | } | ||
| 663 | |||
| 664 | if(!host->present || timeout) | ||
| 665 | host->status_reg = STATUS_TIME_OUT_RESP | STATUS_TIME_OUT_READ | | ||
| 666 | STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR; | ||
| 667 | |||
| 668 | if(test_bit(IMXMCI_PEND_IRQ_b, &host->pending_events) || timeout) { | ||
| 669 | clear_bit(IMXMCI_PEND_IRQ_b, &host->pending_events); | ||
| 670 | |||
| 671 | stat = MMC_STATUS; | ||
| 672 | /* | ||
| 673 | * This is not required in theory, but there is chance to miss some flag | ||
| 674 | * which clears automatically by mask write, FreeScale original code keeps | ||
| 675 | * stat from IRQ time so do I | ||
| 676 | */ | ||
| 677 | stat |= host->status_reg; | ||
| 678 | |||
| 679 | if(test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) { | ||
| 680 | imxmci_busy_wait_for_status(host, &stat, | ||
| 681 | STATUS_END_CMD_RESP | STATUS_ERR_MASK, | ||
| 682 | 20, "imxmci_tasklet_fnc resp (ERRATUM #4)"); | ||
| 683 | } | ||
| 684 | |||
| 685 | if(stat & (STATUS_END_CMD_RESP | STATUS_ERR_MASK)) { | ||
| 686 | if(test_and_clear_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) | ||
| 687 | imxmci_cmd_done(host, stat); | ||
| 688 | if(host->data && (stat & STATUS_ERR_MASK)) | ||
| 689 | imxmci_data_done(host, stat); | ||
| 690 | } | ||
| 691 | |||
| 692 | if(test_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events)) { | ||
| 693 | stat |= MMC_STATUS; | ||
| 694 | if(imxmci_cpu_driven_data(host, &stat)){ | ||
| 695 | if(test_and_clear_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) | ||
| 696 | imxmci_cmd_done(host, stat); | ||
| 697 | atomic_clear_mask(IMXMCI_PEND_IRQ_m|IMXMCI_PEND_CPU_DATA_m, | ||
| 698 | &host->pending_events); | ||
| 699 | imxmci_data_done(host, stat); | ||
| 700 | } | ||
| 701 | } | ||
| 702 | } | ||
| 703 | |||
| 704 | if(test_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events) && | ||
| 705 | !test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) { | ||
| 706 | |||
| 707 | stat = MMC_STATUS; | ||
| 708 | /* Same as above */ | ||
| 709 | stat |= host->status_reg; | ||
| 710 | |||
| 711 | if(host->dma_dir == DMA_TO_DEVICE) { | ||
| 712 | data_dir_mask = STATUS_WRITE_OP_DONE; | ||
| 713 | } else { | ||
| 714 | data_dir_mask = STATUS_DATA_TRANS_DONE; | ||
| 715 | } | ||
| 716 | |||
| 717 | imxmci_busy_wait_for_status(host, &stat, | ||
| 718 | data_dir_mask, | ||
| 719 | 50, "imxmci_tasklet_fnc data"); | ||
| 720 | |||
| 721 | if(stat & data_dir_mask) { | ||
| 722 | clear_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events); | ||
| 723 | imxmci_data_done(host, stat); | ||
| 724 | } | ||
| 725 | } | ||
| 726 | |||
| 727 | if(test_and_clear_bit(IMXMCI_PEND_CARD_XCHG_b, &host->pending_events)) { | ||
| 728 | |||
| 729 | if(host->cmd) | ||
| 730 | imxmci_cmd_done(host, STATUS_TIME_OUT_RESP); | ||
| 731 | |||
| 732 | if(host->data) | ||
| 733 | imxmci_data_done(host, STATUS_TIME_OUT_READ | | ||
| 734 | STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR); | ||
| 735 | |||
| 736 | if(host->req) | ||
| 737 | imxmci_finish_request(host, host->req); | ||
| 738 | |||
| 739 | mmc_detect_change(host->mmc, msecs_to_jiffies(100)); | ||
| 740 | |||
| 741 | } | ||
| 742 | } | ||
| 743 | |||
| 744 | static void imxmci_request(struct mmc_host *mmc, struct mmc_request *req) | ||
| 745 | { | ||
| 746 | struct imxmci_host *host = mmc_priv(mmc); | ||
| 747 | unsigned int cmdat; | ||
| 748 | |||
| 749 | WARN_ON(host->req != NULL); | ||
| 750 | |||
| 751 | host->req = req; | ||
| 752 | |||
| 753 | cmdat = 0; | ||
| 754 | |||
| 755 | if (req->data) { | ||
| 756 | imxmci_setup_data(host, req->data); | ||
| 757 | |||
| 758 | cmdat |= CMD_DAT_CONT_DATA_ENABLE; | ||
| 759 | |||
| 760 | if (req->data->flags & MMC_DATA_WRITE) | ||
| 761 | cmdat |= CMD_DAT_CONT_WRITE; | ||
| 762 | |||
| 763 | if (req->data->flags & MMC_DATA_STREAM) { | ||
| 764 | cmdat |= CMD_DAT_CONT_STREAM_BLOCK; | ||
| 765 | } | ||
| 766 | } | ||
| 767 | |||
| 768 | imxmci_start_cmd(host, req->cmd, cmdat); | ||
| 769 | } | ||
| 770 | |||
| 771 | #define CLK_RATE 19200000 | ||
| 772 | |||
| 773 | static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
| 774 | { | ||
| 775 | struct imxmci_host *host = mmc_priv(mmc); | ||
| 776 | int prescaler; | ||
| 777 | |||
| 778 | dev_dbg(mmc_dev(host->mmc), "clock %u power %u vdd %u width %u\n", | ||
| 779 | ios->clock, ios->power_mode, ios->vdd, | ||
| 780 | (ios->bus_width==MMC_BUS_WIDTH_4)?4:1); | ||
| 781 | |||
| 782 | if( ios->bus_width==MMC_BUS_WIDTH_4 ) { | ||
| 783 | host->actual_bus_width = MMC_BUS_WIDTH_4; | ||
| 784 | imx_gpio_mode(PB11_PF_SD_DAT3); | ||
| 785 | }else{ | ||
| 786 | host->actual_bus_width = MMC_BUS_WIDTH_1; | ||
| 787 | imx_gpio_mode(GPIO_PORTB | GPIO_IN | GPIO_PUEN | 11); | ||
| 788 | } | ||
| 789 | |||
| 790 | if ( host->power_mode != ios->power_mode ) { | ||
| 791 | switch (ios->power_mode) { | ||
| 792 | case MMC_POWER_OFF: | ||
| 793 | break; | ||
| 794 | case MMC_POWER_UP: | ||
| 795 | set_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events); | ||
| 796 | break; | ||
| 797 | case MMC_POWER_ON: | ||
| 798 | break; | ||
| 799 | } | ||
| 800 | host->power_mode = ios->power_mode; | ||
| 801 | } | ||
| 802 | |||
| 803 | if ( ios->clock ) { | ||
| 804 | unsigned int clk; | ||
| 805 | |||
| 806 | /* The prescaler is 5 for PERCLK2 equal to 96MHz | ||
| 807 | * then 96MHz / 5 = 19.2 MHz | ||
| 808 | */ | ||
| 809 | clk=imx_get_perclk2(); | ||
| 810 | prescaler=(clk+(CLK_RATE*7)/8)/CLK_RATE; | ||
| 811 | switch(prescaler) { | ||
| 812 | case 0: | ||
| 813 | case 1: prescaler = 0; | ||
| 814 | break; | ||
| 815 | case 2: prescaler = 1; | ||
| 816 | break; | ||
| 817 | case 3: prescaler = 2; | ||
| 818 | break; | ||
| 819 | case 4: prescaler = 4; | ||
| 820 | break; | ||
| 821 | default: | ||
| 822 | case 5: prescaler = 5; | ||
| 823 | break; | ||
| 824 | } | ||
| 825 | |||
| 826 | dev_dbg(mmc_dev(host->mmc), "PERCLK2 %d MHz -> prescaler %d\n", | ||
| 827 | clk, prescaler); | ||
| 828 | |||
| 829 | for(clk=0; clk<8; clk++) { | ||
| 830 | int x; | ||
| 831 | x = CLK_RATE / (1<<clk); | ||
| 832 | if( x <= ios->clock) | ||
| 833 | break; | ||
| 834 | } | ||
| 835 | |||
| 836 | MMC_STR_STP_CLK |= STR_STP_CLK_ENABLE; /* enable controller */ | ||
| 837 | |||
| 838 | imxmci_stop_clock(host); | ||
| 839 | MMC_CLK_RATE = (prescaler<<3) | clk; | ||
| 840 | imxmci_start_clock(host); | ||
| 841 | |||
| 842 | dev_dbg(mmc_dev(host->mmc), "MMC_CLK_RATE: 0x%08x\n", MMC_CLK_RATE); | ||
| 843 | } else { | ||
| 844 | imxmci_stop_clock(host); | ||
| 845 | } | ||
| 846 | } | ||
| 847 | |||
| 848 | static struct mmc_host_ops imxmci_ops = { | ||
| 849 | .request = imxmci_request, | ||
| 850 | .set_ios = imxmci_set_ios, | ||
| 851 | }; | ||
| 852 | |||
| 853 | static struct resource *platform_device_resource(struct platform_device *dev, unsigned int mask, int nr) | ||
| 854 | { | ||
| 855 | int i; | ||
| 856 | |||
| 857 | for (i = 0; i < dev->num_resources; i++) | ||
| 858 | if (dev->resource[i].flags == mask && nr-- == 0) | ||
| 859 | return &dev->resource[i]; | ||
| 860 | return NULL; | ||
| 861 | } | ||
| 862 | |||
| 863 | static int platform_device_irq(struct platform_device *dev, int nr) | ||
| 864 | { | ||
| 865 | int i; | ||
| 866 | |||
| 867 | for (i = 0; i < dev->num_resources; i++) | ||
| 868 | if (dev->resource[i].flags == IORESOURCE_IRQ && nr-- == 0) | ||
| 869 | return dev->resource[i].start; | ||
| 870 | return NO_IRQ; | ||
| 871 | } | ||
| 872 | |||
| 873 | static void imxmci_check_status(unsigned long data) | ||
| 874 | { | ||
| 875 | struct imxmci_host *host = (struct imxmci_host *)data; | ||
| 876 | |||
| 877 | if( host->pdata->card_present() != host->present ) { | ||
| 878 | host->present ^= 1; | ||
| 879 | dev_info(mmc_dev(host->mmc), "card %s\n", | ||
| 880 | host->present ? "inserted" : "removed"); | ||
| 881 | |||
| 882 | set_bit(IMXMCI_PEND_CARD_XCHG_b, &host->pending_events); | ||
| 883 | tasklet_schedule(&host->tasklet); | ||
| 884 | } | ||
| 885 | |||
| 886 | if(test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events) || | ||
| 887 | test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) { | ||
| 888 | atomic_inc(&host->stuck_timeout); | ||
| 889 | if(atomic_read(&host->stuck_timeout) > 4) | ||
| 890 | tasklet_schedule(&host->tasklet); | ||
| 891 | } else { | ||
| 892 | atomic_set(&host->stuck_timeout, 0); | ||
| 893 | |||
| 894 | } | ||
| 895 | |||
| 896 | mod_timer(&host->timer, jiffies + (HZ>>1)); | ||
| 897 | } | ||
| 898 | |||
| 899 | static int imxmci_probe(struct platform_device *pdev) | ||
| 900 | { | ||
| 901 | struct mmc_host *mmc; | ||
| 902 | struct imxmci_host *host = NULL; | ||
| 903 | struct resource *r; | ||
| 904 | int ret = 0, irq; | ||
| 905 | |||
| 906 | printk(KERN_INFO "i.MX mmc driver\n"); | ||
| 907 | |||
| 908 | r = platform_device_resource(pdev, IORESOURCE_MEM, 0); | ||
| 909 | irq = platform_device_irq(pdev, 0); | ||
| 910 | if (!r || irq == NO_IRQ) | ||
| 911 | return -ENXIO; | ||
| 912 | |||
| 913 | r = request_mem_region(r->start, 0x100, "IMXMCI"); | ||
| 914 | if (!r) | ||
| 915 | return -EBUSY; | ||
| 916 | |||
| 917 | mmc = mmc_alloc_host(sizeof(struct imxmci_host), &pdev->dev); | ||
| 918 | if (!mmc) { | ||
| 919 | ret = -ENOMEM; | ||
| 920 | goto out; | ||
| 921 | } | ||
| 922 | |||
| 923 | mmc->ops = &imxmci_ops; | ||
| 924 | mmc->f_min = 150000; | ||
| 925 | mmc->f_max = CLK_RATE/2; | ||
| 926 | mmc->ocr_avail = MMC_VDD_32_33; | ||
| 927 | mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
| 928 | |||
| 929 | /* MMC core transfer sizes tunable parameters */ | ||
| 930 | mmc->max_hw_segs = 64; | ||
| 931 | mmc->max_phys_segs = 64; | ||
| 932 | mmc->max_sectors = 64; /* default 1 << (PAGE_CACHE_SHIFT - 9) */ | ||
| 933 | mmc->max_seg_size = 64*512; /* default PAGE_CACHE_SIZE */ | ||
| 934 | |||
| 935 | host = mmc_priv(mmc); | ||
| 936 | host->mmc = mmc; | ||
| 937 | host->dma_allocated = 0; | ||
| 938 | host->pdata = pdev->dev.platform_data; | ||
| 939 | |||
| 940 | spin_lock_init(&host->lock); | ||
| 941 | host->res = r; | ||
| 942 | host->irq = irq; | ||
| 943 | |||
| 944 | imx_gpio_mode(PB8_PF_SD_DAT0); | ||
| 945 | imx_gpio_mode(PB9_PF_SD_DAT1); | ||
| 946 | imx_gpio_mode(PB10_PF_SD_DAT2); | ||
| 947 | /* Configured as GPIO with pull-up to ensure right MCC card mode */ | ||
| 948 | /* Switched to PB11_PF_SD_DAT3 if 4 bit bus is configured */ | ||
| 949 | imx_gpio_mode(GPIO_PORTB | GPIO_IN | GPIO_PUEN | 11); | ||
| 950 | /* imx_gpio_mode(PB11_PF_SD_DAT3); */ | ||
| 951 | imx_gpio_mode(PB12_PF_SD_CLK); | ||
| 952 | imx_gpio_mode(PB13_PF_SD_CMD); | ||
| 953 | |||
| 954 | imxmci_softreset(); | ||
| 955 | |||
| 956 | if ( MMC_REV_NO != 0x390 ) { | ||
| 957 | dev_err(mmc_dev(host->mmc), "wrong rev.no. 0x%08x. aborting.\n", | ||
| 958 | MMC_REV_NO); | ||
| 959 | goto out; | ||
| 960 | } | ||
| 961 | |||
| 962 | MMC_READ_TO = 0x2db4; /* recommended in data sheet */ | ||
| 963 | |||
| 964 | host->imask = IMXMCI_INT_MASK_DEFAULT; | ||
| 965 | MMC_INT_MASK = host->imask; | ||
| 966 | |||
| 967 | |||
| 968 | if(imx_dma_request_by_prio(&host->dma, DRIVER_NAME, DMA_PRIO_LOW)<0){ | ||
| 969 | dev_err(mmc_dev(host->mmc), "imx_dma_request_by_prio failed\n"); | ||
| 970 | ret = -EBUSY; | ||
| 971 | goto out; | ||
| 972 | } | ||
| 973 | host->dma_allocated=1; | ||
| 974 | imx_dma_setup_handlers(host->dma, imxmci_dma_irq, NULL, host); | ||
| 975 | |||
| 976 | tasklet_init(&host->tasklet, imxmci_tasklet_fnc, (unsigned long)host); | ||
| 977 | host->status_reg=0; | ||
| 978 | host->pending_events=0; | ||
| 979 | |||
| 980 | ret = request_irq(host->irq, imxmci_irq, 0, DRIVER_NAME, host); | ||
| 981 | if (ret) | ||
| 982 | goto out; | ||
| 983 | |||
| 984 | host->present = host->pdata->card_present(); | ||
| 985 | init_timer(&host->timer); | ||
| 986 | host->timer.data = (unsigned long)host; | ||
| 987 | host->timer.function = imxmci_check_status; | ||
| 988 | add_timer(&host->timer); | ||
| 989 | mod_timer(&host->timer, jiffies + (HZ>>1)); | ||
| 990 | |||
| 991 | platform_set_drvdata(pdev, mmc); | ||
| 992 | |||
| 993 | mmc_add_host(mmc); | ||
| 994 | |||
| 995 | return 0; | ||
| 996 | |||
| 997 | out: | ||
| 998 | if (host) { | ||
| 999 | if(host->dma_allocated){ | ||
| 1000 | imx_dma_free(host->dma); | ||
| 1001 | host->dma_allocated=0; | ||
| 1002 | } | ||
| 1003 | } | ||
| 1004 | if (mmc) | ||
| 1005 | mmc_free_host(mmc); | ||
| 1006 | release_resource(r); | ||
| 1007 | return ret; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | static int imxmci_remove(struct platform_device *pdev) | ||
| 1011 | { | ||
| 1012 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
| 1013 | |||
| 1014 | platform_set_drvdata(pdev, NULL); | ||
| 1015 | |||
| 1016 | if (mmc) { | ||
| 1017 | struct imxmci_host *host = mmc_priv(mmc); | ||
| 1018 | |||
| 1019 | tasklet_disable(&host->tasklet); | ||
| 1020 | |||
| 1021 | del_timer_sync(&host->timer); | ||
| 1022 | mmc_remove_host(mmc); | ||
| 1023 | |||
| 1024 | free_irq(host->irq, host); | ||
| 1025 | if(host->dma_allocated){ | ||
| 1026 | imx_dma_free(host->dma); | ||
| 1027 | host->dma_allocated=0; | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | tasklet_kill(&host->tasklet); | ||
| 1031 | |||
| 1032 | release_resource(host->res); | ||
| 1033 | |||
| 1034 | mmc_free_host(mmc); | ||
| 1035 | } | ||
| 1036 | return 0; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | #ifdef CONFIG_PM | ||
| 1040 | static int imxmci_suspend(struct platform_device *dev, pm_message_t state) | ||
| 1041 | { | ||
| 1042 | struct mmc_host *mmc = platform_get_drvdata(dev); | ||
| 1043 | int ret = 0; | ||
| 1044 | |||
| 1045 | if (mmc) | ||
| 1046 | ret = mmc_suspend_host(mmc, state); | ||
| 1047 | |||
| 1048 | return ret; | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | static int imxmci_resume(struct platform_device *dev) | ||
| 1052 | { | ||
| 1053 | struct mmc_host *mmc = platform_get_drvdata(dev); | ||
| 1054 | struct imxmci_host *host; | ||
| 1055 | int ret = 0; | ||
| 1056 | |||
| 1057 | if (mmc) { | ||
| 1058 | host = mmc_priv(mmc); | ||
| 1059 | if(host) | ||
| 1060 | set_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events); | ||
| 1061 | ret = mmc_resume_host(mmc); | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | return ret; | ||
| 1065 | } | ||
| 1066 | #else | ||
| 1067 | #define imxmci_suspend NULL | ||
| 1068 | #define imxmci_resume NULL | ||
| 1069 | #endif /* CONFIG_PM */ | ||
| 1070 | |||
| 1071 | static struct platform_driver imxmci_driver = { | ||
| 1072 | .probe = imxmci_probe, | ||
| 1073 | .remove = imxmci_remove, | ||
| 1074 | .suspend = imxmci_suspend, | ||
| 1075 | .resume = imxmci_resume, | ||
| 1076 | .driver = { | ||
| 1077 | .name = DRIVER_NAME, | ||
| 1078 | } | ||
| 1079 | }; | ||
| 1080 | |||
| 1081 | static int __init imxmci_init(void) | ||
| 1082 | { | ||
| 1083 | return platform_driver_register(&imxmci_driver); | ||
| 1084 | } | ||
| 1085 | |||
| 1086 | static void __exit imxmci_exit(void) | ||
| 1087 | { | ||
| 1088 | platform_driver_unregister(&imxmci_driver); | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | module_init(imxmci_init); | ||
| 1092 | module_exit(imxmci_exit); | ||
| 1093 | |||
| 1094 | MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver"); | ||
| 1095 | MODULE_AUTHOR("Sascha Hauer, Pengutronix"); | ||
| 1096 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mmc/imxmmc.h b/drivers/mmc/imxmmc.h new file mode 100644 index 000000000000..e5339e334dbb --- /dev/null +++ b/drivers/mmc/imxmmc.h | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | |||
| 2 | # define __REG16(x) (*((volatile u16 *)IO_ADDRESS(x))) | ||
| 3 | |||
| 4 | #define MMC_STR_STP_CLK __REG16(IMX_MMC_BASE + 0x00) | ||
| 5 | #define MMC_STATUS __REG16(IMX_MMC_BASE + 0x04) | ||
| 6 | #define MMC_CLK_RATE __REG16(IMX_MMC_BASE + 0x08) | ||
| 7 | #define MMC_CMD_DAT_CONT __REG16(IMX_MMC_BASE + 0x0C) | ||
| 8 | #define MMC_RES_TO __REG16(IMX_MMC_BASE + 0x10) | ||
| 9 | #define MMC_READ_TO __REG16(IMX_MMC_BASE + 0x14) | ||
| 10 | #define MMC_BLK_LEN __REG16(IMX_MMC_BASE + 0x18) | ||
| 11 | #define MMC_NOB __REG16(IMX_MMC_BASE + 0x1C) | ||
| 12 | #define MMC_REV_NO __REG16(IMX_MMC_BASE + 0x20) | ||
| 13 | #define MMC_INT_MASK __REG16(IMX_MMC_BASE + 0x24) | ||
| 14 | #define MMC_CMD __REG16(IMX_MMC_BASE + 0x28) | ||
| 15 | #define MMC_ARGH __REG16(IMX_MMC_BASE + 0x2C) | ||
| 16 | #define MMC_ARGL __REG16(IMX_MMC_BASE + 0x30) | ||
| 17 | #define MMC_RES_FIFO __REG16(IMX_MMC_BASE + 0x34) | ||
| 18 | #define MMC_BUFFER_ACCESS __REG16(IMX_MMC_BASE + 0x38) | ||
| 19 | #define MMC_BUFFER_ACCESS_OFS 0x38 | ||
| 20 | |||
| 21 | |||
| 22 | #define STR_STP_CLK_ENDIAN (1<<5) | ||
| 23 | #define STR_STP_CLK_RESET (1<<3) | ||
| 24 | #define STR_STP_CLK_ENABLE (1<<2) | ||
| 25 | #define STR_STP_CLK_START_CLK (1<<1) | ||
| 26 | #define STR_STP_CLK_STOP_CLK (1<<0) | ||
| 27 | #define STATUS_CARD_PRESENCE (1<<15) | ||
| 28 | #define STATUS_SDIO_INT_ACTIVE (1<<14) | ||
| 29 | #define STATUS_END_CMD_RESP (1<<13) | ||
| 30 | #define STATUS_WRITE_OP_DONE (1<<12) | ||
| 31 | #define STATUS_DATA_TRANS_DONE (1<<11) | ||
| 32 | #define STATUS_WR_CRC_ERROR_CODE_MASK (3<<10) | ||
| 33 | #define STATUS_CARD_BUS_CLK_RUN (1<<8) | ||
| 34 | #define STATUS_APPL_BUFF_FF (1<<7) | ||
| 35 | #define STATUS_APPL_BUFF_FE (1<<6) | ||
| 36 | #define STATUS_RESP_CRC_ERR (1<<5) | ||
| 37 | #define STATUS_CRC_READ_ERR (1<<3) | ||
| 38 | #define STATUS_CRC_WRITE_ERR (1<<2) | ||
| 39 | #define STATUS_TIME_OUT_RESP (1<<1) | ||
| 40 | #define STATUS_TIME_OUT_READ (1<<0) | ||
| 41 | #define STATUS_ERR_MASK 0x2f | ||
| 42 | #define CLK_RATE_PRESCALER(x) ((x) & 0x7) | ||
| 43 | #define CLK_RATE_CLK_RATE(x) (((x) & 0x7) << 3) | ||
| 44 | #define CMD_DAT_CONT_CMD_RESP_LONG_OFF (1<<12) | ||
| 45 | #define CMD_DAT_CONT_STOP_READWAIT (1<<11) | ||
| 46 | #define CMD_DAT_CONT_START_READWAIT (1<<10) | ||
| 47 | #define CMD_DAT_CONT_BUS_WIDTH_1 (0<<8) | ||
| 48 | #define CMD_DAT_CONT_BUS_WIDTH_4 (2<<8) | ||
| 49 | #define CMD_DAT_CONT_INIT (1<<7) | ||
| 50 | #define CMD_DAT_CONT_BUSY (1<<6) | ||
| 51 | #define CMD_DAT_CONT_STREAM_BLOCK (1<<5) | ||
| 52 | #define CMD_DAT_CONT_WRITE (1<<4) | ||
| 53 | #define CMD_DAT_CONT_DATA_ENABLE (1<<3) | ||
| 54 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R1 (1) | ||
| 55 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R2 (2) | ||
| 56 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R3 (3) | ||
| 57 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R4 (4) | ||
| 58 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R5 (5) | ||
| 59 | #define CMD_DAT_CONT_RESPONSE_FORMAT_R6 (6) | ||
| 60 | #define INT_MASK_AUTO_CARD_DETECT (1<<6) | ||
| 61 | #define INT_MASK_DAT0_EN (1<<5) | ||
| 62 | #define INT_MASK_SDIO (1<<4) | ||
| 63 | #define INT_MASK_BUF_READY (1<<3) | ||
| 64 | #define INT_MASK_END_CMD_RES (1<<2) | ||
| 65 | #define INT_MASK_WRITE_OP_DONE (1<<1) | ||
| 66 | #define INT_MASK_DATA_TRAN (1<<0) | ||
| 67 | #define INT_ALL (0x7f) | ||
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 1888060c5e0c..da6ddd910fc5 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c | |||
| @@ -27,12 +27,6 @@ | |||
| 27 | 27 | ||
| 28 | #include "mmc.h" | 28 | #include "mmc.h" |
| 29 | 29 | ||
| 30 | #ifdef CONFIG_MMC_DEBUG | ||
| 31 | #define DBG(x...) printk(KERN_DEBUG x) | ||
| 32 | #else | ||
| 33 | #define DBG(x...) do { } while (0) | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #define CMD_RETRIES 3 | 30 | #define CMD_RETRIES 3 |
| 37 | 31 | ||
| 38 | /* | 32 | /* |
| @@ -77,8 +71,9 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) | |||
| 77 | { | 71 | { |
| 78 | struct mmc_command *cmd = mrq->cmd; | 72 | struct mmc_command *cmd = mrq->cmd; |
| 79 | int err = mrq->cmd->error; | 73 | int err = mrq->cmd->error; |
| 80 | DBG("MMC: req done (%02x): %d: %08x %08x %08x %08x\n", cmd->opcode, | 74 | pr_debug("MMC: req done (%02x): %d: %08x %08x %08x %08x\n", |
| 81 | err, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); | 75 | cmd->opcode, err, cmd->resp[0], cmd->resp[1], |
| 76 | cmd->resp[2], cmd->resp[3]); | ||
| 82 | 77 | ||
| 83 | if (err && cmd->retries) { | 78 | if (err && cmd->retries) { |
| 84 | cmd->retries--; | 79 | cmd->retries--; |
| @@ -102,8 +97,8 @@ EXPORT_SYMBOL(mmc_request_done); | |||
| 102 | void | 97 | void |
| 103 | mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) | 98 | mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) |
| 104 | { | 99 | { |
| 105 | DBG("MMC: starting cmd %02x arg %08x flags %08x\n", | 100 | pr_debug("MMC: starting cmd %02x arg %08x flags %08x\n", |
| 106 | mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags); | 101 | mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags); |
| 107 | 102 | ||
| 108 | WARN_ON(host->card_busy == NULL); | 103 | WARN_ON(host->card_busy == NULL); |
| 109 | 104 | ||
| @@ -976,8 +971,8 @@ static unsigned int mmc_calculate_clock(struct mmc_host *host) | |||
| 976 | if (!mmc_card_dead(card) && max_dtr > card->csd.max_dtr) | 971 | if (!mmc_card_dead(card) && max_dtr > card->csd.max_dtr) |
| 977 | max_dtr = card->csd.max_dtr; | 972 | max_dtr = card->csd.max_dtr; |
| 978 | 973 | ||
| 979 | DBG("MMC: selected %d.%03dMHz transfer rate\n", | 974 | pr_debug("MMC: selected %d.%03dMHz transfer rate\n", |
| 980 | max_dtr / 1000000, (max_dtr / 1000) % 1000); | 975 | max_dtr / 1000000, (max_dtr / 1000) % 1000); |
| 981 | 976 | ||
| 982 | return max_dtr; | 977 | return max_dtr; |
| 983 | } | 978 | } |
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c index 9fef29d978b5..df7e861e2fc7 100644 --- a/drivers/mmc/mmci.c +++ b/drivers/mmc/mmci.c | |||
| @@ -33,12 +33,8 @@ | |||
| 33 | 33 | ||
| 34 | #define DRIVER_NAME "mmci-pl18x" | 34 | #define DRIVER_NAME "mmci-pl18x" |
| 35 | 35 | ||
| 36 | #ifdef CONFIG_MMC_DEBUG | ||
| 37 | #define DBG(host,fmt,args...) \ | 36 | #define DBG(host,fmt,args...) \ |
| 38 | pr_debug("%s: %s: " fmt, mmc_hostname(host->mmc), __func__ , args) | 37 | pr_debug("%s: %s: " fmt, mmc_hostname(host->mmc), __func__ , args) |
| 39 | #else | ||
| 40 | #define DBG(host,fmt,args...) do { } while (0) | ||
| 41 | #endif | ||
| 42 | 38 | ||
| 43 | static unsigned int fmax = 515633; | 39 | static unsigned int fmax = 515633; |
| 44 | 40 | ||
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c new file mode 100644 index 000000000000..becb3c68c34d --- /dev/null +++ b/drivers/mmc/omap.c | |||
| @@ -0,0 +1,1226 @@ | |||
| 1 | /* | ||
| 2 | * linux/drivers/media/mmc/omap.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2004 Nokia Corporation | ||
| 5 | * Written by Tuukka Tikkanen and Juha Yrjölä<juha.yrjola@nokia.com> | ||
| 6 | * Misc hacks here and there by Tony Lindgren <tony@atomide.com> | ||
| 7 | * Other hacks (DMA, SD, etc) by David Brownell | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2 as | ||
| 11 | * published by the Free Software Foundation. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/config.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/moduleparam.h> | ||
| 17 | #include <linux/init.h> | ||
| 18 | #include <linux/ioport.h> | ||
| 19 | #include <linux/platform_device.h> | ||
| 20 | #include <linux/interrupt.h> | ||
| 21 | #include <linux/dma-mapping.h> | ||
| 22 | #include <linux/delay.h> | ||
| 23 | #include <linux/spinlock.h> | ||
| 24 | #include <linux/timer.h> | ||
| 25 | #include <linux/mmc/host.h> | ||
| 26 | #include <linux/mmc/protocol.h> | ||
| 27 | #include <linux/mmc/card.h> | ||
| 28 | #include <linux/clk.h> | ||
| 29 | |||
| 30 | #include <asm/io.h> | ||
| 31 | #include <asm/irq.h> | ||
| 32 | #include <asm/scatterlist.h> | ||
| 33 | #include <asm/mach-types.h> | ||
| 34 | |||
| 35 | #include <asm/arch/board.h> | ||
| 36 | #include <asm/arch/gpio.h> | ||
| 37 | #include <asm/arch/dma.h> | ||
| 38 | #include <asm/arch/mux.h> | ||
| 39 | #include <asm/arch/fpga.h> | ||
| 40 | #include <asm/arch/tps65010.h> | ||
| 41 | |||
| 42 | #include "omap.h" | ||
| 43 | |||
| 44 | #define DRIVER_NAME "mmci-omap" | ||
| 45 | #define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE)) | ||
| 46 | |||
| 47 | /* Specifies how often in millisecs to poll for card status changes | ||
| 48 | * when the cover switch is open */ | ||
| 49 | #define OMAP_MMC_SWITCH_POLL_DELAY 500 | ||
| 50 | |||
| 51 | static int mmc_omap_enable_poll = 1; | ||
| 52 | |||
| 53 | struct mmc_omap_host { | ||
| 54 | int initialized; | ||
| 55 | int suspended; | ||
| 56 | struct mmc_request * mrq; | ||
| 57 | struct mmc_command * cmd; | ||
| 58 | struct mmc_data * data; | ||
| 59 | struct mmc_host * mmc; | ||
| 60 | struct device * dev; | ||
| 61 | unsigned char id; /* 16xx chips have 2 MMC blocks */ | ||
| 62 | struct clk * iclk; | ||
| 63 | struct clk * fclk; | ||
| 64 | void __iomem *base; | ||
| 65 | int irq; | ||
| 66 | unsigned char bus_mode; | ||
| 67 | unsigned char hw_bus_mode; | ||
| 68 | |||
| 69 | unsigned int sg_len; | ||
| 70 | int sg_idx; | ||
| 71 | u16 * buffer; | ||
| 72 | u32 buffer_bytes_left; | ||
| 73 | u32 total_bytes_left; | ||
| 74 | |||
| 75 | unsigned use_dma:1; | ||
| 76 | unsigned brs_received:1, dma_done:1; | ||
| 77 | unsigned dma_is_read:1; | ||
| 78 | unsigned dma_in_use:1; | ||
| 79 | int dma_ch; | ||
| 80 | spinlock_t dma_lock; | ||
| 81 | struct timer_list dma_timer; | ||
| 82 | unsigned dma_len; | ||
| 83 | |||
| 84 | short power_pin; | ||
| 85 | short wp_pin; | ||
| 86 | |||
| 87 | int switch_pin; | ||
| 88 | struct work_struct switch_work; | ||
| 89 | struct timer_list switch_timer; | ||
| 90 | int switch_last_state; | ||
| 91 | }; | ||
| 92 | |||
| 93 | static inline int | ||
| 94 | mmc_omap_cover_is_open(struct mmc_omap_host *host) | ||
| 95 | { | ||
| 96 | if (host->switch_pin < 0) | ||
| 97 | return 0; | ||
| 98 | return omap_get_gpio_datain(host->switch_pin); | ||
| 99 | } | ||
| 100 | |||
| 101 | static ssize_t | ||
| 102 | mmc_omap_show_cover_switch(struct device *dev, | ||
| 103 | struct device_attribute *attr, char *buf) | ||
| 104 | { | ||
| 105 | struct mmc_omap_host *host = dev_get_drvdata(dev); | ||
| 106 | |||
| 107 | return sprintf(buf, "%s\n", mmc_omap_cover_is_open(host) ? "open" : | ||
| 108 | "closed"); | ||
| 109 | } | ||
| 110 | |||
| 111 | static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL); | ||
| 112 | |||
| 113 | static ssize_t | ||
| 114 | mmc_omap_show_enable_poll(struct device *dev, | ||
| 115 | struct device_attribute *attr, char *buf) | ||
| 116 | { | ||
| 117 | return snprintf(buf, PAGE_SIZE, "%d\n", mmc_omap_enable_poll); | ||
| 118 | } | ||
| 119 | |||
| 120 | static ssize_t | ||
| 121 | mmc_omap_store_enable_poll(struct device *dev, | ||
| 122 | struct device_attribute *attr, const char *buf, | ||
| 123 | size_t size) | ||
| 124 | { | ||
| 125 | int enable_poll; | ||
| 126 | |||
| 127 | if (sscanf(buf, "%10d", &enable_poll) != 1) | ||
| 128 | return -EINVAL; | ||
| 129 | |||
| 130 | if (enable_poll != mmc_omap_enable_poll) { | ||
| 131 | struct mmc_omap_host *host = dev_get_drvdata(dev); | ||
| 132 | |||
| 133 | mmc_omap_enable_poll = enable_poll; | ||
| 134 | if (enable_poll && host->switch_pin >= 0) | ||
| 135 | schedule_work(&host->switch_work); | ||
| 136 | } | ||
| 137 | return size; | ||
| 138 | } | ||
| 139 | |||
| 140 | static DEVICE_ATTR(enable_poll, 0664, | ||
| 141 | mmc_omap_show_enable_poll, mmc_omap_store_enable_poll); | ||
| 142 | |||
| 143 | static void | ||
| 144 | mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd) | ||
| 145 | { | ||
| 146 | u32 cmdreg; | ||
| 147 | u32 resptype; | ||
| 148 | u32 cmdtype; | ||
| 149 | |||
| 150 | host->cmd = cmd; | ||
| 151 | |||
| 152 | resptype = 0; | ||
| 153 | cmdtype = 0; | ||
| 154 | |||
| 155 | /* Our hardware needs to know exact type */ | ||
| 156 | switch (RSP_TYPE(mmc_resp_type(cmd))) { | ||
| 157 | case RSP_TYPE(MMC_RSP_R1): | ||
| 158 | /* resp 1, resp 1b */ | ||
| 159 | resptype = 1; | ||
| 160 | break; | ||
| 161 | case RSP_TYPE(MMC_RSP_R2): | ||
| 162 | resptype = 2; | ||
| 163 | break; | ||
| 164 | case RSP_TYPE(MMC_RSP_R3): | ||
| 165 | resptype = 3; | ||
| 166 | break; | ||
| 167 | default: | ||
| 168 | break; | ||
| 169 | } | ||
| 170 | |||
| 171 | if (mmc_cmd_type(cmd) == MMC_CMD_ADTC) { | ||
| 172 | cmdtype = OMAP_MMC_CMDTYPE_ADTC; | ||
| 173 | } else if (mmc_cmd_type(cmd) == MMC_CMD_BC) { | ||
| 174 | cmdtype = OMAP_MMC_CMDTYPE_BC; | ||
| 175 | } else if (mmc_cmd_type(cmd) == MMC_CMD_BCR) { | ||
| 176 | cmdtype = OMAP_MMC_CMDTYPE_BCR; | ||
| 177 | } else { | ||
| 178 | cmdtype = OMAP_MMC_CMDTYPE_AC; | ||
| 179 | } | ||
| 180 | |||
| 181 | cmdreg = cmd->opcode | (resptype << 8) | (cmdtype << 12); | ||
| 182 | |||
| 183 | if (host->bus_mode == MMC_BUSMODE_OPENDRAIN) | ||
| 184 | cmdreg |= 1 << 6; | ||
| 185 | |||
| 186 | if (cmd->flags & MMC_RSP_BUSY) | ||
| 187 | cmdreg |= 1 << 11; | ||
| 188 | |||
| 189 | if (host->data && !(host->data->flags & MMC_DATA_WRITE)) | ||
| 190 | cmdreg |= 1 << 15; | ||
| 191 | |||
| 192 | clk_enable(host->fclk); | ||
| 193 | |||
| 194 | OMAP_MMC_WRITE(host->base, CTO, 200); | ||
| 195 | OMAP_MMC_WRITE(host->base, ARGL, cmd->arg & 0xffff); | ||
| 196 | OMAP_MMC_WRITE(host->base, ARGH, cmd->arg >> 16); | ||
| 197 | OMAP_MMC_WRITE(host->base, IE, | ||
| 198 | OMAP_MMC_STAT_A_EMPTY | OMAP_MMC_STAT_A_FULL | | ||
| 199 | OMAP_MMC_STAT_CMD_CRC | OMAP_MMC_STAT_CMD_TOUT | | ||
| 200 | OMAP_MMC_STAT_DATA_CRC | OMAP_MMC_STAT_DATA_TOUT | | ||
| 201 | OMAP_MMC_STAT_END_OF_CMD | OMAP_MMC_STAT_CARD_ERR | | ||
| 202 | OMAP_MMC_STAT_END_OF_DATA); | ||
| 203 | OMAP_MMC_WRITE(host->base, CMD, cmdreg); | ||
| 204 | } | ||
| 205 | |||
| 206 | static void | ||
| 207 | mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data) | ||
| 208 | { | ||
| 209 | if (host->dma_in_use) { | ||
| 210 | enum dma_data_direction dma_data_dir; | ||
| 211 | |||
| 212 | BUG_ON(host->dma_ch < 0); | ||
| 213 | if (data->error != MMC_ERR_NONE) | ||
| 214 | omap_stop_dma(host->dma_ch); | ||
| 215 | /* Release DMA channel lazily */ | ||
| 216 | mod_timer(&host->dma_timer, jiffies + HZ); | ||
| 217 | if (data->flags & MMC_DATA_WRITE) | ||
| 218 | dma_data_dir = DMA_TO_DEVICE; | ||
| 219 | else | ||
| 220 | dma_data_dir = DMA_FROM_DEVICE; | ||
| 221 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->sg_len, | ||
| 222 | dma_data_dir); | ||
| 223 | } | ||
| 224 | host->data = NULL; | ||
| 225 | host->sg_len = 0; | ||
| 226 | clk_disable(host->fclk); | ||
| 227 | |||
| 228 | /* NOTE: MMC layer will sometimes poll-wait CMD13 next, issuing | ||
| 229 | * dozens of requests until the card finishes writing data. | ||
| 230 | * It'd be cheaper to just wait till an EOFB interrupt arrives... | ||
| 231 | */ | ||
| 232 | |||
| 233 | if (!data->stop) { | ||
| 234 | host->mrq = NULL; | ||
| 235 | mmc_request_done(host->mmc, data->mrq); | ||
| 236 | return; | ||
| 237 | } | ||
| 238 | |||
| 239 | mmc_omap_start_command(host, data->stop); | ||
| 240 | } | ||
| 241 | |||
| 242 | static void | ||
| 243 | mmc_omap_end_of_data(struct mmc_omap_host *host, struct mmc_data *data) | ||
| 244 | { | ||
| 245 | unsigned long flags; | ||
| 246 | int done; | ||
| 247 | |||
| 248 | if (!host->dma_in_use) { | ||
| 249 | mmc_omap_xfer_done(host, data); | ||
| 250 | return; | ||
| 251 | } | ||
| 252 | done = 0; | ||
| 253 | spin_lock_irqsave(&host->dma_lock, flags); | ||
| 254 | if (host->dma_done) | ||
| 255 | done = 1; | ||
| 256 | else | ||
| 257 | host->brs_received = 1; | ||
| 258 | spin_unlock_irqrestore(&host->dma_lock, flags); | ||
| 259 | if (done) | ||
| 260 | mmc_omap_xfer_done(host, data); | ||
| 261 | } | ||
| 262 | |||
| 263 | static void | ||
| 264 | mmc_omap_dma_timer(unsigned long data) | ||
| 265 | { | ||
| 266 | struct mmc_omap_host *host = (struct mmc_omap_host *) data; | ||
| 267 | |||
| 268 | BUG_ON(host->dma_ch < 0); | ||
| 269 | omap_free_dma(host->dma_ch); | ||
| 270 | host->dma_ch = -1; | ||
| 271 | } | ||
| 272 | |||
| 273 | static void | ||
| 274 | mmc_omap_dma_done(struct mmc_omap_host *host, struct mmc_data *data) | ||
| 275 | { | ||
| 276 | unsigned long flags; | ||
| 277 | int done; | ||
| 278 | |||
| 279 | done = 0; | ||
| 280 | spin_lock_irqsave(&host->dma_lock, flags); | ||
| 281 | if (host->brs_received) | ||
| 282 | done = 1; | ||
| 283 | else | ||
| 284 | host->dma_done = 1; | ||
| 285 | spin_unlock_irqrestore(&host->dma_lock, flags); | ||
| 286 | if (done) | ||
| 287 | mmc_omap_xfer_done(host, data); | ||
| 288 | } | ||
| 289 | |||
| 290 | static void | ||
| 291 | mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd) | ||
| 292 | { | ||
| 293 | host->cmd = NULL; | ||
| 294 | |||
| 295 | if (cmd->flags & MMC_RSP_PRESENT) { | ||
| 296 | if (cmd->flags & MMC_RSP_136) { | ||
| 297 | /* response type 2 */ | ||
| 298 | cmd->resp[3] = | ||
| 299 | OMAP_MMC_READ(host->base, RSP0) | | ||
| 300 | (OMAP_MMC_READ(host->base, RSP1) << 16); | ||
| 301 | cmd->resp[2] = | ||
| 302 | OMAP_MMC_READ(host->base, RSP2) | | ||
| 303 | (OMAP_MMC_READ(host->base, RSP3) << 16); | ||
| 304 | cmd->resp[1] = | ||
| 305 | OMAP_MMC_READ(host->base, RSP4) | | ||
| 306 | (OMAP_MMC_READ(host->base, RSP5) << 16); | ||
| 307 | cmd->resp[0] = | ||
| 308 | OMAP_MMC_READ(host->base, RSP6) | | ||
| 309 | (OMAP_MMC_READ(host->base, RSP7) << 16); | ||
| 310 | } else { | ||
| 311 | /* response types 1, 1b, 3, 4, 5, 6 */ | ||
| 312 | cmd->resp[0] = | ||
| 313 | OMAP_MMC_READ(host->base, RSP6) | | ||
| 314 | (OMAP_MMC_READ(host->base, RSP7) << 16); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | if (host->data == NULL || cmd->error != MMC_ERR_NONE) { | ||
| 319 | host->mrq = NULL; | ||
| 320 | clk_disable(host->fclk); | ||
| 321 | mmc_request_done(host->mmc, cmd->mrq); | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | /* PIO only */ | ||
| 326 | static void | ||
| 327 | mmc_omap_sg_to_buf(struct mmc_omap_host *host) | ||
| 328 | { | ||
| 329 | struct scatterlist *sg; | ||
| 330 | |||
| 331 | sg = host->data->sg + host->sg_idx; | ||
| 332 | host->buffer_bytes_left = sg->length; | ||
| 333 | host->buffer = page_address(sg->page) + sg->offset; | ||
| 334 | if (host->buffer_bytes_left > host->total_bytes_left) | ||
| 335 | host->buffer_bytes_left = host->total_bytes_left; | ||
| 336 | } | ||
| 337 | |||
| 338 | /* PIO only */ | ||
| 339 | static void | ||
| 340 | mmc_omap_xfer_data(struct mmc_omap_host *host, int write) | ||
| 341 | { | ||
| 342 | int n; | ||
| 343 | void __iomem *reg; | ||
| 344 | u16 *p; | ||
| 345 | |||
| 346 | if (host->buffer_bytes_left == 0) { | ||
| 347 | host->sg_idx++; | ||
| 348 | BUG_ON(host->sg_idx == host->sg_len); | ||
| 349 | mmc_omap_sg_to_buf(host); | ||
| 350 | } | ||
| 351 | n = 64; | ||
| 352 | if (n > host->buffer_bytes_left) | ||
| 353 | n = host->buffer_bytes_left; | ||
| 354 | host->buffer_bytes_left -= n; | ||
| 355 | host->total_bytes_left -= n; | ||
| 356 | host->data->bytes_xfered += n; | ||
| 357 | |||
| 358 | if (write) { | ||
| 359 | __raw_writesw(host->base + OMAP_MMC_REG_DATA, host->buffer, n); | ||
| 360 | } else { | ||
| 361 | __raw_readsw(host->base + OMAP_MMC_REG_DATA, host->buffer, n); | ||
| 362 | } | ||
| 363 | } | ||
| 364 | |||
| 365 | static inline void mmc_omap_report_irq(u16 status) | ||
| 366 | { | ||
| 367 | static const char *mmc_omap_status_bits[] = { | ||
| 368 | "EOC", "CD", "CB", "BRS", "EOFB", "DTO", "DCRC", "CTO", | ||
| 369 | "CCRC", "CRW", "AF", "AE", "OCRB", "CIRQ", "CERR" | ||
| 370 | }; | ||
| 371 | int i, c = 0; | ||
| 372 | |||
| 373 | for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++) | ||
| 374 | if (status & (1 << i)) { | ||
| 375 | if (c) | ||
| 376 | printk(" "); | ||
| 377 | printk("%s", mmc_omap_status_bits[i]); | ||
| 378 | c++; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs) | ||
| 383 | { | ||
| 384 | struct mmc_omap_host * host = (struct mmc_omap_host *)dev_id; | ||
| 385 | u16 status; | ||
| 386 | int end_command; | ||
| 387 | int end_transfer; | ||
| 388 | int transfer_error; | ||
| 389 | |||
| 390 | if (host->cmd == NULL && host->data == NULL) { | ||
| 391 | status = OMAP_MMC_READ(host->base, STAT); | ||
| 392 | dev_info(mmc_dev(host->mmc),"spurious irq 0x%04x\n", status); | ||
| 393 | if (status != 0) { | ||
| 394 | OMAP_MMC_WRITE(host->base, STAT, status); | ||
| 395 | OMAP_MMC_WRITE(host->base, IE, 0); | ||
| 396 | } | ||
| 397 | return IRQ_HANDLED; | ||
| 398 | } | ||
| 399 | |||
| 400 | end_command = 0; | ||
| 401 | end_transfer = 0; | ||
| 402 | transfer_error = 0; | ||
| 403 | |||
| 404 | while ((status = OMAP_MMC_READ(host->base, STAT)) != 0) { | ||
| 405 | OMAP_MMC_WRITE(host->base, STAT, status); | ||
| 406 | #ifdef CONFIG_MMC_DEBUG | ||
| 407 | dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ", | ||
| 408 | status, host->cmd != NULL ? host->cmd->opcode : -1); | ||
| 409 | mmc_omap_report_irq(status); | ||
| 410 | printk("\n"); | ||
| 411 | #endif | ||
| 412 | if (host->total_bytes_left) { | ||
| 413 | if ((status & OMAP_MMC_STAT_A_FULL) || | ||
| 414 | (status & OMAP_MMC_STAT_END_OF_DATA)) | ||
| 415 | mmc_omap_xfer_data(host, 0); | ||
| 416 | if (status & OMAP_MMC_STAT_A_EMPTY) | ||
| 417 | mmc_omap_xfer_data(host, 1); | ||
| 418 | } | ||
| 419 | |||
| 420 | if (status & OMAP_MMC_STAT_END_OF_DATA) { | ||
| 421 | end_transfer = 1; | ||
| 422 | } | ||
| 423 | |||
| 424 | if (status & OMAP_MMC_STAT_DATA_TOUT) { | ||
| 425 | dev_dbg(mmc_dev(host->mmc), "data timeout\n"); | ||
| 426 | if (host->data) { | ||
| 427 | host->data->error |= MMC_ERR_TIMEOUT; | ||
| 428 | transfer_error = 1; | ||
| 429 | } | ||
| 430 | } | ||
| 431 | |||
| 432 | if (status & OMAP_MMC_STAT_DATA_CRC) { | ||
| 433 | if (host->data) { | ||
| 434 | host->data->error |= MMC_ERR_BADCRC; | ||
| 435 | dev_dbg(mmc_dev(host->mmc), | ||
| 436 | "data CRC error, bytes left %d\n", | ||
| 437 | host->total_bytes_left); | ||
| 438 | transfer_error = 1; | ||
| 439 | } else { | ||
| 440 | dev_dbg(mmc_dev(host->mmc), "data CRC error\n"); | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | if (status & OMAP_MMC_STAT_CMD_TOUT) { | ||
| 445 | /* Timeouts are routine with some commands */ | ||
| 446 | if (host->cmd) { | ||
| 447 | if (host->cmd->opcode != MMC_ALL_SEND_CID && | ||
| 448 | host->cmd->opcode != | ||
| 449 | MMC_SEND_OP_COND && | ||
| 450 | host->cmd->opcode != | ||
| 451 | MMC_APP_CMD && | ||
| 452 | !mmc_omap_cover_is_open(host)) | ||
| 453 | dev_err(mmc_dev(host->mmc), | ||
| 454 | "command timeout, CMD %d\n", | ||
| 455 | host->cmd->opcode); | ||
| 456 | host->cmd->error = MMC_ERR_TIMEOUT; | ||
| 457 | end_command = 1; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | if (status & OMAP_MMC_STAT_CMD_CRC) { | ||
| 462 | if (host->cmd) { | ||
| 463 | dev_err(mmc_dev(host->mmc), | ||
| 464 | "command CRC error (CMD%d, arg 0x%08x)\n", | ||
| 465 | host->cmd->opcode, host->cmd->arg); | ||
| 466 | host->cmd->error = MMC_ERR_BADCRC; | ||
| 467 | end_command = 1; | ||
| 468 | } else | ||
| 469 | dev_err(mmc_dev(host->mmc), | ||
| 470 | "command CRC error without cmd?\n"); | ||
| 471 | } | ||
| 472 | |||
| 473 | if (status & OMAP_MMC_STAT_CARD_ERR) { | ||
| 474 | if (host->cmd && host->cmd->opcode == MMC_STOP_TRANSMISSION) { | ||
| 475 | u32 response = OMAP_MMC_READ(host->base, RSP6) | ||
| 476 | | (OMAP_MMC_READ(host->base, RSP7) << 16); | ||
| 477 | /* STOP sometimes sets must-ignore bits */ | ||
| 478 | if (!(response & (R1_CC_ERROR | ||
| 479 | | R1_ILLEGAL_COMMAND | ||
| 480 | | R1_COM_CRC_ERROR))) { | ||
| 481 | end_command = 1; | ||
| 482 | continue; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | dev_dbg(mmc_dev(host->mmc), "card status error (CMD%d)\n", | ||
| 487 | host->cmd->opcode); | ||
| 488 | if (host->cmd) { | ||
| 489 | host->cmd->error = MMC_ERR_FAILED; | ||
| 490 | end_command = 1; | ||
| 491 | } | ||
| 492 | if (host->data) { | ||
| 493 | host->data->error = MMC_ERR_FAILED; | ||
| 494 | transfer_error = 1; | ||
| 495 | } | ||
| 496 | } | ||
| 497 | |||
| 498 | /* | ||
| 499 | * NOTE: On 1610 the END_OF_CMD may come too early when | ||
| 500 | * starting a write | ||
| 501 | */ | ||
| 502 | if ((status & OMAP_MMC_STAT_END_OF_CMD) && | ||
| 503 | (!(status & OMAP_MMC_STAT_A_EMPTY))) { | ||
| 504 | end_command = 1; | ||
| 505 | } | ||
| 506 | } | ||
| 507 | |||
| 508 | if (end_command) { | ||
| 509 | mmc_omap_cmd_done(host, host->cmd); | ||
| 510 | } | ||
| 511 | if (transfer_error) | ||
| 512 | mmc_omap_xfer_done(host, host->data); | ||
| 513 | else if (end_transfer) | ||
| 514 | mmc_omap_end_of_data(host, host->data); | ||
| 515 | |||
| 516 | return IRQ_HANDLED; | ||
| 517 | } | ||
| 518 | |||
| 519 | static irqreturn_t mmc_omap_switch_irq(int irq, void *dev_id, struct pt_regs *regs) | ||
| 520 | { | ||
| 521 | struct mmc_omap_host *host = (struct mmc_omap_host *) dev_id; | ||
| 522 | |||
| 523 | schedule_work(&host->switch_work); | ||
| 524 | |||
| 525 | return IRQ_HANDLED; | ||
| 526 | } | ||
| 527 | |||
| 528 | static void mmc_omap_switch_timer(unsigned long arg) | ||
| 529 | { | ||
| 530 | struct mmc_omap_host *host = (struct mmc_omap_host *) arg; | ||
| 531 | |||
| 532 | schedule_work(&host->switch_work); | ||
| 533 | } | ||
| 534 | |||
| 535 | /* FIXME: Handle card insertion and removal properly. Maybe use a mask | ||
| 536 | * for MMC state? */ | ||
| 537 | static void mmc_omap_switch_callback(unsigned long data, u8 mmc_mask) | ||
| 538 | { | ||
| 539 | } | ||
| 540 | |||
| 541 | static void mmc_omap_switch_handler(void *data) | ||
| 542 | { | ||
| 543 | struct mmc_omap_host *host = (struct mmc_omap_host *) data; | ||
| 544 | struct mmc_card *card; | ||
| 545 | static int complained = 0; | ||
| 546 | int cards = 0, cover_open; | ||
| 547 | |||
| 548 | if (host->switch_pin == -1) | ||
| 549 | return; | ||
| 550 | cover_open = mmc_omap_cover_is_open(host); | ||
| 551 | if (cover_open != host->switch_last_state) { | ||
| 552 | kobject_uevent(&host->dev->kobj, KOBJ_CHANGE); | ||
| 553 | host->switch_last_state = cover_open; | ||
| 554 | } | ||
| 555 | mmc_detect_change(host->mmc, 0); | ||
| 556 | list_for_each_entry(card, &host->mmc->cards, node) { | ||
| 557 | if (mmc_card_present(card)) | ||
| 558 | cards++; | ||
| 559 | } | ||
| 560 | if (mmc_omap_cover_is_open(host)) { | ||
| 561 | if (!complained) { | ||
| 562 | dev_info(mmc_dev(host->mmc), "cover is open"); | ||
| 563 | complained = 1; | ||
| 564 | } | ||
| 565 | if (mmc_omap_enable_poll) | ||
| 566 | mod_timer(&host->switch_timer, jiffies + | ||
| 567 | msecs_to_jiffies(OMAP_MMC_SWITCH_POLL_DELAY)); | ||
| 568 | } else { | ||
| 569 | complained = 0; | ||
| 570 | } | ||
| 571 | } | ||
| 572 | |||
| 573 | /* Prepare to transfer the next segment of a scatterlist */ | ||
| 574 | static void | ||
| 575 | mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data) | ||
| 576 | { | ||
| 577 | int dma_ch = host->dma_ch; | ||
| 578 | unsigned long data_addr; | ||
| 579 | u16 buf, frame; | ||
| 580 | u32 count; | ||
| 581 | struct scatterlist *sg = &data->sg[host->sg_idx]; | ||
| 582 | int src_port = 0; | ||
| 583 | int dst_port = 0; | ||
| 584 | int sync_dev = 0; | ||
| 585 | |||
| 586 | data_addr = io_v2p((u32) host->base) + OMAP_MMC_REG_DATA; | ||
| 587 | frame = 1 << data->blksz_bits; | ||
| 588 | count = sg_dma_len(sg); | ||
| 589 | |||
| 590 | if ((data->blocks == 1) && (count > (1 << data->blksz_bits))) | ||
| 591 | count = frame; | ||
| 592 | |||
| 593 | host->dma_len = count; | ||
| 594 | |||
| 595 | /* FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx and 24xx. | ||
| 596 | * Use 16 or 32 word frames when the blocksize is at least that large. | ||
| 597 | * Blocksize is usually 512 bytes; but not for some SD reads. | ||
| 598 | */ | ||
| 599 | if (cpu_is_omap15xx() && frame > 32) | ||
| 600 | frame = 32; | ||
| 601 | else if (frame > 64) | ||
| 602 | frame = 64; | ||
| 603 | count /= frame; | ||
| 604 | frame >>= 1; | ||
| 605 | |||
| 606 | if (!(data->flags & MMC_DATA_WRITE)) { | ||
| 607 | buf = 0x800f | ((frame - 1) << 8); | ||
| 608 | |||
| 609 | if (cpu_class_is_omap1()) { | ||
| 610 | src_port = OMAP_DMA_PORT_TIPB; | ||
| 611 | dst_port = OMAP_DMA_PORT_EMIFF; | ||
| 612 | } | ||
| 613 | if (cpu_is_omap24xx()) | ||
| 614 | sync_dev = OMAP24XX_DMA_MMC1_RX; | ||
| 615 | |||
| 616 | omap_set_dma_src_params(dma_ch, src_port, | ||
| 617 | OMAP_DMA_AMODE_CONSTANT, | ||
| 618 | data_addr, 0, 0); | ||
| 619 | omap_set_dma_dest_params(dma_ch, dst_port, | ||
| 620 | OMAP_DMA_AMODE_POST_INC, | ||
| 621 | sg_dma_address(sg), 0, 0); | ||
| 622 | omap_set_dma_dest_data_pack(dma_ch, 1); | ||
| 623 | omap_set_dma_dest_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); | ||
| 624 | } else { | ||
| 625 | buf = 0x0f80 | ((frame - 1) << 0); | ||
| 626 | |||
| 627 | if (cpu_class_is_omap1()) { | ||
| 628 | src_port = OMAP_DMA_PORT_EMIFF; | ||
| 629 | dst_port = OMAP_DMA_PORT_TIPB; | ||
| 630 | } | ||
| 631 | if (cpu_is_omap24xx()) | ||
| 632 | sync_dev = OMAP24XX_DMA_MMC1_TX; | ||
| 633 | |||
| 634 | omap_set_dma_dest_params(dma_ch, dst_port, | ||
| 635 | OMAP_DMA_AMODE_CONSTANT, | ||
| 636 | data_addr, 0, 0); | ||
| 637 | omap_set_dma_src_params(dma_ch, src_port, | ||
| 638 | OMAP_DMA_AMODE_POST_INC, | ||
| 639 | sg_dma_address(sg), 0, 0); | ||
| 640 | omap_set_dma_src_data_pack(dma_ch, 1); | ||
| 641 | omap_set_dma_src_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); | ||
| 642 | } | ||
| 643 | |||
| 644 | /* Max limit for DMA frame count is 0xffff */ | ||
| 645 | if (unlikely(count > 0xffff)) | ||
| 646 | BUG(); | ||
| 647 | |||
| 648 | OMAP_MMC_WRITE(host->base, BUF, buf); | ||
| 649 | omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S16, | ||
| 650 | frame, count, OMAP_DMA_SYNC_FRAME, | ||
| 651 | sync_dev, 0); | ||
| 652 | } | ||
| 653 | |||
| 654 | /* A scatterlist segment completed */ | ||
| 655 | static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data) | ||
| 656 | { | ||
| 657 | struct mmc_omap_host *host = (struct mmc_omap_host *) data; | ||
| 658 | struct mmc_data *mmcdat = host->data; | ||
| 659 | |||
| 660 | if (unlikely(host->dma_ch < 0)) { | ||
| 661 | dev_err(mmc_dev(host->mmc), "DMA callback while DMA not | ||
| 662 | enabled\n"); | ||
| 663 | return; | ||
| 664 | } | ||
| 665 | /* FIXME: We really should do something to _handle_ the errors */ | ||
| 666 | if (ch_status & OMAP_DMA_TOUT_IRQ) { | ||
| 667 | dev_err(mmc_dev(host->mmc),"DMA timeout\n"); | ||
| 668 | return; | ||
| 669 | } | ||
| 670 | if (ch_status & OMAP_DMA_DROP_IRQ) { | ||
| 671 | dev_err(mmc_dev(host->mmc), "DMA sync error\n"); | ||
| 672 | return; | ||
| 673 | } | ||
| 674 | if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { | ||
| 675 | return; | ||
| 676 | } | ||
| 677 | mmcdat->bytes_xfered += host->dma_len; | ||
| 678 | host->sg_idx++; | ||
| 679 | if (host->sg_idx < host->sg_len) { | ||
| 680 | mmc_omap_prepare_dma(host, host->data); | ||
| 681 | omap_start_dma(host->dma_ch); | ||
| 682 | } else | ||
| 683 | mmc_omap_dma_done(host, host->data); | ||
| 684 | } | ||
| 685 | |||
| 686 | static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data) | ||
| 687 | { | ||
| 688 | const char *dev_name; | ||
| 689 | int sync_dev, dma_ch, is_read, r; | ||
| 690 | |||
| 691 | is_read = !(data->flags & MMC_DATA_WRITE); | ||
| 692 | del_timer_sync(&host->dma_timer); | ||
| 693 | if (host->dma_ch >= 0) { | ||
| 694 | if (is_read == host->dma_is_read) | ||
| 695 | return 0; | ||
| 696 | omap_free_dma(host->dma_ch); | ||
| 697 | host->dma_ch = -1; | ||
| 698 | } | ||
| 699 | |||
| 700 | if (is_read) { | ||
| 701 | if (host->id == 1) { | ||
| 702 | sync_dev = OMAP_DMA_MMC_RX; | ||
| 703 | dev_name = "MMC1 read"; | ||
| 704 | } else { | ||
| 705 | sync_dev = OMAP_DMA_MMC2_RX; | ||
| 706 | dev_name = "MMC2 read"; | ||
| 707 | } | ||
| 708 | } else { | ||
| 709 | if (host->id == 1) { | ||
| 710 | sync_dev = OMAP_DMA_MMC_TX; | ||
| 711 | dev_name = "MMC1 write"; | ||
| 712 | } else { | ||
| 713 | sync_dev = OMAP_DMA_MMC2_TX; | ||
| 714 | dev_name = "MMC2 write"; | ||
| 715 | } | ||
| 716 | } | ||
| 717 | r = omap_request_dma(sync_dev, dev_name, mmc_omap_dma_cb, | ||
| 718 | host, &dma_ch); | ||
| 719 | if (r != 0) { | ||
| 720 | dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r); | ||
| 721 | return r; | ||
| 722 | } | ||
| 723 | host->dma_ch = dma_ch; | ||
| 724 | host->dma_is_read = is_read; | ||
| 725 | |||
| 726 | return 0; | ||
| 727 | } | ||
| 728 | |||
| 729 | static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req) | ||
| 730 | { | ||
| 731 | u16 reg; | ||
| 732 | |||
| 733 | reg = OMAP_MMC_READ(host->base, SDIO); | ||
| 734 | reg &= ~(1 << 5); | ||
| 735 | OMAP_MMC_WRITE(host->base, SDIO, reg); | ||
| 736 | /* Set maximum timeout */ | ||
| 737 | OMAP_MMC_WRITE(host->base, CTO, 0xff); | ||
| 738 | } | ||
| 739 | |||
| 740 | static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_request *req) | ||
| 741 | { | ||
| 742 | int timeout; | ||
| 743 | u16 reg; | ||
| 744 | |||
| 745 | /* Convert ns to clock cycles by assuming 20MHz frequency | ||
| 746 | * 1 cycle at 20MHz = 500 ns | ||
| 747 | */ | ||
| 748 | timeout = req->data->timeout_clks + req->data->timeout_ns / 500; | ||
| 749 | |||
| 750 | /* Check if we need to use timeout multiplier register */ | ||
| 751 | reg = OMAP_MMC_READ(host->base, SDIO); | ||
| 752 | if (timeout > 0xffff) { | ||
| 753 | reg |= (1 << 5); | ||
| 754 | timeout /= 1024; | ||
| 755 | } else | ||
| 756 | reg &= ~(1 << 5); | ||
| 757 | OMAP_MMC_WRITE(host->base, SDIO, reg); | ||
| 758 | OMAP_MMC_WRITE(host->base, DTO, timeout); | ||
| 759 | } | ||
| 760 | |||
| 761 | static void | ||
| 762 | mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) | ||
| 763 | { | ||
| 764 | struct mmc_data *data = req->data; | ||
| 765 | int i, use_dma, block_size; | ||
| 766 | unsigned sg_len; | ||
| 767 | |||
| 768 | host->data = data; | ||
| 769 | if (data == NULL) { | ||
| 770 | OMAP_MMC_WRITE(host->base, BLEN, 0); | ||
| 771 | OMAP_MMC_WRITE(host->base, NBLK, 0); | ||
| 772 | OMAP_MMC_WRITE(host->base, BUF, 0); | ||
| 773 | host->dma_in_use = 0; | ||
| 774 | set_cmd_timeout(host, req); | ||
| 775 | return; | ||
| 776 | } | ||
| 777 | |||
| 778 | |||
| 779 | block_size = 1 << data->blksz_bits; | ||
| 780 | |||
| 781 | OMAP_MMC_WRITE(host->base, NBLK, data->blocks - 1); | ||
| 782 | OMAP_MMC_WRITE(host->base, BLEN, block_size - 1); | ||
| 783 | set_data_timeout(host, req); | ||
| 784 | |||
| 785 | /* cope with calling layer confusion; it issues "single | ||
| 786 | * block" writes using multi-block scatterlists. | ||
| 787 | */ | ||
| 788 | sg_len = (data->blocks == 1) ? 1 : data->sg_len; | ||
| 789 | |||
| 790 | /* Only do DMA for entire blocks */ | ||
| 791 | use_dma = host->use_dma; | ||
| 792 | if (use_dma) { | ||
| 793 | for (i = 0; i < sg_len; i++) { | ||
| 794 | if ((data->sg[i].length % block_size) != 0) { | ||
| 795 | use_dma = 0; | ||
| 796 | break; | ||
| 797 | } | ||
| 798 | } | ||
| 799 | } | ||
| 800 | |||
| 801 | host->sg_idx = 0; | ||
| 802 | if (use_dma) { | ||
| 803 | if (mmc_omap_get_dma_channel(host, data) == 0) { | ||
| 804 | enum dma_data_direction dma_data_dir; | ||
| 805 | |||
| 806 | if (data->flags & MMC_DATA_WRITE) | ||
| 807 | dma_data_dir = DMA_TO_DEVICE; | ||
| 808 | else | ||
| 809 | dma_data_dir = DMA_FROM_DEVICE; | ||
| 810 | |||
| 811 | host->sg_len = dma_map_sg(mmc_dev(host->mmc), data->sg, | ||
| 812 | sg_len, dma_data_dir); | ||
| 813 | host->total_bytes_left = 0; | ||
| 814 | mmc_omap_prepare_dma(host, req->data); | ||
| 815 | host->brs_received = 0; | ||
| 816 | host->dma_done = 0; | ||
| 817 | host->dma_in_use = 1; | ||
| 818 | } else | ||
| 819 | use_dma = 0; | ||
| 820 | } | ||
| 821 | |||
| 822 | /* Revert to PIO? */ | ||
| 823 | if (!use_dma) { | ||
| 824 | OMAP_MMC_WRITE(host->base, BUF, 0x1f1f); | ||
| 825 | host->total_bytes_left = data->blocks * block_size; | ||
| 826 | host->sg_len = sg_len; | ||
| 827 | mmc_omap_sg_to_buf(host); | ||
| 828 | host->dma_in_use = 0; | ||
| 829 | } | ||
| 830 | } | ||
| 831 | |||
| 832 | static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req) | ||
| 833 | { | ||
| 834 | struct mmc_omap_host *host = mmc_priv(mmc); | ||
| 835 | |||
| 836 | WARN_ON(host->mrq != NULL); | ||
| 837 | |||
| 838 | host->mrq = req; | ||
| 839 | |||
| 840 | /* only touch fifo AFTER the controller readies it */ | ||
| 841 | mmc_omap_prepare_data(host, req); | ||
| 842 | mmc_omap_start_command(host, req->cmd); | ||
| 843 | if (host->dma_in_use) | ||
| 844 | omap_start_dma(host->dma_ch); | ||
| 845 | } | ||
| 846 | |||
| 847 | static void innovator_fpga_socket_power(int on) | ||
| 848 | { | ||
| 849 | #if defined(CONFIG_MACH_OMAP_INNOVATOR) && defined(CONFIG_ARCH_OMAP15XX) | ||
| 850 | |||
| 851 | if (on) { | ||
| 852 | fpga_write(fpga_read(OMAP1510_FPGA_POWER) | (1 << 3), | ||
| 853 | OMAP1510_FPGA_POWER); | ||
| 854 | } else { | ||
| 855 | fpga_write(fpga_read(OMAP1510_FPGA_POWER) & ~(1 << 3), | ||
| 856 | OMAP1510_FPGA_POWER); | ||
| 857 | } | ||
| 858 | #endif | ||
| 859 | } | ||
| 860 | |||
| 861 | /* | ||
| 862 | * Turn the socket power on/off. Innovator uses FPGA, most boards | ||
| 863 | * probably use GPIO. | ||
| 864 | */ | ||
| 865 | static void mmc_omap_power(struct mmc_omap_host *host, int on) | ||
| 866 | { | ||
| 867 | if (on) { | ||
| 868 | if (machine_is_omap_innovator()) | ||
| 869 | innovator_fpga_socket_power(1); | ||
| 870 | else if (machine_is_omap_h2()) | ||
| 871 | tps65010_set_gpio_out_value(GPIO3, HIGH); | ||
| 872 | else if (machine_is_omap_h3()) | ||
| 873 | /* GPIO 4 of TPS65010 sends SD_EN signal */ | ||
| 874 | tps65010_set_gpio_out_value(GPIO4, HIGH); | ||
| 875 | else if (cpu_is_omap24xx()) { | ||
| 876 | u16 reg = OMAP_MMC_READ(host->base, CON); | ||
| 877 | OMAP_MMC_WRITE(host->base, CON, reg | (1 << 11)); | ||
| 878 | } else | ||
| 879 | if (host->power_pin >= 0) | ||
| 880 | omap_set_gpio_dataout(host->power_pin, 1); | ||
| 881 | } else { | ||
| 882 | if (machine_is_omap_innovator()) | ||
| 883 | innovator_fpga_socket_power(0); | ||
| 884 | else if (machine_is_omap_h2()) | ||
| 885 | tps65010_set_gpio_out_value(GPIO3, LOW); | ||
| 886 | else if (machine_is_omap_h3()) | ||
| 887 | tps65010_set_gpio_out_value(GPIO4, LOW); | ||
| 888 | else if (cpu_is_omap24xx()) { | ||
| 889 | u16 reg = OMAP_MMC_READ(host->base, CON); | ||
| 890 | OMAP_MMC_WRITE(host->base, CON, reg & ~(1 << 11)); | ||
| 891 | } else | ||
| 892 | if (host->power_pin >= 0) | ||
| 893 | omap_set_gpio_dataout(host->power_pin, 0); | ||
| 894 | } | ||
| 895 | } | ||
| 896 | |||
| 897 | static void mmc_omap_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
| 898 | { | ||
| 899 | struct mmc_omap_host *host = mmc_priv(mmc); | ||
| 900 | int dsor; | ||
| 901 | int realclock, i; | ||
| 902 | |||
| 903 | realclock = ios->clock; | ||
| 904 | |||
| 905 | if (ios->clock == 0) | ||
| 906 | dsor = 0; | ||
| 907 | else { | ||
| 908 | int func_clk_rate = clk_get_rate(host->fclk); | ||
| 909 | |||
| 910 | dsor = func_clk_rate / realclock; | ||
| 911 | if (dsor < 1) | ||
| 912 | dsor = 1; | ||
| 913 | |||
| 914 | if (func_clk_rate / dsor > realclock) | ||
| 915 | dsor++; | ||
| 916 | |||
| 917 | if (dsor > 250) | ||
| 918 | dsor = 250; | ||
| 919 | dsor++; | ||
| 920 | |||
| 921 | if (ios->bus_width == MMC_BUS_WIDTH_4) | ||
| 922 | dsor |= 1 << 15; | ||
| 923 | } | ||
| 924 | |||
| 925 | switch (ios->power_mode) { | ||
| 926 | case MMC_POWER_OFF: | ||
| 927 | mmc_omap_power(host, 0); | ||
| 928 | break; | ||
| 929 | case MMC_POWER_UP: | ||
| 930 | case MMC_POWER_ON: | ||
| 931 | mmc_omap_power(host, 1); | ||
| 932 | dsor |= 1<<11; | ||
| 933 | break; | ||
| 934 | } | ||
| 935 | |||
| 936 | host->bus_mode = ios->bus_mode; | ||
| 937 | host->hw_bus_mode = host->bus_mode; | ||
| 938 | |||
| 939 | clk_enable(host->fclk); | ||
| 940 | |||
| 941 | /* On insanely high arm_per frequencies something sometimes | ||
| 942 | * goes somehow out of sync, and the POW bit is not being set, | ||
| 943 | * which results in the while loop below getting stuck. | ||
| 944 | * Writing to the CON register twice seems to do the trick. */ | ||
| 945 | for (i = 0; i < 2; i++) | ||
| 946 | OMAP_MMC_WRITE(host->base, CON, dsor); | ||
| 947 | if (ios->power_mode == MMC_POWER_UP) { | ||
| 948 | /* Send clock cycles, poll completion */ | ||
| 949 | OMAP_MMC_WRITE(host->base, IE, 0); | ||
| 950 | OMAP_MMC_WRITE(host->base, STAT, 0xffff); | ||
| 951 | OMAP_MMC_WRITE(host->base, CMD, 1<<7); | ||
| 952 | while (0 == (OMAP_MMC_READ(host->base, STAT) & 1)); | ||
| 953 | OMAP_MMC_WRITE(host->base, STAT, 1); | ||
| 954 | } | ||
| 955 | clk_disable(host->fclk); | ||
| 956 | } | ||
| 957 | |||
| 958 | static int mmc_omap_get_ro(struct mmc_host *mmc) | ||
| 959 | { | ||
| 960 | struct mmc_omap_host *host = mmc_priv(mmc); | ||
| 961 | |||
| 962 | return host->wp_pin && omap_get_gpio_datain(host->wp_pin); | ||
| 963 | } | ||
| 964 | |||
| 965 | static struct mmc_host_ops mmc_omap_ops = { | ||
| 966 | .request = mmc_omap_request, | ||
| 967 | .set_ios = mmc_omap_set_ios, | ||
| 968 | .get_ro = mmc_omap_get_ro, | ||
| 969 | }; | ||
| 970 | |||
| 971 | static int __init mmc_omap_probe(struct platform_device *pdev) | ||
| 972 | { | ||
| 973 | struct omap_mmc_conf *minfo = pdev->dev.platform_data; | ||
| 974 | struct mmc_host *mmc; | ||
| 975 | struct mmc_omap_host *host = NULL; | ||
| 976 | int ret = 0; | ||
| 977 | |||
| 978 | if (platform_get_resource(pdev, IORESOURCE_MEM, 0) || | ||
| 979 | platform_get_irq(pdev, IORESOURCE_IRQ, 0)) { | ||
| 980 | dev_err(&pdev->dev, "mmc_omap_probe: invalid resource type\n"); | ||
| 981 | return -ENODEV; | ||
| 982 | } | ||
| 983 | |||
| 984 | if (!request_mem_region(pdev->resource[0].start, | ||
| 985 | pdev->resource[0].end - pdev->resource[0].start + 1, | ||
| 986 | pdev->name)) { | ||
| 987 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); | ||
| 988 | return -EBUSY; | ||
| 989 | } | ||
| 990 | |||
| 991 | mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev); | ||
| 992 | if (!mmc) { | ||
| 993 | ret = -ENOMEM; | ||
| 994 | goto out; | ||
| 995 | } | ||
| 996 | |||
| 997 | host = mmc_priv(mmc); | ||
| 998 | host->mmc = mmc; | ||
| 999 | |||
| 1000 | spin_lock_init(&host->dma_lock); | ||
| 1001 | init_timer(&host->dma_timer); | ||
| 1002 | host->dma_timer.function = mmc_omap_dma_timer; | ||
| 1003 | host->dma_timer.data = (unsigned long) host; | ||
| 1004 | |||
| 1005 | host->id = pdev->id; | ||
| 1006 | |||
| 1007 | if (cpu_is_omap24xx()) { | ||
| 1008 | host->iclk = clk_get(&pdev->dev, "mmc_ick"); | ||
| 1009 | if (IS_ERR(host->iclk)) | ||
| 1010 | goto out; | ||
| 1011 | clk_enable(host->iclk); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | if (!cpu_is_omap24xx()) | ||
| 1015 | host->fclk = clk_get(&pdev->dev, "mmc_ck"); | ||
| 1016 | else | ||
| 1017 | host->fclk = clk_get(&pdev->dev, "mmc_fck"); | ||
| 1018 | |||
| 1019 | if (IS_ERR(host->fclk)) { | ||
| 1020 | ret = PTR_ERR(host->fclk); | ||
| 1021 | goto out; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | /* REVISIT: | ||
| 1025 | * Also, use minfo->cover to decide how to manage | ||
| 1026 | * the card detect sensing. | ||
| 1027 | */ | ||
| 1028 | host->power_pin = minfo->power_pin; | ||
| 1029 | host->switch_pin = minfo->switch_pin; | ||
| 1030 | host->wp_pin = minfo->wp_pin; | ||
| 1031 | host->use_dma = 1; | ||
| 1032 | host->dma_ch = -1; | ||
| 1033 | |||
| 1034 | host->irq = pdev->resource[1].start; | ||
| 1035 | host->base = ioremap(pdev->res.start, SZ_4K); | ||
| 1036 | if (!host->base) { | ||
| 1037 | ret = -ENOMEM; | ||
| 1038 | goto out; | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | if (minfo->wire4) | ||
| 1042 | mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
| 1043 | |||
| 1044 | mmc->ops = &mmc_omap_ops; | ||
| 1045 | mmc->f_min = 400000; | ||
| 1046 | mmc->f_max = 24000000; | ||
| 1047 | mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; | ||
| 1048 | |||
| 1049 | /* Use scatterlist DMA to reduce per-transfer costs. | ||
| 1050 | * NOTE max_seg_size assumption that small blocks aren't | ||
| 1051 | * normally used (except e.g. for reading SD registers). | ||
| 1052 | */ | ||
| 1053 | mmc->max_phys_segs = 32; | ||
| 1054 | mmc->max_hw_segs = 32; | ||
| 1055 | mmc->max_sectors = 256; /* NBLK max 11-bits, OMAP also limited by DMA */ | ||
| 1056 | mmc->max_seg_size = mmc->max_sectors * 512; | ||
| 1057 | |||
| 1058 | if (host->power_pin >= 0) { | ||
| 1059 | if ((ret = omap_request_gpio(host->power_pin)) != 0) { | ||
| 1060 | dev_err(mmc_dev(host->mmc), "Unable to get GPIO | ||
| 1061 | pin for MMC power\n"); | ||
| 1062 | goto out; | ||
| 1063 | } | ||
| 1064 | omap_set_gpio_direction(host->power_pin, 0); | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); | ||
| 1068 | if (ret) | ||
| 1069 | goto out; | ||
| 1070 | |||
| 1071 | host->dev = &pdev->dev; | ||
| 1072 | platform_set_drvdata(pdev, host); | ||
| 1073 | |||
| 1074 | mmc_add_host(mmc); | ||
| 1075 | |||
| 1076 | if (host->switch_pin >= 0) { | ||
| 1077 | INIT_WORK(&host->switch_work, mmc_omap_switch_handler, host); | ||
| 1078 | init_timer(&host->switch_timer); | ||
| 1079 | host->switch_timer.function = mmc_omap_switch_timer; | ||
| 1080 | host->switch_timer.data = (unsigned long) host; | ||
| 1081 | if (omap_request_gpio(host->switch_pin) != 0) { | ||
| 1082 | dev_warn(mmc_dev(host->mmc), "Unable to get GPIO pin for MMC cover switch\n"); | ||
| 1083 | host->switch_pin = -1; | ||
| 1084 | goto no_switch; | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | omap_set_gpio_direction(host->switch_pin, 1); | ||
| 1088 | ret = request_irq(OMAP_GPIO_IRQ(host->switch_pin), | ||
| 1089 | mmc_omap_switch_irq, SA_TRIGGER_RISING, DRIVER_NAME, host); | ||
| 1090 | if (ret) { | ||
| 1091 | dev_warn(mmc_dev(host->mmc), "Unable to get IRQ for MMC cover switch\n"); | ||
| 1092 | omap_free_gpio(host->switch_pin); | ||
| 1093 | host->switch_pin = -1; | ||
| 1094 | goto no_switch; | ||
| 1095 | } | ||
| 1096 | ret = device_create_file(&pdev->dev, &dev_attr_cover_switch); | ||
| 1097 | if (ret == 0) { | ||
| 1098 | ret = device_create_file(&pdev->dev, &dev_attr_enable_poll); | ||
| 1099 | if (ret != 0) | ||
| 1100 | device_remove_file(&pdev->dev, &dev_attr_cover_switch); | ||
| 1101 | } | ||
| 1102 | if (ret) { | ||
| 1103 | dev_wan(mmc_dev(host->mmc), "Unable to create sysfs attributes\n"); | ||
| 1104 | free_irq(OMAP_GPIO_IRQ(host->switch_pin), host); | ||
| 1105 | omap_free_gpio(host->switch_pin); | ||
| 1106 | host->switch_pin = -1; | ||
| 1107 | goto no_switch; | ||
| 1108 | } | ||
| 1109 | if (mmc_omap_enable_poll && mmc_omap_cover_is_open(host)) | ||
| 1110 | schedule_work(&host->switch_work); | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | no_switch: | ||
| 1114 | return 0; | ||
| 1115 | |||
| 1116 | out: | ||
| 1117 | /* FIXME: Free other resources too. */ | ||
| 1118 | if (host) { | ||
| 1119 | if (host->iclk && !IS_ERR(host->iclk)) | ||
| 1120 | clk_put(host->iclk); | ||
| 1121 | if (host->fclk && !IS_ERR(host->fclk)) | ||
| 1122 | clk_put(host->fclk); | ||
| 1123 | mmc_free_host(host->mmc); | ||
| 1124 | } | ||
| 1125 | return ret; | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | static int mmc_omap_remove(struct platform_device *pdev) | ||
| 1129 | { | ||
| 1130 | struct mmc_omap_host *host = platform_get_drvdata(pdev); | ||
| 1131 | |||
| 1132 | platform_set_drvdata(pdev, NULL); | ||
| 1133 | |||
| 1134 | if (host) { | ||
| 1135 | mmc_remove_host(host->mmc); | ||
| 1136 | free_irq(host->irq, host); | ||
| 1137 | |||
| 1138 | if (host->power_pin >= 0) | ||
| 1139 | omap_free_gpio(host->power_pin); | ||
| 1140 | if (host->switch_pin >= 0) { | ||
| 1141 | device_remove_file(&pdev->dev, &dev_attr_enable_poll); | ||
| 1142 | device_remove_file(&pdev->dev, &dev_attr_cover_switch); | ||
| 1143 | free_irq(OMAP_GPIO_IRQ(host->switch_pin), host); | ||
| 1144 | omap_free_gpio(host->switch_pin); | ||
| 1145 | host->switch_pin = -1; | ||
| 1146 | del_timer_sync(&host->switch_timer); | ||
| 1147 | flush_scheduled_work(); | ||
| 1148 | } | ||
| 1149 | if (host->iclk && !IS_ERR(host->iclk)) | ||
| 1150 | clk_put(host->iclk); | ||
| 1151 | if (host->fclk && !IS_ERR(host->fclk)) | ||
| 1152 | clk_put(host->fclk); | ||
| 1153 | mmc_free_host(host->mmc); | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | release_mem_region(pdev->resource[0].start, | ||
| 1157 | pdev->resource[0].end - pdev->resource[0].start + 1); | ||
| 1158 | |||
| 1159 | return 0; | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | #ifdef CONFIG_PM | ||
| 1163 | static int mmc_omap_suspend(struct platform_device *pdev, pm_message_t mesg) | ||
| 1164 | { | ||
| 1165 | int ret = 0; | ||
| 1166 | struct mmc_omap_host *host = platform_get_drvdata(pdev); | ||
| 1167 | |||
| 1168 | if (host && host->suspended) | ||
| 1169 | return 0; | ||
| 1170 | |||
| 1171 | if (host) { | ||
| 1172 | ret = mmc_suspend_host(host->mmc, mesg); | ||
| 1173 | if (ret == 0) | ||
| 1174 | host->suspended = 1; | ||
| 1175 | } | ||
| 1176 | return ret; | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | static int mmc_omap_resume(struct platform_device *pdev) | ||
| 1180 | { | ||
| 1181 | int ret = 0; | ||
| 1182 | struct mmc_omap_host *host = platform_get_drvdata(pdev); | ||
| 1183 | |||
| 1184 | if (host && !host->suspended) | ||
| 1185 | return 0; | ||
| 1186 | |||
| 1187 | if (host) { | ||
| 1188 | ret = mmc_resume_host(host->mmc); | ||
| 1189 | if (ret == 0) | ||
| 1190 | host->suspended = 0; | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | return ret; | ||
| 1194 | } | ||
| 1195 | #else | ||
| 1196 | #define mmc_omap_suspend NULL | ||
| 1197 | #define mmc_omap_resume NULL | ||
| 1198 | #endif | ||
| 1199 | |||
| 1200 | static struct platform_driver mmc_omap_driver = { | ||
| 1201 | .probe = mmc_omap_probe, | ||
| 1202 | .remove = mmc_omap_remove, | ||
| 1203 | .suspend = mmc_omap_suspend, | ||
| 1204 | .resume = mmc_omap_resume, | ||
| 1205 | .driver = { | ||
| 1206 | .name = DRIVER_NAME, | ||
| 1207 | }, | ||
| 1208 | }; | ||
| 1209 | |||
| 1210 | static int __init mmc_omap_init(void) | ||
| 1211 | { | ||
| 1212 | return platform_driver_register(&mmc_omap_driver); | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | static void __exit mmc_omap_exit(void) | ||
| 1216 | { | ||
| 1217 | platform_driver_unregister(&mmc_omap_driver); | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | module_init(mmc_omap_init); | ||
| 1221 | module_exit(mmc_omap_exit); | ||
| 1222 | |||
| 1223 | MODULE_DESCRIPTION("OMAP Multimedia Card driver"); | ||
| 1224 | MODULE_LICENSE("GPL"); | ||
| 1225 | MODULE_ALIAS(DRIVER_NAME); | ||
| 1226 | MODULE_AUTHOR("Juha Yrjölä"); | ||
diff --git a/drivers/mmc/omap.h b/drivers/mmc/omap.h new file mode 100644 index 000000000000..c954d355a5e3 --- /dev/null +++ b/drivers/mmc/omap.h | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #ifndef DRIVERS_MEDIA_MMC_OMAP_H | ||
| 2 | #define DRIVERS_MEDIA_MMC_OMAP_H | ||
| 3 | |||
| 4 | #define OMAP_MMC_REG_CMD 0x00 | ||
| 5 | #define OMAP_MMC_REG_ARGL 0x04 | ||
| 6 | #define OMAP_MMC_REG_ARGH 0x08 | ||
| 7 | #define OMAP_MMC_REG_CON 0x0c | ||
| 8 | #define OMAP_MMC_REG_STAT 0x10 | ||
| 9 | #define OMAP_MMC_REG_IE 0x14 | ||
| 10 | #define OMAP_MMC_REG_CTO 0x18 | ||
| 11 | #define OMAP_MMC_REG_DTO 0x1c | ||
| 12 | #define OMAP_MMC_REG_DATA 0x20 | ||
| 13 | #define OMAP_MMC_REG_BLEN 0x24 | ||
| 14 | #define OMAP_MMC_REG_NBLK 0x28 | ||
| 15 | #define OMAP_MMC_REG_BUF 0x2c | ||
| 16 | #define OMAP_MMC_REG_SDIO 0x34 | ||
| 17 | #define OMAP_MMC_REG_REV 0x3c | ||
| 18 | #define OMAP_MMC_REG_RSP0 0x40 | ||
| 19 | #define OMAP_MMC_REG_RSP1 0x44 | ||
| 20 | #define OMAP_MMC_REG_RSP2 0x48 | ||
| 21 | #define OMAP_MMC_REG_RSP3 0x4c | ||
| 22 | #define OMAP_MMC_REG_RSP4 0x50 | ||
| 23 | #define OMAP_MMC_REG_RSP5 0x54 | ||
| 24 | #define OMAP_MMC_REG_RSP6 0x58 | ||
| 25 | #define OMAP_MMC_REG_RSP7 0x5c | ||
| 26 | #define OMAP_MMC_REG_IOSR 0x60 | ||
| 27 | #define OMAP_MMC_REG_SYSC 0x64 | ||
| 28 | #define OMAP_MMC_REG_SYSS 0x68 | ||
| 29 | |||
| 30 | #define OMAP_MMC_STAT_CARD_ERR (1 << 14) | ||
| 31 | #define OMAP_MMC_STAT_CARD_IRQ (1 << 13) | ||
| 32 | #define OMAP_MMC_STAT_OCR_BUSY (1 << 12) | ||
| 33 | #define OMAP_MMC_STAT_A_EMPTY (1 << 11) | ||
| 34 | #define OMAP_MMC_STAT_A_FULL (1 << 10) | ||
| 35 | #define OMAP_MMC_STAT_CMD_CRC (1 << 8) | ||
| 36 | #define OMAP_MMC_STAT_CMD_TOUT (1 << 7) | ||
| 37 | #define OMAP_MMC_STAT_DATA_CRC (1 << 6) | ||
| 38 | #define OMAP_MMC_STAT_DATA_TOUT (1 << 5) | ||
| 39 | #define OMAP_MMC_STAT_END_BUSY (1 << 4) | ||
| 40 | #define OMAP_MMC_STAT_END_OF_DATA (1 << 3) | ||
| 41 | #define OMAP_MMC_STAT_CARD_BUSY (1 << 2) | ||
| 42 | #define OMAP_MMC_STAT_END_OF_CMD (1 << 0) | ||
| 43 | |||
| 44 | #define OMAP_MMC_READ(base, reg) __raw_readw((base) + OMAP_MMC_REG_##reg) | ||
| 45 | #define OMAP_MMC_WRITE(base, reg, val) __raw_writew((val), (base) + OMAP_MMC_REG_##reg) | ||
| 46 | |||
| 47 | /* | ||
| 48 | * Command types | ||
| 49 | */ | ||
| 50 | #define OMAP_MMC_CMDTYPE_BC 0 | ||
| 51 | #define OMAP_MMC_CMDTYPE_BCR 1 | ||
| 52 | #define OMAP_MMC_CMDTYPE_AC 2 | ||
| 53 | #define OMAP_MMC_CMDTYPE_ADTC 3 | ||
| 54 | |||
| 55 | #endif | ||
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c index c32fad1ce51c..eb9a8826e9b5 100644 --- a/drivers/mmc/pxamci.c +++ b/drivers/mmc/pxamci.c | |||
| @@ -37,12 +37,6 @@ | |||
| 37 | 37 | ||
| 38 | #include "pxamci.h" | 38 | #include "pxamci.h" |
| 39 | 39 | ||
| 40 | #ifdef CONFIG_MMC_DEBUG | ||
| 41 | #define DBG(x...) printk(KERN_DEBUG x) | ||
| 42 | #else | ||
| 43 | #define DBG(x...) do { } while (0) | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #define DRIVER_NAME "pxa2xx-mci" | 40 | #define DRIVER_NAME "pxa2xx-mci" |
| 47 | 41 | ||
| 48 | #define NR_SG 1 | 42 | #define NR_SG 1 |
| @@ -206,7 +200,7 @@ static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd, | |||
| 206 | 200 | ||
| 207 | static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq) | 201 | static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq) |
| 208 | { | 202 | { |
| 209 | DBG("PXAMCI: request done\n"); | 203 | pr_debug("PXAMCI: request done\n"); |
| 210 | host->mrq = NULL; | 204 | host->mrq = NULL; |
| 211 | host->cmd = NULL; | 205 | host->cmd = NULL; |
| 212 | host->data = NULL; | 206 | host->data = NULL; |
| @@ -252,7 +246,7 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat) | |||
| 252 | if ((cmd->resp[0] & 0x80000000) == 0) | 246 | if ((cmd->resp[0] & 0x80000000) == 0) |
| 253 | cmd->error = MMC_ERR_BADCRC; | 247 | cmd->error = MMC_ERR_BADCRC; |
| 254 | } else { | 248 | } else { |
| 255 | DBG("ignoring CRC from command %d - *risky*\n",cmd->opcode); | 249 | pr_debug("ignoring CRC from command %d - *risky*\n",cmd->opcode); |
| 256 | } | 250 | } |
| 257 | #else | 251 | #else |
| 258 | cmd->error = MMC_ERR_BADCRC; | 252 | cmd->error = MMC_ERR_BADCRC; |
| @@ -317,12 +311,12 @@ static irqreturn_t pxamci_irq(int irq, void *devid, struct pt_regs *regs) | |||
| 317 | 311 | ||
| 318 | ireg = readl(host->base + MMC_I_REG); | 312 | ireg = readl(host->base + MMC_I_REG); |
| 319 | 313 | ||
| 320 | DBG("PXAMCI: irq %08x\n", ireg); | 314 | pr_debug("PXAMCI: irq %08x\n", ireg); |
| 321 | 315 | ||
| 322 | if (ireg) { | 316 | if (ireg) { |
| 323 | unsigned stat = readl(host->base + MMC_STAT); | 317 | unsigned stat = readl(host->base + MMC_STAT); |
| 324 | 318 | ||
| 325 | DBG("PXAMCI: stat %08x\n", stat); | 319 | pr_debug("PXAMCI: stat %08x\n", stat); |
| 326 | 320 | ||
| 327 | if (ireg & END_CMD_RES) | 321 | if (ireg & END_CMD_RES) |
| 328 | handled |= pxamci_cmd_done(host, stat); | 322 | handled |= pxamci_cmd_done(host, stat); |
| @@ -376,9 +370,9 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 376 | { | 370 | { |
| 377 | struct pxamci_host *host = mmc_priv(mmc); | 371 | struct pxamci_host *host = mmc_priv(mmc); |
| 378 | 372 | ||
| 379 | DBG("pxamci_set_ios: clock %u power %u vdd %u.%02u\n", | 373 | pr_debug("pxamci_set_ios: clock %u power %u vdd %u.%02u\n", |
| 380 | ios->clock, ios->power_mode, ios->vdd / 100, | 374 | ios->clock, ios->power_mode, ios->vdd / 100, |
| 381 | ios->vdd % 100); | 375 | ios->vdd % 100); |
| 382 | 376 | ||
| 383 | if (ios->clock) { | 377 | if (ios->clock) { |
| 384 | unsigned int clk = CLOCKRATE / ios->clock; | 378 | unsigned int clk = CLOCKRATE / ios->clock; |
| @@ -405,8 +399,8 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 405 | host->cmdat |= CMDAT_INIT; | 399 | host->cmdat |= CMDAT_INIT; |
| 406 | } | 400 | } |
| 407 | 401 | ||
| 408 | DBG("pxamci_set_ios: clkrt = %x cmdat = %x\n", | 402 | pr_debug("pxamci_set_ios: clkrt = %x cmdat = %x\n", |
| 409 | host->clkrt, host->cmdat); | 403 | host->clkrt, host->cmdat); |
| 410 | } | 404 | } |
| 411 | 405 | ||
| 412 | static struct mmc_host_ops pxamci_ops = { | 406 | static struct mmc_host_ops pxamci_ops = { |
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 8b811d94371c..bdbfca050029 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c | |||
| @@ -31,12 +31,8 @@ | |||
| 31 | 31 | ||
| 32 | #define BUGMAIL "<sdhci-devel@list.drzeus.cx>" | 32 | #define BUGMAIL "<sdhci-devel@list.drzeus.cx>" |
| 33 | 33 | ||
| 34 | #ifdef CONFIG_MMC_DEBUG | ||
| 35 | #define DBG(f, x...) \ | 34 | #define DBG(f, x...) \ |
| 36 | printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__,## x) | 35 | pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) |
| 37 | #else | ||
| 38 | #define DBG(f, x...) do { } while (0) | ||
| 39 | #endif | ||
| 40 | 36 | ||
| 41 | static const struct pci_device_id pci_ids[] __devinitdata = { | 37 | static const struct pci_device_id pci_ids[] __devinitdata = { |
| 42 | /* handle any SD host controller */ | 38 | /* handle any SD host controller */ |
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c index 3be397d436fa..511f7b0b31d2 100644 --- a/drivers/mmc/wbsd.c +++ b/drivers/mmc/wbsd.c | |||
| @@ -44,15 +44,10 @@ | |||
| 44 | #define DRIVER_NAME "wbsd" | 44 | #define DRIVER_NAME "wbsd" |
| 45 | #define DRIVER_VERSION "1.5" | 45 | #define DRIVER_VERSION "1.5" |
| 46 | 46 | ||
| 47 | #ifdef CONFIG_MMC_DEBUG | ||
| 48 | #define DBG(x...) \ | 47 | #define DBG(x...) \ |
| 49 | printk(KERN_DEBUG DRIVER_NAME ": " x) | 48 | pr_debug(DRIVER_NAME ": " x) |
| 50 | #define DBGF(f, x...) \ | 49 | #define DBGF(f, x...) \ |
| 51 | printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__ , ##x) | 50 | pr_debug(DRIVER_NAME " [%s()]: " f, __func__ , ##x) |
| 52 | #else | ||
| 53 | #define DBG(x...) do { } while (0) | ||
| 54 | #define DBGF(x...) do { } while (0) | ||
| 55 | #endif | ||
| 56 | 51 | ||
| 57 | /* | 52 | /* |
| 58 | * Device resources | 53 | * Device resources |
