blob: 86e4a1a3c6426d4524a79effd9310fa48c7bc2e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services.
3 *
Yoichi Yuasaada8e952009-07-03 00:39:38 +09004 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/types.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010026#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/io.h>
29
30#include <pcmcia/ss.h>
31
32#include "i82365.h"
33
34MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services");
Yoichi Yuasaada8e952009-07-03 00:39:38 +090035MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070036MODULE_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
87typedef 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
95typedef enum {
96 SLOTB_IS_NONE,
97 SLOTB_IS_PCCARD,
98 SLOTB_IS_CF,
99 SLOTB_IS_FLASHROM,
100} vrc4171_slotb_t;
101
102typedef 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;
Yoichi Yuasa7a410e82010-03-10 15:57:56 +0900108 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109} vrc4171_socket_t;
110
111static vrc4171_socket_t vrc4171_sockets[CARD_MAX_SLOTS];
112static vrc4171_slotb_t vrc4171_slotb = SLOTB_IS_NONE;
113static char vrc4171_card_name[] = "NEC VRC4171 Card Controller";
114static unsigned int vrc4171_irq;
115static uint16_t vrc4171_irq_mask = 0xdeb8;
116
117static 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
132static 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
139static inline uint16_t vrc4171_get_irq_status(void)
140{
141 return inw(INTERRUPT_STATUS);
142}
143
144static 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
171static 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
180static 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
196static 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
207static 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
221static 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
235static 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
250 return 0;
251}
252
253static int pccard_get_status(struct pcmcia_socket *sock, u_int *value)
254{
255 unsigned int slot;
256 uint8_t status, sense;
257 u_int val = 0;
258
259 if (sock == NULL || sock->sock >= CARD_MAX_SLOTS || value == NULL)
260 return -EINVAL;
261
262 slot = sock->sock;
263
264 status = exca_read_byte(slot, I365_STATUS);
265 if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
266 if (status & I365_CS_STSCHG)
267 val |= SS_STSCHG;
268 } else {
269 if (!(status & I365_CS_BVD1))
270 val |= SS_BATDEAD;
271 else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
272 val |= SS_BATWARN;
273 }
274 if ((status & I365_CS_DETECT) == I365_CS_DETECT)
275 val |= SS_DETECT;
276 if (status & I365_CS_WRPROT)
277 val |= SS_WRPROT;
278 if (status & I365_CS_READY)
279 val |= SS_READY;
280 if (status & I365_CS_POWERON)
281 val |= SS_POWERON;
282
283 sense = exca_read_byte(slot, CARD_VOLTAGE_SENSE);
284 switch (sense) {
285 case VCC_3VORXV_CAPABLE:
286 val |= SS_3VCARD | SS_XVCARD;
287 break;
288 case VCC_XV_ONLY:
289 val |= SS_XVCARD;
290 break;
291 case VCC_3V_CAPABLE:
292 val |= SS_3VCARD;
293 break;
294 default:
295 /* 5V only */
296 break;
297 }
298
299 *value = val;
300
301 return 0;
302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304static inline uint8_t set_Vcc_value(u_char Vcc)
305{
306 switch (Vcc) {
307 case 33:
308 return VCC_3V;
309 case 50:
310 return VCC_5V;
311 }
312
313 /* Small voltage is chosen for safety. */
314 return VCC_3V;
315}
316
317static int pccard_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
318{
319 vrc4171_socket_t *socket;
320 unsigned int slot;
321 uint8_t voltage, power, control, cscint;
322
323 if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
324 (state->Vpp != state->Vcc && state->Vpp != 0) ||
325 (state->Vcc != 50 && state->Vcc != 33 && state->Vcc != 0))
326 return -EINVAL;
327
328 slot = sock->sock;
329 socket = &vrc4171_sockets[slot];
330
Yoichi Yuasa7a410e82010-03-10 15:57:56 +0900331 spin_lock_irq(&socket->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 voltage = set_Vcc_value(state->Vcc);
334 exca_write_byte(slot, CARD_VOLTAGE_SELECT, voltage);
335
336 power = POWER_ENABLE;
337 if (state->Vpp == state->Vcc)
338 power |= VPP_GET_VCC;
339 if (state->flags & SS_OUTPUT_ENA)
340 power |= I365_PWR_OUT;
341 exca_write_byte(slot, I365_POWER, power);
342
343 control = 0;
344 if (state->io_irq != 0)
345 control |= socket->io_irq;
346 if (state->flags & SS_IOCARD)
347 control |= I365_PC_IOCARD;
348 if (state->flags & SS_RESET)
349 control &= ~I365_PC_RESET;
350 else
351 control |= I365_PC_RESET;
352 exca_write_byte(slot, I365_INTCTL, control);
353
354 cscint = 0;
355 exca_write_byte(slot, I365_CSCINT, cscint);
356 exca_read_byte(slot, I365_CSC); /* clear CardStatus change */
357 if (state->csc_mask != 0)
358 cscint |= socket->csc_irq << 8;
359 if (state->flags & SS_IOCARD) {
360 if (state->csc_mask & SS_STSCHG)
361 cscint |= I365_CSC_STSCHG;
362 } else {
363 if (state->csc_mask & SS_BATDEAD)
364 cscint |= I365_CSC_BVD1;
365 if (state->csc_mask & SS_BATWARN)
366 cscint |= I365_CSC_BVD2;
367 }
368 if (state->csc_mask & SS_READY)
369 cscint |= I365_CSC_READY;
370 if (state->csc_mask & SS_DETECT)
371 cscint |= I365_CSC_DETECT;
372 exca_write_byte(slot, I365_CSCINT, cscint);
373
Yoichi Yuasa7a410e82010-03-10 15:57:56 +0900374 spin_unlock_irq(&socket->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 return 0;
377}
378
379static int pccard_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
380{
381 unsigned int slot;
382 uint8_t ioctl, addrwin;
383 u_char map;
384
385 if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
386 io == NULL || io->map >= IO_MAX_MAPS ||
387 io->start > 0xffff || io->stop > 0xffff || io->start > io->stop)
388 return -EINVAL;
389
390 slot = sock->sock;
391 map = io->map;
392
393 addrwin = exca_read_byte(slot, I365_ADDRWIN);
394 if (addrwin & I365_ENA_IO(map)) {
395 addrwin &= ~I365_ENA_IO(map);
396 exca_write_byte(slot, I365_ADDRWIN, addrwin);
397 }
398
399 exca_write_word(slot, I365_IO(map)+I365_W_START, io->start);
400 exca_write_word(slot, I365_IO(map)+I365_W_STOP, io->stop);
401
402 ioctl = 0;
403 if (io->speed > 0)
404 ioctl |= I365_IOCTL_WAIT(map);
405 if (io->flags & MAP_16BIT)
406 ioctl |= I365_IOCTL_16BIT(map);
407 if (io->flags & MAP_AUTOSZ)
408 ioctl |= I365_IOCTL_IOCS16(map);
409 if (io->flags & MAP_0WS)
410 ioctl |= I365_IOCTL_0WS(map);
411 exca_write_byte(slot, I365_IOCTL, ioctl);
412
413 if (io->flags & MAP_ACTIVE) {
414 addrwin |= I365_ENA_IO(map);
415 exca_write_byte(slot, I365_ADDRWIN, addrwin);
416 }
417
418 return 0;
419}
420
421static int pccard_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
422{
423 unsigned int slot;
424 uint16_t start, stop, offset;
425 uint8_t addrwin;
426 u_char map;
427
428 if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
429 mem == NULL || mem->map >= MEM_MAX_MAPS ||
430 mem->res->start < CARD_MEM_START || mem->res->start > CARD_MEM_END ||
431 mem->res->end < CARD_MEM_START || mem->res->end > CARD_MEM_END ||
432 mem->res->start > mem->res->end ||
433 mem->card_start > CARD_MAX_MEM_OFFSET ||
434 mem->speed > CARD_MAX_MEM_SPEED)
435 return -EINVAL;
436
437 slot = sock->sock;
438 map = mem->map;
439
440 addrwin = exca_read_byte(slot, I365_ADDRWIN);
441 if (addrwin & I365_ENA_MEM(map)) {
442 addrwin &= ~I365_ENA_MEM(map);
443 exca_write_byte(slot, I365_ADDRWIN, addrwin);
444 }
445
446 start = (mem->res->start >> 12) & 0x3fff;
447 if (mem->flags & MAP_16BIT)
448 start |= I365_MEM_16BIT;
449 exca_write_word(slot, I365_MEM(map)+I365_W_START, start);
450
451 stop = (mem->res->end >> 12) & 0x3fff;
452 switch (mem->speed) {
453 case 0:
454 break;
455 case 1:
456 stop |= I365_MEM_WS0;
457 break;
458 case 2:
459 stop |= I365_MEM_WS1;
460 break;
461 default:
462 stop |= I365_MEM_WS0 | I365_MEM_WS1;
463 break;
464 }
465 exca_write_word(slot, I365_MEM(map)+I365_W_STOP, stop);
466
467 offset = (mem->card_start >> 12) & 0x3fff;
468 if (mem->flags & MAP_ATTRIB)
469 offset |= I365_MEM_REG;
470 if (mem->flags & MAP_WRPROT)
471 offset |= I365_MEM_WRPROT;
472 exca_write_word(slot, I365_MEM(map)+I365_W_OFF, offset);
473
474 if (mem->flags & MAP_ACTIVE) {
475 addrwin |= I365_ENA_MEM(map);
476 exca_write_byte(slot, I365_ADDRWIN, addrwin);
477 }
478
479 return 0;
480}
481
482static struct pccard_operations vrc4171_pccard_operations = {
483 .init = pccard_init,
484 .get_status = pccard_get_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .set_socket = pccard_set_socket,
486 .set_io_map = pccard_set_io_map,
487 .set_mem_map = pccard_set_mem_map,
488};
489
490static inline unsigned int get_events(int slot)
491{
492 unsigned int events = 0;
493 uint8_t status, csc;
494
495 status = exca_read_byte(slot, I365_STATUS);
496 csc = exca_read_byte(slot, I365_CSC);
497
498 if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
499 if ((csc & I365_CSC_STSCHG) && (status & I365_CS_STSCHG))
500 events |= SS_STSCHG;
501 } else {
502 if (csc & (I365_CSC_BVD1 | I365_CSC_BVD2)) {
503 if (!(status & I365_CS_BVD1))
504 events |= SS_BATDEAD;
505 else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
506 events |= SS_BATWARN;
507 }
508 }
509 if ((csc & I365_CSC_READY) && (status & I365_CS_READY))
510 events |= SS_READY;
511 if ((csc & I365_CSC_DETECT) && ((status & I365_CS_DETECT) == I365_CS_DETECT))
512 events |= SS_DETECT;
513
514 return events;
515}
516
David Howells7d12e782006-10-05 14:55:46 +0100517static irqreturn_t pccard_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
519 vrc4171_socket_t *socket;
520 unsigned int events;
521 irqreturn_t retval = IRQ_NONE;
522 uint16_t status;
523
524 status = vrc4171_get_irq_status();
525 if (status & IRQ_A) {
526 socket = &vrc4171_sockets[CARD_SLOTA];
527 if (socket->slot == SLOT_INITIALIZED) {
528 if (status & (1 << socket->csc_irq)) {
529 events = get_events(CARD_SLOTA);
530 if (events != 0) {
531 pcmcia_parse_events(&socket->pcmcia_socket, events);
532 retval = IRQ_HANDLED;
533 }
534 }
535 }
536 }
537
538 if (status & IRQ_B) {
539 socket = &vrc4171_sockets[CARD_SLOTB];
540 if (socket->slot == SLOT_INITIALIZED) {
541 if (status & (1 << socket->csc_irq)) {
542 events = get_events(CARD_SLOTB);
543 if (events != 0) {
544 pcmcia_parse_events(&socket->pcmcia_socket, events);
545 retval = IRQ_HANDLED;
546 }
547 }
548 }
549 }
550
551 return retval;
552}
553
554static inline void reserve_using_irq(int slot)
555{
556 unsigned int irq;
557
558 irq = exca_read_byte(slot, I365_INTCTL);
559 irq &= 0x0f;
560 vrc4171_irq_mask &= ~(1 << irq);
561
562 irq = exca_read_byte(slot, I365_CSCINT);
563 irq = (irq & 0xf0) >> 4;
564 vrc4171_irq_mask &= ~(1 << irq);
565}
566
567static int __devinit vrc4171_add_sockets(void)
568{
569 vrc4171_socket_t *socket;
570 int slot, retval;
571
572 for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
573 if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
574 continue;
575
576 socket = &vrc4171_sockets[slot];
577 if (socket->slot != SLOT_PROBE) {
578 uint8_t addrwin;
579
580 switch (socket->slot) {
581 case SLOT_NOPROBE_MEM:
582 addrwin = exca_read_byte(slot, I365_ADDRWIN);
583 addrwin &= 0x1f;
584 exca_write_byte(slot, I365_ADDRWIN, addrwin);
585 break;
586 case SLOT_NOPROBE_IO:
587 addrwin = exca_read_byte(slot, I365_ADDRWIN);
588 addrwin &= 0xc0;
589 exca_write_byte(slot, I365_ADDRWIN, addrwin);
590 break;
591 default:
592 break;
593 }
594
595 reserve_using_irq(slot);
596 continue;
597 }
598
599 sprintf(socket->name, "NEC VRC4171 Card Slot %1c", 'A' + slot);
Manuel Laussdfe461a2007-02-21 14:47:20 +0100600 socket->pcmcia_socket.dev.parent = &vrc4171_card_device.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 socket->pcmcia_socket.ops = &vrc4171_pccard_operations;
602 socket->pcmcia_socket.owner = THIS_MODULE;
603
604 retval = pcmcia_register_socket(&socket->pcmcia_socket);
605 if (retval < 0)
606 return retval;
607
608 exca_write_byte(slot, I365_ADDRWIN, 0);
609 exca_write_byte(slot, GLOBAL_CONTROL, 0);
610
611 socket->slot = SLOT_INITIALIZED;
612 }
613
614 return 0;
615}
616
617static void vrc4171_remove_sockets(void)
618{
619 vrc4171_socket_t *socket;
620 int slot;
621
622 for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
623 if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
624 continue;
625
626 socket = &vrc4171_sockets[slot];
627 if (socket->slot == SLOT_INITIALIZED)
628 pcmcia_unregister_socket(&socket->pcmcia_socket);
629
630 socket->slot = SLOT_PROBE;
631 }
632}
633
634static int __devinit vrc4171_card_setup(char *options)
635{
636 if (options == NULL || *options == '\0')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800637 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 if (strncmp(options, "irq:", 4) == 0) {
640 int irq;
641 options += 4;
642 irq = simple_strtoul(options, &options, 0);
Yinghai Lu9130add2008-08-19 20:49:52 -0700643 if (irq >= 0 && irq < nr_irqs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 vrc4171_irq = irq;
645
646 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800647 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 options++;
649 }
650
651 if (strncmp(options, "slota:", 6) == 0) {
652 options += 6;
653 if (*options != '\0') {
654 if (strncmp(options, "memnoprobe", 10) == 0) {
655 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_MEM;
656 options += 10;
657 } else if (strncmp(options, "ionoprobe", 9) == 0) {
658 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_IO;
659 options += 9;
660 } else if ( strncmp(options, "noprobe", 7) == 0) {
661 vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_ALL;
662 options += 7;
663 }
664
665 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800666 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 options++;
668 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800669 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 }
672
673 if (strncmp(options, "slotb:", 6) == 0) {
674 options += 6;
675 if (*options != '\0') {
676 if (strncmp(options, "pccard", 6) == 0) {
677 vrc4171_slotb = SLOTB_IS_PCCARD;
678 options += 6;
679 } else if (strncmp(options, "cf", 2) == 0) {
680 vrc4171_slotb = SLOTB_IS_CF;
681 options += 2;
682 } else if (strncmp(options, "flashrom", 8) == 0) {
683 vrc4171_slotb = SLOTB_IS_FLASHROM;
684 options += 8;
685 } else if (strncmp(options, "none", 4) == 0) {
686 vrc4171_slotb = SLOTB_IS_NONE;
687 options += 4;
688 }
689
690 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800691 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 options++;
693
694 if (strncmp(options, "memnoprobe", 10) == 0)
695 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_MEM;
696 if (strncmp(options, "ionoprobe", 9) == 0)
697 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_IO;
698 if (strncmp(options, "noprobe", 7) == 0)
699 vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_ALL;
700 }
701 }
702
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800703 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
705
706__setup("vrc4171_card=", vrc4171_card_setup);
707
Ming Lei7a192ec2009-02-06 23:40:12 +0800708static struct platform_driver vrc4171_card_driver = {
709 .driver = {
710 .name = vrc4171_card_name,
711 .owner = THIS_MODULE,
712 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713};
714
715static int __devinit vrc4171_card_init(void)
716{
717 int retval;
718
Ming Lei7a192ec2009-02-06 23:40:12 +0800719 retval = platform_driver_register(&vrc4171_card_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (retval < 0)
721 return retval;
722
723 retval = platform_device_register(&vrc4171_card_device);
724 if (retval < 0) {
Ming Lei7a192ec2009-02-06 23:40:12 +0800725 platform_driver_unregister(&vrc4171_card_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return retval;
727 }
728
729 vrc4171_set_multifunction_pin(vrc4171_slotb);
730
731 retval = vrc4171_add_sockets();
732 if (retval == 0)
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700733 retval = request_irq(vrc4171_irq, pccard_interrupt, IRQF_SHARED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 vrc4171_card_name, vrc4171_sockets);
735
736 if (retval < 0) {
737 vrc4171_remove_sockets();
738 platform_device_unregister(&vrc4171_card_device);
Ming Lei7a192ec2009-02-06 23:40:12 +0800739 platform_driver_unregister(&vrc4171_card_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return retval;
741 }
742
Ming Lei7a192ec2009-02-06 23:40:12 +0800743 printk(KERN_INFO "%s, connected to IRQ %d\n",
744 vrc4171_card_driver.driver.name, vrc4171_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 return 0;
747}
748
749static void __devexit vrc4171_card_exit(void)
750{
751 free_irq(vrc4171_irq, vrc4171_sockets);
752 vrc4171_remove_sockets();
753 platform_device_unregister(&vrc4171_card_device);
Ming Lei7a192ec2009-02-06 23:40:12 +0800754 platform_driver_unregister(&vrc4171_card_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757module_init(vrc4171_card_init);
758module_exit(vrc4171_card_exit);