⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcic.c

📁 pcmcia source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*======================================================================    Device driver for Databook TCIC-2 PCMCIA controller    tcic.c 1.123 2002/06/29 06:23:09    The contents of this file are subject to the Mozilla Public    License Version 1.1 (the "License"); you may not use this file    except in compliance with the License. You may obtain a copy of    the License at http://www.mozilla.org/MPL/    Software distributed under the License is distributed on an "AS    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or    implied. See the License for the specific language governing    rights and limitations under the License.    The initial developer of the original code is David A. Hinds    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.    Alternatively, the contents of this file may be used under the    terms of the GNU General Public License version 2 (the "GPL"), in    which case the provisions of the GPL are applicable instead of the    above.  If you wish to allow the use of your version of this file    only under the terms of the GPL and not to allow others to use    your version of this file under the MPL, indicate your decision    by deleting the provisions above and replace them with the notice    and other provisions required by the GPL.  If you do not delete    the provisions above, a recipient may use your version of this    file under either the MPL or the GPL.    ======================================================================*/#include <linux/module.h>#include <linux/init.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/string.h>#include <asm/io.h>#include <asm/bitops.h>#include <asm/system.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/slab.h>#include <linux/timer.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/pci.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/ss.h>#include "tcic.h"/*====================================================================*//* Module parameters */MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");MODULE_DESCRIPTION("Databook TCIC-2 PCMCIA socket driver");MODULE_LICENSE("Dual MPL/GPL");#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")INT_MODULE_PARM(tcic_base, TCIC_BASE);	/* base IO port */INT_MODULE_PARM(ignore, -1);		/* socket to ignore */INT_MODULE_PARM(do_scan, 1);		/* probe irq's? */INT_MODULE_PARM(irq_mask, 0xffff);	/* bit map of irq's to use */static int irq_list[16] = { -1 };MODULE_PARM(irq_list, "1-16i");INT_MODULE_PARM(cs_irq, 0);		/* card status irq */INT_MODULE_PARM(poll_interval, 0);	/* in ticks, 0 means never */INT_MODULE_PARM(poll_quick, HZ/20);INT_MODULE_PARM(cycle_time, 70);	/* in ns, 70 = 14.31818 MHz */#ifdef PCMCIA_DEBUGINT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);static const char *version ="tcic.c 1.123 2002/06/29 06:23:09 (David Hinds)";#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)#else#define DEBUG(n, args...)#endif/*====================================================================*/static void tcic_interrupt(int irq, void *dev, struct pt_regs *regs);static void tcic_timer(u_long data);static int tcic_service(u_int sock, u_int cmd, void *arg);typedef struct socket_info_t {    u_short	psock;    void	(*handler)(void *info, u_int events);    void	*info;    u_char	last_sstat;    u_char	id;} socket_info_t;static int sockets;static socket_info_t socket_table[2];static struct timer_list poll_timer = { function: tcic_timer };static socket_cap_t tcic_cap = {    /* only 16-bit cards, memory windows must be size-aligned */    SS_CAP_PCCARD | SS_CAP_MEM_ALIGN,    0x4cf8,		/* irq 14, 11, 10, 7, 6, 5, 4, 3 */    0x1000,		/* 4K minimum window size */    0, 0		/* No PCI or CardBus support */};/*====================================================================*//* Trick when selecting interrupts: the TCIC sktirq pin is supposed   to map to irq 11, but is coded as 0 or 1 in the irq registers. */#define TCIC_IRQ(x) ((x) ? (((x) == 11) ? 1 : (x)) : 15)#ifdef PCMCIA_DEBUG_Xstatic u_char tcic_getb(u_char reg){    u_char val = inb(tcic_base+reg);    printk(KERN_DEBUG "tcic_getb(%#x) = %#x\n", tcic_base+reg, val);    return val;}static u_short tcic_getw(u_char reg){    u_short val = inw(tcic_base+reg);    printk(KERN_DEBUG "tcic_getw(%#x) = %#x\n", tcic_base+reg, val);    return val;}static void tcic_setb(u_char reg, u_char data){    printk(KERN_DEBUG "tcic_setb(%#x, %#x)\n", tcic_base+reg, data);    outb(data, tcic_base+reg);}static void tcic_setw(u_char reg, u_short data){    printk(KERN_DEBUG "tcic_setw(%#x, %#x)\n", tcic_base+reg, data);    outw(data, tcic_base+reg);}#else#define tcic_getb(reg) inb(tcic_base+reg)#define tcic_getw(reg) inw(tcic_base+reg)#define tcic_setb(reg, data) outb(data, tcic_base+reg)#define tcic_setw(reg, data) outw(data, tcic_base+reg)#endifstatic void tcic_setl(u_char reg, u_int data){#ifdef PCMCIA_DEBUG_X    printk(KERN_DEBUG "tcic_setl(%#x, %#lx)\n", tcic_base+reg, data);#endif    outw(data & 0xffff, tcic_base+reg);    outw(data >> 16, tcic_base+reg+2);}static u_char tcic_aux_getb(u_short reg){    u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;    tcic_setb(TCIC_MODE, mode);    return tcic_getb(TCIC_AUX);}static void tcic_aux_setb(u_short reg, u_char data){    u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;    tcic_setb(TCIC_MODE, mode);    tcic_setb(TCIC_AUX, data);}static u_short tcic_aux_getw(u_short reg){    u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;    tcic_setb(TCIC_MODE, mode);    return tcic_getw(TCIC_AUX);}static void tcic_aux_setw(u_short reg, u_short data){    u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg;    tcic_setb(TCIC_MODE, mode);    tcic_setw(TCIC_AUX, data);}/*====================================================================*//* Time conversion functions */static int to_cycles(int ns){    if (ns < 14)	return 0;    else	return 2*(ns-14)/cycle_time;}static int to_ns(int cycles){    return (cycles*cycle_time)/2 + 14;}/*====================================================================*/static volatile u_int irq_hits;static void __init irq_count(int irq, void *dev, struct pt_regs *regs){    irq_hits++;}static u_int __init try_irq(int irq){    u_short cfg;    irq_hits = 0;    if (request_irq(irq, irq_count, 0, "irq scan", irq_count) != 0)	return -1;    mdelay(10);    if (irq_hits) {	free_irq(irq, irq_count);	return -1;    }    /* Generate one interrupt */    cfg = TCIC_SYSCFG_AUTOBUSY | 0x0a00;    tcic_aux_setw(TCIC_AUX_SYSCFG, cfg | TCIC_IRQ(irq));    tcic_setb(TCIC_IENA, TCIC_IENA_ERR | TCIC_IENA_CFG_HIGH);    tcic_setb(TCIC_ICSR, TCIC_ICSR_ERR | TCIC_ICSR_JAM);    mdelay(1);    free_irq(irq, irq_count);    /* Turn off interrupts */    tcic_setb(TCIC_IENA, TCIC_IENA_CFG_OFF);    while (tcic_getb(TCIC_ICSR))	tcic_setb(TCIC_ICSR, TCIC_ICSR_JAM);    tcic_aux_setw(TCIC_AUX_SYSCFG, cfg);        return (irq_hits != 1);}static u_int __init irq_scan(u_int mask0){    u_int mask1;    int i;#ifdef CONFIG_PCI    mask0 &= ~pci_irq_mask;#endif    mask1 = 0;    if (do_scan) {	for (i = 0; i < 16; i++)	    if ((mask0 & (1 << i)) && (try_irq(i) == 0))		mask1 |= (1 << i);	for (i = 0; i < 16; i++)	    if ((mask1 & (1 << i)) && (try_irq(i) != 0)) {		mask1 ^= (1 << i);	    }    }        if (mask1) {	printk("scanned");    } else {	/* Fallback: just find interrupts that aren't in use */	for (i = 0; i < 16; i++)	    if ((mask0 & (1 << i)) &&		(request_irq(i, irq_count, 0, "x", irq_count) == 0)) {		mask1 |= (1 << i);		free_irq(i, irq_count);	    }	printk("default");    }        printk(") = ");    for (i = 0; i < 16; i++)	if (mask1 & (1<<i))	    printk("%s%d", ((mask1 & ((1<<i)-1)) ? "," : ""), i);    printk(" ");        return mask1;}/*======================================================================    See if a card is present, powered up, in IO mode, and already    bound to a (non-PCMCIA) Linux driver.    We make an exception for cards that look like serial devices.    ======================================================================*/static int __init is_active(int s){    u_short scf1, ioctl, base, num;    u_char pwr, sstat;    u_int addr;        tcic_setl(TCIC_ADDR, (s << TCIC_ADDR_SS_SHFT)	      | TCIC_ADDR_INDREG | TCIC_SCF1(s));    scf1 = tcic_getw(TCIC_DATA);    pwr = tcic_getb(TCIC_PWR);    sstat = tcic_getb(TCIC_SSTAT);    addr = TCIC_IWIN(s, 0);    tcic_setw(TCIC_ADDR, addr + TCIC_IBASE_X);    base = tcic_getw(TCIC_DATA);    tcic_setw(TCIC_ADDR, addr + TCIC_ICTL_X);    ioctl = tcic_getw(TCIC_DATA);    if (ioctl & TCIC_ICTL_TINY)	num = 1;    else {	num = (base ^ (base-1));	base = base & (base-1);    }    if ((sstat & TCIC_SSTAT_CD) && (pwr & TCIC_PWR_VCC(s)) &&	(scf1 & TCIC_SCF1_IOSTS) && (ioctl & TCIC_ICTL_ENA) &&	(check_region(base, num) != 0) && ((base & 0xfeef) != 0x02e8))	return 1;    else	return 0;}/*======================================================================    This returns the revision code for the specified socket.    ======================================================================*/static int __init get_tcic_id(void){    u_short id;        tcic_aux_setw(TCIC_AUX_TEST, TCIC_TEST_DIAG);    id = tcic_aux_getw(TCIC_AUX_ILOCK);    id = (id & TCIC_ILOCKTEST_ID_MASK) >> TCIC_ILOCKTEST_ID_SH;    tcic_aux_setw(TCIC_AUX_TEST, 0);    return id;}/*====================================================================*/static int __init init_tcic(void){    int i, sock;    u_int mask, scan;    servinfo_t serv;    DEBUG(0, "%s\n", version);    CardServices(GetCardServicesInfo, &serv);    if (serv.Revision != CS_RELEASE_CODE) {	printk(KERN_NOTICE "tcic: Card Services release "	       "does not match!\n");	return -EINVAL;    }        printk(KERN_INFO "Databook TCIC-2 PCMCIA probe: ");    sock = 0;    if (check_region(tcic_base, 16) == 0) {	tcic_setw(TCIC_ADDR, 0);	if (tcic_getw(TCIC_ADDR) == 0) {	    tcic_setw(TCIC_ADDR, 0xc3a5);	    if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;	}	if (sock == 0) {	    /* See if resetting the controller does any good */	    tcic_setb(TCIC_SCTRL, TCIC_SCTRL_RESET);	    tcic_setb(TCIC_SCTRL, 0);	    tcic_setw(TCIC_ADDR, 0);	    if (tcic_getw(TCIC_ADDR) == 0) {		tcic_setw(TCIC_ADDR, 0xc3a5);		if (tcic_getw(TCIC_ADDR) == 0xc3a5) sock = 2;	    }	}    } else	printk("could not allocate ports, ");    if (sock == 0) {	printk("not found.\n");	return -ENODEV;    }    request_region(tcic_base, 16, "tcic-2");    sockets = 0;    for (i = 0; i < sock; i++) {	if ((i == ignore) || is_active(i)) continue;	socket_table[sockets].psock = i;	socket_table[sockets].handler = NULL;	socket_table[sockets].info = NULL;	socket_table[sockets].id = get_tcic_id();	sockets++;    }    switch (socket_table[0].id) {    case TCIC_ID_DB86082:	printk("DB86082"); break;    case TCIC_ID_DB86082A:	printk("DB86082A"); break;    case TCIC_ID_DB86084:	printk("DB86084"); break;    case TCIC_ID_DB86084A:	printk("DB86084A"); break;    case TCIC_ID_DB86072:	printk("DB86072"); break;    case TCIC_ID_DB86184:	printk("DB86184"); break;    case TCIC_ID_DB86082B:	printk("DB86082B"); break;    default:	printk("Unknown ID 0x%02x", socket_table[0].id);    }        /* Build interrupt mask */    printk(", %d sockets\n" KERN_INFO "  irq list (", sockets);    if (irq_list[0] == -1)	mask = irq_mask;    else	for (i = mask = 0; i < 16; i++)	    mask |= (1<<irq_list[i]);    mask &= tcic_cap.irq_mask;    /* Scan interrupts */    mask = irq_scan(mask);    tcic_cap.irq_mask = mask;        /* Check for only two interrupts available */    scan = (mask & (mask-1));    if (((scan & (scan-1)) == 0) && (poll_interval == 0))	poll_interval = HZ;        if (poll_interval == 0) {	/* Avoid irq 12 unless it is explicitly requested */	u_int cs_mask = mask & ((cs_irq) ? (1<<cs_irq) : ~(1<<12));	for (i = 15; i > 0; i--)	    if ((cs_mask & (1 << i)) &&		(request_irq(i, tcic_interrupt, 0, "tcic",			     tcic_interrupt) == 0))		break;	cs_irq = i;	if (cs_irq == 0) poll_interval = HZ;    }        if (tcic_cap.irq_mask & (1 << 11))	printk("sktirq is irq 11, ");    if (cs_irq != 0)	printk("status change on irq %d\n", cs_irq);    else	printk("polled status, interval = %d ms\n",	       poll_interval * 1000 / HZ);        for (i = 0; i < sockets; i++) {	tcic_setw(TCIC_ADDR+2, socket_table[i].psock << TCIC_SS_SHFT);	socket_table[i].last_sstat = tcic_getb(TCIC_SSTAT);    }    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -