2 * $Id: hd64465_ss.c,v 1.7 2003/07/06 14:42:50 lethal Exp $
4 * Device driver for the PCMCIA controller module of the
5 * Hitachi HD64465 handheld companion chip.
7 * Note that the HD64465 provides a very thin PCMCIA host bridge
8 * layer, requiring a lot of the work of supporting cards to be
9 * performed by the processor. For example: mapping of card
10 * interrupts to processor IRQs is done by IRQ demuxing software;
11 * IO and memory mappings are fixed; setting voltages according
12 * to card Voltage Select pins etc is done in software.
14 * Note also that this driver uses only the simple, fixed,
15 * 16MB, 16-bit wide mappings to PCMCIA spaces defined by the
16 * HD64465. Larger mappings, smaller mappings, or mappings of
17 * different width to the same socket, are all possible only by
18 * involving the SH7750's MMU, which is considered unnecessary here.
19 * The downside is that it may be possible for some drivers to
20 * break because they need or expect 8-bit mappings.
22 * This driver currently supports only the following configuration:
23 * SH7750 CPU, HD64465, TPS2206 voltage control chip.
25 * by Greg Banks <gbanks@pocketpenguins.com>
26 * (c) 2000 PocketPenguins Inc
29 #include <linux/types.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/string.h>
33 #include <linux/kernel.h>
34 #include <linux/ioport.h>
36 #include <linux/vmalloc.h>
37 #include <asm/errno.h>
38 #include <linux/irq.h>
39 #include <linux/interrupt.h>
40 #include <linux/device.h>
43 #include <asm/hd64465/hd64465.h>
44 #include <asm/hd64465/io.h>
46 #include <pcmcia/version.h>
47 #include <pcmcia/cs_types.h>
48 #include <pcmcia/cs.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/ds.h>
51 #include <pcmcia/ss.h>
52 #include <pcmcia/bulkmem.h>
53 #include "cs_internal.h"
55 #define MODNAME "hd64465_ss"
57 /* #define HD64465_DEBUG 1 */
60 #define DPRINTK(args...) printk(MODNAME ": " args)
62 #define DPRINTK(args...)
65 extern int hd64465_io_debug
;
66 extern void * p3_ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
);
67 extern void p3_iounmap(void *addr
);
69 /*============================================================*/
71 #define HS_IO_MAP_SIZE (64*1024)
73 typedef struct hs_socket_t
82 pccard_io_map io_maps
[MAX_IO_WIN
];
83 pccard_mem_map mem_maps
[MAX_WIN
];
84 struct pcmcia_socket socket
;
89 #define HS_MAX_SOCKETS 2
90 static hs_socket_t hs_sockets
[HS_MAX_SOCKETS
];
92 #define hs_in(sp, r) inb((sp)->ctrl_base + (r))
93 #define hs_out(sp, v, r) outb(v, (sp)->ctrl_base + (r))
96 /* translate a boolean value to a bit in a register */
97 #define bool_to_regbit(sp, r, bi, bo) \
99 unsigned short v = hs_in(sp, r); \
107 /* register offsets from HD64465_REG_PCC[01]ISR */
115 /* Mask and values for CSCIER register */
116 #define IER_MASK 0x80
117 #define IER_ON 0x3f /* interrupts on */
118 #define IER_OFF 0x00 /* interrupts off */
120 /*============================================================*/
122 #if HD64465_DEBUG > 10
124 static void cis_hex_dump(const unsigned char *x
, int len
)
128 for (i
=0 ; i
<len
; i
++)
131 printk("\n%08x", (unsigned)(x
+ i
));
132 printk(" %02x", *(volatile unsigned short*)x
);
139 /*============================================================*/
142 * This code helps create the illusion that the IREQ line from
143 * the PC card is mapped to one of the CPU's IRQ lines by the
144 * host bridge hardware (which is how every host bridge *except*
145 * the HD64465 works). In particular, it supports enabling
146 * and disabling the IREQ line by code which knows nothing
147 * about the host bridge (e.g. device drivers, IDE code) using
148 * the request_irq(), free_irq(), probe_irq_on() and probe_irq_off()
149 * functions. Also, it supports sharing the mapped IRQ with
150 * real hardware IRQs from the -IRL0-3 lines.
153 #define HS_NUM_MAPPED_IRQS 16 /* Limitation of the PCMCIA code */
156 /* index is mapped irq number */
158 hw_irq_controller
*old_handler
;
159 } hs_mapped_irq
[HS_NUM_MAPPED_IRQS
];
161 static void hs_socket_enable_ireq(hs_socket_t
*sp
)
163 unsigned short cscier
;
165 DPRINTK("hs_socket_enable_ireq(sock=%d)\n", sp
->number
);
167 cscier
= hs_in(sp
, CSCIER
);
168 cscier
&= ~HD64465_PCCCSCIER_PIREQE_MASK
;
169 cscier
|= HD64465_PCCCSCIER_PIREQE_LEVEL
;
170 hs_out(sp
, cscier
, CSCIER
);
173 static void hs_socket_disable_ireq(hs_socket_t
*sp
)
175 unsigned short cscier
;
177 DPRINTK("hs_socket_disable_ireq(sock=%d)\n", sp
->number
);
179 cscier
= hs_in(sp
, CSCIER
);
180 cscier
&= ~HD64465_PCCCSCIER_PIREQE_MASK
;
181 hs_out(sp
, cscier
, CSCIER
);
184 static unsigned int hs_startup_irq(unsigned int irq
)
186 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
187 hs_mapped_irq
[irq
].old_handler
->startup(irq
);
191 static void hs_shutdown_irq(unsigned int irq
)
193 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
194 hs_mapped_irq
[irq
].old_handler
->shutdown(irq
);
197 static void hs_enable_irq(unsigned int irq
)
199 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
200 hs_mapped_irq
[irq
].old_handler
->enable(irq
);
203 static void hs_disable_irq(unsigned int irq
)
205 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
206 hs_mapped_irq
[irq
].old_handler
->disable(irq
);
209 extern struct hw_interrupt_type no_irq_type
;
211 static void hs_mask_and_ack_irq(unsigned int irq
)
213 hs_socket_disable_ireq(hs_mapped_irq
[irq
].sock
);
214 /* ack_none() spuriously complains about an unexpected IRQ */
215 if (hs_mapped_irq
[irq
].old_handler
!= &no_irq_type
)
216 hs_mapped_irq
[irq
].old_handler
->ack(irq
);
219 static void hs_end_irq(unsigned int irq
)
221 hs_socket_enable_ireq(hs_mapped_irq
[irq
].sock
);
222 hs_mapped_irq
[irq
].old_handler
->end(irq
);
226 static struct hw_interrupt_type hd64465_ss_irq_type
= {
227 .typename
= "PCMCIA-IRQ",
228 .startup
= hs_startup_irq
,
229 .shutdown
= hs_shutdown_irq
,
230 .enable
= hs_enable_irq
,
231 .disable
= hs_disable_irq
,
232 .ack
= hs_mask_and_ack_irq
,
237 * This function should only ever be called with interrupts disabled.
239 static void hs_map_irq(hs_socket_t
*sp
, unsigned int irq
)
241 DPRINTK("hs_map_irq(sock=%d irq=%d)\n", sp
->number
, irq
);
243 if (irq
>= HS_NUM_MAPPED_IRQS
)
246 hs_mapped_irq
[irq
].sock
= sp
;
247 /* insert ourselves as the irq controller */
248 hs_mapped_irq
[irq
].old_handler
= irq_desc
[irq
].handler
;
249 irq_desc
[irq
].handler
= &hd64465_ss_irq_type
;
254 * This function should only ever be called with interrupts disabled.
256 static void hs_unmap_irq(hs_socket_t
*sp
, unsigned int irq
)
258 DPRINTK("hs_unmap_irq(sock=%d irq=%d)\n", sp
->number
, irq
);
260 if (irq
>= HS_NUM_MAPPED_IRQS
)
263 /* restore the original irq controller */
264 irq_desc
[irq
].handler
= hs_mapped_irq
[irq
].old_handler
;
267 /*============================================================*/
271 * Set Vpp and Vcc (in tenths of a Volt). Does not
272 * support the hi-Z state.
274 * Note, this assumes the board uses a TPS2206 chip to control
275 * the Vcc and Vpp voltages to the hs_sockets. If your board
276 * uses the MIC2563 (also supported by the HD64465) then you
277 * will have to modify this function.
280 static const u_char hs_tps2206_avcc
[3] = { 0x00, 0x04, 0x08 };
281 static const u_char hs_tps2206_bvcc
[3] = { 0x00, 0x80, 0x40 };
283 static int hs_set_voltages(hs_socket_t
*sp
, int Vcc
, int Vpp
)
287 u_int sock
= sp
->number
;
289 DPRINTK("hs_set_voltage(%d, %d, %d)\n", sock
, Vcc
, Vpp
);
293 case 0: vcci
= 0; break;
294 case 33: vcci
= 1; break;
295 case 50: vcci
= 2; break;
299 /* Note: Vpp = 120 not supported -- Greg Banks */
300 if (Vpp
!= 0 && Vpp
!= Vcc
)
303 /* The PSR register holds 8 of the 9 bits which control
304 * the TPS2206 via its serial interface.
306 psr
= inw(HD64465_REG_PCCPSR
);
311 psr
|= hs_tps2206_avcc
[vcci
];
312 psr
|= (Vpp
== 0 ? 0x00 : 0x02);
316 psr
|= hs_tps2206_bvcc
[vcci
];
317 psr
|= (Vpp
== 0 ? 0x00 : 0x20);
320 outw(psr
, HD64465_REG_PCCPSR
);
326 /*============================================================*/
329 * Drive the RESET line to the card.
331 static void hs_reset_socket(hs_socket_t
*sp
, int on
)
337 v
|= HD64465_PCCGCR_PCCR
;
339 v
&= ~HD64465_PCCGCR_PCCR
;
343 /*============================================================*/
345 static int hs_init(struct pcmcia_socket
*s
)
347 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
349 DPRINTK("hs_init(%d)\n", sp
->number
);
354 /*============================================================*/
356 static int hs_suspend(struct pcmcia_socket
*s
)
359 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
360 DPRINTK("hs_suspend(%d)\n", sp
->number
);
368 /*============================================================*/
371 static int hs_get_status(struct pcmcia_socket
*s
, u_int
*value
)
373 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
378 isr
= hs_in(sp
, ISR
);
380 /* Card is seated and powered when *both* CD pins are low */
381 if ((isr
& HD64465_PCCISR_PCD_MASK
) == 0)
383 status
|= SS_DETECT
; /* card present */
385 switch (isr
& HD64465_PCCISR_PBVD_MASK
)
387 case HD64465_PCCISR_PBVD_BATGOOD
:
389 case HD64465_PCCISR_PBVD_BATWARN
:
390 status
|= SS_BATWARN
;
393 status
|= SS_BATDEAD
;
397 if (isr
& HD64465_PCCISR_PREADY
)
400 if (isr
& HD64465_PCCISR_PMWP
)
403 /* Voltage Select pins interpreted as per Table 4-5 of the std.
404 * Assuming we have the TPS2206, the socket is a "Low Voltage
405 * key, 3.3V and 5V available, no X.XV available".
407 switch (isr
& (HD64465_PCCISR_PVS2
|HD64465_PCCISR_PVS1
))
409 case HD64465_PCCISR_PVS1
:
410 printk(KERN_NOTICE MODNAME
": cannot handle X.XV card, ignored\n");
414 case HD64465_PCCISR_PVS2
:
418 case HD64465_PCCISR_PVS2
|HD64465_PCCISR_PVS1
:
423 /* TODO: SS_POWERON */
424 /* TODO: SS_STSCHG */
427 DPRINTK("hs_get_status(%d) = %x\n", sock
, status
);
433 /*============================================================*/
435 static int hs_get_socket(struct pcmcia_socket
*s
, socket_state_t
*state
)
437 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
439 DPRINTK("hs_get_socket(%d)\n", sock
);
445 /*============================================================*/
447 static int hs_set_socket(struct pcmcia_socket
*s
, socket_state_t
*state
)
449 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
452 unsigned short cscier
;
454 DPRINTK("hs_set_socket(sock=%d, flags=%x, csc_mask=%x, Vcc=%d, Vpp=%d, io_irq=%d)\n",
455 sock
, state
->flags
, state
->csc_mask
, state
->Vcc
, state
->Vpp
, state
->io_irq
);
457 local_irq_save(flags
); /* Don't want interrupts happening here */
459 if (state
->Vpp
!= sp
->state
.Vpp
||
460 state
->Vcc
!= sp
->state
.Vcc
) {
461 if (!hs_set_voltages(sp
, state
->Vcc
, state
->Vpp
)) {
462 local_irq_restore(flags
);
467 /* hd64465_io_debug = 1; */
469 * Handle changes in the Card Status Change mask,
470 * by propagating to the CSCR register
472 changed
= sp
->state
.csc_mask
^ state
->csc_mask
;
473 cscier
= hs_in(sp
, CSCIER
);
475 if (changed
& SS_DETECT
) {
476 if (state
->csc_mask
& SS_DETECT
)
477 cscier
|= HD64465_PCCCSCIER_PCDE
;
479 cscier
&= ~HD64465_PCCCSCIER_PCDE
;
482 if (changed
& SS_READY
) {
483 if (state
->csc_mask
& SS_READY
)
484 cscier
|= HD64465_PCCCSCIER_PRE
;
486 cscier
&= ~HD64465_PCCCSCIER_PRE
;
489 if (changed
& SS_BATDEAD
) {
490 if (state
->csc_mask
& SS_BATDEAD
)
491 cscier
|= HD64465_PCCCSCIER_PBDE
;
493 cscier
&= ~HD64465_PCCCSCIER_PBDE
;
496 if (changed
& SS_BATWARN
) {
497 if (state
->csc_mask
& SS_BATWARN
)
498 cscier
|= HD64465_PCCCSCIER_PBWE
;
500 cscier
&= ~HD64465_PCCCSCIER_PBWE
;
503 if (changed
& SS_STSCHG
) {
504 if (state
->csc_mask
& SS_STSCHG
)
505 cscier
|= HD64465_PCCCSCIER_PSCE
;
507 cscier
&= ~HD64465_PCCCSCIER_PSCE
;
510 hs_out(sp
, cscier
, CSCIER
);
512 if (sp
->state
.io_irq
&& !state
->io_irq
)
513 hs_unmap_irq(sp
, sp
->state
.io_irq
);
514 else if (!sp
->state
.io_irq
&& state
->io_irq
)
515 hs_map_irq(sp
, state
->io_irq
);
519 * Handle changes in the flags field,
520 * by propagating to config registers.
522 changed
= sp
->state
.flags
^ state
->flags
;
524 if (changed
& SS_IOCARD
) {
525 DPRINTK("card type: %s\n",
526 (state
->flags
& SS_IOCARD
? "i/o" : "memory" ));
527 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PCCT
,
528 state
->flags
& SS_IOCARD
);
531 if (changed
& SS_RESET
) {
532 DPRINTK("%s reset card\n",
533 (state
->flags
& SS_RESET
? "start" : "stop"));
534 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PCCR
,
535 state
->flags
& SS_RESET
);
538 if (changed
& SS_OUTPUT_ENA
) {
539 DPRINTK("%sabling card output\n",
540 (state
->flags
& SS_OUTPUT_ENA
? "en" : "dis"));
541 bool_to_regbit(sp
, GCR
, HD64465_PCCGCR_PDRV
,
542 state
->flags
& SS_OUTPUT_ENA
);
545 /* TODO: SS_SPKR_ENA */
547 /* hd64465_io_debug = 0; */
550 local_irq_restore(flags
);
552 #if HD64465_DEBUG > 10
553 if (state
->flags
& SS_OUTPUT_ENA
)
554 cis_hex_dump((const unsigned char*)sp
->mem_base
, 0x100);
559 /*============================================================*/
561 static int hs_set_io_map(struct pcmcia_socket
*s
, struct pccard_io_map
*io
)
563 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
565 int sock
= sp
->number
;
566 struct pccard_io_map
*sio
;
569 DPRINTK("hs_set_io_map(sock=%d, map=%d, flags=0x%x, speed=%dns, start=0x%04x, stop=0x%04x)\n",
570 sock
, map
, io
->flags
, io
->speed
, io
->start
, io
->stop
);
571 if (map
>= MAX_IO_WIN
)
573 sio
= &sp
->io_maps
[map
];
575 /* check for null changes */
576 if (io
->flags
== sio
->flags
&&
577 io
->start
== sio
->start
&&
578 io
->stop
== sio
->stop
)
581 if (io
->flags
& MAP_AUTOSZ
)
582 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IODYN
);
583 else if (io
->flags
& MAP_16BIT
)
584 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IO16
);
586 prot
= PAGE_KERNEL_PCC(sock
, _PAGE_PCC_IO8
);
588 /* TODO: handle MAP_USE_WAIT */
589 if (io
->flags
& MAP_USE_WAIT
)
590 printk(KERN_INFO MODNAME
": MAP_USE_WAIT unimplemented\n");
591 /* TODO: handle MAP_PREFETCH */
592 if (io
->flags
& MAP_PREFETCH
)
593 printk(KERN_INFO MODNAME
": MAP_PREFETCH unimplemented\n");
594 /* TODO: handle MAP_WRPROT */
595 if (io
->flags
& MAP_WRPROT
)
596 printk(KERN_INFO MODNAME
": MAP_WRPROT unimplemented\n");
597 /* TODO: handle MAP_0WS */
598 if (io
->flags
& MAP_0WS
)
599 printk(KERN_INFO MODNAME
": MAP_0WS unimplemented\n");
601 if (io
->flags
& MAP_ACTIVE
) {
602 unsigned long pstart
, psize
, paddrbase
;
604 paddrbase
= virt_to_phys((void*)(sp
->mem_base
+ 2 * HD64465_PCC_WINDOW
));
605 pstart
= io
->start
& PAGE_MASK
;
606 psize
= ((io
->stop
+ PAGE_SIZE
) & PAGE_MASK
) - pstart
;
609 * Change PTEs in only that portion of the mapping requested
610 * by the caller. This means that most of the time, most of
611 * the PTEs in the io_vma will be unmapped and only the bottom
612 * page will be mapped. But the code allows for weird cards
613 * that might want IO ports > 4K.
615 sp
->io_base
= p3_ioremap(paddrbase
+ pstart
, psize
, pgprot_val(prot
));
618 * Change the mapping used by inb() outb() etc
620 hd64465_port_map(io
->start
,
621 io
->stop
- io
->start
+ 1,
622 (unsigned long)sp
->io_base
+ io
->start
, 0);
624 hd64465_port_unmap(sio
->start
, sio
->stop
- sio
->start
+ 1);
625 p3_iounmap(sp
->io_base
);
632 /*============================================================*/
634 static int hs_set_mem_map(struct pcmcia_socket
*s
, struct pccard_mem_map
*mem
)
636 hs_socket_t
*sp
= container_of(s
, struct hs_socket_t
, socket
);
637 struct pccard_mem_map
*smem
;
642 DPRINTK("hs_set_mem_map(sock=%d, map=%d, flags=0x%x, card_start=0x%08x)\n",
643 sock
, map
, mem
->flags
, mem
->card_start
);
648 smem
= &sp
->mem_maps
[map
];
650 paddr
= sp
->mem_base
; /* base of Attribute mapping */
651 if (!(mem
->flags
& MAP_ATTRIB
))
652 paddr
+= HD64465_PCC_WINDOW
; /* base of Common mapping */
653 paddr
+= mem
->card_start
;
655 /* Because we specified SS_CAP_STATIC_MAP, we are obliged
656 * at this time to report the system address corresponding
657 * to the card address requested. This is how Socket Services
658 * queries our fixed mapping. I wish this fact had been
659 * documented - Greg Banks.
661 mem
->static_start
= paddr
;
668 /* TODO: do we need to use the MMU to access Common memory ??? */
670 /*============================================================*/
673 * This function is registered with the HD64465 glue code to do a
674 * secondary demux step on the PCMCIA interrupts. It handles
675 * mapping the IREQ request from the card to a standard Linux
676 * IRQ, as requested by SocketServices.
678 static int hs_irq_demux(int irq
, void *dev
)
680 hs_socket_t
*sp
= (hs_socket_t
*)dev
;
683 DPRINTK("hs_irq_demux(irq=%d)\n", irq
);
685 if (sp
->state
.io_irq
&&
686 (cscr
= hs_in(sp
, CSCR
)) & HD64465_PCCCSCR_PIREQ
) {
687 cscr
&= ~HD64465_PCCCSCR_PIREQ
;
688 hs_out(sp
, cscr
, CSCR
);
689 return sp
->state
.io_irq
;
695 /*============================================================*/
698 * Interrupt handling routine.
701 static irqreturn_t
hs_interrupt(int irq
, void *dev
, struct pt_regs
*regs
)
703 hs_socket_t
*sp
= (hs_socket_t
*)dev
;
708 cscr
= hs_in(sp
, CSCR
);
710 DPRINTK("hs_interrupt, cscr=%04x\n", cscr
);
712 /* check for bus-related changes to be reported to Socket Services */
713 if (cscr
& HD64465_PCCCSCR_PCDC
) {
714 /* double-check for a 16-bit card, as we don't support CardBus */
715 if ((hs_in(sp
, ISR
) & HD64465_PCCISR_PCD_MASK
) != 0) {
716 printk(KERN_NOTICE MODNAME
717 ": socket %d, card not a supported card type or not inserted correctly\n",
719 /* Don't do the rest unless a card is present */
720 cscr
&= ~(HD64465_PCCCSCR_PCDC
|
724 HD64465_PCCCSCR_PSC
);
726 cscr
&= ~HD64465_PCCCSCR_PCDC
;
727 events
|= SS_DETECT
; /* card insertion or removal */
730 if (cscr
& HD64465_PCCCSCR_PRC
) {
731 cscr
&= ~HD64465_PCCCSCR_PRC
;
732 events
|= SS_READY
; /* ready signal changed */
734 if (cscr
& HD64465_PCCCSCR_PBW
) {
735 cscr
&= ~HD64465_PCCCSCR_PSC
;
736 events
|= SS_BATWARN
; /* battery warning */
738 if (cscr
& HD64465_PCCCSCR_PBD
) {
739 cscr
&= ~HD64465_PCCCSCR_PSC
;
740 events
|= SS_BATDEAD
; /* battery dead */
742 if (cscr
& HD64465_PCCCSCR_PSC
) {
743 cscr
&= ~HD64465_PCCCSCR_PSC
;
744 events
|= SS_STSCHG
; /* STSCHG (status changed) signal */
747 if (cscr
& HD64465_PCCCSCR_PIREQ
) {
748 cscr
&= ~HD64465_PCCCSCR_PIREQ
;
750 /* This should have been dealt with during irq demux */
751 printk(KERN_NOTICE MODNAME
": unexpected IREQ from card\n");
754 hs_out(sp
, cscr
, CSCR
);
757 pcmcia_parse_events(&sp
->socket
, events
);
762 /*============================================================*/
764 static struct pccard_operations hs_operations
= {
766 .suspend
= hs_suspend
,
767 .get_status
= hs_get_status
,
768 .get_socket
= hs_get_socket
,
769 .set_socket
= hs_set_socket
,
770 .set_io_map
= hs_set_io_map
,
771 .set_mem_map
= hs_set_mem_map
,
774 static int hs_init_socket(hs_socket_t
*sp
, int irq
, unsigned long mem_base
,
775 unsigned int ctrl_base
)
780 memset(sp
, 0, sizeof(*sp
));
782 sp
->mem_base
= mem_base
;
783 sp
->mem_length
= 4*HD64465_PCC_WINDOW
; /* 16MB */
784 sp
->ctrl_base
= ctrl_base
;
786 for (i
=0 ; i
<MAX_IO_WIN
; i
++)
787 sp
->io_maps
[i
].map
= i
;
788 for (i
=0 ; i
<MAX_WIN
; i
++)
789 sp
->mem_maps
[i
].map
= i
;
791 hd64465_register_irq_demux(sp
->irq
, hs_irq_demux
, sp
);
793 if ((err
= request_irq(sp
->irq
, hs_interrupt
, SA_INTERRUPT
, MODNAME
, sp
)) < 0)
795 if (request_mem_region(sp
->mem_base
, sp
->mem_length
, MODNAME
) == 0) {
801 /* According to section 3.2 of the PCMCIA standard, low-voltage
802 * capable cards must implement cold insertion, i.e. Vpp and
803 * Vcc set to 0 before card is inserted.
805 /*hs_set_voltages(sp, 0, 0);*/
807 /* hi-Z the outputs to the card and set 16MB map mode */
809 v
&= ~HD64465_PCCGCR_PCCT
; /* memory-only card */
813 v
|= HD64465_PCCGCR_PDRV
; /* enable outputs to card */
817 v
|= HD64465_PCCGCR_PMMOD
; /* 16MB mapping mode */
821 /* lowest 16MB of Common */
822 v
&= ~(HD64465_PCCGCR_PPA25
|HD64465_PCCGCR_PPA24
);
825 hs_reset_socket(sp
, 1);
827 printk(KERN_INFO
"HD64465 PCMCIA bridge socket %d at 0x%08lx irq %d\n",
828 i
, sp
->mem_base
, sp
->irq
);
833 static void hs_exit_socket(hs_socket_t
*sp
)
835 unsigned short cscier
, gcr
;
838 local_irq_save(flags
);
840 /* turn off interrupts in hardware */
841 cscier
= hs_in(sp
, CSCIER
);
842 cscier
= (cscier
& IER_MASK
) | IER_OFF
;
843 hs_out(sp
, cscier
, CSCIER
);
845 /* hi-Z the outputs to the card */
846 gcr
= hs_in(sp
, GCR
);
847 gcr
&= HD64465_PCCGCR_PDRV
;
848 hs_out(sp
, gcr
, GCR
);
850 /* power the card down */
851 hs_set_voltages(sp
, 0, 0);
853 if (sp
->mem_base
!= 0)
854 release_mem_region(sp
->mem_base
, sp
->mem_length
);
856 free_irq(sp
->irq
, hs_interrupt
);
857 hd64465_unregister_irq_demux(sp
->irq
);
860 local_irq_restore(flags
);
863 static int hd64465_suspend(struct device
*dev
, u32 state
, u32 level
)
866 if (level
== SUSPEND_SAVE_STATE
)
867 ret
= pcmcia_socket_dev_suspend(dev
, state
);
871 static int hd64465_resume(struct device
*dev
, u32 level
)
874 if (level
== RESUME_RESTORE_STATE
)
875 ret
= pcmcia_socket_dev_resume(dev
);
879 static struct device_driver hd64465_driver
= {
880 .name
= "hd64465-pcmcia",
881 .bus
= &platform_bus_type
,
882 .suspend
= hd64465_suspend
,
883 .resume
= hd64465_resume
,
886 static struct platform_device hd64465_device
= {
887 .name
= "hd64465-pcmcia",
891 static int __init
init_hs(void)
896 /* hd64465_io_debug = 1; */
897 if (driver_register(&hd64465_driver
))
900 /* Wake both sockets out of STANDBY mode */
901 /* TODO: wait 15ms */
902 v
= inw(HD64465_REG_SMSCR
);
903 v
&= ~(HD64465_SMSCR_PC0ST
|HD64465_SMSCR_PC1ST
);
904 outw(v
, HD64465_REG_SMSCR
);
906 /* keep power controller out of shutdown mode */
907 v
= inb(HD64465_REG_PCC0SCR
);
908 v
|= HD64465_PCCSCR_SHDN
;
909 outb(v
, HD64465_REG_PCC0SCR
);
911 /* use serial (TPS2206) power controller */
912 v
= inb(HD64465_REG_PCC0CSCR
);
913 v
|= HD64465_PCCCSCR_PSWSEL
;
914 outb(v
, HD64465_REG_PCC0CSCR
);
917 * Setup hs_sockets[] structures and request system resources.
918 * TODO: on memory allocation failure, power down the socket
921 for (i
=0; i
<HS_MAX_SOCKETS
; i
++) {
922 hs_set_voltages(&hs_sockets
[i
], 0, 0);
924 hs_sockets
[i
].socket
.features
|= SS_CAP_PCCARD
| SS_CAP_STATIC_MAP
; /* mappings are fixed in host memory */
925 hs_sockets
[i
].socket
.irq_mask
= 0xffde;/*0xffff*/ /* IRQs mapped in s/w so can do any, really */
926 hs_sockets
[i
].socket
.map_size
= HD64465_PCC_WINDOW
; /* 16MB fixed window size */
928 hs_sockets
[i
].socket
.owner
= THIS_MODULE
;
929 hs_sockets
[i
].socket
.ss_entry
= &hs_operations
;
932 i
= hs_init_socket(&hs_sockets
[0],
935 HD64465_REG_PCC0ISR
);
937 unregister_driver(&hd64465_driver
);
940 i
= hs_init_socket(&hs_sockets
[1],
943 HD64465_REG_PCC1ISR
);
945 unregister_driver(&hd64465_driver
);
949 /* hd64465_io_debug = 0; */
951 platform_device_register(&hd64465_device
);
953 for (i
=0; i
<HS_MAX_SOCKETS
; i
++) {
955 hs_sockets
[i
].socket
.dev
.dev
= &hd64465_device
.dev
;
956 hs_sockets
[i
].number
= i
;
957 ret
= pcmcia_register_socket(&hs_sockets
[i
].socket
);
959 pcmcia_unregister_socket(&hs_sockets
[0].socket
);
965 static void __exit
exit_hs(void)
969 for (i
=0 ; i
<HS_MAX_SOCKETS
; i
++) {
970 pcmcia_unregister_socket(&hs_sockets
[i
].socket
);
971 hs_exit_socket(&hs_sockets
[i
]);
974 platform_device_unregister(&hd64465_device
);
975 unregister_driver(&hd64465_driver
);
978 module_init(init_hs
);
979 module_exit(exit_hs
);
981 /*============================================================*/