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