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