USB: unusual devs patch for Nokia 7610 Supernova
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / pcmcia / hd64465_ss.c
blobfb2bc1fb015d417c19d879378a4538bee57ee372
1 /*
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>
33 #include <linux/mm.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>
40 #include <asm/io.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>
49 #include "cs_internal.h"
51 #define MODNAME "hd64465_ss"
53 /* #define HD64465_DEBUG 1 */
55 #if HD64465_DEBUG
56 #define DPRINTK(args...) printk(MODNAME ": " args)
57 #else
58 #define DPRINTK(args...)
59 #endif
61 extern int hd64465_io_debug;
62 extern void * p3_ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags);
63 extern void p3_iounmap(void *addr);
65 /*============================================================*/
67 #define HS_IO_MAP_SIZE (64*1024)
69 typedef struct hs_socket_t
71 unsigned int number;
72 u_int irq;
73 u_long mem_base;
74 void *io_base;
75 u_long mem_length;
76 u_int ctrl_base;
77 socket_state_t state;
78 pccard_io_map io_maps[MAX_IO_WIN];
79 pccard_mem_map mem_maps[MAX_WIN];
80 struct pcmcia_socket socket;
81 } hs_socket_t;
85 #define HS_MAX_SOCKETS 2
86 static hs_socket_t hs_sockets[HS_MAX_SOCKETS];
88 #define hs_in(sp, r) inb((sp)->ctrl_base + (r))
89 #define hs_out(sp, v, r) outb(v, (sp)->ctrl_base + (r))
92 /* translate a boolean value to a bit in a register */
93 #define bool_to_regbit(sp, r, bi, bo) \
94 do { \
95 unsigned short v = hs_in(sp, r); \
96 if (bo) \
97 v |= (bi); \
98 else \
99 v &= ~(bi); \
100 hs_out(sp, v, r); \
101 } while(0)
103 /* register offsets from HD64465_REG_PCC[01]ISR */
104 #define ISR 0x0
105 #define GCR 0x2
106 #define CSCR 0x4
107 #define CSCIER 0x6
108 #define SCR 0x8
111 /* Mask and values for CSCIER register */
112 #define IER_MASK 0x80
113 #define IER_ON 0x3f /* interrupts on */
114 #define IER_OFF 0x00 /* interrupts off */
116 /*============================================================*/
118 #if HD64465_DEBUG > 10
120 static void cis_hex_dump(const unsigned char *x, int len)
122 int i;
124 for (i=0 ; i<len ; i++)
126 if (!(i & 0xf))
127 printk("\n%08x", (unsigned)(x + i));
128 printk(" %02x", *(volatile unsigned short*)x);
129 x += 2;
131 printk("\n");
134 #endif
135 /*============================================================*/
138 * This code helps create the illusion that the IREQ line from
139 * the PC card is mapped to one of the CPU's IRQ lines by the
140 * host bridge hardware (which is how every host bridge *except*
141 * the HD64465 works). In particular, it supports enabling
142 * and disabling the IREQ line by code which knows nothing
143 * about the host bridge (e.g. device drivers, IDE code) using
144 * the request_irq(), free_irq(), probe_irq_on() and probe_irq_off()
145 * functions. Also, it supports sharing the mapped IRQ with
146 * real hardware IRQs from the -IRL0-3 lines.
149 #define HS_NUM_MAPPED_IRQS 16 /* Limitation of the PCMCIA code */
150 static struct
152 /* index is mapped irq number */
153 hs_socket_t *sock;
154 hw_irq_controller *old_handler;
155 } hs_mapped_irq[HS_NUM_MAPPED_IRQS];
157 static void hs_socket_enable_ireq(hs_socket_t *sp)
159 unsigned short cscier;
161 DPRINTK("hs_socket_enable_ireq(sock=%d)\n", sp->number);
163 cscier = hs_in(sp, CSCIER);
164 cscier &= ~HD64465_PCCCSCIER_PIREQE_MASK;
165 cscier |= HD64465_PCCCSCIER_PIREQE_LEVEL;
166 hs_out(sp, cscier, CSCIER);
169 static void hs_socket_disable_ireq(hs_socket_t *sp)
171 unsigned short cscier;
173 DPRINTK("hs_socket_disable_ireq(sock=%d)\n", sp->number);
175 cscier = hs_in(sp, CSCIER);
176 cscier &= ~HD64465_PCCCSCIER_PIREQE_MASK;
177 hs_out(sp, cscier, CSCIER);
180 static unsigned int hs_startup_irq(unsigned int irq)
182 hs_socket_enable_ireq(hs_mapped_irq[irq].sock);
183 hs_mapped_irq[irq].old_handler->startup(irq);
184 return 0;
187 static void hs_shutdown_irq(unsigned int irq)
189 hs_socket_disable_ireq(hs_mapped_irq[irq].sock);
190 hs_mapped_irq[irq].old_handler->shutdown(irq);
193 static void hs_enable_irq(unsigned int irq)
195 hs_socket_enable_ireq(hs_mapped_irq[irq].sock);
196 hs_mapped_irq[irq].old_handler->enable(irq);
199 static void hs_disable_irq(unsigned int irq)
201 hs_socket_disable_ireq(hs_mapped_irq[irq].sock);
202 hs_mapped_irq[irq].old_handler->disable(irq);
205 extern struct hw_interrupt_type no_irq_type;
207 static void hs_mask_and_ack_irq(unsigned int irq)
209 hs_socket_disable_ireq(hs_mapped_irq[irq].sock);
210 /* ack_none() spuriously complains about an unexpected IRQ */
211 if (hs_mapped_irq[irq].old_handler != &no_irq_type)
212 hs_mapped_irq[irq].old_handler->ack(irq);
215 static void hs_end_irq(unsigned int irq)
217 hs_socket_enable_ireq(hs_mapped_irq[irq].sock);
218 hs_mapped_irq[irq].old_handler->end(irq);
222 static struct hw_interrupt_type hd64465_ss_irq_type = {
223 .typename = "PCMCIA-IRQ",
224 .startup = hs_startup_irq,
225 .shutdown = hs_shutdown_irq,
226 .enable = hs_enable_irq,
227 .disable = hs_disable_irq,
228 .ack = hs_mask_and_ack_irq,
229 .end = hs_end_irq
233 * This function should only ever be called with interrupts disabled.
235 static void hs_map_irq(hs_socket_t *sp, unsigned int irq)
237 DPRINTK("hs_map_irq(sock=%d irq=%d)\n", sp->number, irq);
239 if (irq >= HS_NUM_MAPPED_IRQS)
240 return;
242 hs_mapped_irq[irq].sock = sp;
243 /* insert ourselves as the irq controller */
244 hs_mapped_irq[irq].old_handler = irq_desc[irq].chip;
245 irq_desc[irq].chip = &hd64465_ss_irq_type;
250 * This function should only ever be called with interrupts disabled.
252 static void hs_unmap_irq(hs_socket_t *sp, unsigned int irq)
254 DPRINTK("hs_unmap_irq(sock=%d irq=%d)\n", sp->number, irq);
256 if (irq >= HS_NUM_MAPPED_IRQS)
257 return;
259 /* restore the original irq controller */
260 irq_desc[irq].chip = hs_mapped_irq[irq].old_handler;
263 /*============================================================*/
267 * Set Vpp and Vcc (in tenths of a Volt). Does not
268 * support the hi-Z state.
270 * Note, this assumes the board uses a TPS2206 chip to control
271 * the Vcc and Vpp voltages to the hs_sockets. If your board
272 * uses the MIC2563 (also supported by the HD64465) then you
273 * will have to modify this function.
275 /* 0V 3.3V 5.5V */
276 static const u_char hs_tps2206_avcc[3] = { 0x00, 0x04, 0x08 };
277 static const u_char hs_tps2206_bvcc[3] = { 0x00, 0x80, 0x40 };
279 static int hs_set_voltages(hs_socket_t *sp, int Vcc, int Vpp)
281 u_int psr;
282 u_int vcci = 0;
283 u_int sock = sp->number;
285 DPRINTK("hs_set_voltage(%d, %d, %d)\n", sock, Vcc, Vpp);
287 switch (Vcc)
289 case 0: vcci = 0; break;
290 case 33: vcci = 1; break;
291 case 50: vcci = 2; break;
292 default: return 0;
295 /* Note: Vpp = 120 not supported -- Greg Banks */
296 if (Vpp != 0 && Vpp != Vcc)
297 return 0;
299 /* The PSR register holds 8 of the 9 bits which control
300 * the TPS2206 via its serial interface.
302 psr = inw(HD64465_REG_PCCPSR);
303 switch (sock)
305 case 0:
306 psr &= 0x0f;
307 psr |= hs_tps2206_avcc[vcci];
308 psr |= (Vpp == 0 ? 0x00 : 0x02);
309 break;
310 case 1:
311 psr &= 0xf0;
312 psr |= hs_tps2206_bvcc[vcci];
313 psr |= (Vpp == 0 ? 0x00 : 0x20);
314 break;
316 outw(psr, HD64465_REG_PCCPSR);
318 return 1;
322 /*============================================================*/
325 * Drive the RESET line to the card.
327 static void hs_reset_socket(hs_socket_t *sp, int on)
329 unsigned short v;
331 v = hs_in(sp, GCR);
332 if (on)
333 v |= HD64465_PCCGCR_PCCR;
334 else
335 v &= ~HD64465_PCCGCR_PCCR;
336 hs_out(sp, v, GCR);
339 /*============================================================*/
341 static int hs_init(struct pcmcia_socket *s)
343 hs_socket_t *sp = container_of(s, struct hs_socket_t, socket);
345 DPRINTK("hs_init(%d)\n", sp->number);
347 return 0;
350 /*============================================================*/
353 static int hs_get_status(struct pcmcia_socket *s, u_int *value)
355 hs_socket_t *sp = container_of(s, struct hs_socket_t, socket);
356 unsigned int isr;
357 u_int status = 0;
360 isr = hs_in(sp, ISR);
362 /* Card is seated and powered when *both* CD pins are low */
363 if ((isr & HD64465_PCCISR_PCD_MASK) == 0)
365 status |= SS_DETECT; /* card present */
367 switch (isr & HD64465_PCCISR_PBVD_MASK)
369 case HD64465_PCCISR_PBVD_BATGOOD:
370 break;
371 case HD64465_PCCISR_PBVD_BATWARN:
372 status |= SS_BATWARN;
373 break;
374 default:
375 status |= SS_BATDEAD;
376 break;
379 if (isr & HD64465_PCCISR_PREADY)
380 status |= SS_READY;
382 if (isr & HD64465_PCCISR_PMWP)
383 status |= SS_WRPROT;
385 /* Voltage Select pins interpreted as per Table 4-5 of the std.
386 * Assuming we have the TPS2206, the socket is a "Low Voltage
387 * key, 3.3V and 5V available, no X.XV available".
389 switch (isr & (HD64465_PCCISR_PVS2|HD64465_PCCISR_PVS1))
391 case HD64465_PCCISR_PVS1:
392 printk(KERN_NOTICE MODNAME ": cannot handle X.XV card, ignored\n");
393 status = 0;
394 break;
395 case 0:
396 case HD64465_PCCISR_PVS2:
397 /* 3.3V */
398 status |= SS_3VCARD;
399 break;
400 case HD64465_PCCISR_PVS2|HD64465_PCCISR_PVS1:
401 /* 5V */
402 break;
405 /* TODO: SS_POWERON */
406 /* TODO: SS_STSCHG */
409 DPRINTK("hs_get_status(%d) = %x\n", sock, status);
411 *value = status;
412 return 0;
415 /*============================================================*/
417 static int hs_set_socket(struct pcmcia_socket *s, socket_state_t *state)
419 hs_socket_t *sp = container_of(s, struct hs_socket_t, socket);
420 u_long flags;
421 u_int changed;
422 unsigned short cscier;
424 DPRINTK("hs_set_socket(sock=%d, flags=%x, csc_mask=%x, Vcc=%d, Vpp=%d, io_irq=%d)\n",
425 sock, state->flags, state->csc_mask, state->Vcc, state->Vpp, state->io_irq);
427 local_irq_save(flags); /* Don't want interrupts happening here */
429 if (state->Vpp != sp->state.Vpp ||
430 state->Vcc != sp->state.Vcc) {
431 if (!hs_set_voltages(sp, state->Vcc, state->Vpp)) {
432 local_irq_restore(flags);
433 return -EINVAL;
437 /* hd64465_io_debug = 1; */
439 * Handle changes in the Card Status Change mask,
440 * by propagating to the CSCR register
442 changed = sp->state.csc_mask ^ state->csc_mask;
443 cscier = hs_in(sp, CSCIER);
445 if (changed & SS_DETECT) {
446 if (state->csc_mask & SS_DETECT)
447 cscier |= HD64465_PCCCSCIER_PCDE;
448 else
449 cscier &= ~HD64465_PCCCSCIER_PCDE;
452 if (changed & SS_READY) {
453 if (state->csc_mask & SS_READY)
454 cscier |= HD64465_PCCCSCIER_PRE;
455 else
456 cscier &= ~HD64465_PCCCSCIER_PRE;
459 if (changed & SS_BATDEAD) {
460 if (state->csc_mask & SS_BATDEAD)
461 cscier |= HD64465_PCCCSCIER_PBDE;
462 else
463 cscier &= ~HD64465_PCCCSCIER_PBDE;
466 if (changed & SS_BATWARN) {
467 if (state->csc_mask & SS_BATWARN)
468 cscier |= HD64465_PCCCSCIER_PBWE;
469 else
470 cscier &= ~HD64465_PCCCSCIER_PBWE;
473 if (changed & SS_STSCHG) {
474 if (state->csc_mask & SS_STSCHG)
475 cscier |= HD64465_PCCCSCIER_PSCE;
476 else
477 cscier &= ~HD64465_PCCCSCIER_PSCE;
480 hs_out(sp, cscier, CSCIER);
482 if (sp->state.io_irq && !state->io_irq)
483 hs_unmap_irq(sp, sp->state.io_irq);
484 else if (!sp->state.io_irq && state->io_irq)
485 hs_map_irq(sp, state->io_irq);
489 * Handle changes in the flags field,
490 * by propagating to config registers.
492 changed = sp->state.flags ^ state->flags;
494 if (changed & SS_IOCARD) {
495 DPRINTK("card type: %s\n",
496 (state->flags & SS_IOCARD ? "i/o" : "memory" ));
497 bool_to_regbit(sp, GCR, HD64465_PCCGCR_PCCT,
498 state->flags & SS_IOCARD);
501 if (changed & SS_RESET) {
502 DPRINTK("%s reset card\n",
503 (state->flags & SS_RESET ? "start" : "stop"));
504 bool_to_regbit(sp, GCR, HD64465_PCCGCR_PCCR,
505 state->flags & SS_RESET);
508 if (changed & SS_OUTPUT_ENA) {
509 DPRINTK("%sabling card output\n",
510 (state->flags & SS_OUTPUT_ENA ? "en" : "dis"));
511 bool_to_regbit(sp, GCR, HD64465_PCCGCR_PDRV,
512 state->flags & SS_OUTPUT_ENA);
515 /* TODO: SS_SPKR_ENA */
517 /* hd64465_io_debug = 0; */
518 sp->state = *state;
520 local_irq_restore(flags);
522 #if HD64465_DEBUG > 10
523 if (state->flags & SS_OUTPUT_ENA)
524 cis_hex_dump((const unsigned char*)sp->mem_base, 0x100);
525 #endif
526 return 0;
529 /*============================================================*/
531 static int hs_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
533 hs_socket_t *sp = container_of(s, struct hs_socket_t, socket);
534 int map = io->map;
535 int sock = sp->number;
536 struct pccard_io_map *sio;
537 pgprot_t prot;
539 DPRINTK("hs_set_io_map(sock=%d, map=%d, flags=0x%x, speed=%dns, start=%#lx, stop=%#lx)\n",
540 sock, map, io->flags, io->speed, io->start, io->stop);
541 if (map >= MAX_IO_WIN)
542 return -EINVAL;
543 sio = &sp->io_maps[map];
545 /* check for null changes */
546 if (io->flags == sio->flags &&
547 io->start == sio->start &&
548 io->stop == sio->stop)
549 return 0;
551 if (io->flags & MAP_AUTOSZ)
552 prot = PAGE_KERNEL_PCC(sock, _PAGE_PCC_IODYN);
553 else if (io->flags & MAP_16BIT)
554 prot = PAGE_KERNEL_PCC(sock, _PAGE_PCC_IO16);
555 else
556 prot = PAGE_KERNEL_PCC(sock, _PAGE_PCC_IO8);
558 /* TODO: handle MAP_USE_WAIT */
559 if (io->flags & MAP_USE_WAIT)
560 printk(KERN_INFO MODNAME ": MAP_USE_WAIT unimplemented\n");
561 /* TODO: handle MAP_PREFETCH */
562 if (io->flags & MAP_PREFETCH)
563 printk(KERN_INFO MODNAME ": MAP_PREFETCH unimplemented\n");
564 /* TODO: handle MAP_WRPROT */
565 if (io->flags & MAP_WRPROT)
566 printk(KERN_INFO MODNAME ": MAP_WRPROT unimplemented\n");
567 /* TODO: handle MAP_0WS */
568 if (io->flags & MAP_0WS)
569 printk(KERN_INFO MODNAME ": MAP_0WS unimplemented\n");
571 if (io->flags & MAP_ACTIVE) {
572 unsigned long pstart, psize, paddrbase;
574 paddrbase = virt_to_phys((void*)(sp->mem_base + 2 * HD64465_PCC_WINDOW));
575 pstart = io->start & PAGE_MASK;
576 psize = ((io->stop + PAGE_SIZE) & PAGE_MASK) - pstart;
579 * Change PTEs in only that portion of the mapping requested
580 * by the caller. This means that most of the time, most of
581 * the PTEs in the io_vma will be unmapped and only the bottom
582 * page will be mapped. But the code allows for weird cards
583 * that might want IO ports > 4K.
585 sp->io_base = p3_ioremap(paddrbase + pstart, psize, pgprot_val(prot));
588 * Change the mapping used by inb() outb() etc
590 hd64465_port_map(io->start,
591 io->stop - io->start + 1,
592 (unsigned long)sp->io_base + io->start, 0);
593 } else {
594 hd64465_port_unmap(sio->start, sio->stop - sio->start + 1);
595 p3_iounmap(sp->io_base);
598 *sio = *io;
599 return 0;
602 /*============================================================*/
604 static int hs_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *mem)
606 hs_socket_t *sp = container_of(s, struct hs_socket_t, socket);
607 struct pccard_mem_map *smem;
608 int map = mem->map;
609 unsigned long paddr;
611 #if 0
612 DPRINTK("hs_set_mem_map(sock=%d, map=%d, flags=0x%x, card_start=0x%08x)\n",
613 sock, map, mem->flags, mem->card_start);
614 #endif
616 if (map >= MAX_WIN)
617 return -EINVAL;
618 smem = &sp->mem_maps[map];
620 paddr = sp->mem_base; /* base of Attribute mapping */
621 if (!(mem->flags & MAP_ATTRIB))
622 paddr += HD64465_PCC_WINDOW; /* base of Common mapping */
623 paddr += mem->card_start;
625 /* Because we specified SS_CAP_STATIC_MAP, we are obliged
626 * at this time to report the system address corresponding
627 * to the card address requested. This is how Socket Services
628 * queries our fixed mapping. I wish this fact had been
629 * documented - Greg Banks.
631 mem->static_start = paddr;
633 *smem = *mem;
635 return 0;
638 /* TODO: do we need to use the MMU to access Common memory ??? */
640 /*============================================================*/
643 * This function is registered with the HD64465 glue code to do a
644 * secondary demux step on the PCMCIA interrupts. It handles
645 * mapping the IREQ request from the card to a standard Linux
646 * IRQ, as requested by SocketServices.
648 static int hs_irq_demux(int irq, void *dev)
650 hs_socket_t *sp = dev;
651 u_int cscr;
653 DPRINTK("hs_irq_demux(irq=%d)\n", irq);
655 if (sp->state.io_irq &&
656 (cscr = hs_in(sp, CSCR)) & HD64465_PCCCSCR_PIREQ) {
657 cscr &= ~HD64465_PCCCSCR_PIREQ;
658 hs_out(sp, cscr, CSCR);
659 return sp->state.io_irq;
662 return irq;
665 /*============================================================*/
668 * Interrupt handling routine.
671 static irqreturn_t hs_interrupt(int irq, void *dev)
673 hs_socket_t *sp = dev;
674 u_int events = 0;
675 u_int cscr;
677 cscr = hs_in(sp, CSCR);
679 DPRINTK("hs_interrupt, cscr=%04x\n", cscr);
681 /* check for bus-related changes to be reported to Socket Services */
682 if (cscr & HD64465_PCCCSCR_PCDC) {
683 /* double-check for a 16-bit card, as we don't support CardBus */
684 if ((hs_in(sp, ISR) & HD64465_PCCISR_PCD_MASK) != 0) {
685 printk(KERN_NOTICE MODNAME
686 ": socket %d, card not a supported card type or not inserted correctly\n",
687 sp->number);
688 /* Don't do the rest unless a card is present */
689 cscr &= ~(HD64465_PCCCSCR_PCDC|
690 HD64465_PCCCSCR_PRC|
691 HD64465_PCCCSCR_PBW|
692 HD64465_PCCCSCR_PBD|
693 HD64465_PCCCSCR_PSC);
694 } else {
695 cscr &= ~HD64465_PCCCSCR_PCDC;
696 events |= SS_DETECT; /* card insertion or removal */
699 if (cscr & HD64465_PCCCSCR_PRC) {
700 cscr &= ~HD64465_PCCCSCR_PRC;
701 events |= SS_READY; /* ready signal changed */
703 if (cscr & HD64465_PCCCSCR_PBW) {
704 cscr &= ~HD64465_PCCCSCR_PSC;
705 events |= SS_BATWARN; /* battery warning */
707 if (cscr & HD64465_PCCCSCR_PBD) {
708 cscr &= ~HD64465_PCCCSCR_PSC;
709 events |= SS_BATDEAD; /* battery dead */
711 if (cscr & HD64465_PCCCSCR_PSC) {
712 cscr &= ~HD64465_PCCCSCR_PSC;
713 events |= SS_STSCHG; /* STSCHG (status changed) signal */
716 if (cscr & HD64465_PCCCSCR_PIREQ) {
717 cscr &= ~HD64465_PCCCSCR_PIREQ;
719 /* This should have been dealt with during irq demux */
720 printk(KERN_NOTICE MODNAME ": unexpected IREQ from card\n");
723 hs_out(sp, cscr, CSCR);
725 if (events)
726 pcmcia_parse_events(&sp->socket, events);
728 return IRQ_HANDLED;
731 /*============================================================*/
733 static struct pccard_operations hs_operations = {
734 .init = hs_init,
735 .get_status = hs_get_status,
736 .set_socket = hs_set_socket,
737 .set_io_map = hs_set_io_map,
738 .set_mem_map = hs_set_mem_map,
741 static int hs_init_socket(hs_socket_t *sp, int irq, unsigned long mem_base,
742 unsigned int ctrl_base)
744 unsigned short v;
745 int i, err;
747 memset(sp, 0, sizeof(*sp));
748 sp->irq = irq;
749 sp->mem_base = mem_base;
750 sp->mem_length = 4*HD64465_PCC_WINDOW; /* 16MB */
751 sp->ctrl_base = ctrl_base;
753 for (i=0 ; i<MAX_IO_WIN ; i++)
754 sp->io_maps[i].map = i;
755 for (i=0 ; i<MAX_WIN ; i++)
756 sp->mem_maps[i].map = i;
758 hd64465_register_irq_demux(sp->irq, hs_irq_demux, sp);
760 if ((err = request_irq(sp->irq, hs_interrupt, IRQF_DISABLED, MODNAME, sp)) < 0)
761 return err;
762 if (request_mem_region(sp->mem_base, sp->mem_length, MODNAME) == 0) {
763 sp->mem_base = 0;
764 return -ENOMEM;
768 /* According to section 3.2 of the PCMCIA standard, low-voltage
769 * capable cards must implement cold insertion, i.e. Vpp and
770 * Vcc set to 0 before card is inserted.
772 /*hs_set_voltages(sp, 0, 0);*/
774 /* hi-Z the outputs to the card and set 16MB map mode */
775 v = hs_in(sp, GCR);
776 v &= ~HD64465_PCCGCR_PCCT; /* memory-only card */
777 hs_out(sp, v, GCR);
779 v = hs_in(sp, GCR);
780 v |= HD64465_PCCGCR_PDRV; /* enable outputs to card */
781 hs_out(sp, v, GCR);
783 v = hs_in(sp, GCR);
784 v |= HD64465_PCCGCR_PMMOD; /* 16MB mapping mode */
785 hs_out(sp, v, GCR);
787 v = hs_in(sp, GCR);
788 /* lowest 16MB of Common */
789 v &= ~(HD64465_PCCGCR_PPA25|HD64465_PCCGCR_PPA24);
790 hs_out(sp, v, GCR);
792 hs_reset_socket(sp, 1);
794 printk(KERN_INFO "HD64465 PCMCIA bridge socket %d at 0x%08lx irq %d\n",
795 i, sp->mem_base, sp->irq);
797 return 0;
800 static void hs_exit_socket(hs_socket_t *sp)
802 unsigned short cscier, gcr;
803 unsigned long flags;
805 local_irq_save(flags);
807 /* turn off interrupts in hardware */
808 cscier = hs_in(sp, CSCIER);
809 cscier = (cscier & IER_MASK) | IER_OFF;
810 hs_out(sp, cscier, CSCIER);
812 /* hi-Z the outputs to the card */
813 gcr = hs_in(sp, GCR);
814 gcr &= HD64465_PCCGCR_PDRV;
815 hs_out(sp, gcr, GCR);
817 /* power the card down */
818 hs_set_voltages(sp, 0, 0);
820 if (sp->mem_base != 0)
821 release_mem_region(sp->mem_base, sp->mem_length);
822 if (sp->irq != 0) {
823 free_irq(sp->irq, hs_interrupt);
824 hd64465_unregister_irq_demux(sp->irq);
827 local_irq_restore(flags);
830 static struct device_driver hd64465_driver = {
831 .name = "hd64465-pcmcia",
832 .bus = &platform_bus_type,
833 .suspend = pcmcia_socket_dev_suspend,
834 .resume = pcmcia_socket_dev_resume,
837 static struct platform_device hd64465_device = {
838 .name = "hd64465-pcmcia",
839 .id = 0,
842 static int __init init_hs(void)
844 int i;
845 unsigned short v;
847 /* hd64465_io_debug = 1; */
848 if (driver_register(&hd64465_driver))
849 return -EINVAL;
851 /* Wake both sockets out of STANDBY mode */
852 /* TODO: wait 15ms */
853 v = inw(HD64465_REG_SMSCR);
854 v &= ~(HD64465_SMSCR_PC0ST|HD64465_SMSCR_PC1ST);
855 outw(v, HD64465_REG_SMSCR);
857 /* keep power controller out of shutdown mode */
858 v = inb(HD64465_REG_PCC0SCR);
859 v |= HD64465_PCCSCR_SHDN;
860 outb(v, HD64465_REG_PCC0SCR);
862 /* use serial (TPS2206) power controller */
863 v = inb(HD64465_REG_PCC0CSCR);
864 v |= HD64465_PCCCSCR_PSWSEL;
865 outb(v, HD64465_REG_PCC0CSCR);
868 * Setup hs_sockets[] structures and request system resources.
869 * TODO: on memory allocation failure, power down the socket
870 * before quitting.
872 for (i=0; i<HS_MAX_SOCKETS; i++) {
873 hs_set_voltages(&hs_sockets[i], 0, 0);
875 hs_sockets[i].socket.features |= SS_CAP_PCCARD | SS_CAP_STATIC_MAP; /* mappings are fixed in host memory */
876 hs_sockets[i].socket.resource_ops = &pccard_static_ops;
877 hs_sockets[i].socket.irq_mask = 0xffde;/*0xffff*/ /* IRQs mapped in s/w so can do any, really */
878 hs_sockets[i].socket.map_size = HD64465_PCC_WINDOW; /* 16MB fixed window size */
880 hs_sockets[i].socket.owner = THIS_MODULE;
881 hs_sockets[i].socket.ss_entry = &hs_operations;
884 i = hs_init_socket(&hs_sockets[0],
885 HD64465_IRQ_PCMCIA0,
886 HD64465_PCC0_BASE,
887 HD64465_REG_PCC0ISR);
888 if (i < 0) {
889 unregister_driver(&hd64465_driver);
890 return i;
892 i = hs_init_socket(&hs_sockets[1],
893 HD64465_IRQ_PCMCIA1,
894 HD64465_PCC1_BASE,
895 HD64465_REG_PCC1ISR);
896 if (i < 0) {
897 unregister_driver(&hd64465_driver);
898 return i;
901 /* hd64465_io_debug = 0; */
903 platform_device_register(&hd64465_device);
905 for (i=0; i<HS_MAX_SOCKETS; i++) {
906 unsigned int ret;
907 hs_sockets[i].socket.dev.parent = &hd64465_device.dev;
908 hs_sockets[i].number = i;
909 ret = pcmcia_register_socket(&hs_sockets[i].socket);
910 if (ret && i)
911 pcmcia_unregister_socket(&hs_sockets[0].socket);
914 return 0;
917 static void __exit exit_hs(void)
919 int i;
921 for (i=0 ; i<HS_MAX_SOCKETS ; i++) {
922 pcmcia_unregister_socket(&hs_sockets[i].socket);
923 hs_exit_socket(&hs_sockets[i]);
926 platform_device_unregister(&hd64465_device);
927 unregister_driver(&hd64465_driver);
930 module_init(init_hs);
931 module_exit(exit_hs);
933 /*============================================================*/
934 /*END*/