Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 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 | /* |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 14 | This is the AT91 MCI driver that has been tested with both MMC cards |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 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. |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 41 | Due to a bug in the AT91RM9200 controller, when a read is completed, all the words are byte |
| 42 | swapped in the scatterlist buffers. AT91SAM926x are not affected by this bug. |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 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 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 56 | #include <linux/module.h> |
| 57 | #include <linux/moduleparam.h> |
| 58 | #include <linux/init.h> |
| 59 | #include <linux/ioport.h> |
| 60 | #include <linux/platform_device.h> |
| 61 | #include <linux/interrupt.h> |
| 62 | #include <linux/blkdev.h> |
| 63 | #include <linux/delay.h> |
| 64 | #include <linux/err.h> |
| 65 | #include <linux/dma-mapping.h> |
| 66 | #include <linux/clk.h> |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 67 | #include <linux/atmel_pdc.h> |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 68 | |
| 69 | #include <linux/mmc/host.h> |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 70 | |
| 71 | #include <asm/io.h> |
| 72 | #include <asm/irq.h> |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 73 | #include <asm/gpio.h> |
| 74 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 75 | #include <mach/board.h> |
| 76 | #include <mach/cpu.h> |
| 77 | #include <mach/at91_mci.h> |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 78 | |
| 79 | #define DRIVER_NAME "at91_mci" |
| 80 | |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 81 | static inline int at91mci_is_mci1rev2xx(void) |
| 82 | { |
| 83 | return ( cpu_is_at91sam9260() |
| 84 | || cpu_is_at91sam9263() |
| 85 | || cpu_is_at91cap9() |
| 86 | || cpu_is_at91sam9rl() |
| 87 | || cpu_is_at91sam9g10() |
| 88 | || cpu_is_at91sam9g20() |
| 89 | ); |
| 90 | } |
| 91 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 92 | #define FL_SENT_COMMAND (1 << 0) |
| 93 | #define FL_SENT_STOP (1 << 1) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 94 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 95 | #define AT91_MCI_ERRORS (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE \ |
| 96 | | AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE \ |
Nicolas Ferre | 37b758e | 2007-08-08 12:01:44 +0200 | [diff] [blame] | 97 | | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 98 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 99 | #define at91_mci_read(host, reg) __raw_readl((host)->baseaddr + (reg)) |
| 100 | #define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg)) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 101 | |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 102 | #define MCI_BLKSIZE 512 |
| 103 | #define MCI_MAXBLKSIZE 4095 |
| 104 | #define MCI_BLKATONCE 256 |
| 105 | #define MCI_BUFSIZE (MCI_BLKSIZE * MCI_BLKATONCE) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Low level type for this driver |
| 109 | */ |
| 110 | struct at91mci_host |
| 111 | { |
| 112 | struct mmc_host *mmc; |
| 113 | struct mmc_command *cmd; |
| 114 | struct mmc_request *request; |
| 115 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 116 | void __iomem *baseaddr; |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 117 | int irq; |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 118 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 119 | struct at91_mmc_data *board; |
| 120 | int present; |
| 121 | |
Andrew Victor | 3dd3b03 | 2006-10-23 14:46:54 +0200 | [diff] [blame] | 122 | struct clk *mci_clk; |
| 123 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 124 | /* |
| 125 | * Flag indicating when the command has been sent. This is used to |
| 126 | * work out whether or not to send the stop |
| 127 | */ |
| 128 | unsigned int flags; |
| 129 | /* flag for current bus settings */ |
| 130 | u32 bus_mode; |
| 131 | |
| 132 | /* DMA buffer used for transmitting */ |
| 133 | unsigned int* buffer; |
| 134 | dma_addr_t physical_address; |
| 135 | unsigned int total_length; |
| 136 | |
| 137 | /* Latest in the scatterlist that has been enabled for transfer, but not freed */ |
| 138 | int in_use_index; |
| 139 | |
| 140 | /* Latest in the scatterlist that has been enabled for transfer */ |
| 141 | int transfer_index; |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 142 | |
| 143 | /* Timer for timeouts */ |
| 144 | struct timer_list timer; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 145 | }; |
| 146 | |
Marc Pignat | c5a89c6 | 2008-05-30 14:07:47 +0200 | [diff] [blame] | 147 | /* |
| 148 | * Reset the controller and restore most of the state |
| 149 | */ |
| 150 | static void at91_reset_host(struct at91mci_host *host) |
| 151 | { |
| 152 | unsigned long flags; |
| 153 | u32 mr; |
| 154 | u32 sdcr; |
| 155 | u32 dtor; |
| 156 | u32 imr; |
| 157 | |
| 158 | local_irq_save(flags); |
| 159 | imr = at91_mci_read(host, AT91_MCI_IMR); |
| 160 | |
| 161 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff); |
| 162 | |
| 163 | /* save current state */ |
| 164 | mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; |
| 165 | sdcr = at91_mci_read(host, AT91_MCI_SDCR); |
| 166 | dtor = at91_mci_read(host, AT91_MCI_DTOR); |
| 167 | |
| 168 | /* reset the controller */ |
| 169 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST); |
| 170 | |
| 171 | /* restore state */ |
| 172 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN); |
| 173 | at91_mci_write(host, AT91_MCI_MR, mr); |
| 174 | at91_mci_write(host, AT91_MCI_SDCR, sdcr); |
| 175 | at91_mci_write(host, AT91_MCI_DTOR, dtor); |
| 176 | at91_mci_write(host, AT91_MCI_IER, imr); |
| 177 | |
| 178 | /* make sure sdio interrupts will fire */ |
| 179 | at91_mci_read(host, AT91_MCI_SR); |
| 180 | |
| 181 | local_irq_restore(flags); |
| 182 | } |
| 183 | |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 184 | static void at91_timeout_timer(unsigned long data) |
| 185 | { |
| 186 | struct at91mci_host *host; |
| 187 | |
| 188 | host = (struct at91mci_host *)data; |
| 189 | |
| 190 | if (host->request) { |
| 191 | dev_err(host->mmc->parent, "Timeout waiting end of packet\n"); |
| 192 | |
| 193 | if (host->cmd && host->cmd->data) { |
| 194 | host->cmd->data->error = -ETIMEDOUT; |
| 195 | } else { |
| 196 | if (host->cmd) |
| 197 | host->cmd->error = -ETIMEDOUT; |
| 198 | else |
| 199 | host->request->cmd->error = -ETIMEDOUT; |
| 200 | } |
| 201 | |
Marc Pignat | c5a89c6 | 2008-05-30 14:07:47 +0200 | [diff] [blame] | 202 | at91_reset_host(host); |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 203 | mmc_request_done(host->mmc, host->request); |
| 204 | } |
| 205 | } |
| 206 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 207 | /* |
| 208 | * Copy from sg to a dma block - used for transfers |
| 209 | */ |
Nicolas Ferre | e8d04d3 | 2007-06-19 18:32:34 +0200 | [diff] [blame] | 210 | static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 211 | { |
| 212 | unsigned int len, i, size; |
| 213 | unsigned *dmabuf = host->buffer; |
| 214 | |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 215 | size = data->blksz * data->blocks; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 216 | len = data->sg_len; |
| 217 | |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 218 | /* MCI1 rev2xx Data Write Operation and number of bytes erratum */ |
| 219 | if (at91mci_is_mci1rev2xx()) |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 220 | if (host->total_length == 12) |
| 221 | memset(dmabuf, 0, 12); |
| 222 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 223 | /* |
| 224 | * Just loop through all entries. Size might not |
| 225 | * be the entire list though so make sure that |
| 226 | * we do not transfer too much. |
| 227 | */ |
| 228 | for (i = 0; i < len; i++) { |
| 229 | struct scatterlist *sg; |
| 230 | int amount; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 231 | unsigned int *sgbuffer; |
| 232 | |
| 233 | sg = &data->sg[i]; |
| 234 | |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 235 | sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 236 | amount = min(size, sg->length); |
| 237 | size -= amount; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 238 | |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 239 | if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */ |
| 240 | int index; |
| 241 | |
| 242 | for (index = 0; index < (amount / 4); index++) |
| 243 | *dmabuf++ = swab32(sgbuffer[index]); |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 244 | } else { |
Wolfgang Muees | 0b3520f | 2010-03-05 13:43:38 -0800 | [diff] [blame] | 245 | char *tmpv = (char *)dmabuf; |
| 246 | memcpy(tmpv, sgbuffer, amount); |
| 247 | tmpv += amount; |
| 248 | dmabuf = (unsigned *)tmpv; |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 249 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 250 | |
Nicolas Ferre | 752993e | 2010-03-05 13:43:45 -0800 | [diff] [blame] | 251 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 252 | |
| 253 | if (size == 0) |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Check that we didn't get a request to transfer |
| 259 | * more data than can fit into the SG list. |
| 260 | */ |
| 261 | BUG_ON(size != 0); |
| 262 | } |
| 263 | |
| 264 | /* |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 265 | * Handle after a dma read |
| 266 | */ |
Nicolas Ferre | e8d04d3 | 2007-06-19 18:32:34 +0200 | [diff] [blame] | 267 | static void at91_mci_post_dma_read(struct at91mci_host *host) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 268 | { |
| 269 | struct mmc_command *cmd; |
| 270 | struct mmc_data *data; |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 271 | unsigned int len, i, size; |
| 272 | unsigned *dmabuf = host->buffer; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 273 | |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 274 | pr_debug("post dma read\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 275 | |
| 276 | cmd = host->cmd; |
| 277 | if (!cmd) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 278 | pr_debug("no command\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 279 | return; |
| 280 | } |
| 281 | |
| 282 | data = cmd->data; |
| 283 | if (!data) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 284 | pr_debug("no data\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 288 | size = data->blksz * data->blocks; |
| 289 | len = data->sg_len; |
| 290 | |
| 291 | at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX); |
| 292 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF); |
| 293 | |
| 294 | for (i = 0; i < len; i++) { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 295 | struct scatterlist *sg; |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 296 | int amount; |
| 297 | unsigned int *sgbuffer; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 298 | |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 299 | sg = &data->sg[i]; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 300 | |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 301 | sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; |
| 302 | amount = min(size, sg->length); |
| 303 | size -= amount; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 304 | |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 305 | if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */ |
| 306 | int index; |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 307 | for (index = 0; index < (amount / 4); index++) |
| 308 | sgbuffer[index] = swab32(*dmabuf++); |
| 309 | } else { |
| 310 | char *tmpv = (char *)dmabuf; |
| 311 | memcpy(sgbuffer, tmpv, amount); |
| 312 | tmpv += amount; |
| 313 | dmabuf = (unsigned *)tmpv; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 314 | } |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 315 | |
Nicolas Ferre | 752993e | 2010-03-05 13:43:45 -0800 | [diff] [blame] | 316 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 317 | dmac_flush_range((void *)sgbuffer, ((void *)sgbuffer) + amount); |
| 318 | data->bytes_xfered += amount; |
| 319 | if (size == 0) |
| 320 | break; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 323 | pr_debug("post dma read done\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 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 | |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 334 | pr_debug("Handling the transmit\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 335 | |
| 336 | /* Disable the transfer */ |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 337 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 338 | |
| 339 | /* Now wait for cmd ready */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 340 | at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 341 | |
| 342 | cmd = host->cmd; |
| 343 | if (!cmd) return; |
| 344 | |
| 345 | data = cmd->data; |
| 346 | if (!data) return; |
| 347 | |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 348 | if (cmd->data->blocks > 1) { |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 349 | pr_debug("multiple write : wait for BLKE...\n"); |
| 350 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE); |
| 351 | } else |
| 352 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Nicolas Ferre | 4ac24a8 | 2008-05-30 14:18:57 +0200 | [diff] [blame] | 355 | /* |
| 356 | * Update bytes tranfered count during a write operation |
| 357 | */ |
| 358 | static void at91_mci_update_bytes_xfered(struct at91mci_host *host) |
| 359 | { |
| 360 | struct mmc_data *data; |
| 361 | |
| 362 | /* always deal with the effective request (and not the current cmd) */ |
| 363 | |
| 364 | if (host->request->cmd && host->request->cmd->error != 0) |
| 365 | return; |
| 366 | |
| 367 | if (host->request->data) { |
| 368 | data = host->request->data; |
| 369 | if (data->flags & MMC_DATA_WRITE) { |
| 370 | /* card is in IDLE mode now */ |
| 371 | pr_debug("-> bytes_xfered %d, total_length = %d\n", |
| 372 | data->bytes_xfered, host->total_length); |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 373 | data->bytes_xfered = data->blksz * data->blocks; |
Nicolas Ferre | 4ac24a8 | 2008-05-30 14:18:57 +0200 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 379 | /*Handle after command sent ready*/ |
| 380 | static int at91_mci_handle_cmdrdy(struct at91mci_host *host) |
| 381 | { |
| 382 | if (!host->cmd) |
| 383 | return 1; |
| 384 | else if (!host->cmd->data) { |
| 385 | if (host->flags & FL_SENT_STOP) { |
| 386 | /*After multi block write, we must wait for NOTBUSY*/ |
| 387 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); |
| 388 | } else return 1; |
| 389 | } else if (host->cmd->data->flags & MMC_DATA_WRITE) { |
| 390 | /*After sendding multi-block-write command, start DMA transfer*/ |
Nicolas Ferre | 4ac24a8 | 2008-05-30 14:18:57 +0200 | [diff] [blame] | 391 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE | AT91_MCI_BLKE); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 392 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); |
| 393 | } |
| 394 | |
| 395 | /* command not completed, have to wait */ |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 400 | /* |
| 401 | * Enable the controller |
| 402 | */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 403 | static void at91_mci_enable(struct at91mci_host *host) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 404 | { |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 405 | unsigned int mr; |
| 406 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 407 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN); |
Andrew Victor | f3a8efa | 2006-10-23 14:53:20 +0200 | [diff] [blame] | 408 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff); |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 409 | at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 410 | mr = AT91_MCI_PDCMODE | 0x34a; |
| 411 | |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 412 | if (at91mci_is_mci1rev2xx()) |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 413 | mr |= AT91_MCI_RDPROOF | AT91_MCI_WRPROOF; |
| 414 | |
| 415 | at91_mci_write(host, AT91_MCI_MR, mr); |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 416 | |
| 417 | /* use Slot A or B (only one at same time) */ |
| 418 | at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Disable the controller |
| 423 | */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 424 | static void at91_mci_disable(struct at91mci_host *host) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 425 | { |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 426 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Send a command |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 431 | */ |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 432 | static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 433 | { |
| 434 | unsigned int cmdr, mr; |
| 435 | unsigned int block_length; |
| 436 | struct mmc_data *data = cmd->data; |
| 437 | |
| 438 | unsigned int blocks; |
| 439 | unsigned int ier = 0; |
| 440 | |
| 441 | host->cmd = cmd; |
| 442 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 443 | /* Needed for leaving busy state before CMD1 */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 444 | if ((at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 445 | pr_debug("Clearing timeout\n"); |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 446 | at91_mci_write(host, AT91_MCI_ARGR, 0); |
| 447 | at91_mci_write(host, AT91_MCI_CMDR, AT91_MCI_OPDCMD); |
| 448 | while (!(at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_CMDRDY)) { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 449 | /* spin */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 450 | pr_debug("Clearing: SR = %08X\n", at91_mci_read(host, AT91_MCI_SR)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 451 | } |
| 452 | } |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 453 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 454 | cmdr = cmd->opcode; |
| 455 | |
| 456 | if (mmc_resp_type(cmd) == MMC_RSP_NONE) |
| 457 | cmdr |= AT91_MCI_RSPTYP_NONE; |
| 458 | else { |
| 459 | /* if a response is expected then allow maximum response latancy */ |
| 460 | cmdr |= AT91_MCI_MAXLAT; |
| 461 | /* set 136 bit response for R2, 48 bit response otherwise */ |
| 462 | if (mmc_resp_type(cmd) == MMC_RSP_R2) |
| 463 | cmdr |= AT91_MCI_RSPTYP_136; |
| 464 | else |
| 465 | cmdr |= AT91_MCI_RSPTYP_48; |
| 466 | } |
| 467 | |
| 468 | if (data) { |
Marc Pignat | 1d4de9e | 2007-08-09 13:56:29 +0200 | [diff] [blame] | 469 | |
Ville Syrjala | 9da3cba | 2008-06-09 22:06:44 +0300 | [diff] [blame] | 470 | if (cpu_is_at91rm9200() || cpu_is_at91sam9261()) { |
| 471 | if (data->blksz & 0x3) { |
| 472 | pr_debug("Unsupported block size\n"); |
| 473 | cmd->error = -EINVAL; |
| 474 | mmc_request_done(host->mmc, host->request); |
| 475 | return; |
| 476 | } |
| 477 | if (data->flags & MMC_DATA_STREAM) { |
| 478 | pr_debug("Stream commands not supported\n"); |
| 479 | cmd->error = -EINVAL; |
| 480 | mmc_request_done(host->mmc, host->request); |
| 481 | return; |
| 482 | } |
Marc Pignat | 1d4de9e | 2007-08-09 13:56:29 +0200 | [diff] [blame] | 483 | } |
| 484 | |
Russell King | a3fd4a1 | 2006-06-04 17:51:15 +0100 | [diff] [blame] | 485 | block_length = data->blksz; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 486 | blocks = data->blocks; |
| 487 | |
| 488 | /* always set data start - also set direction flag for read */ |
| 489 | if (data->flags & MMC_DATA_READ) |
| 490 | cmdr |= (AT91_MCI_TRDIR | AT91_MCI_TRCMD_START); |
| 491 | else if (data->flags & MMC_DATA_WRITE) |
| 492 | cmdr |= AT91_MCI_TRCMD_START; |
| 493 | |
| 494 | if (data->flags & MMC_DATA_STREAM) |
| 495 | cmdr |= AT91_MCI_TRTYP_STREAM; |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 496 | if (data->blocks > 1) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 497 | cmdr |= AT91_MCI_TRTYP_MULTIPLE; |
| 498 | } |
| 499 | else { |
| 500 | block_length = 0; |
| 501 | blocks = 0; |
| 502 | } |
| 503 | |
Marc Pignat | b6cedb3 | 2007-06-06 20:27:59 +0200 | [diff] [blame] | 504 | if (host->flags & FL_SENT_STOP) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 505 | cmdr |= AT91_MCI_TRCMD_STOP; |
| 506 | |
| 507 | if (host->bus_mode == MMC_BUSMODE_OPENDRAIN) |
| 508 | cmdr |= AT91_MCI_OPDCMD; |
| 509 | |
| 510 | /* |
| 511 | * Set the arguments and send the command |
| 512 | */ |
Andrew Victor | f3a8efa | 2006-10-23 14:53:20 +0200 | [diff] [blame] | 513 | pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08X)\n", |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 514 | cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 515 | |
| 516 | if (!data) { |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 517 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS | ATMEL_PDC_RXTDIS); |
| 518 | at91_mci_write(host, ATMEL_PDC_RPR, 0); |
| 519 | at91_mci_write(host, ATMEL_PDC_RCR, 0); |
| 520 | at91_mci_write(host, ATMEL_PDC_RNPR, 0); |
| 521 | at91_mci_write(host, ATMEL_PDC_RNCR, 0); |
| 522 | at91_mci_write(host, ATMEL_PDC_TPR, 0); |
| 523 | at91_mci_write(host, ATMEL_PDC_TCR, 0); |
| 524 | at91_mci_write(host, ATMEL_PDC_TNPR, 0); |
| 525 | at91_mci_write(host, ATMEL_PDC_TNCR, 0); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 526 | ier = AT91_MCI_CMDRDY; |
| 527 | } else { |
| 528 | /* zero block length and PDC mode */ |
Ville Syrjala | 12bd257 | 2008-06-09 22:06:45 +0300 | [diff] [blame] | 529 | mr = at91_mci_read(host, AT91_MCI_MR) & 0x5fff; |
Marc Pignat | 80f9254 | 2008-05-30 14:05:24 +0200 | [diff] [blame] | 530 | mr |= (data->blksz & 0x3) ? AT91_MCI_PDCFBYTE : 0; |
| 531 | mr |= (block_length << 16); |
| 532 | mr |= AT91_MCI_PDCMODE; |
| 533 | at91_mci_write(host, AT91_MCI_MR, mr); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 534 | |
Ville Syrjala | 9da3cba | 2008-06-09 22:06:44 +0300 | [diff] [blame] | 535 | if (!(cpu_is_at91rm9200() || cpu_is_at91sam9261())) |
Marc Pignat | c5a89c6 | 2008-05-30 14:07:47 +0200 | [diff] [blame] | 536 | at91_mci_write(host, AT91_MCI_BLKR, |
| 537 | AT91_MCI_BLKR_BCNT(blocks) | |
| 538 | AT91_MCI_BLKR_BLKLEN(block_length)); |
| 539 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 540 | /* |
| 541 | * Disable the PDC controller |
| 542 | */ |
| 543 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 544 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 545 | if (cmdr & AT91_MCI_TRCMD_START) { |
| 546 | data->bytes_xfered = 0; |
| 547 | host->transfer_index = 0; |
| 548 | host->in_use_index = 0; |
| 549 | if (cmdr & AT91_MCI_TRDIR) { |
| 550 | /* |
| 551 | * Handle a read |
| 552 | */ |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 553 | host->total_length = 0; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 554 | |
Wolfgang Muees | 86ee26f | 2010-03-05 13:43:41 -0800 | [diff] [blame] | 555 | at91_mci_write(host, ATMEL_PDC_RPR, host->physical_address); |
| 556 | at91_mci_write(host, ATMEL_PDC_RCR, (data->blksz & 0x3) ? |
| 557 | (blocks * block_length) : (blocks * block_length) / 4); |
| 558 | at91_mci_write(host, ATMEL_PDC_RNPR, 0); |
| 559 | at91_mci_write(host, ATMEL_PDC_RNCR, 0); |
| 560 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 561 | ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */; |
| 562 | } |
| 563 | else { |
| 564 | /* |
| 565 | * Handle a write |
| 566 | */ |
| 567 | host->total_length = block_length * blocks; |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 568 | /* |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 569 | * MCI1 rev2xx Data Write Operation and |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 570 | * number of bytes erratum |
| 571 | */ |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 572 | if (at91mci_is_mci1rev2xx()) |
Ville Syrjala | 5385edc | 2008-06-14 20:27:20 +0300 | [diff] [blame] | 573 | if (host->total_length < 12) |
| 574 | host->total_length = 12; |
David Brownell | e385ea6 | 2008-09-02 14:35:46 -0700 | [diff] [blame] | 575 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 576 | at91_mci_sg_to_dma(host, data); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 577 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 578 | pr_debug("Transmitting %d bytes\n", host->total_length); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 579 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 580 | at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address); |
Marc Pignat | 80f9254 | 2008-05-30 14:05:24 +0200 | [diff] [blame] | 581 | at91_mci_write(host, ATMEL_PDC_TCR, (data->blksz & 0x3) ? |
| 582 | host->total_length : host->total_length / 4); |
| 583 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 584 | ier = AT91_MCI_CMDRDY; |
| 585 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Send the command and then enable the PDC - not the other way round as |
| 591 | * the data sheet says |
| 592 | */ |
| 593 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 594 | at91_mci_write(host, AT91_MCI_ARGR, cmd->arg); |
| 595 | at91_mci_write(host, AT91_MCI_CMDR, cmdr); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 596 | |
| 597 | if (cmdr & AT91_MCI_TRCMD_START) { |
| 598 | if (cmdr & AT91_MCI_TRDIR) |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 599 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 600 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 601 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 602 | /* Enable selected interrupts */ |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 603 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Process the next step in the request |
| 608 | */ |
Nicolas Ferre | e8d04d3 | 2007-06-19 18:32:34 +0200 | [diff] [blame] | 609 | static void at91_mci_process_next(struct at91mci_host *host) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 610 | { |
| 611 | if (!(host->flags & FL_SENT_COMMAND)) { |
| 612 | host->flags |= FL_SENT_COMMAND; |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 613 | at91_mci_send_command(host, host->request->cmd); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 614 | } |
| 615 | else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) { |
| 616 | host->flags |= FL_SENT_STOP; |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 617 | at91_mci_send_command(host, host->request->stop); |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 618 | } else { |
| 619 | del_timer(&host->timer); |
Marc Pignat | c5a89c6 | 2008-05-30 14:07:47 +0200 | [diff] [blame] | 620 | /* the at91rm9200 mci controller hangs after some transfers, |
| 621 | * and the workaround is to reset it after each transfer. |
| 622 | */ |
| 623 | if (cpu_is_at91rm9200()) |
| 624 | at91_reset_host(host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 625 | mmc_request_done(host->mmc, host->request); |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 626 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Handle a command that has been completed |
| 631 | */ |
Nicolas Ferre | ba7deee | 2008-05-30 14:28:45 +0200 | [diff] [blame] | 632 | static void at91_mci_completed_command(struct at91mci_host *host, unsigned int status) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 633 | { |
| 634 | struct mmc_command *cmd = host->cmd; |
Nicolas Ferre | fa1fe01 | 2008-06-10 11:27:29 +0200 | [diff] [blame] | 635 | struct mmc_data *data = cmd->data; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 636 | |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 637 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 638 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 639 | cmd->resp[0] = at91_mci_read(host, AT91_MCI_RSPR(0)); |
| 640 | cmd->resp[1] = at91_mci_read(host, AT91_MCI_RSPR(1)); |
| 641 | cmd->resp[2] = at91_mci_read(host, AT91_MCI_RSPR(2)); |
| 642 | cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 643 | |
Nicolas Ferre | ba7deee | 2008-05-30 14:28:45 +0200 | [diff] [blame] | 644 | pr_debug("Status = %08X/%08x [%08X %08X %08X %08X]\n", |
| 645 | status, at91_mci_read(host, AT91_MCI_SR), |
| 646 | cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 647 | |
Andrew Victor | 9e3866b | 2007-10-17 11:53:40 +0200 | [diff] [blame] | 648 | if (status & AT91_MCI_ERRORS) { |
Marc Pignat | b6cedb3 | 2007-06-06 20:27:59 +0200 | [diff] [blame] | 649 | if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 650 | cmd->error = 0; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 651 | } |
| 652 | else { |
Nicolas Ferre | fa1fe01 | 2008-06-10 11:27:29 +0200 | [diff] [blame] | 653 | if (status & (AT91_MCI_DTOE | AT91_MCI_DCRCE)) { |
| 654 | if (data) { |
| 655 | if (status & AT91_MCI_DTOE) |
| 656 | data->error = -ETIMEDOUT; |
| 657 | else if (status & AT91_MCI_DCRCE) |
| 658 | data->error = -EILSEQ; |
| 659 | } |
| 660 | } else { |
| 661 | if (status & AT91_MCI_RTOE) |
| 662 | cmd->error = -ETIMEDOUT; |
| 663 | else if (status & AT91_MCI_RCRCE) |
| 664 | cmd->error = -EILSEQ; |
| 665 | else |
| 666 | cmd->error = -EIO; |
| 667 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 668 | |
Nicolas Ferre | fa1fe01 | 2008-06-10 11:27:29 +0200 | [diff] [blame] | 669 | pr_debug("Error detected and set to %d/%d (cmd = %d, retries = %d)\n", |
| 670 | cmd->error, data ? data->error : 0, |
| 671 | cmd->opcode, cmd->retries); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | else |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 675 | cmd->error = 0; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 676 | |
Nicolas Ferre | e8d04d3 | 2007-06-19 18:32:34 +0200 | [diff] [blame] | 677 | at91_mci_process_next(host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Handle an MMC request |
| 682 | */ |
| 683 | static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 684 | { |
| 685 | struct at91mci_host *host = mmc_priv(mmc); |
| 686 | host->request = mrq; |
| 687 | host->flags = 0; |
| 688 | |
Wolfgang Muees | a04ac5b | 2010-03-05 13:43:39 -0800 | [diff] [blame] | 689 | /* more than 1s timeout needed with slow SD cards */ |
| 690 | mod_timer(&host->timer, jiffies + msecs_to_jiffies(2000)); |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 691 | |
Nicolas Ferre | e8d04d3 | 2007-06-19 18:32:34 +0200 | [diff] [blame] | 692 | at91_mci_process_next(host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /* |
| 696 | * Set the IOS |
| 697 | */ |
| 698 | static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 699 | { |
| 700 | int clkdiv; |
| 701 | struct at91mci_host *host = mmc_priv(mmc); |
Andrew Victor | 3dd3b03 | 2006-10-23 14:46:54 +0200 | [diff] [blame] | 702 | unsigned long at91_master_clock = clk_get_rate(host->mci_clk); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 703 | |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 704 | host->bus_mode = ios->bus_mode; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 705 | |
| 706 | if (ios->clock == 0) { |
| 707 | /* Disable the MCI controller */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 708 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 709 | clkdiv = 0; |
| 710 | } |
| 711 | else { |
| 712 | /* Enable the MCI controller */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 713 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 714 | |
| 715 | if ((at91_master_clock % (ios->clock * 2)) == 0) |
| 716 | clkdiv = ((at91_master_clock / ios->clock) / 2) - 1; |
| 717 | else |
| 718 | clkdiv = (at91_master_clock / ios->clock) / 2; |
| 719 | |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 720 | pr_debug("clkdiv = %d. mcck = %ld\n", clkdiv, |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 721 | at91_master_clock / (2 * (clkdiv + 1))); |
| 722 | } |
| 723 | if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 724 | pr_debug("MMC: Setting controller bus width to 4\n"); |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 725 | at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) | AT91_MCI_SDCBUS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 726 | } |
| 727 | else { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 728 | pr_debug("MMC: Setting controller bus width to 1\n"); |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 729 | at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* Set the clock divider */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 733 | at91_mci_write(host, AT91_MCI_MR, (at91_mci_read(host, AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 734 | |
| 735 | /* maybe switch power to the card */ |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 736 | if (host->board->vcc_pin) { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 737 | switch (ios->power_mode) { |
| 738 | case MMC_POWER_OFF: |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 739 | gpio_set_value(host->board->vcc_pin, 0); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 740 | break; |
| 741 | case MMC_POWER_UP: |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 742 | gpio_set_value(host->board->vcc_pin, 1); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 743 | break; |
Marc Pignat | e5c0ef9 | 2008-05-09 11:07:07 +0200 | [diff] [blame] | 744 | case MMC_POWER_ON: |
| 745 | break; |
| 746 | default: |
| 747 | WARN_ON(1); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * Handle an interrupt |
| 754 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 755 | static irqreturn_t at91_mci_irq(int irq, void *devid) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 756 | { |
| 757 | struct at91mci_host *host = devid; |
| 758 | int completed = 0; |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 759 | unsigned int int_status, int_mask; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 760 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 761 | int_status = at91_mci_read(host, AT91_MCI_SR); |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 762 | int_mask = at91_mci_read(host, AT91_MCI_IMR); |
Nicolas Ferre | 37b758e | 2007-08-08 12:01:44 +0200 | [diff] [blame] | 763 | |
Andrew Victor | f3a8efa | 2006-10-23 14:53:20 +0200 | [diff] [blame] | 764 | pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask, |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 765 | int_status & int_mask); |
Nicolas Ferre | 37b758e | 2007-08-08 12:01:44 +0200 | [diff] [blame] | 766 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 767 | int_status = int_status & int_mask; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 768 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 769 | if (int_status & AT91_MCI_ERRORS) { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 770 | completed = 1; |
Nicolas Ferre | 37b758e | 2007-08-08 12:01:44 +0200 | [diff] [blame] | 771 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 772 | if (int_status & AT91_MCI_UNRE) |
| 773 | pr_debug("MMC: Underrun error\n"); |
| 774 | if (int_status & AT91_MCI_OVRE) |
| 775 | pr_debug("MMC: Overrun error\n"); |
| 776 | if (int_status & AT91_MCI_DTOE) |
| 777 | pr_debug("MMC: Data timeout\n"); |
| 778 | if (int_status & AT91_MCI_DCRCE) |
| 779 | pr_debug("MMC: CRC error in data\n"); |
| 780 | if (int_status & AT91_MCI_RTOE) |
| 781 | pr_debug("MMC: Response timeout\n"); |
| 782 | if (int_status & AT91_MCI_RENDE) |
| 783 | pr_debug("MMC: Response end bit error\n"); |
| 784 | if (int_status & AT91_MCI_RCRCE) |
| 785 | pr_debug("MMC: Response CRC error\n"); |
| 786 | if (int_status & AT91_MCI_RDIRE) |
| 787 | pr_debug("MMC: Response direction error\n"); |
| 788 | if (int_status & AT91_MCI_RINDE) |
| 789 | pr_debug("MMC: Response index error\n"); |
| 790 | } else { |
| 791 | /* Only continue processing if no errors */ |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 792 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 793 | if (int_status & AT91_MCI_TXBUFE) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 794 | pr_debug("TX buffer empty\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 795 | at91_mci_handle_transmitted(host); |
| 796 | } |
| 797 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 798 | if (int_status & AT91_MCI_ENDRX) { |
| 799 | pr_debug("ENDRX\n"); |
| 800 | at91_mci_post_dma_read(host); |
| 801 | } |
| 802 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 803 | if (int_status & AT91_MCI_RXBUFF) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 804 | pr_debug("RX buffer full\n"); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 805 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); |
| 806 | at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_RXBUFF | AT91_MCI_ENDRX); |
| 807 | completed = 1; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 810 | if (int_status & AT91_MCI_ENDTX) |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 811 | pr_debug("Transmit has ended\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 812 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 813 | if (int_status & AT91_MCI_NOTBUSY) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 814 | pr_debug("Card is ready\n"); |
Nicolas Ferre | 4ac24a8 | 2008-05-30 14:18:57 +0200 | [diff] [blame] | 815 | at91_mci_update_bytes_xfered(host); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 816 | completed = 1; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 817 | } |
| 818 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 819 | if (int_status & AT91_MCI_DTIP) |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 820 | pr_debug("Data transfer in progress\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 821 | |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 822 | if (int_status & AT91_MCI_BLKE) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 823 | pr_debug("Block transfer has ended\n"); |
Nicolas Ferre | 4ac24a8 | 2008-05-30 14:18:57 +0200 | [diff] [blame] | 824 | if (host->request->data && host->request->data->blocks > 1) { |
| 825 | /* multi block write : complete multi write |
| 826 | * command and send stop */ |
| 827 | completed = 1; |
| 828 | } else { |
| 829 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); |
| 830 | } |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 831 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 832 | |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 833 | if (int_status & AT91_MCI_SDIOIRQA) |
| 834 | mmc_signal_sdio_irq(host->mmc); |
| 835 | |
| 836 | if (int_status & AT91_MCI_SDIOIRQB) |
| 837 | mmc_signal_sdio_irq(host->mmc); |
| 838 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 839 | if (int_status & AT91_MCI_TXRDY) |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 840 | pr_debug("Ready to transmit\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 841 | |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 842 | if (int_status & AT91_MCI_RXRDY) |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 843 | pr_debug("Ready to receive\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 844 | |
| 845 | if (int_status & AT91_MCI_CMDRDY) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 846 | pr_debug("Command ready\n"); |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 847 | completed = at91_mci_handle_cmdrdy(host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 848 | } |
| 849 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 850 | |
| 851 | if (completed) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 852 | pr_debug("Completed command\n"); |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 853 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
Nicolas Ferre | ba7deee | 2008-05-30 14:28:45 +0200 | [diff] [blame] | 854 | at91_mci_completed_command(host, int_status); |
Andrew Victor | df05a30 | 2006-10-23 14:50:09 +0200 | [diff] [blame] | 855 | } else |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 856 | at91_mci_write(host, AT91_MCI_IDR, int_status & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 857 | |
| 858 | return IRQ_HANDLED; |
| 859 | } |
| 860 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 861 | static irqreturn_t at91_mmc_det_irq(int irq, void *_host) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 862 | { |
| 863 | struct at91mci_host *host = _host; |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 864 | int present = !gpio_get_value(irq_to_gpio(irq)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * we expect this irq on both insert and remove, |
| 868 | * and use a short delay to debounce. |
| 869 | */ |
| 870 | if (present != host->present) { |
| 871 | host->present = present; |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 872 | pr_debug("%s: card %s\n", mmc_hostname(host->mmc), |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 873 | present ? "insert" : "remove"); |
| 874 | if (!present) { |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 875 | pr_debug("****** Resetting SD-card bus width ******\n"); |
Andrew Victor | 99eeb8d | 2006-12-11 12:40:23 +0100 | [diff] [blame] | 876 | at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 877 | } |
Wolfgang Muees | a04ac5b | 2010-03-05 13:43:39 -0800 | [diff] [blame] | 878 | /* 0.5s needed because of early card detect switch firing */ |
| 879 | mmc_detect_change(host->mmc, msecs_to_jiffies(500)); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 880 | } |
| 881 | return IRQ_HANDLED; |
| 882 | } |
| 883 | |
David Brownell | a26b498 | 2006-12-26 14:45:26 -0800 | [diff] [blame] | 884 | static int at91_mci_get_ro(struct mmc_host *mmc) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 885 | { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 886 | struct at91mci_host *host = mmc_priv(mmc); |
| 887 | |
Anton Vorontsov | 08f80bb | 2008-06-17 18:17:39 +0400 | [diff] [blame] | 888 | if (host->board->wp_pin) |
| 889 | return !!gpio_get_value(host->board->wp_pin); |
| 890 | /* |
| 891 | * Board doesn't support read only detection; let the mmc core |
| 892 | * decide what to do. |
| 893 | */ |
| 894 | return -ENOSYS; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 897 | static void at91_mci_enable_sdio_irq(struct mmc_host *mmc, int enable) |
| 898 | { |
| 899 | struct at91mci_host *host = mmc_priv(mmc); |
| 900 | |
| 901 | pr_debug("%s: sdio_irq %c : %s\n", mmc_hostname(host->mmc), |
| 902 | host->board->slot_b ? 'B':'A', enable ? "enable" : "disable"); |
| 903 | at91_mci_write(host, enable ? AT91_MCI_IER : AT91_MCI_IDR, |
| 904 | host->board->slot_b ? AT91_MCI_SDIOIRQB : AT91_MCI_SDIOIRQA); |
| 905 | |
| 906 | } |
| 907 | |
David Brownell | ab7aefd | 2006-11-12 17:55:30 -0800 | [diff] [blame] | 908 | static const struct mmc_host_ops at91_mci_ops = { |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 909 | .request = at91_mci_request, |
| 910 | .set_ios = at91_mci_set_ios, |
| 911 | .get_ro = at91_mci_get_ro, |
Eric Benard | 7a6588b | 2008-05-30 14:26:05 +0200 | [diff] [blame] | 912 | .enable_sdio_irq = at91_mci_enable_sdio_irq, |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 913 | }; |
| 914 | |
| 915 | /* |
| 916 | * Probe for the device |
| 917 | */ |
David Brownell | a26b498 | 2006-12-26 14:45:26 -0800 | [diff] [blame] | 918 | static int __init at91_mci_probe(struct platform_device *pdev) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 919 | { |
| 920 | struct mmc_host *mmc; |
| 921 | struct at91mci_host *host; |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 922 | struct resource *res; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 923 | int ret; |
| 924 | |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 925 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 926 | if (!res) |
| 927 | return -ENXIO; |
| 928 | |
| 929 | if (!request_mem_region(res->start, res->end - res->start + 1, DRIVER_NAME)) |
| 930 | return -EBUSY; |
| 931 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 932 | mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); |
| 933 | if (!mmc) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 934 | ret = -ENOMEM; |
| 935 | dev_dbg(&pdev->dev, "couldn't allocate mmc host\n"); |
| 936 | goto fail6; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | mmc->ops = &at91_mci_ops; |
| 940 | mmc->f_min = 375000; |
| 941 | mmc->f_max = 25000000; |
| 942 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
Nicolas Ferre | 541e7ef | 2010-03-05 13:43:43 -0800 | [diff] [blame] | 943 | mmc->caps = 0; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 944 | |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 945 | mmc->max_blk_size = MCI_MAXBLKSIZE; |
| 946 | mmc->max_blk_count = MCI_BLKATONCE; |
| 947 | mmc->max_req_size = MCI_BUFSIZE; |
Wolfgang Muees | 9af13be | 2010-03-05 13:43:42 -0800 | [diff] [blame] | 948 | mmc->max_phys_segs = MCI_BLKATONCE; |
| 949 | mmc->max_hw_segs = MCI_BLKATONCE; |
| 950 | mmc->max_seg_size = MCI_BUFSIZE; |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 951 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 952 | host = mmc_priv(mmc); |
| 953 | host->mmc = mmc; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 954 | host->bus_mode = 0; |
| 955 | host->board = pdev->dev.platform_data; |
| 956 | if (host->board->wire4) { |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 957 | if (at91mci_is_mci1rev2xx()) |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 958 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 959 | else |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 960 | dev_warn(&pdev->dev, "4 wire bus mode not supported" |
Nicolas Ferre | ed99c54 | 2007-07-09 14:58:16 +0200 | [diff] [blame] | 961 | " - using 1 wire\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 962 | } |
| 963 | |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 964 | host->buffer = dma_alloc_coherent(&pdev->dev, MCI_BUFSIZE, |
| 965 | &host->physical_address, GFP_KERNEL); |
| 966 | if (!host->buffer) { |
| 967 | ret = -ENOMEM; |
| 968 | dev_err(&pdev->dev, "Can't allocate transmit buffer\n"); |
| 969 | goto fail5; |
| 970 | } |
| 971 | |
Nicolas Ferre | 541e7ef | 2010-03-05 13:43:43 -0800 | [diff] [blame] | 972 | /* Add SDIO capability when available */ |
Nicolas Ferre | 5b27a1a | 2010-03-05 13:43:44 -0800 | [diff] [blame] | 973 | if (at91mci_is_mci1rev2xx()) { |
| 974 | /* at91mci MCI1 rev2xx sdio interrupt erratum */ |
Nicolas Ferre | 541e7ef | 2010-03-05 13:43:43 -0800 | [diff] [blame] | 975 | if (host->board->wire4 || !host->board->slot_b) |
| 976 | mmc->caps |= MMC_CAP_SDIO_IRQ; |
| 977 | } |
| 978 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 979 | /* |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 980 | * Reserve GPIOs ... board init code makes sure these pins are set |
| 981 | * up as GPIOs with the right direction (input, except for vcc) |
| 982 | */ |
| 983 | if (host->board->det_pin) { |
| 984 | ret = gpio_request(host->board->det_pin, "mmc_detect"); |
| 985 | if (ret < 0) { |
| 986 | dev_dbg(&pdev->dev, "couldn't claim card detect pin\n"); |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 987 | goto fail4b; |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | if (host->board->wp_pin) { |
| 991 | ret = gpio_request(host->board->wp_pin, "mmc_wp"); |
| 992 | if (ret < 0) { |
| 993 | dev_dbg(&pdev->dev, "couldn't claim wp sense pin\n"); |
| 994 | goto fail4; |
| 995 | } |
| 996 | } |
| 997 | if (host->board->vcc_pin) { |
| 998 | ret = gpio_request(host->board->vcc_pin, "mmc_vcc"); |
| 999 | if (ret < 0) { |
| 1000 | dev_dbg(&pdev->dev, "couldn't claim vcc switch pin\n"); |
| 1001 | goto fail3; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | /* |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1006 | * Get Clock |
| 1007 | */ |
Andrew Victor | 3dd3b03 | 2006-10-23 14:46:54 +0200 | [diff] [blame] | 1008 | host->mci_clk = clk_get(&pdev->dev, "mci_clk"); |
| 1009 | if (IS_ERR(host->mci_clk)) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1010 | ret = -ENODEV; |
| 1011 | dev_dbg(&pdev->dev, "no mci_clk?\n"); |
| 1012 | goto fail2; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1013 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1014 | |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1015 | /* |
| 1016 | * Map I/O region |
| 1017 | */ |
| 1018 | host->baseaddr = ioremap(res->start, res->end - res->start + 1); |
| 1019 | if (!host->baseaddr) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1020 | ret = -ENOMEM; |
| 1021 | goto fail1; |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1022 | } |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 1023 | |
| 1024 | /* |
| 1025 | * Reset hardware |
| 1026 | */ |
Andrew Victor | 3dd3b03 | 2006-10-23 14:46:54 +0200 | [diff] [blame] | 1027 | clk_enable(host->mci_clk); /* Enable the peripheral clock */ |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 1028 | at91_mci_disable(host); |
| 1029 | at91_mci_enable(host); |
| 1030 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1031 | /* |
| 1032 | * Allocate the MCI interrupt |
| 1033 | */ |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1034 | host->irq = platform_get_irq(pdev, 0); |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1035 | ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, |
| 1036 | mmc_hostname(mmc), host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1037 | if (ret) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1038 | dev_dbg(&pdev->dev, "request MCI interrupt failed\n"); |
| 1039 | goto fail0; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
Nicolas Ferre | 99ba040 | 2008-11-27 17:23:49 +0100 | [diff] [blame] | 1042 | setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host); |
| 1043 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1044 | platform_set_drvdata(pdev, mmc); |
| 1045 | |
| 1046 | /* |
| 1047 | * Add host to MMC layer |
| 1048 | */ |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1049 | if (host->board->det_pin) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1050 | host->present = !gpio_get_value(host->board->det_pin); |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1051 | } |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1052 | else |
| 1053 | host->present = -1; |
| 1054 | |
| 1055 | mmc_add_host(mmc); |
| 1056 | |
| 1057 | /* |
| 1058 | * monitor card insertion/removal if we can |
| 1059 | */ |
| 1060 | if (host->board->det_pin) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1061 | ret = request_irq(gpio_to_irq(host->board->det_pin), |
| 1062 | at91_mmc_det_irq, 0, mmc_hostname(mmc), host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1063 | if (ret) |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1064 | dev_warn(&pdev->dev, "request MMC detect irq failed\n"); |
| 1065 | else |
| 1066 | device_init_wakeup(&pdev->dev, 1); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Andrew Victor | f3a8efa | 2006-10-23 14:53:20 +0200 | [diff] [blame] | 1069 | pr_debug("Added MCI driver\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1070 | |
| 1071 | return 0; |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1072 | |
| 1073 | fail0: |
| 1074 | clk_disable(host->mci_clk); |
| 1075 | iounmap(host->baseaddr); |
| 1076 | fail1: |
| 1077 | clk_put(host->mci_clk); |
| 1078 | fail2: |
| 1079 | if (host->board->vcc_pin) |
| 1080 | gpio_free(host->board->vcc_pin); |
| 1081 | fail3: |
| 1082 | if (host->board->wp_pin) |
| 1083 | gpio_free(host->board->wp_pin); |
| 1084 | fail4: |
| 1085 | if (host->board->det_pin) |
| 1086 | gpio_free(host->board->det_pin); |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 1087 | fail4b: |
| 1088 | if (host->buffer) |
| 1089 | dma_free_coherent(&pdev->dev, MCI_BUFSIZE, |
| 1090 | host->buffer, host->physical_address); |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1091 | fail5: |
| 1092 | mmc_free_host(mmc); |
| 1093 | fail6: |
| 1094 | release_mem_region(res->start, res->end - res->start + 1); |
| 1095 | dev_err(&pdev->dev, "probe failed, err %d\n", ret); |
| 1096 | return ret; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * Remove a device |
| 1101 | */ |
David Brownell | a26b498 | 2006-12-26 14:45:26 -0800 | [diff] [blame] | 1102 | static int __exit at91_mci_remove(struct platform_device *pdev) |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1103 | { |
| 1104 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
| 1105 | struct at91mci_host *host; |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1106 | struct resource *res; |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1107 | |
| 1108 | if (!mmc) |
| 1109 | return -1; |
| 1110 | |
| 1111 | host = mmc_priv(mmc); |
| 1112 | |
Wolfgang Muees | 3780d90 | 2010-03-05 13:43:40 -0800 | [diff] [blame] | 1113 | if (host->buffer) |
| 1114 | dma_free_coherent(&pdev->dev, MCI_BUFSIZE, |
| 1115 | host->buffer, host->physical_address); |
| 1116 | |
Anti Sullin | e0cda54 | 2007-08-30 16:15:16 +0200 | [diff] [blame] | 1117 | if (host->board->det_pin) { |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1118 | if (device_can_wakeup(&pdev->dev)) |
| 1119 | free_irq(gpio_to_irq(host->board->det_pin), host); |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1120 | device_init_wakeup(&pdev->dev, 0); |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1121 | gpio_free(host->board->det_pin); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Andrew Victor | e0b19b8 | 2006-10-25 19:42:38 +0200 | [diff] [blame] | 1124 | at91_mci_disable(host); |
Marc Pignat | e181dce | 2008-05-30 14:06:32 +0200 | [diff] [blame] | 1125 | del_timer_sync(&host->timer); |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1126 | mmc_remove_host(mmc); |
| 1127 | free_irq(host->irq, host); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1128 | |
Andrew Victor | 3dd3b03 | 2006-10-23 14:46:54 +0200 | [diff] [blame] | 1129 | clk_disable(host->mci_clk); /* Disable the peripheral clock */ |
| 1130 | clk_put(host->mci_clk); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1131 | |
David Brownell | 6e996ee | 2008-02-04 18:12:48 +0100 | [diff] [blame] | 1132 | if (host->board->vcc_pin) |
| 1133 | gpio_free(host->board->vcc_pin); |
| 1134 | if (host->board->wp_pin) |
| 1135 | gpio_free(host->board->wp_pin); |
| 1136 | |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1137 | iounmap(host->baseaddr); |
| 1138 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1139 | release_mem_region(res->start, res->end - res->start + 1); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1140 | |
Andrew Victor | 17ea059 | 2006-10-23 14:44:40 +0200 | [diff] [blame] | 1141 | mmc_free_host(mmc); |
| 1142 | platform_set_drvdata(pdev, NULL); |
Andrew Victor | b44fb7a | 2006-06-19 13:06:05 +0100 | [diff] [blame] | 1143 | pr_debug("MCI Removed\n"); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | #ifdef CONFIG_PM |
| 1149 | static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state) |
| 1150 | { |
| 1151 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1152 | struct at91mci_host *host = mmc_priv(mmc); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1153 | int ret = 0; |
| 1154 | |
Anti Sullin | e0cda54 | 2007-08-30 16:15:16 +0200 | [diff] [blame] | 1155 | if (host->board->det_pin && device_may_wakeup(&pdev->dev)) |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1156 | enable_irq_wake(host->board->det_pin); |
| 1157 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1158 | if (mmc) |
| 1159 | ret = mmc_suspend_host(mmc, state); |
| 1160 | |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
| 1164 | static int at91_mci_resume(struct platform_device *pdev) |
| 1165 | { |
| 1166 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1167 | struct at91mci_host *host = mmc_priv(mmc); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1168 | int ret = 0; |
| 1169 | |
Anti Sullin | e0cda54 | 2007-08-30 16:15:16 +0200 | [diff] [blame] | 1170 | if (host->board->det_pin && device_may_wakeup(&pdev->dev)) |
Marc Pignat | 63b6643 | 2007-07-16 11:07:02 +0200 | [diff] [blame] | 1171 | disable_irq_wake(host->board->det_pin); |
| 1172 | |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1173 | if (mmc) |
| 1174 | ret = mmc_resume_host(mmc); |
| 1175 | |
| 1176 | return ret; |
| 1177 | } |
| 1178 | #else |
| 1179 | #define at91_mci_suspend NULL |
| 1180 | #define at91_mci_resume NULL |
| 1181 | #endif |
| 1182 | |
| 1183 | static struct platform_driver at91_mci_driver = { |
David Brownell | a26b498 | 2006-12-26 14:45:26 -0800 | [diff] [blame] | 1184 | .remove = __exit_p(at91_mci_remove), |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1185 | .suspend = at91_mci_suspend, |
| 1186 | .resume = at91_mci_resume, |
| 1187 | .driver = { |
| 1188 | .name = DRIVER_NAME, |
| 1189 | .owner = THIS_MODULE, |
| 1190 | }, |
| 1191 | }; |
| 1192 | |
| 1193 | static int __init at91_mci_init(void) |
| 1194 | { |
David Brownell | a26b498 | 2006-12-26 14:45:26 -0800 | [diff] [blame] | 1195 | return platform_driver_probe(&at91_mci_driver, at91_mci_probe); |
Andrew Victor | 65dbf34 | 2006-04-02 19:18:51 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | static void __exit at91_mci_exit(void) |
| 1199 | { |
| 1200 | platform_driver_unregister(&at91_mci_driver); |
| 1201 | } |
| 1202 | |
| 1203 | module_init(at91_mci_init); |
| 1204 | module_exit(at91_mci_exit); |
| 1205 | |
| 1206 | MODULE_DESCRIPTION("AT91 Multimedia Card Interface driver"); |
| 1207 | MODULE_AUTHOR("Nick Randell"); |
| 1208 | MODULE_LICENSE("GPL"); |
Kay Sievers | bc65c72 | 2008-04-15 14:34:28 -0700 | [diff] [blame] | 1209 | MODULE_ALIAS("platform:at91_mci"); |