Merge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / pcmcia / vrc4171_card.c
1 /*
2  * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services.
3  *
4  * Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@linux-mips.org>
5  *
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
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include <linux/init.h>
21 #include <linux/ioport.h>
22 #include <linux/interrupt.h>
23 #include <linux/module.h>
24 #include <linux/spinlock.h>
25 #include <linux/types.h>
26 #include <linux/platform_device.h>
27
28 #include <asm/io.h>
29
30 #include <pcmcia/ss.h>
31
32 #include "i82365.h"
33
34 MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services");
35 MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
36 MODULE_LICENSE("GPL");
37
38 #define CARD_MAX_SLOTS          2
39 #define CARD_SLOTA              0
40 #define CARD_SLOTB              1
41 #define CARD_SLOTB_OFFSET       0x40
42
43 #define CARD_MEM_START          0x10000000
44 #define CARD_MEM_END            0x13ffffff
45 #define CARD_MAX_MEM_OFFSET     0x3ffffff
46 #define CARD_MAX_MEM_SPEED      1000
47
48 #define CARD_CONTROLLER_INDEX   0x03e0
49 #define CARD_CONTROLLER_DATA    0x03e1
50  /* Power register */
51   #define VPP_GET_VCC           0x01
52   #define POWER_ENABLE          0x10
53  #define CARD_VOLTAGE_SENSE     0x1f
54   #define VCC_3VORXV_CAPABLE    0x00
55   #define VCC_XV_ONLY           0x01
56   #define VCC_3V_CAPABLE        0x02
57   #define VCC_5V_ONLY           0x03
58  #define CARD_VOLTAGE_SELECT    0x2f
59   #define VCC_3V                0x01
60   #define VCC_5V                0x00
61   #define VCC_XV                0x02
62   #define VCC_STATUS_3V         0x02
63   #define VCC_STATUS_5V         0x01
64   #define VCC_STATUS_XV         0x03
65  #define GLOBAL_CONTROL         0x1e
66   #define EXWRBK                0x04
67   #define IRQPM_EN              0x08
68   #define CLRPMIRQ              0x10
69
70 #define INTERRUPT_STATUS        0x05fa
71  #define IRQ_A                  0x02
72  #define IRQ_B                  0x04
73
74 #define CONFIGURATION1          0x05fe
75  #define SLOTB_CONFIG           0xc000
76  #define SLOTB_NONE             0x0000
77  #define SLOTB_PCCARD           0x4000
78  #define SLOTB_CF               0x8000
79  #define SLOTB_FLASHROM         0xc000
80
81 #define CARD_CONTROLLER_START   CARD_CONTROLLER_INDEX
82 #define CARD_CONTROLLER_END     CARD_CONTROLLER_DATA
83
84 #define IO_MAX_MAPS     2
85 #define MEM_MAX_MAPS    5
86
87 typedef enum {
88         SLOT_PROBE = 0,
89         SLOT_NOPROBE_IO,
90         SLOT_NOPROBE_MEM,
91         SLOT_NOPROBE_ALL,
92         SLOT_INITIALIZED,
93 } vrc4171_slot_t;
94
95 typedef enum {
96         SLOTB_IS_NONE,
97         SLOTB_IS_PCCARD,
98         SLOTB_IS_CF,
99         SLOTB_IS_FLASHROM,
100 } vrc4171_slotb_t;
101
102 typedef struct vrc4171_socket {
103         vrc4171_slot_t slot;
104         struct pcmcia_socket pcmcia_socket;
105         char name[24];
106         int csc_irq;
107         int io_irq;
108         spinlock_t lock;
109 } vrc4171_socket_t;
110
111 static vrc4171_socket_t vrc4171_sockets[CARD_MAX_SLOTS];
112 static vrc4171_slotb_t vrc4171_slotb = SLOTB_IS_NONE;
113 static char vrc4171_card_name[] = "NEC VRC4171 Card Controller";
114 static unsigned int vrc4171_irq;
115 static uint16_t vrc4171_irq_mask = 0xdeb8;
116
117 static struct resource vrc4171_card_resource[3] = {
118         {       .name           = vrc4171_card_name,
119                 .start          = CARD_CONTROLLER_START,
120                 .end            = CARD_CONTROLLER_END,
121                 .flags          = IORESOURCE_IO,        },
122         {       .name           = vrc4171_card_name,
123                 .start          = INTERRUPT_STATUS,
124                 .end            = INTERRUPT_STATUS,
125                 .flags          = IORESOURCE_IO,        },
126         {       .name           = vrc4171_card_name,
127                 .start          = CONFIGURATION1,
128                 .end            = CONFIGURATION1,
129                 .flags          = IORESOURCE_IO,        },
130 };
131
132 static struct platform_device vrc4171_card_device = {
133         .name           = vrc4171_card_name,
134         .id             = 0,
135         .num_resources  = 3,
136         .resource       = vrc4171_card_resource,
137 };
138
139 static inline uint16_t vrc4171_get_irq_status(void)
140 {
141         return inw(INTERRUPT_STATUS);
142 }
143
144 static inline void vrc4171_set_multifunction_pin(vrc4171_slotb_t config)
145 {
146         uint16_t config1;
147
148         config1 = inw(CONFIGURATION1);
149         config1 &= ~SLOTB_CONFIG;
150
151         switch (config) {
152         case SLOTB_IS_NONE:
153                 config1 |= SLOTB_NONE;
154                 break;
155         case SLOTB_IS_PCCARD:
156                 config1 |= SLOTB_PCCARD;
157                 break;
158         case SLOTB_IS_CF:
159                 config1 |= SLOTB_CF;
160                 break;
161         case SLOTB_IS_FLASHROM:
162                 config1 |= SLOTB_FLASHROM;
163                 break;
164         default:
165                 break;
166         }
167
168         outw(config1, CONFIGURATION1);
169 }
170
171 static inline uint8_t exca_read_byte(int slot, uint8_t index)
172 {
173         if (slot == CARD_SLOTB)
174                 index += CARD_SLOTB_OFFSET;
175
176         outb(index, CARD_CONTROLLER_INDEX);
177         return inb(CARD_CONTROLLER_DATA);
178 }
179
180 static inline uint16_t exca_read_word(int slot, uint8_t index)
181 {
182         uint16_t data;
183
184         if (slot == CARD_SLOTB)
185                 index += CARD_SLOTB_OFFSET;
186
187         outb(index++, CARD_CONTROLLER_INDEX);
188         data = inb(CARD_CONTROLLER_DATA);
189
190         outb(index, CARD_CONTROLLER_INDEX);
191         data |= ((uint16_t)inb(CARD_CONTROLLER_DATA)) << 8;
192
193         return data;
194 }
195
196 static inline uint8_t exca_write_byte(int slot, uint8_t index, uint8_t data)
197 {
198         if (slot == CARD_SLOTB)
199                 index += CARD_SLOTB_OFFSET;
200
201         outb(index, CARD_CONTROLLER_INDEX);
202         outb(data, CARD_CONTROLLER_DATA);
203
204         return data;
205 }
206
207 static inline uint16_t exca_write_word(int slot, uint8_t index, uint16_t data)
208 {
209         if (slot == CARD_SLOTB)
210                 index += CARD_SLOTB_OFFSET;
211
212         outb(index++, CARD_CONTROLLER_INDEX);
213         outb(data, CARD_CONTROLLER_DATA);
214
215         outb(index, CARD_CONTROLLER_INDEX);
216         outb((uint8_t)(data >> 8), CARD_CONTROLLER_DATA);
217
218         return data;
219 }
220
221 static inline int search_nonuse_irq(void)
222 {
223         int i;
224
225         for (i = 0; i < 16; i++) {
226                 if (vrc4171_irq_mask & (1 << i)) {
227                         vrc4171_irq_mask &= ~(1 << i);
228                         return i;
229                 }
230         }
231
232         return -1;
233 }
234
235 static int pccard_init(struct pcmcia_socket *sock)
236 {
237         vrc4171_socket_t *socket;
238         unsigned int slot;
239
240         sock->features |= SS_CAP_PCCARD | SS_CAP_PAGE_REGS;
241         sock->irq_mask = 0;
242         sock->map_size = 0x1000;
243         sock->pci_irq = vrc4171_irq;
244
245         slot = sock->sock;
246         socket = &vrc4171_sockets[slot];
247         socket->csc_irq = search_nonuse_irq();
248         socket->io_irq = search_nonuse_irq();
249         spin_lock_init(&socket->lock);
250
251         return 0;
252 }
253
254 static int pccard_get_status(struct pcmcia_socket *sock, u_int *value)
255 {
256         unsigned int slot;
257         uint8_t status, sense;
258         u_int val = 0;
259
260         if (sock == NULL || sock->sock >= CARD_MAX_SLOTS || value == NULL)
261                 return -EINVAL;
262
263         slot = sock->sock;
264
265         status = exca_read_byte(slot, I365_STATUS);
266         if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
267                 if (status & I365_CS_STSCHG)
268                         val |= SS_STSCHG;
269         } else {
270                 if (!(status & I365_CS_BVD1))
271                         val |= SS_BATDEAD;
272                 else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
273                         val |= SS_BATWARN;
274         }
275         if ((status & I365_CS_DETECT) == I365_CS_DETECT)
276                 val |= SS_DETECT;
277         if (status & I365_CS_WRPROT)
278                 val |= SS_WRPROT;
279         if (status & I365_CS_READY)
280                 val |= SS_READY;
281         if (status & I365_CS_POWERON)
282                 val |= SS_POWERON;
283
284         sense = exca_read_byte(slot, CARD_VOLTAGE_SENSE);
285         switch (sense) {
286         case VCC_3VORXV_CAPABLE:
287                 val |= SS_3VCARD | SS_XVCARD;
288                 break;
289         case VCC_XV_ONLY:
290                 val |= SS_XVCARD;
291                 break;
292         case VCC_3V_CAPABLE:
293                 val |= SS_3VCARD;
294                 break;
295         default:
296                 /* 5V only */
297                 break;
298         }
299
300         *value = val;
301
302         return 0;
303 }
304
305 static inline uint8_t set_Vcc_value(u_char Vcc)
306 {
307         switch (Vcc) {
308         case 33:
309                 return VCC_3V;
310         case 50:
311                 return VCC_5V;
312         }
313
314         /* Small voltage is chosen for safety. */
315         return VCC_3V;
316 }
317
318 static int pccard_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
319 {
320         vrc4171_socket_t *socket;
321         unsigned int slot;
322         uint8_t voltage, power, control, cscint;
323
324         if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
325             (state->Vpp != state->Vcc && state->Vpp != 0) ||
326             (state->Vcc != 50 && state->Vcc != 33 && state->Vcc != 0))
327                 return -EINVAL;
328
329         slot = sock->sock;
330         socket = &vrc4171_sockets[slot];
331
332         spin_lock_irq(&socket->lock);
333
334         voltage = set_Vcc_value(state->Vcc);
335         exca_write_byte(slot, CARD_VOLTAGE_SELECT, voltage);
336
337         power = POWER_ENABLE;
338         if (state->Vpp == state->Vcc)
339                 power |= VPP_GET_VCC;
340         if (state->flags & SS_OUTPUT_ENA)
341                 power |= I365_PWR_OUT;
342         exca_write_byte(slot, I365_POWER, power);
343
344         control = 0;
345         if (state->io_irq != 0)
346                 control |= socket->io_irq;
347         if (state->flags & SS_IOCARD)
348                 control |= I365_PC_IOCARD;
349         if (state->flags & SS_RESET)
350                 control &= ~I365_PC_RESET;
351         else
352                 control |= I365_PC_RESET;
353         exca_write_byte(slot, I365_INTCTL, control);
354
355         cscint = 0;
356         exca_write_byte(slot, I365_CSCINT, cscint);
357         exca_read_byte(slot, I365_CSC); /* clear CardStatus change */
358         if (state->csc_mask != 0)
359                 cscint |= socket->csc_irq << 8;
360         if (state->flags & SS_IOCARD) {
361                 if (state->csc_mask & SS_STSCHG)
362                         cscint |= I365_CSC_STSCHG;
363         } else {
364                 if (state->csc_mask & SS_BATDEAD)
365                         cscint |= I365_CSC_BVD1;
366                 if (state->csc_mask & SS_BATWARN)
367                         cscint |= I365_CSC_BVD2;
368         }
369         if (state->csc_mask & SS_READY)
370                 cscint |= I365_CSC_READY;
371         if (state->csc_mask & SS_DETECT)
372                 cscint |= I365_CSC_DETECT;
373         exca_write_byte(slot, I365_CSCINT, cscint);
374
375         spin_unlock_irq(&socket->lock);
376
377         return 0;
378 }
379
380 static int pccard_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
381 {
382         unsigned int slot;
383         uint8_t ioctl, addrwin;
384         u_char map;
385
386         if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
387             io == NULL || io->map >= IO_MAX_MAPS ||
388             io->start > 0xffff || io->stop > 0xffff || io->start > io->stop)
389                 return -EINVAL;
390
391         slot = sock->sock;
392         map = io->map;
393
394         addrwin = exca_read_byte(slot, I365_ADDRWIN);
395         if (addrwin & I365_ENA_IO(map)) {
396                 addrwin &= ~I365_ENA_IO(map);
397                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
398         }
399
400         exca_write_word(slot, I365_IO(map)+I365_W_START, io->start);
401         exca_write_word(slot, I365_IO(map)+I365_W_STOP, io->stop);
402
403         ioctl = 0;
404         if (io->speed > 0)
405                 ioctl |= I365_IOCTL_WAIT(map);
406         if (io->flags & MAP_16BIT)
407                 ioctl |= I365_IOCTL_16BIT(map);
408         if (io->flags & MAP_AUTOSZ)
409                 ioctl |= I365_IOCTL_IOCS16(map);
410         if (io->flags & MAP_0WS)
411                 ioctl |= I365_IOCTL_0WS(map);
412         exca_write_byte(slot, I365_IOCTL, ioctl);
413
414         if (io->flags & MAP_ACTIVE) {
415                 addrwin |= I365_ENA_IO(map);
416                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
417         }
418
419         return 0;
420 }
421
422 static int pccard_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
423 {
424         unsigned int slot;
425         uint16_t start, stop, offset;
426         uint8_t addrwin;
427         u_char map;
428
429         if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
430             mem == NULL || mem->map >= MEM_MAX_MAPS ||
431             mem->res->start < CARD_MEM_START || mem->res->start > CARD_MEM_END ||
432             mem->res->end < CARD_MEM_START || mem->res->end > CARD_MEM_END ||
433             mem->res->start > mem->res->end ||
434             mem->card_start > CARD_MAX_MEM_OFFSET ||
435             mem->speed > CARD_MAX_MEM_SPEED)
436                 return -EINVAL;
437
438         slot = sock->sock;
439         map = mem->map;
440
441         addrwin = exca_read_byte(slot, I365_ADDRWIN);
442         if (addrwin & I365_ENA_MEM(map)) {
443                 addrwin &= ~I365_ENA_MEM(map);
444                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
445         }
446
447         start = (mem->res->start >> 12) & 0x3fff;
448         if (mem->flags & MAP_16BIT)
449                 start |= I365_MEM_16BIT;
450         exca_write_word(slot, I365_MEM(map)+I365_W_START, start);
451
452         stop = (mem->res->end >> 12) & 0x3fff;
453         switch (mem->speed) {
454         case 0:
455                 break;
456         case 1:
457                 stop |= I365_MEM_WS0;
458                 break;
459         case 2:
460                 stop |= I365_MEM_WS1;
461                 break;
462         default:
463                 stop |= I365_MEM_WS0 | I365_MEM_WS1;
464                 break;
465         }
466         exca_write_word(slot, I365_MEM(map)+I365_W_STOP, stop);
467
468         offset = (mem->card_start >> 12) & 0x3fff;
469         if (mem->flags & MAP_ATTRIB)
470                 offset |= I365_MEM_REG;
471         if (mem->flags & MAP_WRPROT)
472                 offset |= I365_MEM_WRPROT;
473         exca_write_word(slot, I365_MEM(map)+I365_W_OFF, offset);
474
475         if (mem->flags & MAP_ACTIVE) {
476                 addrwin |= I365_ENA_MEM(map);
477                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
478         }
479
480         return 0;
481 }
482
483 static struct pccard_operations vrc4171_pccard_operations = {
484         .init                   = pccard_init,
485         .get_status             = pccard_get_status,
486         .set_socket             = pccard_set_socket,
487         .set_io_map             = pccard_set_io_map,
488         .set_mem_map            = pccard_set_mem_map,
489 };
490
491 static inline unsigned int get_events(int slot)
492 {
493         unsigned int events = 0;
494         uint8_t status, csc;
495
496         status = exca_read_byte(slot, I365_STATUS);
497         csc = exca_read_byte(slot, I365_CSC);
498
499         if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
500                 if ((csc & I365_CSC_STSCHG) && (status & I365_CS_STSCHG))
501                         events |= SS_STSCHG;
502         } else {
503                 if (csc & (I365_CSC_BVD1 | I365_CSC_BVD2)) {
504                         if (!(status & I365_CS_BVD1))
505                                 events |= SS_BATDEAD;
506                         else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
507                                 events |= SS_BATWARN;
508                 }
509         }
510         if ((csc & I365_CSC_READY) && (status & I365_CS_READY))
511                 events |= SS_READY;
512         if ((csc & I365_CSC_DETECT) && ((status & I365_CS_DETECT) == I365_CS_DETECT))
513                 events |= SS_DETECT;
514
515         return events;
516 }
517
518 static irqreturn_t pccard_interrupt(int irq, void *dev_id)
519 {
520         vrc4171_socket_t *socket;
521         unsigned int events;
522         irqreturn_t retval = IRQ_NONE;
523         uint16_t status;
524
525         status = vrc4171_get_irq_status();
526         if (status & IRQ_A) {
527                 socket = &vrc4171_sockets[CARD_SLOTA];
528                 if (socket->slot == SLOT_INITIALIZED) {
529                         if (status & (1 << socket->csc_irq)) {
530                                 events = get_events(CARD_SLOTA);
531                                 if (events != 0) {
532                                         pcmcia_parse_events(&socket->pcmcia_socket, events);
533                                         retval = IRQ_HANDLED;
534                                 }
535                         }
536                 }
537         }
538
539         if (status & IRQ_B) {
540                 socket = &vrc4171_sockets[CARD_SLOTB];
541                 if (socket->slot == SLOT_INITIALIZED) {
542                         if (status & (1 << socket->csc_irq)) {
543                                 events = get_events(CARD_SLOTB);
544                                 if (events != 0) {
545                                         pcmcia_parse_events(&socket->pcmcia_socket, events);
546                                         retval = IRQ_HANDLED;
547                                 }
548                         }
549                 }
550         }
551
552         return retval;
553 }
554
555 static inline void reserve_using_irq(int slot)
556 {
557         unsigned int irq;
558
559         irq = exca_read_byte(slot, I365_INTCTL);
560         irq &= 0x0f;
561         vrc4171_irq_mask &= ~(1 << irq);
562
563         irq = exca_read_byte(slot, I365_CSCINT);
564         irq = (irq & 0xf0) >> 4;
565         vrc4171_irq_mask &= ~(1 << irq);
566 }
567
568 static int vrc4171_add_sockets(void)
569 {
570         vrc4171_socket_t *socket;
571         int slot, retval;
572
573         for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
574                 if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
575                         continue;
576
577                 socket = &vrc4171_sockets[slot];
578                 if (socket->slot != SLOT_PROBE) {
579                         uint8_t addrwin;
580
581                         switch (socket->slot) {
582                         case SLOT_NOPROBE_MEM:
583                                 addrwin = exca_read_byte(slot, I365_ADDRWIN);
584                                 addrwin &= 0x1f;
585                                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
586                                 break;
587                         case SLOT_NOPROBE_IO:
588                                 addrwin = exca_read_byte(slot, I365_ADDRWIN);
589                                 addrwin &= 0xc0;
590                                 exca_write_byte(slot, I365_ADDRWIN, addrwin);
591                                 break;
592                         default:
593                                 break;
594                         }
595
596                         reserve_using_irq(slot);
597                         continue;
598                 }
599
600                 sprintf(socket->name, "NEC VRC4171 Card Slot %1c", 'A' + slot);
601                 socket->pcmcia_socket.dev.parent = &vrc4171_card_device.dev;
602                 socket->pcmcia_socket.ops = &vrc4171_pccard_operations;
603                 socket->pcmcia_socket.owner = THIS_MODULE;
604
605                 retval = pcmcia_register_socket(&socket->pcmcia_socket);
606                 if (retval < 0)
607                         return retval;
608
609                 exca_write_byte(slot, I365_ADDRWIN, 0);
610                 exca_write_byte(slot, GLOBAL_CONTROL, 0);
611
612                 socket->slot = SLOT_INITIALIZED;
613         }
614
615         return 0;
616 }
617
618 static void vrc4171_remove_sockets(void)
619 {
620         vrc4171_socket_t *socket;
621         int slot;
622
623         for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
624                 if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
625                         continue;
626
627                 socket = &vrc4171_sockets[slot];
628                 if (socket->slot == SLOT_INITIALIZED)
629                         pcmcia_unregister_socket(&socket->pcmcia_socket);
630
631                 socket->slot = SLOT_PROBE;
632         }
633 }
634
635 static int vrc4171_card_setup(char *options)
636 {
637         if (options == NULL || *options == '\0')
638                 return 1;
639
640         if (strncmp(options, "irq:", 4) == 0) {
641                 int irq;
642                 options += 4;
643                 irq = simple_strtoul(options, &options, 0);
644                 if (irq >= 0 && irq < nr_irqs)
645                         vrc4171_irq = irq;
646
647                 if (*options != ',')
648                         return 1;
649                 options++;
650         }
651
652         if (strncmp(options, "slota:", 6) == 0) {
653                 options += 6;
654                 if (*options != '\0') {
655                         if (strncmp(options, "memnoprobe", 10) == 0) {
656                                 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_MEM;
657                                 options += 10;
658                         } else if (strncmp(options, "ionoprobe", 9) == 0) {
659                                 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_IO;
660                                 options += 9;
661                         } else if ( strncmp(options, "noprobe", 7) == 0) {
662                                 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_ALL;
663                                 options += 7;
664                         }
665
666                         if (*options != ',')
667                                 return 1;
668                         options++;
669                 } else
670                         return 1;
671
672         }
673
674         if (strncmp(options, "slotb:", 6) == 0) {
675                 options += 6;
676                 if (*options != '\0') {
677                         if (strncmp(options, "pccard", 6) == 0) {
678                                 vrc4171_slotb = SLOTB_IS_PCCARD;
679                                 options += 6;
680                         } else if (strncmp(options, "cf", 2) == 0) {
681                                 vrc4171_slotb = SLOTB_IS_CF;
682                                 options += 2;
683                         } else if (strncmp(options, "flashrom", 8) == 0) {
684                                 vrc4171_slotb = SLOTB_IS_FLASHROM;
685                                 options += 8;
686                         } else if (strncmp(options, "none", 4) == 0) {
687                                 vrc4171_slotb = SLOTB_IS_NONE;
688                                 options += 4;
689                         }
690
691                         if (*options != ',')
692                                 return 1;
693                         options++;
694
695                         if (strncmp(options, "memnoprobe", 10) == 0)
696                                 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_MEM;
697                         if (strncmp(options, "ionoprobe", 9) == 0)
698                                 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_IO;
699                         if (strncmp(options, "noprobe", 7) == 0)
700                                 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_ALL;
701                 }
702         }
703
704         return 1;
705 }
706
707 __setup("vrc4171_card=", vrc4171_card_setup);
708
709 static struct platform_driver vrc4171_card_driver = {
710         .driver = {
711                 .name           = vrc4171_card_name,
712                 .owner          = THIS_MODULE,
713         },
714 };
715
716 static int vrc4171_card_init(void)
717 {
718         int retval;
719
720         retval = platform_driver_register(&vrc4171_card_driver);
721         if (retval < 0)
722                 return retval;
723
724         retval = platform_device_register(&vrc4171_card_device);
725         if (retval < 0) {
726                 platform_driver_unregister(&vrc4171_card_driver);
727                 return retval;
728         }
729
730         vrc4171_set_multifunction_pin(vrc4171_slotb);
731
732         retval = vrc4171_add_sockets();
733         if (retval == 0)
734                 retval = request_irq(vrc4171_irq, pccard_interrupt, IRQF_SHARED,
735                                      vrc4171_card_name, vrc4171_sockets);
736
737         if (retval < 0) {
738                 vrc4171_remove_sockets();
739                 platform_device_unregister(&vrc4171_card_device);
740                 platform_driver_unregister(&vrc4171_card_driver);
741                 return retval;
742         }
743
744         printk(KERN_INFO "%s, connected to IRQ %d\n",
745                 vrc4171_card_driver.driver.name, vrc4171_irq);
746
747         return 0;
748 }
749
750 static void vrc4171_card_exit(void)
751 {
752         free_irq(vrc4171_irq, vrc4171_sockets);
753         vrc4171_remove_sockets();
754         platform_device_unregister(&vrc4171_card_device);
755         platform_driver_unregister(&vrc4171_card_driver);
756 }
757
758 module_init(vrc4171_card_init);
759 module_exit(vrc4171_card_exit);