blob: 6b2d1f99af6728d9cd12d42ebe2c71e0adaf08fe [file] [log] [blame]
Pierre Ossmand129bce2006-03-24 03:18:17 -08001/*
Pierre Ossman70f10482007-07-11 20:04:50 +02002 * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
Pierre Ossmand129bce2006-03-24 03:18:17 -08003 *
Pierre Ossmanb69c9052008-03-08 23:44:25 +01004 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
Pierre Ossmand129bce2006-03-24 03:18:17 -08005 *
6 * This program is free software; you can redistribute it and/or modify
Pierre Ossman643f7202006-09-30 23:27:52 -07007 * 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 Ossman84c46a52007-12-02 19:58:16 +010010 *
11 * Thanks to the following companies for their support:
12 *
13 * - JMicron (hardware and technical support)
Pierre Ossmand129bce2006-03-24 03:18:17 -080014 */
15
Pierre Ossmand129bce2006-03-24 03:18:17 -080016#include <linux/delay.h>
17#include <linux/highmem.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010018#include <linux/io.h>
Pierre Ossmand129bce2006-03-24 03:18:17 -080019#include <linux/dma-mapping.h>
Ralf Baechle11763602007-10-23 20:42:11 +020020#include <linux/scatterlist.h>
Pierre Ossmand129bce2006-03-24 03:18:17 -080021
Pierre Ossman2f730fe2008-03-17 10:29:38 +010022#include <linux/leds.h>
23
Pierre Ossmand129bce2006-03-24 03:18:17 -080024#include <linux/mmc/host.h>
Pierre Ossmand129bce2006-03-24 03:18:17 -080025
Pierre Ossmand129bce2006-03-24 03:18:17 -080026#include "sdhci.h"
27
28#define DRIVER_NAME "sdhci"
Pierre Ossmand129bce2006-03-24 03:18:17 -080029
Pierre Ossmand129bce2006-03-24 03:18:17 -080030#define DBG(f, x...) \
Russell Kingc6563172006-03-29 09:30:20 +010031 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
Pierre Ossmand129bce2006-03-24 03:18:17 -080032
Pierre Ossmanf9134312008-12-21 17:01:48 +010033#if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \
34 defined(CONFIG_MMC_SDHCI_MODULE))
35#define SDHCI_USE_LEDS_CLASS
36#endif
37
Pierre Ossmandf673b22006-06-30 02:22:31 -070038static unsigned int debug_quirks = 0;
Pierre Ossman67435272006-06-30 02:22:31 -070039
Pierre Ossmand129bce2006-03-24 03:18:17 -080040static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
41static void sdhci_finish_data(struct sdhci_host *);
42
43static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
44static void sdhci_finish_command(struct sdhci_host *);
45
46static void sdhci_dumpregs(struct sdhci_host *host)
47{
48 printk(KERN_DEBUG DRIVER_NAME ": ============== REGISTER DUMP ==============\n");
49
50 printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
51 readl(host->ioaddr + SDHCI_DMA_ADDRESS),
52 readw(host->ioaddr + SDHCI_HOST_VERSION));
53 printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
54 readw(host->ioaddr + SDHCI_BLOCK_SIZE),
55 readw(host->ioaddr + SDHCI_BLOCK_COUNT));
56 printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
57 readl(host->ioaddr + SDHCI_ARGUMENT),
58 readw(host->ioaddr + SDHCI_TRANSFER_MODE));
59 printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
60 readl(host->ioaddr + SDHCI_PRESENT_STATE),
61 readb(host->ioaddr + SDHCI_HOST_CONTROL));
62 printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
63 readb(host->ioaddr + SDHCI_POWER_CONTROL),
64 readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL));
65 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
Nicolas Pitre2df3b712007-09-29 10:46:20 -040066 readb(host->ioaddr + SDHCI_WAKE_UP_CONTROL),
Pierre Ossmand129bce2006-03-24 03:18:17 -080067 readw(host->ioaddr + SDHCI_CLOCK_CONTROL));
68 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
69 readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL),
70 readl(host->ioaddr + SDHCI_INT_STATUS));
71 printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
72 readl(host->ioaddr + SDHCI_INT_ENABLE),
73 readl(host->ioaddr + SDHCI_SIGNAL_ENABLE));
74 printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
75 readw(host->ioaddr + SDHCI_ACMD12_ERR),
76 readw(host->ioaddr + SDHCI_SLOT_INT_STATUS));
77 printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Max curr: 0x%08x\n",
78 readl(host->ioaddr + SDHCI_CAPABILITIES),
79 readl(host->ioaddr + SDHCI_MAX_CURRENT));
80
81 printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n");
82}
83
84/*****************************************************************************\
85 * *
86 * Low level functions *
87 * *
88\*****************************************************************************/
89
90static void sdhci_reset(struct sdhci_host *host, u8 mask)
91{
Pierre Ossmane16514d82006-06-30 02:22:24 -070092 unsigned long timeout;
93
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010094 if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
Pierre Ossman8a4da142006-10-04 02:15:40 -070095 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) &
96 SDHCI_CARD_PRESENT))
97 return;
98 }
99
Pierre Ossmand129bce2006-03-24 03:18:17 -0800100 writeb(mask, host->ioaddr + SDHCI_SOFTWARE_RESET);
101
Pierre Ossmane16514d82006-06-30 02:22:24 -0700102 if (mask & SDHCI_RESET_ALL)
Pierre Ossmand129bce2006-03-24 03:18:17 -0800103 host->clock = 0;
104
Pierre Ossmane16514d82006-06-30 02:22:24 -0700105 /* Wait max 100 ms */
106 timeout = 100;
107
108 /* hw clears the bit when it's done */
109 while (readb(host->ioaddr + SDHCI_SOFTWARE_RESET) & mask) {
110 if (timeout == 0) {
Pierre Ossmanacf1da42007-02-09 08:29:19 +0100111 printk(KERN_ERR "%s: Reset 0x%x never completed.\n",
Pierre Ossmane16514d82006-06-30 02:22:24 -0700112 mmc_hostname(host->mmc), (int)mask);
113 sdhci_dumpregs(host);
114 return;
115 }
116 timeout--;
117 mdelay(1);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800118 }
119}
120
121static void sdhci_init(struct sdhci_host *host)
122{
123 u32 intmask;
124
125 sdhci_reset(host, SDHCI_RESET_ALL);
126
Pierre Ossman3192a282006-06-30 02:22:26 -0700127 intmask = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
128 SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX |
129 SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
130 SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT |
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100131 SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL |
Pierre Ossman2134a922008-06-28 18:28:51 +0200132 SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
133 SDHCI_INT_ADMA_ERROR;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800134
135 writel(intmask, host->ioaddr + SDHCI_INT_ENABLE);
136 writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800137}
138
139static void sdhci_activate_led(struct sdhci_host *host)
140{
141 u8 ctrl;
142
143 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
144 ctrl |= SDHCI_CTRL_LED;
145 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
146}
147
148static void sdhci_deactivate_led(struct sdhci_host *host)
149{
150 u8 ctrl;
151
152 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
153 ctrl &= ~SDHCI_CTRL_LED;
154 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
155}
156
Pierre Ossmanf9134312008-12-21 17:01:48 +0100157#ifdef SDHCI_USE_LEDS_CLASS
Pierre Ossman2f730fe2008-03-17 10:29:38 +0100158static void sdhci_led_control(struct led_classdev *led,
159 enum led_brightness brightness)
160{
161 struct sdhci_host *host = container_of(led, struct sdhci_host, led);
162 unsigned long flags;
163
164 spin_lock_irqsave(&host->lock, flags);
165
166 if (brightness == LED_OFF)
167 sdhci_deactivate_led(host);
168 else
169 sdhci_activate_led(host);
170
171 spin_unlock_irqrestore(&host->lock, flags);
172}
173#endif
174
Pierre Ossmand129bce2006-03-24 03:18:17 -0800175/*****************************************************************************\
176 * *
177 * Core functions *
178 * *
179\*****************************************************************************/
180
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100181static void sdhci_read_block_pio(struct sdhci_host *host)
Pierre Ossmand129bce2006-03-24 03:18:17 -0800182{
Pierre Ossman76591502008-07-21 00:32:11 +0200183 unsigned long flags;
184 size_t blksize, len, chunk;
Steven Noonan7244b852008-10-01 01:50:25 -0700185 u32 uninitialized_var(scratch);
Pierre Ossman76591502008-07-21 00:32:11 +0200186 u8 *buf;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800187
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100188 DBG("PIO reading\n");
Pierre Ossmand129bce2006-03-24 03:18:17 -0800189
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100190 blksize = host->data->blksz;
Pierre Ossman76591502008-07-21 00:32:11 +0200191 chunk = 0;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800192
Pierre Ossman76591502008-07-21 00:32:11 +0200193 local_irq_save(flags);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800194
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100195 while (blksize) {
Pierre Ossman76591502008-07-21 00:32:11 +0200196 if (!sg_miter_next(&host->sg_miter))
197 BUG();
Pierre Ossmand129bce2006-03-24 03:18:17 -0800198
Pierre Ossman76591502008-07-21 00:32:11 +0200199 len = min(host->sg_miter.length, blksize);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800200
Pierre Ossman76591502008-07-21 00:32:11 +0200201 blksize -= len;
202 host->sg_miter.consumed = len;
Alex Dubov14d836e2007-04-13 19:04:38 +0200203
Pierre Ossman76591502008-07-21 00:32:11 +0200204 buf = host->sg_miter.addr;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800205
Pierre Ossman76591502008-07-21 00:32:11 +0200206 while (len) {
207 if (chunk == 0) {
208 scratch = readl(host->ioaddr + SDHCI_BUFFER);
209 chunk = 4;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800210 }
Pierre Ossman76591502008-07-21 00:32:11 +0200211
212 *buf = scratch & 0xFF;
213
214 buf++;
215 scratch >>= 8;
216 chunk--;
217 len--;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800218 }
219 }
Pierre Ossman76591502008-07-21 00:32:11 +0200220
221 sg_miter_stop(&host->sg_miter);
222
223 local_irq_restore(flags);
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100224}
Pierre Ossmand129bce2006-03-24 03:18:17 -0800225
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100226static void sdhci_write_block_pio(struct sdhci_host *host)
227{
Pierre Ossman76591502008-07-21 00:32:11 +0200228 unsigned long flags;
229 size_t blksize, len, chunk;
230 u32 scratch;
231 u8 *buf;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100232
233 DBG("PIO writing\n");
234
235 blksize = host->data->blksz;
Pierre Ossman76591502008-07-21 00:32:11 +0200236 chunk = 0;
237 scratch = 0;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100238
Pierre Ossman76591502008-07-21 00:32:11 +0200239 local_irq_save(flags);
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100240
241 while (blksize) {
Pierre Ossman76591502008-07-21 00:32:11 +0200242 if (!sg_miter_next(&host->sg_miter))
243 BUG();
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100244
Pierre Ossman76591502008-07-21 00:32:11 +0200245 len = min(host->sg_miter.length, blksize);
Alex Dubov14d836e2007-04-13 19:04:38 +0200246
Pierre Ossman76591502008-07-21 00:32:11 +0200247 blksize -= len;
248 host->sg_miter.consumed = len;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100249
Pierre Ossman76591502008-07-21 00:32:11 +0200250 buf = host->sg_miter.addr;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100251
Pierre Ossman76591502008-07-21 00:32:11 +0200252 while (len) {
253 scratch |= (u32)*buf << (chunk * 8);
254
255 buf++;
256 chunk++;
257 len--;
258
259 if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
260 writel(scratch, host->ioaddr + SDHCI_BUFFER);
261 chunk = 0;
262 scratch = 0;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100263 }
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100264 }
265 }
Pierre Ossman76591502008-07-21 00:32:11 +0200266
267 sg_miter_stop(&host->sg_miter);
268
269 local_irq_restore(flags);
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100270}
271
272static void sdhci_transfer_pio(struct sdhci_host *host)
273{
274 u32 mask;
275
276 BUG_ON(!host->data);
277
Pierre Ossman76591502008-07-21 00:32:11 +0200278 if (host->blocks == 0)
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100279 return;
280
281 if (host->data->flags & MMC_DATA_READ)
282 mask = SDHCI_DATA_AVAILABLE;
283 else
284 mask = SDHCI_SPACE_AVAILABLE;
285
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200286 /*
287 * Some controllers (JMicron JMB38x) mess up the buffer bits
288 * for transfers < 4 bytes. As long as it is just one block,
289 * we can ignore the bits.
290 */
291 if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) &&
292 (host->data->blocks == 1))
293 mask = ~0;
294
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100295 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
296 if (host->data->flags & MMC_DATA_READ)
297 sdhci_read_block_pio(host);
298 else
299 sdhci_write_block_pio(host);
300
Pierre Ossman76591502008-07-21 00:32:11 +0200301 host->blocks--;
302 if (host->blocks == 0)
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100303 break;
Pierre Ossmana406f5a2006-07-02 16:50:59 +0100304 }
305
306 DBG("PIO transfer complete.\n");
Pierre Ossmand129bce2006-03-24 03:18:17 -0800307}
308
Pierre Ossman2134a922008-06-28 18:28:51 +0200309static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
310{
311 local_irq_save(*flags);
312 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
313}
314
315static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
316{
317 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
318 local_irq_restore(*flags);
319}
320
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200321static int sdhci_adma_table_pre(struct sdhci_host *host,
Pierre Ossman2134a922008-06-28 18:28:51 +0200322 struct mmc_data *data)
323{
324 int direction;
325
326 u8 *desc;
327 u8 *align;
328 dma_addr_t addr;
329 dma_addr_t align_addr;
330 int len, offset;
331
332 struct scatterlist *sg;
333 int i;
334 char *buffer;
335 unsigned long flags;
336
337 /*
338 * The spec does not specify endianness of descriptor table.
339 * We currently guess that it is LE.
340 */
341
342 if (data->flags & MMC_DATA_READ)
343 direction = DMA_FROM_DEVICE;
344 else
345 direction = DMA_TO_DEVICE;
346
347 /*
348 * The ADMA descriptor table is mapped further down as we
349 * need to fill it with data first.
350 */
351
352 host->align_addr = dma_map_single(mmc_dev(host->mmc),
353 host->align_buffer, 128 * 4, direction);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700354 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200355 goto fail;
Pierre Ossman2134a922008-06-28 18:28:51 +0200356 BUG_ON(host->align_addr & 0x3);
357
358 host->sg_count = dma_map_sg(mmc_dev(host->mmc),
359 data->sg, data->sg_len, direction);
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200360 if (host->sg_count == 0)
361 goto unmap_align;
Pierre Ossman2134a922008-06-28 18:28:51 +0200362
363 desc = host->adma_desc;
364 align = host->align_buffer;
365
366 align_addr = host->align_addr;
367
368 for_each_sg(data->sg, sg, host->sg_count, i) {
369 addr = sg_dma_address(sg);
370 len = sg_dma_len(sg);
371
372 /*
373 * The SDHCI specification states that ADMA
374 * addresses must be 32-bit aligned. If they
375 * aren't, then we use a bounce buffer for
376 * the (up to three) bytes that screw up the
377 * alignment.
378 */
379 offset = (4 - (addr & 0x3)) & 0x3;
380 if (offset) {
381 if (data->flags & MMC_DATA_WRITE) {
382 buffer = sdhci_kmap_atomic(sg, &flags);
Pierre Ossman6cefd052008-07-21 00:45:15 +0200383 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
Pierre Ossman2134a922008-06-28 18:28:51 +0200384 memcpy(align, buffer, offset);
385 sdhci_kunmap_atomic(buffer, &flags);
386 }
387
388 desc[7] = (align_addr >> 24) & 0xff;
389 desc[6] = (align_addr >> 16) & 0xff;
390 desc[5] = (align_addr >> 8) & 0xff;
391 desc[4] = (align_addr >> 0) & 0xff;
392
393 BUG_ON(offset > 65536);
394
395 desc[3] = (offset >> 8) & 0xff;
396 desc[2] = (offset >> 0) & 0xff;
397
398 desc[1] = 0x00;
399 desc[0] = 0x21; /* tran, valid */
400
401 align += 4;
402 align_addr += 4;
403
404 desc += 8;
405
406 addr += offset;
407 len -= offset;
408 }
409
410 desc[7] = (addr >> 24) & 0xff;
411 desc[6] = (addr >> 16) & 0xff;
412 desc[5] = (addr >> 8) & 0xff;
413 desc[4] = (addr >> 0) & 0xff;
414
415 BUG_ON(len > 65536);
416
417 desc[3] = (len >> 8) & 0xff;
418 desc[2] = (len >> 0) & 0xff;
419
420 desc[1] = 0x00;
421 desc[0] = 0x21; /* tran, valid */
422
423 desc += 8;
424
425 /*
426 * If this triggers then we have a calculation bug
427 * somewhere. :/
428 */
429 WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4);
430 }
431
432 /*
433 * Add a terminating entry.
434 */
435 desc[7] = 0;
436 desc[6] = 0;
437 desc[5] = 0;
438 desc[4] = 0;
439
440 desc[3] = 0;
441 desc[2] = 0;
442
443 desc[1] = 0x00;
444 desc[0] = 0x03; /* nop, end, valid */
445
446 /*
447 * Resync align buffer as we might have changed it.
448 */
449 if (data->flags & MMC_DATA_WRITE) {
450 dma_sync_single_for_device(mmc_dev(host->mmc),
451 host->align_addr, 128 * 4, direction);
452 }
453
454 host->adma_addr = dma_map_single(mmc_dev(host->mmc),
455 host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE);
Pierre Ossman980167b2008-07-29 00:53:20 +0200456 if (dma_mapping_error(mmc_dev(host->mmc), host->adma_addr))
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200457 goto unmap_entries;
Pierre Ossman2134a922008-06-28 18:28:51 +0200458 BUG_ON(host->adma_addr & 0x3);
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200459
460 return 0;
461
462unmap_entries:
463 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
464 data->sg_len, direction);
465unmap_align:
466 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
467 128 * 4, direction);
468fail:
469 return -EINVAL;
Pierre Ossman2134a922008-06-28 18:28:51 +0200470}
471
472static void sdhci_adma_table_post(struct sdhci_host *host,
473 struct mmc_data *data)
474{
475 int direction;
476
477 struct scatterlist *sg;
478 int i, size;
479 u8 *align;
480 char *buffer;
481 unsigned long flags;
482
483 if (data->flags & MMC_DATA_READ)
484 direction = DMA_FROM_DEVICE;
485 else
486 direction = DMA_TO_DEVICE;
487
488 dma_unmap_single(mmc_dev(host->mmc), host->adma_addr,
489 (128 * 2 + 1) * 4, DMA_TO_DEVICE);
490
491 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
492 128 * 4, direction);
493
494 if (data->flags & MMC_DATA_READ) {
495 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg,
496 data->sg_len, direction);
497
498 align = host->align_buffer;
499
500 for_each_sg(data->sg, sg, host->sg_count, i) {
501 if (sg_dma_address(sg) & 0x3) {
502 size = 4 - (sg_dma_address(sg) & 0x3);
503
504 buffer = sdhci_kmap_atomic(sg, &flags);
Pierre Ossman6cefd052008-07-21 00:45:15 +0200505 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
Pierre Ossman2134a922008-06-28 18:28:51 +0200506 memcpy(buffer, align, size);
507 sdhci_kunmap_atomic(buffer, &flags);
508
509 align += 4;
510 }
511 }
512 }
513
514 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
515 data->sg_len, direction);
516}
517
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200518static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
Pierre Ossmand129bce2006-03-24 03:18:17 -0800519{
Pierre Ossman1c8cde92006-06-30 02:22:25 -0700520 u8 count;
521 unsigned target_timeout, current_timeout;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800522
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200523 /*
524 * If the host controller provides us with an incorrect timeout
525 * value, just skip the check and use 0xE. The hardware may take
526 * longer to time out, but that's much better than having a too-short
527 * timeout value.
528 */
529 if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL))
530 return 0xE;
Pierre Ossmane538fbe2007-08-12 16:46:32 +0200531
Pierre Ossman1c8cde92006-06-30 02:22:25 -0700532 /* timeout in us */
533 target_timeout = data->timeout_ns / 1000 +
534 data->timeout_clks / host->clock;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800535
Pierre Ossman1c8cde92006-06-30 02:22:25 -0700536 /*
537 * Figure out needed cycles.
538 * We do this in steps in order to fit inside a 32 bit int.
539 * The first step is the minimum timeout, which will have a
540 * minimum resolution of 6 bits:
541 * (1) 2^13*1000 > 2^22,
542 * (2) host->timeout_clk < 2^16
543 * =>
544 * (1) / (2) > 2^6
545 */
546 count = 0;
547 current_timeout = (1 << 13) * 1000 / host->timeout_clk;
548 while (current_timeout < target_timeout) {
549 count++;
550 current_timeout <<= 1;
551 if (count >= 0xF)
552 break;
553 }
554
555 if (count >= 0xF) {
556 printk(KERN_WARNING "%s: Too large timeout requested!\n",
557 mmc_hostname(host->mmc));
558 count = 0xE;
559 }
560
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200561 return count;
562}
563
564static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
565{
566 u8 count;
Pierre Ossman2134a922008-06-28 18:28:51 +0200567 u8 ctrl;
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200568 int ret;
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200569
570 WARN_ON(host->data);
571
572 if (data == NULL)
573 return;
574
575 /* Sanity checks */
576 BUG_ON(data->blksz * data->blocks > 524288);
577 BUG_ON(data->blksz > host->mmc->max_blk_size);
578 BUG_ON(data->blocks > 65535);
579
580 host->data = data;
581 host->data_early = 0;
582
583 count = sdhci_calc_timeout(host, data);
Pierre Ossman1c8cde92006-06-30 02:22:25 -0700584 writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800585
Pierre Ossmanc9fddbc2007-12-02 19:52:11 +0100586 if (host->flags & SDHCI_USE_DMA)
587 host->flags |= SDHCI_REQ_USE_DMA;
588
Pierre Ossman2134a922008-06-28 18:28:51 +0200589 /*
590 * FIXME: This doesn't account for merging when mapping the
591 * scatterlist.
592 */
593 if (host->flags & SDHCI_REQ_USE_DMA) {
594 int broken, i;
595 struct scatterlist *sg;
596
597 broken = 0;
598 if (host->flags & SDHCI_USE_ADMA) {
599 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
600 broken = 1;
601 } else {
602 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
603 broken = 1;
604 }
605
606 if (unlikely(broken)) {
607 for_each_sg(data->sg, sg, data->sg_len, i) {
608 if (sg->length & 0x3) {
609 DBG("Reverting to PIO because of "
610 "transfer size (%d)\n",
611 sg->length);
612 host->flags &= ~SDHCI_REQ_USE_DMA;
613 break;
614 }
615 }
616 }
Pierre Ossmanc9fddbc2007-12-02 19:52:11 +0100617 }
618
619 /*
620 * The assumption here being that alignment is the same after
621 * translation to device address space.
622 */
Pierre Ossman2134a922008-06-28 18:28:51 +0200623 if (host->flags & SDHCI_REQ_USE_DMA) {
624 int broken, i;
625 struct scatterlist *sg;
626
627 broken = 0;
628 if (host->flags & SDHCI_USE_ADMA) {
629 /*
630 * As we use 3 byte chunks to work around
631 * alignment problems, we need to check this
632 * quirk.
633 */
634 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
635 broken = 1;
636 } else {
637 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR)
638 broken = 1;
639 }
640
641 if (unlikely(broken)) {
642 for_each_sg(data->sg, sg, data->sg_len, i) {
643 if (sg->offset & 0x3) {
644 DBG("Reverting to PIO because of "
645 "bad alignment\n");
646 host->flags &= ~SDHCI_REQ_USE_DMA;
647 break;
648 }
649 }
650 }
651 }
652
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200653 if (host->flags & SDHCI_REQ_USE_DMA) {
654 if (host->flags & SDHCI_USE_ADMA) {
655 ret = sdhci_adma_table_pre(host, data);
656 if (ret) {
657 /*
658 * This only happens when someone fed
659 * us an invalid request.
660 */
661 WARN_ON(1);
Pierre Ossmanebd6d352008-07-29 00:45:51 +0200662 host->flags &= ~SDHCI_REQ_USE_DMA;
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200663 } else {
664 writel(host->adma_addr,
665 host->ioaddr + SDHCI_ADMA_ADDRESS);
666 }
667 } else {
Tomas Winklerc8b3e022008-07-05 19:52:04 +0300668 int sg_cnt;
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200669
Tomas Winklerc8b3e022008-07-05 19:52:04 +0300670 sg_cnt = dma_map_sg(mmc_dev(host->mmc),
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200671 data->sg, data->sg_len,
672 (data->flags & MMC_DATA_READ) ?
673 DMA_FROM_DEVICE :
674 DMA_TO_DEVICE);
Tomas Winklerc8b3e022008-07-05 19:52:04 +0300675 if (sg_cnt == 0) {
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200676 /*
677 * This only happens when someone fed
678 * us an invalid request.
679 */
680 WARN_ON(1);
Pierre Ossmanebd6d352008-07-29 00:45:51 +0200681 host->flags &= ~SDHCI_REQ_USE_DMA;
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200682 } else {
Pierre Ossman719a61b2008-07-22 13:23:23 +0200683 WARN_ON(sg_cnt != 1);
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200684 writel(sg_dma_address(data->sg),
685 host->ioaddr + SDHCI_DMA_ADDRESS);
686 }
687 }
688 }
689
Pierre Ossman2134a922008-06-28 18:28:51 +0200690 /*
691 * Always adjust the DMA selection as some controllers
692 * (e.g. JMicron) can't do PIO properly when the selection
693 * is ADMA.
694 */
695 if (host->version >= SDHCI_SPEC_200) {
696 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
697 ctrl &= ~SDHCI_CTRL_DMA_MASK;
698 if ((host->flags & SDHCI_REQ_USE_DMA) &&
699 (host->flags & SDHCI_USE_ADMA))
700 ctrl |= SDHCI_CTRL_ADMA32;
701 else
702 ctrl |= SDHCI_CTRL_SDMA;
703 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
Pierre Ossmanc9fddbc2007-12-02 19:52:11 +0100704 }
705
Pierre Ossman8f1934c2008-06-30 21:15:49 +0200706 if (!(host->flags & SDHCI_REQ_USE_DMA)) {
Pierre Ossman76591502008-07-21 00:32:11 +0200707 sg_miter_start(&host->sg_miter,
708 data->sg, data->sg_len, SG_MITER_ATOMIC);
709 host->blocks = data->blocks;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800710 }
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700711
Pierre Ossmanbab76962006-07-02 16:51:35 +0100712 /* We do not handle DMA boundaries, so set it to max (512 KiB) */
713 writew(SDHCI_MAKE_BLKSZ(7, data->blksz),
714 host->ioaddr + SDHCI_BLOCK_SIZE);
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700715 writew(data->blocks, host->ioaddr + SDHCI_BLOCK_COUNT);
716}
717
718static void sdhci_set_transfer_mode(struct sdhci_host *host,
719 struct mmc_data *data)
720{
721 u16 mode;
722
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700723 if (data == NULL)
724 return;
725
Pierre Ossmane538fbe2007-08-12 16:46:32 +0200726 WARN_ON(!host->data);
727
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700728 mode = SDHCI_TRNS_BLK_CNT_EN;
729 if (data->blocks > 1)
730 mode |= SDHCI_TRNS_MULTI;
731 if (data->flags & MMC_DATA_READ)
732 mode |= SDHCI_TRNS_READ;
Pierre Ossmanc9fddbc2007-12-02 19:52:11 +0100733 if (host->flags & SDHCI_REQ_USE_DMA)
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700734 mode |= SDHCI_TRNS_DMA;
735
736 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE);
Pierre Ossmand129bce2006-03-24 03:18:17 -0800737}
738
739static void sdhci_finish_data(struct sdhci_host *host)
740{
741 struct mmc_data *data;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800742
743 BUG_ON(!host->data);
744
745 data = host->data;
746 host->data = NULL;
747
Pierre Ossmanc9fddbc2007-12-02 19:52:11 +0100748 if (host->flags & SDHCI_REQ_USE_DMA) {
Pierre Ossman2134a922008-06-28 18:28:51 +0200749 if (host->flags & SDHCI_USE_ADMA)
750 sdhci_adma_table_post(host, data);
751 else {
752 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
753 data->sg_len, (data->flags & MMC_DATA_READ) ?
754 DMA_FROM_DEVICE : DMA_TO_DEVICE);
755 }
Pierre Ossmand129bce2006-03-24 03:18:17 -0800756 }
757
758 /*
Pierre Ossmanc9b74c52008-04-18 20:41:49 +0200759 * The specification states that the block count register must
760 * be updated, but it does not specify at what point in the
761 * data flow. That makes the register entirely useless to read
762 * back so we have to assume that nothing made it to the card
763 * in the event of an error.
Pierre Ossmand129bce2006-03-24 03:18:17 -0800764 */
Pierre Ossmanc9b74c52008-04-18 20:41:49 +0200765 if (data->error)
766 data->bytes_xfered = 0;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800767 else
Pierre Ossmanc9b74c52008-04-18 20:41:49 +0200768 data->bytes_xfered = data->blksz * data->blocks;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800769
Pierre Ossmand129bce2006-03-24 03:18:17 -0800770 if (data->stop) {
771 /*
772 * The controller needs a reset of internal state machines
773 * upon error conditions.
774 */
Pierre Ossman17b04292007-07-22 22:18:46 +0200775 if (data->error) {
Pierre Ossmand129bce2006-03-24 03:18:17 -0800776 sdhci_reset(host, SDHCI_RESET_CMD);
777 sdhci_reset(host, SDHCI_RESET_DATA);
778 }
779
780 sdhci_send_command(host, data->stop);
781 } else
782 tasklet_schedule(&host->finish_tasklet);
783}
784
785static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
786{
787 int flags;
Pierre Ossmanfd2208d2006-06-30 02:22:28 -0700788 u32 mask;
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700789 unsigned long timeout;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800790
791 WARN_ON(host->cmd);
792
Pierre Ossmand129bce2006-03-24 03:18:17 -0800793 /* Wait max 10 ms */
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700794 timeout = 10;
Pierre Ossmanfd2208d2006-06-30 02:22:28 -0700795
796 mask = SDHCI_CMD_INHIBIT;
797 if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
798 mask |= SDHCI_DATA_INHIBIT;
799
800 /* We shouldn't wait for data inihibit for stop commands, even
801 though they might use busy signaling */
802 if (host->mrq->data && (cmd == host->mrq->data->stop))
803 mask &= ~SDHCI_DATA_INHIBIT;
804
805 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700806 if (timeout == 0) {
Pierre Ossmand129bce2006-03-24 03:18:17 -0800807 printk(KERN_ERR "%s: Controller never released "
Pierre Ossmanacf1da42007-02-09 08:29:19 +0100808 "inhibit bit(s).\n", mmc_hostname(host->mmc));
Pierre Ossmand129bce2006-03-24 03:18:17 -0800809 sdhci_dumpregs(host);
Pierre Ossman17b04292007-07-22 22:18:46 +0200810 cmd->error = -EIO;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800811 tasklet_schedule(&host->finish_tasklet);
812 return;
813 }
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700814 timeout--;
815 mdelay(1);
816 }
Pierre Ossmand129bce2006-03-24 03:18:17 -0800817
818 mod_timer(&host->timer, jiffies + 10 * HZ);
819
820 host->cmd = cmd;
821
822 sdhci_prepare_data(host, cmd->data);
823
824 writel(cmd->arg, host->ioaddr + SDHCI_ARGUMENT);
825
Pierre Ossmanc7fa9962006-06-30 02:22:25 -0700826 sdhci_set_transfer_mode(host, cmd->data);
827
Pierre Ossmand129bce2006-03-24 03:18:17 -0800828 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
Pierre Ossmanacf1da42007-02-09 08:29:19 +0100829 printk(KERN_ERR "%s: Unsupported response type!\n",
Pierre Ossmand129bce2006-03-24 03:18:17 -0800830 mmc_hostname(host->mmc));
Pierre Ossman17b04292007-07-22 22:18:46 +0200831 cmd->error = -EINVAL;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800832 tasklet_schedule(&host->finish_tasklet);
833 return;
834 }
835
836 if (!(cmd->flags & MMC_RSP_PRESENT))
837 flags = SDHCI_CMD_RESP_NONE;
838 else if (cmd->flags & MMC_RSP_136)
839 flags = SDHCI_CMD_RESP_LONG;
840 else if (cmd->flags & MMC_RSP_BUSY)
841 flags = SDHCI_CMD_RESP_SHORT_BUSY;
842 else
843 flags = SDHCI_CMD_RESP_SHORT;
844
845 if (cmd->flags & MMC_RSP_CRC)
846 flags |= SDHCI_CMD_CRC;
847 if (cmd->flags & MMC_RSP_OPCODE)
848 flags |= SDHCI_CMD_INDEX;
849 if (cmd->data)
850 flags |= SDHCI_CMD_DATA;
851
Pierre Ossmanfb61e282006-07-11 21:06:48 +0200852 writew(SDHCI_MAKE_CMD(cmd->opcode, flags),
Pierre Ossmand129bce2006-03-24 03:18:17 -0800853 host->ioaddr + SDHCI_COMMAND);
854}
855
856static void sdhci_finish_command(struct sdhci_host *host)
857{
858 int i;
859
860 BUG_ON(host->cmd == NULL);
861
862 if (host->cmd->flags & MMC_RSP_PRESENT) {
863 if (host->cmd->flags & MMC_RSP_136) {
864 /* CRC is stripped so we need to do some shifting. */
865 for (i = 0;i < 4;i++) {
866 host->cmd->resp[i] = readl(host->ioaddr +
867 SDHCI_RESPONSE + (3-i)*4) << 8;
868 if (i != 3)
869 host->cmd->resp[i] |=
870 readb(host->ioaddr +
871 SDHCI_RESPONSE + (3-i)*4-1);
872 }
873 } else {
874 host->cmd->resp[0] = readl(host->ioaddr + SDHCI_RESPONSE);
875 }
876 }
877
Pierre Ossman17b04292007-07-22 22:18:46 +0200878 host->cmd->error = 0;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800879
Pierre Ossmane538fbe2007-08-12 16:46:32 +0200880 if (host->data && host->data_early)
881 sdhci_finish_data(host);
882
883 if (!host->cmd->data)
Pierre Ossmand129bce2006-03-24 03:18:17 -0800884 tasklet_schedule(&host->finish_tasklet);
885
886 host->cmd = NULL;
887}
888
889static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
890{
891 int div;
892 u16 clk;
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700893 unsigned long timeout;
Pierre Ossmand129bce2006-03-24 03:18:17 -0800894
895 if (clock == host->clock)
896 return;
897
898 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
899
900 if (clock == 0)
901 goto out;
902
903 for (div = 1;div < 256;div *= 2) {
904 if ((host->max_clk / div) <= clock)
905 break;
906 }
907 div >>= 1;
908
909 clk = div << SDHCI_DIVIDER_SHIFT;
910 clk |= SDHCI_CLOCK_INT_EN;
911 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
912
913 /* Wait max 10 ms */
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700914 timeout = 10;
915 while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL))
916 & SDHCI_CLOCK_INT_STABLE)) {
917 if (timeout == 0) {
Pierre Ossmanacf1da42007-02-09 08:29:19 +0100918 printk(KERN_ERR "%s: Internal clock never "
919 "stabilised.\n", mmc_hostname(host->mmc));
Pierre Ossmand129bce2006-03-24 03:18:17 -0800920 sdhci_dumpregs(host);
921 return;
922 }
Pierre Ossman7cb2c762006-06-30 02:22:23 -0700923 timeout--;
924 mdelay(1);
925 }
Pierre Ossmand129bce2006-03-24 03:18:17 -0800926
927 clk |= SDHCI_CLOCK_CARD_EN;
928 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
929
930out:
931 host->clock = clock;
932}
933
Pierre Ossman146ad662006-06-30 02:22:23 -0700934static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
935{
936 u8 pwr;
937
938 if (host->power == power)
939 return;
940
Darren Salt9e9dc5f2007-01-27 15:32:31 +0100941 if (power == (unsigned short)-1) {
942 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
Pierre Ossman146ad662006-06-30 02:22:23 -0700943 goto out;
Darren Salt9e9dc5f2007-01-27 15:32:31 +0100944 }
945
946 /*
947 * Spec says that we should clear the power reg before setting
948 * a new value. Some controllers don't seem to like this though.
949 */
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100950 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE))
Darren Salt9e9dc5f2007-01-27 15:32:31 +0100951 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
Pierre Ossman146ad662006-06-30 02:22:23 -0700952
953 pwr = SDHCI_POWER_ON;
954
Philip Langdale4be34c92007-03-11 17:15:15 -0700955 switch (1 << power) {
Philip Langdale55556da2007-03-16 19:39:00 -0700956 case MMC_VDD_165_195:
Pierre Ossman146ad662006-06-30 02:22:23 -0700957 pwr |= SDHCI_POWER_180;
958 break;
Philip Langdale4be34c92007-03-11 17:15:15 -0700959 case MMC_VDD_29_30:
960 case MMC_VDD_30_31:
Pierre Ossman146ad662006-06-30 02:22:23 -0700961 pwr |= SDHCI_POWER_300;
962 break;
Philip Langdale4be34c92007-03-11 17:15:15 -0700963 case MMC_VDD_32_33:
964 case MMC_VDD_33_34:
Pierre Ossman146ad662006-06-30 02:22:23 -0700965 pwr |= SDHCI_POWER_330;
966 break;
967 default:
968 BUG();
969 }
970
Andres Salomone08c1692008-07-04 10:00:03 -0700971 /*
Andres Salomonc71f6512008-07-07 17:25:56 -0400972 * At least the Marvell CaFe chip gets confused if we set the voltage
Andres Salomone08c1692008-07-04 10:00:03 -0700973 * and set turn on power at the same time, so set the voltage first.
974 */
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100975 if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
Andres Salomone08c1692008-07-04 10:00:03 -0700976 writeb(pwr & ~SDHCI_POWER_ON,
977 host->ioaddr + SDHCI_POWER_CONTROL);
978
Pierre Ossman146ad662006-06-30 02:22:23 -0700979 writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL);
980
981out:
982 host->power = power;
983}
984
Pierre Ossmand129bce2006-03-24 03:18:17 -0800985/*****************************************************************************\
986 * *
987 * MMC callbacks *
988 * *
989\*****************************************************************************/
990
991static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
992{
993 struct sdhci_host *host;
994 unsigned long flags;
995
996 host = mmc_priv(mmc);
997
998 spin_lock_irqsave(&host->lock, flags);
999
1000 WARN_ON(host->mrq != NULL);
1001
Pierre Ossmanf9134312008-12-21 17:01:48 +01001002#ifndef SDHCI_USE_LEDS_CLASS
Pierre Ossmand129bce2006-03-24 03:18:17 -08001003 sdhci_activate_led(host);
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001004#endif
Pierre Ossmand129bce2006-03-24 03:18:17 -08001005
1006 host->mrq = mrq;
1007
Pierre Ossman1e728592008-04-16 19:13:13 +02001008 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)
1009 || (host->flags & SDHCI_DEVICE_DEAD)) {
Pierre Ossman17b04292007-07-22 22:18:46 +02001010 host->mrq->cmd->error = -ENOMEDIUM;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001011 tasklet_schedule(&host->finish_tasklet);
1012 } else
1013 sdhci_send_command(host, mrq->cmd);
1014
Pierre Ossman5f25a662006-10-04 02:15:39 -07001015 mmiowb();
Pierre Ossmand129bce2006-03-24 03:18:17 -08001016 spin_unlock_irqrestore(&host->lock, flags);
1017}
1018
1019static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1020{
1021 struct sdhci_host *host;
1022 unsigned long flags;
1023 u8 ctrl;
1024
1025 host = mmc_priv(mmc);
1026
1027 spin_lock_irqsave(&host->lock, flags);
1028
Pierre Ossman1e728592008-04-16 19:13:13 +02001029 if (host->flags & SDHCI_DEVICE_DEAD)
1030 goto out;
1031
Pierre Ossmand129bce2006-03-24 03:18:17 -08001032 /*
1033 * Reset the chip on each power off.
1034 * Should clear out any weird states.
1035 */
1036 if (ios->power_mode == MMC_POWER_OFF) {
1037 writel(0, host->ioaddr + SDHCI_SIGNAL_ENABLE);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001038 sdhci_init(host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001039 }
1040
1041 sdhci_set_clock(host, ios->clock);
1042
1043 if (ios->power_mode == MMC_POWER_OFF)
Pierre Ossman146ad662006-06-30 02:22:23 -07001044 sdhci_set_power(host, -1);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001045 else
Pierre Ossman146ad662006-06-30 02:22:23 -07001046 sdhci_set_power(host, ios->vdd);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001047
1048 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
Pierre Ossmancd9277c2007-02-18 12:07:47 +01001049
Pierre Ossmand129bce2006-03-24 03:18:17 -08001050 if (ios->bus_width == MMC_BUS_WIDTH_4)
1051 ctrl |= SDHCI_CTRL_4BITBUS;
1052 else
1053 ctrl &= ~SDHCI_CTRL_4BITBUS;
Pierre Ossmancd9277c2007-02-18 12:07:47 +01001054
1055 if (ios->timing == MMC_TIMING_SD_HS)
1056 ctrl |= SDHCI_CTRL_HISPD;
1057 else
1058 ctrl &= ~SDHCI_CTRL_HISPD;
1059
Pierre Ossmand129bce2006-03-24 03:18:17 -08001060 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
1061
Leandro Dorileob8352262007-07-25 23:47:04 +02001062 /*
1063 * Some (ENE) controllers go apeshit on some ios operation,
1064 * signalling timeout and CRC errors even on CMD0. Resetting
1065 * it on each ios seems to solve the problem.
1066 */
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001067 if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
Leandro Dorileob8352262007-07-25 23:47:04 +02001068 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
1069
Pierre Ossman1e728592008-04-16 19:13:13 +02001070out:
Pierre Ossman5f25a662006-10-04 02:15:39 -07001071 mmiowb();
Pierre Ossmand129bce2006-03-24 03:18:17 -08001072 spin_unlock_irqrestore(&host->lock, flags);
1073}
1074
1075static int sdhci_get_ro(struct mmc_host *mmc)
1076{
1077 struct sdhci_host *host;
1078 unsigned long flags;
1079 int present;
1080
1081 host = mmc_priv(mmc);
1082
1083 spin_lock_irqsave(&host->lock, flags);
1084
Pierre Ossman1e728592008-04-16 19:13:13 +02001085 if (host->flags & SDHCI_DEVICE_DEAD)
1086 present = 0;
1087 else
1088 present = readl(host->ioaddr + SDHCI_PRESENT_STATE);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001089
1090 spin_unlock_irqrestore(&host->lock, flags);
1091
1092 return !(present & SDHCI_WRITE_PROTECT);
1093}
1094
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001095static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1096{
1097 struct sdhci_host *host;
1098 unsigned long flags;
1099 u32 ier;
1100
1101 host = mmc_priv(mmc);
1102
1103 spin_lock_irqsave(&host->lock, flags);
1104
Pierre Ossman1e728592008-04-16 19:13:13 +02001105 if (host->flags & SDHCI_DEVICE_DEAD)
1106 goto out;
1107
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001108 ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
1109
1110 ier &= ~SDHCI_INT_CARD_INT;
1111 if (enable)
1112 ier |= SDHCI_INT_CARD_INT;
1113
1114 writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
1115 writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
1116
Pierre Ossman1e728592008-04-16 19:13:13 +02001117out:
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001118 mmiowb();
1119
1120 spin_unlock_irqrestore(&host->lock, flags);
1121}
1122
David Brownellab7aefd2006-11-12 17:55:30 -08001123static const struct mmc_host_ops sdhci_ops = {
Pierre Ossmand129bce2006-03-24 03:18:17 -08001124 .request = sdhci_request,
1125 .set_ios = sdhci_set_ios,
1126 .get_ro = sdhci_get_ro,
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001127 .enable_sdio_irq = sdhci_enable_sdio_irq,
Pierre Ossmand129bce2006-03-24 03:18:17 -08001128};
1129
1130/*****************************************************************************\
1131 * *
1132 * Tasklets *
1133 * *
1134\*****************************************************************************/
1135
1136static void sdhci_tasklet_card(unsigned long param)
1137{
1138 struct sdhci_host *host;
1139 unsigned long flags;
1140
1141 host = (struct sdhci_host*)param;
1142
1143 spin_lock_irqsave(&host->lock, flags);
1144
1145 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
1146 if (host->mrq) {
1147 printk(KERN_ERR "%s: Card removed during transfer!\n",
1148 mmc_hostname(host->mmc));
1149 printk(KERN_ERR "%s: Resetting controller.\n",
1150 mmc_hostname(host->mmc));
1151
1152 sdhci_reset(host, SDHCI_RESET_CMD);
1153 sdhci_reset(host, SDHCI_RESET_DATA);
1154
Pierre Ossman17b04292007-07-22 22:18:46 +02001155 host->mrq->cmd->error = -ENOMEDIUM;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001156 tasklet_schedule(&host->finish_tasklet);
1157 }
1158 }
1159
1160 spin_unlock_irqrestore(&host->lock, flags);
1161
Pierre Ossman04cf5852008-08-18 22:18:14 +02001162 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
Pierre Ossmand129bce2006-03-24 03:18:17 -08001163}
1164
1165static void sdhci_tasklet_finish(unsigned long param)
1166{
1167 struct sdhci_host *host;
1168 unsigned long flags;
1169 struct mmc_request *mrq;
1170
1171 host = (struct sdhci_host*)param;
1172
1173 spin_lock_irqsave(&host->lock, flags);
1174
1175 del_timer(&host->timer);
1176
1177 mrq = host->mrq;
1178
Pierre Ossmand129bce2006-03-24 03:18:17 -08001179 /*
1180 * The controller needs a reset of internal state machines
1181 * upon error conditions.
1182 */
Pierre Ossman1e728592008-04-16 19:13:13 +02001183 if (!(host->flags & SDHCI_DEVICE_DEAD) &&
1184 (mrq->cmd->error ||
1185 (mrq->data && (mrq->data->error ||
1186 (mrq->data->stop && mrq->data->stop->error))) ||
1187 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) {
Pierre Ossman645289d2006-06-30 02:22:33 -07001188
1189 /* Some controllers need this kick or reset won't work here */
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001190 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
Pierre Ossman645289d2006-06-30 02:22:33 -07001191 unsigned int clock;
1192
1193 /* This is to force an update */
1194 clock = host->clock;
1195 host->clock = 0;
1196 sdhci_set_clock(host, clock);
1197 }
1198
1199 /* Spec says we should do both at the same time, but Ricoh
1200 controllers do not like that. */
Pierre Ossmand129bce2006-03-24 03:18:17 -08001201 sdhci_reset(host, SDHCI_RESET_CMD);
1202 sdhci_reset(host, SDHCI_RESET_DATA);
1203 }
1204
1205 host->mrq = NULL;
1206 host->cmd = NULL;
1207 host->data = NULL;
1208
Pierre Ossmanf9134312008-12-21 17:01:48 +01001209#ifndef SDHCI_USE_LEDS_CLASS
Pierre Ossmand129bce2006-03-24 03:18:17 -08001210 sdhci_deactivate_led(host);
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001211#endif
Pierre Ossmand129bce2006-03-24 03:18:17 -08001212
Pierre Ossman5f25a662006-10-04 02:15:39 -07001213 mmiowb();
Pierre Ossmand129bce2006-03-24 03:18:17 -08001214 spin_unlock_irqrestore(&host->lock, flags);
1215
1216 mmc_request_done(host->mmc, mrq);
1217}
1218
1219static void sdhci_timeout_timer(unsigned long data)
1220{
1221 struct sdhci_host *host;
1222 unsigned long flags;
1223
1224 host = (struct sdhci_host*)data;
1225
1226 spin_lock_irqsave(&host->lock, flags);
1227
1228 if (host->mrq) {
Pierre Ossmanacf1da42007-02-09 08:29:19 +01001229 printk(KERN_ERR "%s: Timeout waiting for hardware "
1230 "interrupt.\n", mmc_hostname(host->mmc));
Pierre Ossmand129bce2006-03-24 03:18:17 -08001231 sdhci_dumpregs(host);
1232
1233 if (host->data) {
Pierre Ossman17b04292007-07-22 22:18:46 +02001234 host->data->error = -ETIMEDOUT;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001235 sdhci_finish_data(host);
1236 } else {
1237 if (host->cmd)
Pierre Ossman17b04292007-07-22 22:18:46 +02001238 host->cmd->error = -ETIMEDOUT;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001239 else
Pierre Ossman17b04292007-07-22 22:18:46 +02001240 host->mrq->cmd->error = -ETIMEDOUT;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001241
1242 tasklet_schedule(&host->finish_tasklet);
1243 }
1244 }
1245
Pierre Ossman5f25a662006-10-04 02:15:39 -07001246 mmiowb();
Pierre Ossmand129bce2006-03-24 03:18:17 -08001247 spin_unlock_irqrestore(&host->lock, flags);
1248}
1249
1250/*****************************************************************************\
1251 * *
1252 * Interrupt handling *
1253 * *
1254\*****************************************************************************/
1255
1256static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
1257{
1258 BUG_ON(intmask == 0);
1259
1260 if (!host->cmd) {
Pierre Ossmanb67ac3f2007-08-12 17:29:47 +02001261 printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
1262 "though no command operation was in progress.\n",
1263 mmc_hostname(host->mmc), (unsigned)intmask);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001264 sdhci_dumpregs(host);
1265 return;
1266 }
1267
Pierre Ossman43b58b32007-07-25 23:15:27 +02001268 if (intmask & SDHCI_INT_TIMEOUT)
Pierre Ossman17b04292007-07-22 22:18:46 +02001269 host->cmd->error = -ETIMEDOUT;
1270 else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
1271 SDHCI_INT_INDEX))
1272 host->cmd->error = -EILSEQ;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001273
Pierre Ossmane8095172008-07-25 01:09:08 +02001274 if (host->cmd->error) {
Pierre Ossmand129bce2006-03-24 03:18:17 -08001275 tasklet_schedule(&host->finish_tasklet);
Pierre Ossmane8095172008-07-25 01:09:08 +02001276 return;
1277 }
1278
1279 /*
1280 * The host can send and interrupt when the busy state has
1281 * ended, allowing us to wait without wasting CPU cycles.
1282 * Unfortunately this is overloaded on the "data complete"
1283 * interrupt, so we need to take some care when handling
1284 * it.
1285 *
1286 * Note: The 1.0 specification is a bit ambiguous about this
1287 * feature so there might be some problems with older
1288 * controllers.
1289 */
1290 if (host->cmd->flags & MMC_RSP_BUSY) {
1291 if (host->cmd->data)
1292 DBG("Cannot wait for busy signal when also "
1293 "doing a data transfer");
1294 else
1295 return;
1296 }
1297
1298 if (intmask & SDHCI_INT_RESPONSE)
Pierre Ossman43b58b32007-07-25 23:15:27 +02001299 sdhci_finish_command(host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001300}
1301
1302static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
1303{
1304 BUG_ON(intmask == 0);
1305
1306 if (!host->data) {
1307 /*
Pierre Ossmane8095172008-07-25 01:09:08 +02001308 * The "data complete" interrupt is also used to
1309 * indicate that a busy state has ended. See comment
1310 * above in sdhci_cmd_irq().
Pierre Ossmand129bce2006-03-24 03:18:17 -08001311 */
Pierre Ossmane8095172008-07-25 01:09:08 +02001312 if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
1313 if (intmask & SDHCI_INT_DATA_END) {
1314 sdhci_finish_command(host);
1315 return;
1316 }
1317 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001318
Pierre Ossmanb67ac3f2007-08-12 17:29:47 +02001319 printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
1320 "though no data operation was in progress.\n",
1321 mmc_hostname(host->mmc), (unsigned)intmask);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001322 sdhci_dumpregs(host);
1323
1324 return;
1325 }
1326
1327 if (intmask & SDHCI_INT_DATA_TIMEOUT)
Pierre Ossman17b04292007-07-22 22:18:46 +02001328 host->data->error = -ETIMEDOUT;
1329 else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
1330 host->data->error = -EILSEQ;
Pierre Ossman2134a922008-06-28 18:28:51 +02001331 else if (intmask & SDHCI_INT_ADMA_ERROR)
1332 host->data->error = -EIO;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001333
Pierre Ossman17b04292007-07-22 22:18:46 +02001334 if (host->data->error)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001335 sdhci_finish_data(host);
1336 else {
Pierre Ossmana406f5a2006-07-02 16:50:59 +01001337 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
Pierre Ossmand129bce2006-03-24 03:18:17 -08001338 sdhci_transfer_pio(host);
1339
Pierre Ossman6ba736a2007-05-13 22:39:23 +02001340 /*
1341 * We currently don't do anything fancy with DMA
1342 * boundaries, but as we can't disable the feature
1343 * we need to at least restart the transfer.
1344 */
1345 if (intmask & SDHCI_INT_DMA_END)
1346 writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS),
1347 host->ioaddr + SDHCI_DMA_ADDRESS);
1348
Pierre Ossmane538fbe2007-08-12 16:46:32 +02001349 if (intmask & SDHCI_INT_DATA_END) {
1350 if (host->cmd) {
1351 /*
1352 * Data managed to finish before the
1353 * command completed. Make sure we do
1354 * things in the proper order.
1355 */
1356 host->data_early = 1;
1357 } else {
1358 sdhci_finish_data(host);
1359 }
1360 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001361 }
1362}
1363
David Howells7d12e782006-10-05 14:55:46 +01001364static irqreturn_t sdhci_irq(int irq, void *dev_id)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001365{
1366 irqreturn_t result;
1367 struct sdhci_host* host = dev_id;
1368 u32 intmask;
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001369 int cardint = 0;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001370
1371 spin_lock(&host->lock);
1372
1373 intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
1374
Mark Lord62df67a52007-03-06 13:30:13 +01001375 if (!intmask || intmask == 0xffffffff) {
Pierre Ossmand129bce2006-03-24 03:18:17 -08001376 result = IRQ_NONE;
1377 goto out;
1378 }
1379
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001380 DBG("*** %s got interrupt: 0x%08x\n",
1381 mmc_hostname(host->mmc), intmask);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001382
Pierre Ossman3192a282006-06-30 02:22:26 -07001383 if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
1384 writel(intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE),
1385 host->ioaddr + SDHCI_INT_STATUS);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001386 tasklet_schedule(&host->card_tasklet);
Pierre Ossman3192a282006-06-30 02:22:26 -07001387 }
1388
1389 intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001390
1391 if (intmask & SDHCI_INT_CMD_MASK) {
Pierre Ossmand129bce2006-03-24 03:18:17 -08001392 writel(intmask & SDHCI_INT_CMD_MASK,
1393 host->ioaddr + SDHCI_INT_STATUS);
Pierre Ossman3192a282006-06-30 02:22:26 -07001394 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001395 }
1396
1397 if (intmask & SDHCI_INT_DATA_MASK) {
Pierre Ossmand129bce2006-03-24 03:18:17 -08001398 writel(intmask & SDHCI_INT_DATA_MASK,
1399 host->ioaddr + SDHCI_INT_STATUS);
Pierre Ossman3192a282006-06-30 02:22:26 -07001400 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001401 }
1402
1403 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
1404
Pierre Ossman964f9ce2007-07-20 18:20:36 +02001405 intmask &= ~SDHCI_INT_ERROR;
1406
Pierre Ossmand129bce2006-03-24 03:18:17 -08001407 if (intmask & SDHCI_INT_BUS_POWER) {
Pierre Ossman3192a282006-06-30 02:22:26 -07001408 printk(KERN_ERR "%s: Card is consuming too much power!\n",
Pierre Ossmand129bce2006-03-24 03:18:17 -08001409 mmc_hostname(host->mmc));
Pierre Ossman3192a282006-06-30 02:22:26 -07001410 writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001411 }
1412
Rolf Eike Beer9d26a5d2007-06-26 13:31:16 +02001413 intmask &= ~SDHCI_INT_BUS_POWER;
Pierre Ossman3192a282006-06-30 02:22:26 -07001414
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001415 if (intmask & SDHCI_INT_CARD_INT)
1416 cardint = 1;
1417
1418 intmask &= ~SDHCI_INT_CARD_INT;
1419
Pierre Ossman3192a282006-06-30 02:22:26 -07001420 if (intmask) {
Pierre Ossmanacf1da42007-02-09 08:29:19 +01001421 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
Pierre Ossman3192a282006-06-30 02:22:26 -07001422 mmc_hostname(host->mmc), intmask);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001423 sdhci_dumpregs(host);
1424
Pierre Ossmand129bce2006-03-24 03:18:17 -08001425 writel(intmask, host->ioaddr + SDHCI_INT_STATUS);
Pierre Ossman3192a282006-06-30 02:22:26 -07001426 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001427
1428 result = IRQ_HANDLED;
1429
Pierre Ossman5f25a662006-10-04 02:15:39 -07001430 mmiowb();
Pierre Ossmand129bce2006-03-24 03:18:17 -08001431out:
1432 spin_unlock(&host->lock);
1433
Pierre Ossmanf75979b2007-09-04 07:59:18 +02001434 /*
1435 * We have to delay this as it calls back into the driver.
1436 */
1437 if (cardint)
1438 mmc_signal_sdio_irq(host->mmc);
1439
Pierre Ossmand129bce2006-03-24 03:18:17 -08001440 return result;
1441}
1442
1443/*****************************************************************************\
1444 * *
1445 * Suspend/resume *
1446 * *
1447\*****************************************************************************/
1448
1449#ifdef CONFIG_PM
1450
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001451int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001452{
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001453 int ret;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001454
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001455 ret = mmc_suspend_host(host->mmc, state);
Pierre Ossmandf1c4b72007-01-30 07:55:15 +01001456 if (ret)
1457 return ret;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001458
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001459 free_irq(host->irq, host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001460
1461 return 0;
1462}
1463
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001464EXPORT_SYMBOL_GPL(sdhci_suspend_host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001465
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001466int sdhci_resume_host(struct sdhci_host *host)
1467{
1468 int ret;
1469
1470 if (host->flags & SDHCI_USE_DMA) {
1471 if (host->ops->enable_dma)
1472 host->ops->enable_dma(host);
1473 }
1474
1475 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
1476 mmc_hostname(host->mmc), host);
1477 if (ret)
1478 return ret;
1479
1480 sdhci_init(host);
1481 mmiowb();
1482
1483 ret = mmc_resume_host(host->mmc);
1484 if (ret)
1485 return ret;
1486
1487 return 0;
1488}
1489
1490EXPORT_SYMBOL_GPL(sdhci_resume_host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001491
1492#endif /* CONFIG_PM */
1493
1494/*****************************************************************************\
1495 * *
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001496 * Device allocation/registration *
Pierre Ossmand129bce2006-03-24 03:18:17 -08001497 * *
1498\*****************************************************************************/
1499
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001500struct sdhci_host *sdhci_alloc_host(struct device *dev,
1501 size_t priv_size)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001502{
Pierre Ossmand129bce2006-03-24 03:18:17 -08001503 struct mmc_host *mmc;
1504 struct sdhci_host *host;
1505
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001506 WARN_ON(dev == NULL);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001507
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001508 mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001509 if (!mmc)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001510 return ERR_PTR(-ENOMEM);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001511
1512 host = mmc_priv(mmc);
1513 host->mmc = mmc;
1514
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001515 return host;
1516}
Pierre Ossman8a4da142006-10-04 02:15:40 -07001517
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001518EXPORT_SYMBOL_GPL(sdhci_alloc_host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001519
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001520int sdhci_add_host(struct sdhci_host *host)
1521{
1522 struct mmc_host *mmc;
1523 unsigned int caps;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001524 int ret;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001525
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001526 WARN_ON(host == NULL);
1527 if (host == NULL)
1528 return -EINVAL;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001529
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001530 mmc = host->mmc;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001531
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001532 if (debug_quirks)
1533 host->quirks = debug_quirks;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001534
Pierre Ossmand96649e2006-06-30 02:22:30 -07001535 sdhci_reset(host, SDHCI_RESET_ALL);
1536
Pierre Ossman2134a922008-06-28 18:28:51 +02001537 host->version = readw(host->ioaddr + SDHCI_HOST_VERSION);
1538 host->version = (host->version & SDHCI_SPEC_VER_MASK)
1539 >> SDHCI_SPEC_VER_SHIFT;
1540 if (host->version > SDHCI_SPEC_200) {
Pierre Ossman4a965502006-06-30 02:22:29 -07001541 printk(KERN_ERR "%s: Unknown controller version (%d). "
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001542 "You may experience problems.\n", mmc_hostname(mmc),
Pierre Ossman2134a922008-06-28 18:28:51 +02001543 host->version);
Pierre Ossman4a965502006-06-30 02:22:29 -07001544 }
1545
Pierre Ossmand129bce2006-03-24 03:18:17 -08001546 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
1547
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001548 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
Pierre Ossman98608072006-06-30 02:22:34 -07001549 host->flags |= SDHCI_USE_DMA;
Pierre Ossman67435272006-06-30 02:22:31 -07001550 else if (!(caps & SDHCI_CAN_DO_DMA))
1551 DBG("Controller doesn't have DMA capability\n");
1552 else
Pierre Ossmand129bce2006-03-24 03:18:17 -08001553 host->flags |= SDHCI_USE_DMA;
1554
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001555 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
Feng Tang7c168e32007-09-30 12:44:18 +02001556 (host->flags & SDHCI_USE_DMA)) {
Rolf Eike Beercee687c2007-11-02 15:22:30 +01001557 DBG("Disabling DMA as it is marked broken\n");
Feng Tang7c168e32007-09-30 12:44:18 +02001558 host->flags &= ~SDHCI_USE_DMA;
1559 }
1560
Pierre Ossmand129bce2006-03-24 03:18:17 -08001561 if (host->flags & SDHCI_USE_DMA) {
Pierre Ossman2134a922008-06-28 18:28:51 +02001562 if ((host->version >= SDHCI_SPEC_200) &&
1563 (caps & SDHCI_CAN_DO_ADMA2))
1564 host->flags |= SDHCI_USE_ADMA;
1565 }
1566
1567 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
1568 (host->flags & SDHCI_USE_ADMA)) {
1569 DBG("Disabling ADMA as it is marked broken\n");
1570 host->flags &= ~SDHCI_USE_ADMA;
1571 }
1572
1573 if (host->flags & SDHCI_USE_DMA) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001574 if (host->ops->enable_dma) {
1575 if (host->ops->enable_dma(host)) {
1576 printk(KERN_WARNING "%s: No suitable DMA "
1577 "available. Falling back to PIO.\n",
1578 mmc_hostname(mmc));
Pierre Ossman2134a922008-06-28 18:28:51 +02001579 host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001580 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001581 }
1582 }
1583
Pierre Ossman2134a922008-06-28 18:28:51 +02001584 if (host->flags & SDHCI_USE_ADMA) {
1585 /*
1586 * We need to allocate descriptors for all sg entries
1587 * (128) and potentially one alignment transfer for
1588 * each of those entries.
1589 */
1590 host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL);
1591 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL);
1592 if (!host->adma_desc || !host->align_buffer) {
1593 kfree(host->adma_desc);
1594 kfree(host->align_buffer);
1595 printk(KERN_WARNING "%s: Unable to allocate ADMA "
1596 "buffers. Falling back to standard DMA.\n",
1597 mmc_hostname(mmc));
1598 host->flags &= ~SDHCI_USE_ADMA;
1599 }
1600 }
1601
Pierre Ossman76591502008-07-21 00:32:11 +02001602 /*
1603 * If we use DMA, then it's up to the caller to set the DMA
1604 * mask, but PIO does not need the hw shim so we set a new
1605 * mask here in that case.
1606 */
1607 if (!(host->flags & SDHCI_USE_DMA)) {
1608 host->dma_mask = DMA_BIT_MASK(64);
1609 mmc_dev(host->mmc)->dma_mask = &host->dma_mask;
1610 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001611
Pierre Ossman8ef1a142006-06-30 02:22:21 -07001612 host->max_clk =
1613 (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
1614 if (host->max_clk == 0) {
1615 printk(KERN_ERR "%s: Hardware doesn't specify base clock "
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001616 "frequency.\n", mmc_hostname(mmc));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001617 return -ENODEV;
Pierre Ossman8ef1a142006-06-30 02:22:21 -07001618 }
Pierre Ossmand129bce2006-03-24 03:18:17 -08001619 host->max_clk *= 1000000;
1620
Pierre Ossman1c8cde92006-06-30 02:22:25 -07001621 host->timeout_clk =
1622 (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
1623 if (host->timeout_clk == 0) {
1624 printk(KERN_ERR "%s: Hardware doesn't specify timeout clock "
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001625 "frequency.\n", mmc_hostname(mmc));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001626 return -ENODEV;
Pierre Ossman1c8cde92006-06-30 02:22:25 -07001627 }
1628 if (caps & SDHCI_TIMEOUT_CLK_UNIT)
1629 host->timeout_clk *= 1000;
1630
Pierre Ossmand129bce2006-03-24 03:18:17 -08001631 /*
1632 * Set host parameters.
1633 */
1634 mmc->ops = &sdhci_ops;
1635 mmc->f_min = host->max_clk / 256;
1636 mmc->f_max = host->max_clk;
Pierre Ossmanc9b74c52008-04-18 20:41:49 +02001637 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001638
Pierre Ossmana4b76192008-08-16 20:43:04 +02001639 if ((caps & SDHCI_CAN_DO_HISPD) ||
1640 (host->quirks & SDHCI_QUIRK_FORCE_HIGHSPEED))
Pierre Ossmancd9277c2007-02-18 12:07:47 +01001641 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1642
Pierre Ossman146ad662006-06-30 02:22:23 -07001643 mmc->ocr_avail = 0;
1644 if (caps & SDHCI_CAN_VDD_330)
1645 mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34;
Pierre Ossmanc70840e2007-02-02 22:41:41 +01001646 if (caps & SDHCI_CAN_VDD_300)
Pierre Ossman146ad662006-06-30 02:22:23 -07001647 mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31;
Pierre Ossmanc70840e2007-02-02 22:41:41 +01001648 if (caps & SDHCI_CAN_VDD_180)
Philip Langdale55556da2007-03-16 19:39:00 -07001649 mmc->ocr_avail |= MMC_VDD_165_195;
Pierre Ossman146ad662006-06-30 02:22:23 -07001650
1651 if (mmc->ocr_avail == 0) {
1652 printk(KERN_ERR "%s: Hardware doesn't report any "
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001653 "support voltages.\n", mmc_hostname(mmc));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001654 return -ENODEV;
Pierre Ossman146ad662006-06-30 02:22:23 -07001655 }
1656
Pierre Ossmand129bce2006-03-24 03:18:17 -08001657 spin_lock_init(&host->lock);
1658
1659 /*
Pierre Ossman2134a922008-06-28 18:28:51 +02001660 * Maximum number of segments. Depends on if the hardware
1661 * can do scatter/gather or not.
Pierre Ossmand129bce2006-03-24 03:18:17 -08001662 */
Pierre Ossman2134a922008-06-28 18:28:51 +02001663 if (host->flags & SDHCI_USE_ADMA)
1664 mmc->max_hw_segs = 128;
1665 else if (host->flags & SDHCI_USE_DMA)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001666 mmc->max_hw_segs = 1;
Pierre Ossman2134a922008-06-28 18:28:51 +02001667 else /* PIO */
1668 mmc->max_hw_segs = 128;
1669 mmc->max_phys_segs = 128;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001670
1671 /*
Pierre Ossmanbab76962006-07-02 16:51:35 +01001672 * Maximum number of sectors in one transfer. Limited by DMA boundary
Pierre Ossman55db8902006-11-21 17:55:45 +01001673 * size (512KiB).
Pierre Ossmand129bce2006-03-24 03:18:17 -08001674 */
Pierre Ossman55db8902006-11-21 17:55:45 +01001675 mmc->max_req_size = 524288;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001676
1677 /*
1678 * Maximum segment size. Could be one segment with the maximum number
Pierre Ossman2134a922008-06-28 18:28:51 +02001679 * of bytes. When doing hardware scatter/gather, each entry cannot
1680 * be larger than 64 KiB though.
Pierre Ossmand129bce2006-03-24 03:18:17 -08001681 */
Pierre Ossman2134a922008-06-28 18:28:51 +02001682 if (host->flags & SDHCI_USE_ADMA)
1683 mmc->max_seg_size = 65536;
1684 else
1685 mmc->max_seg_size = mmc->max_req_size;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001686
1687 /*
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +01001688 * Maximum block size. This varies from controller to controller and
1689 * is specified in the capabilities register.
1690 */
1691 mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> SDHCI_MAX_BLOCK_SHIFT;
1692 if (mmc->max_blk_size >= 3) {
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001693 printk(KERN_WARNING "%s: Invalid maximum block size, "
1694 "assuming 512 bytes\n", mmc_hostname(mmc));
David Vrabel03f85902007-08-10 13:25:03 +01001695 mmc->max_blk_size = 512;
1696 } else
1697 mmc->max_blk_size = 512 << mmc->max_blk_size;
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +01001698
1699 /*
Pierre Ossman55db8902006-11-21 17:55:45 +01001700 * Maximum block count.
1701 */
1702 mmc->max_blk_count = 65535;
1703
1704 /*
Pierre Ossmand129bce2006-03-24 03:18:17 -08001705 * Init tasklets.
1706 */
1707 tasklet_init(&host->card_tasklet,
1708 sdhci_tasklet_card, (unsigned long)host);
1709 tasklet_init(&host->finish_tasklet,
1710 sdhci_tasklet_finish, (unsigned long)host);
1711
Al Viroe4cad1b2006-10-10 22:47:07 +01001712 setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001713
Thomas Gleixnerdace1452006-07-01 19:29:38 -07001714 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
Pierre Ossmanb69c9052008-03-08 23:44:25 +01001715 mmc_hostname(mmc), host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001716 if (ret)
Pierre Ossman8ef1a142006-06-30 02:22:21 -07001717 goto untasklet;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001718
1719 sdhci_init(host);
1720
1721#ifdef CONFIG_MMC_DEBUG
1722 sdhci_dumpregs(host);
1723#endif
1724
Pierre Ossmanf9134312008-12-21 17:01:48 +01001725#ifdef SDHCI_USE_LEDS_CLASS
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001726 host->led.name = mmc_hostname(mmc);
1727 host->led.brightness = LED_OFF;
1728 host->led.default_trigger = mmc_hostname(mmc);
1729 host->led.brightness_set = sdhci_led_control;
1730
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001731 ret = led_classdev_register(mmc_dev(mmc), &host->led);
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001732 if (ret)
1733 goto reset;
1734#endif
1735
Pierre Ossman5f25a662006-10-04 02:15:39 -07001736 mmiowb();
1737
Pierre Ossmand129bce2006-03-24 03:18:17 -08001738 mmc_add_host(mmc);
1739
Pierre Ossman2134a922008-06-28 18:28:51 +02001740 printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n",
Kay Sieversd1b26862008-11-08 21:37:46 +01001741 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
Pierre Ossman2134a922008-06-28 18:28:51 +02001742 (host->flags & SDHCI_USE_ADMA)?"A":"",
Pierre Ossmand129bce2006-03-24 03:18:17 -08001743 (host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
1744
1745 return 0;
1746
Pierre Ossmanf9134312008-12-21 17:01:48 +01001747#ifdef SDHCI_USE_LEDS_CLASS
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001748reset:
1749 sdhci_reset(host, SDHCI_RESET_ALL);
1750 free_irq(host->irq, host);
1751#endif
Pierre Ossman8ef1a142006-06-30 02:22:21 -07001752untasklet:
Pierre Ossmand129bce2006-03-24 03:18:17 -08001753 tasklet_kill(&host->card_tasklet);
1754 tasklet_kill(&host->finish_tasklet);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001755
1756 return ret;
1757}
1758
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001759EXPORT_SYMBOL_GPL(sdhci_add_host);
1760
Pierre Ossman1e728592008-04-16 19:13:13 +02001761void sdhci_remove_host(struct sdhci_host *host, int dead)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001762{
Pierre Ossman1e728592008-04-16 19:13:13 +02001763 unsigned long flags;
1764
1765 if (dead) {
1766 spin_lock_irqsave(&host->lock, flags);
1767
1768 host->flags |= SDHCI_DEVICE_DEAD;
1769
1770 if (host->mrq) {
1771 printk(KERN_ERR "%s: Controller removed during "
1772 " transfer!\n", mmc_hostname(host->mmc));
1773
1774 host->mrq->cmd->error = -ENOMEDIUM;
1775 tasklet_schedule(&host->finish_tasklet);
1776 }
1777
1778 spin_unlock_irqrestore(&host->lock, flags);
1779 }
1780
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001781 mmc_remove_host(host->mmc);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001782
Pierre Ossmanf9134312008-12-21 17:01:48 +01001783#ifdef SDHCI_USE_LEDS_CLASS
Pierre Ossman2f730fe2008-03-17 10:29:38 +01001784 led_classdev_unregister(&host->led);
1785#endif
1786
Pierre Ossman1e728592008-04-16 19:13:13 +02001787 if (!dead)
1788 sdhci_reset(host, SDHCI_RESET_ALL);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001789
1790 free_irq(host->irq, host);
1791
1792 del_timer_sync(&host->timer);
1793
1794 tasklet_kill(&host->card_tasklet);
1795 tasklet_kill(&host->finish_tasklet);
Pierre Ossman2134a922008-06-28 18:28:51 +02001796
1797 kfree(host->adma_desc);
1798 kfree(host->align_buffer);
1799
1800 host->adma_desc = NULL;
1801 host->align_buffer = NULL;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001802}
1803
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001804EXPORT_SYMBOL_GPL(sdhci_remove_host);
1805
1806void sdhci_free_host(struct sdhci_host *host)
Pierre Ossmand129bce2006-03-24 03:18:17 -08001807{
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001808 mmc_free_host(host->mmc);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001809}
1810
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001811EXPORT_SYMBOL_GPL(sdhci_free_host);
Pierre Ossmand129bce2006-03-24 03:18:17 -08001812
1813/*****************************************************************************\
1814 * *
1815 * Driver init/exit *
1816 * *
1817\*****************************************************************************/
1818
1819static int __init sdhci_drv_init(void)
1820{
1821 printk(KERN_INFO DRIVER_NAME
Pierre Ossman52fbf9c2007-02-09 08:23:41 +01001822 ": Secure Digital Host Controller Interface driver\n");
Pierre Ossmand129bce2006-03-24 03:18:17 -08001823 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1824
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001825 return 0;
Pierre Ossmand129bce2006-03-24 03:18:17 -08001826}
1827
1828static void __exit sdhci_drv_exit(void)
1829{
Pierre Ossmand129bce2006-03-24 03:18:17 -08001830}
1831
1832module_init(sdhci_drv_init);
1833module_exit(sdhci_drv_exit);
1834
Pierre Ossmandf673b22006-06-30 02:22:31 -07001835module_param(debug_quirks, uint, 0444);
Pierre Ossman67435272006-06-30 02:22:31 -07001836
Pierre Ossmand129bce2006-03-24 03:18:17 -08001837MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001838MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
Pierre Ossmand129bce2006-03-24 03:18:17 -08001839MODULE_LICENSE("GPL");
Pierre Ossman67435272006-06-30 02:22:31 -07001840
Pierre Ossmandf673b22006-06-30 02:22:31 -07001841MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");