📄 i82365.c
字号:
/*====================================================================== Device driver for Intel 82365 and compatible PC Card controllers, and Yenta-compatible PCI-to-CardBus controllers. i82365.c 1.352 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/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/slab.h>#include <linux/pci.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/proc_fs.h>#include <linux/spinlock.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/bitops.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 "yenta.h"#include "ti113x.h"#include "smc34c90.h"#include "topic.h"#include "ene.h"/*====================================================================*//* Module parameters */MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");MODULE_DESCRIPTION("Intel ExCA/Yenta PCMCIA socket driver");MODULE_LICENSE("Dual MPL/GPL");#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")/* General options */INT_MODULE_PARM(poll_interval, 0); /* in ticks, 0 means never */INT_MODULE_PARM(cycle_time, 120); /* in ns, 120 ns = 8.33 MHz */INT_MODULE_PARM(do_scan, 1); /* Probe free interrupts? *//* Cirrus options */INT_MODULE_PARM(has_dma, -1);INT_MODULE_PARM(has_led, -1);INT_MODULE_PARM(has_ring, -1);INT_MODULE_PARM(dynamic_mode, 0);INT_MODULE_PARM(freq_bypass, -1);INT_MODULE_PARM(setup_time, -1);INT_MODULE_PARM(cmd_time, -1);INT_MODULE_PARM(recov_time, -1);#ifdef CONFIG_ISAINT_MODULE_PARM(i365_base, 0x3e0); /* IO address for probes */INT_MODULE_PARM(extra_sockets, 0); /* Probe at i365_base+2? */INT_MODULE_PARM(ignore, -1); /* Ignore this socket # */INT_MODULE_PARM(cs_irq, 0); /* card status irq */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(async_clock, -1); /* Vadem specific */INT_MODULE_PARM(cable_mode, -1);INT_MODULE_PARM(wakeup, 0); /* Cirrus specific */#endif#ifdef CONFIG_PCIstatic int pci_irq_list[8] = { 0 }; /* PCI interrupt assignments */MODULE_PARM(pci_irq_list, "1-8i");INT_MODULE_PARM(do_pci_probe, 1); /* Scan for PCI bridges? */INT_MODULE_PARM(fast_pci, -1);INT_MODULE_PARM(cb_write_post, -1);INT_MODULE_PARM(irq_mode, -1); /* Override BIOS routing? */INT_MODULE_PARM(hold_time, -1); /* Ricoh specific */INT_MODULE_PARM(p2cclk, -1); /* TI specific */#endif#if defined(CONFIG_ISA) && defined(CONFIG_PCI)INT_MODULE_PARM(pci_csc, 1); /* PCI card status irqs? */INT_MODULE_PARM(pci_int, 1); /* PCI IO card irqs? */#elif defined(CONFIG_ISA) && !defined(CONFIG_PCI)#define pci_csc 0#define pci_int 0#elif !defined(CONFIG_ISA) && defined(CONFIG_PCI)#define pci_csc 0#define pci_int 1 /* We must use PCI irq's */#else#error "No bus architectures defined!"#endif#ifdef PCMCIA_DEBUGINT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static const char *version ="i82365.c 1.352 2002/06/29 06:23:09 (David Hinds)";#else#define DEBUG(n, args...) do { } while (0)#endif/*====================================================================*/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 HAS_PROC_BUS struct proc_dir_entry *proc;#endif u_char pci_irq_code;#ifdef CONFIG_PCI u_short vendor, device; u_char revision, bus, devfn; u_short bcr; u_char pci_lat, cb_lat, sub_bus, cache; u_int cb_phys; char *cb_virt;#endif union { cirrus_state_t cirrus; vg46x_state_t vg46x; o2micro_state_t o2micro; ti113x_state_t ti113x; ricoh_state_t ricoh; topic_state_t topic; } state;} socket_info_t;/* Where we keep track of our sockets... */static int sockets = 0;static socket_info_t socket[8] = { { 0, }, /* ... */};#ifdef CONFIG_ISAstatic int grab_irq;#ifdef USE_SPIN_LOCKSstatic spinlock_t isa_lock = SPIN_LOCK_UNLOCKED;#endif#define ISA_LOCK(s, f) \ if (!((s)->flags & IS_CARDBUS)) spin_lock_irqsave(&isa_lock, f)#define ISA_UNLOCK(n, f) \ if (!((s)->flags & IS_CARDBUS)) spin_unlock_irqrestore(&isa_lock, f)#else#define ISA_LOCK(n, f) do { } while (0)#define ISA_UNLOCK(n, f) do { } while (0)#endifstatic void pcic_interrupt_wrapper(u_long data);static struct timer_list poll_timer = { function: pcic_interrupt_wrapper};#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))/*====================================================================*//* Some PCI shortcuts */#ifdef CONFIG_PCIstatic int pci_readb(socket_info_t *s, int r, u_char *v){ return pcibios_read_config_byte(s->bus, s->devfn, r, v); }static int pci_writeb(socket_info_t *s, int r, u_char v){ return pcibios_write_config_byte(s->bus, s->devfn, r, v); }static int pci_readw(socket_info_t *s, int r, u_short *v){ return pcibios_read_config_word(s->bus, s->devfn, r, v); }static int pci_writew(socket_info_t *s, int r, u_short v){ return pcibios_write_config_word(s->bus, s->devfn, r, v); }static int pci_readl(socket_info_t *s, int r, u_int *v){ return pcibios_read_config_dword(s->bus, s->devfn, r, v); }static int pci_writel(socket_info_t *s, int r, u_int v){ return pcibios_write_config_dword(s->bus, s->devfn, r, v); }#endif#define cb_readb(s, r) readb((s)->cb_virt + (r))#define cb_readl(s, r) readl((s)->cb_virt + (r))#define cb_writeb(s, r, v) writeb(v, (s)->cb_virt + (r))#define cb_writel(s, r, v) writel(v, (s)->cb_virt + (r))/*====================================================================*//* 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#ifdef CONFIG_PCI IS_I82092AA, IS_OM82C092G, CIRRUS_PCIC_ID, O2MICRO_PCIC_ID, RICOH_PCIC_ID, SMC_PCIC_ID, TI_PCIC_ID, ENE_PCIC_ID, TOPIC_PCIC_ID, IS_UNK_PCI, IS_UNK_CARDBUS#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_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_CARDBUS 0x4000#define IS_ALIVE 0x8000typedef struct pcic_t { char *name; u_short flags;#ifdef CONFIG_PCI u_short vendor, device;#endif} pcic_t;#define ID(a,b) PCI_VENDOR_ID_##a,PCI_DEVICE_ID_##a##_##bstatic 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 },#endif#ifdef CONFIG_PCI { "Intel 82092AA", IS_PCI, ID(INTEL, 82092AA_0) }, { "Omega Micro 82C092G", IS_PCI, ID(OMEGA, 82C092G) }, CIRRUS_PCIC_INFO, O2MICRO_PCIC_INFO, RICOH_PCIC_INFO, SMC_PCIC_INFO, TI_PCIC_INFO, ENE_PCIC_INFO, TOPIC_PCIC_INFO, { "Unknown", IS_PCI|IS_UNKNOWN, 0, 0 }, { "Unknown", IS_CARDBUS|IS_UNKNOWN, 0, 0 }#endif};#define PCIC_COUNT (sizeof(pcic)/sizeof(pcic_t))/*====================================================================*/static u_char i365_get(socket_info_t *s, u_short reg){#ifdef CONFIG_PCI if (s->cb_virt) return cb_readb(s, 0x0800 + reg);#endif outb(I365_REG(s->psock, reg), s->ioaddr); return inb(s->ioaddr+1);}static void i365_set(socket_info_t *s, u_short reg, u_char data){#ifdef CONFIG_PCI if (s->cb_virt) { cb_writeb(s, 0x0800 + reg, data); return; }#endif outb(I365_REG(s->psock, reg), s->ioaddr); outb(data, s->ioaddr+1);}static void i365_bset(socket_info_t *s, u_short reg, u_char mask){ i365_set(s, reg, i365_get(s, reg) | mask);}static void i365_bclr(socket_info_t *s, u_short reg, u_char mask){ i365_set(s, reg, i365_get(s, reg) & ~mask);}static void i365_bflip(socket_info_t *s, u_short reg, u_char mask, int b){ u_char d = i365_get(s, reg); i365_set(s, reg, (b) ? (d | mask) : (d & ~mask));}static u_short i365_get_pair(socket_info_t *s, u_short reg){ return (i365_get(s, reg) + (i365_get(s, reg+1) << 8));}static void i365_set_pair(socket_info_t *s, u_short reg, u_short data){ i365_set(s, reg, data & 0xff); i365_set(s, 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. ======================================================================*/#ifdef CONFIG_PCIstatic int __init get_pci_irq(socket_info_t *s){ u8 irq; irq = pci_find_slot(s->bus, s->devfn)->irq; if ((irq == 0) && (pci_csc || pci_int)) irq = pci_irq_list[s - socket]; if (irq >= NR_IRQS) irq = 0; s->cap.pci_irq = irq; return irq;}#endifstatic void __init cirrus_get_state(socket_info_t *s){ cirrus_state_t *p = &s->state.cirrus; int i; 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); if (s->flags & IS_PCI) p->ectl1 = pd67_ext_get(s, PD67_EXT_CTL_1); for (i = 0; i < 6; i++) p->timer[i] = i365_get(s, PD67_TIME_SETUP(0)+i);}static void cirrus_set_state(socket_info_t *s){ cirrus_state_t *p = &s->state.cirrus; u_char misc; int i; 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); if (s->flags & IS_PCI) pd67_ext_set(s, PD67_EXT_CTL_1, p->ectl1); for (i = 0; i < 6; i++) i365_set(s, PD67_TIME_SETUP(0)+i, p->timer[i]);}#ifdef CONFIG_PCIstatic int cirrus_set_irq_mode(socket_info_t *s, int pcsc, int pint){ flip(s->bcr, PD6832_BCR_MGMT_IRQ_ENA, !pcsc); return 0;}#endifstatic u_int __init cirrus_set_opts(socket_info_t *s, char *buf){ cirrus_state_t *p = &s->state.cirrus; u_int mask = 0xffff; p->misc1 |= PD67_MC1_SPKR_ENA; 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 (!(s->flags & (IS_PCI|IS_CARDBUS))) { 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -