1 /*======================================================================
3 Device driver for Databook TCIC-2 PCMCIA controller
5 tcic.c 1.111 2000/02/15 04:13:12
7 The contents of this file are subject to the Mozilla Public
8 License Version 1.1 (the "License"); you may not use this file
9 except in compliance with the License. You may obtain a copy of
10 the License at http://www.mozilla.org/MPL/
12 Software distributed under the License is distributed on an "AS
13 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 implied. See the License for the specific language governing
15 rights and limitations under the License.
17 The initial developer of the original code is David A. Hinds
18 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
19 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
21 Alternatively, the contents of this file may be used under the
22 terms of the GNU General Public License version 2 (the "GPL"), in which
23 case the provisions of the GPL are applicable instead of the
24 above. If you wish to allow the use of your version of this file
25 only under the terms of the GPL and not to allow others to use
26 your version of this file under the MPL, indicate your decision
27 by deleting the provisions above and replace them with the notice
28 and other provisions required by the GPL. If you do not delete
29 the provisions above, a recipient may use your version of this
30 file under either the MPL or the GPL.
32 ======================================================================*/
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/types.h>
37 #include <linux/fcntl.h>
38 #include <linux/string.h>
41 #include <asm/bitops.h>
42 #include <asm/segment.h>
43 #include <asm/system.h>
45 #include <linux/kernel.h>
46 #include <linux/errno.h>
47 #include <linux/sched.h>
48 #include <linux/slab.h>
49 #include <linux/timer.h>
50 #include <linux/ioport.h>
51 #include <linux/delay.h>
52 #include <linux/proc_fs.h>
54 #include <pcmcia/version.h>
55 #include <pcmcia/cs_types.h>
56 #include <pcmcia/cs.h>
57 #include <pcmcia/ss.h>
61 static int pc_debug = PCMCIA_DEBUG;
62 MODULE_PARM(pc_debug, "i");
63 static const char *version =
64 "tcic.c 1.111 2000/02/15 04:13:12 (David Hinds)";
65 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
67 #define DEBUG(n, args...)
70 MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
71 MODULE_DESCRIPTION("Databook TCIC-2 PCMCIA socket driver");
72 MODULE_LICENSE("Dual MPL/GPL");
74 /*====================================================================*/
76 /* Parameters that can be set with 'insmod' */
78 /* The base port address of the TCIC-2 chip */
79 static int tcic_base = TCIC_BASE;
81 /* Specify a socket number to ignore */
82 static int ignore = -1;
84 /* Probe for safe interrupts? */
85 static int do_scan = 1;
87 /* Bit map of interrupts to choose from */
88 static u_int irq_mask = 0xffff;
89 static int irq_list[16] = { -1 };
91 /* The card status change interrupt -- 0 means autoselect */
92 static int cs_irq = 0;
94 /* Poll status interval -- 0 means default to interrupt */
95 static int poll_interval = 0;
97 /* Delay for card status double-checking */
98 static int poll_quick = HZ/20;
100 /* CCLK external clock time, in nanoseconds. 70 ns = 14.31818 MHz */
101 static int cycle_time = 70;
103 MODULE_PARM(tcic_base, "i");
104 MODULE_PARM(ignore, "i");
105 MODULE_PARM(do_scan, "i");
106 MODULE_PARM(irq_mask, "i");
107 MODULE_PARM(irq_list, "1-16i");
108 MODULE_PARM(cs_irq, "i");
109 MODULE_PARM(poll_interval, "i");
110 MODULE_PARM(poll_quick, "i");
111 MODULE_PARM(cycle_time, "i");
113 /*====================================================================*/
115 static void tcic_interrupt(int irq, void *dev, struct pt_regs *regs);
116 static void tcic_timer(u_long data);
117 static struct pccard_operations tcic_operations;
119 typedef struct socket_info_t {
121 void (*handler)(void *info, u_int events);
127 static struct timer_list poll_timer;
128 static int tcic_timer_pending = 0;
131 static socket_info_t socket_table[2];
133 static socket_cap_t tcic_cap = {
134 /* only 16-bit cards, memory windows must be size-aligned */
135 SS_CAP_PCCARD | SS_CAP_MEM_ALIGN,
136 0x4cf8, /* irq 14, 11, 10, 7, 6, 5, 4, 3 */
137 0x1000, /* 4K minimum window size */
138 0, 0 /* No PCI or CardBus support */
141 /*====================================================================*/
143 /* Trick when selecting interrupts: the TCIC sktirq pin is supposed
144 to map to irq 11, but is coded as 0 or 1 in the irq registers. */
145 #define TCIC_IRQ(x) ((x) ? (((x) == 11) ? 1 : (x)) : 15)
147 #ifdef PCMCIA_DEBUG_X
148 static u_char tcic_getb(u_char reg)
150 u_char val = inb(tcic_base+reg);
151 printk(KERN_DEBUG "tcic_getb(%#x) = %#x\n", tcic_base+reg, val);
155 static u_short tcic_getw(u_char reg)
157 u_short val = inw(tcic_base+reg);
158 printk(KERN_DEBUG "tcic_getw(%#x) = %#x\n", tcic_base+reg, val);
162 static void tcic_setb(u_char reg, u_char data)
164 printk(KERN_DEBUG "tcic_setb(%#x, %#x)\n", tcic_base+reg, data);
165 outb(data, tcic_base+reg);
168 static void tcic_setw(u_char reg, u_short data)
170 printk(KERN_DEBUG "tcic_setw(%#x, %#x)\n", tcic_base+reg, data);
171 outw(data, tcic_base+reg);
174 #define tcic_getb(reg) inb(tcic_base+reg)
175 #define tcic_getw(reg) inw(tcic_base+reg)
176 #define tcic_setb(reg, data) outb(data, tcic_base+reg)
177 #define tcic_setw(reg, data) outw(data, tcic_base+reg)
180 static void tcic_setl(u_char reg, u_int data)
182 #ifdef PCMCIA_DEBUG_X
183 printk(KERN_DEBUG "tcic_setl(%#x, %#lx)\n", tcic_base+reg, data);
185 outw(data & 0xffff, tcic_base+reg);
186 outw(data >> 16, tcic_base+reg+2);
189 static u_char tcic_aux_getb(u_short reg)
191 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
192 tcic_setb(TCIC_MODE, mode);
193 return tcic_getb(TCIC_AUX);
196 static void tcic_aux_setb(u_short reg, u_char data)
198 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
199 tcic_setb(TCIC_MODE, mode);
200 tcic_setb(TCIC_AUX, data);
203 static u_short tcic_aux_getw(u_short reg)
205 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
206 tcic_setb(TCIC_MODE, mode);
207 return tcic_getw(TCIC_AUX);
210 static void tcic_aux_setw(u_short reg, u_short data)
212 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
213 tcic_setb(TCIC_MODE, mode);
214 tcic_setw(TCIC_AUX, data);
217 /*====================================================================*/
219 /* Time conversion functions */
221 static int to_cycles(int ns)
226 return 2*(ns-14)/cycle_time;
229 static int to_ns(int cycles)
231 return (cycles*cycle_time)/2 + 14;
234 /*====================================================================*/
236 static volatile u_int irq_hits;
238 static void __init irq_count(int irq, void *dev, struct pt_regs *regs)
243 static u_int __init try_irq(int irq)
248 if (request_irq(irq, irq_count, 0, "irq scan", irq_count) != 0)
252 free_irq(irq, irq_count);
256 /* Generate one interrupt */
257 cfg = TCIC_SYSCFG_AUTOBUSY | 0x0a00;
258 tcic_aux_setw(TCIC_AUX_SYSCFG, cfg | TCIC_IRQ(irq));
259 tcic_setb(TCIC_IENA, TCIC_IENA_ERR | TCIC_IENA_CFG_HIGH);
260 tcic_setb(TCIC_ICSR, TCIC_ICSR_ERR | TCIC_ICSR_JAM);
263 free_irq(irq, irq_count);
265 /* Turn off interrupts */
266 tcic_setb(TCIC_IENA, TCIC_IENA_CFG_OFF);
267 while (tcic_getb(TCIC_ICSR))
268 tcic_setb(TCIC_ICSR, TCIC_ICSR_JAM);
269 tcic_aux_setw(TCIC_AUX_SYSCFG, cfg);
271 return (irq_hits != 1);
274 static u_int __init irq_scan(u_int mask0)
281 /* Don't probe level-triggered interrupts -- reserved for PCI */
282 int level_mask = inb_p(PIC) | (inb_p(PIC+1) << 8);
284 mask0 &= ~level_mask;
289 for (i = 0; i < 16; i++)
290 if ((mask0 & (1 << i)) && (try_irq(i) == 0))
292 for (i = 0; i < 16; i++)
293 if ((mask1 & (1 << i)) && (try_irq(i) != 0)) {
301 /* Fallback: just find interrupts that aren't in use */
302 for (i = 0; i < 16; i++)
303 if ((mask0 & (1 << i)) &&
304 (request_irq(i, irq_count, 0, "x", irq_count) == 0)) {
306 free_irq(i, irq_count);
312 for (i = 0; i < 16; i++)
314 printk("%s%d", ((mask1 & ((1<<i)-1)) ? "," : ""), i);
320 /*======================================================================
322 See if a card is present, powered up, in IO mode, and already
323 bound to a (non-PCMCIA) Linux driver.
325 We make an exception for cards that look like serial devices.
327 ======================================================================*/
329 static int __init is_active(int s)
331 u_short scf1, ioctl, base, num;
335 tcic_setl(TCIC_ADDR, (s << TCIC_ADDR_SS_SHFT)
336 | TCIC_ADDR_INDREG | TCIC_SCF1(s));
337 scf1 = tcic_getw(TCIC_DATA);
338 pwr = tcic_getb(TCIC_PWR);
339 sstat = tcic_getb(TCIC_SSTAT);
340 addr = TCIC_IWIN(s, 0);
341 tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);
342 base = tcic_getw(TCIC_DATA);
343 tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);
344 ioctl = tcic_getw(TCIC_DATA);
346 if (ioctl & TCIC_ICTL_TINY)
349 num = (base ^ (base-1));
350 base = base & (base-1);
353 if ((sstat & TCIC_SSTAT_CD) && (pwr & TCIC_PWR_VCC(s)) &&
354 (scf1 & TCIC_SCF1_IOSTS) && (ioctl & TCIC_ICTL_ENA) &&
355 (check_region(base, num) != 0) && ((base & 0xfeef) != 0x02e8))
361 /*======================================================================
363 This returns the revision code for the specified socket.
365 ======================================================================*/
367 static int __init get_tcic_id(void)
371 tcic_aux_setw(TCIC_AUX_TEST, TCIC_TEST_DIAG);
372 id = tcic_aux_getw(TCIC_AUX_ILOCK);
373 id = (id & TCIC_ILOCKTEST_ID_MASK) >> TCIC_ILOCKTEST_ID_SH;
374 tcic_aux_setw(TCIC_AUX_TEST, 0);
378 /*====================================================================*/
380 static int __init init_tcic(void)
386 DEBUG(0, "%s\n", version);
387 pcmcia_get_card_services_info(&serv);
388 if (serv.Revision != CS_RELEASE_CODE) {
389 printk(KERN_NOTICE "tcic: Card Services release "
390 "does not match!\n");
394 printk(KERN_INFO "Databook TCIC-2 PCMCIA probe: ");
397 if (check_region(tcic_base, 16) == 0) {
398 tcic_setw(TCIC_ADDR, 0);
399 if (tcic_getw(TCIC_ADDR) == 0) {
400 tcic_setw(TCIC_ADDR, 0xc3a5);
401 if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;
404 /* See if resetting the controller does any good */
405 tcic_setb(TCIC_SCTRL, TCIC_SCTRL_RESET);
406 tcic_setb(TCIC_SCTRL, 0);
407 tcic_setw(TCIC_ADDR, 0);
408 if (tcic_getw(TCIC_ADDR) == 0) {
409 tcic_setw(TCIC_ADDR, 0xc3a5);
410 if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;
414 printk("could not allocate ports, ");
417 printk("not found.\n");
421 request_region(tcic_base, 16, "tcic-2");
424 for (i = 0; i < sock; i++) {
425 if ((i == ignore) || is_active(i)) continue;
426 socket_table[sockets].psock = i;
427 socket_table[sockets].handler = NULL;
428 socket_table[sockets].info = NULL;
429 socket_table[sockets].id = get_tcic_id();
433 switch (socket_table[0].id) {
434 case TCIC_ID_DB86082:
435 printk("DB86082"); break;
436 case TCIC_ID_DB86082A:
437 printk("DB86082A"); break;
438 case TCIC_ID_DB86084:
439 printk("DB86084"); break;
440 case TCIC_ID_DB86084A:
441 printk("DB86084A"); break;
442 case TCIC_ID_DB86072:
443 printk("DB86072"); break;
444 case TCIC_ID_DB86184:
445 printk("DB86184"); break;
446 case TCIC_ID_DB86082B:
447 printk("DB86082B"); break;
449 printk("Unknown ID 0x%02x", socket_table[0].id);
453 poll_timer.function = &tcic_timer;
455 init_timer(&poll_timer);
457 /* Build interrupt mask */
458 printk(", %d sockets\n" KERN_INFO " irq list (", sockets);
459 if (irq_list[0] == -1)
462 for (i = mask = 0; i < 16; i++)
463 mask |= (1<<irq_list[i]);
464 mask &= tcic_cap.irq_mask;
466 /* Scan interrupts */
467 mask = irq_scan(mask);
468 tcic_cap.irq_mask = mask;
470 /* Check for only two interrupts available */
471 scan = (mask & (mask-1));
472 if (((scan & (scan-1)) == 0) && (poll_interval == 0))
475 if (poll_interval == 0) {
476 /* Avoid irq 12 unless it is explicitly requested */
477 u_int cs_mask = mask & ((cs_irq) ? (1<<cs_irq) : ~(1<<12));
478 for (i = 15; i > 0; i--)
479 if ((cs_mask & (1 << i)) &&
480 (request_irq(i, tcic_interrupt, 0, "tcic",
481 tcic_interrupt) == 0))
484 if (cs_irq == 0) poll_interval = HZ;
487 if (tcic_cap.irq_mask & (1 << 11))
488 printk("sktirq is irq 11, ");
490 printk("status change on irq %d\n", cs_irq);
492 printk("polled status, interval = %d ms\n",
493 poll_interval * 1000 / HZ);
495 for (i = 0; i < sockets; i++) {
496 tcic_setw(TCIC_ADDR+2, socket_table[i].psock << TCIC_SS_SHFT);
497 socket_table[i].last_sstat = tcic_getb(TCIC_SSTAT);
500 /* jump start interrupt handler, if needed */
501 tcic_interrupt(0, NULL, NULL);
503 if (register_ss_entry(sockets, &tcic_operations) != 0) {
504 printk(KERN_NOTICE "tcic: register_ss_entry() failed\n");
505 release_region(tcic_base, 16);
507 free_irq(cs_irq, tcic_interrupt);
515 /*====================================================================*/
517 static void __exit exit_tcic(void)
520 unregister_ss_entry(&tcic_operations);
524 tcic_aux_setw(TCIC_AUX_SYSCFG, TCIC_SYSCFG_AUTOBUSY|0x0a00);
525 free_irq(cs_irq, tcic_interrupt);
527 if (tcic_timer_pending)
528 del_timer(&poll_timer);
529 restore_flags(flags);
530 release_region(tcic_base, 16);
533 /*====================================================================*/
535 static u_int pending_events[2];
536 static spinlock_t pending_event_lock = SPIN_LOCK_UNLOCKED;
538 static void tcic_bh(void *dummy)
543 for (i=0; i < sockets; i++) {
544 spin_lock_irq(&pending_event_lock);
545 events = pending_events[i];
546 pending_events[i] = 0;
547 spin_unlock_irq(&pending_event_lock);
548 if (socket_table[i].handler)
549 socket_table[i].handler(socket_table[i].info, events);
553 static struct tq_struct tcic_task = {
557 static void tcic_interrupt(int irq, void *dev, struct pt_regs *regs)
563 static volatile int active = 0;
566 printk(KERN_NOTICE "tcic: reentered interrupt handler!\n");
571 DEBUG(2, "tcic: tcic_interrupt()\n");
573 for (i = 0; i < sockets; i++) {
574 psock = socket_table[i].psock;
575 tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT)
576 | TCIC_ADDR_INDREG | TCIC_SCF1(psock));
577 sstat = tcic_getb(TCIC_SSTAT);
578 latch = sstat ^ socket_table[psock].last_sstat;
579 socket_table[i].last_sstat = sstat;
580 if (tcic_getb(TCIC_ICSR) & TCIC_ICSR_CDCHG) {
581 tcic_setb(TCIC_ICSR, TCIC_ICSR_CLEAR);
584 if ((latch == 0) || (socket_table[psock].handler == NULL))
586 events = (latch & TCIC_SSTAT_CD) ? SS_DETECT : 0;
587 events |= (latch & TCIC_SSTAT_WP) ? SS_WRPROT : 0;
588 if (tcic_getw(TCIC_DATA) & TCIC_SCF1_IOSTS) {
589 events |= (latch & TCIC_SSTAT_LBAT1) ? SS_STSCHG : 0;
591 events |= (latch & TCIC_SSTAT_RDY) ? SS_READY : 0;
592 events |= (latch & TCIC_SSTAT_LBAT1) ? SS_BATDEAD : 0;
593 events |= (latch & TCIC_SSTAT_LBAT2) ? SS_BATWARN : 0;
596 spin_lock(&pending_event_lock);
597 pending_events[i] |= events;
598 spin_unlock(&pending_event_lock);
599 schedule_task(&tcic_task);
603 /* Schedule next poll, if needed */
604 if (((cs_irq == 0) || quick) && (!tcic_timer_pending)) {
605 poll_timer.expires = jiffies + (quick ? poll_quick : poll_interval);
606 add_timer(&poll_timer);
607 tcic_timer_pending = 1;
611 DEBUG(2, "tcic: interrupt done\n");
613 } /* tcic_interrupt */
615 static void tcic_timer(u_long data)
617 DEBUG(2, "tcic: tcic_timer()\n");
618 tcic_timer_pending = 0;
619 tcic_interrupt(0, NULL, NULL);
622 /*====================================================================*/
624 static int tcic_register_callback(unsigned int lsock, void (*handler)(void *, unsigned int), void * info)
626 socket_table[lsock].handler = handler;
627 socket_table[lsock].info = info;
628 if (handler == NULL) {
634 } /* tcic_register_callback */
636 /*====================================================================*/
638 static int tcic_get_status(unsigned int lsock, u_int *value)
640 u_short psock = socket_table[lsock].psock;
643 tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT)
644 | TCIC_ADDR_INDREG | TCIC_SCF1(psock));
645 reg = tcic_getb(TCIC_SSTAT);
646 *value = (reg & TCIC_SSTAT_CD) ? SS_DETECT : 0;
647 *value |= (reg & TCIC_SSTAT_WP) ? SS_WRPROT : 0;
648 if (tcic_getw(TCIC_DATA) & TCIC_SCF1_IOSTS) {
649 *value |= (reg & TCIC_SSTAT_LBAT1) ? SS_STSCHG : 0;
651 *value |= (reg & TCIC_SSTAT_RDY) ? SS_READY : 0;
652 *value |= (reg & TCIC_SSTAT_LBAT1) ? SS_BATDEAD : 0;
653 *value |= (reg & TCIC_SSTAT_LBAT2) ? SS_BATWARN : 0;
655 reg = tcic_getb(TCIC_PWR);
656 if (reg & (TCIC_PWR_VCC(psock)|TCIC_PWR_VPP(psock)))
657 *value |= SS_POWERON;
658 DEBUG(1, "tcic: GetStatus(%d) = %#2.2x\n", lsock, *value);
660 } /* tcic_get_status */
662 /*====================================================================*/
664 static int tcic_inquire_socket(unsigned int lsock, socket_cap_t *cap)
668 } /* tcic_inquire_socket */
670 /*====================================================================*/
672 static int tcic_get_socket(unsigned int lsock, socket_state_t *state)
674 u_short psock = socket_table[lsock].psock;
678 tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT)
679 | TCIC_ADDR_INDREG | TCIC_SCF1(psock));
680 scf1 = tcic_getw(TCIC_DATA);
681 state->flags = (scf1 & TCIC_SCF1_IOSTS) ? SS_IOCARD : 0;
682 state->flags |= (scf1 & TCIC_SCF1_DMA_MASK) ? SS_DMA_MODE : 0;
683 state->flags |= (scf1 & TCIC_SCF1_SPKR) ? SS_SPKR_ENA : 0;
684 if (tcic_getb(TCIC_SCTRL) & TCIC_SCTRL_ENA)
685 state->flags |= SS_OUTPUT_ENA;
686 state->io_irq = scf1 & TCIC_SCF1_IRQ_MASK;
687 if (state->io_irq == 1) state->io_irq = 11;
689 reg = tcic_getb(TCIC_PWR);
690 state->Vcc = state->Vpp = 0;
691 if (reg & TCIC_PWR_VCC(psock)) {
692 if (reg & TCIC_PWR_VPP(psock))
695 state->Vcc = state->Vpp = 50;
697 if (reg & TCIC_PWR_VPP(psock)) {
702 reg = tcic_aux_getb(TCIC_AUX_ILOCK);
703 state->flags |= (reg & TCIC_ILOCK_CRESET) ? SS_RESET : 0;
705 /* Card status change interrupt mask */
706 tcic_setw(TCIC_ADDR, TCIC_SCF2(psock));
707 scf2 = tcic_getw(TCIC_DATA);
708 state->csc_mask = (scf2 & TCIC_SCF2_MCD) ? 0 : SS_DETECT;
709 if (state->flags & SS_IOCARD) {
710 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_STSCHG;
712 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_BATDEAD;
713 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT2) ? 0 : SS_BATWARN;
714 state->csc_mask |= (scf2 & TCIC_SCF2_MRDY) ? 0 : SS_READY;
717 DEBUG(1, "tcic: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
718 "io_irq %d, csc_mask %#2.2x\n", lsock, state->flags,
719 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
721 } /* tcic_get_socket */
723 /*====================================================================*/
725 static int tcic_set_socket(unsigned int lsock, socket_state_t *state)
727 u_short psock = socket_table[lsock].psock;
731 DEBUG(1, "tcic: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
732 "io_irq %d, csc_mask %#2.2x)\n", lsock, state->flags,
733 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
734 tcic_setw(TCIC_ADDR+2, (psock << TCIC_SS_SHFT) | TCIC_ADR2_INDREG);
736 reg = tcic_getb(TCIC_PWR);
737 reg &= ~(TCIC_PWR_VCC(psock) | TCIC_PWR_VPP(psock));
739 if (state->Vcc == 50) {
740 switch (state->Vpp) {
741 case 0: reg |= TCIC_PWR_VCC(psock) | TCIC_PWR_VPP(psock); break;
742 case 50: reg |= TCIC_PWR_VCC(psock); break;
743 case 120: reg |= TCIC_PWR_VPP(psock); break;
744 default: return -EINVAL;
746 } else if (state->Vcc != 0)
749 if (reg != tcic_getb(TCIC_PWR))
750 tcic_setb(TCIC_PWR, reg);
752 reg = TCIC_ILOCK_HOLD_CCLK | TCIC_ILOCK_CWAIT;
753 if (state->flags & SS_OUTPUT_ENA) {
754 tcic_setb(TCIC_SCTRL, TCIC_SCTRL_ENA);
755 reg |= TCIC_ILOCK_CRESENA;
757 tcic_setb(TCIC_SCTRL, 0);
758 if (state->flags & SS_RESET)
759 reg |= TCIC_ILOCK_CRESET;
760 tcic_aux_setb(TCIC_AUX_ILOCK, reg);
762 tcic_setw(TCIC_ADDR, TCIC_SCF1(psock));
763 scf1 = TCIC_SCF1_FINPACK;
764 scf1 |= TCIC_IRQ(state->io_irq);
765 if (state->flags & SS_IOCARD) {
766 scf1 |= TCIC_SCF1_IOSTS;
767 if (state->flags & SS_SPKR_ENA)
768 scf1 |= TCIC_SCF1_SPKR;
769 if (state->flags & SS_DMA_MODE)
770 scf1 |= TCIC_SCF1_DREQ2 << TCIC_SCF1_DMA_SHIFT;
772 tcic_setw(TCIC_DATA, scf1);
774 /* Some general setup stuff, and configure status interrupt */
775 reg = TCIC_WAIT_ASYNC | TCIC_WAIT_SENSE | to_cycles(250);
776 tcic_aux_setb(TCIC_AUX_WCTL, reg);
777 tcic_aux_setw(TCIC_AUX_SYSCFG, TCIC_SYSCFG_AUTOBUSY|0x0a00|
780 /* Card status change interrupt mask */
781 tcic_setw(TCIC_ADDR, TCIC_SCF2(psock));
782 scf2 = TCIC_SCF2_MALL;
783 if (state->csc_mask & SS_DETECT) scf2 &= ~TCIC_SCF2_MCD;
784 if (state->flags & SS_IOCARD) {
785 if (state->csc_mask & SS_STSCHG) reg &= ~TCIC_SCF2_MLBAT1;
787 if (state->csc_mask & SS_BATDEAD) reg &= ~TCIC_SCF2_MLBAT1;
788 if (state->csc_mask & SS_BATWARN) reg &= ~TCIC_SCF2_MLBAT2;
789 if (state->csc_mask & SS_READY) reg &= ~TCIC_SCF2_MRDY;
791 tcic_setw(TCIC_DATA, scf2);
792 /* For the ISA bus, the irq should be active-high totem-pole */
793 tcic_setb(TCIC_IENA, TCIC_IENA_CDCHG | TCIC_IENA_CFG_HIGH);
796 } /* tcic_set_socket */
798 /*====================================================================*/
800 static int tcic_get_io_map(unsigned int lsock, struct pccard_io_map *io)
802 u_short psock = socket_table[lsock].psock;
806 if (io->map > 1) return -EINVAL;
807 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
808 addr = TCIC_IWIN(psock, io->map);
809 tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);
810 base = tcic_getw(TCIC_DATA);
811 tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);
812 ioctl = tcic_getw(TCIC_DATA);
814 if (ioctl & TCIC_ICTL_TINY)
815 io->start = io->stop = base;
817 io->start = base & (base-1);
818 io->stop = io->start + (base ^ (base-1));
820 io->speed = to_ns(ioctl & TCIC_ICTL_WSCNT_MASK);
821 io->flags = (ioctl & TCIC_ICTL_ENA) ? MAP_ACTIVE : 0;
822 switch (ioctl & TCIC_ICTL_BW_MASK) {
823 case TCIC_ICTL_BW_DYN:
824 io->flags |= MAP_AUTOSZ; break;
825 case TCIC_ICTL_BW_16:
826 io->flags |= MAP_16BIT; break;
830 DEBUG(1, "tcic: GetIOMap(%d, %d) = %#2.2x, %d ns, "
831 "%#4.4x-%#4.4x\n", lsock, io->map, io->flags,
832 io->speed, io->start, io->stop);
834 } /* tcic_get_io_map */
836 /*====================================================================*/
838 static int tcic_set_io_map(unsigned int lsock, struct pccard_io_map *io)
840 u_short psock = socket_table[lsock].psock;
842 u_short base, len, ioctl;
844 DEBUG(1, "tcic: SetIOMap(%d, %d, %#2.2x, %d ns, "
845 "%#4.4x-%#4.4x)\n", lsock, io->map, io->flags,
846 io->speed, io->start, io->stop);
847 if ((io->map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
848 (io->stop < io->start)) return -EINVAL;
849 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
850 addr = TCIC_IWIN(psock, io->map);
852 base = io->start; len = io->stop - io->start;
853 /* Check to see that len+1 is power of two, etc */
854 if ((len & (len+1)) || (base & len)) return -EINVAL;
856 tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);
857 tcic_setw(TCIC_DATA, base);
859 ioctl = (psock << TCIC_ICTL_SS_SHFT);
860 ioctl |= (len == 0) ? TCIC_ICTL_TINY : 0;
861 ioctl |= (io->flags & MAP_ACTIVE) ? TCIC_ICTL_ENA : 0;
862 ioctl |= to_cycles(io->speed) & TCIC_ICTL_WSCNT_MASK;
863 if (!(io->flags & MAP_AUTOSZ)) {
864 ioctl |= TCIC_ICTL_QUIET;
865 ioctl |= (io->flags & MAP_16BIT) ? TCIC_ICTL_BW_16 : TCIC_ICTL_BW_8;
867 tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);
868 tcic_setw(TCIC_DATA, ioctl);
871 } /* tcic_set_io_map */
873 /*====================================================================*/
875 static int tcic_get_mem_map(unsigned int lsock, struct pccard_mem_map *mem)
877 u_short psock = socket_table[lsock].psock;
881 if (mem->map > 3) return -EINVAL;
882 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
883 addr = TCIC_MWIN(psock, mem->map);
885 tcic_setw(TCIC_ADDR, addr + TCIC_MBASE_X);
886 base = tcic_getw(TCIC_DATA);
887 if (base & TCIC_MBASE_4K_BIT) {
888 mem->sys_start = base & TCIC_MBASE_HA_MASK;
889 mem->sys_stop = mem->sys_start;
891 base &= TCIC_MBASE_HA_MASK;
892 mem->sys_start = (base & (base-1));
893 mem->sys_stop = mem->sys_start + (base ^ (base-1));
895 mem->sys_start = mem->sys_start << TCIC_MBASE_HA_SHFT;
896 mem->sys_stop = (mem->sys_stop << TCIC_MBASE_HA_SHFT) + 0x0fff;
898 tcic_setw(TCIC_ADDR, addr + TCIC_MMAP_X);
899 mmap = tcic_getw(TCIC_DATA);
900 mem->flags = (mmap & TCIC_MMAP_REG) ? MAP_ATTRIB : 0;
901 mmap &= TCIC_MMAP_CA_MASK;
902 mem->card_start = mem->sys_start + (mmap << TCIC_MMAP_CA_SHFT);
903 mem->card_start &= 0x3ffffff;
905 tcic_setw(TCIC_ADDR, addr + TCIC_MCTL_X);
906 ctl = tcic_getw(TCIC_DATA);
907 mem->flags |= (ctl & TCIC_MCTL_ENA) ? MAP_ACTIVE : 0;
908 mem->flags |= (ctl & TCIC_MCTL_B8) ? 0 : MAP_16BIT;
909 mem->flags |= (ctl & TCIC_MCTL_WP) ? MAP_WRPROT : 0;
910 mem->speed = to_ns(ctl & TCIC_MCTL_WSCNT_MASK);
912 DEBUG(1, "tcic: GetMemMap(%d, %d) = %#2.2x, %d ns, "
913 "%#5.5lx-%#5.5lx, %#5.5x\n", lsock, mem->map, mem->flags,
914 mem->speed, mem->sys_start, mem->sys_stop, mem->card_start);
916 } /* tcic_get_mem_map */
918 /*====================================================================*/
920 static int tcic_set_mem_map(unsigned int lsock, struct pccard_mem_map *mem)
922 u_short psock = socket_table[lsock].psock;
924 u_long base, len, mmap;
926 DEBUG(1, "tcic: SetMemMap(%d, %d, %#2.2x, %d ns, "
927 "%#5.5lx-%#5.5lx, %#5.5x)\n", lsock, mem->map, mem->flags,
928 mem->speed, mem->sys_start, mem->sys_stop, mem->card_start);
929 if ((mem->map > 3) || (mem->card_start > 0x3ffffff) ||
930 (mem->sys_start > 0xffffff) || (mem->sys_stop > 0xffffff) ||
931 (mem->sys_start > mem->sys_stop) || (mem->speed > 1000))
933 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
934 addr = TCIC_MWIN(psock, mem->map);
936 base = mem->sys_start; len = mem->sys_stop - mem->sys_start;
937 if ((len & (len+1)) || (base & len)) return -EINVAL;
939 base = (base >> TCIC_MBASE_HA_SHFT) | TCIC_MBASE_4K_BIT;
941 base = (base | (len+1)>>1) >> TCIC_MBASE_HA_SHFT;
942 tcic_setw(TCIC_ADDR, addr + TCIC_MBASE_X);
943 tcic_setw(TCIC_DATA, base);
945 mmap = mem->card_start - mem->sys_start;
946 mmap = (mmap >> TCIC_MMAP_CA_SHFT) & TCIC_MMAP_CA_MASK;
947 if (mem->flags & MAP_ATTRIB) mmap |= TCIC_MMAP_REG;
948 tcic_setw(TCIC_ADDR, addr + TCIC_MMAP_X);
949 tcic_setw(TCIC_DATA, mmap);
951 ctl = TCIC_MCTL_QUIET | (psock << TCIC_MCTL_SS_SHFT);
952 ctl |= to_cycles(mem->speed) & TCIC_MCTL_WSCNT_MASK;
953 ctl |= (mem->flags & MAP_16BIT) ? 0 : TCIC_MCTL_B8;
954 ctl |= (mem->flags & MAP_WRPROT) ? TCIC_MCTL_WP : 0;
955 ctl |= (mem->flags & MAP_ACTIVE) ? TCIC_MCTL_ENA : 0;
956 tcic_setw(TCIC_ADDR, addr + TCIC_MCTL_X);
957 tcic_setw(TCIC_DATA, ctl);
960 } /* tcic_set_mem_map */
962 /*====================================================================*/
964 static void tcic_proc_setup(unsigned int sock, struct proc_dir_entry *base)
968 static int tcic_init(unsigned int s)
971 pccard_io_map io = { 0, 0, 0, 0, 1 };
972 pccard_mem_map mem = { 0, 0, 0, 0, 0, 0 };
974 mem.sys_stop = 0x1000;
975 tcic_set_socket(s, &dead_socket);
976 for (i = 0; i < 2; i++) {
978 tcic_set_io_map(s, &io);
980 for (i = 0; i < 5; i++) {
982 tcic_set_mem_map(s, &mem);
987 static int tcic_suspend(unsigned int sock)
989 return tcic_set_socket(sock, &dead_socket);
992 static struct pccard_operations tcic_operations = {
995 tcic_register_callback,
1007 /*====================================================================*/
1009 module_init(init_tcic);
1010 module_exit(exit_tcic);