Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * tifm_sd.c - TI FlashMedia driver |
| 3 | * |
| 4 | * Copyright (C) 2006 Alex Dubov <oakad@yahoo.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #include <linux/tifm.h> |
| 14 | #include <linux/mmc/protocol.h> |
| 15 | #include <linux/mmc/host.h> |
| 16 | #include <linux/highmem.h> |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 17 | #include <linux/scatterlist.h> |
Al Viro | 2099c99 | 2006-10-24 11:17:06 +0100 | [diff] [blame] | 18 | #include <asm/io.h> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 19 | |
| 20 | #define DRIVER_NAME "tifm_sd" |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 21 | #define DRIVER_VERSION "0.8" |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 22 | |
| 23 | static int no_dma = 0; |
| 24 | static int fixed_timeout = 0; |
| 25 | module_param(no_dma, bool, 0644); |
| 26 | module_param(fixed_timeout, bool, 0644); |
| 27 | |
| 28 | /* Constants here are mostly from OMAP5912 datasheet */ |
| 29 | #define TIFM_MMCSD_RESET 0x0002 |
| 30 | #define TIFM_MMCSD_CLKMASK 0x03ff |
| 31 | #define TIFM_MMCSD_POWER 0x0800 |
| 32 | #define TIFM_MMCSD_4BBUS 0x8000 |
| 33 | #define TIFM_MMCSD_RXDE 0x8000 /* rx dma enable */ |
| 34 | #define TIFM_MMCSD_TXDE 0x0080 /* tx dma enable */ |
| 35 | #define TIFM_MMCSD_BUFINT 0x0c00 /* set bits: AE, AF */ |
| 36 | #define TIFM_MMCSD_DPE 0x0020 /* data timeout counted in kilocycles */ |
| 37 | #define TIFM_MMCSD_INAB 0x0080 /* abort / initialize command */ |
| 38 | #define TIFM_MMCSD_READ 0x8000 |
| 39 | |
Alex Dubov | 12c8345 | 2007-02-10 21:16:40 -0800 | [diff] [blame] | 40 | #define TIFM_MMCSD_ERRMASK 0x01e0 /* set bits: CCRC, CTO, DCRC, DTO */ |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 41 | #define TIFM_MMCSD_EOC 0x0001 /* end of command phase */ |
| 42 | #define TIFM_MMCSD_CB 0x0004 /* card enter busy state */ |
| 43 | #define TIFM_MMCSD_BRS 0x0008 /* block received/sent */ |
| 44 | #define TIFM_MMCSD_EOFB 0x0010 /* card exit busy state */ |
| 45 | #define TIFM_MMCSD_DTO 0x0020 /* data time-out */ |
| 46 | #define TIFM_MMCSD_DCRC 0x0040 /* data crc error */ |
| 47 | #define TIFM_MMCSD_CTO 0x0080 /* command time-out */ |
| 48 | #define TIFM_MMCSD_CCRC 0x0100 /* command crc error */ |
| 49 | #define TIFM_MMCSD_AF 0x0400 /* fifo almost full */ |
| 50 | #define TIFM_MMCSD_AE 0x0800 /* fifo almost empty */ |
| 51 | #define TIFM_MMCSD_CERR 0x4000 /* card status error */ |
| 52 | |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 53 | #define TIFM_MMCSD_ODTO 0x0040 /* open drain / extended timeout */ |
| 54 | #define TIFM_MMCSD_CARD_RO 0x0200 /* card is read-only */ |
| 55 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 56 | #define TIFM_MMCSD_FIFO_SIZE 0x0020 |
| 57 | |
| 58 | #define TIFM_MMCSD_RSP_R0 0x0000 |
| 59 | #define TIFM_MMCSD_RSP_R1 0x0100 |
| 60 | #define TIFM_MMCSD_RSP_R2 0x0200 |
| 61 | #define TIFM_MMCSD_RSP_R3 0x0300 |
| 62 | #define TIFM_MMCSD_RSP_R4 0x0400 |
| 63 | #define TIFM_MMCSD_RSP_R5 0x0500 |
| 64 | #define TIFM_MMCSD_RSP_R6 0x0600 |
| 65 | |
| 66 | #define TIFM_MMCSD_RSP_BUSY 0x0800 |
| 67 | |
| 68 | #define TIFM_MMCSD_CMD_BC 0x0000 |
| 69 | #define TIFM_MMCSD_CMD_BCR 0x1000 |
| 70 | #define TIFM_MMCSD_CMD_AC 0x2000 |
| 71 | #define TIFM_MMCSD_CMD_ADTC 0x3000 |
| 72 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 73 | #define TIFM_MMCSD_MAX_BLOCK_SIZE 0x0800UL |
| 74 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 75 | enum { |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 76 | CMD_READY = 0x0001, |
| 77 | FIFO_READY = 0x0002, |
| 78 | BRS_READY = 0x0004, |
| 79 | SCMD_ACTIVE = 0x0008, |
| 80 | SCMD_READY = 0x0010, |
| 81 | CARD_BUSY = 0x0020, |
| 82 | DATA_CARRY = 0x0040 |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 83 | }; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 84 | |
| 85 | struct tifm_sd { |
| 86 | struct tifm_dev *dev; |
| 87 | |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 88 | unsigned short eject:1, |
| 89 | open_drain:1, |
| 90 | no_dma:1; |
| 91 | unsigned short cmd_flags; |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 92 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 93 | unsigned int clk_freq; |
| 94 | unsigned int clk_div; |
Alex Dubov | 0803dd0 | 2006-12-08 16:50:49 +1100 | [diff] [blame] | 95 | unsigned long timeout_jiffies; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 96 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 97 | struct tasklet_struct finish_tasklet; |
Alex Dubov | 0803dd0 | 2006-12-08 16:50:49 +1100 | [diff] [blame] | 98 | struct timer_list timer; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 99 | struct mmc_request *req; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 100 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 101 | int sg_len; |
| 102 | int sg_pos; |
| 103 | unsigned int block_pos; |
| 104 | struct scatterlist bounce_buf; |
| 105 | unsigned char bounce_buf_data[TIFM_MMCSD_MAX_BLOCK_SIZE]; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 108 | /* for some reason, host won't respond correctly to readw/writew */ |
| 109 | static void tifm_sd_read_fifo(struct tifm_sd *host, struct page *pg, |
| 110 | unsigned int off, unsigned int cnt) |
Alex Dubov | 255ef22 | 2006-12-08 16:50:48 +1100 | [diff] [blame] | 111 | { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 112 | struct tifm_dev *sock = host->dev; |
| 113 | unsigned char *buf; |
| 114 | unsigned int pos = 0, val; |
| 115 | |
| 116 | buf = kmap_atomic(pg, KM_BIO_DST_IRQ) + off; |
| 117 | if (host->cmd_flags & DATA_CARRY) { |
| 118 | buf[pos++] = host->bounce_buf_data[0]; |
| 119 | host->cmd_flags &= ~DATA_CARRY; |
| 120 | } |
| 121 | |
| 122 | while (pos < cnt) { |
| 123 | val = readl(sock->addr + SOCK_MMCSD_DATA); |
| 124 | buf[pos++] = val & 0xff; |
| 125 | if (pos == cnt) { |
| 126 | host->bounce_buf_data[0] = (val >> 8) & 0xff; |
| 127 | host->cmd_flags |= DATA_CARRY; |
| 128 | break; |
| 129 | } |
| 130 | buf[pos++] = (val >> 8) & 0xff; |
| 131 | } |
| 132 | kunmap_atomic(buf - off, KM_BIO_DST_IRQ); |
Alex Dubov | 255ef22 | 2006-12-08 16:50:48 +1100 | [diff] [blame] | 133 | } |
| 134 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 135 | static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg, |
| 136 | unsigned int off, unsigned int cnt) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 137 | { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 138 | struct tifm_dev *sock = host->dev; |
| 139 | unsigned char *buf; |
| 140 | unsigned int pos = 0, val; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 141 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 142 | buf = kmap_atomic(pg, KM_BIO_SRC_IRQ) + off; |
| 143 | if (host->cmd_flags & DATA_CARRY) { |
| 144 | val = host->bounce_buf_data[0] | ((buf[pos++] << 8) & 0xff00); |
| 145 | writel(val, sock->addr + SOCK_MMCSD_DATA); |
| 146 | host->cmd_flags &= ~DATA_CARRY; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 147 | } |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 148 | |
| 149 | while (pos < cnt) { |
| 150 | val = buf[pos++]; |
| 151 | if (pos == cnt) { |
| 152 | host->bounce_buf_data[0] = val & 0xff; |
| 153 | host->cmd_flags |= DATA_CARRY; |
| 154 | break; |
| 155 | } |
| 156 | val |= (buf[pos++] << 8) & 0xff00; |
| 157 | writel(val, sock->addr + SOCK_MMCSD_DATA); |
| 158 | } |
| 159 | kunmap_atomic(buf - off, KM_BIO_SRC_IRQ); |
| 160 | } |
| 161 | |
| 162 | static void tifm_sd_transfer_data(struct tifm_sd *host) |
| 163 | { |
| 164 | struct mmc_data *r_data = host->req->cmd->data; |
| 165 | struct scatterlist *sg = r_data->sg; |
| 166 | unsigned int off, cnt, t_size = TIFM_MMCSD_FIFO_SIZE * 2; |
| 167 | unsigned int p_off, p_cnt; |
| 168 | struct page *pg; |
| 169 | |
| 170 | if (host->sg_pos == host->sg_len) |
| 171 | return; |
| 172 | while (t_size) { |
| 173 | cnt = sg[host->sg_pos].length - host->block_pos; |
| 174 | if (!cnt) { |
| 175 | host->block_pos = 0; |
| 176 | host->sg_pos++; |
| 177 | if (host->sg_pos == host->sg_len) { |
| 178 | if ((r_data->flags & MMC_DATA_WRITE) |
| 179 | && DATA_CARRY) |
| 180 | writel(host->bounce_buf_data[0], |
| 181 | host->dev->addr |
| 182 | + SOCK_MMCSD_DATA); |
| 183 | |
| 184 | return; |
| 185 | } |
| 186 | cnt = sg[host->sg_pos].length; |
| 187 | } |
| 188 | off = sg[host->sg_pos].offset + host->block_pos; |
| 189 | |
| 190 | pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT); |
| 191 | p_off = offset_in_page(off); |
| 192 | p_cnt = PAGE_SIZE - p_off; |
| 193 | p_cnt = min(p_cnt, cnt); |
| 194 | p_cnt = min(p_cnt, t_size); |
| 195 | |
| 196 | if (r_data->flags & MMC_DATA_READ) |
| 197 | tifm_sd_read_fifo(host, pg, p_off, p_cnt); |
| 198 | else if (r_data->flags & MMC_DATA_WRITE) |
| 199 | tifm_sd_write_fifo(host, pg, p_off, p_cnt); |
| 200 | |
| 201 | t_size -= p_cnt; |
| 202 | host->block_pos += p_cnt; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | static void tifm_sd_copy_page(struct page *dst, unsigned int dst_off, |
| 207 | struct page *src, unsigned int src_off, |
| 208 | unsigned int count) |
| 209 | { |
| 210 | unsigned char *src_buf = kmap_atomic(src, KM_BIO_SRC_IRQ) + src_off; |
| 211 | unsigned char *dst_buf = kmap_atomic(dst, KM_BIO_DST_IRQ) + dst_off; |
| 212 | |
| 213 | memcpy(dst_buf, src_buf, count); |
| 214 | |
| 215 | kunmap_atomic(dst_buf - dst_off, KM_BIO_DST_IRQ); |
| 216 | kunmap_atomic(src_buf - src_off, KM_BIO_SRC_IRQ); |
| 217 | } |
| 218 | |
| 219 | static void tifm_sd_bounce_block(struct tifm_sd *host, struct mmc_data *r_data) |
| 220 | { |
| 221 | struct scatterlist *sg = r_data->sg; |
| 222 | unsigned int t_size = r_data->blksz; |
| 223 | unsigned int off, cnt; |
| 224 | unsigned int p_off, p_cnt; |
| 225 | struct page *pg; |
| 226 | |
| 227 | dev_dbg(&host->dev->dev, "bouncing block\n"); |
| 228 | while (t_size) { |
| 229 | cnt = sg[host->sg_pos].length - host->block_pos; |
| 230 | if (!cnt) { |
| 231 | host->block_pos = 0; |
| 232 | host->sg_pos++; |
| 233 | if (host->sg_pos == host->sg_len) |
| 234 | return; |
| 235 | cnt = sg[host->sg_pos].length; |
| 236 | } |
| 237 | off = sg[host->sg_pos].offset + host->block_pos; |
| 238 | |
| 239 | pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT); |
| 240 | p_off = offset_in_page(off); |
| 241 | p_cnt = PAGE_SIZE - p_off; |
| 242 | p_cnt = min(p_cnt, cnt); |
| 243 | p_cnt = min(p_cnt, t_size); |
| 244 | |
| 245 | if (r_data->flags & MMC_DATA_WRITE) |
| 246 | tifm_sd_copy_page(host->bounce_buf.page, |
| 247 | r_data->blksz - t_size, |
| 248 | pg, p_off, p_cnt); |
| 249 | else if (r_data->flags & MMC_DATA_READ) |
| 250 | tifm_sd_copy_page(pg, p_off, host->bounce_buf.page, |
| 251 | r_data->blksz - t_size, p_cnt); |
| 252 | |
| 253 | t_size -= p_cnt; |
| 254 | host->block_pos += p_cnt; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | int tifm_sd_set_dma_data(struct tifm_sd *host, struct mmc_data *r_data) |
| 259 | { |
| 260 | struct tifm_dev *sock = host->dev; |
| 261 | unsigned int t_size = TIFM_DMA_TSIZE * r_data->blksz; |
| 262 | unsigned int dma_len, dma_blk_cnt, dma_off; |
| 263 | struct scatterlist *sg = NULL; |
| 264 | unsigned long flags; |
| 265 | |
| 266 | if (host->sg_pos == host->sg_len) |
| 267 | return 1; |
| 268 | |
| 269 | if (host->cmd_flags & DATA_CARRY) { |
| 270 | host->cmd_flags &= ~DATA_CARRY; |
| 271 | local_irq_save(flags); |
| 272 | tifm_sd_bounce_block(host, r_data); |
| 273 | local_irq_restore(flags); |
| 274 | if (host->sg_pos == host->sg_len) |
| 275 | return 1; |
| 276 | } |
| 277 | |
| 278 | dma_len = sg_dma_len(&r_data->sg[host->sg_pos]) - host->block_pos; |
| 279 | if (!dma_len) { |
| 280 | host->block_pos = 0; |
| 281 | host->sg_pos++; |
| 282 | if (host->sg_pos == host->sg_len) |
| 283 | return 1; |
| 284 | dma_len = sg_dma_len(&r_data->sg[host->sg_pos]); |
| 285 | } |
| 286 | |
| 287 | if (dma_len < t_size) { |
| 288 | dma_blk_cnt = dma_len / r_data->blksz; |
| 289 | dma_off = host->block_pos; |
| 290 | host->block_pos += dma_blk_cnt * r_data->blksz; |
| 291 | } else { |
| 292 | dma_blk_cnt = TIFM_DMA_TSIZE; |
| 293 | dma_off = host->block_pos; |
| 294 | host->block_pos += t_size; |
| 295 | } |
| 296 | |
| 297 | if (dma_blk_cnt) |
| 298 | sg = &r_data->sg[host->sg_pos]; |
| 299 | else if (dma_len) { |
| 300 | if (r_data->flags & MMC_DATA_WRITE) { |
| 301 | local_irq_save(flags); |
| 302 | tifm_sd_bounce_block(host, r_data); |
| 303 | local_irq_restore(flags); |
| 304 | } else |
| 305 | host->cmd_flags |= DATA_CARRY; |
| 306 | |
| 307 | sg = &host->bounce_buf; |
| 308 | dma_off = 0; |
| 309 | dma_blk_cnt = 1; |
| 310 | } else |
| 311 | return 1; |
| 312 | |
| 313 | dev_dbg(&sock->dev, "setting dma for %d blocks\n", dma_blk_cnt); |
| 314 | writel(sg_dma_address(sg) + dma_off, sock->addr + SOCK_DMA_ADDRESS); |
| 315 | if (r_data->flags & MMC_DATA_WRITE) |
| 316 | writel((dma_blk_cnt << 8) | TIFM_DMA_TX | TIFM_DMA_EN, |
| 317 | sock->addr + SOCK_DMA_CONTROL); |
| 318 | else |
| 319 | writel((dma_blk_cnt << 8) | TIFM_DMA_EN, |
| 320 | sock->addr + SOCK_DMA_CONTROL); |
| 321 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static unsigned int tifm_sd_op_flags(struct mmc_command *cmd) |
| 326 | { |
| 327 | unsigned int rc = 0; |
| 328 | |
| 329 | switch (mmc_resp_type(cmd)) { |
| 330 | case MMC_RSP_NONE: |
| 331 | rc |= TIFM_MMCSD_RSP_R0; |
| 332 | break; |
| 333 | case MMC_RSP_R1B: |
| 334 | rc |= TIFM_MMCSD_RSP_BUSY; // deliberate fall-through |
| 335 | case MMC_RSP_R1: |
| 336 | rc |= TIFM_MMCSD_RSP_R1; |
| 337 | break; |
| 338 | case MMC_RSP_R2: |
| 339 | rc |= TIFM_MMCSD_RSP_R2; |
| 340 | break; |
| 341 | case MMC_RSP_R3: |
| 342 | rc |= TIFM_MMCSD_RSP_R3; |
| 343 | break; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 344 | default: |
| 345 | BUG(); |
| 346 | } |
| 347 | |
| 348 | switch (mmc_cmd_type(cmd)) { |
| 349 | case MMC_CMD_BC: |
| 350 | rc |= TIFM_MMCSD_CMD_BC; |
| 351 | break; |
| 352 | case MMC_CMD_BCR: |
| 353 | rc |= TIFM_MMCSD_CMD_BCR; |
| 354 | break; |
| 355 | case MMC_CMD_AC: |
| 356 | rc |= TIFM_MMCSD_CMD_AC; |
| 357 | break; |
| 358 | case MMC_CMD_ADTC: |
| 359 | rc |= TIFM_MMCSD_CMD_ADTC; |
| 360 | break; |
| 361 | default: |
| 362 | BUG(); |
| 363 | } |
| 364 | return rc; |
| 365 | } |
| 366 | |
| 367 | static void tifm_sd_exec(struct tifm_sd *host, struct mmc_command *cmd) |
| 368 | { |
| 369 | struct tifm_dev *sock = host->dev; |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 370 | unsigned int cmd_mask = tifm_sd_op_flags(cmd); |
| 371 | |
| 372 | if (host->open_drain) |
| 373 | cmd_mask |= TIFM_MMCSD_ODTO; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 374 | |
| 375 | if (cmd->data && (cmd->data->flags & MMC_DATA_READ)) |
| 376 | cmd_mask |= TIFM_MMCSD_READ; |
| 377 | |
| 378 | dev_dbg(&sock->dev, "executing opcode 0x%x, arg: 0x%x, mask: 0x%x\n", |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 379 | cmd->opcode, cmd->arg, cmd_mask); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 380 | |
| 381 | writel((cmd->arg >> 16) & 0xffff, sock->addr + SOCK_MMCSD_ARG_HIGH); |
| 382 | writel(cmd->arg & 0xffff, sock->addr + SOCK_MMCSD_ARG_LOW); |
| 383 | writel(cmd->opcode | cmd_mask, sock->addr + SOCK_MMCSD_COMMAND); |
| 384 | } |
| 385 | |
| 386 | static void tifm_sd_fetch_resp(struct mmc_command *cmd, struct tifm_dev *sock) |
| 387 | { |
| 388 | cmd->resp[0] = (readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x1c) << 16) |
| 389 | | readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x18); |
| 390 | cmd->resp[1] = (readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x14) << 16) |
| 391 | | readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x10); |
| 392 | cmd->resp[2] = (readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x0c) << 16) |
| 393 | | readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x08); |
| 394 | cmd->resp[3] = (readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x04) << 16) |
| 395 | | readl(sock->addr + SOCK_MMCSD_RESPONSE + 0x00); |
| 396 | } |
| 397 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 398 | static void tifm_sd_check_status(struct tifm_sd *host) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 399 | { |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 400 | struct tifm_dev *sock = host->dev; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 401 | struct mmc_command *cmd = host->req->cmd; |
| 402 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 403 | if (cmd->error != MMC_ERR_NONE) |
| 404 | goto finish_request; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 405 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 406 | if (!(host->cmd_flags & CMD_READY)) |
| 407 | return; |
| 408 | |
| 409 | if (cmd->data) { |
| 410 | if (cmd->data->error != MMC_ERR_NONE) { |
| 411 | if ((host->cmd_flags & SCMD_ACTIVE) |
| 412 | && !(host->cmd_flags & SCMD_READY)) |
| 413 | return; |
| 414 | |
| 415 | goto finish_request; |
| 416 | } |
| 417 | |
| 418 | if (!(host->cmd_flags & BRS_READY)) |
| 419 | return; |
| 420 | |
| 421 | if (!(host->no_dma || (host->cmd_flags & FIFO_READY))) |
| 422 | return; |
| 423 | |
| 424 | if (cmd->data->flags & MMC_DATA_WRITE) { |
| 425 | if (host->req->stop) { |
| 426 | if (!(host->cmd_flags & SCMD_ACTIVE)) { |
| 427 | host->cmd_flags |= SCMD_ACTIVE; |
| 428 | writel(TIFM_MMCSD_EOFB |
| 429 | | readl(sock->addr |
| 430 | + SOCK_MMCSD_INT_ENABLE), |
| 431 | sock->addr |
| 432 | + SOCK_MMCSD_INT_ENABLE); |
| 433 | tifm_sd_exec(host, host->req->stop); |
| 434 | return; |
| 435 | } else { |
| 436 | if (!(host->cmd_flags & SCMD_READY) |
| 437 | || (host->cmd_flags & CARD_BUSY)) |
| 438 | return; |
| 439 | writel((~TIFM_MMCSD_EOFB) |
| 440 | & readl(sock->addr |
| 441 | + SOCK_MMCSD_INT_ENABLE), |
| 442 | sock->addr |
| 443 | + SOCK_MMCSD_INT_ENABLE); |
| 444 | } |
| 445 | } else { |
| 446 | if (host->cmd_flags & CARD_BUSY) |
| 447 | return; |
| 448 | writel((~TIFM_MMCSD_EOFB) |
| 449 | & readl(sock->addr |
| 450 | + SOCK_MMCSD_INT_ENABLE), |
| 451 | sock->addr + SOCK_MMCSD_INT_ENABLE); |
| 452 | } |
| 453 | } else { |
| 454 | if (host->req->stop) { |
| 455 | if (!(host->cmd_flags & SCMD_ACTIVE)) { |
| 456 | host->cmd_flags |= SCMD_ACTIVE; |
| 457 | tifm_sd_exec(host, host->req->stop); |
| 458 | return; |
| 459 | } else { |
| 460 | if (!(host->cmd_flags & SCMD_READY)) |
| 461 | return; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | finish_request: |
| 467 | tasklet_schedule(&host->finish_tasklet); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* Called from interrupt handler */ |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 471 | static void tifm_sd_data_event(struct tifm_dev *sock) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 472 | { |
| 473 | struct tifm_sd *host; |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 474 | unsigned int fifo_status = 0; |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 475 | struct mmc_data *r_data = NULL; |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 476 | |
| 477 | spin_lock(&sock->lock); |
| 478 | host = mmc_priv((struct mmc_host*)tifm_get_drvdata(sock)); |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 479 | fifo_status = readl(sock->addr + SOCK_DMA_FIFO_STATUS); |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 480 | dev_dbg(&sock->dev, "data event: fifo_status %x, flags %x\n", |
| 481 | fifo_status, host->cmd_flags); |
| 482 | |
| 483 | if (host->req) { |
| 484 | r_data = host->req->cmd->data; |
| 485 | |
| 486 | if (r_data && (fifo_status & TIFM_FIFO_READY)) { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 487 | if (tifm_sd_set_dma_data(host, r_data)) { |
| 488 | host->cmd_flags |= FIFO_READY; |
| 489 | tifm_sd_check_status(host); |
| 490 | } |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 494 | writel(fifo_status, sock->addr + SOCK_DMA_FIFO_STATUS); |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 495 | spin_unlock(&sock->lock); |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* Called from interrupt handler */ |
| 499 | static void tifm_sd_card_event(struct tifm_dev *sock) |
| 500 | { |
| 501 | struct tifm_sd *host; |
| 502 | unsigned int host_status = 0; |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 503 | int cmd_error = MMC_ERR_NONE; |
| 504 | struct mmc_command *cmd = NULL; |
| 505 | unsigned long flags; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 506 | |
| 507 | spin_lock(&sock->lock); |
| 508 | host = mmc_priv((struct mmc_host*)tifm_get_drvdata(sock)); |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 509 | host_status = readl(sock->addr + SOCK_MMCSD_STATUS); |
| 510 | dev_dbg(&sock->dev, "host event: host_status %x, flags %x\n", |
| 511 | host_status, host->cmd_flags); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 512 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 513 | if (host->req) { |
| 514 | cmd = host->req->cmd; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 515 | |
| 516 | if (host_status & TIFM_MMCSD_ERRMASK) { |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 517 | writel(host_status & TIFM_MMCSD_ERRMASK, |
| 518 | sock->addr + SOCK_MMCSD_STATUS); |
| 519 | if (host_status & TIFM_MMCSD_CTO) |
| 520 | cmd_error = MMC_ERR_TIMEOUT; |
| 521 | else if (host_status & TIFM_MMCSD_CCRC) |
| 522 | cmd_error = MMC_ERR_BADCRC; |
| 523 | |
| 524 | if (cmd->data) { |
| 525 | if (host_status & TIFM_MMCSD_DTO) |
| 526 | cmd->data->error = MMC_ERR_TIMEOUT; |
| 527 | else if (host_status & TIFM_MMCSD_DCRC) |
| 528 | cmd->data->error = MMC_ERR_BADCRC; |
| 529 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 530 | |
| 531 | writel(TIFM_FIFO_INT_SETALL, |
| 532 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); |
| 533 | writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL); |
| 534 | |
| 535 | if (host->req->stop) { |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 536 | if (host->cmd_flags & SCMD_ACTIVE) { |
| 537 | host->req->stop->error = cmd_error; |
| 538 | host->cmd_flags |= SCMD_READY; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 539 | } else { |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 540 | cmd->error = cmd_error; |
| 541 | host->cmd_flags |= SCMD_ACTIVE; |
| 542 | tifm_sd_exec(host, host->req->stop); |
| 543 | goto done; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 544 | } |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 545 | } else |
| 546 | cmd->error = cmd_error; |
| 547 | } else { |
| 548 | if (host_status & (TIFM_MMCSD_EOC | TIFM_MMCSD_CERR)) { |
| 549 | if (!(host->cmd_flags & CMD_READY)) { |
| 550 | host->cmd_flags |= CMD_READY; |
| 551 | tifm_sd_fetch_resp(cmd, sock); |
| 552 | } else if (host->cmd_flags & SCMD_ACTIVE) { |
| 553 | host->cmd_flags |= SCMD_READY; |
| 554 | tifm_sd_fetch_resp(host->req->stop, |
| 555 | sock); |
| 556 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 557 | } |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 558 | if (host_status & TIFM_MMCSD_BRS) |
| 559 | host->cmd_flags |= BRS_READY; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 562 | if (host->no_dma && cmd->data) { |
| 563 | if (host_status & TIFM_MMCSD_AE) |
| 564 | writel(host_status & TIFM_MMCSD_AE, |
| 565 | sock->addr + SOCK_MMCSD_STATUS); |
| 566 | |
| 567 | if (host_status & (TIFM_MMCSD_AE | TIFM_MMCSD_AF |
| 568 | | TIFM_MMCSD_BRS)) { |
| 569 | local_irq_save(flags); |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 570 | tifm_sd_transfer_data(host); |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 571 | local_irq_restore(flags); |
| 572 | host_status &= ~TIFM_MMCSD_AE; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (host_status & TIFM_MMCSD_EOFB) |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 577 | host->cmd_flags &= ~CARD_BUSY; |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 578 | else if (host_status & TIFM_MMCSD_CB) |
| 579 | host->cmd_flags |= CARD_BUSY; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 580 | |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 581 | tifm_sd_check_status(host); |
| 582 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 583 | done: |
Alex Dubov | 72dc9d9 | 2007-04-12 17:05:23 +1000 | [diff] [blame] | 584 | writel(host_status, sock->addr + SOCK_MMCSD_STATUS); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 585 | spin_unlock(&sock->lock); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 588 | static void tifm_sd_set_data_timeout(struct tifm_sd *host, |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 589 | struct mmc_data *data) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 590 | { |
| 591 | struct tifm_dev *sock = host->dev; |
| 592 | unsigned int data_timeout = data->timeout_clks; |
| 593 | |
| 594 | if (fixed_timeout) |
| 595 | return; |
| 596 | |
| 597 | data_timeout += data->timeout_ns / |
Alex Dubov | 83d420b | 2006-12-08 16:50:50 +1100 | [diff] [blame] | 598 | ((1000000000UL / host->clk_freq) * host->clk_div); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 599 | |
| 600 | if (data_timeout < 0xffff) { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 601 | writel(data_timeout, sock->addr + SOCK_MMCSD_DATA_TO); |
Alex Dubov | 83d420b | 2006-12-08 16:50:50 +1100 | [diff] [blame] | 602 | writel((~TIFM_MMCSD_DPE) |
| 603 | & readl(sock->addr + SOCK_MMCSD_SDIO_MODE_CONFIG), |
| 604 | sock->addr + SOCK_MMCSD_SDIO_MODE_CONFIG); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 605 | } else { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 606 | data_timeout = (data_timeout >> 10) + 1; |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 607 | if (data_timeout > 0xffff) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 608 | data_timeout = 0; /* set to unlimited */ |
| 609 | writel(data_timeout, sock->addr + SOCK_MMCSD_DATA_TO); |
Alex Dubov | 83d420b | 2006-12-08 16:50:50 +1100 | [diff] [blame] | 610 | writel(TIFM_MMCSD_DPE |
| 611 | | readl(sock->addr + SOCK_MMCSD_SDIO_MODE_CONFIG), |
| 612 | sock->addr + SOCK_MMCSD_SDIO_MODE_CONFIG); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 617 | { |
| 618 | struct tifm_sd *host = mmc_priv(mmc); |
| 619 | struct tifm_dev *sock = host->dev; |
| 620 | unsigned long flags; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 621 | struct mmc_data *r_data = mrq->cmd->data; |
| 622 | |
| 623 | spin_lock_irqsave(&sock->lock, flags); |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 624 | if (host->eject) { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 625 | spin_unlock_irqrestore(&sock->lock, flags); |
| 626 | goto err_out; |
| 627 | } |
| 628 | |
| 629 | if (host->req) { |
| 630 | printk(KERN_ERR DRIVER_NAME ": unfinished request detected\n"); |
| 631 | spin_unlock_irqrestore(&sock->lock, flags); |
| 632 | goto err_out; |
| 633 | } |
| 634 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 635 | host->cmd_flags = 0; |
| 636 | host->block_pos = 0; |
| 637 | host->sg_pos = 0; |
| 638 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 639 | if (r_data) { |
| 640 | tifm_sd_set_data_timeout(host, r_data); |
| 641 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 642 | if ((r_data->flags & MMC_DATA_WRITE) && !mrq->stop) |
| 643 | writel(TIFM_MMCSD_EOFB |
| 644 | | readl(sock->addr + SOCK_MMCSD_INT_ENABLE), |
| 645 | sock->addr + SOCK_MMCSD_INT_ENABLE); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 646 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 647 | if (host->no_dma) { |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 648 | writel(TIFM_MMCSD_BUFINT |
| 649 | | readl(sock->addr + SOCK_MMCSD_INT_ENABLE), |
| 650 | sock->addr + SOCK_MMCSD_INT_ENABLE); |
| 651 | writel(((TIFM_MMCSD_FIFO_SIZE - 1) << 8) |
| 652 | | (TIFM_MMCSD_FIFO_SIZE - 1), |
| 653 | sock->addr + SOCK_MMCSD_BUFFER_CONFIG); |
| 654 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 655 | host->sg_len = r_data->sg_len; |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 656 | } else { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 657 | sg_init_one(&host->bounce_buf, host->bounce_buf_data, |
| 658 | r_data->blksz); |
| 659 | |
| 660 | if(1 != tifm_map_sg(sock, &host->bounce_buf, 1, |
| 661 | r_data->flags & MMC_DATA_WRITE |
| 662 | ? PCI_DMA_TODEVICE |
| 663 | : PCI_DMA_FROMDEVICE)) { |
| 664 | printk(KERN_ERR "%s : scatterlist map failed\n", |
| 665 | sock->dev.bus_id); |
| 666 | spin_unlock_irqrestore(&sock->lock, flags); |
| 667 | goto err_out; |
| 668 | } |
| 669 | host->sg_len = tifm_map_sg(sock, r_data->sg, |
| 670 | r_data->sg_len, |
| 671 | r_data->flags |
| 672 | & MMC_DATA_WRITE |
| 673 | ? PCI_DMA_TODEVICE |
| 674 | : PCI_DMA_FROMDEVICE); |
| 675 | if (host->sg_len < 1) { |
| 676 | printk(KERN_ERR "%s : scatterlist map failed\n", |
| 677 | sock->dev.bus_id); |
| 678 | tifm_unmap_sg(sock, &host->bounce_buf, 1, |
| 679 | r_data->flags & MMC_DATA_WRITE |
| 680 | ? PCI_DMA_TODEVICE |
| 681 | : PCI_DMA_FROMDEVICE); |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 682 | spin_unlock_irqrestore(&sock->lock, flags); |
| 683 | goto err_out; |
| 684 | } |
| 685 | |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 686 | writel(TIFM_FIFO_INT_SETALL, |
| 687 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); |
| 688 | writel(ilog2(r_data->blksz) - 2, |
| 689 | sock->addr + SOCK_FIFO_PAGE_SIZE); |
| 690 | writel(TIFM_FIFO_ENABLE, |
| 691 | sock->addr + SOCK_FIFO_CONTROL); |
| 692 | writel(TIFM_FIFO_INTMASK, |
| 693 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET); |
| 694 | |
| 695 | if (r_data->flags & MMC_DATA_WRITE) |
| 696 | writel(TIFM_MMCSD_TXDE, |
| 697 | sock->addr + SOCK_MMCSD_BUFFER_CONFIG); |
| 698 | else |
| 699 | writel(TIFM_MMCSD_RXDE, |
| 700 | sock->addr + SOCK_MMCSD_BUFFER_CONFIG); |
| 701 | |
| 702 | tifm_sd_set_dma_data(host, r_data); |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 703 | } |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 704 | |
| 705 | writel(r_data->blocks - 1, |
| 706 | sock->addr + SOCK_MMCSD_NUM_BLOCKS); |
| 707 | writel(r_data->blksz - 1, |
| 708 | sock->addr + SOCK_MMCSD_BLOCK_LEN); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | host->req = mrq; |
Alex Dubov | 0803dd0 | 2006-12-08 16:50:49 +1100 | [diff] [blame] | 712 | mod_timer(&host->timer, jiffies + host->timeout_jiffies); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 713 | writel(TIFM_CTRL_LED | readl(sock->addr + SOCK_CONTROL), |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 714 | sock->addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 715 | tifm_sd_exec(host, mrq->cmd); |
| 716 | spin_unlock_irqrestore(&sock->lock, flags); |
| 717 | return; |
| 718 | |
| 719 | err_out: |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 720 | mrq->cmd->error = MMC_ERR_TIMEOUT; |
| 721 | mmc_request_done(mmc, mrq); |
| 722 | } |
| 723 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 724 | static void tifm_sd_end_cmd(unsigned long data) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 725 | { |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 726 | struct tifm_sd *host = (struct tifm_sd*)data; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 727 | struct tifm_dev *sock = host->dev; |
| 728 | struct mmc_host *mmc = tifm_get_drvdata(sock); |
| 729 | struct mmc_request *mrq; |
Al Viro | e069d79 | 2006-10-09 20:29:43 +0100 | [diff] [blame] | 730 | struct mmc_data *r_data = NULL; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 731 | unsigned long flags; |
| 732 | |
| 733 | spin_lock_irqsave(&sock->lock, flags); |
| 734 | |
Alex Dubov | 0803dd0 | 2006-12-08 16:50:49 +1100 | [diff] [blame] | 735 | del_timer(&host->timer); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 736 | mrq = host->req; |
Al Viro | e069d79 | 2006-10-09 20:29:43 +0100 | [diff] [blame] | 737 | host->req = NULL; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 738 | |
| 739 | if (!mrq) { |
| 740 | printk(KERN_ERR DRIVER_NAME ": no request to complete?\n"); |
| 741 | spin_unlock_irqrestore(&sock->lock, flags); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | r_data = mrq->cmd->data; |
| 746 | if (r_data) { |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 747 | if (host->no_dma) { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 748 | writel((~TIFM_MMCSD_BUFINT) |
| 749 | & readl(sock->addr + SOCK_MMCSD_INT_ENABLE), |
| 750 | sock->addr + SOCK_MMCSD_INT_ENABLE); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 751 | } else { |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 752 | tifm_unmap_sg(sock, &host->bounce_buf, 1, |
| 753 | (r_data->flags & MMC_DATA_WRITE) |
| 754 | ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 755 | tifm_unmap_sg(sock, r_data->sg, r_data->sg_len, |
| 756 | (r_data->flags & MMC_DATA_WRITE) |
| 757 | ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 758 | } |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 759 | |
| 760 | r_data->bytes_xfered = r_data->blocks |
| 761 | - readl(sock->addr + SOCK_MMCSD_NUM_BLOCKS) - 1; |
| 762 | r_data->bytes_xfered *= r_data->blksz; |
| 763 | r_data->bytes_xfered += r_data->blksz |
| 764 | - readl(sock->addr + SOCK_MMCSD_BLOCK_LEN) + 1; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | writel((~TIFM_CTRL_LED) & readl(sock->addr + SOCK_CONTROL), |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 768 | sock->addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 769 | |
| 770 | spin_unlock_irqrestore(&sock->lock, flags); |
| 771 | mmc_request_done(mmc, mrq); |
| 772 | } |
| 773 | |
Alex Dubov | 0803dd0 | 2006-12-08 16:50:49 +1100 | [diff] [blame] | 774 | static void tifm_sd_abort(unsigned long data) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 775 | { |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 776 | struct tifm_sd *host = (struct tifm_sd*)data; |
| 777 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 778 | printk(KERN_ERR DRIVER_NAME |
Alex Dubov | b039d4a | 2007-04-12 16:59:21 +1000 | [diff] [blame] | 779 | ": card failed to respond for a long period of time\n"); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 780 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 781 | tifm_eject(host->dev); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static void tifm_sd_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 785 | { |
| 786 | struct tifm_sd *host = mmc_priv(mmc); |
| 787 | struct tifm_dev *sock = host->dev; |
| 788 | unsigned int clk_div1, clk_div2; |
| 789 | unsigned long flags; |
| 790 | |
| 791 | spin_lock_irqsave(&sock->lock, flags); |
| 792 | |
| 793 | dev_dbg(&sock->dev, "Setting bus width %d, power %d\n", ios->bus_width, |
| 794 | ios->power_mode); |
| 795 | if (ios->bus_width == MMC_BUS_WIDTH_4) { |
| 796 | writel(TIFM_MMCSD_4BBUS | readl(sock->addr + SOCK_MMCSD_CONFIG), |
| 797 | sock->addr + SOCK_MMCSD_CONFIG); |
| 798 | } else { |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 799 | writel((~TIFM_MMCSD_4BBUS) |
| 800 | & readl(sock->addr + SOCK_MMCSD_CONFIG), |
| 801 | sock->addr + SOCK_MMCSD_CONFIG); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | if (ios->clock) { |
| 805 | clk_div1 = 20000000 / ios->clock; |
| 806 | if (!clk_div1) |
| 807 | clk_div1 = 1; |
| 808 | |
| 809 | clk_div2 = 24000000 / ios->clock; |
| 810 | if (!clk_div2) |
| 811 | clk_div2 = 1; |
| 812 | |
| 813 | if ((20000000 / clk_div1) > ios->clock) |
| 814 | clk_div1++; |
| 815 | if ((24000000 / clk_div2) > ios->clock) |
| 816 | clk_div2++; |
| 817 | if ((20000000 / clk_div1) > (24000000 / clk_div2)) { |
| 818 | host->clk_freq = 20000000; |
| 819 | host->clk_div = clk_div1; |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 820 | writel((~TIFM_CTRL_FAST_CLK) |
| 821 | & readl(sock->addr + SOCK_CONTROL), |
| 822 | sock->addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 823 | } else { |
| 824 | host->clk_freq = 24000000; |
| 825 | host->clk_div = clk_div2; |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 826 | writel(TIFM_CTRL_FAST_CLK |
| 827 | | readl(sock->addr + SOCK_CONTROL), |
| 828 | sock->addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 829 | } |
| 830 | } else { |
| 831 | host->clk_div = 0; |
| 832 | } |
| 833 | host->clk_div &= TIFM_MMCSD_CLKMASK; |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 834 | writel(host->clk_div |
| 835 | | ((~TIFM_MMCSD_CLKMASK) |
| 836 | & readl(sock->addr + SOCK_MMCSD_CONFIG)), |
| 837 | sock->addr + SOCK_MMCSD_CONFIG); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 838 | |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 839 | host->open_drain = (ios->bus_mode == MMC_BUSMODE_OPENDRAIN); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 840 | |
| 841 | /* chip_select : maybe later */ |
| 842 | //vdd |
| 843 | //power is set before probe / after remove |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 844 | |
| 845 | spin_unlock_irqrestore(&sock->lock, flags); |
| 846 | } |
| 847 | |
| 848 | static int tifm_sd_ro(struct mmc_host *mmc) |
| 849 | { |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 850 | int rc = 0; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 851 | struct tifm_sd *host = mmc_priv(mmc); |
| 852 | struct tifm_dev *sock = host->dev; |
| 853 | unsigned long flags; |
| 854 | |
| 855 | spin_lock_irqsave(&sock->lock, flags); |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 856 | if (TIFM_MMCSD_CARD_RO & readl(sock->addr + SOCK_PRESENT_STATE)) |
| 857 | rc = 1; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 858 | spin_unlock_irqrestore(&sock->lock, flags); |
| 859 | return rc; |
| 860 | } |
| 861 | |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 862 | static const struct mmc_host_ops tifm_sd_ops = { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 863 | .request = tifm_sd_request, |
| 864 | .set_ios = tifm_sd_ios, |
| 865 | .get_ro = tifm_sd_ro |
| 866 | }; |
| 867 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 868 | static int tifm_sd_initialize_host(struct tifm_sd *host) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 869 | { |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 870 | int rc; |
| 871 | unsigned int host_status = 0; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 872 | struct tifm_dev *sock = host->dev; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 873 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 874 | writel(0, sock->addr + SOCK_MMCSD_INT_ENABLE); |
| 875 | mmiowb(); |
| 876 | host->clk_div = 61; |
| 877 | host->clk_freq = 20000000; |
| 878 | writel(TIFM_MMCSD_RESET, sock->addr + SOCK_MMCSD_SYSTEM_CONTROL); |
| 879 | writel(host->clk_div | TIFM_MMCSD_POWER, |
| 880 | sock->addr + SOCK_MMCSD_CONFIG); |
| 881 | |
| 882 | /* wait up to 0.51 sec for reset */ |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 883 | for (rc = 32; rc <= 256; rc <<= 1) { |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 884 | if (1 & readl(sock->addr + SOCK_MMCSD_SYSTEM_STATUS)) { |
| 885 | rc = 0; |
| 886 | break; |
| 887 | } |
| 888 | msleep(rc); |
| 889 | } |
| 890 | |
| 891 | if (rc) { |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 892 | printk(KERN_ERR "%s : controller failed to reset\n", |
| 893 | sock->dev.bus_id); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 894 | return -ENODEV; |
| 895 | } |
| 896 | |
| 897 | writel(0, sock->addr + SOCK_MMCSD_NUM_BLOCKS); |
| 898 | writel(host->clk_div | TIFM_MMCSD_POWER, |
| 899 | sock->addr + SOCK_MMCSD_CONFIG); |
| 900 | writel(TIFM_MMCSD_RXDE, sock->addr + SOCK_MMCSD_BUFFER_CONFIG); |
| 901 | |
| 902 | // command timeout fixed to 64 clocks for now |
| 903 | writel(64, sock->addr + SOCK_MMCSD_COMMAND_TO); |
| 904 | writel(TIFM_MMCSD_INAB, sock->addr + SOCK_MMCSD_COMMAND); |
| 905 | |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 906 | for (rc = 16; rc <= 64; rc <<= 1) { |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 907 | host_status = readl(sock->addr + SOCK_MMCSD_STATUS); |
| 908 | writel(host_status, sock->addr + SOCK_MMCSD_STATUS); |
| 909 | if (!(host_status & TIFM_MMCSD_ERRMASK) |
| 910 | && (host_status & TIFM_MMCSD_EOC)) { |
| 911 | rc = 0; |
| 912 | break; |
| 913 | } |
| 914 | msleep(rc); |
| 915 | } |
| 916 | |
| 917 | if (rc) { |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 918 | printk(KERN_ERR |
| 919 | "%s : card not ready - probe failed on initialization\n", |
| 920 | sock->dev.bus_id); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 921 | return -ENODEV; |
| 922 | } |
| 923 | |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 924 | writel(TIFM_MMCSD_CERR | TIFM_MMCSD_BRS | TIFM_MMCSD_EOC |
| 925 | | TIFM_MMCSD_ERRMASK, |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 926 | sock->addr + SOCK_MMCSD_INT_ENABLE); |
| 927 | mmiowb(); |
| 928 | |
| 929 | return 0; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | static int tifm_sd_probe(struct tifm_dev *sock) |
| 933 | { |
| 934 | struct mmc_host *mmc; |
| 935 | struct tifm_sd *host; |
| 936 | int rc = -EIO; |
| 937 | |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 938 | if (!(TIFM_SOCK_STATE_OCCUPIED |
| 939 | & readl(sock->addr + SOCK_PRESENT_STATE))) { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 940 | printk(KERN_WARNING DRIVER_NAME ": card gone, unexpectedly\n"); |
| 941 | return rc; |
| 942 | } |
| 943 | |
| 944 | mmc = mmc_alloc_host(sizeof(struct tifm_sd), &sock->dev); |
| 945 | if (!mmc) |
| 946 | return -ENOMEM; |
| 947 | |
| 948 | host = mmc_priv(mmc); |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 949 | host->no_dma = no_dma; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 950 | tifm_set_drvdata(sock, mmc); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 951 | host->dev = sock; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 952 | host->timeout_jiffies = msecs_to_jiffies(1000); |
| 953 | |
Alex Dubov | dfef26d | 2007-04-12 16:59:24 +1000 | [diff] [blame] | 954 | tasklet_init(&host->finish_tasklet, tifm_sd_end_cmd, |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 955 | (unsigned long)host); |
| 956 | setup_timer(&host->timer, tifm_sd_abort, (unsigned long)host); |
| 957 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 958 | mmc->ops = &tifm_sd_ops; |
| 959 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 960 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 961 | mmc->f_min = 20000000 / 60; |
| 962 | mmc->f_max = 24000000; |
Alex Dubov | 13cdf48 | 2007-04-12 17:05:25 +1000 | [diff] [blame^] | 963 | |
| 964 | mmc->max_blk_count = 2048; |
| 965 | mmc->max_hw_segs = mmc->max_blk_count; |
| 966 | mmc->max_blk_size = min(TIFM_MMCSD_MAX_BLOCK_SIZE, PAGE_SIZE); |
| 967 | mmc->max_seg_size = mmc->max_blk_count * mmc->max_blk_size; |
| 968 | mmc->max_req_size = mmc->max_seg_size; |
| 969 | mmc->max_phys_segs = mmc->max_hw_segs; |
| 970 | |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 971 | sock->card_event = tifm_sd_card_event; |
| 972 | sock->data_event = tifm_sd_data_event; |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 973 | rc = tifm_sd_initialize_host(host); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 974 | |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 975 | if (!rc) |
| 976 | rc = mmc_add_host(mmc); |
| 977 | if (rc) |
| 978 | goto out_free_mmc; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 979 | |
| 980 | return 0; |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 981 | out_free_mmc: |
| 982 | mmc_free_host(mmc); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 983 | return rc; |
| 984 | } |
| 985 | |
| 986 | static void tifm_sd_remove(struct tifm_dev *sock) |
| 987 | { |
| 988 | struct mmc_host *mmc = tifm_get_drvdata(sock); |
| 989 | struct tifm_sd *host = mmc_priv(mmc); |
Alex Dubov | b039d4a | 2007-04-12 16:59:21 +1000 | [diff] [blame] | 990 | unsigned long flags; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 991 | |
Alex Dubov | b039d4a | 2007-04-12 16:59:21 +1000 | [diff] [blame] | 992 | spin_lock_irqsave(&sock->lock, flags); |
Alex Dubov | 0007d48 | 2007-04-12 16:59:23 +1000 | [diff] [blame] | 993 | host->eject = 1; |
Alex Dubov | 592d372 | 2007-04-12 16:59:22 +1000 | [diff] [blame] | 994 | writel(0, sock->addr + SOCK_MMCSD_INT_ENABLE); |
| 995 | mmiowb(); |
| 996 | spin_unlock_irqrestore(&sock->lock, flags); |
| 997 | |
| 998 | tasklet_kill(&host->finish_tasklet); |
| 999 | |
| 1000 | spin_lock_irqsave(&sock->lock, flags); |
Alex Dubov | b039d4a | 2007-04-12 16:59:21 +1000 | [diff] [blame] | 1001 | if (host->req) { |
| 1002 | writel(TIFM_FIFO_INT_SETALL, |
| 1003 | sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); |
| 1004 | writel(0, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET); |
Alex Dubov | 592d372 | 2007-04-12 16:59:22 +1000 | [diff] [blame] | 1005 | host->req->cmd->error = MMC_ERR_TIMEOUT; |
| 1006 | if (host->req->stop) |
| 1007 | host->req->stop->error = MMC_ERR_TIMEOUT; |
Alex Dubov | b039d4a | 2007-04-12 16:59:21 +1000 | [diff] [blame] | 1008 | tasklet_schedule(&host->finish_tasklet); |
| 1009 | } |
| 1010 | spin_unlock_irqrestore(&sock->lock, flags); |
Alex Dubov | 8e02f85 | 2006-12-08 16:50:51 +1100 | [diff] [blame] | 1011 | mmc_remove_host(mmc); |
Alex Dubov | 592d372 | 2007-04-12 16:59:22 +1000 | [diff] [blame] | 1012 | dev_dbg(&sock->dev, "after remove\n"); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1013 | |
| 1014 | /* The meaning of the bit majority in this constant is unknown. */ |
| 1015 | writel(0xfff8 & readl(sock->addr + SOCK_CONTROL), |
Alex Dubov | 2e8ce5e | 2006-12-08 16:50:52 +1100 | [diff] [blame] | 1016 | sock->addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1017 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1018 | mmc_free_host(mmc); |
| 1019 | } |
| 1020 | |
Alex Dubov | dba4acc | 2006-12-11 01:55:38 +1100 | [diff] [blame] | 1021 | #ifdef CONFIG_PM |
| 1022 | |
| 1023 | static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state) |
| 1024 | { |
| 1025 | struct mmc_host *mmc = tifm_get_drvdata(sock); |
| 1026 | int rc; |
| 1027 | |
| 1028 | rc = mmc_suspend_host(mmc, state); |
| 1029 | /* The meaning of the bit majority in this constant is unknown. */ |
| 1030 | writel(0xfff8 & readl(sock->addr + SOCK_CONTROL), |
| 1031 | sock->addr + SOCK_CONTROL); |
| 1032 | return rc; |
| 1033 | } |
| 1034 | |
| 1035 | static int tifm_sd_resume(struct tifm_dev *sock) |
| 1036 | { |
| 1037 | struct mmc_host *mmc = tifm_get_drvdata(sock); |
| 1038 | struct tifm_sd *host = mmc_priv(mmc); |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 1039 | int rc; |
Alex Dubov | dba4acc | 2006-12-11 01:55:38 +1100 | [diff] [blame] | 1040 | |
Alex Dubov | 5897d65 | 2007-04-12 17:05:24 +1000 | [diff] [blame] | 1041 | rc = tifm_sd_initialize_host(host); |
| 1042 | dev_dbg(&sock->dev, "resume initialize %d\n", rc); |
| 1043 | |
| 1044 | if (rc) |
| 1045 | host->eject = 1; |
| 1046 | else |
| 1047 | rc = mmc_resume_host(mmc); |
| 1048 | |
| 1049 | return rc; |
Alex Dubov | dba4acc | 2006-12-11 01:55:38 +1100 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | #else |
| 1053 | |
| 1054 | #define tifm_sd_suspend NULL |
| 1055 | #define tifm_sd_resume NULL |
| 1056 | |
| 1057 | #endif /* CONFIG_PM */ |
| 1058 | |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 1059 | static struct tifm_device_id tifm_sd_id_tbl[] = { |
| 1060 | { TIFM_TYPE_SD }, { } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1061 | }; |
| 1062 | |
| 1063 | static struct tifm_driver tifm_sd_driver = { |
| 1064 | .driver = { |
| 1065 | .name = DRIVER_NAME, |
| 1066 | .owner = THIS_MODULE |
| 1067 | }, |
| 1068 | .id_table = tifm_sd_id_tbl, |
| 1069 | .probe = tifm_sd_probe, |
Alex Dubov | dba4acc | 2006-12-11 01:55:38 +1100 | [diff] [blame] | 1070 | .remove = tifm_sd_remove, |
| 1071 | .suspend = tifm_sd_suspend, |
| 1072 | .resume = tifm_sd_resume |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1073 | }; |
| 1074 | |
| 1075 | static int __init tifm_sd_init(void) |
| 1076 | { |
| 1077 | return tifm_register_driver(&tifm_sd_driver); |
| 1078 | } |
| 1079 | |
| 1080 | static void __exit tifm_sd_exit(void) |
| 1081 | { |
| 1082 | tifm_unregister_driver(&tifm_sd_driver); |
| 1083 | } |
| 1084 | |
| 1085 | MODULE_AUTHOR("Alex Dubov"); |
| 1086 | MODULE_DESCRIPTION("TI FlashMedia SD driver"); |
| 1087 | MODULE_LICENSE("GPL"); |
| 1088 | MODULE_DEVICE_TABLE(tifm, tifm_sd_id_tbl); |
| 1089 | MODULE_VERSION(DRIVER_VERSION); |
| 1090 | |
| 1091 | module_init(tifm_sd_init); |
| 1092 | module_exit(tifm_sd_exit); |