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

📄 i82365.c

📁 这是一个SIGMA方案的PMP播放器的UCLINUX程序,可播放DVD,VCD,CD MP3...有很好的参考价值.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*======================================================================    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 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 <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>#include <linux/isapnp.h>/* ISA-bus controllers */#include "i82365.h"#include "cirrus.h"#include "vg468.h"#include "ricoh.h"#include "o2micro.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! */#ifdef CONFIG_ISAtypedef enum pcic_id {    IS_I82365A, IS_I82365B, IS_I82365DF,    IS_IBM, IS_RF5Cx96, IS_VLSI, IS_VG468, IS_VG469,    IS_PD6710, IS_PD672X, IS_VT83C469,} pcic_id;#endif/* 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 spinlock_t bus_lock = SPIN_LOCK_UNLOCKED;static u_char i365_get(u_short sock, u_short reg){    unsigned long flags;    spin_lock_irqsave(&bus_lock,flags);    {	ioaddr_t port = socket[sock].ioaddr;	u_char val;	reg = I365_REG(socket[sock].psock, reg);	outb(reg, port); val = inb(port+1);	spin_unlock_irqrestore(&bus_lock,flags);	return val;    }}static void i365_set(u_short sock, u_short reg, u_char data){    unsigned long flags;    spin_lock_irqsave(&bus_lock,flags);    {	ioaddr_t port = socket[sock].ioaddr;	u_char val = I365_REG(socket[sock].psock, reg);	outb(val, port); outb(data, port+1);	spin_unlock_irqrestore(&bus_lock,flags);    }}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;}/*======================================================================

⌨️ 快捷键说明

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