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