2 * Device driver for the PCMCIA controller module of the
3 * Hitachi HD64465 handheld companion chip.
5 * Note that the HD64465 provides a very thin PCMCIA host bridge
6 * layer, requiring a lot of the work of supporting cards to be
7 * performed by the processor. For example: mapping of card
8 * interrupts to processor IRQs is done by IRQ demuxing software;
9 * IO and memory mappings are fixed; setting voltages according
10 * to card Voltage Select pins etc is done in software.
12 * Note also that this driver uses only the simple, fixed,
13 * 16MB, 16-bit wide mappings to PCMCIA spaces defined by the
14 * HD64465. Larger mappings, smaller mappings, or mappings of
15 * different width to the same socket, are all possible only by
16 * involving the SH7750's MMU, which is considered unnecessary here.
17 * The downside is that it may be possible for some drivers to
18 * break because they need or expect 8-bit mappings.
20 * This driver currently supports only the following configuration:
21 * SH7750 CPU, HD64465, TPS2206 voltage control chip.
23 * by Greg Banks <gbanks@pocketpenguins.com>
24 * (c) 2000 PocketPenguins Inc
27 #include <linux/types.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/string.h>
31 #include <linux/kernel.h>
32 #include <linux/ioport.h>
34 #include <linux/vmalloc.h>
35 #include <asm/errno.h>
36 #include <linux/irq.h>
37 #include <linux/interrupt.h>
38 #include <linux/platform_device.h>
41 #include <asm/hd64465/hd64465.h>
42 #include <asm/hd64465/io.h>
44 #include <pcmcia/cs_types.h>
45 #include <pcmcia/cs.h>
46 #include <pcmcia/cistpl.h>
47 #include <pcmcia/ds.h>
48 #include <pcmcia/ss.h>
50 #define MODNAME "hd64465_ss"
52 /* #define HD64465_DEBUG 1 */
55 #define DPRINTK(args...) printk(MODNAME ": " args)
57 #define DPRINTK(args...)
60 extern int hd64465_io_debug
;
61 extern void * p3_ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
);
62 extern void p3_iounmap(void *addr
);
64 /*============================================================*/
66 #define HS_IO_MAP_SIZE (64*1024)
68 typedef struct hs_socket_t
77 pccard_io_map io_maps
[MAX_IO_WIN
];
78 pccard_mem_map mem_maps
[MAX_WIN
];
79 struct pcmcia_socket socket
;
84 #define HS_MAX_SOCKETS 2
85 static hs_socket_t hs_sockets
[HS_MAX_SOCKETS
];
87 #define hs_in(sp, r) inb((sp)->ctrl_base + (r))
88 #define hs_out(sp, v, r) outb(v, (sp)->ctrl_base + (r))
91 /* translate a boolean value to a bit in a register */
92 #define bool_to_regbit(sp, r, bi, bo) \
94 unsigned short v = hs_in(sp, r); \
102 /* register offsets from HD64465_REG_PCC[01]ISR */
110 /* Mask and values for CSCIER register */
111 #define IER_MASK 0x80
112 #define IER_ON 0x3f /* interrupts on */
113 #define IER_OFF 0x00 /* interrupts off */
115 /*============================================================*/
117 #if HD64465_DEBUG > 10
119 static void cis_hex_dump(const unsigned char *x
, int len
)
123 for (i
=0 ; i
<len
; i
++)
126 printk("\n%08x", (unsigned)(x
+ i
));
127 printk(" %02x", *(volatile unsigned short*)x
);
134 /*============================================================*/
137 * This code helps create the illusion that the IREQ line from
138 * the PC card is mapped to one of the CPU's IRQ lines by the
139 * host bridge hardware (which is how every host bridge *except*
140 * the HD64465 works). In particular, it supports enabling
141 * and disabling the IREQ line by code which knows nothing
142 * about the host bridge (e.g. device drivers, IDE code) using
143 * the request_irq(), free_irq(), probe_irq_on() and probe_irq_off()
144 * functions. Also, it supports sharing the mapped IRQ with
145 * real hardware IRQs from the -IRL0-3 lines.
148 #define HS_NUM_MAPPED_IRQS 16 /* Limitation of the PCMCIA code */
151 /* index is mapped irq number */
153 hw_irq_controller
*old_handler
;
154 } hs_mapped_irq
[HS_NUM_MAPPED_IRQS
];
156 static void hs_socket_enable_ireq(hs_socket_t
*sp
)
158 unsigned short cscier
;
160 DPRINTK("hs_socket_enable_ireq(sock=%d)\n", sp
->number
);
162 cscier
= hs_in(sp
, CSCIER
);
163 cscier
&= ~HD64465_PCCCSCIER_PIREQE_MASK
;
164 cscier
|= HD64465_PCCCSCIER_PIREQE_LEVEL
;
165 hs_out(sp
, cscier
, CSCIER
);
168 static void hs_socket_disable_ireq(hs_socket_t
*sp
)
170 unsigned short cscier
;
172 DPRINTK("hs_socket_disable_ireq(sock=%d)\n", sp
->number
);
174 cscier
= hs_in(sp
, CSCIER
);
175 cscier
&= ~HD64465_PCCCSCIER_PIREQE_MASK
;
176 hs_out(sp
, cscier
, CSCIER
);
179 static unsigned int hs_startup_irq(unsigned int irq
)
181 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
182 hs_mapped_irq
[irq
].old_handler
->startup(irq
);
186 static void hs_shutdown_irq(unsigned int irq
)
188 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
189 hs_mapped_irq
[irq
].old_handler
->shutdown(irq
);
192 static void hs_enable_irq(unsigned int irq
)
194 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
195 hs_mapped_irq
[irq
].old_handler
->enable(irq
);
198 static void hs_disable_irq(unsigned int irq
)
200 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
201 hs_mapped_irq
[irq
].old_handler
->disable(irq
);
204 extern struct hw_interrupt_type no_irq_type
;
206 static void hs_mask_and_ack_irq(unsigned int irq
)
208 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
209 /* ack_none() spuriously complains about an unexpected IRQ */
210 if (hs_mapped_irq
[irq
].old_handler
!= &no_irq_type
)
211 hs_mapped_irq
[irq
].old_handler
->ack(irq
);
214 static void hs_end_irq(unsigned int irq
)
216 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
217 hs_mapped_irq
[irq
].old_handler
->end(irq
);
221 static struct hw_interrupt_type hd64465_ss_irq_type
= {
222 .typename
= "PCMCIA-IRQ",
223 .startup
= hs_startup_irq
,
224 .shutdown
= hs_shutdown_irq
,
225 .enable
= hs_enable_irq
,
226 .disable
= hs_disable_irq
,
227 .ack
= hs_mask_and_ack_irq
,
232 * This function should only ever be called with interrupts disabled.
234 static void hs_map_irq(hs_socket_t
*sp
, unsigned int irq
)
236 DPRINTK("hs_map_irq(sock=%d irq=%d)\n", sp
->number
, irq
);
238 if (irq
>= HS_NUM_MAPPED_IRQS
)
241 hs_mapped_irq
[irq
].sock
= sp
;
242 /* insert ourselves as the irq controller */
243 hs_mapped_irq
[irq
].old_handler
= irq_desc
[irq
].chip
;
244 irq_desc
[irq
].chip
= &hd64465_ss_irq_type
;
249 * This function should only ever be called with interrupts disabled.
251 static void hs_unmap_irq(hs_socket_t
*sp
, unsigned int irq
)
253 DPRINTK("hs_unmap_irq(sock=%d irq=%d)\n", sp
->number
, irq
);
255 if (irq
>= HS_NUM_MAPPED_IRQS
)
258 /* restore the original irq controller */
259 irq_desc
[irq
].chip
= hs_mapped_irq
[irq
].old_handler
;
262 /*============================================================*/
266 * Set Vpp and Vcc (in tenths of a Volt). Does not
267 * support the hi-Z state.
269 * Note, this assumes the board uses a TPS2206 chip to control
270 * the Vcc and Vpp voltages to the hs_sockets. If your board
271 * uses the MIC2563 (also supported by the HD64465) then you
272 * will have to modify this function.
275 static const u_char hs_tps2206_avcc
[3] = { 0x00, 0x04, 0x08 };
276 static const u_char hs_tps2206_bvcc
[3] = { 0x00, 0x80, 0x40 };
278 static int hs_set_voltages(hs_socket_t
*sp
, int Vcc
, int Vpp
)
282 u_int sock
= sp
->number
;
284 DPRINTK("hs_set_voltage(%d, %d, %d)\n", sock
, Vcc
, Vpp
);
288 case 0: vcci
= 0; break;
289 case 33: vcci
= 1; break;
290 case 50: vcci
= 2; break;
294 /* Note: Vpp = 120 not supported -- Greg Banks */
295 if (Vpp
!= 0 && Vpp
!= Vcc
)
298 /* The PSR register holds 8 of the 9 bits which control
299 * the TPS2206 via its serial interface.
301 psr
= inw(HD64465_REG_PCCPSR
);
306 psr
|= hs_tps2206_avcc
[vcci
];
307 psr
|= (Vpp
== 0 ? 0x00 : 0x02);
311 psr
|= hs_tps2206_bvcc
[vcci
];
312 psr
|= (Vpp
== 0 ? 0x00 : 0x20);
315 outw(psr
, HD64465_REG_PCCPSR
);
321 /*============================================================*/
324 * Drive the RESET line to the card.
326 static void hs_reset_socket(hs_socket_t
*sp
, int on
)
332 v
|= HD64465_PCCGCR_PCCR
;
334 v
&= ~HD64465_PCCGCR_PCCR
;
338 /*============================================================*/
340 static int hs_init(struct pcmcia_socket
*s
)
342 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
344 DPRINTK("hs_init(%d)\n", sp
->number
);
349 /*============================================================*/
352 static int hs_get_status(struct pcmcia_socket
*s
, u_int
*value
)
354 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
359 isr
= hs_in(sp
, ISR
);
361 /* Card is seated and powered when *both* CD pins are low */
362 if ((isr
& HD64465_PCCISR_PCD_MASK
) == 0)
364 status
|= SS_DETECT
; /* card present */
366 switch (isr
& HD64465_PCCISR_PBVD_MASK
)
368 case HD64465_PCCISR_PBVD_BATGOOD
:
370 case HD64465_PCCISR_PBVD_BATWARN
:
371 status
|= SS_BATWARN
;
374 status
|= SS_BATDEAD
;
378 if (isr
& HD64465_PCCISR_PREADY
)
381 if (isr
& HD64465_PCCISR_PMWP
)
384 /* Voltage Select pins interpreted as per Table 4-5 of the std.
385 * Assuming we have the TPS2206, the socket is a "Low Voltage
386 * key, 3.3V and 5V available, no X.XV available".
388 switch (isr
& (HD64465_PCCISR_PVS2
|HD64465_PCCISR_PVS1
))
390 case HD64465_PCCISR_PVS1
:
391 printk(KERN_NOTICE MODNAME
": cannot handle X.XV card, ignored\n");
395 case HD64465_PCCISR_PVS2
:
399 case HD64465_PCCISR_PVS2
|HD64465_PCCISR_PVS1
:
404 /* TODO: SS_POWERON */
405 /* TODO: SS_STSCHG */
408 DPRINTK("hs_get_status(%d) = %x\n", sock
, status
);
414 /*============================================================*/
416 static int hs_set_socket(struct pcmcia_socket
*s
, socket_state_t
*state
)
418 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
421 unsigned short cscier
;
423 DPRINTK("hs_set_socket(sock=%d, flags=%x, csc_mask=%x, Vcc=%d, Vpp=%d, io_irq=%d)\n",
424 sock
, state
->flags
, state
->csc_mask
, state
->Vcc
, state
->Vpp
, state
->io_irq
);
426 local_irq_save(flags
); /* Don't want interrupts happening here */
428 if (state
->Vpp
!= sp
->state
.Vpp
||
429 state
->Vcc
!= sp
->state
.Vcc
) {
430 if (!hs_set_voltages(sp
, state
->Vcc
, state
->Vpp
)) {
431 local_irq_restore(flags
);
436 /* hd64465_io_debug = 1; */
438 * Handle changes in the Card Status Change mask,
439 * by propagating to the CSCR register
441 changed
= sp
->state
.csc_mask
^ state
->csc_mask
;
442 cscier
= hs_in(sp
, CSCIER
);
444 if (changed
& SS_DETECT
) {
445 if (state
->csc_mask
& SS_DETECT
)
446 cscier
|= HD64465_PCCCSCIER_PCDE
;
448 cscier
&= ~HD64465_PCCCSCIER_PCDE
;
451 if (changed
& SS_READY
) {
452 if (state
->csc_mask
& SS_READY
)
453 cscier
|= HD64465_PCCCSCIER_PRE
;
455 cscier
&= ~HD64465_PCCCSCIER_PRE
;
458 if (changed
& SS_BATDEAD
) {
459 if (state
->csc_mask
& SS_BATDEAD
)
460 cscier
|= HD64465_PCCCSCIER_PBDE
;
462 cscier
&= ~HD64465_PCCCSCIER_PBDE
;
465 if (changed
& SS_BATWARN
) {
466 if (state
->csc_mask
& SS_BATWARN
)
467 cscier
|= HD64465_PCCCSCIER_PBWE
;
469 cscier
&= ~HD64465_PCCCSCIER_PBWE
;
472 if (changed
& SS_STSCHG
) {
473 if (state
->csc_mask
& SS_STSCHG
)
474 cscier
|= HD64465_PCCCSCIER_PSCE
;
476 cscier
&= ~HD64465_PCCCSCIER_PSCE
;
479 hs_out(sp
, cscier
, CSCIER
);
481 if (sp
->state
.io_irq
&& !state
->io_irq
)
482 hs_unmap_irq(sp
, sp
->state
.io_irq
);
483 else if (!sp
->state
.io_irq
&& state
->io_irq
)
484 hs_map_irq(sp
, state
->io_irq
);
488 * Handle changes in the flags field,
489 * by propagating to config registers.
491 changed
= sp
->state
.flags
^ state
->flags
;
493 if (changed
& SS_IOCARD
) {
494 DPRINTK("card type: %s\n",
495 (state
->flags
& SS_IOCARD
? "i/o" : "memory" ));
496 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PCCT
,
497 state
->flags
& SS_IOCARD
);
500 if (changed
& SS_RESET
) {
501 DPRINTK("%s reset card\n",
502 (state
->flags
& SS_RESET
? "start" : "stop"));
503 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PCCR
,
504 state
->flags
& SS_RESET
);
507 if (changed
& SS_OUTPUT_ENA
) {
508 DPRINTK("%sabling card output\n",
509 (state
->flags
& SS_OUTPUT_ENA
? "en" : "dis"));
510 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PDRV
,
511 state
->flags
& SS_OUTPUT_ENA
);
514 /* TODO: SS_SPKR_ENA */
516 /* hd64465_io_debug = 0; */
519 local_irq_restore(flags
);
521 #if HD64465_DEBUG > 10
522 if (state
->flags
& SS_OUTPUT_ENA
)
523 cis_hex_dump((const unsigned char*)sp
->mem_base
, 0x100);
528 /*============================================================*/
530 static int hs_set_io_map(struct pcmcia_socket
*s
, struct pccard_io_map
*io
)
532 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
534 int sock
= sp
->number
;
535 struct pccard_io_map
*sio
;
538 DPRINTK("hs_set_io_map(sock=%d, map=%d, flags=0x%x, speed=%dns, start=%#lx, stop=%#lx)\n",
539 sock
, map
, io
->flags
, io
->speed
, io
->start
, io
->stop
);
540 if (map
>= MAX_IO_WIN
)
542 sio
= &sp
->io_maps
[map
];
544 /* check for null changes */
545 if (io
->flags
== sio
->flags
&&
546 io
->start
== sio
->start
&&
547 io
->stop
== sio
->stop
)
550 if (io
->flags
& MAP_AUTOSZ
)
551 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IODYN
);
552 else if (io
->flags
& MAP_16BIT
)
553 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IO16
);
555 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IO8
);
557 /* TODO: handle MAP_USE_WAIT */
558 if (io
->flags
& MAP_USE_WAIT
)
559 printk(KERN_INFO MODNAME
": MAP_USE_WAIT unimplemented\n");
560 /* TODO: handle MAP_PREFETCH */
561 if (io
->flags
& MAP_PREFETCH
)
562 printk(KERN_INFO MODNAME
": MAP_PREFETCH unimplemented\n");
563 /* TODO: handle MAP_WRPROT */
564 if (io
->flags
& MAP_WRPROT
)
565 printk(KERN_INFO MODNAME
": MAP_WRPROT unimplemented\n");
566 /* TODO: handle MAP_0WS */
567 if (io
->flags
& MAP_0WS
)
568 printk(KERN_INFO MODNAME
": MAP_0WS unimplemented\n");
570 if (io
->flags
& MAP_ACTIVE
) {
571 unsigned long pstart
, psize
, paddrbase
;
573 paddrbase
= virt_to_phys((void*)(sp
->mem_base
+ 2 * HD64465_PCC_WINDOW
));
574 pstart
= io
->start
& PAGE_MASK
;
575 psize
= ((io
->stop
+ PAGE_SIZE
) & PAGE_MASK
) - pstart
;
578 * Change PTEs in only that portion of the mapping requested
579 * by the caller. This means that most of the time, most of
580 * the PTEs in the io_vma will be unmapped and only the bottom
581 * page will be mapped. But the code allows for weird cards
582 * that might want IO ports > 4K.
584 sp
->io_base
= p3_ioremap(paddrbase
+ pstart
, psize
, pgprot_val(prot
));
587 * Change the mapping used by inb() outb() etc
589 hd64465_port_map(io
->start
,
590 io
->stop
- io
->start
+ 1,
591 (unsigned long)sp
->io_base
+ io
->start
, 0);
593 hd64465_port_unmap(sio
->start
, sio
->stop
- sio
->start
+ 1);
594 p3_iounmap(sp
->io_base
);
601 /*============================================================*/
603 static int hs_set_mem_map(struct pcmcia_socket
*s
, struct pccard_mem_map
*mem
)
605 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
606 struct pccard_mem_map
*smem
;
611 DPRINTK("hs_set_mem_map(sock=%d, map=%d, flags=0x%x, card_start=0x%08x)\n",
612 sock
, map
, mem
->flags
, mem
->card_start
);
617 smem
= &sp
->mem_maps
[map
];
619 paddr
= sp
->mem_base
; /* base of Attribute mapping */
620 if (!(mem
->flags
& MAP_ATTRIB
))
621 paddr
+= HD64465_PCC_WINDOW
; /* base of Common mapping */
622 paddr
+= mem
->card_start
;
624 /* Because we specified SS_CAP_STATIC_MAP, we are obliged
625 * at this time to report the system address corresponding
626 * to the card address requested. This is how Socket Services
627 * queries our fixed mapping. I wish this fact had been
628 * documented - Greg Banks.
630 mem
->static_start
= paddr
;
637 /* TODO: do we need to use the MMU to access Common memory ??? */
639 /*============================================================*/
642 * This function is registered with the HD64465 glue code to do a
643 * secondary demux step on the PCMCIA interrupts. It handles
644 * mapping the IREQ request from the card to a standard Linux
645 * IRQ, as requested by SocketServices.
647 static int hs_irq_demux(int irq
, void *dev
)
649 hs_socket_t
*sp
= dev
;
652 DPRINTK("hs_irq_demux(irq=%d)\n", irq
);
654 if (sp
->state
.io_irq
&&
655 (cscr
= hs_in(sp
, CSCR
)) & HD64465_PCCCSCR_PIREQ
) {
656 cscr
&= ~HD64465_PCCCSCR_PIREQ
;
657 hs_out(sp
, cscr
, CSCR
);
658 return sp
->state
.io_irq
;
664 /*============================================================*/
667 * Interrupt handling routine.
670 static irqreturn_t
hs_interrupt(int irq
, void *dev
)
672 hs_socket_t
*sp
= dev
;
676 cscr
= hs_in(sp
, CSCR
);
678 DPRINTK("hs_interrupt, cscr=%04x\n", cscr
);
680 /* check for bus-related changes to be reported to Socket Services */
681 if (cscr
& HD64465_PCCCSCR_PCDC
) {
682 /* double-check for a 16-bit card, as we don't support CardBus */
683 if ((hs_in(sp
, ISR
) & HD64465_PCCISR_PCD_MASK
) != 0) {
684 printk(KERN_NOTICE MODNAME
685 ": socket %d, card not a supported card type or not inserted correctly\n",
687 /* Don't do the rest unless a card is present */
688 cscr
&= ~(HD64465_PCCCSCR_PCDC
|
692 HD64465_PCCCSCR_PSC
);
694 cscr
&= ~HD64465_PCCCSCR_PCDC
;
695 events
|= SS_DETECT
; /* card insertion or removal */
698 if (cscr
& HD64465_PCCCSCR_PRC
) {
699 cscr
&= ~HD64465_PCCCSCR_PRC
;
700 events
|= SS_READY
; /* ready signal changed */
702 if (cscr
& HD64465_PCCCSCR_PBW
) {
703 cscr
&= ~HD64465_PCCCSCR_PSC
;
704 events
|= SS_BATWARN
; /* battery warning */
706 if (cscr
& HD64465_PCCCSCR_PBD
) {
707 cscr
&= ~HD64465_PCCCSCR_PSC
;
708 events
|= SS_BATDEAD
; /* battery dead */
710 if (cscr
& HD64465_PCCCSCR_PSC
) {
711 cscr
&= ~HD64465_PCCCSCR_PSC
;
712 events
|= SS_STSCHG
; /* STSCHG (status changed) signal */
715 if (cscr
& HD64465_PCCCSCR_PIREQ
) {
716 cscr
&= ~HD64465_PCCCSCR_PIREQ
;
718 /* This should have been dealt with during irq demux */
719 printk(KERN_NOTICE MODNAME
": unexpected IREQ from card\n");
722 hs_out(sp
, cscr
, CSCR
);
725 pcmcia_parse_events(&sp
->socket
, events
);
730 /*============================================================*/
732 static struct pccard_operations hs_operations
= {
734 .get_status
= hs_get_status
,
735 .set_socket
= hs_set_socket
,
736 .set_io_map
= hs_set_io_map
,
737 .set_mem_map
= hs_set_mem_map
,
740 static int hs_init_socket(hs_socket_t
*sp
, int irq
, unsigned long mem_base
,
741 unsigned int ctrl_base
)
746 memset(sp
, 0, sizeof(*sp
));
748 sp
->mem_base
= mem_base
;
749 sp
->mem_length
= 4*HD64465_PCC_WINDOW
; /* 16MB */
750 sp
->ctrl_base
= ctrl_base
;
752 for (i
=0 ; i
<MAX_IO_WIN
; i
++)
753 sp
->io_maps
[i
].map
= i
;
754 for (i
=0 ; i
<MAX_WIN
; i
++)
755 sp
->mem_maps
[i
].map
= i
;
757 hd64465_register_irq_demux(sp
->irq
, hs_irq_demux
, sp
);
759 if ((err
= request_irq(sp
->irq
, hs_interrupt
, IRQF_DISABLED
, MODNAME
, sp
)) < 0)
761 if (request_mem_region(sp
->mem_base
, sp
->mem_length
, MODNAME
) == 0) {
767 /* According to section 3.2 of the PCMCIA standard, low-voltage
768 * capable cards must implement cold insertion, i.e. Vpp and
769 * Vcc set to 0 before card is inserted.
771 /*hs_set_voltages(sp, 0, 0);*/
773 /* hi-Z the outputs to the card and set 16MB map mode */
775 v
&= ~HD64465_PCCGCR_PCCT
; /* memory-only card */
779 v
|= HD64465_PCCGCR_PDRV
; /* enable outputs to card */
783 v
|= HD64465_PCCGCR_PMMOD
; /* 16MB mapping mode */
787 /* lowest 16MB of Common */
788 v
&= ~(HD64465_PCCGCR_PPA25
|HD64465_PCCGCR_PPA24
);
791 hs_reset_socket(sp
, 1);
793 printk(KERN_INFO
"HD64465 PCMCIA bridge socket %d at 0x%08lx irq %d\n",
794 i
, sp
->mem_base
, sp
->irq
);
799 static void hs_exit_socket(hs_socket_t
*sp
)
801 unsigned short cscier
, gcr
;
804 local_irq_save(flags
);
806 /* turn off interrupts in hardware */
807 cscier
= hs_in(sp
, CSCIER
);
808 cscier
= (cscier
& IER_MASK
) | IER_OFF
;
809 hs_out(sp
, cscier
, CSCIER
);
811 /* hi-Z the outputs to the card */
812 gcr
= hs_in(sp
, GCR
);
813 gcr
&= HD64465_PCCGCR_PDRV
;
814 hs_out(sp
, gcr
, GCR
);
816 /* power the card down */
817 hs_set_voltages(sp
, 0, 0);
819 if (sp
->mem_base
!= 0)
820 release_mem_region(sp
->mem_base
, sp
->mem_length
);
822 free_irq(sp
->irq
, hs_interrupt
);
823 hd64465_unregister_irq_demux(sp
->irq
);
826 local_irq_restore(flags
);
829 static struct device_driver hd64465_driver
= {
830 .name
= "hd64465-pcmcia",
831 .bus
= &platform_bus_type
,
832 .suspend
= pcmcia_socket_dev_suspend
,
833 .resume
= pcmcia_socket_dev_resume
,
836 static struct platform_device hd64465_device
= {
837 .name
= "hd64465-pcmcia",
841 static int __init
init_hs(void)
846 /* hd64465_io_debug = 1; */
847 if (driver_register(&hd64465_driver
))
850 /* Wake both sockets out of STANDBY mode */
851 /* TODO: wait 15ms */
852 v
= inw(HD64465_REG_SMSCR
);
853 v
&= ~(HD64465_SMSCR_PC0ST
|HD64465_SMSCR_PC1ST
);
854 outw(v
, HD64465_REG_SMSCR
);
856 /* keep power controller out of shutdown mode */
857 v
= inb(HD64465_REG_PCC0SCR
);
858 v
|= HD64465_PCCSCR_SHDN
;
859 outb(v
, HD64465_REG_PCC0SCR
);
861 /* use serial (TPS2206) power controller */
862 v
= inb(HD64465_REG_PCC0CSCR
);
863 v
|= HD64465_PCCCSCR_PSWSEL
;
864 outb(v
, HD64465_REG_PCC0CSCR
);
867 * Setup hs_sockets[] structures and request system resources.
868 * TODO: on memory allocation failure, power down the socket
871 for (i
=0; i
<HS_MAX_SOCKETS
; i
++) {
872 hs_set_voltages(&hs_sockets
[i
], 0, 0);
874 hs_sockets
[i
].socket
.features
|= SS_CAP_PCCARD
| SS_CAP_STATIC_MAP
; /* mappings are fixed in host memory */
875 hs_sockets
[i
].socket
.resource_ops
= &pccard_static_ops
;
876 hs_sockets
[i
].socket
.irq_mask
= 0xffde;/*0xffff*/ /* IRQs mapped in s/w so can do any, really */
877 hs_sockets
[i
].socket
.map_size
= HD64465_PCC_WINDOW
; /* 16MB fixed window size */
879 hs_sockets
[i
].socket
.owner
= THIS_MODULE
;
880 hs_sockets
[i
].socket
.ss_entry
= &hs_operations
;
883 i
= hs_init_socket(&hs_sockets
[0],
886 HD64465_REG_PCC0ISR
);
888 unregister_driver(&hd64465_driver
);
891 i
= hs_init_socket(&hs_sockets
[1],
894 HD64465_REG_PCC1ISR
);
896 unregister_driver(&hd64465_driver
);
900 /* hd64465_io_debug = 0; */
902 platform_device_register(&hd64465_device
);
904 for (i
=0; i
<HS_MAX_SOCKETS
; i
++) {
906 hs_sockets
[i
].socket
.dev
.parent
= &hd64465_device
.dev
;
907 hs_sockets
[i
].number
= i
;
908 ret
= pcmcia_register_socket(&hs_sockets
[i
].socket
);
910 pcmcia_unregister_socket(&hs_sockets
[0].socket
);
916 static void __exit
exit_hs(void)
920 for (i
=0 ; i
<HS_MAX_SOCKETS
; i
++) {
921 pcmcia_unregister_socket(&hs_sockets
[i
].socket
);
922 hs_exit_socket(&hs_sockets
[i
]);
925 platform_device_unregister(&hd64465_device
);
926 unregister_driver(&hd64465_driver
);
929 module_init(init_hs
);
930 module_exit(exit_hs
);
932 /*============================================================*/