[PATCH] Kconfig fix (PHYLIB vs. s390)
[linux-2.6/sactl.git] / drivers / mmc / wbsd.c
blob08ae22aed9e8f7f38a1c61af4a0b87b92b563a0b
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.4"
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
58 * Device resources
61 #ifdef CONFIG_PNP
63 static const struct pnp_device_id pnp_dev_table[] = {
64 { "WEC0517", 0 },
65 { "WEC0518", 0 },
66 { "", 0 },
69 MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
71 #endif /* CONFIG_PNP */
73 static const int config_ports[] = { 0x2E, 0x4E };
74 static const int unlock_codes[] = { 0x83, 0x87 };
76 static const int valid_ids[] = {
77 0x7112,
80 #ifdef CONFIG_PNP
81 static unsigned int nopnp = 0;
82 #else
83 static const unsigned int nopnp = 1;
84 #endif
85 static unsigned int io = 0x248;
86 static unsigned int irq = 6;
87 static int dma = 2;
90 * Basic functions
93 static inline void wbsd_unlock_config(struct wbsd_host* host)
95 BUG_ON(host->config == 0);
97 outb(host->unlock_code, host->config);
98 outb(host->unlock_code, host->config);
101 static inline void wbsd_lock_config(struct wbsd_host* host)
103 BUG_ON(host->config == 0);
105 outb(LOCK_CODE, host->config);
108 static inline void wbsd_write_config(struct wbsd_host* host, u8 reg, u8 value)
110 BUG_ON(host->config == 0);
112 outb(reg, host->config);
113 outb(value, host->config + 1);
116 static inline u8 wbsd_read_config(struct wbsd_host* host, u8 reg)
118 BUG_ON(host->config == 0);
120 outb(reg, host->config);
121 return inb(host->config + 1);
124 static inline void wbsd_write_index(struct wbsd_host* host, u8 index, u8 value)
126 outb(index, host->base + WBSD_IDXR);
127 outb(value, host->base + WBSD_DATAR);
130 static inline u8 wbsd_read_index(struct wbsd_host* host, u8 index)
132 outb(index, host->base + WBSD_IDXR);
133 return inb(host->base + WBSD_DATAR);
137 * Common routines
140 static void wbsd_init_device(struct wbsd_host* host)
142 u8 setup, ier;
145 * Reset chip (SD/MMC part) and fifo.
147 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
148 setup |= WBSD_FIFO_RESET | WBSD_SOFT_RESET;
149 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
152 * Set DAT3 to input
154 setup &= ~WBSD_DAT3_H;
155 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
156 host->flags &= ~WBSD_FIGNORE_DETECT;
159 * Read back default clock.
161 host->clk = wbsd_read_index(host, WBSD_IDX_CLK);
164 * Power down port.
166 outb(WBSD_POWER_N, host->base + WBSD_CSR);
169 * Set maximum timeout.
171 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F);
174 * Test for card presence
176 if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT)
177 host->flags |= WBSD_FCARD_PRESENT;
178 else
179 host->flags &= ~WBSD_FCARD_PRESENT;
182 * Enable interesting interrupts.
184 ier = 0;
185 ier |= WBSD_EINT_CARD;
186 ier |= WBSD_EINT_FIFO_THRE;
187 ier |= WBSD_EINT_CCRC;
188 ier |= WBSD_EINT_TIMEOUT;
189 ier |= WBSD_EINT_CRC;
190 ier |= WBSD_EINT_TC;
192 outb(ier, host->base + WBSD_EIR);
195 * Clear interrupts.
197 inb(host->base + WBSD_ISR);
200 static void wbsd_reset(struct wbsd_host* host)
202 u8 setup;
204 printk(KERN_ERR DRIVER_NAME ": Resetting chip\n");
207 * Soft reset of chip (SD/MMC part).
209 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
210 setup |= WBSD_SOFT_RESET;
211 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
214 static void wbsd_request_end(struct wbsd_host* host, struct mmc_request* mrq)
216 unsigned long dmaflags;
218 DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode);
220 if (host->dma >= 0)
223 * Release ISA DMA controller.
225 dmaflags = claim_dma_lock();
226 disable_dma(host->dma);
227 clear_dma_ff(host->dma);
228 release_dma_lock(dmaflags);
231 * Disable DMA on host.
233 wbsd_write_index(host, WBSD_IDX_DMA, 0);
236 host->mrq = NULL;
239 * MMC layer might call back into the driver so first unlock.
241 spin_unlock(&host->lock);
242 mmc_request_done(host->mmc, mrq);
243 spin_lock(&host->lock);
247 * Scatter/gather functions
250 static inline void wbsd_init_sg(struct wbsd_host* host, struct mmc_data* data)
253 * Get info. about SG list from data structure.
255 host->cur_sg = data->sg;
256 host->num_sg = data->sg_len;
258 host->offset = 0;
259 host->remain = host->cur_sg->length;
262 static inline int wbsd_next_sg(struct wbsd_host* host)
265 * Skip to next SG entry.
267 host->cur_sg++;
268 host->num_sg--;
271 * Any entries left?
273 if (host->num_sg > 0)
275 host->offset = 0;
276 host->remain = host->cur_sg->length;
279 return host->num_sg;
282 static inline char* wbsd_kmap_sg(struct wbsd_host* host)
284 host->mapped_sg = kmap_atomic(host->cur_sg->page, KM_BIO_SRC_IRQ) +
285 host->cur_sg->offset;
286 return host->mapped_sg;
289 static inline void wbsd_kunmap_sg(struct wbsd_host* host)
291 kunmap_atomic(host->mapped_sg, KM_BIO_SRC_IRQ);
294 static inline void wbsd_sg_to_dma(struct wbsd_host* host, struct mmc_data* data)
296 unsigned int len, i, size;
297 struct scatterlist* sg;
298 char* dmabuf = host->dma_buffer;
299 char* sgbuf;
301 size = host->size;
303 sg = data->sg;
304 len = data->sg_len;
307 * Just loop through all entries. Size might not
308 * be the entire list though so make sure that
309 * we do not transfer too much.
311 for (i = 0;i < len;i++)
313 sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset;
314 if (size < sg[i].length)
315 memcpy(dmabuf, sgbuf, size);
316 else
317 memcpy(dmabuf, sgbuf, sg[i].length);
318 kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ);
319 dmabuf += sg[i].length;
321 if (size < sg[i].length)
322 size = 0;
323 else
324 size -= sg[i].length;
326 if (size == 0)
327 break;
331 * Check that we didn't get a request to transfer
332 * more data than can fit into the SG list.
335 BUG_ON(size != 0);
337 host->size -= size;
340 static inline void wbsd_dma_to_sg(struct wbsd_host* host, struct mmc_data* data)
342 unsigned int len, i, size;
343 struct scatterlist* sg;
344 char* dmabuf = host->dma_buffer;
345 char* sgbuf;
347 size = host->size;
349 sg = data->sg;
350 len = data->sg_len;
353 * Just loop through all entries. Size might not
354 * be the entire list though so make sure that
355 * we do not transfer too much.
357 for (i = 0;i < len;i++)
359 sgbuf = kmap_atomic(sg[i].page, KM_BIO_SRC_IRQ) + sg[i].offset;
360 if (size < sg[i].length)
361 memcpy(sgbuf, dmabuf, size);
362 else
363 memcpy(sgbuf, dmabuf, sg[i].length);
364 kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ);
365 dmabuf += sg[i].length;
367 if (size < sg[i].length)
368 size = 0;
369 else
370 size -= sg[i].length;
372 if (size == 0)
373 break;
377 * Check that we didn't get a request to transfer
378 * more data than can fit into the SG list.
381 BUG_ON(size != 0);
383 host->size -= size;
387 * Command handling
390 static inline void wbsd_get_short_reply(struct wbsd_host* host,
391 struct mmc_command* cmd)
394 * Correct response type?
396 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT)
398 cmd->error = MMC_ERR_INVALID;
399 return;
402 cmd->resp[0] =
403 wbsd_read_index(host, WBSD_IDX_RESP12) << 24;
404 cmd->resp[0] |=
405 wbsd_read_index(host, WBSD_IDX_RESP13) << 16;
406 cmd->resp[0] |=
407 wbsd_read_index(host, WBSD_IDX_RESP14) << 8;
408 cmd->resp[0] |=
409 wbsd_read_index(host, WBSD_IDX_RESP15) << 0;
410 cmd->resp[1] =
411 wbsd_read_index(host, WBSD_IDX_RESP16) << 24;
414 static inline void wbsd_get_long_reply(struct wbsd_host* host,
415 struct mmc_command* cmd)
417 int i;
420 * Correct response type?
422 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG)
424 cmd->error = MMC_ERR_INVALID;
425 return;
428 for (i = 0;i < 4;i++)
430 cmd->resp[i] =
431 wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24;
432 cmd->resp[i] |=
433 wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16;
434 cmd->resp[i] |=
435 wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8;
436 cmd->resp[i] |=
437 wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0;
441 static void wbsd_send_command(struct wbsd_host* host, struct mmc_command* cmd)
443 int i;
444 u8 status, isr;
446 DBGF("Sending cmd (%x)\n", cmd->opcode);
449 * Clear accumulated ISR. The interrupt routine
450 * will fill this one with events that occur during
451 * transfer.
453 host->isr = 0;
456 * Send the command (CRC calculated by host).
458 outb(cmd->opcode, host->base + WBSD_CMDR);
459 for (i = 3;i >= 0;i--)
460 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
462 cmd->error = MMC_ERR_NONE;
465 * Wait for the request to complete.
467 do {
468 status = wbsd_read_index(host, WBSD_IDX_STATUS);
469 } while (status & WBSD_CARDTRAFFIC);
472 * Do we expect a reply?
474 if ((cmd->flags & MMC_RSP_MASK) != MMC_RSP_NONE)
477 * Read back status.
479 isr = host->isr;
481 /* Card removed? */
482 if (isr & WBSD_INT_CARD)
483 cmd->error = MMC_ERR_TIMEOUT;
484 /* Timeout? */
485 else if (isr & WBSD_INT_TIMEOUT)
486 cmd->error = MMC_ERR_TIMEOUT;
487 /* CRC? */
488 else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
489 cmd->error = MMC_ERR_BADCRC;
490 /* All ok */
491 else
493 if ((cmd->flags & MMC_RSP_MASK) == MMC_RSP_SHORT)
494 wbsd_get_short_reply(host, cmd);
495 else
496 wbsd_get_long_reply(host, cmd);
500 DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error);
504 * Data functions
507 static void wbsd_empty_fifo(struct wbsd_host* host)
509 struct mmc_data* data = host->mrq->cmd->data;
510 char* buffer;
511 int i, fsr, fifo;
514 * Handle excessive data.
516 if (data->bytes_xfered == host->size)
517 return;
519 buffer = wbsd_kmap_sg(host) + host->offset;
522 * Drain the fifo. This has a tendency to loop longer
523 * than the FIFO length (usually one block).
525 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY))
528 * The size field in the FSR is broken so we have to
529 * do some guessing.
531 if (fsr & WBSD_FIFO_FULL)
532 fifo = 16;
533 else if (fsr & WBSD_FIFO_FUTHRE)
534 fifo = 8;
535 else
536 fifo = 1;
538 for (i = 0;i < fifo;i++)
540 *buffer = inb(host->base + WBSD_DFR);
541 buffer++;
542 host->offset++;
543 host->remain--;
545 data->bytes_xfered++;
548 * Transfer done?
550 if (data->bytes_xfered == host->size)
552 wbsd_kunmap_sg(host);
553 return;
557 * End of scatter list entry?
559 if (host->remain == 0)
561 wbsd_kunmap_sg(host);
564 * Get next entry. Check if last.
566 if (!wbsd_next_sg(host))
569 * We should never reach this point.
570 * It means that we're trying to
571 * transfer more blocks than can fit
572 * into the scatter list.
574 BUG_ON(1);
576 host->size = data->bytes_xfered;
578 return;
581 buffer = wbsd_kmap_sg(host);
586 wbsd_kunmap_sg(host);
589 * This is a very dirty hack to solve a
590 * hardware problem. The chip doesn't trigger
591 * FIFO threshold interrupts properly.
593 if ((host->size - data->bytes_xfered) < 16)
594 tasklet_schedule(&host->fifo_tasklet);
597 static void wbsd_fill_fifo(struct wbsd_host* host)
599 struct mmc_data* data = host->mrq->cmd->data;
600 char* buffer;
601 int i, fsr, fifo;
604 * Check that we aren't being called after the
605 * entire buffer has been transfered.
607 if (data->bytes_xfered == host->size)
608 return;
610 buffer = wbsd_kmap_sg(host) + host->offset;
613 * Fill the fifo. This has a tendency to loop longer
614 * than the FIFO length (usually one block).
616 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL))
619 * The size field in the FSR is broken so we have to
620 * do some guessing.
622 if (fsr & WBSD_FIFO_EMPTY)
623 fifo = 0;
624 else if (fsr & WBSD_FIFO_EMTHRE)
625 fifo = 8;
626 else
627 fifo = 15;
629 for (i = 16;i > fifo;i--)
631 outb(*buffer, host->base + WBSD_DFR);
632 buffer++;
633 host->offset++;
634 host->remain--;
636 data->bytes_xfered++;
639 * Transfer done?
641 if (data->bytes_xfered == host->size)
643 wbsd_kunmap_sg(host);
644 return;
648 * End of scatter list entry?
650 if (host->remain == 0)
652 wbsd_kunmap_sg(host);
655 * Get next entry. Check if last.
657 if (!wbsd_next_sg(host))
660 * We should never reach this point.
661 * It means that we're trying to
662 * transfer more blocks than can fit
663 * into the scatter list.
665 BUG_ON(1);
667 host->size = data->bytes_xfered;
669 return;
672 buffer = wbsd_kmap_sg(host);
677 wbsd_kunmap_sg(host);
680 * The controller stops sending interrupts for
681 * 'FIFO empty' under certain conditions. So we
682 * need to be a bit more pro-active.
684 tasklet_schedule(&host->fifo_tasklet);
687 static void wbsd_prepare_data(struct wbsd_host* host, struct mmc_data* data)
689 u16 blksize;
690 u8 setup;
691 unsigned long dmaflags;
693 DBGF("blksz %04x blks %04x flags %08x\n",
694 1 << data->blksz_bits, data->blocks, data->flags);
695 DBGF("tsac %d ms nsac %d clk\n",
696 data->timeout_ns / 1000000, data->timeout_clks);
699 * Calculate size.
701 host->size = data->blocks << data->blksz_bits;
704 * Check timeout values for overflow.
705 * (Yes, some cards cause this value to overflow).
707 if (data->timeout_ns > 127000000)
708 wbsd_write_index(host, WBSD_IDX_TAAC, 127);
709 else
710 wbsd_write_index(host, WBSD_IDX_TAAC, data->timeout_ns/1000000);
712 if (data->timeout_clks > 255)
713 wbsd_write_index(host, WBSD_IDX_NSAC, 255);
714 else
715 wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks);
718 * Inform the chip of how large blocks will be
719 * sent. It needs this to determine when to
720 * calculate CRC.
722 * Space for CRC must be included in the size.
724 blksize = (1 << data->blksz_bits) + 2;
726 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0);
727 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
730 * Clear the FIFO. This is needed even for DMA
731 * transfers since the chip still uses the FIFO
732 * internally.
734 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
735 setup |= WBSD_FIFO_RESET;
736 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
739 * DMA transfer?
741 if (host->dma >= 0)
744 * The buffer for DMA is only 64 kB.
746 BUG_ON(host->size > 0x10000);
747 if (host->size > 0x10000)
749 data->error = MMC_ERR_INVALID;
750 return;
754 * Transfer data from the SG list to
755 * the DMA buffer.
757 if (data->flags & MMC_DATA_WRITE)
758 wbsd_sg_to_dma(host, data);
761 * Initialise the ISA DMA controller.
763 dmaflags = claim_dma_lock();
764 disable_dma(host->dma);
765 clear_dma_ff(host->dma);
766 if (data->flags & MMC_DATA_READ)
767 set_dma_mode(host->dma, DMA_MODE_READ & ~0x40);
768 else
769 set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40);
770 set_dma_addr(host->dma, host->dma_addr);
771 set_dma_count(host->dma, host->size);
773 enable_dma(host->dma);
774 release_dma_lock(dmaflags);
777 * Enable DMA on the host.
779 wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE);
781 else
784 * This flag is used to keep printk
785 * output to a minimum.
787 host->firsterr = 1;
790 * Initialise the SG list.
792 wbsd_init_sg(host, data);
795 * Turn off DMA.
797 wbsd_write_index(host, WBSD_IDX_DMA, 0);
800 * Set up FIFO threshold levels (and fill
801 * buffer if doing a write).
803 if (data->flags & MMC_DATA_READ)
805 wbsd_write_index(host, WBSD_IDX_FIFOEN,
806 WBSD_FIFOEN_FULL | 8);
808 else
810 wbsd_write_index(host, WBSD_IDX_FIFOEN,
811 WBSD_FIFOEN_EMPTY | 8);
812 wbsd_fill_fifo(host);
816 data->error = MMC_ERR_NONE;
819 static void wbsd_finish_data(struct wbsd_host* host, struct mmc_data* data)
821 unsigned long dmaflags;
822 int count;
823 u8 status;
825 WARN_ON(host->mrq == NULL);
828 * Send a stop command if needed.
830 if (data->stop)
831 wbsd_send_command(host, data->stop);
834 * Wait for the controller to leave data
835 * transfer state.
839 status = wbsd_read_index(host, WBSD_IDX_STATUS);
840 } while (status & (WBSD_BLOCK_READ | WBSD_BLOCK_WRITE));
843 * DMA transfer?
845 if (host->dma >= 0)
848 * Disable DMA on the host.
850 wbsd_write_index(host, WBSD_IDX_DMA, 0);
853 * Turn of ISA DMA controller.
855 dmaflags = claim_dma_lock();
856 disable_dma(host->dma);
857 clear_dma_ff(host->dma);
858 count = get_dma_residue(host->dma);
859 release_dma_lock(dmaflags);
862 * Any leftover data?
864 if (count)
866 printk(KERN_ERR DRIVER_NAME ": Incomplete DMA "
867 "transfer. %d bytes left.\n", count);
869 data->error = MMC_ERR_FAILED;
871 else
874 * Transfer data from DMA buffer to
875 * SG list.
877 if (data->flags & MMC_DATA_READ)
878 wbsd_dma_to_sg(host, data);
880 data->bytes_xfered = host->size;
884 DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered);
886 wbsd_request_end(host, host->mrq);
889 /*****************************************************************************\
891 * MMC layer callbacks *
893 \*****************************************************************************/
895 static void wbsd_request(struct mmc_host* mmc, struct mmc_request* mrq)
897 struct wbsd_host* host = mmc_priv(mmc);
898 struct mmc_command* cmd;
901 * Disable tasklets to avoid a deadlock.
903 spin_lock_bh(&host->lock);
905 BUG_ON(host->mrq != NULL);
907 cmd = mrq->cmd;
909 host->mrq = mrq;
912 * If there is no card in the slot then
913 * timeout immediatly.
915 if (!(host->flags & WBSD_FCARD_PRESENT))
917 cmd->error = MMC_ERR_TIMEOUT;
918 goto done;
922 * Does the request include data?
924 if (cmd->data)
926 wbsd_prepare_data(host, cmd->data);
928 if (cmd->data->error != MMC_ERR_NONE)
929 goto done;
932 wbsd_send_command(host, cmd);
935 * If this is a data transfer the request
936 * will be finished after the data has
937 * transfered.
939 if (cmd->data && (cmd->error == MMC_ERR_NONE))
942 * Dirty fix for hardware bug.
944 if (host->dma == -1)
945 tasklet_schedule(&host->fifo_tasklet);
947 spin_unlock_bh(&host->lock);
949 return;
952 done:
953 wbsd_request_end(host, mrq);
955 spin_unlock_bh(&host->lock);
958 static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
960 struct wbsd_host* host = mmc_priv(mmc);
961 u8 clk, setup, pwr;
963 DBGF("clock %uHz busmode %u powermode %u cs %u Vdd %u\n",
964 ios->clock, ios->bus_mode, ios->power_mode, ios->chip_select,
965 ios->vdd);
967 spin_lock_bh(&host->lock);
970 * Reset the chip on each power off.
971 * Should clear out any weird states.
973 if (ios->power_mode == MMC_POWER_OFF)
974 wbsd_init_device(host);
976 if (ios->clock >= 24000000)
977 clk = WBSD_CLK_24M;
978 else if (ios->clock >= 16000000)
979 clk = WBSD_CLK_16M;
980 else if (ios->clock >= 12000000)
981 clk = WBSD_CLK_12M;
982 else
983 clk = WBSD_CLK_375K;
986 * Only write to the clock register when
987 * there is an actual change.
989 if (clk != host->clk)
991 wbsd_write_index(host, WBSD_IDX_CLK, clk);
992 host->clk = clk;
996 * Power up card.
998 if (ios->power_mode != MMC_POWER_OFF)
1000 pwr = inb(host->base + WBSD_CSR);
1001 pwr &= ~WBSD_POWER_N;
1002 outb(pwr, host->base + WBSD_CSR);
1006 * MMC cards need to have pin 1 high during init.
1007 * It wreaks havoc with the card detection though so
1008 * that needs to be disabled.
1010 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
1011 if (ios->chip_select == MMC_CS_HIGH)
1013 setup |= WBSD_DAT3_H;
1014 host->flags |= WBSD_FIGNORE_DETECT;
1016 else
1018 setup &= ~WBSD_DAT3_H;
1021 * We cannot resume card detection immediatly
1022 * because of capacitance and delays in the chip.
1024 mod_timer(&host->ignore_timer, jiffies + HZ/100);
1026 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
1028 spin_unlock_bh(&host->lock);
1031 static struct mmc_host_ops wbsd_ops = {
1032 .request = wbsd_request,
1033 .set_ios = wbsd_set_ios,
1036 /*****************************************************************************\
1038 * Interrupt handling *
1040 \*****************************************************************************/
1043 * Helper function to reset detection ignore
1046 static void wbsd_reset_ignore(unsigned long data)
1048 struct wbsd_host *host = (struct wbsd_host*)data;
1050 BUG_ON(host == NULL);
1052 DBG("Resetting card detection ignore\n");
1054 spin_lock_bh(&host->lock);
1056 host->flags &= ~WBSD_FIGNORE_DETECT;
1059 * Card status might have changed during the
1060 * blackout.
1062 tasklet_schedule(&host->card_tasklet);
1064 spin_unlock_bh(&host->lock);
1068 * Helper function for card detection
1070 static void wbsd_detect_card(unsigned long data)
1072 struct wbsd_host *host = (struct wbsd_host*)data;
1074 BUG_ON(host == NULL);
1076 DBG("Executing card detection\n");
1078 mmc_detect_change(host->mmc);
1082 * Tasklets
1085 static inline struct mmc_data* wbsd_get_data(struct wbsd_host* host)
1087 WARN_ON(!host->mrq);
1088 if (!host->mrq)
1089 return NULL;
1091 WARN_ON(!host->mrq->cmd);
1092 if (!host->mrq->cmd)
1093 return NULL;
1095 WARN_ON(!host->mrq->cmd->data);
1096 if (!host->mrq->cmd->data)
1097 return NULL;
1099 return host->mrq->cmd->data;
1102 static void wbsd_tasklet_card(unsigned long param)
1104 struct wbsd_host* host = (struct wbsd_host*)param;
1105 u8 csr;
1107 spin_lock(&host->lock);
1109 if (host->flags & WBSD_FIGNORE_DETECT)
1111 spin_unlock(&host->lock);
1112 return;
1115 csr = inb(host->base + WBSD_CSR);
1116 WARN_ON(csr == 0xff);
1118 if (csr & WBSD_CARDPRESENT)
1120 if (!(host->flags & WBSD_FCARD_PRESENT))
1122 DBG("Card inserted\n");
1123 host->flags |= WBSD_FCARD_PRESENT;
1126 * Delay card detection to allow electrical connections
1127 * to stabilise.
1129 mod_timer(&host->detect_timer, jiffies + HZ/2);
1132 spin_unlock(&host->lock);
1134 else if (host->flags & WBSD_FCARD_PRESENT)
1136 DBG("Card removed\n");
1137 host->flags &= ~WBSD_FCARD_PRESENT;
1139 if (host->mrq)
1141 printk(KERN_ERR DRIVER_NAME
1142 ": Card removed during transfer!\n");
1143 wbsd_reset(host);
1145 host->mrq->cmd->error = MMC_ERR_FAILED;
1146 tasklet_schedule(&host->finish_tasklet);
1150 * Unlock first since we might get a call back.
1152 spin_unlock(&host->lock);
1154 mmc_detect_change(host->mmc);
1156 else
1157 spin_unlock(&host->lock);
1160 static void wbsd_tasklet_fifo(unsigned long param)
1162 struct wbsd_host* host = (struct wbsd_host*)param;
1163 struct mmc_data* data;
1165 spin_lock(&host->lock);
1167 if (!host->mrq)
1168 goto end;
1170 data = wbsd_get_data(host);
1171 if (!data)
1172 goto end;
1174 if (data->flags & MMC_DATA_WRITE)
1175 wbsd_fill_fifo(host);
1176 else
1177 wbsd_empty_fifo(host);
1180 * Done?
1182 if (host->size == data->bytes_xfered)
1184 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0);
1185 tasklet_schedule(&host->finish_tasklet);
1188 end:
1189 spin_unlock(&host->lock);
1192 static void wbsd_tasklet_crc(unsigned long param)
1194 struct wbsd_host* host = (struct wbsd_host*)param;
1195 struct mmc_data* data;
1197 spin_lock(&host->lock);
1199 if (!host->mrq)
1200 goto end;
1202 data = wbsd_get_data(host);
1203 if (!data)
1204 goto end;
1206 DBGF("CRC error\n");
1208 data->error = MMC_ERR_BADCRC;
1210 tasklet_schedule(&host->finish_tasklet);
1212 end:
1213 spin_unlock(&host->lock);
1216 static void wbsd_tasklet_timeout(unsigned long param)
1218 struct wbsd_host* host = (struct wbsd_host*)param;
1219 struct mmc_data* data;
1221 spin_lock(&host->lock);
1223 if (!host->mrq)
1224 goto end;
1226 data = wbsd_get_data(host);
1227 if (!data)
1228 goto end;
1230 DBGF("Timeout\n");
1232 data->error = MMC_ERR_TIMEOUT;
1234 tasklet_schedule(&host->finish_tasklet);
1236 end:
1237 spin_unlock(&host->lock);
1240 static void wbsd_tasklet_finish(unsigned long param)
1242 struct wbsd_host* host = (struct wbsd_host*)param;
1243 struct mmc_data* data;
1245 spin_lock(&host->lock);
1247 WARN_ON(!host->mrq);
1248 if (!host->mrq)
1249 goto end;
1251 data = wbsd_get_data(host);
1252 if (!data)
1253 goto end;
1255 wbsd_finish_data(host, data);
1257 end:
1258 spin_unlock(&host->lock);
1261 static void wbsd_tasklet_block(unsigned long param)
1263 struct wbsd_host* host = (struct wbsd_host*)param;
1264 struct mmc_data* data;
1266 spin_lock(&host->lock);
1268 if ((wbsd_read_index(host, WBSD_IDX_CRCSTATUS) & WBSD_CRC_MASK) !=
1269 WBSD_CRC_OK)
1271 data = wbsd_get_data(host);
1272 if (!data)
1273 goto end;
1275 DBGF("CRC error\n");
1277 data->error = MMC_ERR_BADCRC;
1279 tasklet_schedule(&host->finish_tasklet);
1282 end:
1283 spin_unlock(&host->lock);
1287 * Interrupt handling
1290 static irqreturn_t wbsd_irq(int irq, void *dev_id, struct pt_regs *regs)
1292 struct wbsd_host* host = dev_id;
1293 int isr;
1295 isr = inb(host->base + WBSD_ISR);
1298 * Was it actually our hardware that caused the interrupt?
1300 if (isr == 0xff || isr == 0x00)
1301 return IRQ_NONE;
1303 host->isr |= isr;
1306 * Schedule tasklets as needed.
1308 if (isr & WBSD_INT_CARD)
1309 tasklet_schedule(&host->card_tasklet);
1310 if (isr & WBSD_INT_FIFO_THRE)
1311 tasklet_schedule(&host->fifo_tasklet);
1312 if (isr & WBSD_INT_CRC)
1313 tasklet_hi_schedule(&host->crc_tasklet);
1314 if (isr & WBSD_INT_TIMEOUT)
1315 tasklet_hi_schedule(&host->timeout_tasklet);
1316 if (isr & WBSD_INT_BUSYEND)
1317 tasklet_hi_schedule(&host->block_tasklet);
1318 if (isr & WBSD_INT_TC)
1319 tasklet_schedule(&host->finish_tasklet);
1321 return IRQ_HANDLED;
1324 /*****************************************************************************\
1326 * Device initialisation and shutdown *
1328 \*****************************************************************************/
1331 * Allocate/free MMC structure.
1334 static int __devinit wbsd_alloc_mmc(struct device* dev)
1336 struct mmc_host* mmc;
1337 struct wbsd_host* host;
1340 * Allocate MMC structure.
1342 mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev);
1343 if (!mmc)
1344 return -ENOMEM;
1346 host = mmc_priv(mmc);
1347 host->mmc = mmc;
1349 host->dma = -1;
1352 * Set host parameters.
1354 mmc->ops = &wbsd_ops;
1355 mmc->f_min = 375000;
1356 mmc->f_max = 24000000;
1357 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1359 spin_lock_init(&host->lock);
1362 * Set up timers
1364 init_timer(&host->detect_timer);
1365 host->detect_timer.data = (unsigned long)host;
1366 host->detect_timer.function = wbsd_detect_card;
1368 init_timer(&host->ignore_timer);
1369 host->ignore_timer.data = (unsigned long)host;
1370 host->ignore_timer.function = wbsd_reset_ignore;
1373 * Maximum number of segments. Worst case is one sector per segment
1374 * so this will be 64kB/512.
1376 mmc->max_hw_segs = 128;
1377 mmc->max_phys_segs = 128;
1380 * Maximum number of sectors in one transfer. Also limited by 64kB
1381 * buffer.
1383 mmc->max_sectors = 128;
1386 * Maximum segment size. Could be one segment with the maximum number
1387 * of segments.
1389 mmc->max_seg_size = mmc->max_sectors * 512;
1391 dev_set_drvdata(dev, mmc);
1393 return 0;
1396 static void __devexit wbsd_free_mmc(struct device* dev)
1398 struct mmc_host* mmc;
1399 struct wbsd_host* host;
1401 mmc = dev_get_drvdata(dev);
1402 if (!mmc)
1403 return;
1405 host = mmc_priv(mmc);
1406 BUG_ON(host == NULL);
1408 del_timer_sync(&host->ignore_timer);
1409 del_timer_sync(&host->detect_timer);
1411 mmc_free_host(mmc);
1413 dev_set_drvdata(dev, NULL);
1417 * Scan for known chip id:s
1420 static int __devinit wbsd_scan(struct wbsd_host* host)
1422 int i, j, k;
1423 int id;
1426 * Iterate through all ports, all codes to
1427 * find hardware that is in our known list.
1429 for (i = 0;i < sizeof(config_ports)/sizeof(int);i++)
1431 if (!request_region(config_ports[i], 2, DRIVER_NAME))
1432 continue;
1434 for (j = 0;j < sizeof(unlock_codes)/sizeof(int);j++)
1436 id = 0xFFFF;
1438 outb(unlock_codes[j], config_ports[i]);
1439 outb(unlock_codes[j], config_ports[i]);
1441 outb(WBSD_CONF_ID_HI, config_ports[i]);
1442 id = inb(config_ports[i] + 1) << 8;
1444 outb(WBSD_CONF_ID_LO, config_ports[i]);
1445 id |= inb(config_ports[i] + 1);
1447 for (k = 0;k < sizeof(valid_ids)/sizeof(int);k++)
1449 if (id == valid_ids[k])
1451 host->chip_id = id;
1452 host->config = config_ports[i];
1453 host->unlock_code = unlock_codes[i];
1455 return 0;
1459 if (id != 0xFFFF)
1461 DBG("Unknown hardware (id %x) found at %x\n",
1462 id, config_ports[i]);
1465 outb(LOCK_CODE, config_ports[i]);
1468 release_region(config_ports[i], 2);
1471 return -ENODEV;
1475 * Allocate/free io port ranges
1478 static int __devinit wbsd_request_region(struct wbsd_host* host, int base)
1480 if (io & 0x7)
1481 return -EINVAL;
1483 if (!request_region(base, 8, DRIVER_NAME))
1484 return -EIO;
1486 host->base = io;
1488 return 0;
1491 static void __devexit wbsd_release_regions(struct wbsd_host* host)
1493 if (host->base)
1494 release_region(host->base, 8);
1496 host->base = 0;
1498 if (host->config)
1499 release_region(host->config, 2);
1501 host->config = 0;
1505 * Allocate/free DMA port and buffer
1508 static void __devinit wbsd_request_dma(struct wbsd_host* host, int dma)
1510 if (dma < 0)
1511 return;
1513 if (request_dma(dma, DRIVER_NAME))
1514 goto err;
1517 * We need to allocate a special buffer in
1518 * order for ISA to be able to DMA to it.
1520 host->dma_buffer = kmalloc(WBSD_DMA_SIZE,
1521 GFP_NOIO | GFP_DMA | __GFP_REPEAT | __GFP_NOWARN);
1522 if (!host->dma_buffer)
1523 goto free;
1526 * Translate the address to a physical address.
1528 host->dma_addr = dma_map_single(host->mmc->dev, host->dma_buffer,
1529 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1532 * ISA DMA must be aligned on a 64k basis.
1534 if ((host->dma_addr & 0xffff) != 0)
1535 goto kfree;
1537 * ISA cannot access memory above 16 MB.
1539 else if (host->dma_addr >= 0x1000000)
1540 goto kfree;
1542 host->dma = dma;
1544 return;
1546 kfree:
1548 * If we've gotten here then there is some kind of alignment bug
1550 BUG_ON(1);
1552 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
1553 DMA_BIDIRECTIONAL);
1554 host->dma_addr = (dma_addr_t)NULL;
1556 kfree(host->dma_buffer);
1557 host->dma_buffer = NULL;
1559 free:
1560 free_dma(dma);
1562 err:
1563 printk(KERN_WARNING DRIVER_NAME ": Unable to allocate DMA %d. "
1564 "Falling back on FIFO.\n", dma);
1567 static void __devexit wbsd_release_dma(struct wbsd_host* host)
1569 if (host->dma_addr)
1570 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
1571 DMA_BIDIRECTIONAL);
1572 if (host->dma_buffer)
1573 kfree(host->dma_buffer);
1574 if (host->dma >= 0)
1575 free_dma(host->dma);
1577 host->dma = -1;
1578 host->dma_buffer = NULL;
1579 host->dma_addr = (dma_addr_t)NULL;
1583 * Allocate/free IRQ.
1586 static int __devinit wbsd_request_irq(struct wbsd_host* host, int irq)
1588 int ret;
1591 * Allocate interrupt.
1594 ret = request_irq(irq, wbsd_irq, SA_SHIRQ, DRIVER_NAME, host);
1595 if (ret)
1596 return ret;
1598 host->irq = irq;
1601 * Set up tasklets.
1603 tasklet_init(&host->card_tasklet, wbsd_tasklet_card, (unsigned long)host);
1604 tasklet_init(&host->fifo_tasklet, wbsd_tasklet_fifo, (unsigned long)host);
1605 tasklet_init(&host->crc_tasklet, wbsd_tasklet_crc, (unsigned long)host);
1606 tasklet_init(&host->timeout_tasklet, wbsd_tasklet_timeout, (unsigned long)host);
1607 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish, (unsigned long)host);
1608 tasklet_init(&host->block_tasklet, wbsd_tasklet_block, (unsigned long)host);
1610 return 0;
1613 static void __devexit wbsd_release_irq(struct wbsd_host* host)
1615 if (!host->irq)
1616 return;
1618 free_irq(host->irq, host);
1620 host->irq = 0;
1622 tasklet_kill(&host->card_tasklet);
1623 tasklet_kill(&host->fifo_tasklet);
1624 tasklet_kill(&host->crc_tasklet);
1625 tasklet_kill(&host->timeout_tasklet);
1626 tasklet_kill(&host->finish_tasklet);
1627 tasklet_kill(&host->block_tasklet);
1631 * Allocate all resources for the host.
1634 static int __devinit wbsd_request_resources(struct wbsd_host* host,
1635 int base, int irq, int dma)
1637 int ret;
1640 * Allocate I/O ports.
1642 ret = wbsd_request_region(host, base);
1643 if (ret)
1644 return ret;
1647 * Allocate interrupt.
1649 ret = wbsd_request_irq(host, irq);
1650 if (ret)
1651 return ret;
1654 * Allocate DMA.
1656 wbsd_request_dma(host, dma);
1658 return 0;
1662 * Release all resources for the host.
1665 static void __devexit wbsd_release_resources(struct wbsd_host* host)
1667 wbsd_release_dma(host);
1668 wbsd_release_irq(host);
1669 wbsd_release_regions(host);
1673 * Configure the resources the chip should use.
1676 static void __devinit wbsd_chip_config(struct wbsd_host* host)
1679 * Reset the chip.
1681 wbsd_write_config(host, WBSD_CONF_SWRST, 1);
1682 wbsd_write_config(host, WBSD_CONF_SWRST, 0);
1685 * Select SD/MMC function.
1687 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1690 * Set up card detection.
1692 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11);
1695 * Configure chip
1697 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8);
1698 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff);
1700 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq);
1702 if (host->dma >= 0)
1703 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma);
1706 * Enable and power up chip.
1708 wbsd_write_config(host, WBSD_CONF_ENABLE, 1);
1709 wbsd_write_config(host, WBSD_CONF_POWER, 0x20);
1713 * Check that configured resources are correct.
1716 static int __devinit wbsd_chip_validate(struct wbsd_host* host)
1718 int base, irq, dma;
1721 * Select SD/MMC function.
1723 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1726 * Read configuration.
1728 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8;
1729 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO);
1731 irq = wbsd_read_config(host, WBSD_CONF_IRQ);
1733 dma = wbsd_read_config(host, WBSD_CONF_DRQ);
1736 * Validate against given configuration.
1738 if (base != host->base)
1739 return 0;
1740 if (irq != host->irq)
1741 return 0;
1742 if ((dma != host->dma) && (host->dma != -1))
1743 return 0;
1745 return 1;
1748 /*****************************************************************************\
1750 * Devices setup and shutdown *
1752 \*****************************************************************************/
1754 static int __devinit wbsd_init(struct device* dev, int base, int irq, int dma,
1755 int pnp)
1757 struct wbsd_host* host = NULL;
1758 struct mmc_host* mmc = NULL;
1759 int ret;
1761 ret = wbsd_alloc_mmc(dev);
1762 if (ret)
1763 return ret;
1765 mmc = dev_get_drvdata(dev);
1766 host = mmc_priv(mmc);
1769 * Scan for hardware.
1771 ret = wbsd_scan(host);
1772 if (ret)
1774 if (pnp && (ret == -ENODEV))
1776 printk(KERN_WARNING DRIVER_NAME
1777 ": Unable to confirm device presence. You may "
1778 "experience lock-ups.\n");
1780 else
1782 wbsd_free_mmc(dev);
1783 return ret;
1788 * Request resources.
1790 ret = wbsd_request_resources(host, io, irq, dma);
1791 if (ret)
1793 wbsd_release_resources(host);
1794 wbsd_free_mmc(dev);
1795 return ret;
1799 * See if chip needs to be configured.
1801 if (pnp && (host->config != 0))
1803 if (!wbsd_chip_validate(host))
1805 printk(KERN_WARNING DRIVER_NAME
1806 ": PnP active but chip not configured! "
1807 "You probably have a buggy BIOS. "
1808 "Configuring chip manually.\n");
1809 wbsd_chip_config(host);
1812 else
1813 wbsd_chip_config(host);
1816 * Power Management stuff. No idea how this works.
1817 * Not tested.
1819 #ifdef CONFIG_PM
1820 if (host->config)
1821 wbsd_write_config(host, WBSD_CONF_PME, 0xA0);
1822 #endif
1824 * Allow device to initialise itself properly.
1826 mdelay(5);
1829 * Reset the chip into a known state.
1831 wbsd_init_device(host);
1833 mmc_add_host(mmc);
1835 printk(KERN_INFO "%s: W83L51xD", mmc_hostname(mmc));
1836 if (host->chip_id != 0)
1837 printk(" id %x", (int)host->chip_id);
1838 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
1839 if (host->dma >= 0)
1840 printk(" dma %d", (int)host->dma);
1841 else
1842 printk(" FIFO");
1843 if (pnp)
1844 printk(" PnP");
1845 printk("\n");
1847 return 0;
1850 static void __devexit wbsd_shutdown(struct device* dev, int pnp)
1852 struct mmc_host* mmc = dev_get_drvdata(dev);
1853 struct wbsd_host* host;
1855 if (!mmc)
1856 return;
1858 host = mmc_priv(mmc);
1860 mmc_remove_host(mmc);
1862 if (!pnp)
1865 * Power down the SD/MMC function.
1867 wbsd_unlock_config(host);
1868 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1869 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1870 wbsd_lock_config(host);
1873 wbsd_release_resources(host);
1875 wbsd_free_mmc(dev);
1879 * Non-PnP
1882 static int __devinit wbsd_probe(struct device* dev)
1884 return wbsd_init(dev, io, irq, dma, 0);
1887 static int __devexit wbsd_remove(struct device* dev)
1889 wbsd_shutdown(dev, 0);
1891 return 0;
1895 * PnP
1898 #ifdef CONFIG_PNP
1900 static int __devinit
1901 wbsd_pnp_probe(struct pnp_dev * pnpdev, const struct pnp_device_id *dev_id)
1903 int io, irq, dma;
1906 * Get resources from PnP layer.
1908 io = pnp_port_start(pnpdev, 0);
1909 irq = pnp_irq(pnpdev, 0);
1910 if (pnp_dma_valid(pnpdev, 0))
1911 dma = pnp_dma(pnpdev, 0);
1912 else
1913 dma = -1;
1915 DBGF("PnP resources: port %3x irq %d dma %d\n", io, irq, dma);
1917 return wbsd_init(&pnpdev->dev, io, irq, dma, 1);
1920 static void __devexit wbsd_pnp_remove(struct pnp_dev * dev)
1922 wbsd_shutdown(&dev->dev, 1);
1925 #endif /* CONFIG_PNP */
1928 * Power management
1931 #ifdef CONFIG_PM
1932 static int wbsd_suspend(struct device *dev, pm_message_t state, u32 level)
1934 DBGF("Not yet supported\n");
1936 return 0;
1939 static int wbsd_resume(struct device *dev, u32 level)
1941 DBGF("Not yet supported\n");
1943 return 0;
1945 #else
1946 #define wbsd_suspend NULL
1947 #define wbsd_resume NULL
1948 #endif
1950 static struct platform_device *wbsd_device;
1952 static struct device_driver wbsd_driver = {
1953 .name = DRIVER_NAME,
1954 .bus = &platform_bus_type,
1955 .probe = wbsd_probe,
1956 .remove = wbsd_remove,
1958 .suspend = wbsd_suspend,
1959 .resume = wbsd_resume,
1962 #ifdef CONFIG_PNP
1964 static struct pnp_driver wbsd_pnp_driver = {
1965 .name = DRIVER_NAME,
1966 .id_table = pnp_dev_table,
1967 .probe = wbsd_pnp_probe,
1968 .remove = wbsd_pnp_remove,
1971 #endif /* CONFIG_PNP */
1974 * Module loading/unloading
1977 static int __init wbsd_drv_init(void)
1979 int result;
1981 printk(KERN_INFO DRIVER_NAME
1982 ": Winbond W83L51xD SD/MMC card interface driver, "
1983 DRIVER_VERSION "\n");
1984 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1986 #ifdef CONFIG_PNP
1988 if (!nopnp)
1990 result = pnp_register_driver(&wbsd_pnp_driver);
1991 if (result < 0)
1992 return result;
1995 #endif /* CONFIG_PNP */
1997 if (nopnp)
1999 result = driver_register(&wbsd_driver);
2000 if (result < 0)
2001 return result;
2003 wbsd_device = platform_device_register_simple(DRIVER_NAME, -1,
2004 NULL, 0);
2005 if (IS_ERR(wbsd_device))
2006 return PTR_ERR(wbsd_device);
2009 return 0;
2012 static void __exit wbsd_drv_exit(void)
2014 #ifdef CONFIG_PNP
2016 if (!nopnp)
2017 pnp_unregister_driver(&wbsd_pnp_driver);
2019 #endif /* CONFIG_PNP */
2021 if (nopnp)
2023 platform_device_unregister(wbsd_device);
2025 driver_unregister(&wbsd_driver);
2028 DBG("unloaded\n");
2031 module_init(wbsd_drv_init);
2032 module_exit(wbsd_drv_exit);
2033 #ifdef CONFIG_PNP
2034 module_param(nopnp, uint, 0444);
2035 #endif
2036 module_param(io, uint, 0444);
2037 module_param(irq, uint, 0444);
2038 module_param(dma, int, 0444);
2040 MODULE_LICENSE("GPL");
2041 MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver");
2042 MODULE_VERSION(DRIVER_VERSION);
2044 #ifdef CONFIG_PNP
2045 MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)");
2046 #endif
2047 MODULE_PARM_DESC(io, "I/O base to allocate. Must be 8 byte aligned. (default 0x248)");
2048 MODULE_PARM_DESC(irq, "IRQ to allocate. (default 6)");
2049 MODULE_PARM_DESC(dma, "DMA channel to allocate. -1 for no DMA. (default 2)");