Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3 | * |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 4 | * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Pierre Ossman | 643f720 | 2006-09-30 23:27:52 -0700 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or (at |
| 9 | * your option) any later version. |
Pierre Ossman | 84c46a5 | 2007-12-02 19:58:16 +0100 | [diff] [blame] | 10 | * |
| 11 | * Thanks to the following companies for their support: |
| 12 | * |
| 13 | * - JMicron (hardware and technical support) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/highmem.h> |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 19 | #include <linux/dma-mapping.h> |
Ralf Baechle | 1176360 | 2007-10-23 20:42:11 +0200 | [diff] [blame] | 20 | #include <linux/scatterlist.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 21 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 22 | #include <linux/leds.h> |
| 23 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 24 | #include <linux/mmc/host.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 25 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 26 | #include "sdhci.h" |
| 27 | |
| 28 | #define DRIVER_NAME "sdhci" |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 29 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 30 | #define DBG(f, x...) \ |
Russell King | c656317 | 2006-03-29 09:30:20 +0100 | [diff] [blame] | 31 | pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 32 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 33 | static unsigned int debug_quirks = 0; |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 34 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 35 | static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *); |
| 36 | static void sdhci_finish_data(struct sdhci_host *); |
| 37 | |
| 38 | static void sdhci_send_command(struct sdhci_host *, struct mmc_command *); |
| 39 | static void sdhci_finish_command(struct sdhci_host *); |
| 40 | |
| 41 | static void sdhci_dumpregs(struct sdhci_host *host) |
| 42 | { |
| 43 | printk(KERN_DEBUG DRIVER_NAME ": ============== REGISTER DUMP ==============\n"); |
| 44 | |
| 45 | printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n", |
| 46 | readl(host->ioaddr + SDHCI_DMA_ADDRESS), |
| 47 | readw(host->ioaddr + SDHCI_HOST_VERSION)); |
| 48 | printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n", |
| 49 | readw(host->ioaddr + SDHCI_BLOCK_SIZE), |
| 50 | readw(host->ioaddr + SDHCI_BLOCK_COUNT)); |
| 51 | printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n", |
| 52 | readl(host->ioaddr + SDHCI_ARGUMENT), |
| 53 | readw(host->ioaddr + SDHCI_TRANSFER_MODE)); |
| 54 | printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n", |
| 55 | readl(host->ioaddr + SDHCI_PRESENT_STATE), |
| 56 | readb(host->ioaddr + SDHCI_HOST_CONTROL)); |
| 57 | printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n", |
| 58 | readb(host->ioaddr + SDHCI_POWER_CONTROL), |
| 59 | readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL)); |
| 60 | printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n", |
Nicolas Pitre | 2df3b71 | 2007-09-29 10:46:20 -0400 | [diff] [blame] | 61 | readb(host->ioaddr + SDHCI_WAKE_UP_CONTROL), |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 62 | readw(host->ioaddr + SDHCI_CLOCK_CONTROL)); |
| 63 | printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n", |
| 64 | readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL), |
| 65 | readl(host->ioaddr + SDHCI_INT_STATUS)); |
| 66 | printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n", |
| 67 | readl(host->ioaddr + SDHCI_INT_ENABLE), |
| 68 | readl(host->ioaddr + SDHCI_SIGNAL_ENABLE)); |
| 69 | printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n", |
| 70 | readw(host->ioaddr + SDHCI_ACMD12_ERR), |
| 71 | readw(host->ioaddr + SDHCI_SLOT_INT_STATUS)); |
| 72 | printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Max curr: 0x%08x\n", |
| 73 | readl(host->ioaddr + SDHCI_CAPABILITIES), |
| 74 | readl(host->ioaddr + SDHCI_MAX_CURRENT)); |
| 75 | |
| 76 | printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n"); |
| 77 | } |
| 78 | |
| 79 | /*****************************************************************************\ |
| 80 | * * |
| 81 | * Low level functions * |
| 82 | * * |
| 83 | \*****************************************************************************/ |
| 84 | |
| 85 | static void sdhci_reset(struct sdhci_host *host, u8 mask) |
| 86 | { |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 87 | unsigned long timeout; |
| 88 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 89 | if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { |
Pierre Ossman | 8a4da14 | 2006-10-04 02:15:40 -0700 | [diff] [blame] | 90 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & |
| 91 | SDHCI_CARD_PRESENT)) |
| 92 | return; |
| 93 | } |
| 94 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 95 | writeb(mask, host->ioaddr + SDHCI_SOFTWARE_RESET); |
| 96 | |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 97 | if (mask & SDHCI_RESET_ALL) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 98 | host->clock = 0; |
| 99 | |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 100 | /* Wait max 100 ms */ |
| 101 | timeout = 100; |
| 102 | |
| 103 | /* hw clears the bit when it's done */ |
| 104 | while (readb(host->ioaddr + SDHCI_SOFTWARE_RESET) & mask) { |
| 105 | if (timeout == 0) { |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 106 | printk(KERN_ERR "%s: Reset 0x%x never completed.\n", |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 107 | mmc_hostname(host->mmc), (int)mask); |
| 108 | sdhci_dumpregs(host); |
| 109 | return; |
| 110 | } |
| 111 | timeout--; |
| 112 | mdelay(1); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | static void sdhci_init(struct sdhci_host *host) |
| 117 | { |
| 118 | u32 intmask; |
| 119 | |
| 120 | sdhci_reset(host, SDHCI_RESET_ALL); |
| 121 | |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 122 | intmask = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | |
| 123 | SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX | |
| 124 | SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT | |
| 125 | SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 126 | SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 127 | SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE | |
| 128 | SDHCI_INT_ADMA_ERROR; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 129 | |
| 130 | writel(intmask, host->ioaddr + SDHCI_INT_ENABLE); |
| 131 | writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void sdhci_activate_led(struct sdhci_host *host) |
| 135 | { |
| 136 | u8 ctrl; |
| 137 | |
| 138 | ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); |
| 139 | ctrl |= SDHCI_CTRL_LED; |
| 140 | writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); |
| 141 | } |
| 142 | |
| 143 | static void sdhci_deactivate_led(struct sdhci_host *host) |
| 144 | { |
| 145 | u8 ctrl; |
| 146 | |
| 147 | ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); |
| 148 | ctrl &= ~SDHCI_CTRL_LED; |
| 149 | writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); |
| 150 | } |
| 151 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 152 | #ifdef CONFIG_LEDS_CLASS |
| 153 | static void sdhci_led_control(struct led_classdev *led, |
| 154 | enum led_brightness brightness) |
| 155 | { |
| 156 | struct sdhci_host *host = container_of(led, struct sdhci_host, led); |
| 157 | unsigned long flags; |
| 158 | |
| 159 | spin_lock_irqsave(&host->lock, flags); |
| 160 | |
| 161 | if (brightness == LED_OFF) |
| 162 | sdhci_deactivate_led(host); |
| 163 | else |
| 164 | sdhci_activate_led(host); |
| 165 | |
| 166 | spin_unlock_irqrestore(&host->lock, flags); |
| 167 | } |
| 168 | #endif |
| 169 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 170 | /*****************************************************************************\ |
| 171 | * * |
| 172 | * Core functions * |
| 173 | * * |
| 174 | \*****************************************************************************/ |
| 175 | |
Pierre Ossman | 2a22b14 | 2007-02-02 18:27:42 +0100 | [diff] [blame] | 176 | static inline char* sdhci_sg_to_buffer(struct sdhci_host* host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 177 | { |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 178 | return sg_virt(host->cur_sg); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static inline int sdhci_next_sg(struct sdhci_host* host) |
| 182 | { |
| 183 | /* |
| 184 | * Skip to next SG entry. |
| 185 | */ |
| 186 | host->cur_sg++; |
| 187 | host->num_sg--; |
| 188 | |
| 189 | /* |
| 190 | * Any entries left? |
| 191 | */ |
| 192 | if (host->num_sg > 0) { |
| 193 | host->offset = 0; |
| 194 | host->remain = host->cur_sg->length; |
| 195 | } |
| 196 | |
| 197 | return host->num_sg; |
| 198 | } |
| 199 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 200 | static void sdhci_read_block_pio(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 201 | { |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 202 | int blksize, chunk_remain; |
| 203 | u32 data; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 204 | char *buffer; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 205 | int size; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 206 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 207 | DBG("PIO reading\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 208 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 209 | blksize = host->data->blksz; |
| 210 | chunk_remain = 0; |
| 211 | data = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 212 | |
Pierre Ossman | 2a22b14 | 2007-02-02 18:27:42 +0100 | [diff] [blame] | 213 | buffer = sdhci_sg_to_buffer(host) + host->offset; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 214 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 215 | while (blksize) { |
| 216 | if (chunk_remain == 0) { |
| 217 | data = readl(host->ioaddr + SDHCI_BUFFER); |
| 218 | chunk_remain = min(blksize, 4); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 221 | size = min(host->remain, chunk_remain); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 222 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 223 | chunk_remain -= size; |
| 224 | blksize -= size; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 225 | host->offset += size; |
| 226 | host->remain -= size; |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 227 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 228 | while (size) { |
| 229 | *buffer = data & 0xFF; |
| 230 | buffer++; |
| 231 | data >>= 8; |
| 232 | size--; |
| 233 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 234 | |
| 235 | if (host->remain == 0) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 236 | if (sdhci_next_sg(host) == 0) { |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 237 | BUG_ON(blksize != 0); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 238 | return; |
| 239 | } |
Pierre Ossman | 2a22b14 | 2007-02-02 18:27:42 +0100 | [diff] [blame] | 240 | buffer = sdhci_sg_to_buffer(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 243 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 244 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 245 | static void sdhci_write_block_pio(struct sdhci_host *host) |
| 246 | { |
| 247 | int blksize, chunk_remain; |
| 248 | u32 data; |
| 249 | char *buffer; |
| 250 | int bytes, size; |
| 251 | |
| 252 | DBG("PIO writing\n"); |
| 253 | |
| 254 | blksize = host->data->blksz; |
| 255 | chunk_remain = 4; |
| 256 | data = 0; |
| 257 | |
| 258 | bytes = 0; |
Pierre Ossman | 2a22b14 | 2007-02-02 18:27:42 +0100 | [diff] [blame] | 259 | buffer = sdhci_sg_to_buffer(host) + host->offset; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 260 | |
| 261 | while (blksize) { |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 262 | size = min(host->remain, chunk_remain); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 263 | |
| 264 | chunk_remain -= size; |
| 265 | blksize -= size; |
| 266 | host->offset += size; |
| 267 | host->remain -= size; |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 268 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 269 | while (size) { |
| 270 | data >>= 8; |
| 271 | data |= (u32)*buffer << 24; |
| 272 | buffer++; |
| 273 | size--; |
| 274 | } |
| 275 | |
| 276 | if (chunk_remain == 0) { |
| 277 | writel(data, host->ioaddr + SDHCI_BUFFER); |
| 278 | chunk_remain = min(blksize, 4); |
| 279 | } |
| 280 | |
| 281 | if (host->remain == 0) { |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 282 | if (sdhci_next_sg(host) == 0) { |
| 283 | BUG_ON(blksize != 0); |
| 284 | return; |
| 285 | } |
Pierre Ossman | 2a22b14 | 2007-02-02 18:27:42 +0100 | [diff] [blame] | 286 | buffer = sdhci_sg_to_buffer(host); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 287 | } |
| 288 | } |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | static void sdhci_transfer_pio(struct sdhci_host *host) |
| 292 | { |
| 293 | u32 mask; |
| 294 | |
| 295 | BUG_ON(!host->data); |
| 296 | |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 297 | if (host->num_sg == 0) |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 298 | return; |
| 299 | |
| 300 | if (host->data->flags & MMC_DATA_READ) |
| 301 | mask = SDHCI_DATA_AVAILABLE; |
| 302 | else |
| 303 | mask = SDHCI_SPACE_AVAILABLE; |
| 304 | |
| 305 | while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) { |
| 306 | if (host->data->flags & MMC_DATA_READ) |
| 307 | sdhci_read_block_pio(host); |
| 308 | else |
| 309 | sdhci_write_block_pio(host); |
| 310 | |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 311 | if (host->num_sg == 0) |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 312 | break; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | DBG("PIO transfer complete.\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 318 | static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags) |
| 319 | { |
| 320 | local_irq_save(*flags); |
| 321 | return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; |
| 322 | } |
| 323 | |
| 324 | static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags) |
| 325 | { |
| 326 | kunmap_atomic(buffer, KM_BIO_SRC_IRQ); |
| 327 | local_irq_restore(*flags); |
| 328 | } |
| 329 | |
| 330 | static void sdhci_adma_table_pre(struct sdhci_host *host, |
| 331 | struct mmc_data *data) |
| 332 | { |
| 333 | int direction; |
| 334 | |
| 335 | u8 *desc; |
| 336 | u8 *align; |
| 337 | dma_addr_t addr; |
| 338 | dma_addr_t align_addr; |
| 339 | int len, offset; |
| 340 | |
| 341 | struct scatterlist *sg; |
| 342 | int i; |
| 343 | char *buffer; |
| 344 | unsigned long flags; |
| 345 | |
| 346 | /* |
| 347 | * The spec does not specify endianness of descriptor table. |
| 348 | * We currently guess that it is LE. |
| 349 | */ |
| 350 | |
| 351 | if (data->flags & MMC_DATA_READ) |
| 352 | direction = DMA_FROM_DEVICE; |
| 353 | else |
| 354 | direction = DMA_TO_DEVICE; |
| 355 | |
| 356 | /* |
| 357 | * The ADMA descriptor table is mapped further down as we |
| 358 | * need to fill it with data first. |
| 359 | */ |
| 360 | |
| 361 | host->align_addr = dma_map_single(mmc_dev(host->mmc), |
| 362 | host->align_buffer, 128 * 4, direction); |
| 363 | BUG_ON(host->align_addr & 0x3); |
| 364 | |
| 365 | host->sg_count = dma_map_sg(mmc_dev(host->mmc), |
| 366 | data->sg, data->sg_len, direction); |
| 367 | |
| 368 | desc = host->adma_desc; |
| 369 | align = host->align_buffer; |
| 370 | |
| 371 | align_addr = host->align_addr; |
| 372 | |
| 373 | for_each_sg(data->sg, sg, host->sg_count, i) { |
| 374 | addr = sg_dma_address(sg); |
| 375 | len = sg_dma_len(sg); |
| 376 | |
| 377 | /* |
| 378 | * The SDHCI specification states that ADMA |
| 379 | * addresses must be 32-bit aligned. If they |
| 380 | * aren't, then we use a bounce buffer for |
| 381 | * the (up to three) bytes that screw up the |
| 382 | * alignment. |
| 383 | */ |
| 384 | offset = (4 - (addr & 0x3)) & 0x3; |
| 385 | if (offset) { |
| 386 | if (data->flags & MMC_DATA_WRITE) { |
| 387 | buffer = sdhci_kmap_atomic(sg, &flags); |
| 388 | memcpy(align, buffer, offset); |
| 389 | sdhci_kunmap_atomic(buffer, &flags); |
| 390 | } |
| 391 | |
| 392 | desc[7] = (align_addr >> 24) & 0xff; |
| 393 | desc[6] = (align_addr >> 16) & 0xff; |
| 394 | desc[5] = (align_addr >> 8) & 0xff; |
| 395 | desc[4] = (align_addr >> 0) & 0xff; |
| 396 | |
| 397 | BUG_ON(offset > 65536); |
| 398 | |
| 399 | desc[3] = (offset >> 8) & 0xff; |
| 400 | desc[2] = (offset >> 0) & 0xff; |
| 401 | |
| 402 | desc[1] = 0x00; |
| 403 | desc[0] = 0x21; /* tran, valid */ |
| 404 | |
| 405 | align += 4; |
| 406 | align_addr += 4; |
| 407 | |
| 408 | desc += 8; |
| 409 | |
| 410 | addr += offset; |
| 411 | len -= offset; |
| 412 | } |
| 413 | |
| 414 | desc[7] = (addr >> 24) & 0xff; |
| 415 | desc[6] = (addr >> 16) & 0xff; |
| 416 | desc[5] = (addr >> 8) & 0xff; |
| 417 | desc[4] = (addr >> 0) & 0xff; |
| 418 | |
| 419 | BUG_ON(len > 65536); |
| 420 | |
| 421 | desc[3] = (len >> 8) & 0xff; |
| 422 | desc[2] = (len >> 0) & 0xff; |
| 423 | |
| 424 | desc[1] = 0x00; |
| 425 | desc[0] = 0x21; /* tran, valid */ |
| 426 | |
| 427 | desc += 8; |
| 428 | |
| 429 | /* |
| 430 | * If this triggers then we have a calculation bug |
| 431 | * somewhere. :/ |
| 432 | */ |
| 433 | WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4); |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * Add a terminating entry. |
| 438 | */ |
| 439 | desc[7] = 0; |
| 440 | desc[6] = 0; |
| 441 | desc[5] = 0; |
| 442 | desc[4] = 0; |
| 443 | |
| 444 | desc[3] = 0; |
| 445 | desc[2] = 0; |
| 446 | |
| 447 | desc[1] = 0x00; |
| 448 | desc[0] = 0x03; /* nop, end, valid */ |
| 449 | |
| 450 | /* |
| 451 | * Resync align buffer as we might have changed it. |
| 452 | */ |
| 453 | if (data->flags & MMC_DATA_WRITE) { |
| 454 | dma_sync_single_for_device(mmc_dev(host->mmc), |
| 455 | host->align_addr, 128 * 4, direction); |
| 456 | } |
| 457 | |
| 458 | host->adma_addr = dma_map_single(mmc_dev(host->mmc), |
| 459 | host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE); |
| 460 | BUG_ON(host->adma_addr & 0x3); |
| 461 | } |
| 462 | |
| 463 | static void sdhci_adma_table_post(struct sdhci_host *host, |
| 464 | struct mmc_data *data) |
| 465 | { |
| 466 | int direction; |
| 467 | |
| 468 | struct scatterlist *sg; |
| 469 | int i, size; |
| 470 | u8 *align; |
| 471 | char *buffer; |
| 472 | unsigned long flags; |
| 473 | |
| 474 | if (data->flags & MMC_DATA_READ) |
| 475 | direction = DMA_FROM_DEVICE; |
| 476 | else |
| 477 | direction = DMA_TO_DEVICE; |
| 478 | |
| 479 | dma_unmap_single(mmc_dev(host->mmc), host->adma_addr, |
| 480 | (128 * 2 + 1) * 4, DMA_TO_DEVICE); |
| 481 | |
| 482 | dma_unmap_single(mmc_dev(host->mmc), host->align_addr, |
| 483 | 128 * 4, direction); |
| 484 | |
| 485 | if (data->flags & MMC_DATA_READ) { |
| 486 | dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, |
| 487 | data->sg_len, direction); |
| 488 | |
| 489 | align = host->align_buffer; |
| 490 | |
| 491 | for_each_sg(data->sg, sg, host->sg_count, i) { |
| 492 | if (sg_dma_address(sg) & 0x3) { |
| 493 | size = 4 - (sg_dma_address(sg) & 0x3); |
| 494 | |
| 495 | buffer = sdhci_kmap_atomic(sg, &flags); |
| 496 | memcpy(buffer, align, size); |
| 497 | sdhci_kunmap_atomic(buffer, &flags); |
| 498 | |
| 499 | align += 4; |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, |
| 505 | data->sg_len, direction); |
| 506 | } |
| 507 | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 508 | static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 509 | { |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 510 | u8 count; |
| 511 | unsigned target_timeout, current_timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 512 | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 513 | /* |
| 514 | * If the host controller provides us with an incorrect timeout |
| 515 | * value, just skip the check and use 0xE. The hardware may take |
| 516 | * longer to time out, but that's much better than having a too-short |
| 517 | * timeout value. |
| 518 | */ |
| 519 | if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL)) |
| 520 | return 0xE; |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 521 | |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 522 | /* timeout in us */ |
| 523 | target_timeout = data->timeout_ns / 1000 + |
| 524 | data->timeout_clks / host->clock; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 525 | |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 526 | /* |
| 527 | * Figure out needed cycles. |
| 528 | * We do this in steps in order to fit inside a 32 bit int. |
| 529 | * The first step is the minimum timeout, which will have a |
| 530 | * minimum resolution of 6 bits: |
| 531 | * (1) 2^13*1000 > 2^22, |
| 532 | * (2) host->timeout_clk < 2^16 |
| 533 | * => |
| 534 | * (1) / (2) > 2^6 |
| 535 | */ |
| 536 | count = 0; |
| 537 | current_timeout = (1 << 13) * 1000 / host->timeout_clk; |
| 538 | while (current_timeout < target_timeout) { |
| 539 | count++; |
| 540 | current_timeout <<= 1; |
| 541 | if (count >= 0xF) |
| 542 | break; |
| 543 | } |
| 544 | |
| 545 | if (count >= 0xF) { |
| 546 | printk(KERN_WARNING "%s: Too large timeout requested!\n", |
| 547 | mmc_hostname(host->mmc)); |
| 548 | count = 0xE; |
| 549 | } |
| 550 | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 551 | return count; |
| 552 | } |
| 553 | |
| 554 | static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) |
| 555 | { |
| 556 | u8 count; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 557 | u8 ctrl; |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 558 | |
| 559 | WARN_ON(host->data); |
| 560 | |
| 561 | if (data == NULL) |
| 562 | return; |
| 563 | |
| 564 | /* Sanity checks */ |
| 565 | BUG_ON(data->blksz * data->blocks > 524288); |
| 566 | BUG_ON(data->blksz > host->mmc->max_blk_size); |
| 567 | BUG_ON(data->blocks > 65535); |
| 568 | |
| 569 | host->data = data; |
| 570 | host->data_early = 0; |
| 571 | |
| 572 | count = sdhci_calc_timeout(host, data); |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 573 | writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 574 | |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 575 | if (host->flags & SDHCI_USE_DMA) |
| 576 | host->flags |= SDHCI_REQ_USE_DMA; |
| 577 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 578 | /* |
| 579 | * FIXME: This doesn't account for merging when mapping the |
| 580 | * scatterlist. |
| 581 | */ |
| 582 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 583 | int broken, i; |
| 584 | struct scatterlist *sg; |
| 585 | |
| 586 | broken = 0; |
| 587 | if (host->flags & SDHCI_USE_ADMA) { |
| 588 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) |
| 589 | broken = 1; |
| 590 | } else { |
| 591 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) |
| 592 | broken = 1; |
| 593 | } |
| 594 | |
| 595 | if (unlikely(broken)) { |
| 596 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 597 | if (sg->length & 0x3) { |
| 598 | DBG("Reverting to PIO because of " |
| 599 | "transfer size (%d)\n", |
| 600 | sg->length); |
| 601 | host->flags &= ~SDHCI_REQ_USE_DMA; |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | } |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /* |
| 609 | * The assumption here being that alignment is the same after |
| 610 | * translation to device address space. |
| 611 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 612 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 613 | int broken, i; |
| 614 | struct scatterlist *sg; |
| 615 | |
| 616 | broken = 0; |
| 617 | if (host->flags & SDHCI_USE_ADMA) { |
| 618 | /* |
| 619 | * As we use 3 byte chunks to work around |
| 620 | * alignment problems, we need to check this |
| 621 | * quirk. |
| 622 | */ |
| 623 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) |
| 624 | broken = 1; |
| 625 | } else { |
| 626 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) |
| 627 | broken = 1; |
| 628 | } |
| 629 | |
| 630 | if (unlikely(broken)) { |
| 631 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 632 | if (sg->offset & 0x3) { |
| 633 | DBG("Reverting to PIO because of " |
| 634 | "bad alignment\n"); |
| 635 | host->flags &= ~SDHCI_REQ_USE_DMA; |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * Always adjust the DMA selection as some controllers |
| 644 | * (e.g. JMicron) can't do PIO properly when the selection |
| 645 | * is ADMA. |
| 646 | */ |
| 647 | if (host->version >= SDHCI_SPEC_200) { |
| 648 | ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); |
| 649 | ctrl &= ~SDHCI_CTRL_DMA_MASK; |
| 650 | if ((host->flags & SDHCI_REQ_USE_DMA) && |
| 651 | (host->flags & SDHCI_USE_ADMA)) |
| 652 | ctrl |= SDHCI_CTRL_ADMA32; |
| 653 | else |
| 654 | ctrl |= SDHCI_CTRL_SDMA; |
| 655 | writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (host->flags & SDHCI_REQ_USE_DMA) { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 659 | if (host->flags & SDHCI_USE_ADMA) { |
| 660 | sdhci_adma_table_pre(host, data); |
| 661 | writel(host->adma_addr, |
| 662 | host->ioaddr + SDHCI_ADMA_ADDRESS); |
| 663 | } else { |
| 664 | int count; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 665 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 666 | count = dma_map_sg(mmc_dev(host->mmc), |
| 667 | data->sg, data->sg_len, |
| 668 | (data->flags & MMC_DATA_READ) ? |
| 669 | DMA_FROM_DEVICE : |
| 670 | DMA_TO_DEVICE); |
| 671 | WARN_ON(count != 1); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 672 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 673 | writel(sg_dma_address(data->sg), |
| 674 | host->ioaddr + SDHCI_DMA_ADDRESS); |
| 675 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 676 | } else { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 677 | host->cur_sg = data->sg; |
| 678 | host->num_sg = data->sg_len; |
| 679 | |
| 680 | host->offset = 0; |
| 681 | host->remain = host->cur_sg->length; |
| 682 | } |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 683 | |
Pierre Ossman | bab7696 | 2006-07-02 16:51:35 +0100 | [diff] [blame] | 684 | /* We do not handle DMA boundaries, so set it to max (512 KiB) */ |
| 685 | writew(SDHCI_MAKE_BLKSZ(7, data->blksz), |
| 686 | host->ioaddr + SDHCI_BLOCK_SIZE); |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 687 | writew(data->blocks, host->ioaddr + SDHCI_BLOCK_COUNT); |
| 688 | } |
| 689 | |
| 690 | static void sdhci_set_transfer_mode(struct sdhci_host *host, |
| 691 | struct mmc_data *data) |
| 692 | { |
| 693 | u16 mode; |
| 694 | |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 695 | if (data == NULL) |
| 696 | return; |
| 697 | |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 698 | WARN_ON(!host->data); |
| 699 | |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 700 | mode = SDHCI_TRNS_BLK_CNT_EN; |
| 701 | if (data->blocks > 1) |
| 702 | mode |= SDHCI_TRNS_MULTI; |
| 703 | if (data->flags & MMC_DATA_READ) |
| 704 | mode |= SDHCI_TRNS_READ; |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 705 | if (host->flags & SDHCI_REQ_USE_DMA) |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 706 | mode |= SDHCI_TRNS_DMA; |
| 707 | |
| 708 | writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static void sdhci_finish_data(struct sdhci_host *host) |
| 712 | { |
| 713 | struct mmc_data *data; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 714 | |
| 715 | BUG_ON(!host->data); |
| 716 | |
| 717 | data = host->data; |
| 718 | host->data = NULL; |
| 719 | |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 720 | if (host->flags & SDHCI_REQ_USE_DMA) { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 721 | if (host->flags & SDHCI_USE_ADMA) |
| 722 | sdhci_adma_table_post(host, data); |
| 723 | else { |
| 724 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, |
| 725 | data->sg_len, (data->flags & MMC_DATA_READ) ? |
| 726 | DMA_FROM_DEVICE : DMA_TO_DEVICE); |
| 727 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /* |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 731 | * The specification states that the block count register must |
| 732 | * be updated, but it does not specify at what point in the |
| 733 | * data flow. That makes the register entirely useless to read |
| 734 | * back so we have to assume that nothing made it to the card |
| 735 | * in the event of an error. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 736 | */ |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 737 | if (data->error) |
| 738 | data->bytes_xfered = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 739 | else |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 740 | data->bytes_xfered = data->blksz * data->blocks; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 741 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 742 | if (data->stop) { |
| 743 | /* |
| 744 | * The controller needs a reset of internal state machines |
| 745 | * upon error conditions. |
| 746 | */ |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 747 | if (data->error) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 748 | sdhci_reset(host, SDHCI_RESET_CMD); |
| 749 | sdhci_reset(host, SDHCI_RESET_DATA); |
| 750 | } |
| 751 | |
| 752 | sdhci_send_command(host, data->stop); |
| 753 | } else |
| 754 | tasklet_schedule(&host->finish_tasklet); |
| 755 | } |
| 756 | |
| 757 | static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) |
| 758 | { |
| 759 | int flags; |
Pierre Ossman | fd2208d | 2006-06-30 02:22:28 -0700 | [diff] [blame] | 760 | u32 mask; |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 761 | unsigned long timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 762 | |
| 763 | WARN_ON(host->cmd); |
| 764 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 765 | /* Wait max 10 ms */ |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 766 | timeout = 10; |
Pierre Ossman | fd2208d | 2006-06-30 02:22:28 -0700 | [diff] [blame] | 767 | |
| 768 | mask = SDHCI_CMD_INHIBIT; |
| 769 | if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY)) |
| 770 | mask |= SDHCI_DATA_INHIBIT; |
| 771 | |
| 772 | /* We shouldn't wait for data inihibit for stop commands, even |
| 773 | though they might use busy signaling */ |
| 774 | if (host->mrq->data && (cmd == host->mrq->data->stop)) |
| 775 | mask &= ~SDHCI_DATA_INHIBIT; |
| 776 | |
| 777 | while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) { |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 778 | if (timeout == 0) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 779 | printk(KERN_ERR "%s: Controller never released " |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 780 | "inhibit bit(s).\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 781 | sdhci_dumpregs(host); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 782 | cmd->error = -EIO; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 783 | tasklet_schedule(&host->finish_tasklet); |
| 784 | return; |
| 785 | } |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 786 | timeout--; |
| 787 | mdelay(1); |
| 788 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 789 | |
| 790 | mod_timer(&host->timer, jiffies + 10 * HZ); |
| 791 | |
| 792 | host->cmd = cmd; |
| 793 | |
| 794 | sdhci_prepare_data(host, cmd->data); |
| 795 | |
| 796 | writel(cmd->arg, host->ioaddr + SDHCI_ARGUMENT); |
| 797 | |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 798 | sdhci_set_transfer_mode(host, cmd->data); |
| 799 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 800 | if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 801 | printk(KERN_ERR "%s: Unsupported response type!\n", |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 802 | mmc_hostname(host->mmc)); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 803 | cmd->error = -EINVAL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 804 | tasklet_schedule(&host->finish_tasklet); |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | if (!(cmd->flags & MMC_RSP_PRESENT)) |
| 809 | flags = SDHCI_CMD_RESP_NONE; |
| 810 | else if (cmd->flags & MMC_RSP_136) |
| 811 | flags = SDHCI_CMD_RESP_LONG; |
| 812 | else if (cmd->flags & MMC_RSP_BUSY) |
| 813 | flags = SDHCI_CMD_RESP_SHORT_BUSY; |
| 814 | else |
| 815 | flags = SDHCI_CMD_RESP_SHORT; |
| 816 | |
| 817 | if (cmd->flags & MMC_RSP_CRC) |
| 818 | flags |= SDHCI_CMD_CRC; |
| 819 | if (cmd->flags & MMC_RSP_OPCODE) |
| 820 | flags |= SDHCI_CMD_INDEX; |
| 821 | if (cmd->data) |
| 822 | flags |= SDHCI_CMD_DATA; |
| 823 | |
Pierre Ossman | fb61e28 | 2006-07-11 21:06:48 +0200 | [diff] [blame] | 824 | writew(SDHCI_MAKE_CMD(cmd->opcode, flags), |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 825 | host->ioaddr + SDHCI_COMMAND); |
| 826 | } |
| 827 | |
| 828 | static void sdhci_finish_command(struct sdhci_host *host) |
| 829 | { |
| 830 | int i; |
| 831 | |
| 832 | BUG_ON(host->cmd == NULL); |
| 833 | |
| 834 | if (host->cmd->flags & MMC_RSP_PRESENT) { |
| 835 | if (host->cmd->flags & MMC_RSP_136) { |
| 836 | /* CRC is stripped so we need to do some shifting. */ |
| 837 | for (i = 0;i < 4;i++) { |
| 838 | host->cmd->resp[i] = readl(host->ioaddr + |
| 839 | SDHCI_RESPONSE + (3-i)*4) << 8; |
| 840 | if (i != 3) |
| 841 | host->cmd->resp[i] |= |
| 842 | readb(host->ioaddr + |
| 843 | SDHCI_RESPONSE + (3-i)*4-1); |
| 844 | } |
| 845 | } else { |
| 846 | host->cmd->resp[0] = readl(host->ioaddr + SDHCI_RESPONSE); |
| 847 | } |
| 848 | } |
| 849 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 850 | host->cmd->error = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 851 | |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 852 | if (host->data && host->data_early) |
| 853 | sdhci_finish_data(host); |
| 854 | |
| 855 | if (!host->cmd->data) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 856 | tasklet_schedule(&host->finish_tasklet); |
| 857 | |
| 858 | host->cmd = NULL; |
| 859 | } |
| 860 | |
| 861 | static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) |
| 862 | { |
| 863 | int div; |
| 864 | u16 clk; |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 865 | unsigned long timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 866 | |
| 867 | if (clock == host->clock) |
| 868 | return; |
| 869 | |
| 870 | writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL); |
| 871 | |
| 872 | if (clock == 0) |
| 873 | goto out; |
| 874 | |
| 875 | for (div = 1;div < 256;div *= 2) { |
| 876 | if ((host->max_clk / div) <= clock) |
| 877 | break; |
| 878 | } |
| 879 | div >>= 1; |
| 880 | |
| 881 | clk = div << SDHCI_DIVIDER_SHIFT; |
| 882 | clk |= SDHCI_CLOCK_INT_EN; |
| 883 | writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL); |
| 884 | |
| 885 | /* Wait max 10 ms */ |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 886 | timeout = 10; |
| 887 | while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL)) |
| 888 | & SDHCI_CLOCK_INT_STABLE)) { |
| 889 | if (timeout == 0) { |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 890 | printk(KERN_ERR "%s: Internal clock never " |
| 891 | "stabilised.\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 892 | sdhci_dumpregs(host); |
| 893 | return; |
| 894 | } |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 895 | timeout--; |
| 896 | mdelay(1); |
| 897 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 898 | |
| 899 | clk |= SDHCI_CLOCK_CARD_EN; |
| 900 | writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL); |
| 901 | |
| 902 | out: |
| 903 | host->clock = clock; |
| 904 | } |
| 905 | |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 906 | static void sdhci_set_power(struct sdhci_host *host, unsigned short power) |
| 907 | { |
| 908 | u8 pwr; |
| 909 | |
| 910 | if (host->power == power) |
| 911 | return; |
| 912 | |
Darren Salt | 9e9dc5f | 2007-01-27 15:32:31 +0100 | [diff] [blame] | 913 | if (power == (unsigned short)-1) { |
| 914 | writeb(0, host->ioaddr + SDHCI_POWER_CONTROL); |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 915 | goto out; |
Darren Salt | 9e9dc5f | 2007-01-27 15:32:31 +0100 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /* |
| 919 | * Spec says that we should clear the power reg before setting |
| 920 | * a new value. Some controllers don't seem to like this though. |
| 921 | */ |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 922 | if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) |
Darren Salt | 9e9dc5f | 2007-01-27 15:32:31 +0100 | [diff] [blame] | 923 | writeb(0, host->ioaddr + SDHCI_POWER_CONTROL); |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 924 | |
| 925 | pwr = SDHCI_POWER_ON; |
| 926 | |
Philip Langdale | 4be34c9 | 2007-03-11 17:15:15 -0700 | [diff] [blame] | 927 | switch (1 << power) { |
Philip Langdale | 55556da | 2007-03-16 19:39:00 -0700 | [diff] [blame] | 928 | case MMC_VDD_165_195: |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 929 | pwr |= SDHCI_POWER_180; |
| 930 | break; |
Philip Langdale | 4be34c9 | 2007-03-11 17:15:15 -0700 | [diff] [blame] | 931 | case MMC_VDD_29_30: |
| 932 | case MMC_VDD_30_31: |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 933 | pwr |= SDHCI_POWER_300; |
| 934 | break; |
Philip Langdale | 4be34c9 | 2007-03-11 17:15:15 -0700 | [diff] [blame] | 935 | case MMC_VDD_32_33: |
| 936 | case MMC_VDD_33_34: |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 937 | pwr |= SDHCI_POWER_330; |
| 938 | break; |
| 939 | default: |
| 940 | BUG(); |
| 941 | } |
| 942 | |
Andres Salomon | e08c169 | 2008-07-04 10:00:03 -0700 | [diff] [blame] | 943 | /* |
| 944 | * At least the CaFe chip gets confused if we set the voltage |
| 945 | * and set turn on power at the same time, so set the voltage first. |
| 946 | */ |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 947 | if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER)) |
Andres Salomon | e08c169 | 2008-07-04 10:00:03 -0700 | [diff] [blame] | 948 | writeb(pwr & ~SDHCI_POWER_ON, |
| 949 | host->ioaddr + SDHCI_POWER_CONTROL); |
| 950 | |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 951 | writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL); |
| 952 | |
| 953 | out: |
| 954 | host->power = power; |
| 955 | } |
| 956 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 957 | /*****************************************************************************\ |
| 958 | * * |
| 959 | * MMC callbacks * |
| 960 | * * |
| 961 | \*****************************************************************************/ |
| 962 | |
| 963 | static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 964 | { |
| 965 | struct sdhci_host *host; |
| 966 | unsigned long flags; |
| 967 | |
| 968 | host = mmc_priv(mmc); |
| 969 | |
| 970 | spin_lock_irqsave(&host->lock, flags); |
| 971 | |
| 972 | WARN_ON(host->mrq != NULL); |
| 973 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 974 | #ifndef CONFIG_LEDS_CLASS |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 975 | sdhci_activate_led(host); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 976 | #endif |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 977 | |
| 978 | host->mrq = mrq; |
| 979 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 980 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT) |
| 981 | || (host->flags & SDHCI_DEVICE_DEAD)) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 982 | host->mrq->cmd->error = -ENOMEDIUM; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 983 | tasklet_schedule(&host->finish_tasklet); |
| 984 | } else |
| 985 | sdhci_send_command(host, mrq->cmd); |
| 986 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 987 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 988 | spin_unlock_irqrestore(&host->lock, flags); |
| 989 | } |
| 990 | |
| 991 | static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 992 | { |
| 993 | struct sdhci_host *host; |
| 994 | unsigned long flags; |
| 995 | u8 ctrl; |
| 996 | |
| 997 | host = mmc_priv(mmc); |
| 998 | |
| 999 | spin_lock_irqsave(&host->lock, flags); |
| 1000 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1001 | if (host->flags & SDHCI_DEVICE_DEAD) |
| 1002 | goto out; |
| 1003 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1004 | /* |
| 1005 | * Reset the chip on each power off. |
| 1006 | * Should clear out any weird states. |
| 1007 | */ |
| 1008 | if (ios->power_mode == MMC_POWER_OFF) { |
| 1009 | writel(0, host->ioaddr + SDHCI_SIGNAL_ENABLE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1010 | sdhci_init(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | sdhci_set_clock(host, ios->clock); |
| 1014 | |
| 1015 | if (ios->power_mode == MMC_POWER_OFF) |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1016 | sdhci_set_power(host, -1); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1017 | else |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1018 | sdhci_set_power(host, ios->vdd); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1019 | |
| 1020 | ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 1021 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1022 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
| 1023 | ctrl |= SDHCI_CTRL_4BITBUS; |
| 1024 | else |
| 1025 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 1026 | |
| 1027 | if (ios->timing == MMC_TIMING_SD_HS) |
| 1028 | ctrl |= SDHCI_CTRL_HISPD; |
| 1029 | else |
| 1030 | ctrl &= ~SDHCI_CTRL_HISPD; |
| 1031 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1032 | writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); |
| 1033 | |
Leandro Dorileo | b835226 | 2007-07-25 23:47:04 +0200 | [diff] [blame] | 1034 | /* |
| 1035 | * Some (ENE) controllers go apeshit on some ios operation, |
| 1036 | * signalling timeout and CRC errors even on CMD0. Resetting |
| 1037 | * it on each ios seems to solve the problem. |
| 1038 | */ |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1039 | if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) |
Leandro Dorileo | b835226 | 2007-07-25 23:47:04 +0200 | [diff] [blame] | 1040 | sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); |
| 1041 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1042 | out: |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1043 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1044 | spin_unlock_irqrestore(&host->lock, flags); |
| 1045 | } |
| 1046 | |
| 1047 | static int sdhci_get_ro(struct mmc_host *mmc) |
| 1048 | { |
| 1049 | struct sdhci_host *host; |
| 1050 | unsigned long flags; |
| 1051 | int present; |
| 1052 | |
| 1053 | host = mmc_priv(mmc); |
| 1054 | |
| 1055 | spin_lock_irqsave(&host->lock, flags); |
| 1056 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1057 | if (host->flags & SDHCI_DEVICE_DEAD) |
| 1058 | present = 0; |
| 1059 | else |
| 1060 | present = readl(host->ioaddr + SDHCI_PRESENT_STATE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1061 | |
| 1062 | spin_unlock_irqrestore(&host->lock, flags); |
| 1063 | |
| 1064 | return !(present & SDHCI_WRITE_PROTECT); |
| 1065 | } |
| 1066 | |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1067 | static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) |
| 1068 | { |
| 1069 | struct sdhci_host *host; |
| 1070 | unsigned long flags; |
| 1071 | u32 ier; |
| 1072 | |
| 1073 | host = mmc_priv(mmc); |
| 1074 | |
| 1075 | spin_lock_irqsave(&host->lock, flags); |
| 1076 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1077 | if (host->flags & SDHCI_DEVICE_DEAD) |
| 1078 | goto out; |
| 1079 | |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1080 | ier = readl(host->ioaddr + SDHCI_INT_ENABLE); |
| 1081 | |
| 1082 | ier &= ~SDHCI_INT_CARD_INT; |
| 1083 | if (enable) |
| 1084 | ier |= SDHCI_INT_CARD_INT; |
| 1085 | |
| 1086 | writel(ier, host->ioaddr + SDHCI_INT_ENABLE); |
| 1087 | writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE); |
| 1088 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1089 | out: |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1090 | mmiowb(); |
| 1091 | |
| 1092 | spin_unlock_irqrestore(&host->lock, flags); |
| 1093 | } |
| 1094 | |
David Brownell | ab7aefd | 2006-11-12 17:55:30 -0800 | [diff] [blame] | 1095 | static const struct mmc_host_ops sdhci_ops = { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1096 | .request = sdhci_request, |
| 1097 | .set_ios = sdhci_set_ios, |
| 1098 | .get_ro = sdhci_get_ro, |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1099 | .enable_sdio_irq = sdhci_enable_sdio_irq, |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | /*****************************************************************************\ |
| 1103 | * * |
| 1104 | * Tasklets * |
| 1105 | * * |
| 1106 | \*****************************************************************************/ |
| 1107 | |
| 1108 | static void sdhci_tasklet_card(unsigned long param) |
| 1109 | { |
| 1110 | struct sdhci_host *host; |
| 1111 | unsigned long flags; |
| 1112 | |
| 1113 | host = (struct sdhci_host*)param; |
| 1114 | |
| 1115 | spin_lock_irqsave(&host->lock, flags); |
| 1116 | |
| 1117 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { |
| 1118 | if (host->mrq) { |
| 1119 | printk(KERN_ERR "%s: Card removed during transfer!\n", |
| 1120 | mmc_hostname(host->mmc)); |
| 1121 | printk(KERN_ERR "%s: Resetting controller.\n", |
| 1122 | mmc_hostname(host->mmc)); |
| 1123 | |
| 1124 | sdhci_reset(host, SDHCI_RESET_CMD); |
| 1125 | sdhci_reset(host, SDHCI_RESET_DATA); |
| 1126 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1127 | host->mrq->cmd->error = -ENOMEDIUM; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1128 | tasklet_schedule(&host->finish_tasklet); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | spin_unlock_irqrestore(&host->lock, flags); |
| 1133 | |
| 1134 | mmc_detect_change(host->mmc, msecs_to_jiffies(500)); |
| 1135 | } |
| 1136 | |
| 1137 | static void sdhci_tasklet_finish(unsigned long param) |
| 1138 | { |
| 1139 | struct sdhci_host *host; |
| 1140 | unsigned long flags; |
| 1141 | struct mmc_request *mrq; |
| 1142 | |
| 1143 | host = (struct sdhci_host*)param; |
| 1144 | |
| 1145 | spin_lock_irqsave(&host->lock, flags); |
| 1146 | |
| 1147 | del_timer(&host->timer); |
| 1148 | |
| 1149 | mrq = host->mrq; |
| 1150 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1151 | /* |
| 1152 | * The controller needs a reset of internal state machines |
| 1153 | * upon error conditions. |
| 1154 | */ |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1155 | if (!(host->flags & SDHCI_DEVICE_DEAD) && |
| 1156 | (mrq->cmd->error || |
| 1157 | (mrq->data && (mrq->data->error || |
| 1158 | (mrq->data->stop && mrq->data->stop->error))) || |
| 1159 | (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) { |
Pierre Ossman | 645289d | 2006-06-30 02:22:33 -0700 | [diff] [blame] | 1160 | |
| 1161 | /* Some controllers need this kick or reset won't work here */ |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1162 | if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) { |
Pierre Ossman | 645289d | 2006-06-30 02:22:33 -0700 | [diff] [blame] | 1163 | unsigned int clock; |
| 1164 | |
| 1165 | /* This is to force an update */ |
| 1166 | clock = host->clock; |
| 1167 | host->clock = 0; |
| 1168 | sdhci_set_clock(host, clock); |
| 1169 | } |
| 1170 | |
| 1171 | /* Spec says we should do both at the same time, but Ricoh |
| 1172 | controllers do not like that. */ |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1173 | sdhci_reset(host, SDHCI_RESET_CMD); |
| 1174 | sdhci_reset(host, SDHCI_RESET_DATA); |
| 1175 | } |
| 1176 | |
| 1177 | host->mrq = NULL; |
| 1178 | host->cmd = NULL; |
| 1179 | host->data = NULL; |
| 1180 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1181 | #ifndef CONFIG_LEDS_CLASS |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1182 | sdhci_deactivate_led(host); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1183 | #endif |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1184 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1185 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1186 | spin_unlock_irqrestore(&host->lock, flags); |
| 1187 | |
| 1188 | mmc_request_done(host->mmc, mrq); |
| 1189 | } |
| 1190 | |
| 1191 | static void sdhci_timeout_timer(unsigned long data) |
| 1192 | { |
| 1193 | struct sdhci_host *host; |
| 1194 | unsigned long flags; |
| 1195 | |
| 1196 | host = (struct sdhci_host*)data; |
| 1197 | |
| 1198 | spin_lock_irqsave(&host->lock, flags); |
| 1199 | |
| 1200 | if (host->mrq) { |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 1201 | printk(KERN_ERR "%s: Timeout waiting for hardware " |
| 1202 | "interrupt.\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1203 | sdhci_dumpregs(host); |
| 1204 | |
| 1205 | if (host->data) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1206 | host->data->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1207 | sdhci_finish_data(host); |
| 1208 | } else { |
| 1209 | if (host->cmd) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1210 | host->cmd->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1211 | else |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1212 | host->mrq->cmd->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1213 | |
| 1214 | tasklet_schedule(&host->finish_tasklet); |
| 1215 | } |
| 1216 | } |
| 1217 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1218 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1219 | spin_unlock_irqrestore(&host->lock, flags); |
| 1220 | } |
| 1221 | |
| 1222 | /*****************************************************************************\ |
| 1223 | * * |
| 1224 | * Interrupt handling * |
| 1225 | * * |
| 1226 | \*****************************************************************************/ |
| 1227 | |
| 1228 | static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask) |
| 1229 | { |
| 1230 | BUG_ON(intmask == 0); |
| 1231 | |
| 1232 | if (!host->cmd) { |
Pierre Ossman | b67ac3f | 2007-08-12 17:29:47 +0200 | [diff] [blame] | 1233 | printk(KERN_ERR "%s: Got command interrupt 0x%08x even " |
| 1234 | "though no command operation was in progress.\n", |
| 1235 | mmc_hostname(host->mmc), (unsigned)intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1236 | sdhci_dumpregs(host); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
Pierre Ossman | 43b58b3 | 2007-07-25 23:15:27 +0200 | [diff] [blame] | 1240 | if (intmask & SDHCI_INT_TIMEOUT) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1241 | host->cmd->error = -ETIMEDOUT; |
| 1242 | else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT | |
| 1243 | SDHCI_INT_INDEX)) |
| 1244 | host->cmd->error = -EILSEQ; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1245 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1246 | if (host->cmd->error) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1247 | tasklet_schedule(&host->finish_tasklet); |
Pierre Ossman | 43b58b3 | 2007-07-25 23:15:27 +0200 | [diff] [blame] | 1248 | else if (intmask & SDHCI_INT_RESPONSE) |
| 1249 | sdhci_finish_command(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) |
| 1253 | { |
| 1254 | BUG_ON(intmask == 0); |
| 1255 | |
| 1256 | if (!host->data) { |
| 1257 | /* |
| 1258 | * A data end interrupt is sent together with the response |
| 1259 | * for the stop command. |
| 1260 | */ |
| 1261 | if (intmask & SDHCI_INT_DATA_END) |
| 1262 | return; |
| 1263 | |
Pierre Ossman | b67ac3f | 2007-08-12 17:29:47 +0200 | [diff] [blame] | 1264 | printk(KERN_ERR "%s: Got data interrupt 0x%08x even " |
| 1265 | "though no data operation was in progress.\n", |
| 1266 | mmc_hostname(host->mmc), (unsigned)intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1267 | sdhci_dumpregs(host); |
| 1268 | |
| 1269 | return; |
| 1270 | } |
| 1271 | |
| 1272 | if (intmask & SDHCI_INT_DATA_TIMEOUT) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1273 | host->data->error = -ETIMEDOUT; |
| 1274 | else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT)) |
| 1275 | host->data->error = -EILSEQ; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1276 | else if (intmask & SDHCI_INT_ADMA_ERROR) |
| 1277 | host->data->error = -EIO; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1278 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1279 | if (host->data->error) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1280 | sdhci_finish_data(host); |
| 1281 | else { |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 1282 | if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1283 | sdhci_transfer_pio(host); |
| 1284 | |
Pierre Ossman | 6ba736a | 2007-05-13 22:39:23 +0200 | [diff] [blame] | 1285 | /* |
| 1286 | * We currently don't do anything fancy with DMA |
| 1287 | * boundaries, but as we can't disable the feature |
| 1288 | * we need to at least restart the transfer. |
| 1289 | */ |
| 1290 | if (intmask & SDHCI_INT_DMA_END) |
| 1291 | writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS), |
| 1292 | host->ioaddr + SDHCI_DMA_ADDRESS); |
| 1293 | |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 1294 | if (intmask & SDHCI_INT_DATA_END) { |
| 1295 | if (host->cmd) { |
| 1296 | /* |
| 1297 | * Data managed to finish before the |
| 1298 | * command completed. Make sure we do |
| 1299 | * things in the proper order. |
| 1300 | */ |
| 1301 | host->data_early = 1; |
| 1302 | } else { |
| 1303 | sdhci_finish_data(host); |
| 1304 | } |
| 1305 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1309 | static irqreturn_t sdhci_irq(int irq, void *dev_id) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1310 | { |
| 1311 | irqreturn_t result; |
| 1312 | struct sdhci_host* host = dev_id; |
| 1313 | u32 intmask; |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1314 | int cardint = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1315 | |
| 1316 | spin_lock(&host->lock); |
| 1317 | |
| 1318 | intmask = readl(host->ioaddr + SDHCI_INT_STATUS); |
| 1319 | |
Mark Lord | 62df67a5 | 2007-03-06 13:30:13 +0100 | [diff] [blame] | 1320 | if (!intmask || intmask == 0xffffffff) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1321 | result = IRQ_NONE; |
| 1322 | goto out; |
| 1323 | } |
| 1324 | |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1325 | DBG("*** %s got interrupt: 0x%08x\n", |
| 1326 | mmc_hostname(host->mmc), intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1327 | |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1328 | if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { |
| 1329 | writel(intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE), |
| 1330 | host->ioaddr + SDHCI_INT_STATUS); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1331 | tasklet_schedule(&host->card_tasklet); |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1335 | |
| 1336 | if (intmask & SDHCI_INT_CMD_MASK) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1337 | writel(intmask & SDHCI_INT_CMD_MASK, |
| 1338 | host->ioaddr + SDHCI_INT_STATUS); |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1339 | sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | if (intmask & SDHCI_INT_DATA_MASK) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1343 | writel(intmask & SDHCI_INT_DATA_MASK, |
| 1344 | host->ioaddr + SDHCI_INT_STATUS); |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1345 | sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK); |
| 1349 | |
Pierre Ossman | 964f9ce | 2007-07-20 18:20:36 +0200 | [diff] [blame] | 1350 | intmask &= ~SDHCI_INT_ERROR; |
| 1351 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1352 | if (intmask & SDHCI_INT_BUS_POWER) { |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1353 | printk(KERN_ERR "%s: Card is consuming too much power!\n", |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1354 | mmc_hostname(host->mmc)); |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1355 | writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Rolf Eike Beer | 9d26a5d | 2007-06-26 13:31:16 +0200 | [diff] [blame] | 1358 | intmask &= ~SDHCI_INT_BUS_POWER; |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1359 | |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1360 | if (intmask & SDHCI_INT_CARD_INT) |
| 1361 | cardint = 1; |
| 1362 | |
| 1363 | intmask &= ~SDHCI_INT_CARD_INT; |
| 1364 | |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1365 | if (intmask) { |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 1366 | printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n", |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1367 | mmc_hostname(host->mmc), intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1368 | sdhci_dumpregs(host); |
| 1369 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1370 | writel(intmask, host->ioaddr + SDHCI_INT_STATUS); |
Pierre Ossman | 3192a28 | 2006-06-30 02:22:26 -0700 | [diff] [blame] | 1371 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1372 | |
| 1373 | result = IRQ_HANDLED; |
| 1374 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1375 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1376 | out: |
| 1377 | spin_unlock(&host->lock); |
| 1378 | |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1379 | /* |
| 1380 | * We have to delay this as it calls back into the driver. |
| 1381 | */ |
| 1382 | if (cardint) |
| 1383 | mmc_signal_sdio_irq(host->mmc); |
| 1384 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1385 | return result; |
| 1386 | } |
| 1387 | |
| 1388 | /*****************************************************************************\ |
| 1389 | * * |
| 1390 | * Suspend/resume * |
| 1391 | * * |
| 1392 | \*****************************************************************************/ |
| 1393 | |
| 1394 | #ifdef CONFIG_PM |
| 1395 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1396 | int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1397 | { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1398 | int ret; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1399 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1400 | ret = mmc_suspend_host(host->mmc, state); |
Pierre Ossman | df1c4b7 | 2007-01-30 07:55:15 +0100 | [diff] [blame] | 1401 | if (ret) |
| 1402 | return ret; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1403 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1404 | free_irq(host->irq, host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1405 | |
| 1406 | return 0; |
| 1407 | } |
| 1408 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1409 | EXPORT_SYMBOL_GPL(sdhci_suspend_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1410 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1411 | int sdhci_resume_host(struct sdhci_host *host) |
| 1412 | { |
| 1413 | int ret; |
| 1414 | |
| 1415 | if (host->flags & SDHCI_USE_DMA) { |
| 1416 | if (host->ops->enable_dma) |
| 1417 | host->ops->enable_dma(host); |
| 1418 | } |
| 1419 | |
| 1420 | ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, |
| 1421 | mmc_hostname(host->mmc), host); |
| 1422 | if (ret) |
| 1423 | return ret; |
| 1424 | |
| 1425 | sdhci_init(host); |
| 1426 | mmiowb(); |
| 1427 | |
| 1428 | ret = mmc_resume_host(host->mmc); |
| 1429 | if (ret) |
| 1430 | return ret; |
| 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
| 1435 | EXPORT_SYMBOL_GPL(sdhci_resume_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1436 | |
| 1437 | #endif /* CONFIG_PM */ |
| 1438 | |
| 1439 | /*****************************************************************************\ |
| 1440 | * * |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1441 | * Device allocation/registration * |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1442 | * * |
| 1443 | \*****************************************************************************/ |
| 1444 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1445 | struct sdhci_host *sdhci_alloc_host(struct device *dev, |
| 1446 | size_t priv_size) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1447 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1448 | struct mmc_host *mmc; |
| 1449 | struct sdhci_host *host; |
| 1450 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1451 | WARN_ON(dev == NULL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1452 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1453 | mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1454 | if (!mmc) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1455 | return ERR_PTR(-ENOMEM); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1456 | |
| 1457 | host = mmc_priv(mmc); |
| 1458 | host->mmc = mmc; |
| 1459 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1460 | return host; |
| 1461 | } |
Pierre Ossman | 8a4da14 | 2006-10-04 02:15:40 -0700 | [diff] [blame] | 1462 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1463 | EXPORT_SYMBOL_GPL(sdhci_alloc_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1464 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1465 | int sdhci_add_host(struct sdhci_host *host) |
| 1466 | { |
| 1467 | struct mmc_host *mmc; |
| 1468 | unsigned int caps; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1469 | int ret; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1470 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1471 | WARN_ON(host == NULL); |
| 1472 | if (host == NULL) |
| 1473 | return -EINVAL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1474 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1475 | mmc = host->mmc; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1476 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1477 | if (debug_quirks) |
| 1478 | host->quirks = debug_quirks; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1479 | |
Pierre Ossman | d96649e | 2006-06-30 02:22:30 -0700 | [diff] [blame] | 1480 | sdhci_reset(host, SDHCI_RESET_ALL); |
| 1481 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1482 | host->version = readw(host->ioaddr + SDHCI_HOST_VERSION); |
| 1483 | host->version = (host->version & SDHCI_SPEC_VER_MASK) |
| 1484 | >> SDHCI_SPEC_VER_SHIFT; |
| 1485 | if (host->version > SDHCI_SPEC_200) { |
Pierre Ossman | 4a96550 | 2006-06-30 02:22:29 -0700 | [diff] [blame] | 1486 | printk(KERN_ERR "%s: Unknown controller version (%d). " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1487 | "You may experience problems.\n", mmc_hostname(mmc), |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1488 | host->version); |
Pierre Ossman | 4a96550 | 2006-06-30 02:22:29 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1491 | caps = readl(host->ioaddr + SDHCI_CAPABILITIES); |
| 1492 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1493 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) |
Pierre Ossman | 9860807 | 2006-06-30 02:22:34 -0700 | [diff] [blame] | 1494 | host->flags |= SDHCI_USE_DMA; |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 1495 | else if (!(caps & SDHCI_CAN_DO_DMA)) |
| 1496 | DBG("Controller doesn't have DMA capability\n"); |
| 1497 | else |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1498 | host->flags |= SDHCI_USE_DMA; |
| 1499 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1500 | if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && |
Feng Tang | 7c168e3 | 2007-09-30 12:44:18 +0200 | [diff] [blame] | 1501 | (host->flags & SDHCI_USE_DMA)) { |
Rolf Eike Beer | cee687c | 2007-11-02 15:22:30 +0100 | [diff] [blame] | 1502 | DBG("Disabling DMA as it is marked broken\n"); |
Feng Tang | 7c168e3 | 2007-09-30 12:44:18 +0200 | [diff] [blame] | 1503 | host->flags &= ~SDHCI_USE_DMA; |
| 1504 | } |
| 1505 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1506 | if (host->flags & SDHCI_USE_DMA) { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1507 | if ((host->version >= SDHCI_SPEC_200) && |
| 1508 | (caps & SDHCI_CAN_DO_ADMA2)) |
| 1509 | host->flags |= SDHCI_USE_ADMA; |
| 1510 | } |
| 1511 | |
| 1512 | if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && |
| 1513 | (host->flags & SDHCI_USE_ADMA)) { |
| 1514 | DBG("Disabling ADMA as it is marked broken\n"); |
| 1515 | host->flags &= ~SDHCI_USE_ADMA; |
| 1516 | } |
| 1517 | |
| 1518 | if (host->flags & SDHCI_USE_DMA) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1519 | if (host->ops->enable_dma) { |
| 1520 | if (host->ops->enable_dma(host)) { |
| 1521 | printk(KERN_WARNING "%s: No suitable DMA " |
| 1522 | "available. Falling back to PIO.\n", |
| 1523 | mmc_hostname(mmc)); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1524 | host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1525 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1529 | if (host->flags & SDHCI_USE_ADMA) { |
| 1530 | /* |
| 1531 | * We need to allocate descriptors for all sg entries |
| 1532 | * (128) and potentially one alignment transfer for |
| 1533 | * each of those entries. |
| 1534 | */ |
| 1535 | host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL); |
| 1536 | host->align_buffer = kmalloc(128 * 4, GFP_KERNEL); |
| 1537 | if (!host->adma_desc || !host->align_buffer) { |
| 1538 | kfree(host->adma_desc); |
| 1539 | kfree(host->align_buffer); |
| 1540 | printk(KERN_WARNING "%s: Unable to allocate ADMA " |
| 1541 | "buffers. Falling back to standard DMA.\n", |
| 1542 | mmc_hostname(mmc)); |
| 1543 | host->flags &= ~SDHCI_USE_ADMA; |
| 1544 | } |
| 1545 | } |
| 1546 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1547 | /* XXX: Hack to get MMC layer to avoid highmem */ |
| 1548 | if (!(host->flags & SDHCI_USE_DMA)) |
| 1549 | mmc_dev(host->mmc)->dma_mask = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1550 | |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 1551 | host->max_clk = |
| 1552 | (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT; |
| 1553 | if (host->max_clk == 0) { |
| 1554 | printk(KERN_ERR "%s: Hardware doesn't specify base clock " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1555 | "frequency.\n", mmc_hostname(mmc)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1556 | return -ENODEV; |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 1557 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1558 | host->max_clk *= 1000000; |
| 1559 | |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 1560 | host->timeout_clk = |
| 1561 | (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT; |
| 1562 | if (host->timeout_clk == 0) { |
| 1563 | printk(KERN_ERR "%s: Hardware doesn't specify timeout clock " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1564 | "frequency.\n", mmc_hostname(mmc)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1565 | return -ENODEV; |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 1566 | } |
| 1567 | if (caps & SDHCI_TIMEOUT_CLK_UNIT) |
| 1568 | host->timeout_clk *= 1000; |
| 1569 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1570 | /* |
| 1571 | * Set host parameters. |
| 1572 | */ |
| 1573 | mmc->ops = &sdhci_ops; |
| 1574 | mmc->f_min = host->max_clk / 256; |
| 1575 | mmc->f_max = host->max_clk; |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 1576 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1577 | |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 1578 | if (caps & SDHCI_CAN_DO_HISPD) |
| 1579 | mmc->caps |= MMC_CAP_SD_HIGHSPEED; |
| 1580 | |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1581 | mmc->ocr_avail = 0; |
| 1582 | if (caps & SDHCI_CAN_VDD_330) |
| 1583 | mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34; |
Pierre Ossman | c70840e | 2007-02-02 22:41:41 +0100 | [diff] [blame] | 1584 | if (caps & SDHCI_CAN_VDD_300) |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1585 | mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31; |
Pierre Ossman | c70840e | 2007-02-02 22:41:41 +0100 | [diff] [blame] | 1586 | if (caps & SDHCI_CAN_VDD_180) |
Philip Langdale | 55556da | 2007-03-16 19:39:00 -0700 | [diff] [blame] | 1587 | mmc->ocr_avail |= MMC_VDD_165_195; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1588 | |
| 1589 | if (mmc->ocr_avail == 0) { |
| 1590 | printk(KERN_ERR "%s: Hardware doesn't report any " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1591 | "support voltages.\n", mmc_hostname(mmc)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1592 | return -ENODEV; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1595 | spin_lock_init(&host->lock); |
| 1596 | |
| 1597 | /* |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1598 | * Maximum number of segments. Depends on if the hardware |
| 1599 | * can do scatter/gather or not. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1600 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1601 | if (host->flags & SDHCI_USE_ADMA) |
| 1602 | mmc->max_hw_segs = 128; |
| 1603 | else if (host->flags & SDHCI_USE_DMA) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1604 | mmc->max_hw_segs = 1; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1605 | else /* PIO */ |
| 1606 | mmc->max_hw_segs = 128; |
| 1607 | mmc->max_phys_segs = 128; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1608 | |
| 1609 | /* |
Pierre Ossman | bab7696 | 2006-07-02 16:51:35 +0100 | [diff] [blame] | 1610 | * Maximum number of sectors in one transfer. Limited by DMA boundary |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1611 | * size (512KiB). |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1612 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1613 | mmc->max_req_size = 524288; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1614 | |
| 1615 | /* |
| 1616 | * Maximum segment size. Could be one segment with the maximum number |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1617 | * of bytes. When doing hardware scatter/gather, each entry cannot |
| 1618 | * be larger than 64 KiB though. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1619 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1620 | if (host->flags & SDHCI_USE_ADMA) |
| 1621 | mmc->max_seg_size = 65536; |
| 1622 | else |
| 1623 | mmc->max_seg_size = mmc->max_req_size; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1624 | |
| 1625 | /* |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1626 | * Maximum block size. This varies from controller to controller and |
| 1627 | * is specified in the capabilities register. |
| 1628 | */ |
| 1629 | mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> SDHCI_MAX_BLOCK_SHIFT; |
| 1630 | if (mmc->max_blk_size >= 3) { |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1631 | printk(KERN_WARNING "%s: Invalid maximum block size, " |
| 1632 | "assuming 512 bytes\n", mmc_hostname(mmc)); |
David Vrabel | 03f8590 | 2007-08-10 13:25:03 +0100 | [diff] [blame] | 1633 | mmc->max_blk_size = 512; |
| 1634 | } else |
| 1635 | mmc->max_blk_size = 512 << mmc->max_blk_size; |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1636 | |
| 1637 | /* |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1638 | * Maximum block count. |
| 1639 | */ |
| 1640 | mmc->max_blk_count = 65535; |
| 1641 | |
| 1642 | /* |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1643 | * Init tasklets. |
| 1644 | */ |
| 1645 | tasklet_init(&host->card_tasklet, |
| 1646 | sdhci_tasklet_card, (unsigned long)host); |
| 1647 | tasklet_init(&host->finish_tasklet, |
| 1648 | sdhci_tasklet_finish, (unsigned long)host); |
| 1649 | |
Al Viro | e4cad1b | 2006-10-10 22:47:07 +0100 | [diff] [blame] | 1650 | setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1651 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 1652 | ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 1653 | mmc_hostname(mmc), host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1654 | if (ret) |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 1655 | goto untasklet; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1656 | |
| 1657 | sdhci_init(host); |
| 1658 | |
| 1659 | #ifdef CONFIG_MMC_DEBUG |
| 1660 | sdhci_dumpregs(host); |
| 1661 | #endif |
| 1662 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1663 | #ifdef CONFIG_LEDS_CLASS |
| 1664 | host->led.name = mmc_hostname(mmc); |
| 1665 | host->led.brightness = LED_OFF; |
| 1666 | host->led.default_trigger = mmc_hostname(mmc); |
| 1667 | host->led.brightness_set = sdhci_led_control; |
| 1668 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1669 | ret = led_classdev_register(mmc_dev(mmc), &host->led); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1670 | if (ret) |
| 1671 | goto reset; |
| 1672 | #endif |
| 1673 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1674 | mmiowb(); |
| 1675 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1676 | mmc_add_host(mmc); |
| 1677 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1678 | printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n", |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1679 | mmc_hostname(mmc), host->hw_name, mmc_dev(mmc)->bus_id, |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1680 | (host->flags & SDHCI_USE_ADMA)?"A":"", |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1681 | (host->flags & SDHCI_USE_DMA)?"DMA":"PIO"); |
| 1682 | |
| 1683 | return 0; |
| 1684 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1685 | #ifdef CONFIG_LEDS_CLASS |
| 1686 | reset: |
| 1687 | sdhci_reset(host, SDHCI_RESET_ALL); |
| 1688 | free_irq(host->irq, host); |
| 1689 | #endif |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 1690 | untasklet: |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1691 | tasklet_kill(&host->card_tasklet); |
| 1692 | tasklet_kill(&host->finish_tasklet); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1693 | |
| 1694 | return ret; |
| 1695 | } |
| 1696 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1697 | EXPORT_SYMBOL_GPL(sdhci_add_host); |
| 1698 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1699 | void sdhci_remove_host(struct sdhci_host *host, int dead) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1700 | { |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1701 | unsigned long flags; |
| 1702 | |
| 1703 | if (dead) { |
| 1704 | spin_lock_irqsave(&host->lock, flags); |
| 1705 | |
| 1706 | host->flags |= SDHCI_DEVICE_DEAD; |
| 1707 | |
| 1708 | if (host->mrq) { |
| 1709 | printk(KERN_ERR "%s: Controller removed during " |
| 1710 | " transfer!\n", mmc_hostname(host->mmc)); |
| 1711 | |
| 1712 | host->mrq->cmd->error = -ENOMEDIUM; |
| 1713 | tasklet_schedule(&host->finish_tasklet); |
| 1714 | } |
| 1715 | |
| 1716 | spin_unlock_irqrestore(&host->lock, flags); |
| 1717 | } |
| 1718 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1719 | mmc_remove_host(host->mmc); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1720 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1721 | #ifdef CONFIG_LEDS_CLASS |
| 1722 | led_classdev_unregister(&host->led); |
| 1723 | #endif |
| 1724 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1725 | if (!dead) |
| 1726 | sdhci_reset(host, SDHCI_RESET_ALL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1727 | |
| 1728 | free_irq(host->irq, host); |
| 1729 | |
| 1730 | del_timer_sync(&host->timer); |
| 1731 | |
| 1732 | tasklet_kill(&host->card_tasklet); |
| 1733 | tasklet_kill(&host->finish_tasklet); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame^] | 1734 | |
| 1735 | kfree(host->adma_desc); |
| 1736 | kfree(host->align_buffer); |
| 1737 | |
| 1738 | host->adma_desc = NULL; |
| 1739 | host->align_buffer = NULL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1742 | EXPORT_SYMBOL_GPL(sdhci_remove_host); |
| 1743 | |
| 1744 | void sdhci_free_host(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1745 | { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1746 | mmc_free_host(host->mmc); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1749 | EXPORT_SYMBOL_GPL(sdhci_free_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1750 | |
| 1751 | /*****************************************************************************\ |
| 1752 | * * |
| 1753 | * Driver init/exit * |
| 1754 | * * |
| 1755 | \*****************************************************************************/ |
| 1756 | |
| 1757 | static int __init sdhci_drv_init(void) |
| 1758 | { |
| 1759 | printk(KERN_INFO DRIVER_NAME |
Pierre Ossman | 52fbf9c | 2007-02-09 08:23:41 +0100 | [diff] [blame] | 1760 | ": Secure Digital Host Controller Interface driver\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1761 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); |
| 1762 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1763 | return 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | static void __exit sdhci_drv_exit(void) |
| 1767 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | module_init(sdhci_drv_init); |
| 1771 | module_exit(sdhci_drv_exit); |
| 1772 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 1773 | module_param(debug_quirks, uint, 0444); |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 1774 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1775 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1776 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1777 | MODULE_LICENSE("GPL"); |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 1778 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 1779 | MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); |