2 * jmb38x_ms.c - JMicron jmb38x MemoryStick card reader
4 * Copyright (C) 2008 Alex Dubov <oakad@yahoo.com>
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.
12 #include <linux/spinlock.h>
13 #include <linux/interrupt.h>
14 #include <linux/pci.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/delay.h>
17 #include <linux/highmem.h>
18 #include <linux/memstick.h>
20 #define DRIVER_NAME "jmb38x_ms"
23 module_param(no_dma, bool, 0644);
36 INT_STATUS_ENABLE = 0x28,
37 INT_SIGNAL_ENABLE = 0x2c,
40 PAD_OUTPUT_ENABLE = 0x38,
49 struct jmb38x_ms_host {
50 struct jmb38x_ms *chip;
53 struct tasklet_struct notify;
57 unsigned int block_pos;
58 unsigned long timeout_jiffies;
59 struct timer_list timer;
60 struct memstick_request *req;
61 unsigned char cmd_flags;
63 unsigned int io_word[2];
69 struct memstick_host *hosts[];
72 #define BLOCK_COUNT_MASK 0xffff0000
73 #define BLOCK_SIZE_MASK 0x00000fff
75 #define DMA_CONTROL_ENABLE 0x00000001
77 #define TPC_DATA_SEL 0x00008000
78 #define TPC_DIR 0x00004000
79 #define TPC_WAIT_INT 0x00002000
80 #define TPC_GET_INT 0x00000800
81 #define TPC_CODE_SZ_MASK 0x00000700
82 #define TPC_DATA_SZ_MASK 0x00000007
84 #define HOST_CONTROL_RESET_REQ 0x00008000
85 #define HOST_CONTROL_REI 0x00004000
86 #define HOST_CONTROL_LED 0x00000400
87 #define HOST_CONTROL_FAST_CLK 0x00000200
88 #define HOST_CONTROL_RESET 0x00000100
89 #define HOST_CONTROL_POWER_EN 0x00000080
90 #define HOST_CONTROL_CLOCK_EN 0x00000040
91 #define HOST_CONTROL_IF_SHIFT 4
93 #define HOST_CONTROL_IF_SERIAL 0x0
94 #define HOST_CONTROL_IF_PAR4 0x1
95 #define HOST_CONTROL_IF_PAR8 0x3
97 #define STATUS_BUSY 0x00080000
98 #define STATUS_MS_DAT7 0x00040000
99 #define STATUS_MS_DAT6 0x00020000
100 #define STATUS_MS_DAT5 0x00010000
101 #define STATUS_MS_DAT4 0x00008000
102 #define STATUS_MS_DAT3 0x00004000
103 #define STATUS_MS_DAT2 0x00002000
104 #define STATUS_MS_DAT1 0x00001000
105 #define STATUS_MS_DAT0 0x00000800
106 #define STATUS_HAS_MEDIA 0x00000400
107 #define STATUS_FIFO_EMPTY 0x00000200
108 #define STATUS_FIFO_FULL 0x00000100
109 #define STATUS_MS_CED 0x00000080
110 #define STATUS_MS_ERR 0x00000040
111 #define STATUS_MS_BRQ 0x00000020
112 #define STATUS_MS_CNK 0x00000001
114 #define INT_STATUS_TPC_ERR 0x00080000
115 #define INT_STATUS_CRC_ERR 0x00040000
116 #define INT_STATUS_TIMER_TO 0x00020000
117 #define INT_STATUS_HSK_TO 0x00010000
118 #define INT_STATUS_ANY_ERR 0x00008000
119 #define INT_STATUS_FIFO_WRDY 0x00000080
120 #define INT_STATUS_FIFO_RRDY 0x00000040
121 #define INT_STATUS_MEDIA_OUT 0x00000010
122 #define INT_STATUS_MEDIA_IN 0x00000008
123 #define INT_STATUS_DMA_BOUNDARY 0x00000004
124 #define INT_STATUS_EOTRAN 0x00000002
125 #define INT_STATUS_EOTPC 0x00000001
127 #define INT_STATUS_ALL 0x000f801f
129 #define PAD_OUTPUT_ENABLE_MS 0x0F3F
131 #define PAD_PU_PD_OFF 0x7FFF0000
132 #define PAD_PU_PD_ON_MS_SOCK0 0x5f8f0000
133 #define PAD_PU_PD_ON_MS_SOCK1 0x0f0f0000
135 #define CLOCK_CONTROL_40MHZ 0x00000001
136 #define CLOCK_CONTROL_50MHZ 0x00000002
137 #define CLOCK_CONTROL_60MHZ 0x00000008
138 #define CLOCK_CONTROL_62_5MHZ 0x0000000c
139 #define CLOCK_CONTROL_OFF 0x00000000
148 static unsigned int jmb38x_ms_read_data(struct jmb38x_ms_host *host,
149 unsigned char *buf, unsigned int length)
151 unsigned int off = 0;
153 while (host->io_pos && length) {
154 buf[off++] = host->io_word[0] & 0xff;
155 host->io_word[0] >>= 8;
163 while (!(STATUS_FIFO_EMPTY & readl(host->addr + STATUS))) {
166 *(unsigned int *)(buf + off) = __raw_readl(host->addr + DATA);
172 && !(STATUS_FIFO_EMPTY & readl(host->addr + STATUS))) {
173 host->io_word[0] = readl(host->addr + DATA);
174 for (host->io_pos = 4; host->io_pos; --host->io_pos) {
175 buf[off++] = host->io_word[0] & 0xff;
176 host->io_word[0] >>= 8;
186 static unsigned int jmb38x_ms_read_reg_data(struct jmb38x_ms_host *host,
190 unsigned int off = 0;
192 while (host->io_pos > 4 && length) {
193 buf[off++] = host->io_word[0] & 0xff;
194 host->io_word[0] >>= 8;
202 while (host->io_pos && length) {
203 buf[off++] = host->io_word[1] & 0xff;
204 host->io_word[1] >>= 8;
212 static unsigned int jmb38x_ms_write_data(struct jmb38x_ms_host *host,
216 unsigned int off = 0;
219 while (host->io_pos < 4 && length) {
220 host->io_word[0] |= buf[off++] << (host->io_pos * 8);
226 if (host->io_pos == 4
227 && !(STATUS_FIFO_FULL & readl(host->addr + STATUS))) {
228 writel(host->io_word[0], host->addr + DATA);
230 host->io_word[0] = 0;
231 } else if (host->io_pos) {
238 while (!(STATUS_FIFO_FULL & readl(host->addr + STATUS))) {
242 __raw_writel(*(unsigned int *)(buf + off),
250 host->io_word[0] |= buf[off + 2] << 16;
253 host->io_word[0] |= buf[off + 1] << 8;
256 host->io_word[0] |= buf[off];
265 static unsigned int jmb38x_ms_write_reg_data(struct jmb38x_ms_host *host,
269 unsigned int off = 0;
271 while (host->io_pos < 4 && length) {
272 host->io_word[0] &= ~(0xff << (host->io_pos * 8));
273 host->io_word[0] |= buf[off++] << (host->io_pos * 8);
281 while (host->io_pos < 8 && length) {
282 host->io_word[1] &= ~(0xff << (host->io_pos * 8));
283 host->io_word[1] |= buf[off++] << (host->io_pos * 8);
291 static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host)
295 unsigned int t_size, p_cnt;
298 unsigned long flags = 0;
300 if (host->req->long_data) {
301 length = host->req->sg.length - host->block_pos;
302 off = host->req->sg.offset + host->block_pos;
304 length = host->req->data_len - host->block_pos;
309 unsigned int uninitialized_var(p_off);
311 if (host->req->long_data) {
312 pg = nth_page(sg_page(&host->req->sg),
314 p_off = offset_in_page(off);
315 p_cnt = PAGE_SIZE - p_off;
316 p_cnt = min(p_cnt, length);
318 local_irq_save(flags);
319 buf = kmap_atomic(pg, KM_BIO_SRC_IRQ) + p_off;
321 buf = host->req->data + host->block_pos;
322 p_cnt = host->req->data_len - host->block_pos;
325 if (host->req->data_dir == WRITE)
326 t_size = !(host->cmd_flags & REG_DATA)
327 ? jmb38x_ms_write_data(host, buf, p_cnt)
328 : jmb38x_ms_write_reg_data(host, buf, p_cnt);
330 t_size = !(host->cmd_flags & REG_DATA)
331 ? jmb38x_ms_read_data(host, buf, p_cnt)
332 : jmb38x_ms_read_reg_data(host, buf, p_cnt);
334 if (host->req->long_data) {
335 kunmap_atomic(buf - p_off, KM_BIO_SRC_IRQ);
336 local_irq_restore(flags);
341 host->block_pos += t_size;
346 if (!length && host->req->data_dir == WRITE) {
347 if (host->cmd_flags & REG_DATA) {
348 writel(host->io_word[0], host->addr + TPC_P0);
349 writel(host->io_word[1], host->addr + TPC_P1);
350 } else if (host->io_pos) {
351 writel(host->io_word[0], host->addr + DATA);
358 static int jmb38x_ms_issue_cmd(struct memstick_host *msh)
360 struct jmb38x_ms_host *host = memstick_priv(msh);
362 unsigned int data_len, cmd, t_val;
364 if (!(STATUS_HAS_MEDIA & readl(host->addr + STATUS))) {
365 dev_dbg(&msh->dev, "no media status\n");
366 host->req->error = -ETIME;
367 return host->req->error;
370 dev_dbg(&msh->dev, "control %08x\n",
371 readl(host->addr + HOST_CONTROL));
372 dev_dbg(&msh->dev, "status %08x\n", readl(host->addr + INT_STATUS));
373 dev_dbg(&msh->dev, "hstatus %08x\n", readl(host->addr + STATUS));
378 host->io_word[0] = 0;
379 host->io_word[1] = 0;
381 cmd = host->req->tpc << 16;
384 if (host->req->data_dir == READ)
386 if (host->req->need_card_int)
389 data = host->req->data;
392 host->cmd_flags |= DMA_DATA;
394 if (host->req->long_data) {
395 data_len = host->req->sg.length;
397 data_len = host->req->data_len;
398 host->cmd_flags &= ~DMA_DATA;
402 cmd &= ~(TPC_DATA_SEL | 0xf);
403 host->cmd_flags |= REG_DATA;
404 cmd |= data_len & 0xf;
405 host->cmd_flags &= ~DMA_DATA;
408 if (host->cmd_flags & DMA_DATA) {
409 if (1 != pci_map_sg(host->chip->pdev, &host->req->sg, 1,
410 host->req->data_dir == READ
412 : PCI_DMA_TODEVICE)) {
413 host->req->error = -ENOMEM;
414 return host->req->error;
416 data_len = sg_dma_len(&host->req->sg);
417 writel(sg_dma_address(&host->req->sg),
418 host->addr + DMA_ADDRESS);
419 writel(((1 << 16) & BLOCK_COUNT_MASK)
420 | (data_len & BLOCK_SIZE_MASK),
422 writel(DMA_CONTROL_ENABLE, host->addr + DMA_CONTROL);
423 } else if (!(host->cmd_flags & REG_DATA)) {
424 writel(((1 << 16) & BLOCK_COUNT_MASK)
425 | (data_len & BLOCK_SIZE_MASK),
427 t_val = readl(host->addr + INT_STATUS_ENABLE);
428 t_val |= host->req->data_dir == READ
429 ? INT_STATUS_FIFO_RRDY
430 : INT_STATUS_FIFO_WRDY;
432 writel(t_val, host->addr + INT_STATUS_ENABLE);
433 writel(t_val, host->addr + INT_SIGNAL_ENABLE);
435 cmd &= ~(TPC_DATA_SEL | 0xf);
436 host->cmd_flags |= REG_DATA;
437 cmd |= data_len & 0xf;
439 if (host->req->data_dir == WRITE) {
440 jmb38x_ms_transfer_data(host);
441 writel(host->io_word[0], host->addr + TPC_P0);
442 writel(host->io_word[1], host->addr + TPC_P1);
446 mod_timer(&host->timer, jiffies + host->timeout_jiffies);
447 writel(HOST_CONTROL_LED | readl(host->addr + HOST_CONTROL),
448 host->addr + HOST_CONTROL);
449 host->req->error = 0;
451 writel(cmd, host->addr + TPC);
452 dev_dbg(&msh->dev, "executing TPC %08x, len %x\n", cmd, data_len);
457 static void jmb38x_ms_complete_cmd(struct memstick_host *msh, int last)
459 struct jmb38x_ms_host *host = memstick_priv(msh);
460 unsigned int t_val = 0;
463 del_timer(&host->timer);
465 dev_dbg(&msh->dev, "c control %08x\n",
466 readl(host->addr + HOST_CONTROL));
467 dev_dbg(&msh->dev, "c status %08x\n",
468 readl(host->addr + INT_STATUS));
469 dev_dbg(&msh->dev, "c hstatus %08x\n", readl(host->addr + STATUS));
471 host->req->int_reg = readl(host->addr + STATUS) & 0xff;
473 writel(0, host->addr + BLOCK);
474 writel(0, host->addr + DMA_CONTROL);
476 if (host->cmd_flags & DMA_DATA) {
477 pci_unmap_sg(host->chip->pdev, &host->req->sg, 1,
478 host->req->data_dir == READ
479 ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
481 t_val = readl(host->addr + INT_STATUS_ENABLE);
482 if (host->req->data_dir == READ)
483 t_val &= ~INT_STATUS_FIFO_RRDY;
485 t_val &= ~INT_STATUS_FIFO_WRDY;
487 writel(t_val, host->addr + INT_STATUS_ENABLE);
488 writel(t_val, host->addr + INT_SIGNAL_ENABLE);
491 writel((~HOST_CONTROL_LED) & readl(host->addr + HOST_CONTROL),
492 host->addr + HOST_CONTROL);
496 rc = memstick_next_req(msh, &host->req);
497 } while (!rc && jmb38x_ms_issue_cmd(msh));
500 rc = memstick_next_req(msh, &host->req);
502 host->req->error = -ETIME;
507 static irqreturn_t jmb38x_ms_isr(int irq, void *dev_id)
509 struct memstick_host *msh = dev_id;
510 struct jmb38x_ms_host *host = memstick_priv(msh);
511 unsigned int irq_status;
513 spin_lock(&host->lock);
514 irq_status = readl(host->addr + INT_STATUS);
515 dev_dbg(&host->chip->pdev->dev, "irq_status = %08x\n", irq_status);
516 if (irq_status == 0 || irq_status == (~0)) {
517 spin_unlock(&host->lock);
522 if (irq_status & INT_STATUS_ANY_ERR) {
523 if (irq_status & INT_STATUS_CRC_ERR)
524 host->req->error = -EILSEQ;
526 host->req->error = -ETIME;
528 if (host->cmd_flags & DMA_DATA) {
529 if (irq_status & INT_STATUS_EOTRAN)
530 host->cmd_flags |= FIFO_READY;
532 if (irq_status & (INT_STATUS_FIFO_RRDY
533 | INT_STATUS_FIFO_WRDY))
534 jmb38x_ms_transfer_data(host);
536 if (irq_status & INT_STATUS_EOTRAN) {
537 jmb38x_ms_transfer_data(host);
538 host->cmd_flags |= FIFO_READY;
542 if (irq_status & INT_STATUS_EOTPC) {
543 host->cmd_flags |= CMD_READY;
544 if (host->cmd_flags & REG_DATA) {
545 if (host->req->data_dir == READ) {
554 jmb38x_ms_transfer_data(host);
556 host->cmd_flags |= FIFO_READY;
562 if (irq_status & (INT_STATUS_MEDIA_IN | INT_STATUS_MEDIA_OUT)) {
563 dev_dbg(&host->chip->pdev->dev, "media changed\n");
564 memstick_detect_change(msh);
567 writel(irq_status, host->addr + INT_STATUS);
570 && (((host->cmd_flags & CMD_READY)
571 && (host->cmd_flags & FIFO_READY))
572 || host->req->error))
573 jmb38x_ms_complete_cmd(msh, 0);
575 spin_unlock(&host->lock);
579 static void jmb38x_ms_abort(unsigned long data)
581 struct memstick_host *msh = (struct memstick_host *)data;
582 struct jmb38x_ms_host *host = memstick_priv(msh);
585 dev_dbg(&host->chip->pdev->dev, "abort\n");
586 spin_lock_irqsave(&host->lock, flags);
588 host->req->error = -ETIME;
589 jmb38x_ms_complete_cmd(msh, 0);
591 spin_unlock_irqrestore(&host->lock, flags);
594 static void jmb38x_ms_req_tasklet(unsigned long data)
596 struct memstick_host *msh = (struct memstick_host *)data;
597 struct jmb38x_ms_host *host = memstick_priv(msh);
601 spin_lock_irqsave(&host->lock, flags);
604 rc = memstick_next_req(msh, &host->req);
605 dev_dbg(&host->chip->pdev->dev, "tasklet req %d\n", rc);
606 } while (!rc && jmb38x_ms_issue_cmd(msh));
608 spin_unlock_irqrestore(&host->lock, flags);
611 static void jmb38x_ms_dummy_submit(struct memstick_host *msh)
616 static void jmb38x_ms_submit_req(struct memstick_host *msh)
618 struct jmb38x_ms_host *host = memstick_priv(msh);
620 tasklet_schedule(&host->notify);
623 static int jmb38x_ms_reset(struct jmb38x_ms_host *host)
627 writel(HOST_CONTROL_RESET_REQ | HOST_CONTROL_CLOCK_EN
628 | readl(host->addr + HOST_CONTROL),
629 host->addr + HOST_CONTROL);
632 for (cnt = 0; cnt < 20; ++cnt) {
633 if (!(HOST_CONTROL_RESET_REQ
634 & readl(host->addr + HOST_CONTROL)))
639 dev_dbg(&host->chip->pdev->dev, "reset_req timeout\n");
643 writel(HOST_CONTROL_RESET | HOST_CONTROL_CLOCK_EN
644 | readl(host->addr + HOST_CONTROL),
645 host->addr + HOST_CONTROL);
648 for (cnt = 0; cnt < 20; ++cnt) {
649 if (!(HOST_CONTROL_RESET
650 & readl(host->addr + HOST_CONTROL)))
655 dev_dbg(&host->chip->pdev->dev, "reset timeout\n");
660 writel(INT_STATUS_ALL, host->addr + INT_SIGNAL_ENABLE);
661 writel(INT_STATUS_ALL, host->addr + INT_STATUS_ENABLE);
665 static int jmb38x_ms_set_param(struct memstick_host *msh,
666 enum memstick_param param,
669 struct jmb38x_ms_host *host = memstick_priv(msh);
670 unsigned int host_ctl = readl(host->addr + HOST_CONTROL);
671 unsigned int clock_ctl = CLOCK_CONTROL_40MHZ, clock_delay = 0;
676 if (value == MEMSTICK_POWER_ON) {
677 rc = jmb38x_ms_reset(host);
682 host_ctl |= HOST_CONTROL_POWER_EN
683 | HOST_CONTROL_CLOCK_EN;
684 writel(host_ctl, host->addr + HOST_CONTROL);
686 writel(host->id ? PAD_PU_PD_ON_MS_SOCK1
687 : PAD_PU_PD_ON_MS_SOCK0,
688 host->addr + PAD_PU_PD);
690 writel(PAD_OUTPUT_ENABLE_MS,
691 host->addr + PAD_OUTPUT_ENABLE);
694 dev_dbg(&host->chip->pdev->dev, "power on\n");
695 } else if (value == MEMSTICK_POWER_OFF) {
696 host_ctl &= ~(HOST_CONTROL_POWER_EN
697 | HOST_CONTROL_CLOCK_EN);
698 writel(host_ctl, host->addr + HOST_CONTROL);
699 writel(0, host->addr + PAD_OUTPUT_ENABLE);
700 writel(PAD_PU_PD_OFF, host->addr + PAD_PU_PD);
701 dev_dbg(&host->chip->pdev->dev, "power off\n");
705 case MEMSTICK_INTERFACE:
706 host_ctl &= ~(3 << HOST_CONTROL_IF_SHIFT);
708 if (value == MEMSTICK_SERIAL) {
709 host_ctl &= ~HOST_CONTROL_FAST_CLK;
710 host_ctl |= HOST_CONTROL_IF_SERIAL
711 << HOST_CONTROL_IF_SHIFT;
712 host_ctl |= HOST_CONTROL_REI;
713 clock_ctl = CLOCK_CONTROL_40MHZ;
715 } else if (value == MEMSTICK_PAR4) {
716 host_ctl |= HOST_CONTROL_FAST_CLK;
717 host_ctl |= HOST_CONTROL_IF_PAR4
718 << HOST_CONTROL_IF_SHIFT;
719 host_ctl &= ~HOST_CONTROL_REI;
720 clock_ctl = CLOCK_CONTROL_40MHZ;
722 } else if (value == MEMSTICK_PAR8) {
723 host_ctl |= HOST_CONTROL_FAST_CLK;
724 host_ctl |= HOST_CONTROL_IF_PAR8
725 << HOST_CONTROL_IF_SHIFT;
726 host_ctl &= ~HOST_CONTROL_REI;
727 clock_ctl = CLOCK_CONTROL_60MHZ;
731 writel(host_ctl, host->addr + HOST_CONTROL);
732 writel(clock_ctl, host->addr + CLOCK_CONTROL);
733 writel(clock_delay, host->addr + CLOCK_DELAY);
741 static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
743 struct jmb38x_ms *jm = pci_get_drvdata(dev);
746 for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
749 memstick_suspend_host(jm->hosts[cnt]);
753 pci_enable_wake(dev, pci_choose_state(dev, state), 0);
754 pci_disable_device(dev);
755 pci_set_power_state(dev, pci_choose_state(dev, state));
759 static int jmb38x_ms_resume(struct pci_dev *dev)
761 struct jmb38x_ms *jm = pci_get_drvdata(dev);
764 pci_set_power_state(dev, PCI_D0);
765 pci_restore_state(dev);
766 rc = pci_enable_device(dev);
771 pci_read_config_dword(dev, 0xac, &rc);
772 pci_write_config_dword(dev, 0xac, rc | 0x00470000);
774 for (rc = 0; rc < jm->host_cnt; ++rc) {
777 memstick_resume_host(jm->hosts[rc]);
778 memstick_detect_change(jm->hosts[rc]);
786 #define jmb38x_ms_suspend NULL
787 #define jmb38x_ms_resume NULL
789 #endif /* CONFIG_PM */
791 static int jmb38x_ms_count_slots(struct pci_dev *pdev)
795 for (cnt = 0; cnt < PCI_ROM_RESOURCE; ++cnt) {
796 if (!(IORESOURCE_MEM & pci_resource_flags(pdev, cnt)))
799 if (256 != pci_resource_len(pdev, cnt))
807 static struct memstick_host *jmb38x_ms_alloc_host(struct jmb38x_ms *jm, int cnt)
809 struct memstick_host *msh;
810 struct jmb38x_ms_host *host;
812 msh = memstick_alloc_host(sizeof(struct jmb38x_ms_host),
817 host = memstick_priv(msh);
819 host->addr = ioremap(pci_resource_start(jm->pdev, cnt),
820 pci_resource_len(jm->pdev, cnt));
824 spin_lock_init(&host->lock);
826 snprintf(host->host_id, sizeof(host->host_id), DRIVER_NAME ":slot%d",
828 host->irq = jm->pdev->irq;
829 host->timeout_jiffies = msecs_to_jiffies(1000);
831 tasklet_init(&host->notify, jmb38x_ms_req_tasklet, (unsigned long)msh);
832 msh->request = jmb38x_ms_submit_req;
833 msh->set_param = jmb38x_ms_set_param;
835 msh->caps = MEMSTICK_CAP_PAR4 | MEMSTICK_CAP_PAR8;
837 setup_timer(&host->timer, jmb38x_ms_abort, (unsigned long)msh);
839 if (!request_irq(host->irq, jmb38x_ms_isr, IRQF_SHARED, host->host_id,
849 static void jmb38x_ms_free_host(struct memstick_host *msh)
851 struct jmb38x_ms_host *host = memstick_priv(msh);
853 free_irq(host->irq, msh);
855 memstick_free_host(msh);
858 static int jmb38x_ms_probe(struct pci_dev *pdev,
859 const struct pci_device_id *dev_id)
861 struct jmb38x_ms *jm;
862 int pci_dev_busy = 0;
865 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
869 rc = pci_enable_device(pdev);
873 pci_set_master(pdev);
875 rc = pci_request_regions(pdev, DRIVER_NAME);
881 pci_read_config_dword(pdev, 0xac, &rc);
882 pci_write_config_dword(pdev, 0xac, rc | 0x00470000);
884 cnt = jmb38x_ms_count_slots(pdev);
891 jm = kzalloc(sizeof(struct jmb38x_ms)
892 + cnt * sizeof(struct memstick_host *), GFP_KERNEL);
900 pci_set_drvdata(pdev, jm);
902 for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
903 jm->hosts[cnt] = jmb38x_ms_alloc_host(jm, cnt);
907 rc = memstick_add_host(jm->hosts[cnt]);
910 jmb38x_ms_free_host(jm->hosts[cnt]);
911 jm->hosts[cnt] = NULL;
921 pci_set_drvdata(pdev, NULL);
924 pci_release_regions(pdev);
927 pci_disable_device(pdev);
931 static void jmb38x_ms_remove(struct pci_dev *dev)
933 struct jmb38x_ms *jm = pci_get_drvdata(dev);
934 struct jmb38x_ms_host *host;
938 for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
942 host = memstick_priv(jm->hosts[cnt]);
944 jm->hosts[cnt]->request = jmb38x_ms_dummy_submit;
945 tasklet_kill(&host->notify);
946 writel(0, host->addr + INT_SIGNAL_ENABLE);
947 writel(0, host->addr + INT_STATUS_ENABLE);
949 dev_dbg(&jm->pdev->dev, "interrupts off\n");
950 spin_lock_irqsave(&host->lock, flags);
952 host->req->error = -ETIME;
953 jmb38x_ms_complete_cmd(jm->hosts[cnt], 1);
955 spin_unlock_irqrestore(&host->lock, flags);
957 memstick_remove_host(jm->hosts[cnt]);
958 dev_dbg(&jm->pdev->dev, "host removed\n");
960 jmb38x_ms_free_host(jm->hosts[cnt]);
963 pci_set_drvdata(dev, NULL);
964 pci_release_regions(dev);
965 pci_disable_device(dev);
969 static struct pci_device_id jmb38x_ms_id_tbl [] = {
970 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_MS, PCI_ANY_ID,
971 PCI_ANY_ID, 0, 0, 0 },
975 static struct pci_driver jmb38x_ms_driver = {
977 .id_table = jmb38x_ms_id_tbl,
978 .probe = jmb38x_ms_probe,
979 .remove = jmb38x_ms_remove,
980 .suspend = jmb38x_ms_suspend,
981 .resume = jmb38x_ms_resume
984 static int __init jmb38x_ms_init(void)
986 return pci_register_driver(&jmb38x_ms_driver);
989 static void __exit jmb38x_ms_exit(void)
991 pci_unregister_driver(&jmb38x_ms_driver);
994 MODULE_AUTHOR("Alex Dubov");
995 MODULE_DESCRIPTION("JMicron jmb38x MemoryStick driver");
996 MODULE_LICENSE("GPL");
997 MODULE_DEVICE_TABLE(pci, jmb38x_ms_id_tbl);
999 module_init(jmb38x_ms_init);
1000 module_exit(jmb38x_ms_exit);