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