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