[PATCH] cond_resched_lock() fix
[linux-2.6.git] / drivers / mmc / wbsd.c
blobb7fbd30b49a0de18d1b05cf30bcfe62c0f64efac
1 /*
2 * linux/drivers/mmc/wbsd.c - Winbond W83L51xD SD/MMC driver
4 * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved.
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.
11 * Warning!
13 * Changes to the FIFO system should be done with extreme care since
14 * the hardware is full of bugs related to the FIFO. Known issues are:
16 * - FIFO size field in FSR is always zero.
18 * - FIFO interrupts tend not to work as they should. Interrupts are
19 * triggered only for full/empty events, not for threshold values.
21 * - On APIC systems the FIFO empty interrupt is sometimes lost.
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
29 #include <linux/device.h>
30 #include <linux/interrupt.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/delay.h>
33 #include <linux/pnp.h>
34 #include <linux/highmem.h>
35 #include <linux/mmc/host.h>
36 #include <linux/mmc/protocol.h>
38 #include <asm/io.h>
39 #include <asm/dma.h>
40 #include <asm/scatterlist.h>
42 #include "wbsd.h"
44 #define DRIVER_NAME "wbsd"
45 #define DRIVER_VERSION "1.2"
47 #ifdef CONFIG_MMC_DEBUG
48 #define DBG(x...) \
49 printk(KERN_DEBUG DRIVER_NAME ": " x)
50 #define DBGF(f, x...) \
51 printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__ , ##x)
52 #else
53 #define DBG(x...) do { } while (0)
54 #define DBGF(x...) do { } while (0)
55 #endif
57 #ifdef CONFIG_MMC_DEBUG
58 void DBG_REG(int reg, u8 value)
60 int i;
62 printk(KERN_DEBUG "wbsd: Register %d: 0x%02X %3d '%c' ",
63 reg, (int)value, (int)value, (value < 0x20)?'.':value);
65 for (i = 7;i >= 0;i--)
67 if (value & (1 << i))
68 printk("x");
69 else
70 printk(".");
73 printk("\n");
75 #else
76 #define DBG_REG(r, v) do {} while (0)
77 #endif
80 * Device resources
83 #ifdef CONFIG_PNP
85 static const struct pnp_device_id pnp_dev_table[] = {
86 { "WEC0517", 0 },
87 { "WEC0518", 0 },
88 { "", 0 },
91 MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
93 #endif /* CONFIG_PNP */
95 #ifdef CONFIG_PNP
96 static unsigned int nopnp = 0;
97 #else
98 static const unsigned int nopnp = 1;
99 #endif
100 static unsigned int io = 0x248;
101 static unsigned int irq = 6;
102 static int dma = 2;
105 * Basic functions
108 static inline void wbsd_unlock_config(struct wbsd_host* host)
110 BUG_ON(host->config == 0);
112 outb(host->unlock_code, host->config);
113 outb(host->unlock_code, host->config);
116 static inline void wbsd_lock_config(struct wbsd_host* host)
118 BUG_ON(host->config == 0);
120 outb(LOCK_CODE, host->config);
123 static inline void wbsd_write_config(struct wbsd_host* host, u8 reg, u8 value)
125 BUG_ON(host->config == 0);
127 outb(reg, host->config);
128 outb(value, host->config + 1);
131 static inline u8 wbsd_read_config(struct wbsd_host* host, u8 reg)
133 BUG_ON(host->config == 0);
135 outb(reg, host->config);
136 return inb(host->config + 1);
139 static inline void wbsd_write_index(struct wbsd_host* host, u8 index, u8 value)
141 outb(index, host->base + WBSD_IDXR);
142 outb(value, host->base + WBSD_DATAR);
145 static inline u8 wbsd_read_index(struct wbsd_host* host, u8 index)
147 outb(index, host->base + WBSD_IDXR);
148 return inb(host->base + WBSD_DATAR);
152 * Common routines
155 static void wbsd_init_device(struct wbsd_host* host)
157 u8 setup, ier;
160 * Reset chip (SD/MMC part) and fifo.
162 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
163 setup |= WBSD_FIFO_RESET | WBSD_SOFT_RESET;
164 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
167 * Set DAT3 to input
169 setup &= ~WBSD_DAT3_H;
170 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
171 host->flags &= ~WBSD_FIGNORE_DETECT;
174 * Read back default clock.
176 host->clk = wbsd_read_index(host, WBSD_IDX_CLK);
179 * Power down port.
181 outb(WBSD_POWER_N, host->base + WBSD_CSR);
184 * Set maximum timeout.
186 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F);
189 * Test for card presence
191 if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT)
192 host->flags |= WBSD_FCARD_PRESENT;
193 else
194 host->flags &= ~WBSD_FCARD_PRESENT;
197 * Enable interesting interrupts.
199 ier = 0;
200 ier |= WBSD_EINT_CARD;
201 ier |= WBSD_EINT_FIFO_THRE;
202 ier |= WBSD_EINT_CCRC;
203 ier |= WBSD_EINT_TIMEOUT;
204 ier |= WBSD_EINT_CRC;
205 ier |= WBSD_EINT_TC;
207 outb(ier, host->base + WBSD_EIR);
210 * Clear interrupts.
212 inb(host->base + WBSD_ISR);
215 static void wbsd_reset(struct wbsd_host* host)
217 u8 setup;
219 printk(KERN_ERR DRIVER_NAME ": Resetting chip\n");
222 * Soft reset of chip (SD/MMC part).
224 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
225 setup |= WBSD_SOFT_RESET;
226 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
229 static void wbsd_request_end(struct wbsd_host* host, struct mmc_request* mrq)
231 unsigned long dmaflags;
233 DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode);
235 if (host->dma >= 0)
238 * Release ISA DMA controller.
240 dmaflags = claim_dma_lock();
241 disable_dma(host->dma);
242 clear_dma_ff(host->dma);
243 release_dma_lock(dmaflags);
246 * Disable DMA on host.
248 wbsd_write_index(host, WBSD_IDX_DMA, 0);
251 host->mrq = NULL;
254 * MMC layer might call back into the driver so first unlock.
256 spin_unlock(&host->lock);
257 mmc_request_done(host->mmc, mrq);
258 spin_lock(&host->lock);
262 * Scatter/gather functions
265 static inline void wbsd_init_sg(struct wbsd_host* host, struct mmc_data* data)
268 * Get info. about SG list from data structure.
270 host->cur_sg = data->sg;
271 host->num_sg = data->sg_len;
273 host->offset = 0;
274 host->remain = host->cur_sg->length;
277 static inline int wbsd_next_sg(struct wbsd_host* host)
280 * Skip to next SG entry.
282 host->cur_sg++;
283 host->num_sg--;
286 * Any entries left?
288 if (host->num_sg > 0)
290 host->offset = 0;
291 host->remain = host->cur_sg->length;
294 return host->num_sg;
297 static inline char* wbsd_kmap_sg(struct wbsd_host* host)
299 host->mapped_sg = kmap_atomic(host->cur_sg->page, KM_BIO_SRC_IRQ) +
300 host->cur_sg->offset;
301 return host->mapped_sg;
304 static inline void wbsd_kunmap_sg(struct wbsd_host* host)
306 kunmap_atomic(host->mapped_sg, KM_BIO_SRC_IRQ);
309 static inline void wbsd_sg_to_dma(struct wbsd_host* host, struct mmc_data* data)
311 unsigned int len, i, size;
312 struct scatterlist* sg;
313 char* dmabuf = host->dma_buffer;
314 char* sgbuf;
316 size = host->size;
318 sg = data->sg;
319 len = data->sg_len;
322 * Just loop through all entries. Size might not
323 * be the entire list though so make sure that
324 * we do not transfer too much.
326 for (i = 0;i < len;i++)
328 sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset;
329 if (size < sg[i].length)
330 memcpy(dmabuf, sgbuf, size);
331 else
332 memcpy(dmabuf, sgbuf, sg[i].length);
333 kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ);
334 dmabuf += sg[i].length;
336 if (size < sg[i].length)
337 size = 0;
338 else
339 size -= sg[i].length;
341 if (size == 0)
342 break;
346 * Check that we didn't get a request to transfer
347 * more data than can fit into the SG list.
350 BUG_ON(size != 0);
352 host->size -= size;
355 static inline void wbsd_dma_to_sg(struct wbsd_host* host, struct mmc_data* data)
357 unsigned int len, i, size;
358 struct scatterlist* sg;
359 char* dmabuf = host->dma_buffer;
360 char* sgbuf;
362 size = host->size;
364 sg = data->sg;
365 len = data->sg_len;
368 * Just loop through all entries. Size might not
369 * be the entire list though so make sure that
370 * we do not transfer too much.
372 for (i = 0;i < len;i++)
374 sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset;
375 if (size < sg[i].length)
376 memcpy(sgbuf, dmabuf, size);
377 else
378 memcpy(sgbuf, dmabuf, sg[i].length);
379 kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ);
380 dmabuf += sg[i].length;
382 if (size < sg[i].length)
383 size = 0;
384 else
385 size -= sg[i].length;
387 if (size == 0)
388 break;
392 * Check that we didn't get a request to transfer
393 * more data than can fit into the SG list.
396 BUG_ON(size != 0);
398 host->size -= size;
402 * Command handling
405 static inline void wbsd_get_short_reply(struct wbsd_host* host,
406 struct mmc_command* cmd)
409 * Correct response type?
411 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT)
413 cmd->error = MMC_ERR_INVALID;
414 return;
417 cmd->resp[0] =
418 wbsd_read_index(host, WBSD_IDX_RESP12) << 24;
419 cmd->resp[0] |=
420 wbsd_read_index(host, WBSD_IDX_RESP13) << 16;
421 cmd->resp[0] |=
422 wbsd_read_index(host, WBSD_IDX_RESP14) << 8;
423 cmd->resp[0] |=
424 wbsd_read_index(host, WBSD_IDX_RESP15) << 0;
425 cmd->resp[1] =
426 wbsd_read_index(host, WBSD_IDX_RESP16) << 24;
429 static inline void wbsd_get_long_reply(struct wbsd_host* host,
430 struct mmc_command* cmd)
432 int i;
435 * Correct response type?
437 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG)
439 cmd->error = MMC_ERR_INVALID;
440 return;
443 for (i = 0;i < 4;i++)
445 cmd->resp[i] =
446 wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24;
447 cmd->resp[i] |=
448 wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16;
449 cmd->resp[i] |=
450 wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8;
451 cmd->resp[i] |=
452 wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0;
456 static void wbsd_send_command(struct wbsd_host* host, struct mmc_command* cmd)
458 int i;
459 u8 status, isr;
461 DBGF("Sending cmd (%x)\n", cmd->opcode);
464 * Clear accumulated ISR. The interrupt routine
465 * will fill this one with events that occur during
466 * transfer.
468 host->isr = 0;
471 * Send the command (CRC calculated by host).
473 outb(cmd->opcode, host->base + WBSD_CMDR);
474 for (i = 3;i >= 0;i--)
475 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
477 cmd->error = MMC_ERR_NONE;
480 * Wait for the request to complete.
482 do {
483 status = wbsd_read_index(host, WBSD_IDX_STATUS);
484 } while (status & WBSD_CARDTRAFFIC);
487 * Do we expect a reply?
489 if ((cmd->flags & MMC_RSP_MASK) != MMC_RSP_NONE)
492 * Read back status.
494 isr = host->isr;
496 /* Card removed? */
497 if (isr & WBSD_INT_CARD)
498 cmd->error = MMC_ERR_TIMEOUT;
499 /* Timeout? */
500 else if (isr & WBSD_INT_TIMEOUT)
501 cmd->error = MMC_ERR_TIMEOUT;
502 /* CRC? */
503 else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
504 cmd->error = MMC_ERR_BADCRC;
505 /* All ok */
506 else
508 if ((cmd->flags & MMC_RSP_MASK) == MMC_RSP_SHORT)
509 wbsd_get_short_reply(host, cmd);
510 else
511 wbsd_get_long_reply(host, cmd);
515 DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error);
519 * Data functions
522 static void wbsd_empty_fifo(struct wbsd_host* host)
524 struct mmc_data* data = host->mrq->cmd->data;
525 char* buffer;
526 int i, fsr, fifo;
529 * Handle excessive data.
531 if (data->bytes_xfered == host->size)
532 return;
534 buffer = wbsd_kmap_sg(host) + host->offset;
537 * Drain the fifo. This has a tendency to loop longer
538 * than the FIFO length (usually one block).
540 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY))
543 * The size field in the FSR is broken so we have to
544 * do some guessing.
546 if (fsr & WBSD_FIFO_FULL)
547 fifo = 16;
548 else if (fsr & WBSD_FIFO_FUTHRE)
549 fifo = 8;
550 else
551 fifo = 1;
553 for (i = 0;i < fifo;i++)
555 *buffer = inb(host->base + WBSD_DFR);
556 buffer++;
557 host->offset++;
558 host->remain--;
560 data->bytes_xfered++;
563 * Transfer done?
565 if (data->bytes_xfered == host->size)
567 wbsd_kunmap_sg(host);
568 return;
572 * End of scatter list entry?
574 if (host->remain == 0)
576 wbsd_kunmap_sg(host);
579 * Get next entry. Check if last.
581 if (!wbsd_next_sg(host))
584 * We should never reach this point.
585 * It means that we're trying to
586 * transfer more blocks than can fit
587 * into the scatter list.
589 BUG_ON(1);
591 host->size = data->bytes_xfered;
593 return;
596 buffer = wbsd_kmap_sg(host);
601 wbsd_kunmap_sg(host);
604 * This is a very dirty hack to solve a
605 * hardware problem. The chip doesn't trigger
606 * FIFO threshold interrupts properly.
608 if ((host->size - data->bytes_xfered) < 16)
609 tasklet_schedule(&host->fifo_tasklet);
612 static void wbsd_fill_fifo(struct wbsd_host* host)
614 struct mmc_data* data = host->mrq->cmd->data;
615 char* buffer;
616 int i, fsr, fifo;
619 * Check that we aren't being called after the
620 * entire buffer has been transfered.
622 if (data->bytes_xfered == host->size)
623 return;
625 buffer = wbsd_kmap_sg(host) + host->offset;
628 * Fill the fifo. This has a tendency to loop longer
629 * than the FIFO length (usually one block).
631 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL))
634 * The size field in the FSR is broken so we have to
635 * do some guessing.
637 if (fsr & WBSD_FIFO_EMPTY)
638 fifo = 0;
639 else if (fsr & WBSD_FIFO_EMTHRE)
640 fifo = 8;
641 else
642 fifo = 15;
644 for (i = 16;i > fifo;i--)
646 outb(*buffer, host->base + WBSD_DFR);
647 buffer++;
648 host->offset++;
649 host->remain--;
651 data->bytes_xfered++;
654 * Transfer done?
656 if (data->bytes_xfered == host->size)
658 wbsd_kunmap_sg(host);
659 return;
663 * End of scatter list entry?
665 if (host->remain == 0)
667 wbsd_kunmap_sg(host);
670 * Get next entry. Check if last.
672 if (!wbsd_next_sg(host))
675 * We should never reach this point.
676 * It means that we're trying to
677 * transfer more blocks than can fit
678 * into the scatter list.
680 BUG_ON(1);
682 host->size = data->bytes_xfered;
684 return;
687 buffer = wbsd_kmap_sg(host);
692 wbsd_kunmap_sg(host);
695 * The controller stops sending interrupts for
696 * 'FIFO empty' under certain conditions. So we
697 * need to be a bit more pro-active.
699 tasklet_schedule(&host->fifo_tasklet);
702 static void wbsd_prepare_data(struct wbsd_host* host, struct mmc_data* data)
704 u16 blksize;
705 u8 setup;
706 unsigned long dmaflags;
708 DBGF("blksz %04x blks %04x flags %08x\n",
709 1 << data->blksz_bits, data->blocks, data->flags);
710 DBGF("tsac %d ms nsac %d clk\n",
711 data->timeout_ns / 1000000, data->timeout_clks);
714 * Calculate size.
716 host->size = data->blocks << data->blksz_bits;
719 * Check timeout values for overflow.
720 * (Yes, some cards cause this value to overflow).
722 if (data->timeout_ns > 127000000)
723 wbsd_write_index(host, WBSD_IDX_TAAC, 127);
724 else
725 wbsd_write_index(host, WBSD_IDX_TAAC, data->timeout_ns/1000000);
727 if (data->timeout_clks > 255)
728 wbsd_write_index(host, WBSD_IDX_NSAC, 255);
729 else
730 wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks);
733 * Inform the chip of how large blocks will be
734 * sent. It needs this to determine when to
735 * calculate CRC.
737 * Space for CRC must be included in the size.
739 blksize = (1 << data->blksz_bits) + 2;
741 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0);
742 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
745 * Clear the FIFO. This is needed even for DMA
746 * transfers since the chip still uses the FIFO
747 * internally.
749 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
750 setup |= WBSD_FIFO_RESET;
751 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
754 * DMA transfer?
756 if (host->dma >= 0)
759 * The buffer for DMA is only 64 kB.
761 BUG_ON(host->size > 0x10000);
762 if (host->size > 0x10000)
764 data->error = MMC_ERR_INVALID;
765 return;
769 * Transfer data from the SG list to
770 * the DMA buffer.
772 if (data->flags & MMC_DATA_WRITE)
773 wbsd_sg_to_dma(host, data);
776 * Initialise the ISA DMA controller.
778 dmaflags = claim_dma_lock();
779 disable_dma(host->dma);
780 clear_dma_ff(host->dma);
781 if (data->flags & MMC_DATA_READ)
782 set_dma_mode(host->dma, DMA_MODE_READ & ~0x40);
783 else
784 set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40);
785 set_dma_addr(host->dma, host->dma_addr);
786 set_dma_count(host->dma, host->size);
788 enable_dma(host->dma);
789 release_dma_lock(dmaflags);
792 * Enable DMA on the host.
794 wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE);
796 else
799 * This flag is used to keep printk
800 * output to a minimum.
802 host->firsterr = 1;
805 * Initialise the SG list.
807 wbsd_init_sg(host, data);
810 * Turn off DMA.
812 wbsd_write_index(host, WBSD_IDX_DMA, 0);
815 * Set up FIFO threshold levels (and fill
816 * buffer if doing a write).
818 if (data->flags & MMC_DATA_READ)
820 wbsd_write_index(host, WBSD_IDX_FIFOEN,
821 WBSD_FIFOEN_FULL | 8);
823 else
825 wbsd_write_index(host, WBSD_IDX_FIFOEN,
826 WBSD_FIFOEN_EMPTY | 8);
827 wbsd_fill_fifo(host);
831 data->error = MMC_ERR_NONE;
834 static void wbsd_finish_data(struct wbsd_host* host, struct mmc_data* data)
836 unsigned long dmaflags;
837 int count;
838 u8 status;
840 WARN_ON(host->mrq == NULL);
843 * Send a stop command if needed.
845 if (data->stop)
846 wbsd_send_command(host, data->stop);
849 * Wait for the controller to leave data
850 * transfer state.
854 status = wbsd_read_index(host, WBSD_IDX_STATUS);
855 } while (status & (WBSD_BLOCK_READ | WBSD_BLOCK_WRITE));
858 * DMA transfer?
860 if (host->dma >= 0)
863 * Disable DMA on the host.
865 wbsd_write_index(host, WBSD_IDX_DMA, 0);
868 * Turn of ISA DMA controller.
870 dmaflags = claim_dma_lock();
871 disable_dma(host->dma);
872 clear_dma_ff(host->dma);
873 count = get_dma_residue(host->dma);
874 release_dma_lock(dmaflags);
877 * Any leftover data?
879 if (count)
881 printk(KERN_ERR DRIVER_NAME ": Incomplete DMA "
882 "transfer. %d bytes left.\n", count);
884 data->error = MMC_ERR_FAILED;
886 else
889 * Transfer data from DMA buffer to
890 * SG list.
892 if (data->flags & MMC_DATA_READ)
893 wbsd_dma_to_sg(host, data);
895 data->bytes_xfered = host->size;
899 DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered);
901 wbsd_request_end(host, host->mrq);
904 /*****************************************************************************\
906 * MMC layer callbacks *
908 \*****************************************************************************/
910 static void wbsd_request(struct mmc_host* mmc, struct mmc_request* mrq)
912 struct wbsd_host* host = mmc_priv(mmc);
913 struct mmc_command* cmd;
916 * Disable tasklets to avoid a deadlock.
918 spin_lock_bh(&host->lock);
920 BUG_ON(host->mrq != NULL);
922 cmd = mrq->cmd;
924 host->mrq = mrq;
927 * If there is no card in the slot then
928 * timeout immediatly.
930 if (!(host->flags & WBSD_FCARD_PRESENT))
932 cmd->error = MMC_ERR_TIMEOUT;
933 goto done;
937 * Does the request include data?
939 if (cmd->data)
941 wbsd_prepare_data(host, cmd->data);
943 if (cmd->data->error != MMC_ERR_NONE)
944 goto done;
947 wbsd_send_command(host, cmd);
950 * If this is a data transfer the request
951 * will be finished after the data has
952 * transfered.
954 if (cmd->data && (cmd->error == MMC_ERR_NONE))
957 * Dirty fix for hardware bug.
959 if (host->dma == -1)
960 tasklet_schedule(&host->fifo_tasklet);
962 spin_unlock_bh(&host->lock);
964 return;
967 done:
968 wbsd_request_end(host, mrq);
970 spin_unlock_bh(&host->lock);
973 static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
975 struct wbsd_host* host = mmc_priv(mmc);
976 u8 clk, setup, pwr;
978 DBGF("clock %uHz busmode %u powermode %u Vdd %u\n",
979 ios->clock, ios->bus_mode, ios->power_mode, ios->vdd);
981 spin_lock_bh(&host->lock);
984 * Reset the chip on each power off.
985 * Should clear out any weird states.
987 if (ios->power_mode == MMC_POWER_OFF)
988 wbsd_init_device(host);
990 if (ios->clock >= 24000000)
991 clk = WBSD_CLK_24M;
992 else if (ios->clock >= 16000000)
993 clk = WBSD_CLK_16M;
994 else if (ios->clock >= 12000000)
995 clk = WBSD_CLK_12M;
996 else
997 clk = WBSD_CLK_375K;
1000 * Only write to the clock register when
1001 * there is an actual change.
1003 if (clk != host->clk)
1005 wbsd_write_index(host, WBSD_IDX_CLK, clk);
1006 host->clk = clk;
1010 * Power up card.
1012 if (ios->power_mode != MMC_POWER_OFF)
1014 pwr = inb(host->base + WBSD_CSR);
1015 pwr &= ~WBSD_POWER_N;
1016 outb(pwr, host->base + WBSD_CSR);
1020 * MMC cards need to have pin 1 high during init.
1021 * Init time corresponds rather nicely with the bus mode.
1022 * It wreaks havoc with the card detection though so
1023 * that needs to be disabed.
1025 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
1026 if ((ios->power_mode == MMC_POWER_ON) &&
1027 (ios->bus_mode == MMC_BUSMODE_OPENDRAIN))
1029 setup |= WBSD_DAT3_H;
1030 host->flags |= WBSD_FIGNORE_DETECT;
1032 else
1034 setup &= ~WBSD_DAT3_H;
1035 host->flags &= ~WBSD_FIGNORE_DETECT;
1037 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
1039 spin_unlock_bh(&host->lock);
1042 static struct mmc_host_ops wbsd_ops = {
1043 .request = wbsd_request,
1044 .set_ios = wbsd_set_ios,
1047 /*****************************************************************************\
1049 * Interrupt handling *
1051 \*****************************************************************************/
1054 * Tasklets
1057 inline static struct mmc_data* wbsd_get_data(struct wbsd_host* host)
1059 WARN_ON(!host->mrq);
1060 if (!host->mrq)
1061 return NULL;
1063 WARN_ON(!host->mrq->cmd);
1064 if (!host->mrq->cmd)
1065 return NULL;
1067 WARN_ON(!host->mrq->cmd->data);
1068 if (!host->mrq->cmd->data)
1069 return NULL;
1071 return host->mrq->cmd->data;
1074 static void wbsd_tasklet_card(unsigned long param)
1076 struct wbsd_host* host = (struct wbsd_host*)param;
1077 u8 csr;
1078 int change = 0;
1080 spin_lock(&host->lock);
1082 if (host->flags & WBSD_FIGNORE_DETECT)
1084 spin_unlock(&host->lock);
1085 return;
1088 csr = inb(host->base + WBSD_CSR);
1089 WARN_ON(csr == 0xff);
1091 if (csr & WBSD_CARDPRESENT)
1093 if (!(host->flags & WBSD_FCARD_PRESENT))
1095 DBG("Card inserted\n");
1096 host->flags |= WBSD_FCARD_PRESENT;
1097 change = 1;
1100 else if (host->flags & WBSD_FCARD_PRESENT)
1102 DBG("Card removed\n");
1103 host->flags &= ~WBSD_FCARD_PRESENT;
1104 change = 1;
1106 if (host->mrq)
1108 printk(KERN_ERR DRIVER_NAME
1109 ": Card removed during transfer!\n");
1110 wbsd_reset(host);
1112 host->mrq->cmd->error = MMC_ERR_FAILED;
1113 tasklet_schedule(&host->finish_tasklet);
1118 * Unlock first since we might get a call back.
1120 spin_unlock(&host->lock);
1122 if (change)
1123 mmc_detect_change(host->mmc);
1126 static void wbsd_tasklet_fifo(unsigned long param)
1128 struct wbsd_host* host = (struct wbsd_host*)param;
1129 struct mmc_data* data;
1131 spin_lock(&host->lock);
1133 if (!host->mrq)
1134 goto end;
1136 data = wbsd_get_data(host);
1137 if (!data)
1138 goto end;
1140 if (data->flags & MMC_DATA_WRITE)
1141 wbsd_fill_fifo(host);
1142 else
1143 wbsd_empty_fifo(host);
1146 * Done?
1148 if (host->size == data->bytes_xfered)
1150 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0);
1151 tasklet_schedule(&host->finish_tasklet);
1154 end:
1155 spin_unlock(&host->lock);
1158 static void wbsd_tasklet_crc(unsigned long param)
1160 struct wbsd_host* host = (struct wbsd_host*)param;
1161 struct mmc_data* data;
1163 spin_lock(&host->lock);
1165 if (!host->mrq)
1166 goto end;
1168 data = wbsd_get_data(host);
1169 if (!data)
1170 goto end;
1172 DBGF("CRC error\n");
1174 data->error = MMC_ERR_BADCRC;
1176 tasklet_schedule(&host->finish_tasklet);
1178 end:
1179 spin_unlock(&host->lock);
1182 static void wbsd_tasklet_timeout(unsigned long param)
1184 struct wbsd_host* host = (struct wbsd_host*)param;
1185 struct mmc_data* data;
1187 spin_lock(&host->lock);
1189 if (!host->mrq)
1190 goto end;
1192 data = wbsd_get_data(host);
1193 if (!data)
1194 goto end;
1196 DBGF("Timeout\n");
1198 data->error = MMC_ERR_TIMEOUT;
1200 tasklet_schedule(&host->finish_tasklet);
1202 end:
1203 spin_unlock(&host->lock);
1206 static void wbsd_tasklet_finish(unsigned long param)
1208 struct wbsd_host* host = (struct wbsd_host*)param;
1209 struct mmc_data* data;
1211 spin_lock(&host->lock);
1213 WARN_ON(!host->mrq);
1214 if (!host->mrq)
1215 goto end;
1217 data = wbsd_get_data(host);
1218 if (!data)
1219 goto end;
1221 wbsd_finish_data(host, data);
1223 end:
1224 spin_unlock(&host->lock);
1227 static void wbsd_tasklet_block(unsigned long param)
1229 struct wbsd_host* host = (struct wbsd_host*)param;
1230 struct mmc_data* data;
1232 spin_lock(&host->lock);
1234 if ((wbsd_read_index(host, WBSD_IDX_CRCSTATUS) & WBSD_CRC_MASK) !=
1235 WBSD_CRC_OK)
1237 data = wbsd_get_data(host);
1238 if (!data)
1239 goto end;
1241 DBGF("CRC error\n");
1243 data->error = MMC_ERR_BADCRC;
1245 tasklet_schedule(&host->finish_tasklet);
1248 end:
1249 spin_unlock(&host->lock);
1253 * Interrupt handling
1256 static irqreturn_t wbsd_irq(int irq, void *dev_id, struct pt_regs *regs)
1258 struct wbsd_host* host = dev_id;
1259 int isr;
1261 isr = inb(host->base + WBSD_ISR);
1264 * Was it actually our hardware that caused the interrupt?
1266 if (isr == 0xff || isr == 0x00)
1267 return IRQ_NONE;
1269 host->isr |= isr;
1272 * Schedule tasklets as needed.
1274 if (isr & WBSD_INT_CARD)
1275 tasklet_schedule(&host->card_tasklet);
1276 if (isr & WBSD_INT_FIFO_THRE)
1277 tasklet_schedule(&host->fifo_tasklet);
1278 if (isr & WBSD_INT_CRC)
1279 tasklet_hi_schedule(&host->crc_tasklet);
1280 if (isr & WBSD_INT_TIMEOUT)
1281 tasklet_hi_schedule(&host->timeout_tasklet);
1282 if (isr & WBSD_INT_BUSYEND)
1283 tasklet_hi_schedule(&host->block_tasklet);
1284 if (isr & WBSD_INT_TC)
1285 tasklet_schedule(&host->finish_tasklet);
1287 return IRQ_HANDLED;
1290 /*****************************************************************************\
1292 * Device initialisation and shutdown *
1294 \*****************************************************************************/
1297 * Allocate/free MMC structure.
1300 static int __devinit wbsd_alloc_mmc(struct device* dev)
1302 struct mmc_host* mmc;
1303 struct wbsd_host* host;
1306 * Allocate MMC structure.
1308 mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev);
1309 if (!mmc)
1310 return -ENOMEM;
1312 host = mmc_priv(mmc);
1313 host->mmc = mmc;
1315 host->dma = -1;
1318 * Set host parameters.
1320 mmc->ops = &wbsd_ops;
1321 mmc->f_min = 375000;
1322 mmc->f_max = 24000000;
1323 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1325 spin_lock_init(&host->lock);
1328 * Maximum number of segments. Worst case is one sector per segment
1329 * so this will be 64kB/512.
1331 mmc->max_hw_segs = 128;
1332 mmc->max_phys_segs = 128;
1335 * Maximum number of sectors in one transfer. Also limited by 64kB
1336 * buffer.
1338 mmc->max_sectors = 128;
1341 * Maximum segment size. Could be one segment with the maximum number
1342 * of segments.
1344 mmc->max_seg_size = mmc->max_sectors * 512;
1346 dev_set_drvdata(dev, mmc);
1348 return 0;
1351 static void __devexit wbsd_free_mmc(struct device* dev)
1353 struct mmc_host* mmc;
1355 mmc = dev_get_drvdata(dev);
1356 if (!mmc)
1357 return;
1359 mmc_free_host(mmc);
1361 dev_set_drvdata(dev, NULL);
1365 * Scan for known chip id:s
1368 static int __devinit wbsd_scan(struct wbsd_host* host)
1370 int i, j, k;
1371 int id;
1374 * Iterate through all ports, all codes to
1375 * find hardware that is in our known list.
1377 for (i = 0;i < sizeof(config_ports)/sizeof(int);i++)
1379 if (!request_region(config_ports[i], 2, DRIVER_NAME))
1380 continue;
1382 for (j = 0;j < sizeof(unlock_codes)/sizeof(int);j++)
1384 id = 0xFFFF;
1386 outb(unlock_codes[j], config_ports[i]);
1387 outb(unlock_codes[j], config_ports[i]);
1389 outb(WBSD_CONF_ID_HI, config_ports[i]);
1390 id = inb(config_ports[i] + 1) << 8;
1392 outb(WBSD_CONF_ID_LO, config_ports[i]);
1393 id |= inb(config_ports[i] + 1);
1395 for (k = 0;k < sizeof(valid_ids)/sizeof(int);k++)
1397 if (id == valid_ids[k])
1399 host->chip_id = id;
1400 host->config = config_ports[i];
1401 host->unlock_code = unlock_codes[i];
1403 return 0;
1407 if (id != 0xFFFF)
1409 DBG("Unknown hardware (id %x) found at %x\n",
1410 id, config_ports[i]);
1413 outb(LOCK_CODE, config_ports[i]);
1416 release_region(config_ports[i], 2);
1419 return -ENODEV;
1423 * Allocate/free io port ranges
1426 static int __devinit wbsd_request_region(struct wbsd_host* host, int base)
1428 if (io & 0x7)
1429 return -EINVAL;
1431 if (!request_region(base, 8, DRIVER_NAME))
1432 return -EIO;
1434 host->base = io;
1436 return 0;
1439 static void __devexit wbsd_release_regions(struct wbsd_host* host)
1441 if (host->base)
1442 release_region(host->base, 8);
1444 host->base = 0;
1446 if (host->config)
1447 release_region(host->config, 2);
1449 host->config = 0;
1453 * Allocate/free DMA port and buffer
1456 static void __devinit wbsd_request_dma(struct wbsd_host* host, int dma)
1458 if (dma < 0)
1459 return;
1461 if (request_dma(dma, DRIVER_NAME))
1462 goto err;
1465 * We need to allocate a special buffer in
1466 * order for ISA to be able to DMA to it.
1468 host->dma_buffer = kmalloc(WBSD_DMA_SIZE,
1469 GFP_NOIO | GFP_DMA | __GFP_REPEAT | __GFP_NOWARN);
1470 if (!host->dma_buffer)
1471 goto free;
1474 * Translate the address to a physical address.
1476 host->dma_addr = dma_map_single(host->mmc->dev, host->dma_buffer,
1477 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1480 * ISA DMA must be aligned on a 64k basis.
1482 if ((host->dma_addr & 0xffff) != 0)
1483 goto kfree;
1485 * ISA cannot access memory above 16 MB.
1487 else if (host->dma_addr >= 0x1000000)
1488 goto kfree;
1490 host->dma = dma;
1492 return;
1494 kfree:
1496 * If we've gotten here then there is some kind of alignment bug
1498 BUG_ON(1);
1500 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
1501 DMA_BIDIRECTIONAL);
1502 host->dma_addr = (dma_addr_t)NULL;
1504 kfree(host->dma_buffer);
1505 host->dma_buffer = NULL;
1507 free:
1508 free_dma(dma);
1510 err:
1511 printk(KERN_WARNING DRIVER_NAME ": Unable to allocate DMA %d. "
1512 "Falling back on FIFO.\n", dma);
1515 static void __devexit wbsd_release_dma(struct wbsd_host* host)
1517 if (host->dma_addr)
1518 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
1519 DMA_BIDIRECTIONAL);
1520 if (host->dma_buffer)
1521 kfree(host->dma_buffer);
1522 if (host->dma >= 0)
1523 free_dma(host->dma);
1525 host->dma = -1;
1526 host->dma_buffer = NULL;
1527 host->dma_addr = (dma_addr_t)NULL;
1531 * Allocate/free IRQ.
1534 static int __devinit wbsd_request_irq(struct wbsd_host* host, int irq)
1536 int ret;
1539 * Allocate interrupt.
1542 ret = request_irq(irq, wbsd_irq, SA_SHIRQ, DRIVER_NAME, host);
1543 if (ret)
1544 return ret;
1546 host->irq = irq;
1549 * Set up tasklets.
1551 tasklet_init(&host->card_tasklet, wbsd_tasklet_card, (unsigned long)host);
1552 tasklet_init(&host->fifo_tasklet, wbsd_tasklet_fifo, (unsigned long)host);
1553 tasklet_init(&host->crc_tasklet, wbsd_tasklet_crc, (unsigned long)host);
1554 tasklet_init(&host->timeout_tasklet, wbsd_tasklet_timeout, (unsigned long)host);
1555 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish, (unsigned long)host);
1556 tasklet_init(&host->block_tasklet, wbsd_tasklet_block, (unsigned long)host);
1558 return 0;
1561 static void __devexit wbsd_release_irq(struct wbsd_host* host)
1563 if (!host->irq)
1564 return;
1566 free_irq(host->irq, host);
1568 host->irq = 0;
1570 tasklet_kill(&host->card_tasklet);
1571 tasklet_kill(&host->fifo_tasklet);
1572 tasklet_kill(&host->crc_tasklet);
1573 tasklet_kill(&host->timeout_tasklet);
1574 tasklet_kill(&host->finish_tasklet);
1575 tasklet_kill(&host->block_tasklet);
1579 * Allocate all resources for the host.
1582 static int __devinit wbsd_request_resources(struct wbsd_host* host,
1583 int base, int irq, int dma)
1585 int ret;
1588 * Allocate I/O ports.
1590 ret = wbsd_request_region(host, base);
1591 if (ret)
1592 return ret;
1595 * Allocate interrupt.
1597 ret = wbsd_request_irq(host, irq);
1598 if (ret)
1599 return ret;
1602 * Allocate DMA.
1604 wbsd_request_dma(host, dma);
1606 return 0;
1610 * Release all resources for the host.
1613 static void __devexit wbsd_release_resources(struct wbsd_host* host)
1615 wbsd_release_dma(host);
1616 wbsd_release_irq(host);
1617 wbsd_release_regions(host);
1621 * Configure the resources the chip should use.
1624 static void __devinit wbsd_chip_config(struct wbsd_host* host)
1627 * Reset the chip.
1629 wbsd_write_config(host, WBSD_CONF_SWRST, 1);
1630 wbsd_write_config(host, WBSD_CONF_SWRST, 0);
1633 * Select SD/MMC function.
1635 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1638 * Set up card detection.
1640 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11);
1643 * Configure chip
1645 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8);
1646 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff);
1648 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq);
1650 if (host->dma >= 0)
1651 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma);
1654 * Enable and power up chip.
1656 wbsd_write_config(host, WBSD_CONF_ENABLE, 1);
1657 wbsd_write_config(host, WBSD_CONF_POWER, 0x20);
1661 * Check that configured resources are correct.
1664 static int __devinit wbsd_chip_validate(struct wbsd_host* host)
1666 int base, irq, dma;
1669 * Select SD/MMC function.
1671 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1674 * Read configuration.
1676 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8;
1677 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO);
1679 irq = wbsd_read_config(host, WBSD_CONF_IRQ);
1681 dma = wbsd_read_config(host, WBSD_CONF_DRQ);
1684 * Validate against given configuration.
1686 if (base != host->base)
1687 return 0;
1688 if (irq != host->irq)
1689 return 0;
1690 if ((dma != host->dma) && (host->dma != -1))
1691 return 0;
1693 return 1;
1696 /*****************************************************************************\
1698 * Devices setup and shutdown *
1700 \*****************************************************************************/
1702 static int __devinit wbsd_init(struct device* dev, int base, int irq, int dma,
1703 int pnp)
1705 struct wbsd_host* host = NULL;
1706 struct mmc_host* mmc = NULL;
1707 int ret;
1709 ret = wbsd_alloc_mmc(dev);
1710 if (ret)
1711 return ret;
1713 mmc = dev_get_drvdata(dev);
1714 host = mmc_priv(mmc);
1717 * Scan for hardware.
1719 ret = wbsd_scan(host);
1720 if (ret)
1722 if (pnp && (ret == -ENODEV))
1724 printk(KERN_WARNING DRIVER_NAME
1725 ": Unable to confirm device presence. You may "
1726 "experience lock-ups.\n");
1728 else
1730 wbsd_free_mmc(dev);
1731 return ret;
1736 * Request resources.
1738 ret = wbsd_request_resources(host, io, irq, dma);
1739 if (ret)
1741 wbsd_release_resources(host);
1742 wbsd_free_mmc(dev);
1743 return ret;
1747 * See if chip needs to be configured.
1749 if (pnp && (host->config != 0))
1751 if (!wbsd_chip_validate(host))
1753 printk(KERN_WARNING DRIVER_NAME
1754 ": PnP active but chip not configured! "
1755 "You probably have a buggy BIOS. "
1756 "Configuring chip manually.\n");
1757 wbsd_chip_config(host);
1760 else
1761 wbsd_chip_config(host);
1764 * Power Management stuff. No idea how this works.
1765 * Not tested.
1767 #ifdef CONFIG_PM
1768 if (host->config)
1769 wbsd_write_config(host, WBSD_CONF_PME, 0xA0);
1770 #endif
1772 * Allow device to initialise itself properly.
1774 mdelay(5);
1777 * Reset the chip into a known state.
1779 wbsd_init_device(host);
1781 mmc_add_host(mmc);
1783 printk(KERN_INFO "%s: W83L51xD", mmc->host_name);
1784 if (host->chip_id != 0)
1785 printk(" id %x", (int)host->chip_id);
1786 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
1787 if (host->dma >= 0)
1788 printk(" dma %d", (int)host->dma);
1789 else
1790 printk(" FIFO");
1791 if (pnp)
1792 printk(" PnP");
1793 printk("\n");
1795 return 0;
1798 static void __devexit wbsd_shutdown(struct device* dev, int pnp)
1800 struct mmc_host* mmc = dev_get_drvdata(dev);
1801 struct wbsd_host* host;
1803 if (!mmc)
1804 return;
1806 host = mmc_priv(mmc);
1808 mmc_remove_host(mmc);
1810 if (!pnp)
1813 * Power down the SD/MMC function.
1815 wbsd_unlock_config(host);
1816 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1817 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1818 wbsd_lock_config(host);
1821 wbsd_release_resources(host);
1823 wbsd_free_mmc(dev);
1827 * Non-PnP
1830 static int __devinit wbsd_probe(struct device* dev)
1832 return wbsd_init(dev, io, irq, dma, 0);
1835 static int __devexit wbsd_remove(struct device* dev)
1837 wbsd_shutdown(dev, 0);
1839 return 0;
1843 * PnP
1846 #ifdef CONFIG_PNP
1848 static int __devinit
1849 wbsd_pnp_probe(struct pnp_dev * pnpdev, const struct pnp_device_id *dev_id)
1851 int io, irq, dma;
1854 * Get resources from PnP layer.
1856 io = pnp_port_start(pnpdev, 0);
1857 irq = pnp_irq(pnpdev, 0);
1858 if (pnp_dma_valid(pnpdev, 0))
1859 dma = pnp_dma(pnpdev, 0);
1860 else
1861 dma = -1;
1863 DBGF("PnP resources: port %3x irq %d dma %d\n", io, irq, dma);
1865 return wbsd_init(&pnpdev->dev, io, irq, dma, 1);
1868 static void __devexit wbsd_pnp_remove(struct pnp_dev * dev)
1870 wbsd_shutdown(&dev->dev, 1);
1873 #endif /* CONFIG_PNP */
1876 * Power management
1879 #ifdef CONFIG_PM
1880 static int wbsd_suspend(struct device *dev, pm_message_t state, u32 level)
1882 DBGF("Not yet supported\n");
1884 return 0;
1887 static int wbsd_resume(struct device *dev, u32 level)
1889 DBGF("Not yet supported\n");
1891 return 0;
1893 #else
1894 #define wbsd_suspend NULL
1895 #define wbsd_resume NULL
1896 #endif
1898 static struct platform_device *wbsd_device;
1900 static struct device_driver wbsd_driver = {
1901 .name = DRIVER_NAME,
1902 .bus = &platform_bus_type,
1903 .probe = wbsd_probe,
1904 .remove = wbsd_remove,
1906 .suspend = wbsd_suspend,
1907 .resume = wbsd_resume,
1910 #ifdef CONFIG_PNP
1912 static struct pnp_driver wbsd_pnp_driver = {
1913 .name = DRIVER_NAME,
1914 .id_table = pnp_dev_table,
1915 .probe = wbsd_pnp_probe,
1916 .remove = wbsd_pnp_remove,
1919 #endif /* CONFIG_PNP */
1922 * Module loading/unloading
1925 static int __init wbsd_drv_init(void)
1927 int result;
1929 printk(KERN_INFO DRIVER_NAME
1930 ": Winbond W83L51xD SD/MMC card interface driver, "
1931 DRIVER_VERSION "\n");
1932 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1934 #ifdef CONFIG_PNP
1936 if (!nopnp)
1938 result = pnp_register_driver(&wbsd_pnp_driver);
1939 if (result < 0)
1940 return result;
1943 #endif /* CONFIG_PNP */
1945 if (nopnp)
1947 result = driver_register(&wbsd_driver);
1948 if (result < 0)
1949 return result;
1951 wbsd_device = platform_device_register_simple(DRIVER_NAME, -1,
1952 NULL, 0);
1953 if (IS_ERR(wbsd_device))
1954 return PTR_ERR(wbsd_device);
1957 return 0;
1960 static void __exit wbsd_drv_exit(void)
1962 #ifdef CONFIG_PNP
1964 if (!nopnp)
1965 pnp_unregister_driver(&wbsd_pnp_driver);
1967 #endif /* CONFIG_PNP */
1969 if (nopnp)
1971 platform_device_unregister(wbsd_device);
1973 driver_unregister(&wbsd_driver);
1976 DBG("unloaded\n");
1979 module_init(wbsd_drv_init);
1980 module_exit(wbsd_drv_exit);
1981 #ifdef CONFIG_PNP
1982 module_param(nopnp, uint, 0444);
1983 #endif
1984 module_param(io, uint, 0444);
1985 module_param(irq, uint, 0444);
1986 module_param(dma, int, 0444);
1988 MODULE_LICENSE("GPL");
1989 MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver");
1990 MODULE_VERSION(DRIVER_VERSION);
1992 #ifdef CONFIG_PNP
1993 MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)");
1994 #endif
1995 MODULE_PARM_DESC(io, "I/O base to allocate. Must be 8 byte aligned. (default 0x248)");
1996 MODULE_PARM_DESC(irq, "IRQ to allocate. (default 6)");
1997 MODULE_PARM_DESC(dma, "DMA channel to allocate. -1 for no DMA. (default 2)");