20 #include <linux/module.h>
23 #define DRIVER_NAME "tifm_ms"
33 #define TIFM_MS_STAT_DRQ 0x04000
34 #define TIFM_MS_STAT_MSINT 0x02000
35 #define TIFM_MS_STAT_RDY 0x01000
36 #define TIFM_MS_STAT_CRC 0x00200
37 #define TIFM_MS_STAT_TOE 0x00100
38 #define TIFM_MS_STAT_EMP 0x00020
39 #define TIFM_MS_STAT_FUL 0x00010
40 #define TIFM_MS_STAT_CED 0x00008
41 #define TIFM_MS_STAT_ERR 0x00004
42 #define TIFM_MS_STAT_BRQ 0x00002
43 #define TIFM_MS_STAT_CNK 0x00001
45 #define TIFM_MS_SYS_DMA 0x10000
46 #define TIFM_MS_SYS_RESET 0x08000
47 #define TIFM_MS_SYS_SRAC 0x04000
48 #define TIFM_MS_SYS_INTEN 0x02000
49 #define TIFM_MS_SYS_NOCRC 0x01000
50 #define TIFM_MS_SYS_INTCLR 0x00800
51 #define TIFM_MS_SYS_MSIEN 0x00400
52 #define TIFM_MS_SYS_FCLR 0x00200
53 #define TIFM_MS_SYS_FDIR 0x00100
54 #define TIFM_MS_SYS_DAM 0x00080
55 #define TIFM_MS_SYS_DRM 0x00040
56 #define TIFM_MS_SYS_DRQSL 0x00020
57 #define TIFM_MS_SYS_REI 0x00010
58 #define TIFM_MS_SYS_REO 0x00008
59 #define TIFM_MS_SYS_BSY_MASK 0x00007
61 #define TIFM_MS_SYS_FIFO (TIFM_MS_SYS_INTEN | TIFM_MS_SYS_MSIEN \
62 | TIFM_MS_SYS_FCLR | TIFM_MS_SYS_BSY_MASK)
86 static unsigned int tifm_ms_read_data(
struct tifm_ms *
host,
92 while (host->
io_pos && length) {
93 buf[off++] = host->
io_word & 0xff;
115 buf[off++] = host->
io_word & 0xff;
126 static unsigned int tifm_ms_write_data(
struct tifm_ms *host,
127 unsigned char *buf,
unsigned int length)
130 unsigned int off = 0;
133 while (host->
io_pos < 4 && length) {
147 }
else if (host->
io_pos) {
167 host->
io_word |= buf[off + 2] << 16;
170 host->
io_word |= buf[off + 1] << 8;
182 static unsigned int tifm_ms_transfer_data(
struct tifm_ms *host)
187 unsigned int t_size, p_cnt;
190 unsigned long flags = 0;
192 if (host->
req->long_data) {
199 dev_dbg(&sock->
dev,
"fifo data transfer, %d, %d\n", length,
205 if (host->
req->long_data) {
206 pg = nth_page(sg_page(&host->
req->sg),
210 p_cnt =
min(p_cnt, length);
219 t_size = host->
req->data_dir ==
WRITE
220 ? tifm_ms_write_data(host, buf, p_cnt)
221 : tifm_ms_read_data(host, buf, p_cnt);
223 if (host->
req->long_data) {
235 dev_dbg(&sock->
dev,
"fifo data transfer, %d remaining\n", length);
236 if (!length && (host->
req->data_dir ==
WRITE)) {
254 static int tifm_ms_issue_cmd(
struct tifm_ms *host)
266 data = host->
req->data;
270 if (host->
req->long_data) {
271 data_len = host->
req->sg.length;
275 data_len = host->
req->data_len;
290 return host->
req->error;
319 host->
req->error = 0;
331 cmd = (host->
req->tpc & 0xf) << 12;
335 dev_dbg(&sock->
dev,
"executing TPC %x, %x\n", cmd, sys_param);
339 static void tifm_ms_complete_cmd(
struct tifm_ms *host)
348 host->
req->int_reg = (host->
req->int_reg & 1)
349 | ((host->
req->int_reg << 4) & 0xe0);
368 }
while (!rc && tifm_ms_issue_cmd(host));
371 static int tifm_ms_check_status(
struct tifm_ms *host)
373 if (!host->
req->error) {
378 if (host->
req->need_card_int
386 static void tifm_ms_data_event(
struct tifm_dev *sock)
392 spin_lock(&sock->
lock);
393 host = memstick_priv((
struct memstick_host *)tifm_get_drvdata(sock));
397 "data event: fifo_status %x, host_status %x, flags %x\n",
401 if (host->
use_dma && (fifo_status & 1)) {
403 rc = tifm_ms_check_status(host);
406 if (!tifm_ms_transfer_data(host)) {
408 rc = tifm_ms_check_status(host);
415 tifm_ms_complete_cmd(host);
417 spin_unlock(&sock->
lock);
422 static void tifm_ms_card_event(
struct tifm_dev *sock)
428 spin_lock(&sock->
lock);
429 host = memstick_priv((
struct memstick_host *)tifm_get_drvdata(sock));
431 dev_dbg(&sock->
dev,
"host event: host_status %x, flags %x\n",
446 rc = tifm_ms_check_status(host);
454 tifm_ms_complete_cmd(host);
456 spin_unlock(&sock->
lock);
460 static void tifm_ms_req_tasklet(
unsigned long data)
463 struct tifm_ms *host = memstick_priv(msh);
476 spin_unlock_irqrestore(&sock->
lock, flags);
482 }
while (!rc && tifm_ms_issue_cmd(host));
484 spin_unlock_irqrestore(&sock->
lock, flags);
494 struct tifm_ms *host = memstick_priv(msh);
496 tasklet_schedule(&host->
notify);
503 struct tifm_ms *host = memstick_priv(msh);
541 static void tifm_ms_abort(
unsigned long data)
548 "%s : card failed to respond for a long period of time "
550 dev_name(&host->
dev->dev), host->
req ? host->
req->tpc : 0,
556 static int tifm_ms_probe(
struct tifm_dev *sock)
565 dev_name(&sock->
dev));
573 host = memstick_priv(msh);
574 tifm_set_drvdata(sock, msh);
581 msh->
request = tifm_ms_submit_req;
596 static void tifm_ms_remove(
struct tifm_dev *sock)
599 struct tifm_ms *host = memstick_priv(msh);
603 msh->
request = tifm_ms_dummy_submit;
625 spin_unlock_irqrestore(&sock->
lock, flags);
651 #define tifm_ms_suspend NULL
652 #define tifm_ms_resume NULL
665 .id_table = tifm_ms_id_tbl,
666 .probe = tifm_ms_probe,
667 .remove = tifm_ms_remove,
672 static int __init tifm_ms_init(
void)
677 static void __exit tifm_ms_exit(
void)