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