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