2 * drivers/pcmcia/m32r_cfc.c
4 * Device driver for the CFC functionality of M32R.
6 * Copyright (c) 2001, 2002, 2003, 2004
7 * Hiroyuki Kondo, Naoto Sugai, Hayato Fujiwara
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/init.h>
13 #include <linux/config.h>
14 #include <linux/types.h>
15 #include <linux/fcntl.h>
16 #include <linux/string.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/timer.h>
20 #include <linux/sched.h>
21 #include <linux/slab.h>
22 #include <linux/ioport.h>
23 #include <linux/delay.h>
24 #include <linux/workqueue.h>
25 #include <linux/interrupt.h>
26 #include <linux/device.h>
29 #include <asm/bitops.h>
30 #include <asm/system.h>
32 #include <pcmcia/version.h>
33 #include <pcmcia/cs_types.h>
34 #include <pcmcia/ss.h>
35 #include <pcmcia/cs.h>
37 #undef MAX_IO_WIN /* FIXME */
39 #undef MAX_WIN /* FIXME */
45 static int m32r_cfc_debug
;
46 module_param(m32r_cfc_debug
, int, 0644);
47 #define debug(lvl, fmt, arg...) do { \
48 if (m32r_cfc_debug > (lvl)) \
49 printk(KERN_DEBUG "m32r_cfc: " fmt , ## arg); \
52 #define debug(n, args...) do { } while (0)
55 /* Poll status interval -- 0 means default to interrupt */
56 static int poll_interval
= 0;
58 typedef enum pcc_space
{ as_none
= 0, as_comm
, as_attr
, as_io
} pcc_as_t
;
60 typedef struct pcc_socket
{
62 struct pcmcia_socket socket
;
66 u_long base
; /* PCC register base */
67 u_char cs_irq1
, cs_irq2
, intr
;
68 pccard_io_map io_map
[MAX_IO_WIN
];
69 pccard_mem_map mem_map
[MAX_WIN
];
72 pcc_as_t current_space
;
75 struct proc_dir_entry
*proc
;
79 static int pcc_sockets
= 0;
80 static pcc_socket_t socket
[M32R_MAX_PCC
] = {
84 /*====================================================================*/
86 static unsigned int pcc_get(u_short
, unsigned int);
87 static void pcc_set(u_short
, unsigned int , unsigned int );
89 static DEFINE_SPINLOCK(pcc_lock
);
91 #if !defined(CONFIG_PLAT_USRV)
92 static inline u_long
pcc_port2addr(unsigned long port
, int size
) {
96 if (size
== 1) { /* byte access */
99 addr
= CFC_IO_MAPBASE_BYTE
- CFC_IOPORT_BASE
+ odd
+ port
;
100 } else if (size
== 2)
101 addr
= CFC_IO_MAPBASE_WORD
- CFC_IOPORT_BASE
+ port
;
105 #else /* CONFIG_PLAT_USRV */
106 static inline u_long
pcc_port2addr(unsigned long port
, int size
) {
108 u_long addr
= ((port
- CFC_IOPORT_BASE
) & 0xf000) << 8;
110 if (size
== 1) { /* byte access */
114 addr
= (addr
| CFC_IO_MAPBASE_BYTE
) + odd
+ (port
& 0xfff);
115 } else if (size
== 2) /* word access */
116 addr
= (addr
| CFC_IO_MAPBASE_WORD
) + (port
& 0xfff);
120 #endif /* CONFIG_PLAT_USRV */
122 void pcc_ioread_byte(int sock
, unsigned long port
, void *buf
, size_t size
,
123 size_t nmemb
, int flag
)
126 unsigned char *bp
= (unsigned char *)buf
;
129 debug(3, "m32r_cfc: pcc_ioread_byte: sock=%d, port=%#lx, buf=%p, "
130 "size=%u, nmemb=%d, flag=%d\n",
131 sock
, port
, buf
, size
, nmemb
, flag
);
133 addr
= pcc_port2addr(port
, 1);
135 printk("m32r_cfc:ioread_byte null port :%#lx\n",port
);
138 debug(3, "m32r_cfc: pcc_ioread_byte: addr=%#lx\n", addr
);
140 spin_lock_irqsave(&pcc_lock
, flags
);
144 spin_unlock_irqrestore(&pcc_lock
, flags
);
147 void pcc_ioread_word(int sock
, unsigned long port
, void *buf
, size_t size
,
148 size_t nmemb
, int flag
)
151 unsigned short *bp
= (unsigned short *)buf
;
154 debug(3, "m32r_cfc: pcc_ioread_word: sock=%d, port=%#lx, "
155 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
156 sock
, port
, buf
, size
, nmemb
, flag
);
159 printk("m32r_cfc: ioread_word :illigal size %u : %#lx\n", size
,
162 printk("m32r_cfc: ioread_word :insw \n");
164 addr
= pcc_port2addr(port
, 2);
166 printk("m32r_cfc:ioread_word null port :%#lx\n",port
);
169 debug(3, "m32r_cfc: pcc_ioread_word: addr=%#lx\n", addr
);
171 spin_lock_irqsave(&pcc_lock
, flags
);
175 spin_unlock_irqrestore(&pcc_lock
, flags
);
178 void pcc_iowrite_byte(int sock
, unsigned long port
, void *buf
, size_t size
,
179 size_t nmemb
, int flag
)
182 unsigned char *bp
= (unsigned char *)buf
;
185 debug(3, "m32r_cfc: pcc_iowrite_byte: sock=%d, port=%#lx, "
186 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
187 sock
, port
, buf
, size
, nmemb
, flag
);
190 addr
= pcc_port2addr(port
, 1);
192 printk("m32r_cfc:iowrite_byte null port:%#lx\n",port
);
195 debug(3, "m32r_cfc: pcc_iowrite_byte: addr=%#lx\n", addr
);
197 spin_lock_irqsave(&pcc_lock
, flags
);
200 spin_unlock_irqrestore(&pcc_lock
, flags
);
203 void pcc_iowrite_word(int sock
, unsigned long port
, void *buf
, size_t size
,
204 size_t nmemb
, int flag
)
207 unsigned short *bp
= (unsigned short *)buf
;
210 debug(3, "m32r_cfc: pcc_iowrite_word: sock=%d, port=%#lx, "
211 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
212 sock
, port
, buf
, size
, nmemb
, flag
);
215 printk("m32r_cfc: iowrite_word :illigal size %u : %#lx\n",
218 printk("m32r_cfc: iowrite_word :outsw \n");
220 addr
= pcc_port2addr(port
, 2);
222 printk("m32r_cfc:iowrite_word null addr :%#lx\n",port
);
227 printk("m32r_cfc:iowrite_word port addr (%#lx):%#lx\n", port
,
232 debug(3, "m32r_cfc: pcc_iowrite_word: addr=%#lx\n", addr
);
234 spin_lock_irqsave(&pcc_lock
, flags
);
237 spin_unlock_irqrestore(&pcc_lock
, flags
);
240 /*====================================================================*/
242 #define IS_REGISTERED 0x2000
243 #define IS_ALIVE 0x8000
245 typedef struct pcc_t
{
250 static pcc_t pcc
[] = {
251 #if !defined(CONFIG_PLAT_USRV)
252 { "m32r_cfc", 0 }, { "", 0 },
253 #else /* CONFIG_PLAT_USRV */
254 { "m32r_cfc", 0 }, { "m32r_cfc", 0 }, { "m32r_cfc", 0 },
255 { "m32r_cfc", 0 }, { "m32r_cfc", 0 }, { "", 0 },
256 #endif /* CONFIG_PLAT_USRV */
259 static irqreturn_t
pcc_interrupt(int, void *, struct pt_regs
*);
261 /*====================================================================*/
263 static struct timer_list poll_timer
;
265 static unsigned int pcc_get(u_short sock
, unsigned int reg
)
267 unsigned int val
= inw(reg
);
268 debug(3, "m32r_cfc: pcc_get: reg(0x%08x)=0x%04x\n", reg
, val
);
273 static void pcc_set(u_short sock
, unsigned int reg
, unsigned int data
)
276 debug(3, "m32r_cfc: pcc_set: reg(0x%08x)=0x%04x\n", reg
, data
);
279 /*======================================================================
281 See if a card is present, powered up, in IO mode, and already
282 bound to a (non PC Card) Linux driver. We leave these alone.
284 We make an exception for cards that seem to be serial devices.
286 ======================================================================*/
288 static int __init
is_alive(u_short sock
)
292 debug(3, "m32r_cfc: is_alive:\n");
295 stat
= pcc_get(sock
, (unsigned int)PLD_CFSTS
);
298 printk("Card is detected at socket %d : stat = 0x%08x\n", sock
, stat
);
299 debug(3, "m32r_cfc: is_alive: sock stat is 0x%04x\n", stat
);
304 static void add_pcc_socket(ulong base
, int irq
, ulong mapaddr
, kio_addr_t ioaddr
)
306 pcc_socket_t
*t
= &socket
[pcc_sockets
];
308 debug(3, "m32r_cfc: add_pcc_socket: base=%#lx, irq=%d, "
309 "mapaddr=%#lx, ioaddr=%08x\n",
310 base
, irq
, mapaddr
, ioaddr
);
314 t
->mapaddr
= mapaddr
;
315 #if !defined(CONFIG_PLAT_USRV)
318 t
->cs_irq1
= irq
; // insert irq
319 t
->cs_irq2
= irq
+ 1; // eject irq
320 #else /* CONFIG_PLAT_USRV */
323 t
->cs_irq1
= 0; // insert irq
324 t
->cs_irq2
= 0; // eject irq
325 #endif /* CONFIG_PLAT_USRV */
327 if (is_alive(pcc_sockets
))
328 t
->flags
|= IS_ALIVE
;
331 #if !defined(CONFIG_PLAT_USRV)
332 request_region((unsigned int)PLD_CFRSTCR
, 0x20, "m32r_cfc");
333 #else /* CONFIG_PLAT_USRV */
335 unsigned int reg_base
;
337 reg_base
= (unsigned int)PLD_CFRSTCR
;
338 reg_base
|= pcc_sockets
<< 8;
339 request_region(reg_base
, 0x20, "m32r_cfc");
341 #endif /* CONFIG_PLAT_USRV */
342 printk(KERN_INFO
" %s ", pcc
[pcc_sockets
].name
);
343 printk("pcc at 0x%08lx\n", t
->base
);
345 /* Update socket interrupt information, capabilities */
346 t
->socket
.features
|= (SS_CAP_PCCARD
| SS_CAP_STATIC_MAP
);
347 t
->socket
.map_size
= M32R_PCC_MAPSIZE
;
348 t
->socket
.io_offset
= ioaddr
; /* use for io access offset */
349 t
->socket
.irq_mask
= 0;
350 #if !defined(CONFIG_PLAT_USRV)
351 t
->socket
.pci_irq
= PLD_IRQ_CFIREQ
; /* card interrupt */
352 #else /* CONFIG_PLAT_USRV */
353 t
->socket
.pci_irq
= PLD_IRQ_CF0
+ pcc_sockets
;
354 #endif /* CONFIG_PLAT_USRV */
356 #ifndef CONFIG_PLAT_USRV
357 /* insert interrupt */
358 request_irq(irq
, pcc_interrupt
, 0, "m32r_cfc", pcc_interrupt
);
359 /* eject interrupt */
360 request_irq(irq
+1, pcc_interrupt
, 0, "m32r_cfc", pcc_interrupt
);
362 debug(3, "m32r_cfc: enable CFMSK, RDYSEL\n");
363 pcc_set(pcc_sockets
, (unsigned int)PLD_CFIMASK
, 0x01);
364 #endif /* CONFIG_PLAT_USRV */
365 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
366 pcc_set(pcc_sockets
, (unsigned int)PLD_CFCR1
, 0x0200);
374 /*====================================================================*/
376 static irqreturn_t
pcc_interrupt(int irq
, void *dev
, struct pt_regs
*regs
)
382 debug(3, "m32r_cfc: pcc_interrupt: irq=%d, dev=%p, regs=%p\n",
384 for (i
= 0; i
< pcc_sockets
; i
++) {
385 if (socket
[i
].cs_irq1
!= irq
&& socket
[i
].cs_irq2
!= irq
)
389 debug(3, "m32r_cfc: pcc_interrupt: socket %d irq 0x%02x ",
391 events
|= SS_DETECT
; /* insert or eject */
393 pcmcia_parse_events(&socket
[i
].socket
, events
);
395 debug(3, "m32r_cfc: pcc_interrupt: done\n");
397 return IRQ_RETVAL(handled
);
398 } /* pcc_interrupt */
400 static void pcc_interrupt_wrapper(u_long data
)
402 debug(3, "m32r_cfc: pcc_interrupt_wrapper:\n");
403 pcc_interrupt(0, NULL
, NULL
);
404 init_timer(&poll_timer
);
405 poll_timer
.expires
= jiffies
+ poll_interval
;
406 add_timer(&poll_timer
);
409 /*====================================================================*/
411 static int _pcc_get_status(u_short sock
, u_int
*value
)
415 debug(3, "m32r_cfc: _pcc_get_status:\n");
416 status
= pcc_get(sock
, (unsigned int)PLD_CFSTS
);
417 *value
= (status
) ? SS_DETECT
: 0;
418 debug(3, "m32r_cfc: _pcc_get_status: status=0x%08x\n", status
);
420 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
422 /* enable CF power */
423 status
= inw((unsigned int)PLD_CPCR
);
424 if (!(status
& PLD_CPCR_CF
)) {
425 debug(3, "m32r_cfc: _pcc_get_status: "
426 "power on (CPCR=0x%08x)\n", status
);
427 status
|= PLD_CPCR_CF
;
428 outw(status
, (unsigned int)PLD_CPCR
);
431 *value
|= SS_POWERON
;
433 pcc_set(sock
, (unsigned int)PLD_CFBUFCR
,0);/* enable buffer */
436 *value
|= SS_READY
; /* always ready */
439 /* disable CF power */
440 status
= inw((unsigned int)PLD_CPCR
);
441 status
&= ~PLD_CPCR_CF
;
442 outw(status
, (unsigned int)PLD_CPCR
);
444 debug(3, "m32r_cfc: _pcc_get_status: "
445 "power off (CPCR=0x%08x)\n", status
);
447 #elif defined(CONFIG_PLAT_MAPPI2)
449 status
= pcc_get(sock
, (unsigned int)PLD_CPCR
);
450 if (status
== 0) { /* power off */
451 pcc_set(sock
, (unsigned int)PLD_CPCR
, 1);
452 pcc_set(sock
, (unsigned int)PLD_CFBUFCR
,0); /* force buffer off for ZA-36 */
455 status
= pcc_get(sock
, (unsigned int)PLD_CFBUFCR
);
456 if (status
!= 0) { /* buffer off */
457 pcc_set(sock
, (unsigned int)PLD_CFBUFCR
,0);
459 pcc_set(sock
, (unsigned int)PLD_CFRSTCR
, 0x0101);
460 udelay(25); /* for IDE reset */
461 pcc_set(sock
, (unsigned int)PLD_CFRSTCR
, 0x0100);
462 mdelay(2); /* for IDE reset */
464 *value
|= SS_POWERON
;
469 #error no platform configuration
471 debug(3, "m32r_cfc: _pcc_get_status: GetStatus(%d) = %#4.4x\n",
476 /*====================================================================*/
478 static int _pcc_get_socket(u_short sock
, socket_state_t
*state
)
480 // pcc_socket_t *t = &socket[sock];
482 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
484 state
->csc_mask
= SS_DETECT
;
485 state
->csc_mask
|= SS_READY
;
487 state
->Vcc
= 33; /* 3.3V fixed */
490 debug(3, "m32r_cfc: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
491 "io_irq %d, csc_mask %#2.2x\n", sock
, state
->flags
,
492 state
->Vcc
, state
->Vpp
, state
->io_irq
, state
->csc_mask
);
496 /*====================================================================*/
498 static int _pcc_set_socket(u_short sock
, socket_state_t
*state
)
500 #if defined(CONFIG_PLAT_MAPPI2)
503 debug(3, "m32r_cfc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
504 "io_irq %d, csc_mask %#2.2x)\n", sock
, state
->flags
,
505 state
->Vcc
, state
->Vpp
, state
->io_irq
, state
->csc_mask
);
507 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
509 if ((state
->Vcc
!= 50) && (state
->Vcc
!= 33))
511 /* accept 5V and 3.3V */
513 #elif defined(CONFIG_PLAT_MAPPI2)
518 if (state
->Vcc
== 50) {
526 if (state
->flags
& SS_RESET
) {
527 debug(3, ":RESET\n");
528 pcc_set(sock
,(unsigned int)PLD_CFRSTCR
,0x101);
530 pcc_set(sock
,(unsigned int)PLD_CFRSTCR
,0x100);
532 if (state
->flags
& SS_OUTPUT_ENA
){
533 debug(3, ":OUTPUT_ENA\n");
535 pcc_set(sock
,(unsigned int)PLD_CFBUFCR
,0);
537 pcc_set(sock
,(unsigned int)PLD_CFBUFCR
,1);
541 if(state
->flags
& SS_IOCARD
){
544 if (state
->flags
& SS_PWR_AUTO
) {
545 debug(3, ":PWR_AUTO");
547 if (state
->csc_mask
& SS_DETECT
)
548 debug(3, ":csc-SS_DETECT");
549 if (state
->flags
& SS_IOCARD
) {
550 if (state
->csc_mask
& SS_STSCHG
)
553 if (state
->csc_mask
& SS_BATDEAD
)
554 debug(3, ":BATDEAD");
555 if (state
->csc_mask
& SS_BATWARN
)
556 debug(3, ":BATWARN");
557 if (state
->csc_mask
& SS_READY
)
565 /*====================================================================*/
567 static int _pcc_set_io_map(u_short sock
, struct pccard_io_map
*io
)
571 debug(3, "m32r_cfc: SetIOMap(%d, %d, %#2.2x, %d ns, "
572 "%#lx-%#lx)\n", sock
, io
->map
, io
->flags
,
573 io
->speed
, io
->start
, io
->stop
);
579 /*====================================================================*/
581 static int _pcc_set_mem_map(u_short sock
, struct pccard_mem_map
*mem
)
584 u_char map
= mem
->map
;
586 pcc_socket_t
*t
= &socket
[sock
];
588 debug(3, "m32r_cfc: SetMemMap(%d, %d, %#2.2x, %d ns, "
589 "%#lx, %#x)\n", sock
, map
, mem
->flags
,
590 mem
->speed
, mem
->static_start
, mem
->card_start
);
595 if ((map
> MAX_WIN
) || (mem
->card_start
> 0x3ffffff)){
602 if ((mem
->flags
& MAP_ACTIVE
) == 0) {
603 t
->current_space
= as_none
;
610 if (mem
->flags
& MAP_ATTRIB
) {
611 t
->current_space
= as_attr
;
613 t
->current_space
= as_comm
;
619 addr
= t
->mapaddr
+ (mem
->card_start
& M32R_PCC_MAPMASK
);
620 mem
->static_start
= addr
+ mem
->card_start
;
626 #if 0 /* driver model ordering issue */
627 /*======================================================================
629 Routines for accessing socket information and register dumps via
632 ======================================================================*/
634 static ssize_t
show_info(struct class_device
*class_dev
, char *buf
)
636 pcc_socket_t
*s
= container_of(class_dev
, struct pcc_socket
,
639 return sprintf(buf
, "type: %s\nbase addr: 0x%08lx\n",
640 pcc
[s
->type
].name
, s
->base
);
643 static ssize_t
show_exca(struct class_device
*class_dev
, char *buf
)
650 static CLASS_DEVICE_ATTR(info
, S_IRUGO
, show_info
, NULL
);
651 static CLASS_DEVICE_ATTR(exca
, S_IRUGO
, show_exca
, NULL
);
654 /*====================================================================*/
656 /* this is horribly ugly... proper locking needs to be done here at
658 #define LOCKED(x) do { \
660 unsigned long flags; \
661 spin_lock_irqsave(&pcc_lock, flags); \
663 spin_unlock_irqrestore(&pcc_lock, flags); \
668 static int pcc_get_status(struct pcmcia_socket
*s
, u_int
*value
)
670 unsigned int sock
= container_of(s
, struct pcc_socket
, socket
)->number
;
672 if (socket
[sock
].flags
& IS_ALIVE
) {
673 debug(3, "m32r_cfc: pcc_get_status: sock(%d) -EINVAL\n", sock
);
677 debug(3, "m32r_cfc: pcc_get_status: sock(%d)\n", sock
);
678 LOCKED(_pcc_get_status(sock
, value
));
681 static int pcc_get_socket(struct pcmcia_socket
*s
, socket_state_t
*state
)
683 unsigned int sock
= container_of(s
, struct pcc_socket
, socket
)->number
;
685 if (socket
[sock
].flags
& IS_ALIVE
) {
686 debug(3, "m32r_cfc: pcc_get_socket: sock(%d) -EINVAL\n", sock
);
689 debug(3, "m32r_cfc: pcc_get_socket: sock(%d)\n", sock
);
690 LOCKED(_pcc_get_socket(sock
, state
));
693 static int pcc_set_socket(struct pcmcia_socket
*s
, socket_state_t
*state
)
695 unsigned int sock
= container_of(s
, struct pcc_socket
, socket
)->number
;
697 if (socket
[sock
].flags
& IS_ALIVE
) {
698 debug(3, "m32r_cfc: pcc_set_socket: sock(%d) -EINVAL\n", sock
);
701 debug(3, "m32r_cfc: pcc_set_socket: sock(%d)\n", sock
);
702 LOCKED(_pcc_set_socket(sock
, state
));
705 static int pcc_set_io_map(struct pcmcia_socket
*s
, struct pccard_io_map
*io
)
707 unsigned int sock
= container_of(s
, struct pcc_socket
, socket
)->number
;
709 if (socket
[sock
].flags
& IS_ALIVE
) {
710 debug(3, "m32r_cfc: pcc_set_io_map: sock(%d) -EINVAL\n", sock
);
713 debug(3, "m32r_cfc: pcc_set_io_map: sock(%d)\n", sock
);
714 LOCKED(_pcc_set_io_map(sock
, io
));
717 static int pcc_set_mem_map(struct pcmcia_socket
*s
, struct pccard_mem_map
*mem
)
719 unsigned int sock
= container_of(s
, struct pcc_socket
, socket
)->number
;
721 if (socket
[sock
].flags
& IS_ALIVE
) {
722 debug(3, "m32r_cfc: pcc_set_mem_map: sock(%d) -EINVAL\n", sock
);
725 debug(3, "m32r_cfc: pcc_set_mem_map: sock(%d)\n", sock
);
726 LOCKED(_pcc_set_mem_map(sock
, mem
));
729 static int pcc_init(struct pcmcia_socket
*s
)
731 debug(3, "m32r_cfc: pcc_init()\n");
735 static struct pccard_operations pcc_operations
= {
737 .get_status
= pcc_get_status
,
738 .get_socket
= pcc_get_socket
,
739 .set_socket
= pcc_set_socket
,
740 .set_io_map
= pcc_set_io_map
,
741 .set_mem_map
= pcc_set_mem_map
,
744 /*====================================================================*/
746 static int m32r_pcc_suspend(struct device
*dev
, pm_message_t state
, u32 level
)
749 if (level
== SUSPEND_SAVE_STATE
)
750 ret
= pcmcia_socket_dev_suspend(dev
, state
);
754 static int m32r_pcc_resume(struct device
*dev
, u32 level
)
757 if (level
== RESUME_RESTORE_STATE
)
758 ret
= pcmcia_socket_dev_resume(dev
);
763 static struct device_driver pcc_driver
= {
765 .bus
= &platform_bus_type
,
766 .suspend
= m32r_pcc_suspend
,
767 .resume
= m32r_pcc_resume
,
770 static struct platform_device pcc_device
= {
775 /*====================================================================*/
777 static int __init
init_m32r_pcc(void)
781 ret
= driver_register(&pcc_driver
);
785 ret
= platform_device_register(&pcc_device
);
787 driver_unregister(&pcc_driver
);
791 #if defined(CONFIG_PLAT_MAPPI2)
792 pcc_set(0, (unsigned int)PLD_CFCR0
, 0x0f0f);
793 pcc_set(0, (unsigned int)PLD_CFCR1
, 0x0200);
798 #if !defined(CONFIG_PLAT_USRV)
799 add_pcc_socket(M32R_PCC0_BASE
, PLD_IRQ_CFC_INSERT
, CFC_ATTR_MAPBASE
,
801 #else /* CONFIG_PLAT_USRV */
806 for (i
= 0 ; i
< M32R_MAX_PCC
; i
++) {
807 base
= (ulong
)PLD_CFRSTCR
;
808 base
= base
| (i
<< 8);
809 ioaddr
= (i
+ 1) << 12;
810 mapaddr
= CFC_ATTR_MAPBASE
| (i
<< 20);
811 add_pcc_socket(base
, 0, mapaddr
, ioaddr
);
814 #endif /* CONFIG_PLAT_USRV */
816 if (pcc_sockets
== 0) {
817 printk("socket is not found.\n");
818 platform_device_unregister(&pcc_device
);
819 driver_unregister(&pcc_driver
);
823 /* Set up interrupt handler(s) */
825 for (i
= 0 ; i
< pcc_sockets
; i
++) {
826 socket
[i
].socket
.dev
.dev
= &pcc_device
.dev
;
827 socket
[i
].socket
.ops
= &pcc_operations
;
828 socket
[i
].socket
.resource_ops
= &pccard_static_ops
;
829 socket
[i
].socket
.owner
= THIS_MODULE
;
830 socket
[i
].number
= i
;
831 ret
= pcmcia_register_socket(&socket
[i
].socket
);
833 socket
[i
].flags
|= IS_REGISTERED
;
835 #if 0 /* driver model ordering issue */
836 class_device_create_file(&socket
[i
].socket
.dev
,
837 &class_device_attr_info
);
838 class_device_create_file(&socket
[i
].socket
.dev
,
839 &class_device_attr_exca
);
843 /* Finally, schedule a polling interrupt */
844 if (poll_interval
!= 0) {
845 poll_timer
.function
= pcc_interrupt_wrapper
;
847 init_timer(&poll_timer
);
848 poll_timer
.expires
= jiffies
+ poll_interval
;
849 add_timer(&poll_timer
);
853 } /* init_m32r_pcc */
855 static void __exit
exit_m32r_pcc(void)
859 for (i
= 0; i
< pcc_sockets
; i
++)
860 if (socket
[i
].flags
& IS_REGISTERED
)
861 pcmcia_unregister_socket(&socket
[i
].socket
);
863 platform_device_unregister(&pcc_device
);
864 if (poll_interval
!= 0)
865 del_timer_sync(&poll_timer
);
867 driver_unregister(&pcc_driver
);
868 } /* exit_m32r_pcc */
870 module_init(init_m32r_pcc
);
871 module_exit(exit_m32r_pcc
);
872 MODULE_LICENSE("Dual MPL/GPL");
873 /*====================================================================*/