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