Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/wbsd.c - Winbond W83L51xD SD/MMC driver |
| 3 | * |
| 4 | * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved. |
| 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * |
| 12 | * Warning! |
| 13 | * |
| 14 | * Changes to the FIFO system should be done with extreme care since |
| 15 | * the hardware is full of bugs related to the FIFO. Known issues are: |
| 16 | * |
| 17 | * - FIFO size field in FSR is always zero. |
| 18 | * |
| 19 | * - FIFO interrupts tend not to work as they should. Interrupts are |
| 20 | * triggered only for full/empty events, not for threshold values. |
| 21 | * |
| 22 | * - On APIC systems the FIFO empty interrupt is sometimes lost. |
| 23 | */ |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/ioport.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/interrupt.h> |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 31 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/delay.h> |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 33 | #include <linux/pnp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/highmem.h> |
| 35 | #include <linux/mmc/host.h> |
| 36 | #include <linux/mmc/protocol.h> |
| 37 | |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/dma.h> |
| 40 | #include <asm/scatterlist.h> |
| 41 | |
| 42 | #include "wbsd.h" |
| 43 | |
| 44 | #define DRIVER_NAME "wbsd" |
Pierre Ossman | 916f3ac | 2006-08-06 22:22:23 +0200 | [diff] [blame] | 45 | #define DRIVER_VERSION "1.6" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define DBG(x...) \ |
Russell King | c656317 | 2006-03-29 09:30:20 +0100 | [diff] [blame] | 48 | pr_debug(DRIVER_NAME ": " x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define DBGF(f, x...) \ |
Russell King | c656317 | 2006-03-29 09:30:20 +0100 | [diff] [blame] | 50 | pr_debug(DRIVER_NAME " [%s()]: " f, __func__ , ##x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 53 | * Device resources |
| 54 | */ |
| 55 | |
| 56 | #ifdef CONFIG_PNP |
| 57 | |
| 58 | static const struct pnp_device_id pnp_dev_table[] = { |
| 59 | { "WEC0517", 0 }, |
| 60 | { "WEC0518", 0 }, |
| 61 | { "", 0 }, |
| 62 | }; |
| 63 | |
| 64 | MODULE_DEVICE_TABLE(pnp, pnp_dev_table); |
| 65 | |
| 66 | #endif /* CONFIG_PNP */ |
| 67 | |
Adrian Bunk | 3eee0d0 | 2005-07-01 13:07:37 +0100 | [diff] [blame] | 68 | static const int config_ports[] = { 0x2E, 0x4E }; |
| 69 | static const int unlock_codes[] = { 0x83, 0x87 }; |
| 70 | |
| 71 | static const int valid_ids[] = { |
| 72 | 0x7112, |
| 73 | }; |
| 74 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 75 | #ifdef CONFIG_PNP |
| 76 | static unsigned int nopnp = 0; |
| 77 | #else |
| 78 | static const unsigned int nopnp = 1; |
| 79 | #endif |
| 80 | static unsigned int io = 0x248; |
| 81 | static unsigned int irq = 6; |
| 82 | static int dma = 2; |
| 83 | |
| 84 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | * Basic functions |
| 86 | */ |
| 87 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 88 | static inline void wbsd_unlock_config(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 90 | BUG_ON(host->config == 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | outb(host->unlock_code, host->config); |
| 93 | outb(host->unlock_code, host->config); |
| 94 | } |
| 95 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 96 | static inline void wbsd_lock_config(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 98 | BUG_ON(host->config == 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | outb(LOCK_CODE, host->config); |
| 101 | } |
| 102 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 103 | static inline void wbsd_write_config(struct wbsd_host *host, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 105 | BUG_ON(host->config == 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | outb(reg, host->config); |
| 108 | outb(value, host->config + 1); |
| 109 | } |
| 110 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 111 | static inline u8 wbsd_read_config(struct wbsd_host *host, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 113 | BUG_ON(host->config == 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | outb(reg, host->config); |
| 116 | return inb(host->config + 1); |
| 117 | } |
| 118 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 119 | static inline void wbsd_write_index(struct wbsd_host *host, u8 index, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | outb(index, host->base + WBSD_IDXR); |
| 122 | outb(value, host->base + WBSD_DATAR); |
| 123 | } |
| 124 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 125 | static inline u8 wbsd_read_index(struct wbsd_host *host, u8 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | outb(index, host->base + WBSD_IDXR); |
| 128 | return inb(host->base + WBSD_DATAR); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Common routines |
| 133 | */ |
| 134 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 135 | static void wbsd_init_device(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
| 137 | u8 setup, ier; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
| 140 | * Reset chip (SD/MMC part) and fifo. |
| 141 | */ |
| 142 | setup = wbsd_read_index(host, WBSD_IDX_SETUP); |
| 143 | setup |= WBSD_FIFO_RESET | WBSD_SOFT_RESET; |
| 144 | wbsd_write_index(host, WBSD_IDX_SETUP, setup); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 147 | * Set DAT3 to input |
| 148 | */ |
| 149 | setup &= ~WBSD_DAT3_H; |
| 150 | wbsd_write_index(host, WBSD_IDX_SETUP, setup); |
| 151 | host->flags &= ~WBSD_FIGNORE_DETECT; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 152 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 153 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | * Read back default clock. |
| 155 | */ |
| 156 | host->clk = wbsd_read_index(host, WBSD_IDX_CLK); |
| 157 | |
| 158 | /* |
| 159 | * Power down port. |
| 160 | */ |
| 161 | outb(WBSD_POWER_N, host->base + WBSD_CSR); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
| 164 | * Set maximum timeout. |
| 165 | */ |
| 166 | wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 169 | * Test for card presence |
| 170 | */ |
| 171 | if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT) |
| 172 | host->flags |= WBSD_FCARD_PRESENT; |
| 173 | else |
| 174 | host->flags &= ~WBSD_FCARD_PRESENT; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 175 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 176 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | * Enable interesting interrupts. |
| 178 | */ |
| 179 | ier = 0; |
| 180 | ier |= WBSD_EINT_CARD; |
| 181 | ier |= WBSD_EINT_FIFO_THRE; |
| 182 | ier |= WBSD_EINT_CCRC; |
| 183 | ier |= WBSD_EINT_TIMEOUT; |
| 184 | ier |= WBSD_EINT_CRC; |
| 185 | ier |= WBSD_EINT_TC; |
| 186 | |
| 187 | outb(ier, host->base + WBSD_EIR); |
| 188 | |
| 189 | /* |
| 190 | * Clear interrupts. |
| 191 | */ |
| 192 | inb(host->base + WBSD_ISR); |
| 193 | } |
| 194 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 195 | static void wbsd_reset(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | u8 setup; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 198 | |
Pierre Ossman | d191634 | 2005-11-05 10:36:35 +0000 | [diff] [blame] | 199 | printk(KERN_ERR "%s: Resetting chip\n", mmc_hostname(host->mmc)); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* |
| 202 | * Soft reset of chip (SD/MMC part). |
| 203 | */ |
| 204 | setup = wbsd_read_index(host, WBSD_IDX_SETUP); |
| 205 | setup |= WBSD_SOFT_RESET; |
| 206 | wbsd_write_index(host, WBSD_IDX_SETUP, setup); |
| 207 | } |
| 208 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 209 | static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | unsigned long dmaflags; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 214 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 215 | if (host->dma >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* |
| 217 | * Release ISA DMA controller. |
| 218 | */ |
| 219 | dmaflags = claim_dma_lock(); |
| 220 | disable_dma(host->dma); |
| 221 | clear_dma_ff(host->dma); |
| 222 | release_dma_lock(dmaflags); |
| 223 | |
| 224 | /* |
| 225 | * Disable DMA on host. |
| 226 | */ |
| 227 | wbsd_write_index(host, WBSD_IDX_DMA, 0); |
| 228 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | host->mrq = NULL; |
| 231 | |
| 232 | /* |
| 233 | * MMC layer might call back into the driver so first unlock. |
| 234 | */ |
| 235 | spin_unlock(&host->lock); |
| 236 | mmc_request_done(host->mmc, mrq); |
| 237 | spin_lock(&host->lock); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Scatter/gather functions |
| 242 | */ |
| 243 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 244 | static inline void wbsd_init_sg(struct wbsd_host *host, struct mmc_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
| 246 | /* |
| 247 | * Get info. about SG list from data structure. |
| 248 | */ |
| 249 | host->cur_sg = data->sg; |
| 250 | host->num_sg = data->sg_len; |
| 251 | |
| 252 | host->offset = 0; |
| 253 | host->remain = host->cur_sg->length; |
| 254 | } |
| 255 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 256 | static inline int wbsd_next_sg(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | /* |
| 259 | * Skip to next SG entry. |
| 260 | */ |
| 261 | host->cur_sg++; |
| 262 | host->num_sg--; |
| 263 | |
| 264 | /* |
| 265 | * Any entries left? |
| 266 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 267 | if (host->num_sg > 0) { |
| 268 | host->offset = 0; |
| 269 | host->remain = host->cur_sg->length; |
| 270 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return host->num_sg; |
| 273 | } |
| 274 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 275 | static inline char *wbsd_kmap_sg(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | host->mapped_sg = kmap_atomic(host->cur_sg->page, KM_BIO_SRC_IRQ) + |
| 278 | host->cur_sg->offset; |
| 279 | return host->mapped_sg; |
| 280 | } |
| 281 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 282 | static inline void wbsd_kunmap_sg(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | kunmap_atomic(host->mapped_sg, KM_BIO_SRC_IRQ); |
| 285 | } |
| 286 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 287 | static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | unsigned int len, i, size; |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 290 | struct scatterlist *sg; |
| 291 | char *dmabuf = host->dma_buffer; |
| 292 | char *sgbuf; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | size = host->size; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | sg = data->sg; |
| 297 | len = data->sg_len; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * Just loop through all entries. Size might not |
| 301 | * be the entire list though so make sure that |
| 302 | * we do not transfer too much. |
| 303 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 304 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset; |
| 306 | if (size < sg[i].length) |
| 307 | memcpy(dmabuf, sgbuf, size); |
| 308 | else |
| 309 | memcpy(dmabuf, sgbuf, sg[i].length); |
| 310 | kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ); |
| 311 | dmabuf += sg[i].length; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | if (size < sg[i].length) |
| 314 | size = 0; |
| 315 | else |
| 316 | size -= sg[i].length; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (size == 0) |
| 319 | break; |
| 320 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /* |
| 323 | * Check that we didn't get a request to transfer |
| 324 | * more data than can fit into the SG list. |
| 325 | */ |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | BUG_ON(size != 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | host->size -= size; |
| 330 | } |
| 331 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 332 | static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
| 334 | unsigned int len, i, size; |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 335 | struct scatterlist *sg; |
| 336 | char *dmabuf = host->dma_buffer; |
| 337 | char *sgbuf; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | size = host->size; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | sg = data->sg; |
| 342 | len = data->sg_len; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /* |
| 345 | * Just loop through all entries. Size might not |
| 346 | * be the entire list though so make sure that |
| 347 | * we do not transfer too much. |
| 348 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 349 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset; |
| 351 | if (size < sg[i].length) |
| 352 | memcpy(sgbuf, dmabuf, size); |
| 353 | else |
| 354 | memcpy(sgbuf, dmabuf, sg[i].length); |
| 355 | kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ); |
| 356 | dmabuf += sg[i].length; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (size < sg[i].length) |
| 359 | size = 0; |
| 360 | else |
| 361 | size -= sg[i].length; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (size == 0) |
| 364 | break; |
| 365 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /* |
| 368 | * Check that we didn't get a request to transfer |
| 369 | * more data than can fit into the SG list. |
| 370 | */ |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | BUG_ON(size != 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | host->size -= size; |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Command handling |
| 379 | */ |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 380 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 381 | static inline void wbsd_get_short_reply(struct wbsd_host *host, |
| 382 | struct mmc_command *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
| 384 | /* |
| 385 | * Correct response type? |
| 386 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 387 | if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | cmd->error = MMC_ERR_INVALID; |
| 389 | return; |
| 390 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 391 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 392 | cmd->resp[0] = wbsd_read_index(host, WBSD_IDX_RESP12) << 24; |
| 393 | cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP13) << 16; |
| 394 | cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP14) << 8; |
| 395 | cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP15) << 0; |
| 396 | cmd->resp[1] = wbsd_read_index(host, WBSD_IDX_RESP16) << 24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 399 | static inline void wbsd_get_long_reply(struct wbsd_host *host, |
| 400 | struct mmc_command *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | int i; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /* |
| 405 | * Correct response type? |
| 406 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 407 | if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | cmd->error = MMC_ERR_INVALID; |
| 409 | return; |
| 410 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 411 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 412 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | cmd->resp[i] = |
| 414 | wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24; |
| 415 | cmd->resp[i] |= |
| 416 | wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16; |
| 417 | cmd->resp[i] |= |
| 418 | wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8; |
| 419 | cmd->resp[i] |= |
| 420 | wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0; |
| 421 | } |
| 422 | } |
| 423 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 424 | static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
| 426 | int i; |
| 427 | u8 status, isr; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | DBGF("Sending cmd (%x)\n", cmd->opcode); |
| 430 | |
| 431 | /* |
| 432 | * Clear accumulated ISR. The interrupt routine |
| 433 | * will fill this one with events that occur during |
| 434 | * transfer. |
| 435 | */ |
| 436 | host->isr = 0; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* |
| 439 | * Send the command (CRC calculated by host). |
| 440 | */ |
| 441 | outb(cmd->opcode, host->base + WBSD_CMDR); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 442 | for (i = 3; i >= 0; i--) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | cmd->error = MMC_ERR_NONE; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | /* |
| 448 | * Wait for the request to complete. |
| 449 | */ |
| 450 | do { |
| 451 | status = wbsd_read_index(host, WBSD_IDX_STATUS); |
| 452 | } while (status & WBSD_CARDTRAFFIC); |
| 453 | |
| 454 | /* |
| 455 | * Do we expect a reply? |
| 456 | */ |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 457 | if (cmd->flags & MMC_RSP_PRESENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /* |
| 459 | * Read back status. |
| 460 | */ |
| 461 | isr = host->isr; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* Card removed? */ |
| 464 | if (isr & WBSD_INT_CARD) |
| 465 | cmd->error = MMC_ERR_TIMEOUT; |
| 466 | /* Timeout? */ |
| 467 | else if (isr & WBSD_INT_TIMEOUT) |
| 468 | cmd->error = MMC_ERR_TIMEOUT; |
| 469 | /* CRC? */ |
| 470 | else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC)) |
| 471 | cmd->error = MMC_ERR_BADCRC; |
| 472 | /* All ok */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 473 | else { |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 474 | if (cmd->flags & MMC_RSP_136) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | wbsd_get_long_reply(host, cmd); |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 476 | else |
| 477 | wbsd_get_short_reply(host, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
| 481 | DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error); |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Data functions |
| 486 | */ |
| 487 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 488 | static void wbsd_empty_fifo(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 490 | struct mmc_data *data = host->mrq->cmd->data; |
| 491 | char *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | int i, fsr, fifo; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | /* |
| 495 | * Handle excessive data. |
| 496 | */ |
| 497 | if (data->bytes_xfered == host->size) |
| 498 | return; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | buffer = wbsd_kmap_sg(host) + host->offset; |
| 501 | |
| 502 | /* |
| 503 | * Drain the fifo. This has a tendency to loop longer |
| 504 | * than the FIFO length (usually one block). |
| 505 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 506 | while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* |
| 508 | * The size field in the FSR is broken so we have to |
| 509 | * do some guessing. |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 510 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (fsr & WBSD_FIFO_FULL) |
| 512 | fifo = 16; |
| 513 | else if (fsr & WBSD_FIFO_FUTHRE) |
| 514 | fifo = 8; |
| 515 | else |
| 516 | fifo = 1; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 517 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 518 | for (i = 0; i < fifo; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | *buffer = inb(host->base + WBSD_DFR); |
| 520 | buffer++; |
| 521 | host->offset++; |
| 522 | host->remain--; |
| 523 | |
| 524 | data->bytes_xfered++; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /* |
| 527 | * Transfer done? |
| 528 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 529 | if (data->bytes_xfered == host->size) { |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 530 | wbsd_kunmap_sg(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return; |
| 532 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | /* |
| 535 | * End of scatter list entry? |
| 536 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 537 | if (host->remain == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | wbsd_kunmap_sg(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* |
| 541 | * Get next entry. Check if last. |
| 542 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 543 | if (!wbsd_next_sg(host)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | /* |
| 545 | * We should never reach this point. |
| 546 | * It means that we're trying to |
| 547 | * transfer more blocks than can fit |
| 548 | * into the scatter list. |
| 549 | */ |
| 550 | BUG_ON(1); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | host->size = data->bytes_xfered; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | return; |
| 555 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | buffer = wbsd_kmap_sg(host); |
| 558 | } |
| 559 | } |
| 560 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | wbsd_kunmap_sg(host); |
| 563 | |
| 564 | /* |
| 565 | * This is a very dirty hack to solve a |
| 566 | * hardware problem. The chip doesn't trigger |
| 567 | * FIFO threshold interrupts properly. |
| 568 | */ |
| 569 | if ((host->size - data->bytes_xfered) < 16) |
| 570 | tasklet_schedule(&host->fifo_tasklet); |
| 571 | } |
| 572 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 573 | static void wbsd_fill_fifo(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 575 | struct mmc_data *data = host->mrq->cmd->data; |
| 576 | char *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | int i, fsr, fifo; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Check that we aren't being called after the |
| 581 | * entire buffer has been transfered. |
| 582 | */ |
| 583 | if (data->bytes_xfered == host->size) |
| 584 | return; |
| 585 | |
| 586 | buffer = wbsd_kmap_sg(host) + host->offset; |
| 587 | |
| 588 | /* |
| 589 | * Fill the fifo. This has a tendency to loop longer |
| 590 | * than the FIFO length (usually one block). |
| 591 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 592 | while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | /* |
| 594 | * The size field in the FSR is broken so we have to |
| 595 | * do some guessing. |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 596 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (fsr & WBSD_FIFO_EMPTY) |
| 598 | fifo = 0; |
| 599 | else if (fsr & WBSD_FIFO_EMTHRE) |
| 600 | fifo = 8; |
| 601 | else |
| 602 | fifo = 15; |
| 603 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 604 | for (i = 16; i > fifo; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | outb(*buffer, host->base + WBSD_DFR); |
| 606 | buffer++; |
| 607 | host->offset++; |
| 608 | host->remain--; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | data->bytes_xfered++; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /* |
| 613 | * Transfer done? |
| 614 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 615 | if (data->bytes_xfered == host->size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | wbsd_kunmap_sg(host); |
| 617 | return; |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * End of scatter list entry? |
| 622 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 623 | if (host->remain == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | wbsd_kunmap_sg(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* |
| 627 | * Get next entry. Check if last. |
| 628 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 629 | if (!wbsd_next_sg(host)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
| 631 | * We should never reach this point. |
| 632 | * It means that we're trying to |
| 633 | * transfer more blocks than can fit |
| 634 | * into the scatter list. |
| 635 | */ |
| 636 | BUG_ON(1); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | host->size = data->bytes_xfered; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | return; |
| 641 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | buffer = wbsd_kmap_sg(host); |
| 644 | } |
| 645 | } |
| 646 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | wbsd_kunmap_sg(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 649 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 650 | /* |
| 651 | * The controller stops sending interrupts for |
| 652 | * 'FIFO empty' under certain conditions. So we |
| 653 | * need to be a bit more pro-active. |
| 654 | */ |
| 655 | tasklet_schedule(&host->fifo_tasklet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 658 | static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
| 660 | u16 blksize; |
| 661 | u8 setup; |
| 662 | unsigned long dmaflags; |
| 663 | |
| 664 | DBGF("blksz %04x blks %04x flags %08x\n", |
Pavel Pisa | 2c171bf | 2006-05-19 21:48:03 +0100 | [diff] [blame] | 665 | data->blksz, data->blocks, data->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | DBGF("tsac %d ms nsac %d clk\n", |
| 667 | data->timeout_ns / 1000000, data->timeout_clks); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* |
| 670 | * Calculate size. |
| 671 | */ |
Pavel Pisa | 2c171bf | 2006-05-19 21:48:03 +0100 | [diff] [blame] | 672 | host->size = data->blocks * data->blksz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | /* |
| 675 | * Check timeout values for overflow. |
| 676 | * (Yes, some cards cause this value to overflow). |
| 677 | */ |
| 678 | if (data->timeout_ns > 127000000) |
| 679 | wbsd_write_index(host, WBSD_IDX_TAAC, 127); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 680 | else { |
| 681 | wbsd_write_index(host, WBSD_IDX_TAAC, |
| 682 | data->timeout_ns / 1000000); |
| 683 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | if (data->timeout_clks > 255) |
| 686 | wbsd_write_index(host, WBSD_IDX_NSAC, 255); |
| 687 | else |
| 688 | wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* |
| 691 | * Inform the chip of how large blocks will be |
| 692 | * sent. It needs this to determine when to |
| 693 | * calculate CRC. |
| 694 | * |
| 695 | * Space for CRC must be included in the size. |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 696 | * Two bytes are needed for each data line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 698 | if (host->bus_width == MMC_BUS_WIDTH_1) { |
Pavel Pisa | 2c171bf | 2006-05-19 21:48:03 +0100 | [diff] [blame] | 699 | blksize = data->blksz + 2; |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 700 | |
| 701 | wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0); |
| 702 | wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 703 | } else if (host->bus_width == MMC_BUS_WIDTH_4) { |
Pavel Pisa | 2c171bf | 2006-05-19 21:48:03 +0100 | [diff] [blame] | 704 | blksize = data->blksz + 2 * 4; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 705 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 706 | wbsd_write_index(host, WBSD_IDX_PBSMSB, |
| 707 | ((blksize >> 4) & 0xF0) | WBSD_DATA_WIDTH); |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 708 | wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 709 | } else { |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 710 | data->error = MMC_ERR_INVALID; |
| 711 | return; |
| 712 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
| 714 | /* |
| 715 | * Clear the FIFO. This is needed even for DMA |
| 716 | * transfers since the chip still uses the FIFO |
| 717 | * internally. |
| 718 | */ |
| 719 | setup = wbsd_read_index(host, WBSD_IDX_SETUP); |
| 720 | setup |= WBSD_FIFO_RESET; |
| 721 | wbsd_write_index(host, WBSD_IDX_SETUP, setup); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* |
| 724 | * DMA transfer? |
| 725 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 726 | if (host->dma >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /* |
| 728 | * The buffer for DMA is only 64 kB. |
| 729 | */ |
| 730 | BUG_ON(host->size > 0x10000); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 731 | if (host->size > 0x10000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | data->error = MMC_ERR_INVALID; |
| 733 | return; |
| 734 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | /* |
| 737 | * Transfer data from the SG list to |
| 738 | * the DMA buffer. |
| 739 | */ |
| 740 | if (data->flags & MMC_DATA_WRITE) |
| 741 | wbsd_sg_to_dma(host, data); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /* |
| 744 | * Initialise the ISA DMA controller. |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 745 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | dmaflags = claim_dma_lock(); |
| 747 | disable_dma(host->dma); |
| 748 | clear_dma_ff(host->dma); |
| 749 | if (data->flags & MMC_DATA_READ) |
| 750 | set_dma_mode(host->dma, DMA_MODE_READ & ~0x40); |
| 751 | else |
| 752 | set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40); |
| 753 | set_dma_addr(host->dma, host->dma_addr); |
| 754 | set_dma_count(host->dma, host->size); |
| 755 | |
| 756 | enable_dma(host->dma); |
| 757 | release_dma_lock(dmaflags); |
| 758 | |
| 759 | /* |
| 760 | * Enable DMA on the host. |
| 761 | */ |
| 762 | wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 763 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | /* |
| 765 | * This flag is used to keep printk |
| 766 | * output to a minimum. |
| 767 | */ |
| 768 | host->firsterr = 1; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* |
| 771 | * Initialise the SG list. |
| 772 | */ |
| 773 | wbsd_init_sg(host, data); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | /* |
| 776 | * Turn off DMA. |
| 777 | */ |
| 778 | wbsd_write_index(host, WBSD_IDX_DMA, 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | /* |
| 781 | * Set up FIFO threshold levels (and fill |
| 782 | * buffer if doing a write). |
| 783 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 784 | if (data->flags & MMC_DATA_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | wbsd_write_index(host, WBSD_IDX_FIFOEN, |
| 786 | WBSD_FIFOEN_FULL | 8); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 787 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | wbsd_write_index(host, WBSD_IDX_FIFOEN, |
| 789 | WBSD_FIFOEN_EMPTY | 8); |
| 790 | wbsd_fill_fifo(host); |
| 791 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 792 | } |
| 793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | data->error = MMC_ERR_NONE; |
| 795 | } |
| 796 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 797 | static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
| 799 | unsigned long dmaflags; |
| 800 | int count; |
| 801 | u8 status; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | WARN_ON(host->mrq == NULL); |
| 804 | |
| 805 | /* |
| 806 | * Send a stop command if needed. |
| 807 | */ |
| 808 | if (data->stop) |
| 809 | wbsd_send_command(host, data->stop); |
| 810 | |
| 811 | /* |
| 812 | * Wait for the controller to leave data |
| 813 | * transfer state. |
| 814 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 815 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | status = wbsd_read_index(host, WBSD_IDX_STATUS); |
| 817 | } while (status & (WBSD_BLOCK_READ | WBSD_BLOCK_WRITE)); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | /* |
| 820 | * DMA transfer? |
| 821 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 822 | if (host->dma >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | /* |
| 824 | * Disable DMA on the host. |
| 825 | */ |
| 826 | wbsd_write_index(host, WBSD_IDX_DMA, 0); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | /* |
| 829 | * Turn of ISA DMA controller. |
| 830 | */ |
| 831 | dmaflags = claim_dma_lock(); |
| 832 | disable_dma(host->dma); |
| 833 | clear_dma_ff(host->dma); |
| 834 | count = get_dma_residue(host->dma); |
| 835 | release_dma_lock(dmaflags); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | /* |
| 838 | * Any leftover data? |
| 839 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 840 | if (count) { |
Pierre Ossman | d191634 | 2005-11-05 10:36:35 +0000 | [diff] [blame] | 841 | printk(KERN_ERR "%s: Incomplete DMA transfer. " |
| 842 | "%d bytes left.\n", |
| 843 | mmc_hostname(host->mmc), count); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | data->error = MMC_ERR_FAILED; |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 846 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | /* |
| 848 | * Transfer data from DMA buffer to |
| 849 | * SG list. |
| 850 | */ |
| 851 | if (data->flags & MMC_DATA_READ) |
| 852 | wbsd_dma_to_sg(host, data); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | data->bytes_xfered = host->size; |
| 855 | } |
| 856 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | wbsd_request_end(host, host->mrq); |
| 861 | } |
| 862 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 863 | /*****************************************************************************\ |
| 864 | * * |
| 865 | * MMC layer callbacks * |
| 866 | * * |
| 867 | \*****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 869 | static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 871 | struct wbsd_host *host = mmc_priv(mmc); |
| 872 | struct mmc_command *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | /* |
| 875 | * Disable tasklets to avoid a deadlock. |
| 876 | */ |
| 877 | spin_lock_bh(&host->lock); |
| 878 | |
| 879 | BUG_ON(host->mrq != NULL); |
| 880 | |
| 881 | cmd = mrq->cmd; |
| 882 | |
| 883 | host->mrq = mrq; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | /* |
| 886 | * If there is no card in the slot then |
| 887 | * timeout immediatly. |
| 888 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 889 | if (!(host->flags & WBSD_FCARD_PRESENT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | cmd->error = MMC_ERR_TIMEOUT; |
| 891 | goto done; |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * Does the request include data? |
| 896 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 897 | if (cmd->data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | wbsd_prepare_data(host, cmd->data); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | if (cmd->data->error != MMC_ERR_NONE) |
| 901 | goto done; |
| 902 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | wbsd_send_command(host, cmd); |
| 905 | |
| 906 | /* |
| 907 | * If this is a data transfer the request |
| 908 | * will be finished after the data has |
| 909 | * transfered. |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 910 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 911 | if (cmd->data && (cmd->error == MMC_ERR_NONE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /* |
| 913 | * Dirty fix for hardware bug. |
| 914 | */ |
| 915 | if (host->dma == -1) |
| 916 | tasklet_schedule(&host->fifo_tasklet); |
| 917 | |
| 918 | spin_unlock_bh(&host->lock); |
| 919 | |
| 920 | return; |
| 921 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | done: |
| 924 | wbsd_request_end(host, mrq); |
| 925 | |
| 926 | spin_unlock_bh(&host->lock); |
| 927 | } |
| 928 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 929 | static void wbsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 931 | struct wbsd_host *host = mmc_priv(mmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | u8 clk, setup, pwr; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | spin_lock_bh(&host->lock); |
| 935 | |
| 936 | /* |
| 937 | * Reset the chip on each power off. |
| 938 | * Should clear out any weird states. |
| 939 | */ |
| 940 | if (ios->power_mode == MMC_POWER_OFF) |
| 941 | wbsd_init_device(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (ios->clock >= 24000000) |
| 944 | clk = WBSD_CLK_24M; |
| 945 | else if (ios->clock >= 16000000) |
| 946 | clk = WBSD_CLK_16M; |
| 947 | else if (ios->clock >= 12000000) |
| 948 | clk = WBSD_CLK_12M; |
| 949 | else |
| 950 | clk = WBSD_CLK_375K; |
| 951 | |
| 952 | /* |
| 953 | * Only write to the clock register when |
| 954 | * there is an actual change. |
| 955 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 956 | if (clk != host->clk) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | wbsd_write_index(host, WBSD_IDX_CLK, clk); |
| 958 | host->clk = clk; |
| 959 | } |
| 960 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 961 | /* |
| 962 | * Power up card. |
| 963 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 964 | if (ios->power_mode != MMC_POWER_OFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | pwr = inb(host->base + WBSD_CSR); |
| 966 | pwr &= ~WBSD_POWER_N; |
| 967 | outb(pwr, host->base + WBSD_CSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 970 | /* |
| 971 | * MMC cards need to have pin 1 high during init. |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 972 | * It wreaks havoc with the card detection though so |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 973 | * that needs to be disabled. |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 974 | */ |
| 975 | setup = wbsd_read_index(host, WBSD_IDX_SETUP); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 976 | if (ios->chip_select == MMC_CS_HIGH) { |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 977 | BUG_ON(ios->bus_width != MMC_BUS_WIDTH_1); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 978 | setup |= WBSD_DAT3_H; |
| 979 | host->flags |= WBSD_FIGNORE_DETECT; |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 980 | } else { |
| 981 | if (setup & WBSD_DAT3_H) { |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 982 | setup &= ~WBSD_DAT3_H; |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 983 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 984 | /* |
| 985 | * We cannot resume card detection immediatly |
| 986 | * because of capacitance and delays in the chip. |
| 987 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 988 | mod_timer(&host->ignore_timer, jiffies + HZ / 100); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 989 | } |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 990 | } |
| 991 | wbsd_write_index(host, WBSD_IDX_SETUP, setup); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 992 | |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 993 | /* |
| 994 | * Store bus width for later. Will be used when |
| 995 | * setting up the data transfer. |
| 996 | */ |
| 997 | host->bus_width = ios->bus_width; |
| 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | spin_unlock_bh(&host->lock); |
| 1000 | } |
| 1001 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1002 | static int wbsd_get_ro(struct mmc_host *mmc) |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 1003 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1004 | struct wbsd_host *host = mmc_priv(mmc); |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 1005 | u8 csr; |
| 1006 | |
| 1007 | spin_lock_bh(&host->lock); |
| 1008 | |
| 1009 | csr = inb(host->base + WBSD_CSR); |
| 1010 | csr |= WBSD_MSLED; |
| 1011 | outb(csr, host->base + WBSD_CSR); |
| 1012 | |
| 1013 | mdelay(1); |
| 1014 | |
| 1015 | csr = inb(host->base + WBSD_CSR); |
| 1016 | csr &= ~WBSD_MSLED; |
| 1017 | outb(csr, host->base + WBSD_CSR); |
| 1018 | |
| 1019 | spin_unlock_bh(&host->lock); |
| 1020 | |
| 1021 | return csr & WBSD_WRPT; |
| 1022 | } |
| 1023 | |
David Brownell | ab7aefd | 2006-11-12 17:55:30 -0800 | [diff] [blame] | 1024 | static const struct mmc_host_ops wbsd_ops = { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1025 | .request = wbsd_request, |
| 1026 | .set_ios = wbsd_set_ios, |
Pierre Ossman | 65ae211 | 2005-09-06 15:18:57 -0700 | [diff] [blame] | 1027 | .get_ro = wbsd_get_ro, |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1028 | }; |
| 1029 | |
| 1030 | /*****************************************************************************\ |
| 1031 | * * |
| 1032 | * Interrupt handling * |
| 1033 | * * |
| 1034 | \*****************************************************************************/ |
| 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | /* |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 1037 | * Helper function to reset detection ignore |
| 1038 | */ |
| 1039 | |
| 1040 | static void wbsd_reset_ignore(unsigned long data) |
| 1041 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1042 | struct wbsd_host *host = (struct wbsd_host *)data; |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 1043 | |
| 1044 | BUG_ON(host == NULL); |
| 1045 | |
| 1046 | DBG("Resetting card detection ignore\n"); |
| 1047 | |
| 1048 | spin_lock_bh(&host->lock); |
| 1049 | |
| 1050 | host->flags &= ~WBSD_FIGNORE_DETECT; |
| 1051 | |
| 1052 | /* |
| 1053 | * Card status might have changed during the |
| 1054 | * blackout. |
| 1055 | */ |
| 1056 | tasklet_schedule(&host->card_tasklet); |
| 1057 | |
| 1058 | spin_unlock_bh(&host->lock); |
| 1059 | } |
| 1060 | |
| 1061 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | * Tasklets |
| 1063 | */ |
| 1064 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1065 | static inline struct mmc_data *wbsd_get_data(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
| 1067 | WARN_ON(!host->mrq); |
| 1068 | if (!host->mrq) |
| 1069 | return NULL; |
| 1070 | |
| 1071 | WARN_ON(!host->mrq->cmd); |
| 1072 | if (!host->mrq->cmd) |
| 1073 | return NULL; |
| 1074 | |
| 1075 | WARN_ON(!host->mrq->cmd->data); |
| 1076 | if (!host->mrq->cmd->data) |
| 1077 | return NULL; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | return host->mrq->cmd->data; |
| 1080 | } |
| 1081 | |
| 1082 | static void wbsd_tasklet_card(unsigned long param) |
| 1083 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1084 | struct wbsd_host *host = (struct wbsd_host *)param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | u8 csr; |
Pierre Ossman | 210ce2a | 2005-09-12 20:36:19 +0100 | [diff] [blame] | 1086 | int delay = -1; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | spin_lock(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1089 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1090 | if (host->flags & WBSD_FIGNORE_DETECT) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1091 | spin_unlock(&host->lock); |
| 1092 | return; |
| 1093 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | csr = inb(host->base + WBSD_CSR); |
| 1096 | WARN_ON(csr == 0xff); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1097 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1098 | if (csr & WBSD_CARDPRESENT) { |
| 1099 | if (!(host->flags & WBSD_FCARD_PRESENT)) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1100 | DBG("Card inserted\n"); |
| 1101 | host->flags |= WBSD_FCARD_PRESENT; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1102 | |
Pierre Ossman | 210ce2a | 2005-09-12 20:36:19 +0100 | [diff] [blame] | 1103 | delay = 500; |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1104 | } |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1105 | } else if (host->flags & WBSD_FCARD_PRESENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | DBG("Card removed\n"); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1107 | host->flags &= ~WBSD_FCARD_PRESENT; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1108 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1109 | if (host->mrq) { |
Pierre Ossman | d191634 | 2005-11-05 10:36:35 +0000 | [diff] [blame] | 1110 | printk(KERN_ERR "%s: Card removed during transfer!\n", |
| 1111 | mmc_hostname(host->mmc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | wbsd_reset(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | host->mrq->cmd->error = MMC_ERR_FAILED; |
| 1115 | tasklet_schedule(&host->finish_tasklet); |
| 1116 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1117 | |
Pierre Ossman | 210ce2a | 2005-09-12 20:36:19 +0100 | [diff] [blame] | 1118 | delay = 0; |
Pierre Ossman | 6e6293d | 2005-07-01 12:13:55 +0100 | [diff] [blame] | 1119 | } |
Pierre Ossman | 210ce2a | 2005-09-12 20:36:19 +0100 | [diff] [blame] | 1120 | |
| 1121 | /* |
| 1122 | * Unlock first since we might get a call back. |
| 1123 | */ |
| 1124 | |
| 1125 | spin_unlock(&host->lock); |
| 1126 | |
| 1127 | if (delay != -1) |
| 1128 | mmc_detect_change(host->mmc, msecs_to_jiffies(delay)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static void wbsd_tasklet_fifo(unsigned long param) |
| 1132 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1133 | struct wbsd_host *host = (struct wbsd_host *)param; |
| 1134 | struct mmc_data *data; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | spin_lock(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (!host->mrq) |
| 1139 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | data = wbsd_get_data(host); |
| 1142 | if (!data) |
| 1143 | goto end; |
| 1144 | |
| 1145 | if (data->flags & MMC_DATA_WRITE) |
| 1146 | wbsd_fill_fifo(host); |
| 1147 | else |
| 1148 | wbsd_empty_fifo(host); |
| 1149 | |
| 1150 | /* |
| 1151 | * Done? |
| 1152 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1153 | if (host->size == data->bytes_xfered) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | wbsd_write_index(host, WBSD_IDX_FIFOEN, 0); |
| 1155 | tasklet_schedule(&host->finish_tasklet); |
| 1156 | } |
| 1157 | |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1158 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | spin_unlock(&host->lock); |
| 1160 | } |
| 1161 | |
| 1162 | static void wbsd_tasklet_crc(unsigned long param) |
| 1163 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1164 | struct wbsd_host *host = (struct wbsd_host *)param; |
| 1165 | struct mmc_data *data; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | spin_lock(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | if (!host->mrq) |
| 1170 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | data = wbsd_get_data(host); |
| 1173 | if (!data) |
| 1174 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | DBGF("CRC error\n"); |
| 1177 | |
| 1178 | data->error = MMC_ERR_BADCRC; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | tasklet_schedule(&host->finish_tasklet); |
| 1181 | |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1182 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | spin_unlock(&host->lock); |
| 1184 | } |
| 1185 | |
| 1186 | static void wbsd_tasklet_timeout(unsigned long param) |
| 1187 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1188 | struct wbsd_host *host = (struct wbsd_host *)param; |
| 1189 | struct mmc_data *data; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | spin_lock(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | if (!host->mrq) |
| 1194 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | data = wbsd_get_data(host); |
| 1197 | if (!data) |
| 1198 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | DBGF("Timeout\n"); |
| 1201 | |
| 1202 | data->error = MMC_ERR_TIMEOUT; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | tasklet_schedule(&host->finish_tasklet); |
| 1205 | |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1206 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | spin_unlock(&host->lock); |
| 1208 | } |
| 1209 | |
| 1210 | static void wbsd_tasklet_finish(unsigned long param) |
| 1211 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1212 | struct wbsd_host *host = (struct wbsd_host *)param; |
| 1213 | struct mmc_data *data; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | spin_lock(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | WARN_ON(!host->mrq); |
| 1218 | if (!host->mrq) |
| 1219 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | data = wbsd_get_data(host); |
| 1222 | if (!data) |
| 1223 | goto end; |
| 1224 | |
| 1225 | wbsd_finish_data(host, data); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1226 | |
| 1227 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | spin_unlock(&host->lock); |
| 1229 | } |
| 1230 | |
| 1231 | static void wbsd_tasklet_block(unsigned long param) |
| 1232 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1233 | struct wbsd_host *host = (struct wbsd_host *)param; |
| 1234 | struct mmc_data *data; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | spin_lock(&host->lock); |
| 1237 | |
| 1238 | if ((wbsd_read_index(host, WBSD_IDX_CRCSTATUS) & WBSD_CRC_MASK) != |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1239 | WBSD_CRC_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | data = wbsd_get_data(host); |
| 1241 | if (!data) |
| 1242 | goto end; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | DBGF("CRC error\n"); |
| 1245 | |
| 1246 | data->error = MMC_ERR_BADCRC; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | tasklet_schedule(&host->finish_tasklet); |
| 1249 | } |
| 1250 | |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1251 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | spin_unlock(&host->lock); |
| 1253 | } |
| 1254 | |
| 1255 | /* |
| 1256 | * Interrupt handling |
| 1257 | */ |
| 1258 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1259 | static irqreturn_t wbsd_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1261 | struct wbsd_host *host = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | int isr; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | isr = inb(host->base + WBSD_ISR); |
| 1265 | |
| 1266 | /* |
| 1267 | * Was it actually our hardware that caused the interrupt? |
| 1268 | */ |
| 1269 | if (isr == 0xff || isr == 0x00) |
| 1270 | return IRQ_NONE; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | host->isr |= isr; |
| 1273 | |
| 1274 | /* |
| 1275 | * Schedule tasklets as needed. |
| 1276 | */ |
| 1277 | if (isr & WBSD_INT_CARD) |
| 1278 | tasklet_schedule(&host->card_tasklet); |
| 1279 | if (isr & WBSD_INT_FIFO_THRE) |
| 1280 | tasklet_schedule(&host->fifo_tasklet); |
| 1281 | if (isr & WBSD_INT_CRC) |
| 1282 | tasklet_hi_schedule(&host->crc_tasklet); |
| 1283 | if (isr & WBSD_INT_TIMEOUT) |
| 1284 | tasklet_hi_schedule(&host->timeout_tasklet); |
| 1285 | if (isr & WBSD_INT_BUSYEND) |
| 1286 | tasklet_hi_schedule(&host->block_tasklet); |
| 1287 | if (isr & WBSD_INT_TC) |
| 1288 | tasklet_schedule(&host->finish_tasklet); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | return IRQ_HANDLED; |
| 1291 | } |
| 1292 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1293 | /*****************************************************************************\ |
| 1294 | * * |
| 1295 | * Device initialisation and shutdown * |
| 1296 | * * |
| 1297 | \*****************************************************************************/ |
| 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1300 | * Allocate/free MMC structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | */ |
| 1302 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1303 | static int __devinit wbsd_alloc_mmc(struct device *dev) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1304 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1305 | struct mmc_host *mmc; |
| 1306 | struct wbsd_host *host; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1307 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1308 | /* |
| 1309 | * Allocate MMC structure. |
| 1310 | */ |
| 1311 | mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev); |
| 1312 | if (!mmc) |
| 1313 | return -ENOMEM; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1314 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1315 | host = mmc_priv(mmc); |
| 1316 | host->mmc = mmc; |
| 1317 | |
| 1318 | host->dma = -1; |
| 1319 | |
| 1320 | /* |
| 1321 | * Set host parameters. |
| 1322 | */ |
| 1323 | mmc->ops = &wbsd_ops; |
| 1324 | mmc->f_min = 375000; |
| 1325 | mmc->f_max = 24000000; |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1326 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
Russell King | 42431ac | 2006-09-24 10:44:09 +0100 | [diff] [blame] | 1327 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1328 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1329 | spin_lock_init(&host->lock); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1330 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1331 | /* |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 1332 | * Set up timers |
Pierre Ossman | 6e6293d | 2005-07-01 12:13:55 +0100 | [diff] [blame] | 1333 | */ |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 1334 | init_timer(&host->ignore_timer); |
| 1335 | host->ignore_timer.data = (unsigned long)host; |
| 1336 | host->ignore_timer.function = wbsd_reset_ignore; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1337 | |
Pierre Ossman | 6e6293d | 2005-07-01 12:13:55 +0100 | [diff] [blame] | 1338 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1339 | * Maximum number of segments. Worst case is one sector per segment |
| 1340 | * so this will be 64kB/512. |
| 1341 | */ |
| 1342 | mmc->max_hw_segs = 128; |
| 1343 | mmc->max_phys_segs = 128; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1344 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1345 | /* |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame^] | 1346 | * Maximum request size. Also limited by 64KiB buffer. |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1347 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame^] | 1348 | mmc->max_req_size = 65536; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1349 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1350 | /* |
| 1351 | * Maximum segment size. Could be one segment with the maximum number |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame^] | 1352 | * of bytes. |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1353 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame^] | 1354 | mmc->max_seg_size = mmc->max_req_size; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1355 | |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1356 | /* |
| 1357 | * Maximum block size. We have 12 bits (= 4095) but have to subtract |
| 1358 | * space for CRC. So the maximum is 4095 - 4*2 = 4087. |
| 1359 | */ |
| 1360 | mmc->max_blk_size = 4087; |
| 1361 | |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame^] | 1362 | /* |
| 1363 | * Maximum block count. There is no real limit so the maximum |
| 1364 | * request size will be the only restriction. |
| 1365 | */ |
| 1366 | mmc->max_blk_count = mmc->max_req_size; |
| 1367 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1368 | dev_set_drvdata(dev, mmc); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1369 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1370 | return 0; |
| 1371 | } |
| 1372 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1373 | static void __devexit wbsd_free_mmc(struct device *dev) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1374 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1375 | struct mmc_host *mmc; |
| 1376 | struct wbsd_host *host; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1377 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1378 | mmc = dev_get_drvdata(dev); |
| 1379 | if (!mmc) |
| 1380 | return; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1381 | |
Pierre Ossman | 6e6293d | 2005-07-01 12:13:55 +0100 | [diff] [blame] | 1382 | host = mmc_priv(mmc); |
| 1383 | BUG_ON(host == NULL); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1384 | |
Pierre Ossman | 1656fa5 | 2005-09-03 16:45:49 +0100 | [diff] [blame] | 1385 | del_timer_sync(&host->ignore_timer); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1386 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1387 | mmc_free_host(mmc); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1388 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1389 | dev_set_drvdata(dev, NULL); |
| 1390 | } |
| 1391 | |
| 1392 | /* |
| 1393 | * Scan for known chip id:s |
| 1394 | */ |
| 1395 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1396 | static int __devinit wbsd_scan(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | { |
| 1398 | int i, j, k; |
| 1399 | int id; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | /* |
| 1402 | * Iterate through all ports, all codes to |
| 1403 | * find hardware that is in our known list. |
| 1404 | */ |
Dmitry Torokhov | 63648fb | 2006-01-03 22:56:56 +0000 | [diff] [blame] | 1405 | for (i = 0; i < ARRAY_SIZE(config_ports); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | if (!request_region(config_ports[i], 2, DRIVER_NAME)) |
| 1407 | continue; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1408 | |
Dmitry Torokhov | 63648fb | 2006-01-03 22:56:56 +0000 | [diff] [blame] | 1409 | for (j = 0; j < ARRAY_SIZE(unlock_codes); j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | id = 0xFFFF; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1411 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1412 | host->config = config_ports[i]; |
| 1413 | host->unlock_code = unlock_codes[j]; |
| 1414 | |
| 1415 | wbsd_unlock_config(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | outb(WBSD_CONF_ID_HI, config_ports[i]); |
| 1418 | id = inb(config_ports[i] + 1) << 8; |
| 1419 | |
| 1420 | outb(WBSD_CONF_ID_LO, config_ports[i]); |
| 1421 | id |= inb(config_ports[i] + 1); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1422 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1423 | wbsd_lock_config(host); |
| 1424 | |
Dmitry Torokhov | 63648fb | 2006-01-03 22:56:56 +0000 | [diff] [blame] | 1425 | for (k = 0; k < ARRAY_SIZE(valid_ids); k++) { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1426 | if (id == valid_ids[k]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | host->chip_id = id; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |
| 1431 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1432 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1433 | if (id != 0xFFFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | DBG("Unknown hardware (id %x) found at %x\n", |
| 1435 | id, config_ports[i]); |
| 1436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | release_region(config_ports[i], 2); |
| 1440 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1441 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1442 | host->config = 0; |
| 1443 | host->unlock_code = 0; |
| 1444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | return -ENODEV; |
| 1446 | } |
| 1447 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1448 | /* |
| 1449 | * Allocate/free io port ranges |
| 1450 | */ |
| 1451 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1452 | static int __devinit wbsd_request_region(struct wbsd_host *host, int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Pierre Ossman | 916f3ac | 2006-08-06 22:22:23 +0200 | [diff] [blame] | 1454 | if (base & 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | return -EINVAL; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1456 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1457 | if (!request_region(base, 8, DRIVER_NAME)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | return -EIO; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1459 | |
Pierre Ossman | 916f3ac | 2006-08-06 22:22:23 +0200 | [diff] [blame] | 1460 | host->base = base; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | return 0; |
| 1463 | } |
| 1464 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1465 | static void __devexit wbsd_release_regions(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | { |
| 1467 | if (host->base) |
| 1468 | release_region(host->base, 8); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1469 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1470 | host->base = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | |
| 1472 | if (host->config) |
| 1473 | release_region(host->config, 2); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1474 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1475 | host->config = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1478 | /* |
| 1479 | * Allocate/free DMA port and buffer |
| 1480 | */ |
| 1481 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1482 | static void __devinit wbsd_request_dma(struct wbsd_host *host, int dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | if (dma < 0) |
| 1485 | return; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | if (request_dma(dma, DRIVER_NAME)) |
| 1488 | goto err; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | /* |
| 1491 | * We need to allocate a special buffer in |
| 1492 | * order for ISA to be able to DMA to it. |
| 1493 | */ |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1494 | host->dma_buffer = kmalloc(WBSD_DMA_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | GFP_NOIO | GFP_DMA | __GFP_REPEAT | __GFP_NOWARN); |
| 1496 | if (!host->dma_buffer) |
| 1497 | goto free; |
| 1498 | |
| 1499 | /* |
| 1500 | * Translate the address to a physical address. |
| 1501 | */ |
Greg Kroah-Hartman | fcaf71f | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1502 | host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer, |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1503 | WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | /* |
| 1506 | * ISA DMA must be aligned on a 64k basis. |
| 1507 | */ |
| 1508 | if ((host->dma_addr & 0xffff) != 0) |
| 1509 | goto kfree; |
| 1510 | /* |
| 1511 | * ISA cannot access memory above 16 MB. |
| 1512 | */ |
| 1513 | else if (host->dma_addr >= 0x1000000) |
| 1514 | goto kfree; |
| 1515 | |
| 1516 | host->dma = dma; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | return; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | kfree: |
| 1521 | /* |
| 1522 | * If we've gotten here then there is some kind of alignment bug |
| 1523 | */ |
| 1524 | BUG_ON(1); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1525 | |
Greg Kroah-Hartman | fcaf71f | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1526 | dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1527 | WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1528 | host->dma_addr = (dma_addr_t)NULL; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | kfree(host->dma_buffer); |
| 1531 | host->dma_buffer = NULL; |
| 1532 | |
| 1533 | free: |
| 1534 | free_dma(dma); |
| 1535 | |
| 1536 | err: |
| 1537 | printk(KERN_WARNING DRIVER_NAME ": Unable to allocate DMA %d. " |
| 1538 | "Falling back on FIFO.\n", dma); |
| 1539 | } |
| 1540 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1541 | static void __devexit wbsd_release_dma(struct wbsd_host *host) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1542 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1543 | if (host->dma_addr) { |
Greg Kroah-Hartman | fcaf71f | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1544 | dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1545 | WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); |
| 1546 | } |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 1547 | kfree(host->dma_buffer); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1548 | if (host->dma >= 0) |
| 1549 | free_dma(host->dma); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1550 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1551 | host->dma = -1; |
| 1552 | host->dma_buffer = NULL; |
| 1553 | host->dma_addr = (dma_addr_t)NULL; |
| 1554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
| 1556 | /* |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1557 | * Allocate/free IRQ. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | */ |
| 1559 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1560 | static int __devinit wbsd_request_irq(struct wbsd_host *host, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | int ret; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | * Allocate interrupt. |
| 1566 | */ |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1567 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 1568 | ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (ret) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1570 | return ret; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | host->irq = irq; |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | /* |
| 1575 | * Set up tasklets. |
| 1576 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1577 | tasklet_init(&host->card_tasklet, wbsd_tasklet_card, |
| 1578 | (unsigned long)host); |
| 1579 | tasklet_init(&host->fifo_tasklet, wbsd_tasklet_fifo, |
| 1580 | (unsigned long)host); |
| 1581 | tasklet_init(&host->crc_tasklet, wbsd_tasklet_crc, |
| 1582 | (unsigned long)host); |
| 1583 | tasklet_init(&host->timeout_tasklet, wbsd_tasklet_timeout, |
| 1584 | (unsigned long)host); |
| 1585 | tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish, |
| 1586 | (unsigned long)host); |
| 1587 | tasklet_init(&host->block_tasklet, wbsd_tasklet_block, |
| 1588 | (unsigned long)host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1593 | static void __devexit wbsd_release_irq(struct wbsd_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1595 | if (!host->irq) |
| 1596 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | |
| 1598 | free_irq(host->irq, host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1599 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1600 | host->irq = 0; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | tasklet_kill(&host->card_tasklet); |
| 1603 | tasklet_kill(&host->fifo_tasklet); |
| 1604 | tasklet_kill(&host->crc_tasklet); |
| 1605 | tasklet_kill(&host->timeout_tasklet); |
| 1606 | tasklet_kill(&host->finish_tasklet); |
| 1607 | tasklet_kill(&host->block_tasklet); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * Allocate all resources for the host. |
| 1612 | */ |
| 1613 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1614 | static int __devinit wbsd_request_resources(struct wbsd_host *host, |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1615 | int base, int irq, int dma) |
| 1616 | { |
| 1617 | int ret; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1618 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1619 | /* |
| 1620 | * Allocate I/O ports. |
| 1621 | */ |
| 1622 | ret = wbsd_request_region(host, base); |
| 1623 | if (ret) |
| 1624 | return ret; |
| 1625 | |
| 1626 | /* |
| 1627 | * Allocate interrupt. |
| 1628 | */ |
| 1629 | ret = wbsd_request_irq(host, irq); |
| 1630 | if (ret) |
| 1631 | return ret; |
| 1632 | |
| 1633 | /* |
| 1634 | * Allocate DMA. |
| 1635 | */ |
| 1636 | wbsd_request_dma(host, dma); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1637 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | /* |
| 1642 | * Release all resources for the host. |
| 1643 | */ |
| 1644 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1645 | static void __devexit wbsd_release_resources(struct wbsd_host *host) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1646 | { |
| 1647 | wbsd_release_dma(host); |
| 1648 | wbsd_release_irq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | wbsd_release_regions(host); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | /* |
| 1653 | * Configure the resources the chip should use. |
| 1654 | */ |
| 1655 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1656 | static void wbsd_chip_config(struct wbsd_host *host) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1657 | { |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1658 | wbsd_unlock_config(host); |
| 1659 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1660 | /* |
| 1661 | * Reset the chip. |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1662 | */ |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1663 | wbsd_write_config(host, WBSD_CONF_SWRST, 1); |
| 1664 | wbsd_write_config(host, WBSD_CONF_SWRST, 0); |
| 1665 | |
| 1666 | /* |
| 1667 | * Select SD/MMC function. |
| 1668 | */ |
| 1669 | wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1670 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1671 | /* |
| 1672 | * Set up card detection. |
| 1673 | */ |
| 1674 | wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1675 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1676 | /* |
| 1677 | * Configure chip |
| 1678 | */ |
| 1679 | wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8); |
| 1680 | wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1681 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1682 | wbsd_write_config(host, WBSD_CONF_IRQ, host->irq); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1683 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1684 | if (host->dma >= 0) |
| 1685 | wbsd_write_config(host, WBSD_CONF_DRQ, host->dma); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1686 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1687 | /* |
| 1688 | * Enable and power up chip. |
| 1689 | */ |
| 1690 | wbsd_write_config(host, WBSD_CONF_ENABLE, 1); |
| 1691 | wbsd_write_config(host, WBSD_CONF_POWER, 0x20); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1692 | |
| 1693 | wbsd_lock_config(host); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | /* |
| 1697 | * Check that configured resources are correct. |
| 1698 | */ |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1699 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1700 | static int wbsd_chip_validate(struct wbsd_host *host) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1701 | { |
| 1702 | int base, irq, dma; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1703 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1704 | wbsd_unlock_config(host); |
| 1705 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1706 | /* |
| 1707 | * Select SD/MMC function. |
| 1708 | */ |
| 1709 | wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1710 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1711 | /* |
| 1712 | * Read configuration. |
| 1713 | */ |
| 1714 | base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8; |
| 1715 | base |= wbsd_read_config(host, WBSD_CONF_PORT_LO); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1716 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1717 | irq = wbsd_read_config(host, WBSD_CONF_IRQ); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1718 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1719 | dma = wbsd_read_config(host, WBSD_CONF_DRQ); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1720 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1721 | wbsd_lock_config(host); |
| 1722 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1723 | /* |
| 1724 | * Validate against given configuration. |
| 1725 | */ |
| 1726 | if (base != host->base) |
| 1727 | return 0; |
| 1728 | if (irq != host->irq) |
| 1729 | return 0; |
| 1730 | if ((dma != host->dma) && (host->dma != -1)) |
| 1731 | return 0; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1732 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1733 | return 1; |
| 1734 | } |
| 1735 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1736 | /* |
| 1737 | * Powers down the SD function |
| 1738 | */ |
| 1739 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1740 | static void wbsd_chip_poweroff(struct wbsd_host *host) |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1741 | { |
| 1742 | wbsd_unlock_config(host); |
| 1743 | |
| 1744 | wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); |
| 1745 | wbsd_write_config(host, WBSD_CONF_ENABLE, 0); |
| 1746 | |
| 1747 | wbsd_lock_config(host); |
| 1748 | } |
| 1749 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1750 | /*****************************************************************************\ |
| 1751 | * * |
| 1752 | * Devices setup and shutdown * |
| 1753 | * * |
| 1754 | \*****************************************************************************/ |
| 1755 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1756 | static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma, |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1757 | int pnp) |
| 1758 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1759 | struct wbsd_host *host = NULL; |
| 1760 | struct mmc_host *mmc = NULL; |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1761 | int ret; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1762 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1763 | ret = wbsd_alloc_mmc(dev); |
| 1764 | if (ret) |
| 1765 | return ret; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1766 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1767 | mmc = dev_get_drvdata(dev); |
| 1768 | host = mmc_priv(mmc); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1769 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1770 | /* |
| 1771 | * Scan for hardware. |
| 1772 | */ |
| 1773 | ret = wbsd_scan(host); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1774 | if (ret) { |
| 1775 | if (pnp && (ret == -ENODEV)) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1776 | printk(KERN_WARNING DRIVER_NAME |
| 1777 | ": Unable to confirm device presence. You may " |
| 1778 | "experience lock-ups.\n"); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1779 | } else { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1780 | wbsd_free_mmc(dev); |
| 1781 | return ret; |
| 1782 | } |
| 1783 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1784 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1785 | /* |
| 1786 | * Request resources. |
| 1787 | */ |
Pierre Ossman | dd2c609 | 2006-08-07 01:40:04 +0200 | [diff] [blame] | 1788 | ret = wbsd_request_resources(host, base, irq, dma); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1789 | if (ret) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1790 | wbsd_release_resources(host); |
| 1791 | wbsd_free_mmc(dev); |
| 1792 | return ret; |
| 1793 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1794 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1795 | /* |
| 1796 | * See if chip needs to be configured. |
| 1797 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1798 | if (pnp) { |
| 1799 | if ((host->config != 0) && !wbsd_chip_validate(host)) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1800 | printk(KERN_WARNING DRIVER_NAME |
| 1801 | ": PnP active but chip not configured! " |
| 1802 | "You probably have a buggy BIOS. " |
| 1803 | "Configuring chip manually.\n"); |
| 1804 | wbsd_chip_config(host); |
| 1805 | } |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1806 | } else |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1807 | wbsd_chip_config(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1808 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1809 | /* |
| 1810 | * Power Management stuff. No idea how this works. |
| 1811 | * Not tested. |
| 1812 | */ |
| 1813 | #ifdef CONFIG_PM |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1814 | if (host->config) { |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1815 | wbsd_unlock_config(host); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1816 | wbsd_write_config(host, WBSD_CONF_PME, 0xA0); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1817 | wbsd_lock_config(host); |
| 1818 | } |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1819 | #endif |
| 1820 | /* |
| 1821 | * Allow device to initialise itself properly. |
| 1822 | */ |
| 1823 | mdelay(5); |
| 1824 | |
| 1825 | /* |
| 1826 | * Reset the chip into a known state. |
| 1827 | */ |
| 1828 | wbsd_init_device(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1829 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1830 | mmc_add_host(mmc); |
| 1831 | |
Russell King | d366b64 | 2005-08-19 09:40:08 +0100 | [diff] [blame] | 1832 | printk(KERN_INFO "%s: W83L51xD", mmc_hostname(mmc)); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1833 | if (host->chip_id != 0) |
| 1834 | printk(" id %x", (int)host->chip_id); |
| 1835 | printk(" at 0x%x irq %d", (int)host->base, (int)host->irq); |
| 1836 | if (host->dma >= 0) |
| 1837 | printk(" dma %d", (int)host->dma); |
| 1838 | else |
| 1839 | printk(" FIFO"); |
| 1840 | if (pnp) |
| 1841 | printk(" PnP"); |
| 1842 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1847 | static void __devexit wbsd_shutdown(struct device *dev, int pnp) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1848 | { |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1849 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 1850 | struct wbsd_host *host; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1851 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1852 | if (!mmc) |
| 1853 | return; |
| 1854 | |
| 1855 | host = mmc_priv(mmc); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1856 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1857 | mmc_remove_host(mmc); |
| 1858 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1859 | /* |
| 1860 | * Power down the SD/MMC function. |
| 1861 | */ |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1862 | if (!pnp) |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1863 | wbsd_chip_poweroff(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1864 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1865 | wbsd_release_resources(host); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1866 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1867 | wbsd_free_mmc(dev); |
| 1868 | } |
| 1869 | |
| 1870 | /* |
| 1871 | * Non-PnP |
| 1872 | */ |
| 1873 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1874 | static int __devinit wbsd_probe(struct platform_device *dev) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1875 | { |
Pierre Ossman | dd2c609 | 2006-08-07 01:40:04 +0200 | [diff] [blame] | 1876 | /* Use the module parameters for resources */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1877 | return wbsd_init(&dev->dev, io, irq, dma, 0); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1878 | } |
| 1879 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1880 | static int __devexit wbsd_remove(struct platform_device *dev) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1881 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1882 | wbsd_shutdown(&dev->dev, 0); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * PnP |
| 1889 | */ |
| 1890 | |
| 1891 | #ifdef CONFIG_PNP |
| 1892 | |
| 1893 | static int __devinit |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1894 | wbsd_pnp_probe(struct pnp_dev *pnpdev, const struct pnp_device_id *dev_id) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1895 | { |
| 1896 | int io, irq, dma; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1897 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1898 | /* |
| 1899 | * Get resources from PnP layer. |
| 1900 | */ |
| 1901 | io = pnp_port_start(pnpdev, 0); |
| 1902 | irq = pnp_irq(pnpdev, 0); |
| 1903 | if (pnp_dma_valid(pnpdev, 0)) |
| 1904 | dma = pnp_dma(pnpdev, 0); |
| 1905 | else |
| 1906 | dma = -1; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1907 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1908 | DBGF("PnP resources: port %3x irq %d dma %d\n", io, irq, dma); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 1909 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1910 | return wbsd_init(&pnpdev->dev, io, irq, dma, 1); |
| 1911 | } |
| 1912 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1913 | static void __devexit wbsd_pnp_remove(struct pnp_dev *dev) |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 1914 | { |
| 1915 | wbsd_shutdown(&dev->dev, 1); |
| 1916 | } |
| 1917 | |
| 1918 | #endif /* CONFIG_PNP */ |
| 1919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | /* |
| 1921 | * Power management |
| 1922 | */ |
| 1923 | |
| 1924 | #ifdef CONFIG_PM |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1925 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1926 | static int wbsd_suspend(struct wbsd_host *host, pm_message_t state) |
| 1927 | { |
| 1928 | BUG_ON(host == NULL); |
| 1929 | |
| 1930 | return mmc_suspend_host(host->mmc, state); |
| 1931 | } |
| 1932 | |
| 1933 | static int wbsd_resume(struct wbsd_host *host) |
| 1934 | { |
| 1935 | BUG_ON(host == NULL); |
| 1936 | |
| 1937 | wbsd_init_device(host); |
| 1938 | |
| 1939 | return mmc_resume_host(host->mmc); |
| 1940 | } |
| 1941 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 1942 | static int wbsd_platform_suspend(struct platform_device *dev, |
| 1943 | pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1945 | struct mmc_host *mmc = platform_get_drvdata(dev); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1946 | struct wbsd_host *host; |
| 1947 | int ret; |
| 1948 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1949 | if (mmc == NULL) |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1950 | return 0; |
| 1951 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1952 | DBGF("Suspending...\n"); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1953 | |
| 1954 | host = mmc_priv(mmc); |
| 1955 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1956 | ret = wbsd_suspend(host, state); |
| 1957 | if (ret) |
| 1958 | return ret; |
| 1959 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1960 | wbsd_chip_poweroff(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1965 | static int wbsd_platform_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1967 | struct mmc_host *mmc = platform_get_drvdata(dev); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1968 | struct wbsd_host *host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1970 | if (mmc == NULL) |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1971 | return 0; |
| 1972 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1973 | DBGF("Resuming...\n"); |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1974 | |
| 1975 | host = mmc_priv(mmc); |
| 1976 | |
| 1977 | wbsd_chip_config(host); |
| 1978 | |
| 1979 | /* |
| 1980 | * Allow device to initialise itself properly. |
| 1981 | */ |
| 1982 | mdelay(5); |
| 1983 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1984 | return wbsd_resume(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | } |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 1986 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 1987 | #ifdef CONFIG_PNP |
| 1988 | |
| 1989 | static int wbsd_pnp_suspend(struct pnp_dev *pnp_dev, pm_message_t state) |
| 1990 | { |
| 1991 | struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev); |
| 1992 | struct wbsd_host *host; |
| 1993 | |
| 1994 | if (mmc == NULL) |
| 1995 | return 0; |
| 1996 | |
| 1997 | DBGF("Suspending...\n"); |
| 1998 | |
| 1999 | host = mmc_priv(mmc); |
| 2000 | |
| 2001 | return wbsd_suspend(host, state); |
| 2002 | } |
| 2003 | |
| 2004 | static int wbsd_pnp_resume(struct pnp_dev *pnp_dev) |
| 2005 | { |
| 2006 | struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev); |
| 2007 | struct wbsd_host *host; |
| 2008 | |
| 2009 | if (mmc == NULL) |
| 2010 | return 0; |
| 2011 | |
| 2012 | DBGF("Resuming...\n"); |
| 2013 | |
| 2014 | host = mmc_priv(mmc); |
| 2015 | |
| 2016 | /* |
| 2017 | * See if chip needs to be configured. |
| 2018 | */ |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2019 | if (host->config != 0) { |
| 2020 | if (!wbsd_chip_validate(host)) { |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 2021 | printk(KERN_WARNING DRIVER_NAME |
| 2022 | ": PnP active but chip not configured! " |
| 2023 | "You probably have a buggy BIOS. " |
| 2024 | "Configuring chip manually.\n"); |
| 2025 | wbsd_chip_config(host); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | /* |
| 2030 | * Allow device to initialise itself properly. |
| 2031 | */ |
| 2032 | mdelay(5); |
| 2033 | |
| 2034 | return wbsd_resume(host); |
| 2035 | } |
| 2036 | |
| 2037 | #endif /* CONFIG_PNP */ |
| 2038 | |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 2039 | #else /* CONFIG_PM */ |
| 2040 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 2041 | #define wbsd_platform_suspend NULL |
| 2042 | #define wbsd_platform_resume NULL |
| 2043 | |
| 2044 | #define wbsd_pnp_suspend NULL |
| 2045 | #define wbsd_pnp_resume NULL |
Pierre Ossman | 19c1f3c | 2005-10-28 21:37:29 +0100 | [diff] [blame] | 2046 | |
| 2047 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2049 | static struct platform_device *wbsd_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2051 | static struct platform_driver wbsd_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | .probe = wbsd_probe, |
Pierre Ossman | 93968d7 | 2005-11-09 23:21:06 +0000 | [diff] [blame] | 2053 | .remove = __devexit_p(wbsd_remove), |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 2054 | |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 2055 | .suspend = wbsd_platform_suspend, |
| 2056 | .resume = wbsd_platform_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2057 | .driver = { |
| 2058 | .name = DRIVER_NAME, |
| 2059 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | }; |
| 2061 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2062 | #ifdef CONFIG_PNP |
| 2063 | |
| 2064 | static struct pnp_driver wbsd_pnp_driver = { |
| 2065 | .name = DRIVER_NAME, |
| 2066 | .id_table = pnp_dev_table, |
| 2067 | .probe = wbsd_pnp_probe, |
Pierre Ossman | 93968d7 | 2005-11-09 23:21:06 +0000 | [diff] [blame] | 2068 | .remove = __devexit_p(wbsd_pnp_remove), |
Pierre Ossman | 5e68d95 | 2006-01-08 14:21:52 +0000 | [diff] [blame] | 2069 | |
| 2070 | .suspend = wbsd_pnp_suspend, |
| 2071 | .resume = wbsd_pnp_resume, |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2072 | }; |
| 2073 | |
| 2074 | #endif /* CONFIG_PNP */ |
| 2075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | /* |
| 2077 | * Module loading/unloading |
| 2078 | */ |
| 2079 | |
| 2080 | static int __init wbsd_drv_init(void) |
| 2081 | { |
| 2082 | int result; |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 2083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | printk(KERN_INFO DRIVER_NAME |
| 2085 | ": Winbond W83L51xD SD/MMC card interface driver, " |
| 2086 | DRIVER_VERSION "\n"); |
| 2087 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2089 | #ifdef CONFIG_PNP |
| 2090 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2091 | if (!nopnp) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2092 | result = pnp_register_driver(&wbsd_pnp_driver); |
| 2093 | if (result < 0) |
| 2094 | return result; |
| 2095 | } |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 2096 | #endif /* CONFIG_PNP */ |
| 2097 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2098 | if (nopnp) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2099 | result = platform_driver_register(&wbsd_driver); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2100 | if (result < 0) |
| 2101 | return result; |
| 2102 | |
Dmitry Torokhov | 21500bb | 2006-01-03 22:57:35 +0000 | [diff] [blame] | 2103 | wbsd_device = platform_device_alloc(DRIVER_NAME, -1); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2104 | if (!wbsd_device) { |
Dmitry Torokhov | 21500bb | 2006-01-03 22:57:35 +0000 | [diff] [blame] | 2105 | platform_driver_unregister(&wbsd_driver); |
| 2106 | return -ENOMEM; |
| 2107 | } |
| 2108 | |
| 2109 | result = platform_device_add(wbsd_device); |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2110 | if (result) { |
Dmitry Torokhov | 21500bb | 2006-01-03 22:57:35 +0000 | [diff] [blame] | 2111 | platform_device_put(wbsd_device); |
| 2112 | platform_driver_unregister(&wbsd_driver); |
| 2113 | return result; |
| 2114 | } |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static void __exit wbsd_drv_exit(void) |
| 2121 | { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2122 | #ifdef CONFIG_PNP |
| 2123 | |
| 2124 | if (!nopnp) |
| 2125 | pnp_unregister_driver(&wbsd_pnp_driver); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 2126 | |
| 2127 | #endif /* CONFIG_PNP */ |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2128 | |
Pierre Ossman | cfa7f52 | 2006-01-08 18:17:55 +0000 | [diff] [blame] | 2129 | if (nopnp) { |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2130 | platform_device_unregister(wbsd_device); |
Pierre Ossman | fecf92b | 2005-09-12 12:09:25 +0100 | [diff] [blame] | 2131 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2132 | platform_driver_unregister(&wbsd_driver); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | |
| 2135 | DBG("unloaded\n"); |
| 2136 | } |
| 2137 | |
| 2138 | module_init(wbsd_drv_init); |
| 2139 | module_exit(wbsd_drv_exit); |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2140 | #ifdef CONFIG_PNP |
| 2141 | module_param(nopnp, uint, 0444); |
| 2142 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | module_param(io, uint, 0444); |
| 2144 | module_param(irq, uint, 0444); |
| 2145 | module_param(dma, int, 0444); |
| 2146 | |
| 2147 | MODULE_LICENSE("GPL"); |
Pierre Ossman | de1d09e | 2005-11-09 23:21:49 +0000 | [diff] [blame] | 2148 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver"); |
| 2150 | MODULE_VERSION(DRIVER_VERSION); |
| 2151 | |
Pierre Ossman | 85bcc13 | 2005-05-08 19:35:27 +0100 | [diff] [blame] | 2152 | #ifdef CONFIG_PNP |
| 2153 | MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)"); |
| 2154 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | MODULE_PARM_DESC(io, "I/O base to allocate. Must be 8 byte aligned. (default 0x248)"); |
| 2156 | MODULE_PARM_DESC(irq, "IRQ to allocate. (default 6)"); |
| 2157 | MODULE_PARM_DESC(dma, "DMA channel to allocate. -1 for no DMA. (default 2)"); |