i2c: aspeed: Fix initial values of master and slave state
[linux/fpc-iii.git] / drivers / mmc / host / wbsd.c
blob1e54bbf13d75bb68bc8383655842353a74e8803b
1 /*
2 * linux/drivers/mmc/host/wbsd.c - Winbond W83L51xD SD/MMC driver
4 * Copyright (C) 2004-2007 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 as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
12 * Warning!
14 * Changes to the FIFO system should be done with extreme care since
15 * the hardware is full of bugs related to the FIFO. Known issues are:
17 * - FIFO size field in FSR is always zero.
19 * - FIFO interrupts tend not to work as they should. Interrupts are
20 * triggered only for full/empty events, not for threshold values.
22 * - On APIC systems the FIFO empty interrupt is sometimes lost.
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
29 #include <linux/platform_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/scatterlist.h>
37 #include <linux/slab.h>
39 #include <asm/io.h>
40 #include <asm/dma.h>
42 #include "wbsd.h"
44 #define DRIVER_NAME "wbsd"
46 #define DBG(x...) \
47 pr_debug(DRIVER_NAME ": " x)
48 #define DBGF(f, x...) \
49 pr_debug(DRIVER_NAME " [%s()]: " f, __func__ , ##x)
52 * Device resources
55 #ifdef CONFIG_PNP
57 static const struct pnp_device_id pnp_dev_table[] = {
58 { "WEC0517", 0 },
59 { "WEC0518", 0 },
60 { "", 0 },
63 MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
65 #endif /* CONFIG_PNP */
67 static const int config_ports[] = { 0x2E, 0x4E };
68 static const int unlock_codes[] = { 0x83, 0x87 };
70 static const int valid_ids[] = {
71 0x7112,
74 #ifdef CONFIG_PNP
75 static unsigned int param_nopnp = 0;
76 #else
77 static const unsigned int param_nopnp = 1;
78 #endif
79 static unsigned int param_io = 0x248;
80 static unsigned int param_irq = 6;
81 static int param_dma = 2;
84 * Basic functions
87 static inline void wbsd_unlock_config(struct wbsd_host *host)
89 BUG_ON(host->config == 0);
91 outb(host->unlock_code, host->config);
92 outb(host->unlock_code, host->config);
95 static inline void wbsd_lock_config(struct wbsd_host *host)
97 BUG_ON(host->config == 0);
99 outb(LOCK_CODE, host->config);
102 static inline void wbsd_write_config(struct wbsd_host *host, u8 reg, u8 value)
104 BUG_ON(host->config == 0);
106 outb(reg, host->config);
107 outb(value, host->config + 1);
110 static inline u8 wbsd_read_config(struct wbsd_host *host, u8 reg)
112 BUG_ON(host->config == 0);
114 outb(reg, host->config);
115 return inb(host->config + 1);
118 static inline void wbsd_write_index(struct wbsd_host *host, u8 index, u8 value)
120 outb(index, host->base + WBSD_IDXR);
121 outb(value, host->base + WBSD_DATAR);
124 static inline u8 wbsd_read_index(struct wbsd_host *host, u8 index)
126 outb(index, host->base + WBSD_IDXR);
127 return inb(host->base + WBSD_DATAR);
131 * Common routines
134 static void wbsd_init_device(struct wbsd_host *host)
136 u8 setup, ier;
139 * Reset chip (SD/MMC part) and fifo.
141 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
142 setup |= WBSD_FIFO_RESET | WBSD_SOFT_RESET;
143 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
146 * Set DAT3 to input
148 setup &= ~WBSD_DAT3_H;
149 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
150 host->flags &= ~WBSD_FIGNORE_DETECT;
153 * Read back default clock.
155 host->clk = wbsd_read_index(host, WBSD_IDX_CLK);
158 * Power down port.
160 outb(WBSD_POWER_N, host->base + WBSD_CSR);
163 * Set maximum timeout.
165 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F);
168 * Test for card presence
170 if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT)
171 host->flags |= WBSD_FCARD_PRESENT;
172 else
173 host->flags &= ~WBSD_FCARD_PRESENT;
176 * Enable interesting interrupts.
178 ier = 0;
179 ier |= WBSD_EINT_CARD;
180 ier |= WBSD_EINT_FIFO_THRE;
181 ier |= WBSD_EINT_CRC;
182 ier |= WBSD_EINT_TIMEOUT;
183 ier |= WBSD_EINT_TC;
185 outb(ier, host->base + WBSD_EIR);
188 * Clear interrupts.
190 inb(host->base + WBSD_ISR);
193 static void wbsd_reset(struct wbsd_host *host)
195 u8 setup;
197 pr_err("%s: Resetting chip\n", mmc_hostname(host->mmc));
200 * Soft reset of chip (SD/MMC part).
202 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
203 setup |= WBSD_SOFT_RESET;
204 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
207 static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
209 unsigned long dmaflags;
211 if (host->dma >= 0) {
213 * Release ISA DMA controller.
215 dmaflags = claim_dma_lock();
216 disable_dma(host->dma);
217 clear_dma_ff(host->dma);
218 release_dma_lock(dmaflags);
221 * Disable DMA on host.
223 wbsd_write_index(host, WBSD_IDX_DMA, 0);
226 host->mrq = NULL;
229 * MMC layer might call back into the driver so first unlock.
231 spin_unlock(&host->lock);
232 mmc_request_done(host->mmc, mrq);
233 spin_lock(&host->lock);
237 * Scatter/gather functions
240 static inline void wbsd_init_sg(struct wbsd_host *host, struct mmc_data *data)
243 * Get info. about SG list from data structure.
245 host->cur_sg = data->sg;
246 host->num_sg = data->sg_len;
248 host->offset = 0;
249 host->remain = host->cur_sg->length;
252 static inline int wbsd_next_sg(struct wbsd_host *host)
255 * Skip to next SG entry.
257 host->cur_sg++;
258 host->num_sg--;
261 * Any entries left?
263 if (host->num_sg > 0) {
264 host->offset = 0;
265 host->remain = host->cur_sg->length;
268 return host->num_sg;
271 static inline char *wbsd_map_sg(struct wbsd_host *host)
273 return kmap_atomic(sg_page(host->cur_sg)) + host->cur_sg->offset;
276 static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
278 size_t len = 0;
279 int i;
281 for (i = 0; i < data->sg_len; i++)
282 len += data->sg[i].length;
283 sg_copy_to_buffer(data->sg, data->sg_len, host->dma_buffer, len);
286 static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data)
288 size_t len = 0;
289 int i;
291 for (i = 0; i < data->sg_len; i++)
292 len += data->sg[i].length;
293 sg_copy_from_buffer(data->sg, data->sg_len, host->dma_buffer, len);
297 * Command handling
300 static inline void wbsd_get_short_reply(struct wbsd_host *host,
301 struct mmc_command *cmd)
304 * Correct response type?
306 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) {
307 cmd->error = -EILSEQ;
308 return;
311 cmd->resp[0] = wbsd_read_index(host, WBSD_IDX_RESP12) << 24;
312 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP13) << 16;
313 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP14) << 8;
314 cmd->resp[0] |= wbsd_read_index(host, WBSD_IDX_RESP15) << 0;
315 cmd->resp[1] = wbsd_read_index(host, WBSD_IDX_RESP16) << 24;
318 static inline void wbsd_get_long_reply(struct wbsd_host *host,
319 struct mmc_command *cmd)
321 int i;
324 * Correct response type?
326 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) {
327 cmd->error = -EILSEQ;
328 return;
331 for (i = 0; i < 4; i++) {
332 cmd->resp[i] =
333 wbsd_read_index(host, WBSD_IDX_RESP1 + i * 4) << 24;
334 cmd->resp[i] |=
335 wbsd_read_index(host, WBSD_IDX_RESP2 + i * 4) << 16;
336 cmd->resp[i] |=
337 wbsd_read_index(host, WBSD_IDX_RESP3 + i * 4) << 8;
338 cmd->resp[i] |=
339 wbsd_read_index(host, WBSD_IDX_RESP4 + i * 4) << 0;
343 static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
345 int i;
346 u8 status, isr;
349 * Clear accumulated ISR. The interrupt routine
350 * will fill this one with events that occur during
351 * transfer.
353 host->isr = 0;
356 * Send the command (CRC calculated by host).
358 outb(cmd->opcode, host->base + WBSD_CMDR);
359 for (i = 3; i >= 0; i--)
360 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
362 cmd->error = 0;
365 * Wait for the request to complete.
367 do {
368 status = wbsd_read_index(host, WBSD_IDX_STATUS);
369 } while (status & WBSD_CARDTRAFFIC);
372 * Do we expect a reply?
374 if (cmd->flags & MMC_RSP_PRESENT) {
376 * Read back status.
378 isr = host->isr;
380 /* Card removed? */
381 if (isr & WBSD_INT_CARD)
382 cmd->error = -ENOMEDIUM;
383 /* Timeout? */
384 else if (isr & WBSD_INT_TIMEOUT)
385 cmd->error = -ETIMEDOUT;
386 /* CRC? */
387 else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
388 cmd->error = -EILSEQ;
389 /* All ok */
390 else {
391 if (cmd->flags & MMC_RSP_136)
392 wbsd_get_long_reply(host, cmd);
393 else
394 wbsd_get_short_reply(host, cmd);
400 * Data functions
403 static void wbsd_empty_fifo(struct wbsd_host *host)
405 struct mmc_data *data = host->mrq->cmd->data;
406 char *buffer;
407 int i, idx, fsr, fifo;
410 * Handle excessive data.
412 if (host->num_sg == 0)
413 return;
415 buffer = wbsd_map_sg(host) + host->offset;
416 idx = 0;
419 * Drain the fifo. This has a tendency to loop longer
420 * than the FIFO length (usually one block).
422 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_EMPTY)) {
424 * The size field in the FSR is broken so we have to
425 * do some guessing.
427 if (fsr & WBSD_FIFO_FULL)
428 fifo = 16;
429 else if (fsr & WBSD_FIFO_FUTHRE)
430 fifo = 8;
431 else
432 fifo = 1;
434 for (i = 0; i < fifo; i++) {
435 buffer[idx++] = inb(host->base + WBSD_DFR);
436 host->offset++;
437 host->remain--;
439 data->bytes_xfered++;
442 * End of scatter list entry?
444 if (host->remain == 0) {
445 kunmap_atomic(buffer);
447 * Get next entry. Check if last.
449 if (!wbsd_next_sg(host))
450 return;
452 buffer = wbsd_map_sg(host);
453 idx = 0;
457 kunmap_atomic(buffer);
460 * This is a very dirty hack to solve a
461 * hardware problem. The chip doesn't trigger
462 * FIFO threshold interrupts properly.
464 if ((data->blocks * data->blksz - data->bytes_xfered) < 16)
465 tasklet_schedule(&host->fifo_tasklet);
468 static void wbsd_fill_fifo(struct wbsd_host *host)
470 struct mmc_data *data = host->mrq->cmd->data;
471 char *buffer;
472 int i, idx, fsr, fifo;
475 * Check that we aren't being called after the
476 * entire buffer has been transferred.
478 if (host->num_sg == 0)
479 return;
481 buffer = wbsd_map_sg(host) + host->offset;
482 idx = 0;
485 * Fill the fifo. This has a tendency to loop longer
486 * than the FIFO length (usually one block).
488 while (!((fsr = inb(host->base + WBSD_FSR)) & WBSD_FIFO_FULL)) {
490 * The size field in the FSR is broken so we have to
491 * do some guessing.
493 if (fsr & WBSD_FIFO_EMPTY)
494 fifo = 0;
495 else if (fsr & WBSD_FIFO_EMTHRE)
496 fifo = 8;
497 else
498 fifo = 15;
500 for (i = 16; i > fifo; i--) {
501 outb(buffer[idx], host->base + WBSD_DFR);
502 host->offset++;
503 host->remain--;
505 data->bytes_xfered++;
508 * End of scatter list entry?
510 if (host->remain == 0) {
511 kunmap_atomic(buffer);
513 * Get next entry. Check if last.
515 if (!wbsd_next_sg(host))
516 return;
518 buffer = wbsd_map_sg(host);
519 idx = 0;
523 kunmap_atomic(buffer);
526 * The controller stops sending interrupts for
527 * 'FIFO empty' under certain conditions. So we
528 * need to be a bit more pro-active.
530 tasklet_schedule(&host->fifo_tasklet);
533 static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
535 u16 blksize;
536 u8 setup;
537 unsigned long dmaflags;
538 unsigned int size;
541 * Calculate size.
543 size = data->blocks * data->blksz;
546 * Check timeout values for overflow.
547 * (Yes, some cards cause this value to overflow).
549 if (data->timeout_ns > 127000000)
550 wbsd_write_index(host, WBSD_IDX_TAAC, 127);
551 else {
552 wbsd_write_index(host, WBSD_IDX_TAAC,
553 data->timeout_ns / 1000000);
556 if (data->timeout_clks > 255)
557 wbsd_write_index(host, WBSD_IDX_NSAC, 255);
558 else
559 wbsd_write_index(host, WBSD_IDX_NSAC, data->timeout_clks);
562 * Inform the chip of how large blocks will be
563 * sent. It needs this to determine when to
564 * calculate CRC.
566 * Space for CRC must be included in the size.
567 * Two bytes are needed for each data line.
569 if (host->bus_width == MMC_BUS_WIDTH_1) {
570 blksize = data->blksz + 2;
572 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0);
573 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
574 } else if (host->bus_width == MMC_BUS_WIDTH_4) {
575 blksize = data->blksz + 2 * 4;
577 wbsd_write_index(host, WBSD_IDX_PBSMSB,
578 ((blksize >> 4) & 0xF0) | WBSD_DATA_WIDTH);
579 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
580 } else {
581 data->error = -EINVAL;
582 return;
586 * Clear the FIFO. This is needed even for DMA
587 * transfers since the chip still uses the FIFO
588 * internally.
590 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
591 setup |= WBSD_FIFO_RESET;
592 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
595 * DMA transfer?
597 if (host->dma >= 0) {
599 * The buffer for DMA is only 64 kB.
601 BUG_ON(size > 0x10000);
602 if (size > 0x10000) {
603 data->error = -EINVAL;
604 return;
608 * Transfer data from the SG list to
609 * the DMA buffer.
611 if (data->flags & MMC_DATA_WRITE)
612 wbsd_sg_to_dma(host, data);
615 * Initialise the ISA DMA controller.
617 dmaflags = claim_dma_lock();
618 disable_dma(host->dma);
619 clear_dma_ff(host->dma);
620 if (data->flags & MMC_DATA_READ)
621 set_dma_mode(host->dma, DMA_MODE_READ & ~0x40);
622 else
623 set_dma_mode(host->dma, DMA_MODE_WRITE & ~0x40);
624 set_dma_addr(host->dma, host->dma_addr);
625 set_dma_count(host->dma, size);
627 enable_dma(host->dma);
628 release_dma_lock(dmaflags);
631 * Enable DMA on the host.
633 wbsd_write_index(host, WBSD_IDX_DMA, WBSD_DMA_ENABLE);
634 } else {
636 * This flag is used to keep printk
637 * output to a minimum.
639 host->firsterr = 1;
642 * Initialise the SG list.
644 wbsd_init_sg(host, data);
647 * Turn off DMA.
649 wbsd_write_index(host, WBSD_IDX_DMA, 0);
652 * Set up FIFO threshold levels (and fill
653 * buffer if doing a write).
655 if (data->flags & MMC_DATA_READ) {
656 wbsd_write_index(host, WBSD_IDX_FIFOEN,
657 WBSD_FIFOEN_FULL | 8);
658 } else {
659 wbsd_write_index(host, WBSD_IDX_FIFOEN,
660 WBSD_FIFOEN_EMPTY | 8);
661 wbsd_fill_fifo(host);
665 data->error = 0;
668 static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
670 unsigned long dmaflags;
671 int count;
672 u8 status;
674 WARN_ON(host->mrq == NULL);
677 * Send a stop command if needed.
679 if (data->stop)
680 wbsd_send_command(host, data->stop);
683 * Wait for the controller to leave data
684 * transfer state.
686 do {
687 status = wbsd_read_index(host, WBSD_IDX_STATUS);
688 } while (status & (WBSD_BLOCK_READ | WBSD_BLOCK_WRITE));
691 * DMA transfer?
693 if (host->dma >= 0) {
695 * Disable DMA on the host.
697 wbsd_write_index(host, WBSD_IDX_DMA, 0);
700 * Turn of ISA DMA controller.
702 dmaflags = claim_dma_lock();
703 disable_dma(host->dma);
704 clear_dma_ff(host->dma);
705 count = get_dma_residue(host->dma);
706 release_dma_lock(dmaflags);
708 data->bytes_xfered = host->mrq->data->blocks *
709 host->mrq->data->blksz - count;
710 data->bytes_xfered -= data->bytes_xfered % data->blksz;
713 * Any leftover data?
715 if (count) {
716 pr_err("%s: Incomplete DMA transfer. "
717 "%d bytes left.\n",
718 mmc_hostname(host->mmc), count);
720 if (!data->error)
721 data->error = -EIO;
722 } else {
724 * Transfer data from DMA buffer to
725 * SG list.
727 if (data->flags & MMC_DATA_READ)
728 wbsd_dma_to_sg(host, data);
731 if (data->error) {
732 if (data->bytes_xfered)
733 data->bytes_xfered -= data->blksz;
737 wbsd_request_end(host, host->mrq);
740 /*****************************************************************************\
742 * MMC layer callbacks *
744 \*****************************************************************************/
746 static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
748 struct wbsd_host *host = mmc_priv(mmc);
749 struct mmc_command *cmd;
752 * Disable tasklets to avoid a deadlock.
754 spin_lock_bh(&host->lock);
756 BUG_ON(host->mrq != NULL);
758 cmd = mrq->cmd;
760 host->mrq = mrq;
763 * Check that there is actually a card in the slot.
765 if (!(host->flags & WBSD_FCARD_PRESENT)) {
766 cmd->error = -ENOMEDIUM;
767 goto done;
770 if (cmd->data) {
772 * The hardware is so delightfully stupid that it has a list
773 * of "data" commands. If a command isn't on this list, it'll
774 * just go back to the idle state and won't send any data
775 * interrupts.
777 switch (cmd->opcode) {
778 case 11:
779 case 17:
780 case 18:
781 case 20:
782 case 24:
783 case 25:
784 case 26:
785 case 27:
786 case 30:
787 case 42:
788 case 56:
789 break;
791 /* ACMDs. We don't keep track of state, so we just treat them
792 * like any other command. */
793 case 51:
794 break;
796 default:
797 pr_warn("%s: Data command %d is not supported by this controller\n",
798 mmc_hostname(host->mmc), cmd->opcode);
799 cmd->error = -EINVAL;
801 goto done;
806 * Does the request include data?
808 if (cmd->data) {
809 wbsd_prepare_data(host, cmd->data);
811 if (cmd->data->error)
812 goto done;
815 wbsd_send_command(host, cmd);
818 * If this is a data transfer the request
819 * will be finished after the data has
820 * transferred.
822 if (cmd->data && !cmd->error) {
824 * Dirty fix for hardware bug.
826 if (host->dma == -1)
827 tasklet_schedule(&host->fifo_tasklet);
829 spin_unlock_bh(&host->lock);
831 return;
834 done:
835 wbsd_request_end(host, mrq);
837 spin_unlock_bh(&host->lock);
840 static void wbsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
842 struct wbsd_host *host = mmc_priv(mmc);
843 u8 clk, setup, pwr;
845 spin_lock_bh(&host->lock);
848 * Reset the chip on each power off.
849 * Should clear out any weird states.
851 if (ios->power_mode == MMC_POWER_OFF)
852 wbsd_init_device(host);
854 if (ios->clock >= 24000000)
855 clk = WBSD_CLK_24M;
856 else if (ios->clock >= 16000000)
857 clk = WBSD_CLK_16M;
858 else if (ios->clock >= 12000000)
859 clk = WBSD_CLK_12M;
860 else
861 clk = WBSD_CLK_375K;
864 * Only write to the clock register when
865 * there is an actual change.
867 if (clk != host->clk) {
868 wbsd_write_index(host, WBSD_IDX_CLK, clk);
869 host->clk = clk;
873 * Power up card.
875 if (ios->power_mode != MMC_POWER_OFF) {
876 pwr = inb(host->base + WBSD_CSR);
877 pwr &= ~WBSD_POWER_N;
878 outb(pwr, host->base + WBSD_CSR);
882 * MMC cards need to have pin 1 high during init.
883 * It wreaks havoc with the card detection though so
884 * that needs to be disabled.
886 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
887 if (ios->chip_select == MMC_CS_HIGH) {
888 BUG_ON(ios->bus_width != MMC_BUS_WIDTH_1);
889 setup |= WBSD_DAT3_H;
890 host->flags |= WBSD_FIGNORE_DETECT;
891 } else {
892 if (setup & WBSD_DAT3_H) {
893 setup &= ~WBSD_DAT3_H;
896 * We cannot resume card detection immediately
897 * because of capacitance and delays in the chip.
899 mod_timer(&host->ignore_timer, jiffies + HZ / 100);
902 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
905 * Store bus width for later. Will be used when
906 * setting up the data transfer.
908 host->bus_width = ios->bus_width;
910 spin_unlock_bh(&host->lock);
913 static int wbsd_get_ro(struct mmc_host *mmc)
915 struct wbsd_host *host = mmc_priv(mmc);
916 u8 csr;
918 spin_lock_bh(&host->lock);
920 csr = inb(host->base + WBSD_CSR);
921 csr |= WBSD_MSLED;
922 outb(csr, host->base + WBSD_CSR);
924 mdelay(1);
926 csr = inb(host->base + WBSD_CSR);
927 csr &= ~WBSD_MSLED;
928 outb(csr, host->base + WBSD_CSR);
930 spin_unlock_bh(&host->lock);
932 return !!(csr & WBSD_WRPT);
935 static const struct mmc_host_ops wbsd_ops = {
936 .request = wbsd_request,
937 .set_ios = wbsd_set_ios,
938 .get_ro = wbsd_get_ro,
941 /*****************************************************************************\
943 * Interrupt handling *
945 \*****************************************************************************/
948 * Helper function to reset detection ignore
951 static void wbsd_reset_ignore(struct timer_list *t)
953 struct wbsd_host *host = from_timer(host, t, ignore_timer);
955 BUG_ON(host == NULL);
957 DBG("Resetting card detection ignore\n");
959 spin_lock_bh(&host->lock);
961 host->flags &= ~WBSD_FIGNORE_DETECT;
964 * Card status might have changed during the
965 * blackout.
967 tasklet_schedule(&host->card_tasklet);
969 spin_unlock_bh(&host->lock);
973 * Tasklets
976 static inline struct mmc_data *wbsd_get_data(struct wbsd_host *host)
978 WARN_ON(!host->mrq);
979 if (!host->mrq)
980 return NULL;
982 WARN_ON(!host->mrq->cmd);
983 if (!host->mrq->cmd)
984 return NULL;
986 WARN_ON(!host->mrq->cmd->data);
987 if (!host->mrq->cmd->data)
988 return NULL;
990 return host->mrq->cmd->data;
993 static void wbsd_tasklet_card(unsigned long param)
995 struct wbsd_host *host = (struct wbsd_host *)param;
996 u8 csr;
997 int delay = -1;
999 spin_lock(&host->lock);
1001 if (host->flags & WBSD_FIGNORE_DETECT) {
1002 spin_unlock(&host->lock);
1003 return;
1006 csr = inb(host->base + WBSD_CSR);
1007 WARN_ON(csr == 0xff);
1009 if (csr & WBSD_CARDPRESENT) {
1010 if (!(host->flags & WBSD_FCARD_PRESENT)) {
1011 DBG("Card inserted\n");
1012 host->flags |= WBSD_FCARD_PRESENT;
1014 delay = 500;
1016 } else if (host->flags & WBSD_FCARD_PRESENT) {
1017 DBG("Card removed\n");
1018 host->flags &= ~WBSD_FCARD_PRESENT;
1020 if (host->mrq) {
1021 pr_err("%s: Card removed during transfer!\n",
1022 mmc_hostname(host->mmc));
1023 wbsd_reset(host);
1025 host->mrq->cmd->error = -ENOMEDIUM;
1026 tasklet_schedule(&host->finish_tasklet);
1029 delay = 0;
1033 * Unlock first since we might get a call back.
1036 spin_unlock(&host->lock);
1038 if (delay != -1)
1039 mmc_detect_change(host->mmc, msecs_to_jiffies(delay));
1042 static void wbsd_tasklet_fifo(unsigned long param)
1044 struct wbsd_host *host = (struct wbsd_host *)param;
1045 struct mmc_data *data;
1047 spin_lock(&host->lock);
1049 if (!host->mrq)
1050 goto end;
1052 data = wbsd_get_data(host);
1053 if (!data)
1054 goto end;
1056 if (data->flags & MMC_DATA_WRITE)
1057 wbsd_fill_fifo(host);
1058 else
1059 wbsd_empty_fifo(host);
1062 * Done?
1064 if (host->num_sg == 0) {
1065 wbsd_write_index(host, WBSD_IDX_FIFOEN, 0);
1066 tasklet_schedule(&host->finish_tasklet);
1069 end:
1070 spin_unlock(&host->lock);
1073 static void wbsd_tasklet_crc(unsigned long param)
1075 struct wbsd_host *host = (struct wbsd_host *)param;
1076 struct mmc_data *data;
1078 spin_lock(&host->lock);
1080 if (!host->mrq)
1081 goto end;
1083 data = wbsd_get_data(host);
1084 if (!data)
1085 goto end;
1087 DBGF("CRC error\n");
1089 data->error = -EILSEQ;
1091 tasklet_schedule(&host->finish_tasklet);
1093 end:
1094 spin_unlock(&host->lock);
1097 static void wbsd_tasklet_timeout(unsigned long param)
1099 struct wbsd_host *host = (struct wbsd_host *)param;
1100 struct mmc_data *data;
1102 spin_lock(&host->lock);
1104 if (!host->mrq)
1105 goto end;
1107 data = wbsd_get_data(host);
1108 if (!data)
1109 goto end;
1111 DBGF("Timeout\n");
1113 data->error = -ETIMEDOUT;
1115 tasklet_schedule(&host->finish_tasklet);
1117 end:
1118 spin_unlock(&host->lock);
1121 static void wbsd_tasklet_finish(unsigned long param)
1123 struct wbsd_host *host = (struct wbsd_host *)param;
1124 struct mmc_data *data;
1126 spin_lock(&host->lock);
1128 WARN_ON(!host->mrq);
1129 if (!host->mrq)
1130 goto end;
1132 data = wbsd_get_data(host);
1133 if (!data)
1134 goto end;
1136 wbsd_finish_data(host, data);
1138 end:
1139 spin_unlock(&host->lock);
1143 * Interrupt handling
1146 static irqreturn_t wbsd_irq(int irq, void *dev_id)
1148 struct wbsd_host *host = dev_id;
1149 int isr;
1151 isr = inb(host->base + WBSD_ISR);
1154 * Was it actually our hardware that caused the interrupt?
1156 if (isr == 0xff || isr == 0x00)
1157 return IRQ_NONE;
1159 host->isr |= isr;
1162 * Schedule tasklets as needed.
1164 if (isr & WBSD_INT_CARD)
1165 tasklet_schedule(&host->card_tasklet);
1166 if (isr & WBSD_INT_FIFO_THRE)
1167 tasklet_schedule(&host->fifo_tasklet);
1168 if (isr & WBSD_INT_CRC)
1169 tasklet_hi_schedule(&host->crc_tasklet);
1170 if (isr & WBSD_INT_TIMEOUT)
1171 tasklet_hi_schedule(&host->timeout_tasklet);
1172 if (isr & WBSD_INT_TC)
1173 tasklet_schedule(&host->finish_tasklet);
1175 return IRQ_HANDLED;
1178 /*****************************************************************************\
1180 * Device initialisation and shutdown *
1182 \*****************************************************************************/
1185 * Allocate/free MMC structure.
1188 static int wbsd_alloc_mmc(struct device *dev)
1190 struct mmc_host *mmc;
1191 struct wbsd_host *host;
1194 * Allocate MMC structure.
1196 mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev);
1197 if (!mmc)
1198 return -ENOMEM;
1200 host = mmc_priv(mmc);
1201 host->mmc = mmc;
1203 host->dma = -1;
1206 * Set host parameters.
1208 mmc->ops = &wbsd_ops;
1209 mmc->f_min = 375000;
1210 mmc->f_max = 24000000;
1211 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1212 mmc->caps = MMC_CAP_4_BIT_DATA;
1214 spin_lock_init(&host->lock);
1217 * Set up timers
1219 timer_setup(&host->ignore_timer, wbsd_reset_ignore, 0);
1222 * Maximum number of segments. Worst case is one sector per segment
1223 * so this will be 64kB/512.
1225 mmc->max_segs = 128;
1228 * Maximum request size. Also limited by 64KiB buffer.
1230 mmc->max_req_size = 65536;
1233 * Maximum segment size. Could be one segment with the maximum number
1234 * of bytes.
1236 mmc->max_seg_size = mmc->max_req_size;
1239 * Maximum block size. We have 12 bits (= 4095) but have to subtract
1240 * space for CRC. So the maximum is 4095 - 4*2 = 4087.
1242 mmc->max_blk_size = 4087;
1245 * Maximum block count. There is no real limit so the maximum
1246 * request size will be the only restriction.
1248 mmc->max_blk_count = mmc->max_req_size;
1250 dev_set_drvdata(dev, mmc);
1252 return 0;
1255 static void wbsd_free_mmc(struct device *dev)
1257 struct mmc_host *mmc;
1258 struct wbsd_host *host;
1260 mmc = dev_get_drvdata(dev);
1261 if (!mmc)
1262 return;
1264 host = mmc_priv(mmc);
1265 BUG_ON(host == NULL);
1267 del_timer_sync(&host->ignore_timer);
1269 mmc_free_host(mmc);
1271 dev_set_drvdata(dev, NULL);
1275 * Scan for known chip id:s
1278 static int wbsd_scan(struct wbsd_host *host)
1280 int i, j, k;
1281 int id;
1284 * Iterate through all ports, all codes to
1285 * find hardware that is in our known list.
1287 for (i = 0; i < ARRAY_SIZE(config_ports); i++) {
1288 if (!request_region(config_ports[i], 2, DRIVER_NAME))
1289 continue;
1291 for (j = 0; j < ARRAY_SIZE(unlock_codes); j++) {
1292 id = 0xFFFF;
1294 host->config = config_ports[i];
1295 host->unlock_code = unlock_codes[j];
1297 wbsd_unlock_config(host);
1299 outb(WBSD_CONF_ID_HI, config_ports[i]);
1300 id = inb(config_ports[i] + 1) << 8;
1302 outb(WBSD_CONF_ID_LO, config_ports[i]);
1303 id |= inb(config_ports[i] + 1);
1305 wbsd_lock_config(host);
1307 for (k = 0; k < ARRAY_SIZE(valid_ids); k++) {
1308 if (id == valid_ids[k]) {
1309 host->chip_id = id;
1311 return 0;
1315 if (id != 0xFFFF) {
1316 DBG("Unknown hardware (id %x) found at %x\n",
1317 id, config_ports[i]);
1321 release_region(config_ports[i], 2);
1324 host->config = 0;
1325 host->unlock_code = 0;
1327 return -ENODEV;
1331 * Allocate/free io port ranges
1334 static int wbsd_request_region(struct wbsd_host *host, int base)
1336 if (base & 0x7)
1337 return -EINVAL;
1339 if (!request_region(base, 8, DRIVER_NAME))
1340 return -EIO;
1342 host->base = base;
1344 return 0;
1347 static void wbsd_release_regions(struct wbsd_host *host)
1349 if (host->base)
1350 release_region(host->base, 8);
1352 host->base = 0;
1354 if (host->config)
1355 release_region(host->config, 2);
1357 host->config = 0;
1361 * Allocate/free DMA port and buffer
1364 static void wbsd_request_dma(struct wbsd_host *host, int dma)
1366 if (dma < 0)
1367 return;
1369 if (request_dma(dma, DRIVER_NAME))
1370 goto err;
1373 * We need to allocate a special buffer in
1374 * order for ISA to be able to DMA to it.
1376 host->dma_buffer = kmalloc(WBSD_DMA_SIZE,
1377 GFP_NOIO | GFP_DMA | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
1378 if (!host->dma_buffer)
1379 goto free;
1382 * Translate the address to a physical address.
1384 host->dma_addr = dma_map_single(mmc_dev(host->mmc), host->dma_buffer,
1385 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1386 if (dma_mapping_error(mmc_dev(host->mmc), host->dma_addr))
1387 goto kfree;
1390 * ISA DMA must be aligned on a 64k basis.
1392 if ((host->dma_addr & 0xffff) != 0)
1393 goto unmap;
1395 * ISA cannot access memory above 16 MB.
1397 else if (host->dma_addr >= 0x1000000)
1398 goto unmap;
1400 host->dma = dma;
1402 return;
1404 unmap:
1406 * If we've gotten here then there is some kind of alignment bug
1408 BUG_ON(1);
1410 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
1411 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1412 host->dma_addr = 0;
1414 kfree:
1415 kfree(host->dma_buffer);
1416 host->dma_buffer = NULL;
1418 free:
1419 free_dma(dma);
1421 err:
1422 pr_warn(DRIVER_NAME ": Unable to allocate DMA %d - falling back on FIFO\n",
1423 dma);
1426 static void wbsd_release_dma(struct wbsd_host *host)
1429 * host->dma_addr is valid here iff host->dma_buffer is not NULL.
1431 if (host->dma_buffer) {
1432 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
1433 WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
1434 kfree(host->dma_buffer);
1436 if (host->dma >= 0)
1437 free_dma(host->dma);
1439 host->dma = -1;
1440 host->dma_buffer = NULL;
1441 host->dma_addr = 0;
1445 * Allocate/free IRQ.
1448 static int wbsd_request_irq(struct wbsd_host *host, int irq)
1450 int ret;
1453 * Set up tasklets. Must be done before requesting interrupt.
1455 tasklet_init(&host->card_tasklet, wbsd_tasklet_card,
1456 (unsigned long)host);
1457 tasklet_init(&host->fifo_tasklet, wbsd_tasklet_fifo,
1458 (unsigned long)host);
1459 tasklet_init(&host->crc_tasklet, wbsd_tasklet_crc,
1460 (unsigned long)host);
1461 tasklet_init(&host->timeout_tasklet, wbsd_tasklet_timeout,
1462 (unsigned long)host);
1463 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish,
1464 (unsigned long)host);
1467 * Allocate interrupt.
1469 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host);
1470 if (ret)
1471 return ret;
1473 host->irq = irq;
1475 return 0;
1478 static void wbsd_release_irq(struct wbsd_host *host)
1480 if (!host->irq)
1481 return;
1483 free_irq(host->irq, host);
1485 host->irq = 0;
1487 tasklet_kill(&host->card_tasklet);
1488 tasklet_kill(&host->fifo_tasklet);
1489 tasklet_kill(&host->crc_tasklet);
1490 tasklet_kill(&host->timeout_tasklet);
1491 tasklet_kill(&host->finish_tasklet);
1495 * Allocate all resources for the host.
1498 static int wbsd_request_resources(struct wbsd_host *host,
1499 int base, int irq, int dma)
1501 int ret;
1504 * Allocate I/O ports.
1506 ret = wbsd_request_region(host, base);
1507 if (ret)
1508 return ret;
1511 * Allocate interrupt.
1513 ret = wbsd_request_irq(host, irq);
1514 if (ret)
1515 return ret;
1518 * Allocate DMA.
1520 wbsd_request_dma(host, dma);
1522 return 0;
1526 * Release all resources for the host.
1529 static void wbsd_release_resources(struct wbsd_host *host)
1531 wbsd_release_dma(host);
1532 wbsd_release_irq(host);
1533 wbsd_release_regions(host);
1537 * Configure the resources the chip should use.
1540 static void wbsd_chip_config(struct wbsd_host *host)
1542 wbsd_unlock_config(host);
1545 * Reset the chip.
1547 wbsd_write_config(host, WBSD_CONF_SWRST, 1);
1548 wbsd_write_config(host, WBSD_CONF_SWRST, 0);
1551 * Select SD/MMC function.
1553 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1556 * Set up card detection.
1558 wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11);
1561 * Configure chip
1563 wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8);
1564 wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff);
1566 wbsd_write_config(host, WBSD_CONF_IRQ, host->irq);
1568 if (host->dma >= 0)
1569 wbsd_write_config(host, WBSD_CONF_DRQ, host->dma);
1572 * Enable and power up chip.
1574 wbsd_write_config(host, WBSD_CONF_ENABLE, 1);
1575 wbsd_write_config(host, WBSD_CONF_POWER, 0x20);
1577 wbsd_lock_config(host);
1581 * Check that configured resources are correct.
1584 static int wbsd_chip_validate(struct wbsd_host *host)
1586 int base, irq, dma;
1588 wbsd_unlock_config(host);
1591 * Select SD/MMC function.
1593 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1596 * Read configuration.
1598 base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8;
1599 base |= wbsd_read_config(host, WBSD_CONF_PORT_LO);
1601 irq = wbsd_read_config(host, WBSD_CONF_IRQ);
1603 dma = wbsd_read_config(host, WBSD_CONF_DRQ);
1605 wbsd_lock_config(host);
1608 * Validate against given configuration.
1610 if (base != host->base)
1611 return 0;
1612 if (irq != host->irq)
1613 return 0;
1614 if ((dma != host->dma) && (host->dma != -1))
1615 return 0;
1617 return 1;
1621 * Powers down the SD function
1624 static void wbsd_chip_poweroff(struct wbsd_host *host)
1626 wbsd_unlock_config(host);
1628 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1629 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1631 wbsd_lock_config(host);
1634 /*****************************************************************************\
1636 * Devices setup and shutdown *
1638 \*****************************************************************************/
1640 static int wbsd_init(struct device *dev, int base, int irq, int dma,
1641 int pnp)
1643 struct wbsd_host *host = NULL;
1644 struct mmc_host *mmc = NULL;
1645 int ret;
1647 ret = wbsd_alloc_mmc(dev);
1648 if (ret)
1649 return ret;
1651 mmc = dev_get_drvdata(dev);
1652 host = mmc_priv(mmc);
1655 * Scan for hardware.
1657 ret = wbsd_scan(host);
1658 if (ret) {
1659 if (pnp && (ret == -ENODEV)) {
1660 pr_warn(DRIVER_NAME ": Unable to confirm device presence - you may experience lock-ups\n");
1661 } else {
1662 wbsd_free_mmc(dev);
1663 return ret;
1668 * Request resources.
1670 ret = wbsd_request_resources(host, base, irq, dma);
1671 if (ret) {
1672 wbsd_release_resources(host);
1673 wbsd_free_mmc(dev);
1674 return ret;
1678 * See if chip needs to be configured.
1680 if (pnp) {
1681 if ((host->config != 0) && !wbsd_chip_validate(host)) {
1682 pr_warn(DRIVER_NAME ": PnP active but chip not configured! You probably have a buggy BIOS. Configuring chip manually.\n");
1683 wbsd_chip_config(host);
1685 } else
1686 wbsd_chip_config(host);
1689 * Power Management stuff. No idea how this works.
1690 * Not tested.
1692 #ifdef CONFIG_PM
1693 if (host->config) {
1694 wbsd_unlock_config(host);
1695 wbsd_write_config(host, WBSD_CONF_PME, 0xA0);
1696 wbsd_lock_config(host);
1698 #endif
1700 * Allow device to initialise itself properly.
1702 mdelay(5);
1705 * Reset the chip into a known state.
1707 wbsd_init_device(host);
1709 mmc_add_host(mmc);
1711 pr_info("%s: W83L51xD", mmc_hostname(mmc));
1712 if (host->chip_id != 0)
1713 printk(" id %x", (int)host->chip_id);
1714 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
1715 if (host->dma >= 0)
1716 printk(" dma %d", (int)host->dma);
1717 else
1718 printk(" FIFO");
1719 if (pnp)
1720 printk(" PnP");
1721 printk("\n");
1723 return 0;
1726 static void wbsd_shutdown(struct device *dev, int pnp)
1728 struct mmc_host *mmc = dev_get_drvdata(dev);
1729 struct wbsd_host *host;
1731 if (!mmc)
1732 return;
1734 host = mmc_priv(mmc);
1736 mmc_remove_host(mmc);
1739 * Power down the SD/MMC function.
1741 if (!pnp)
1742 wbsd_chip_poweroff(host);
1744 wbsd_release_resources(host);
1746 wbsd_free_mmc(dev);
1750 * Non-PnP
1753 static int wbsd_probe(struct platform_device *dev)
1755 /* Use the module parameters for resources */
1756 return wbsd_init(&dev->dev, param_io, param_irq, param_dma, 0);
1759 static int wbsd_remove(struct platform_device *dev)
1761 wbsd_shutdown(&dev->dev, 0);
1763 return 0;
1767 * PnP
1770 #ifdef CONFIG_PNP
1772 static int
1773 wbsd_pnp_probe(struct pnp_dev *pnpdev, const struct pnp_device_id *dev_id)
1775 int io, irq, dma;
1778 * Get resources from PnP layer.
1780 io = pnp_port_start(pnpdev, 0);
1781 irq = pnp_irq(pnpdev, 0);
1782 if (pnp_dma_valid(pnpdev, 0))
1783 dma = pnp_dma(pnpdev, 0);
1784 else
1785 dma = -1;
1787 DBGF("PnP resources: port %3x irq %d dma %d\n", io, irq, dma);
1789 return wbsd_init(&pnpdev->dev, io, irq, dma, 1);
1792 static void wbsd_pnp_remove(struct pnp_dev *dev)
1794 wbsd_shutdown(&dev->dev, 1);
1797 #endif /* CONFIG_PNP */
1800 * Power management
1803 #ifdef CONFIG_PM
1805 static int wbsd_platform_suspend(struct platform_device *dev,
1806 pm_message_t state)
1808 struct mmc_host *mmc = platform_get_drvdata(dev);
1809 struct wbsd_host *host;
1811 if (mmc == NULL)
1812 return 0;
1814 DBGF("Suspending...\n");
1816 host = mmc_priv(mmc);
1818 wbsd_chip_poweroff(host);
1819 return 0;
1822 static int wbsd_platform_resume(struct platform_device *dev)
1824 struct mmc_host *mmc = platform_get_drvdata(dev);
1825 struct wbsd_host *host;
1827 if (mmc == NULL)
1828 return 0;
1830 DBGF("Resuming...\n");
1832 host = mmc_priv(mmc);
1834 wbsd_chip_config(host);
1837 * Allow device to initialise itself properly.
1839 mdelay(5);
1841 wbsd_init_device(host);
1842 return 0;
1845 #ifdef CONFIG_PNP
1847 static int wbsd_pnp_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
1849 struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev);
1851 if (mmc == NULL)
1852 return 0;
1854 DBGF("Suspending...\n");
1855 return 0;
1858 static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
1860 struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev);
1861 struct wbsd_host *host;
1863 if (mmc == NULL)
1864 return 0;
1866 DBGF("Resuming...\n");
1868 host = mmc_priv(mmc);
1871 * See if chip needs to be configured.
1873 if (host->config != 0) {
1874 if (!wbsd_chip_validate(host)) {
1875 pr_warn(DRIVER_NAME ": PnP active but chip not configured! You probably have a buggy BIOS. Configuring chip manually.\n");
1876 wbsd_chip_config(host);
1881 * Allow device to initialise itself properly.
1883 mdelay(5);
1885 wbsd_init_device(host);
1886 return 0;
1889 #endif /* CONFIG_PNP */
1891 #else /* CONFIG_PM */
1893 #define wbsd_platform_suspend NULL
1894 #define wbsd_platform_resume NULL
1896 #define wbsd_pnp_suspend NULL
1897 #define wbsd_pnp_resume NULL
1899 #endif /* CONFIG_PM */
1901 static struct platform_device *wbsd_device;
1903 static struct platform_driver wbsd_driver = {
1904 .probe = wbsd_probe,
1905 .remove = wbsd_remove,
1907 .suspend = wbsd_platform_suspend,
1908 .resume = wbsd_platform_resume,
1909 .driver = {
1910 .name = DRIVER_NAME,
1914 #ifdef CONFIG_PNP
1916 static struct pnp_driver wbsd_pnp_driver = {
1917 .name = DRIVER_NAME,
1918 .id_table = pnp_dev_table,
1919 .probe = wbsd_pnp_probe,
1920 .remove = wbsd_pnp_remove,
1922 .suspend = wbsd_pnp_suspend,
1923 .resume = wbsd_pnp_resume,
1926 #endif /* CONFIG_PNP */
1929 * Module loading/unloading
1932 static int __init wbsd_drv_init(void)
1934 int result;
1936 pr_info(DRIVER_NAME
1937 ": Winbond W83L51xD SD/MMC card interface driver\n");
1938 pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1940 #ifdef CONFIG_PNP
1942 if (!param_nopnp) {
1943 result = pnp_register_driver(&wbsd_pnp_driver);
1944 if (result < 0)
1945 return result;
1947 #endif /* CONFIG_PNP */
1949 if (param_nopnp) {
1950 result = platform_driver_register(&wbsd_driver);
1951 if (result < 0)
1952 return result;
1954 wbsd_device = platform_device_alloc(DRIVER_NAME, -1);
1955 if (!wbsd_device) {
1956 platform_driver_unregister(&wbsd_driver);
1957 return -ENOMEM;
1960 result = platform_device_add(wbsd_device);
1961 if (result) {
1962 platform_device_put(wbsd_device);
1963 platform_driver_unregister(&wbsd_driver);
1964 return result;
1968 return 0;
1971 static void __exit wbsd_drv_exit(void)
1973 #ifdef CONFIG_PNP
1975 if (!param_nopnp)
1976 pnp_unregister_driver(&wbsd_pnp_driver);
1978 #endif /* CONFIG_PNP */
1980 if (param_nopnp) {
1981 platform_device_unregister(wbsd_device);
1983 platform_driver_unregister(&wbsd_driver);
1986 DBG("unloaded\n");
1989 module_init(wbsd_drv_init);
1990 module_exit(wbsd_drv_exit);
1991 #ifdef CONFIG_PNP
1992 module_param_hw_named(nopnp, param_nopnp, uint, other, 0444);
1993 #endif
1994 module_param_hw_named(io, param_io, uint, ioport, 0444);
1995 module_param_hw_named(irq, param_irq, uint, irq, 0444);
1996 module_param_hw_named(dma, param_dma, int, dma, 0444);
1998 MODULE_LICENSE("GPL");
1999 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
2000 MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver");
2002 #ifdef CONFIG_PNP
2003 MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)");
2004 #endif
2005 MODULE_PARM_DESC(io, "I/O base to allocate. Must be 8 byte aligned. (default 0x248)");
2006 MODULE_PARM_DESC(irq, "IRQ to allocate. (default 6)");
2007 MODULE_PARM_DESC(dma, "DMA channel to allocate. -1 for no DMA. (default 2)");