📄 i82365.c
字号:
/*====================================================================== Device driver for Intel 82365 and compatible PC Card controllers. i82365.c 1.265 1999/11/10 18:36:21 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 <dhinds@pcmcia.sourceforge.org>. 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 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/config.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/string.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/timer.h>#include <linux/sched.h>#include <linux/malloc.h>#include <linux/pci.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/proc_fs.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/bitops.h>#include <asm/segment.h>#include <asm/system.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/ss.h>#include <pcmcia/cs.h>/* ISA-bus controllers */#include "i82365.h"#include "cirrus.h"#include "vg468.h"#include "ricoh.h"#include "o2micro.h"/* PCI-bus controllers */#include "old-yenta.h"#include "smc34c90.h"#include "topic.h"#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;MODULE_PARM(pc_debug, "i");#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static const char *version ="i82365.c 1.265 1999/11/10 18:36:21 (David Hinds)";#else#define DEBUG(n, args...) do { } while (0)#endifstatic void irq_count(int, void *, struct pt_regs *);static inline int _check_irq(int irq, int flags){ if (request_irq(irq, irq_count, flags, "x", irq_count) != 0) return -1; free_irq(irq, irq_count); return 0;}/*====================================================================*//* Parameters that can be set with 'insmod' */#ifdef CONFIG_ISA/* Default base address for i82365sl and other ISA chips */static int i365_base = 0x3e0;/* Should we probe at 0x3e2 for an extra ISA controller? */static int extra_sockets = 0;/* Specify a socket number to ignore */static int ignore = -1;/* Bit map or list of interrupts to choose from */static u_int irq_mask = 0xffff;static int irq_list[16] = { -1 };/* The card status change interrupt -- 0 means autoselect */static int cs_irq = 0;#endif/* Probe for safe interrupts? */static int do_scan = 1;/* Poll status interval -- 0 means default to interrupt */static int poll_interval = 0;/* External clock time, in nanoseconds. 120 ns = 8.33 MHz */static int cycle_time = 120;/* Cirrus options */static int has_dma = -1;static int has_led = -1;static int has_ring = -1;static int dynamic_mode = 0;static int freq_bypass = -1;static int setup_time = -1;static int cmd_time = -1;static int recov_time = -1;#ifdef CONFIG_ISA/* Vadem options */static int async_clock = -1;static int cable_mode = -1;static int wakeup = 0;#endif#ifdef CONFIG_ISAMODULE_PARM(i365_base, "i");MODULE_PARM(ignore, "i");MODULE_PARM(extra_sockets, "i");MODULE_PARM(irq_mask, "i");MODULE_PARM(irq_list, "1-16i");MODULE_PARM(cs_irq, "i");MODULE_PARM(async_clock, "i");MODULE_PARM(cable_mode, "i");MODULE_PARM(wakeup, "i");#endifMODULE_PARM(do_scan, "i");MODULE_PARM(poll_interval, "i");MODULE_PARM(cycle_time, "i");MODULE_PARM(has_dma, "i");MODULE_PARM(has_led, "i");MODULE_PARM(has_ring, "i");MODULE_PARM(dynamic_mode, "i");MODULE_PARM(freq_bypass, "i");MODULE_PARM(setup_time, "i");MODULE_PARM(cmd_time, "i");MODULE_PARM(recov_time, "i");/*====================================================================*/typedef struct cirrus_state_t { u_char misc1, misc2; u_char timer[6];} cirrus_state_t;typedef struct vg46x_state_t { u_char ctl, ema;} vg46x_state_t;typedef struct socket_info_t { u_short type, flags; socket_cap_t cap; ioaddr_t ioaddr; u_short psock; u_char cs_irq, intr; void (*handler)(void *info, u_int events); void *info;#ifdef CONFIG_PROC_FS struct proc_dir_entry *proc;#endif union { cirrus_state_t cirrus; vg46x_state_t vg46x; } state;} socket_info_t;/* Where we keep track of our sockets... */static int sockets = 0;static socket_info_t socket[8] = { { 0, }, /* ... */};/* Default ISA interrupt mask */#define I365_MASK 0xdeb8 /* irq 15,14,12,11,10,9,7,5,4,3 */#ifdef CONFIG_ISAstatic int grab_irq;static spinlock_t isa_lock = SPIN_LOCK_UNLOCKED;#define ISA_LOCK(n, f) spin_lock_irqsave(&isa_lock, f)#define ISA_UNLOCK(n, f) spin_unlock_irqrestore(&isa_lock, f)#else#define ISA_LOCK(n, f) do { } while (0)#define ISA_UNLOCK(n, f) do { } while (0)#endifstatic struct timer_list poll_timer;/*====================================================================*//* Default settings for PCI command configuration register */#define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \ PCI_COMMAND_MASTER|PCI_COMMAND_WAIT)/* These definitions must match the pcic table! */typedef enum pcic_id {#ifdef CONFIG_ISA IS_I82365A, IS_I82365B, IS_I82365DF, IS_IBM, IS_RF5Cx96, IS_VLSI, IS_VG468, IS_VG469, IS_PD6710, IS_PD672X, IS_VT83C469,#endif} pcic_id;/* Flags for classifying groups of controllers */#define IS_VADEM 0x0001#define IS_CIRRUS 0x0002#define IS_TI 0x0004#define IS_O2MICRO 0x0008#define IS_VIA 0x0010#define IS_TOPIC 0x0020#define IS_RICOH 0x0040#define IS_UNKNOWN 0x0400#define IS_VG_PWR 0x0800#define IS_DF_PWR 0x1000#define IS_PCI 0x2000#define IS_ALIVE 0x8000typedef struct pcic_t { char *name; u_short flags;} pcic_t;static pcic_t pcic[] = {#ifdef CONFIG_ISA { "Intel i82365sl A step", 0 }, { "Intel i82365sl B step", 0 }, { "Intel i82365sl DF", IS_DF_PWR }, { "IBM Clone", 0 }, { "Ricoh RF5C296/396", 0 }, { "VLSI 82C146", 0 }, { "Vadem VG-468", IS_VADEM }, { "Vadem VG-469", IS_VADEM|IS_VG_PWR }, { "Cirrus PD6710", IS_CIRRUS }, { "Cirrus PD672x", IS_CIRRUS }, { "VIA VT83C469", IS_CIRRUS|IS_VIA },#endif};#define PCIC_COUNT (sizeof(pcic)/sizeof(pcic_t))/*====================================================================*/static u_char i365_get(u_short sock, u_short reg){ { ioaddr_t port = socket[sock].ioaddr; u_char val; reg = I365_REG(socket[sock].psock, reg); outb(reg, port); val = inb(port+1); return val; }}static void i365_set(u_short sock, u_short reg, u_char data){ { ioaddr_t port = socket[sock].ioaddr; u_char val = I365_REG(socket[sock].psock, reg); outb(val, port); outb(data, port+1); }}static void i365_bset(u_short sock, u_short reg, u_char mask){ u_char d = i365_get(sock, reg); d |= mask; i365_set(sock, reg, d);}static void i365_bclr(u_short sock, u_short reg, u_char mask){ u_char d = i365_get(sock, reg); d &= ~mask; i365_set(sock, reg, d);}static void i365_bflip(u_short sock, u_short reg, u_char mask, int b){ u_char d = i365_get(sock, reg); if (b) d |= mask; else d &= ~mask; i365_set(sock, reg, d);}static u_short i365_get_pair(u_short sock, u_short reg){ u_short a, b; a = i365_get(sock, reg); b = i365_get(sock, reg+1); return (a + (b<<8));}static void i365_set_pair(u_short sock, u_short reg, u_short data){ i365_set(sock, reg, data & 0xff); i365_set(sock, reg+1, data >> 8);}/*====================================================================== Code to save and restore global state information for Cirrus PD67xx controllers, and to set and report global configuration options. The VIA controllers also use these routines, as they are mostly Cirrus lookalikes, without the timing registers. ======================================================================*/#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))static void cirrus_get_state(u_short s){ int i; cirrus_state_t *p = &socket[s].state.cirrus; p->misc1 = i365_get(s, PD67_MISC_CTL_1); p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); p->misc2 = i365_get(s, PD67_MISC_CTL_2); for (i = 0; i < 6; i++) p->timer[i] = i365_get(s, PD67_TIME_SETUP(0)+i);}static void cirrus_set_state(u_short s){ int i; u_char misc; cirrus_state_t *p = &socket[s].state.cirrus; misc = i365_get(s, PD67_MISC_CTL_2); i365_set(s, PD67_MISC_CTL_2, p->misc2); if (misc & PD67_MC2_SUSPEND) mdelay(50); misc = i365_get(s, PD67_MISC_CTL_1); misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); i365_set(s, PD67_MISC_CTL_1, misc | p->misc1); for (i = 0; i < 6; i++) i365_set(s, PD67_TIME_SETUP(0)+i, p->timer[i]);}static u_int __init cirrus_set_opts(u_short s, char *buf){ socket_info_t *t = &socket[s]; cirrus_state_t *p = &socket[s].state.cirrus; u_int mask = 0xffff; if (has_ring == -1) has_ring = 1; flip(p->misc2, PD67_MC2_IRQ15_RI, has_ring); flip(p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode); if (p->misc2 & PD67_MC2_IRQ15_RI) strcat(buf, " [ring]"); if (p->misc2 & PD67_MC2_DYNAMIC_MODE) strcat(buf, " [dyn mode]"); if (p->misc1 & PD67_MC1_INPACK_ENA) strcat(buf, " [inpack]"); if (!(t->flags & IS_PCI)) { if (p->misc2 & PD67_MC2_IRQ15_RI) mask &= ~0x8000; if (has_led > 0) { strcat(buf, " [led]"); mask &= ~0x1000; } if (has_dma > 0) { strcat(buf, " [dma]"); mask &= ~0x0600; flip(p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass); if (p->misc2 & PD67_MC2_FREQ_BYPASS) strcat(buf, " [freq bypass]"); } } if (!(t->flags & IS_VIA)) { if (setup_time >= 0) p->timer[0] = p->timer[3] = setup_time; if (cmd_time > 0) { p->timer[1] = cmd_time; p->timer[4] = cmd_time*2+4; } if (p->timer[1] == 0) { p->timer[1] = 6; p->timer[4] = 16; if (p->timer[0] == 0) p->timer[0] = p->timer[3] = 1; } if (recov_time >= 0) p->timer[2] = p->timer[5] = recov_time; buf += strlen(buf); sprintf(buf, " [%d/%d/%d] [%d/%d/%d]", p->timer[0], p->timer[1], p->timer[2], p->timer[3], p->timer[4], p->timer[5]); } return mask;}/*====================================================================== Code to save and restore global state information for Vadem VG468 and VG469 controllers, and to set and report global configuration options. ======================================================================*/#ifdef CONFIG_ISAstatic void vg46x_get_state(u_short s){ vg46x_state_t *p = &socket[s].state.vg46x; p->ctl = i365_get(s, VG468_CTL); if (socket[s].type == IS_VG469) p->ema = i365_get(s, VG469_EXT_MODE);}static void vg46x_set_state(u_short s){ vg46x_state_t *p = &socket[s].state.vg46x; i365_set(s, VG468_CTL, p->ctl); if (socket[s].type == IS_VG469) i365_set(s, VG469_EXT_MODE, p->ema);}static u_int __init vg46x_set_opts(u_short s, char *buf){ vg46x_state_t *p = &socket[s].state.vg46x; flip(p->ctl, VG468_CTL_ASYNC, async_clock); flip(p->ema, VG469_MODE_CABLE, cable_mode); if (p->ctl & VG468_CTL_ASYNC) strcat(buf, " [async]"); if (p->ctl & VG468_CTL_INPACK) strcat(buf, " [inpack]"); if (socket[s].type == IS_VG469) { u_char vsel = i365_get(s, VG469_VSELECT); if (vsel & VG469_VSEL_EXT_STAT) { strcat(buf, " [ext mode]"); if (vsel & VG469_VSEL_EXT_BUS) strcat(buf, " [isa buf]"); } if (p->ema & VG469_MODE_CABLE) strcat(buf, " [cable]"); if (p->ema & VG469_MODE_COMPAT) strcat(buf, " [c step]"); } return 0xffff;}#endif/*====================================================================== Generic routines to get and set controller options ======================================================================*/static void get_bridge_state(u_short s){ socket_info_t *t = &socket[s]; if (t->flags & IS_CIRRUS) cirrus_get_state(s);#ifdef CONFIG_ISA else if (t->flags & IS_VADEM) vg46x_get_state(s);#endif}static void set_bridge_state(u_short s){ socket_info_t *t = &socket[s]; if (t->flags & IS_CIRRUS) cirrus_set_state(s); else { i365_set(s, I365_GBLCTL, 0x00); i365_set(s, I365_GENCTL, 0x00); } i365_bflip(s, I365_INTCTL, I365_INTR_ENA, t->intr);#ifdef CONFIG_ISA if (t->flags & IS_VADEM) vg46x_set_state(s);#endif}static u_int __init set_bridge_opts(u_short s, u_short ns){ u_short i; u_int m = 0xffff; char buf[128]; for (i = s; i < s+ns; i++) { if (socket[i].flags & IS_ALIVE) { printk(KERN_INFO " host opts [%d]: already alive!\n", i); continue; } buf[0] = '\0'; get_bridge_state(i); if (socket[i].flags & IS_CIRRUS) m = cirrus_set_opts(i, buf);#ifdef CONFIG_ISA else if (socket[i].flags & IS_VADEM) m = vg46x_set_opts(i, buf);#endif set_bridge_state(i); printk(KERN_INFO " host opts [%d]:%s\n", i, (*buf) ? buf : " none"); } return m;}/*====================================================================== Interrupt testing code, for ISA and PCI interrupts ======================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -