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/moduleparam.h>
36 #include <linux/init.h>
37 #include <linux/types.h>
38 #include <linux/fcntl.h>
39 #include <linux/string.h>
40 #include <linux/errno.h>
41 #include <linux/interrupt.h>
42 #include <linux/slab.h>
43 #include <linux/timer.h>
44 #include <linux/ioport.h>
45 #include <linux/delay.h>
46 #include <linux/workqueue.h>
47 #include <linux/device.h>
48 #include <linux/bitops.h>
51 #include <asm/system.h>
53 #include <pcmcia/cs_types.h>
54 #include <pcmcia/cs.h>
55 #include <pcmcia/ss.h>
61 module_param(pc_debug, int, 0644);
62 static const char version[] =
63 "tcic.c 1.111 2000/02/15 04:13:12 (David Hinds)";
65 #define debug(lvl, fmt, arg...) do { \
66 if (pc_debug > (lvl)) \
67 printk(KERN_DEBUG "tcic: " fmt , ## arg); \
70 #define debug(lvl, fmt, arg...) do { } while (0)
73 MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
74 MODULE_DESCRIPTION("Databook TCIC-2 PCMCIA socket driver");
75 MODULE_LICENSE("Dual MPL/GPL");
77 /*====================================================================*/
79 /* Parameters that can be set with 'insmod' */
81 /* The base port address of the TCIC-2 chip */
82 static unsigned long tcic_base = TCIC_BASE;
84 /* Specify a socket number to ignore */
85 static int ignore = -1;
87 /* Probe for safe interrupts? */
88 static int do_scan = 1;
90 /* Bit map of interrupts to choose from */
91 static u_int irq_mask = 0xffff;
92 static int irq_list[16];
93 static int irq_list_count;
95 /* The card status change interrupt -- 0 means autoselect */
98 /* Poll status interval -- 0 means default to interrupt */
99 static int poll_interval;
101 /* Delay for card status double-checking */
102 static int poll_quick = HZ/20;
104 /* CCLK external clock time, in nanoseconds. 70 ns = 14.31818 MHz */
105 static int cycle_time = 70;
107 module_param(tcic_base, ulong, 0444);
108 module_param(ignore, int, 0444);
109 module_param(do_scan, int, 0444);
110 module_param(irq_mask, int, 0444);
111 module_param_array(irq_list, int, &irq_list_count, 0444);
112 module_param(cs_irq, int, 0444);
113 module_param(poll_interval, int, 0444);
114 module_param(poll_quick, int, 0444);
115 module_param(cycle_time, int, 0444);
117 /*====================================================================*/
119 static irqreturn_t tcic_interrupt(int irq, void *dev, struct pt_regs *regs);
120 static void tcic_timer(u_long data);
121 static struct pccard_operations tcic_operations;
127 struct pcmcia_socket socket;
130 static struct timer_list poll_timer;
131 static int tcic_timer_pending;
134 static struct tcic_socket socket_table[2];
136 /*====================================================================*/
138 /* Trick when selecting interrupts: the TCIC sktirq pin is supposed
139 to map to irq 11, but is coded as 0 or 1 in the irq registers. */
140 #define TCIC_IRQ(x) ((x) ? (((x) == 11) ? 1 : (x)) : 15)
143 static u_char tcic_getb(u_char reg)
145 u_char val = inb(tcic_base+reg);
146 printk(KERN_DEBUG "tcic_getb(%#lx) = %#x\n", tcic_base+reg, val);
150 static u_short tcic_getw(u_char reg)
152 u_short val = inw(tcic_base+reg);
153 printk(KERN_DEBUG "tcic_getw(%#lx) = %#x\n", tcic_base+reg, val);
157 static void tcic_setb(u_char reg, u_char data)
159 printk(KERN_DEBUG "tcic_setb(%#lx, %#x)\n", tcic_base+reg, data);
160 outb(data, tcic_base+reg);
163 static void tcic_setw(u_char reg, u_short data)
165 printk(KERN_DEBUG "tcic_setw(%#lx, %#x)\n", tcic_base+reg, data);
166 outw(data, tcic_base+reg);
169 #define tcic_getb(reg) inb(tcic_base+reg)
170 #define tcic_getw(reg) inw(tcic_base+reg)
171 #define tcic_setb(reg, data) outb(data, tcic_base+reg)
172 #define tcic_setw(reg, data) outw(data, tcic_base+reg)
175 static void tcic_setl(u_char reg, u_int data)
178 printk(KERN_DEBUG "tcic_setl(%#x, %#lx)\n", tcic_base+reg, data);
180 outw(data & 0xffff, tcic_base+reg);
181 outw(data >> 16, tcic_base+reg+2);
184 static u_char tcic_aux_getb(u_short reg)
186 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
187 tcic_setb(TCIC_MODE, mode);
188 return tcic_getb(TCIC_AUX);
191 static void tcic_aux_setb(u_short reg, u_char data)
193 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
194 tcic_setb(TCIC_MODE, mode);
195 tcic_setb(TCIC_AUX, data);
198 static u_short tcic_aux_getw(u_short reg)
200 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
201 tcic_setb(TCIC_MODE, mode);
202 return tcic_getw(TCIC_AUX);
205 static void tcic_aux_setw(u_short reg, u_short data)
207 u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;
208 tcic_setb(TCIC_MODE, mode);
209 tcic_setw(TCIC_AUX, data);
212 /*====================================================================*/
214 /* Time conversion functions */
216 static int to_cycles(int ns)
221 return 2*(ns-14)/cycle_time;
224 /*====================================================================*/
226 static volatile u_int irq_hits;
228 static irqreturn_t __init tcic_irq_count(int irq, void *dev, struct pt_regs *regs)
234 static u_int __init try_irq(int irq)
239 if (request_irq(irq, tcic_irq_count, 0, "irq scan", tcic_irq_count) != 0)
243 free_irq(irq, tcic_irq_count);
247 /* Generate one interrupt */
248 cfg = TCIC_SYSCFG_AUTOBUSY | 0x0a00;
249 tcic_aux_setw(TCIC_AUX_SYSCFG, cfg | TCIC_IRQ(irq));
250 tcic_setb(TCIC_IENA, TCIC_IENA_ERR | TCIC_IENA_CFG_HIGH);
251 tcic_setb(TCIC_ICSR, TCIC_ICSR_ERR | TCIC_ICSR_JAM);
254 free_irq(irq, tcic_irq_count);
256 /* Turn off interrupts */
257 tcic_setb(TCIC_IENA, TCIC_IENA_CFG_OFF);
258 while (tcic_getb(TCIC_ICSR))
259 tcic_setb(TCIC_ICSR, TCIC_ICSR_JAM);
260 tcic_aux_setw(TCIC_AUX_SYSCFG, cfg);
262 return (irq_hits != 1);
265 static u_int __init irq_scan(u_int mask0)
272 /* Don't probe level-triggered interrupts -- reserved for PCI */
273 int level_mask = inb_p(PIC) | (inb_p(PIC+1) << 8);
275 mask0 &= ~level_mask;
280 for (i = 0; i < 16; i++)
281 if ((mask0 & (1 << i)) && (try_irq(i) == 0))
283 for (i = 0; i < 16; i++)
284 if ((mask1 & (1 << i)) && (try_irq(i) != 0)) {
292 /* Fallback: just find interrupts that aren't in use */
293 for (i = 0; i < 16; i++)
294 if ((mask0 & (1 << i)) &&
295 (request_irq(i, tcic_irq_count, 0, "x", tcic_irq_count) == 0)) {
297 free_irq(i, tcic_irq_count);
303 for (i = 0; i < 16; i++)
305 printk("%s%d", ((mask1 & ((1<<i)-1)) ? "," : ""), i);
311 /*======================================================================
313 See if a card is present, powered up, in IO mode, and already
314 bound to a (non-PCMCIA) Linux driver.
316 We make an exception for cards that look like serial devices.
318 ======================================================================*/
320 static int __init is_active(int s)
322 u_short scf1, ioctl, base, num;
326 tcic_setl(TCIC_ADDR, (s << TCIC_ADDR_SS_SHFT)
327 | TCIC_ADDR_INDREG | TCIC_SCF1(s));
328 scf1 = tcic_getw(TCIC_DATA);
329 pwr = tcic_getb(TCIC_PWR);
330 sstat = tcic_getb(TCIC_SSTAT);
331 addr = TCIC_IWIN(s, 0);
332 tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);
333 base = tcic_getw(TCIC_DATA);
334 tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);
335 ioctl = tcic_getw(TCIC_DATA);
337 if (ioctl & TCIC_ICTL_TINY)
340 num = (base ^ (base-1));
341 base = base & (base-1);
344 if ((sstat & TCIC_SSTAT_CD) && (pwr & TCIC_PWR_VCC(s)) &&
345 (scf1 & TCIC_SCF1_IOSTS) && (ioctl & TCIC_ICTL_ENA) &&
346 ((base & 0xfeef) != 0x02e8)) {
347 struct resource *res = request_region(base, num, "tcic-2");
348 if (!res) /* region is busy */
350 release_region(base, num);
356 /*======================================================================
358 This returns the revision code for the specified socket.
360 ======================================================================*/
362 static int __init get_tcic_id(void)
366 tcic_aux_setw(TCIC_AUX_TEST, TCIC_TEST_DIAG);
367 id = tcic_aux_getw(TCIC_AUX_ILOCK);
368 id = (id & TCIC_ILOCKTEST_ID_MASK) >> TCIC_ILOCKTEST_ID_SH;
369 tcic_aux_setw(TCIC_AUX_TEST, 0);
373 /*====================================================================*/
375 static struct device_driver tcic_driver = {
376 .name = "tcic-pcmcia",
377 .bus = &platform_bus_type,
378 .suspend = pcmcia_socket_dev_suspend,
379 .resume = pcmcia_socket_dev_resume,
382 static struct platform_device tcic_device = {
383 .name = "tcic-pcmcia",
388 static int __init init_tcic(void)
390 int i, sock, ret = 0;
393 if (driver_register(&tcic_driver))
396 printk(KERN_INFO "Databook TCIC-2 PCMCIA probe: ");
399 if (!request_region(tcic_base, 16, "tcic-2")) {
400 printk("could not allocate ports,\n ");
401 driver_unregister(&tcic_driver);
405 tcic_setw(TCIC_ADDR, 0);
406 if (tcic_getw(TCIC_ADDR) == 0) {
407 tcic_setw(TCIC_ADDR, 0xc3a5);
408 if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;
411 /* See if resetting the controller does any good */
412 tcic_setb(TCIC_SCTRL, TCIC_SCTRL_RESET);
413 tcic_setb(TCIC_SCTRL, 0);
414 tcic_setw(TCIC_ADDR, 0);
415 if (tcic_getw(TCIC_ADDR) == 0) {
416 tcic_setw(TCIC_ADDR, 0xc3a5);
417 if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;
422 printk("not found.\n");
423 release_region(tcic_base, 16);
424 driver_unregister(&tcic_driver);
429 for (i = 0; i < sock; i++) {
430 if ((i == ignore) || is_active(i)) continue;
431 socket_table[sockets].psock = i;
432 socket_table[sockets].id = get_tcic_id();
434 socket_table[sockets].socket.owner = THIS_MODULE;
435 /* only 16-bit cards, memory windows must be size-aligned */
436 /* No PCI or CardBus support */
437 socket_table[sockets].socket.features = SS_CAP_PCCARD | SS_CAP_MEM_ALIGN;
438 /* irq 14, 11, 10, 7, 6, 5, 4, 3 */
439 socket_table[sockets].socket.irq_mask = 0x4cf8;
440 /* 4K minimum window size */
441 socket_table[sockets].socket.map_size = 0x1000;
445 switch (socket_table[0].id) {
446 case TCIC_ID_DB86082:
447 printk("DB86082"); break;
448 case TCIC_ID_DB86082A:
449 printk("DB86082A"); break;
450 case TCIC_ID_DB86084:
451 printk("DB86084"); break;
452 case TCIC_ID_DB86084A:
453 printk("DB86084A"); break;
454 case TCIC_ID_DB86072:
455 printk("DB86072"); break;
456 case TCIC_ID_DB86184:
457 printk("DB86184"); break;
458 case TCIC_ID_DB86082B:
459 printk("DB86082B"); break;
461 printk("Unknown ID 0x%02x", socket_table[0].id);
465 poll_timer.function = &tcic_timer;
467 init_timer(&poll_timer);
469 /* Build interrupt mask */
470 printk(", %d sockets\n" KERN_INFO " irq list (", sockets);
471 if (irq_list_count == 0)
474 for (i = mask = 0; i < irq_list_count; i++)
475 mask |= (1<<irq_list[i]);
477 /* irq 14, 11, 10, 7, 6, 5, 4, 3 */
479 /* Scan interrupts */
480 mask = irq_scan(mask);
481 for (i=0;i<sockets;i++)
482 socket_table[i].socket.irq_mask = mask;
484 /* Check for only two interrupts available */
485 scan = (mask & (mask-1));
486 if (((scan & (scan-1)) == 0) && (poll_interval == 0))
489 if (poll_interval == 0) {
490 /* Avoid irq 12 unless it is explicitly requested */
491 u_int cs_mask = mask & ((cs_irq) ? (1<<cs_irq) : ~(1<<12));
492 for (i = 15; i > 0; i--)
493 if ((cs_mask & (1 << i)) &&
494 (request_irq(i, tcic_interrupt, 0, "tcic",
495 tcic_interrupt) == 0))
498 if (cs_irq == 0) poll_interval = HZ;
501 if (socket_table[0].socket.irq_mask & (1 << 11))
502 printk("sktirq is irq 11, ");
504 printk("status change on irq %d\n", cs_irq);
506 printk("polled status, interval = %d ms\n",
507 poll_interval * 1000 / HZ);
509 for (i = 0; i < sockets; i++) {
510 tcic_setw(TCIC_ADDR+2, socket_table[i].psock << TCIC_SS_SHFT);
511 socket_table[i].last_sstat = tcic_getb(TCIC_SSTAT);
514 /* jump start interrupt handler, if needed */
515 tcic_interrupt(0, NULL, NULL);
517 platform_device_register(&tcic_device);
519 for (i = 0; i < sockets; i++) {
520 socket_table[i].socket.ops = &tcic_operations;
521 socket_table[i].socket.resource_ops = &pccard_nonstatic_ops;
522 socket_table[i].socket.dev.dev = &tcic_device.dev;
523 ret = pcmcia_register_socket(&socket_table[i].socket);
525 pcmcia_unregister_socket(&socket_table[0].socket);
534 /*====================================================================*/
536 static void __exit exit_tcic(void)
540 del_timer_sync(&poll_timer);
542 tcic_aux_setw(TCIC_AUX_SYSCFG, TCIC_SYSCFG_AUTOBUSY|0x0a00);
543 free_irq(cs_irq, tcic_interrupt);
545 release_region(tcic_base, 16);
547 for (i = 0; i < sockets; i++) {
548 pcmcia_unregister_socket(&socket_table[i].socket);
551 platform_device_unregister(&tcic_device);
552 driver_unregister(&tcic_driver);
555 /*====================================================================*/
557 static irqreturn_t 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_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);
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 pcmcia_parse_events(&socket_table[i].socket, events);
600 /* Schedule next poll, if needed */
601 if (((cs_irq == 0) || quick) && (!tcic_timer_pending)) {
602 poll_timer.expires = jiffies + (quick ? poll_quick : poll_interval);
603 add_timer(&poll_timer);
604 tcic_timer_pending = 1;
608 debug(2, "interrupt done\n");
610 } /* tcic_interrupt */
612 static void tcic_timer(u_long data)
614 debug(2, "tcic_timer()\n");
615 tcic_timer_pending = 0;
616 tcic_interrupt(0, NULL, NULL);
619 /*====================================================================*/
621 static int tcic_get_status(struct pcmcia_socket *sock, u_int *value)
623 u_short psock = container_of(sock, struct tcic_socket, socket)->psock;
626 tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT)
627 | TCIC_ADDR_INDREG | TCIC_SCF1(psock));
628 reg = tcic_getb(TCIC_SSTAT);
629 *value = (reg & TCIC_SSTAT_CD) ? SS_DETECT : 0;
630 *value |= (reg & TCIC_SSTAT_WP) ? SS_WRPROT : 0;
631 if (tcic_getw(TCIC_DATA) & TCIC_SCF1_IOSTS) {
632 *value |= (reg & TCIC_SSTAT_LBAT1) ? SS_STSCHG : 0;
634 *value |= (reg & TCIC_SSTAT_RDY) ? SS_READY : 0;
635 *value |= (reg & TCIC_SSTAT_LBAT1) ? SS_BATDEAD : 0;
636 *value |= (reg & TCIC_SSTAT_LBAT2) ? SS_BATWARN : 0;
638 reg = tcic_getb(TCIC_PWR);
639 if (reg & (TCIC_PWR_VCC(psock)|TCIC_PWR_VPP(psock)))
640 *value |= SS_POWERON;
641 debug(1, "GetStatus(%d) = %#2.2x\n", psock, *value);
643 } /* tcic_get_status */
645 /*====================================================================*/
647 static int tcic_get_socket(struct pcmcia_socket *sock, socket_state_t *state)
649 u_short psock = container_of(sock, struct tcic_socket, socket)->psock;
653 tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT)
654 | TCIC_ADDR_INDREG | TCIC_SCF1(psock));
655 scf1 = tcic_getw(TCIC_DATA);
656 state->flags = (scf1 & TCIC_SCF1_IOSTS) ? SS_IOCARD : 0;
657 state->flags |= (scf1 & TCIC_SCF1_DMA_MASK) ? SS_DMA_MODE : 0;
658 state->flags |= (scf1 & TCIC_SCF1_SPKR) ? SS_SPKR_ENA : 0;
659 if (tcic_getb(TCIC_SCTRL) & TCIC_SCTRL_ENA)
660 state->flags |= SS_OUTPUT_ENA;
661 state->io_irq = scf1 & TCIC_SCF1_IRQ_MASK;
662 if (state->io_irq == 1) state->io_irq = 11;
664 reg = tcic_getb(TCIC_PWR);
665 state->Vcc = state->Vpp = 0;
666 if (reg & TCIC_PWR_VCC(psock)) {
667 if (reg & TCIC_PWR_VPP(psock))
670 state->Vcc = state->Vpp = 50;
672 if (reg & TCIC_PWR_VPP(psock)) {
677 reg = tcic_aux_getb(TCIC_AUX_ILOCK);
678 state->flags |= (reg & TCIC_ILOCK_CRESET) ? SS_RESET : 0;
680 /* Card status change interrupt mask */
681 tcic_setw(TCIC_ADDR, TCIC_SCF2(psock));
682 scf2 = tcic_getw(TCIC_DATA);
683 state->csc_mask = (scf2 & TCIC_SCF2_MCD) ? 0 : SS_DETECT;
684 if (state->flags & SS_IOCARD) {
685 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_STSCHG;
687 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_BATDEAD;
688 state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT2) ? 0 : SS_BATWARN;
689 state->csc_mask |= (scf2 & TCIC_SCF2_MRDY) ? 0 : SS_READY;
692 debug(1, "GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
693 "io_irq %d, csc_mask %#2.2x\n", psock, state->flags,
694 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
696 } /* tcic_get_socket */
698 /*====================================================================*/
700 static int tcic_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
702 u_short psock = container_of(sock, struct tcic_socket, socket)->psock;
706 debug(1, "SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
707 "io_irq %d, csc_mask %#2.2x)\n", psock, state->flags,
708 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
709 tcic_setw(TCIC_ADDR+2, (psock << TCIC_SS_SHFT) | TCIC_ADR2_INDREG);
711 reg = tcic_getb(TCIC_PWR);
712 reg &= ~(TCIC_PWR_VCC(psock) | TCIC_PWR_VPP(psock));
714 if (state->Vcc == 50) {
715 switch (state->Vpp) {
716 case 0: reg |= TCIC_PWR_VCC(psock) | TCIC_PWR_VPP(psock); break;
717 case 50: reg |= TCIC_PWR_VCC(psock); break;
718 case 120: reg |= TCIC_PWR_VPP(psock); break;
719 default: return -EINVAL;
721 } else if (state->Vcc != 0)
724 if (reg != tcic_getb(TCIC_PWR))
725 tcic_setb(TCIC_PWR, reg);
727 reg = TCIC_ILOCK_HOLD_CCLK | TCIC_ILOCK_CWAIT;
728 if (state->flags & SS_OUTPUT_ENA) {
729 tcic_setb(TCIC_SCTRL, TCIC_SCTRL_ENA);
730 reg |= TCIC_ILOCK_CRESENA;
732 tcic_setb(TCIC_SCTRL, 0);
733 if (state->flags & SS_RESET)
734 reg |= TCIC_ILOCK_CRESET;
735 tcic_aux_setb(TCIC_AUX_ILOCK, reg);
737 tcic_setw(TCIC_ADDR, TCIC_SCF1(psock));
738 scf1 = TCIC_SCF1_FINPACK;
739 scf1 |= TCIC_IRQ(state->io_irq);
740 if (state->flags & SS_IOCARD) {
741 scf1 |= TCIC_SCF1_IOSTS;
742 if (state->flags & SS_SPKR_ENA)
743 scf1 |= TCIC_SCF1_SPKR;
744 if (state->flags & SS_DMA_MODE)
745 scf1 |= TCIC_SCF1_DREQ2 << TCIC_SCF1_DMA_SHIFT;
747 tcic_setw(TCIC_DATA, scf1);
749 /* Some general setup stuff, and configure status interrupt */
750 reg = TCIC_WAIT_ASYNC | TCIC_WAIT_SENSE | to_cycles(250);
751 tcic_aux_setb(TCIC_AUX_WCTL, reg);
752 tcic_aux_setw(TCIC_AUX_SYSCFG, TCIC_SYSCFG_AUTOBUSY|0x0a00|
755 /* Card status change interrupt mask */
756 tcic_setw(TCIC_ADDR, TCIC_SCF2(psock));
757 scf2 = TCIC_SCF2_MALL;
758 if (state->csc_mask & SS_DETECT) scf2 &= ~TCIC_SCF2_MCD;
759 if (state->flags & SS_IOCARD) {
760 if (state->csc_mask & SS_STSCHG) reg &= ~TCIC_SCF2_MLBAT1;
762 if (state->csc_mask & SS_BATDEAD) reg &= ~TCIC_SCF2_MLBAT1;
763 if (state->csc_mask & SS_BATWARN) reg &= ~TCIC_SCF2_MLBAT2;
764 if (state->csc_mask & SS_READY) reg &= ~TCIC_SCF2_MRDY;
766 tcic_setw(TCIC_DATA, scf2);
767 /* For the ISA bus, the irq should be active-high totem-pole */
768 tcic_setb(TCIC_IENA, TCIC_IENA_CDCHG | TCIC_IENA_CFG_HIGH);
771 } /* tcic_set_socket */
773 /*====================================================================*/
775 static int tcic_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
777 u_short psock = container_of(sock, struct tcic_socket, socket)->psock;
779 u_short base, len, ioctl;
781 debug(1, "SetIOMap(%d, %d, %#2.2x, %d ns, "
782 "%#lx-%#lx)\n", psock, io->map, io->flags,
783 io->speed, io->start, io->stop);
784 if ((io->map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
785 (io->stop < io->start)) return -EINVAL;
786 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
787 addr = TCIC_IWIN(psock, io->map);
789 base = io->start; len = io->stop - io->start;
790 /* Check to see that len+1 is power of two, etc */
791 if ((len & (len+1)) || (base & len)) return -EINVAL;
793 tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);
794 tcic_setw(TCIC_DATA, base);
796 ioctl = (psock << TCIC_ICTL_SS_SHFT);
797 ioctl |= (len == 0) ? TCIC_ICTL_TINY : 0;
798 ioctl |= (io->flags & MAP_ACTIVE) ? TCIC_ICTL_ENA : 0;
799 ioctl |= to_cycles(io->speed) & TCIC_ICTL_WSCNT_MASK;
800 if (!(io->flags & MAP_AUTOSZ)) {
801 ioctl |= TCIC_ICTL_QUIET;
802 ioctl |= (io->flags & MAP_16BIT) ? TCIC_ICTL_BW_16 : TCIC_ICTL_BW_8;
804 tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);
805 tcic_setw(TCIC_DATA, ioctl);
808 } /* tcic_set_io_map */
810 /*====================================================================*/
812 static int tcic_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
814 u_short psock = container_of(sock, struct tcic_socket, socket)->psock;
816 u_long base, len, mmap;
818 debug(1, "SetMemMap(%d, %d, %#2.2x, %d ns, "
819 "%#lx-%#lx, %#x)\n", psock, mem->map, mem->flags,
820 mem->speed, mem->res->start, mem->res->end, mem->card_start);
821 if ((mem->map > 3) || (mem->card_start > 0x3ffffff) ||
822 (mem->res->start > 0xffffff) || (mem->res->end > 0xffffff) ||
823 (mem->res->start > mem->res->end) || (mem->speed > 1000))
825 tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
826 addr = TCIC_MWIN(psock, mem->map);
828 base = mem->res->start; len = mem->res->end - mem->res->start;
829 if ((len & (len+1)) || (base & len)) return -EINVAL;
831 base = (base >> TCIC_MBASE_HA_SHFT) | TCIC_MBASE_4K_BIT;
833 base = (base | (len+1)>>1) >> TCIC_MBASE_HA_SHFT;
834 tcic_setw(TCIC_ADDR, addr + TCIC_MBASE_X);
835 tcic_setw(TCIC_DATA, base);
837 mmap = mem->card_start - mem->res->start;
838 mmap = (mmap >> TCIC_MMAP_CA_SHFT) & TCIC_MMAP_CA_MASK;
839 if (mem->flags & MAP_ATTRIB) mmap |= TCIC_MMAP_REG;
840 tcic_setw(TCIC_ADDR, addr + TCIC_MMAP_X);
841 tcic_setw(TCIC_DATA, mmap);
843 ctl = TCIC_MCTL_QUIET | (psock << TCIC_MCTL_SS_SHFT);
844 ctl |= to_cycles(mem->speed) & TCIC_MCTL_WSCNT_MASK;
845 ctl |= (mem->flags & MAP_16BIT) ? 0 : TCIC_MCTL_B8;
846 ctl |= (mem->flags & MAP_WRPROT) ? TCIC_MCTL_WP : 0;
847 ctl |= (mem->flags & MAP_ACTIVE) ? TCIC_MCTL_ENA : 0;
848 tcic_setw(TCIC_ADDR, addr + TCIC_MCTL_X);
849 tcic_setw(TCIC_DATA, ctl);
852 } /* tcic_set_mem_map */
854 /*====================================================================*/
856 static int tcic_init(struct pcmcia_socket *s)
859 struct resource res = { .start = 0, .end = 0x1000 };
860 pccard_io_map io = { 0, 0, 0, 0, 1 };
861 pccard_mem_map mem = { .res = &res, };
863 for (i = 0; i < 2; i++) {
865 tcic_set_io_map(s, &io);
867 for (i = 0; i < 5; i++) {
869 tcic_set_mem_map(s, &mem);
874 static struct pccard_operations tcic_operations = {
876 .get_status = tcic_get_status,
877 .get_socket = tcic_get_socket,
878 .set_socket = tcic_set_socket,
879 .set_io_map = tcic_set_io_map,
880 .set_mem_map = tcic_set_mem_map,
883 /*====================================================================*/
885 module_init(init_tcic);
886 module_exit(exit_tcic);