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

📄 sm.c

📁 上传linux-jx2410的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************//* *	sm.c  -- soundcard radio modem driver. * *	Copyright (C) 1996-2000  Thomas Sailer (sailer@ife.ee.ethz.ch) * *	This program is free software; you can redistribute it and/or modify *	it under the terms of the GNU General Public License as published by *	the Free Software Foundation; either version 2 of the License, or *	(at your option) any later version. * *	This program is distributed in the hope that it will be useful, *	but WITHOUT ANY WARRANTY; without even the implied warranty of *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *	GNU General Public License for more details. * *	You should have received a copy of the GNU General Public License *	along with this program; if not, write to the Free Software *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *  Please note that the GPL allows you to use the driver, NOT the radio. *  In order to use the radio, you need a license from the communications *  authority of your country. * * *  Command line options (insmod command line) * *  mode     mode string; eg. "wss:afsk1200" *  iobase   base address of the soundcard; common values are 0x220 for sbc, *           0x530 for wss *  irq      interrupt number; common values are 7 or 5 for sbc, 11 for wss *  dma      dma number; common values are 0 or 1 * * *  History: *   0.1  21.09.1996  Started *        18.10.1996  Changed to new user space access routines (copy_{to,from}_user) *   0.4  21.01.1997  Separately compileable soundcard/modem modules *   0.5  03.03.1997  fixed LPT probing (check_lpt result was interpreted the wrong way round) *   0.6  16.04.1997  init code/data tagged *   0.7  30.07.1997  fixed halfduplex interrupt handlers/hotfix for CS423X *   0.8  14.04.1998  cleanups *   0.9  03.08.1999  adapt to Linus' new __setup/__initcall *                    use parport lowlevel drivers instead of directly writing to a parallel port *                    removed some pre-2.2 kernel compatibility cruft *   0.10 10.08.1999  Check if parport can do SPP and is safe to access during interrupt contexts *   0.11 12.02.2000  adapted to softnet driver interface *   0.12 03.07.2000  fix interface name handling *//*****************************************************************************/#include <linux/config.h>#include <linux/version.h>#include <linux/module.h>#include <linux/ioport.h>#include <linux/string.h>#include <linux/init.h>#include <linux/parport.h>#include <asm/uaccess.h>#include <asm/io.h>#include "sm.h"/* --------------------------------------------------------------------- *//*static*/ const char sm_drvname[] = "soundmodem";static const char sm_drvinfo[] = KERN_INFO "soundmodem: (C) 1996-2000 Thomas Sailer, HB9JNX/AE4WA\n"KERN_INFO "soundmodem: version 0.12 compiled " __TIME__ " " __DATE__ "\n";/* --------------------------------------------------------------------- *//*static*/ const struct modem_tx_info *sm_modem_tx_table[] = {#ifdef CONFIG_SOUNDMODEM_AFSK1200	&sm_afsk1200_tx,#endif /* CONFIG_SOUNDMODEM_AFSK1200 */#ifdef CONFIG_SOUNDMODEM_AFSK2400_7	&sm_afsk2400_7_tx,#endif /* CONFIG_SOUNDMODEM_AFSK2400_7 */#ifdef CONFIG_SOUNDMODEM_AFSK2400_8	&sm_afsk2400_8_tx,#endif /* CONFIG_SOUNDMODEM_AFSK2400_8 */#ifdef CONFIG_SOUNDMODEM_AFSK2666	&sm_afsk2666_tx,#endif /* CONFIG_SOUNDMODEM_AFSK2666 */#ifdef CONFIG_SOUNDMODEM_PSK4800	&sm_psk4800_tx,#endif /* CONFIG_SOUNDMODEM_PSK4800 */#ifdef CONFIG_SOUNDMODEM_HAPN4800	&sm_hapn4800_8_tx,	&sm_hapn4800_10_tx,	&sm_hapn4800_pm8_tx,	&sm_hapn4800_pm10_tx,#endif /* CONFIG_SOUNDMODEM_HAPN4800 */#ifdef CONFIG_SOUNDMODEM_FSK9600	&sm_fsk9600_4_tx,	&sm_fsk9600_5_tx,#endif /* CONFIG_SOUNDMODEM_FSK9600 */	NULL};/*static*/ const struct modem_rx_info *sm_modem_rx_table[] = {#ifdef CONFIG_SOUNDMODEM_AFSK1200	&sm_afsk1200_rx,#endif /* CONFIG_SOUNDMODEM_AFSK1200 */#ifdef CONFIG_SOUNDMODEM_AFSK2400_7	&sm_afsk2400_7_rx,#endif /* CONFIG_SOUNDMODEM_AFSK2400_7 */#ifdef CONFIG_SOUNDMODEM_AFSK2400_8	&sm_afsk2400_8_rx,#endif /* CONFIG_SOUNDMODEM_AFSK2400_8 */#ifdef CONFIG_SOUNDMODEM_AFSK2666	&sm_afsk2666_rx,#endif /* CONFIG_SOUNDMODEM_AFSK2666 */#ifdef CONFIG_SOUNDMODEM_PSK4800	&sm_psk4800_rx,#endif /* CONFIG_SOUNDMODEM_PSK4800 */#ifdef CONFIG_SOUNDMODEM_HAPN4800	&sm_hapn4800_8_rx,	&sm_hapn4800_10_rx,	&sm_hapn4800_pm8_rx,	&sm_hapn4800_pm10_rx,#endif /* CONFIG_SOUNDMODEM_HAPN4800 */#ifdef CONFIG_SOUNDMODEM_FSK9600	&sm_fsk9600_4_rx,	&sm_fsk9600_5_rx,#endif /* CONFIG_SOUNDMODEM_FSK9600 */	NULL};static const struct hardware_info *sm_hardware_table[] = {#ifdef CONFIG_SOUNDMODEM_SBC	&sm_hw_sbc,	&sm_hw_sbcfdx,#endif /* CONFIG_SOUNDMODEM_SBC */#ifdef CONFIG_SOUNDMODEM_WSS	&sm_hw_wss,	&sm_hw_wssfdx,#endif /* CONFIG_SOUNDMODEM_WSS */	NULL};/* --------------------------------------------------------------------- */#define NR_PORTS 4static struct net_device sm_device[NR_PORTS];/* --------------------------------------------------------------------- */#define UART_RBR(iobase) (iobase+0)#define UART_THR(iobase) (iobase+0)#define UART_IER(iobase) (iobase+1)#define UART_IIR(iobase) (iobase+2)#define UART_FCR(iobase) (iobase+2)#define UART_LCR(iobase) (iobase+3)#define UART_MCR(iobase) (iobase+4)#define UART_LSR(iobase) (iobase+5)#define UART_MSR(iobase) (iobase+6)#define UART_SCR(iobase) (iobase+7)#define UART_DLL(iobase) (iobase+0)#define UART_DLM(iobase) (iobase+1)#define SER_EXTENT 8#define MIDI_DATA(iobase)     (iobase)#define MIDI_STATUS(iobase)   (iobase+1)#define MIDI_READ_FULL 0x80   /* attention: negative logic!! */#define MIDI_WRITE_EMPTY 0x40 /* attention: negative logic!! */#define MIDI_EXTENT 2/* ---------------------------------------------------------------------- */#define PARAM_TXDELAY   1#define PARAM_PERSIST   2#define PARAM_SLOTTIME  3#define PARAM_TXTAIL    4#define PARAM_FULLDUP   5#define PARAM_HARDWARE  6#define PARAM_RETURN    255#define SP_SER  1#define SP_PAR  2#define SP_MIDI 4/* * ===================== port checking routines ======================== */enum uart { c_uart_unknown, c_uart_8250,	c_uart_16450, c_uart_16550, c_uart_16550A};static const char *uart_str[] =	{ "unknown", "8250", "16450", "16550", "16550A" };static enum uart check_uart(unsigned int iobase){	unsigned char b1,b2,b3;	enum uart u;	enum uart uart_tab[] =		{ c_uart_16450, c_uart_unknown, c_uart_16550, c_uart_16550A };	if (iobase <= 0 || iobase > 0x1000-SER_EXTENT)		return c_uart_unknown;	if (check_region(iobase, SER_EXTENT))		return c_uart_unknown;	b1 = inb(UART_MCR(iobase));	outb(b1 | 0x10, UART_MCR(iobase));	/* loopback mode */	b2 = inb(UART_MSR(iobase));	outb(0x1a, UART_MCR(iobase));	b3 = inb(UART_MSR(iobase)) & 0xf0;	outb(b1, UART_MCR(iobase));	   /* restore old values */	outb(b2, UART_MSR(iobase));	if (b3 != 0x90)		return c_uart_unknown;	inb(UART_RBR(iobase));	inb(UART_RBR(iobase));	outb(0x01, UART_FCR(iobase));		/* enable FIFOs */	u = uart_tab[(inb(UART_IIR(iobase)) >> 6) & 3];	if (u == c_uart_16450) {		outb(0x5a, UART_SCR(iobase));		b1 = inb(UART_SCR(iobase));		outb(0xa5, UART_SCR(iobase));		b2 = inb(UART_SCR(iobase));		if ((b1 != 0x5a) || (b2 != 0xa5))			u = c_uart_8250;	}	return u;}/* --------------------------------------------------------------------- */static int check_midi(unsigned int iobase){	unsigned long timeout;	unsigned long flags;	unsigned char b;	if (iobase <= 0 || iobase > 0x1000-MIDI_EXTENT)		return 0;	if (check_region(iobase, MIDI_EXTENT))		return 0;	timeout = jiffies + (HZ / 100);	while (inb(MIDI_STATUS(iobase)) & MIDI_WRITE_EMPTY)		if ((signed)(jiffies - timeout) > 0)			return 0;	save_flags(flags);	cli();	outb(0xff, MIDI_DATA(iobase));	b = inb(MIDI_STATUS(iobase));	restore_flags(flags);	if (!(b & MIDI_WRITE_EMPTY))		return 0;	while (inb(MIDI_STATUS(iobase)) & MIDI_WRITE_EMPTY)		if ((signed)(jiffies - timeout) > 0)			return 0;	return 1;}/* --------------------------------------------------------------------- */void sm_output_status(struct sm_state *sm){	int invert_dcd = 0;	int invert_ptt = 0;	int ptt = /*hdlcdrv_ptt(&sm->hdrv)*/(sm->dma.ptt_cnt > 0) ^ invert_ptt;	int dcd = (!!sm->hdrv.hdlcrx.dcd) ^ invert_dcd;	if (sm->hdrv.ptt_out.flags & SP_SER) {		outb(dcd | (ptt << 1), UART_MCR(sm->hdrv.ptt_out.seriobase));		outb(0x40 & (-ptt), UART_LCR(sm->hdrv.ptt_out.seriobase));	}	if (sm->hdrv.ptt_out.flags & SP_PAR && sm->pardev && sm->pardev->port)		parport_write_data(sm->pardev->port, ptt | (dcd << 1));	if (sm->hdrv.ptt_out.flags & SP_MIDI && hdlcdrv_ptt(&sm->hdrv))		outb(0, MIDI_DATA(sm->hdrv.ptt_out.midiiobase));}/* --------------------------------------------------------------------- */static void sm_output_open(struct sm_state *sm, const char *ifname){	enum uart u = c_uart_unknown;	struct parport *pp = NULL;	sm->hdrv.ptt_out.flags = 0;	if (sm->hdrv.ptt_out.seriobase > 0 &&	    sm->hdrv.ptt_out.seriobase <= 0x1000-SER_EXTENT &&	    ((u = check_uart(sm->hdrv.ptt_out.seriobase))) != c_uart_unknown) {		sm->hdrv.ptt_out.flags |= SP_SER;		request_region(sm->hdrv.ptt_out.seriobase, SER_EXTENT, "sm ser ptt");		outb(0, UART_IER(sm->hdrv.ptt_out.seriobase));		/* 5 bits, 1 stop, no parity, no break, Div latch access */		outb(0x80, UART_LCR(sm->hdrv.ptt_out.seriobase));		outb(0, UART_DLM(sm->hdrv.ptt_out.seriobase));		outb(1, UART_DLL(sm->hdrv.ptt_out.seriobase)); /* as fast as possible */		/* LCR and MCR set by output_status */	}	sm->pardev = NULL;	if (sm->hdrv.ptt_out.pariobase > 0) {		pp = parport_enumerate();		while (pp && pp->base != sm->hdrv.ptt_out.pariobase) 			pp = pp->next;		if (!pp)			printk(KERN_WARNING "%s: parport at address 0x%x not found\n", sm_drvname, sm->hdrv.ptt_out.pariobase);		else if ((~pp->modes) & (PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT))			printk(KERN_WARNING "%s: parport at address 0x%x cannot be used\n", sm_drvname, sm->hdrv.ptt_out.pariobase);		else {			sm->pardev = parport_register_device(pp, ifname, NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);			if (!sm->pardev) {				pp = NULL;				printk(KERN_WARNING "%s: cannot register parport device (address 0x%x)\n", sm_drvname, sm->hdrv.ptt_out.pariobase);			} else {				if (parport_claim(sm->pardev)) {					parport_unregister_device(sm->pardev);					sm->pardev = NULL;					printk(KERN_WARNING "%s: cannot claim parport at address 0x%x\n", sm_drvname, sm->hdrv.ptt_out.pariobase);				} else					sm->hdrv.ptt_out.flags |= SP_PAR;			}		}	}	if (sm->hdrv.ptt_out.midiiobase > 0 &&	    sm->hdrv.ptt_out.midiiobase <= 0x1000-MIDI_EXTENT &&	    check_midi(sm->hdrv.ptt_out.midiiobase)) {		sm->hdrv.ptt_out.flags |= SP_MIDI;		request_region(sm->hdrv.ptt_out.midiiobase, MIDI_EXTENT,			       "sm midi ptt");	}	sm_output_status(sm);	printk(KERN_INFO "%s: ptt output:", sm_drvname);	if (sm->hdrv.ptt_out.flags & SP_SER)		printk(" serial interface at 0x%x, uart %s", sm->hdrv.ptt_out.seriobase,		       uart_str[u]);	if (sm->hdrv.ptt_out.flags & SP_PAR)		printk(" parallel interface at 0x%x", sm->hdrv.ptt_out.pariobase);	if (sm->hdrv.ptt_out.flags & SP_MIDI)		printk(" mpu401 (midi) interface at 0x%x", sm->hdrv.ptt_out.midiiobase);	if (!sm->hdrv.ptt_out.flags)		printk(" none");	printk("\n");}/* --------------------------------------------------------------------- */static void sm_output_close(struct sm_state *sm){	/* release regions used for PTT output */	sm->hdrv.hdlctx.ptt = sm->hdrv.hdlctx.calibrate = 0;	sm_output_status(sm);	if (sm->hdrv.ptt_out.flags & SP_SER)		release_region(sm->hdrv.ptt_out.seriobase, SER_EXTENT);       	if (sm->hdrv.ptt_out.flags & SP_PAR && sm->pardev) {		        parport_release(sm->pardev);			parport_unregister_device(sm->pardev);	}       	if (sm->hdrv.ptt_out.flags & SP_MIDI)		release_region(sm->hdrv.ptt_out.midiiobase, MIDI_EXTENT);	sm->hdrv.ptt_out.flags = 0;}/* --------------------------------------------------------------------- */static int sm_open(struct net_device *dev);static int sm_close(struct net_device *dev);static int sm_ioctl(struct net_device *dev, struct ifreq *ifr,		    struct hdlcdrv_ioctl *hi, int cmd);/* --------------------------------------------------------------------- */static const struct hdlcdrv_ops sm_ops = {	sm_drvname, sm_drvinfo, sm_open, sm_close, sm_ioctl};/* --------------------------------------------------------------------- */static int sm_open(struct net_device *dev){

⌨️ 快捷键说明

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