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

📄 msp3400.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * programming the msp34* sound processor family * * (c) 1997-2001 Gerd Knorr <kraxel@bytesex.org> * * what works and what doesn't: * *  AM-Mono *      Support for Hauppauge cards added (decoding handled by tuner) added by *      Frederic Crozat <fcrozat@mail.dotcom.fr> * *  FM-Mono *      should work. The stereo modes are backward compatible to FM-mono, *      therefore FM-Mono should be allways available. * *  FM-Stereo (B/G, used in germany) *      should work, with autodetect * *  FM-Stereo (satellite) *      should work, no autodetect (i.e. default is mono, but you can *      switch to stereo -- untested) * *  NICAM (B/G, L , used in UK, Scandinavia, Spain and France) *      should work, with autodetect. Support for NICAM was added by *      Pekka Pietikainen <pp@netppl.fi> * * * TODO: *   - better SAT support * * * 980623  Thomas Sailer (sailer@ife.ee.ethz.ch) *         using soundcore instead of OSS * */#include <linux/config.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/delay.h>#include <linux/errno.h>#include <linux/slab.h>#include <linux/i2c.h>#include <linux/videodev.h>#include <linux/init.h>#include <linux/smp_lock.h>#include <linux/kthread.h>#include <linux/suspend.h>#include <asm/semaphore.h>#include <asm/pgtable.h>#include <media/audiochip.h>#include "msp3400.h"#define msp3400_dbg(fmt, arg...) \	do { \		if (debug) \			printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \			       i2c_adapter_id(client->adapter), client->addr , ## arg); \	} while (0)/* Medium volume debug. */#define msp3400_dbg_mediumvol(fmt, arg...) \	do { \		if (debug >= 2) \			printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \				i2c_adapter_id(client->adapter), client->addr , ## arg); \	} while (0)/* High volume debug. Use with care. */#define msp3400_dbg_highvol(fmt, arg...) \	do { \		if (debug >= 16) \			printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \				i2c_adapter_id(client->adapter), client->addr , ## arg); \	} while (0)#define msp3400_err(fmt, arg...) do { \	printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->name, \		i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)#define msp3400_warn(fmt, arg...) do { \	printk(KERN_WARNING "%s %d-%04x: " fmt, client->driver->name, \		i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)#define msp3400_info(fmt, arg...) do { \	printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->name, \		i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)#define OPMODE_AUTO    -1#define OPMODE_MANUAL   0#define OPMODE_SIMPLE   1   /* use short programming (>= msp3410 only) */#define OPMODE_SIMPLER  2   /* use shorter programming (>= msp34xxG)   *//* insmod parameters */static int opmode   = OPMODE_AUTO;static int debug    = 0;    /* debug output */static int once     = 0;    /* no continous stereo monitoring */static int amsound  = 0;    /* hard-wire AM sound at 6.5 Hz (france),			       the autoscan seems work well only with FM... */static int standard = 1;    /* Override auto detect of audio standard, if needed. */static int dolby    = 0;static int stereo_threshold = 0x190; /* a2 threshold for stereo/bilingual					(msp34xxg only) 0x00a0-0x03c0 */#define DFP_COUNT 0x41static const int bl_dfp[] = {	0x00, 0x01, 0x02, 0x03, 0x06, 0x08, 0x09, 0x0a,	0x0b, 0x0d, 0x0e, 0x10};#define IS_MSP34XX_G(msp) ((msp)->opmode==2)struct msp3400c {	int rev1,rev2;	int opmode;	int nicam;	int mode;	int norm;	int stereo;	int nicam_on;	int acb;	int in_scart;	int i2s_mode;	int main, second;	/* sound carrier */	int input;	int source;             /* see msp34xxg_set_source */	/* v4l2 */	int audmode;	int rxsubchans;	int muted;	int left, right;	/* volume */	int bass, treble;	/* shadow register set */	int dfp_regs[DFP_COUNT];	/* thread */	struct task_struct   *kthread;	wait_queue_head_t    wq;	int                  restart:1;	int                  watch_stereo:1;};#define MIN(a,b) (((a)>(b))?(b):(a))#define MAX(a,b) (((a)>(b))?(a):(b))#define HAVE_NICAM(msp)   (((msp->rev2>>8) & 0xff) != 00)#define HAVE_SIMPLE(msp)  ((msp->rev1      & 0xff) >= 'D'-'@')#define HAVE_SIMPLER(msp) ((msp->rev1      & 0xff) >= 'G'-'@')#define HAVE_RADIO(msp)   ((msp->rev1      & 0xff) >= 'G'-'@')#define VIDEO_MODE_RADIO 16      /* norm magic for radio mode *//* ---------------------------------------------------------------------- *//* read-only */module_param(opmode,           int, 0444);/* read-write */module_param(once,             int, 0644);module_param(debug,            int, 0644);module_param(stereo_threshold, int, 0644);module_param(standard,         int, 0644);module_param(amsound,          int, 0644);module_param(dolby,            int, 0644);MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Simple, 2=Simpler");MODULE_PARM_DESC(once, "No continuous stereo monitoring");MODULE_PARM_DESC(debug, "Enable debug messages");MODULE_PARM_DESC(stereo_threshold, "Sets signal threshold to activate stereo");MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");MODULE_PARM_DESC(dolby, "Activates Dolby processsing");/* ---------------------------------------------------------------------- */#define I2C_MSP3400C       0x80#define I2C_MSP3400C_ALT   0x88#define I2C_MSP3400C_DEM   0x10#define I2C_MSP3400C_DFP   0x12/* Addresses to scan */static unsigned short normal_i2c[] = {	I2C_MSP3400C      >> 1,	I2C_MSP3400C_ALT  >> 1,	I2C_CLIENT_END};I2C_CLIENT_INSMOD;MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");MODULE_AUTHOR("Gerd Knorr");MODULE_LICENSE("GPL");/* ----------------------------------------------------------------------- *//* functions for talking to the MSP3400C Sound processor                   */static int msp3400c_reset(struct i2c_client *client){	/* reset and read revision code */	static char reset_off[3] = { 0x00, 0x80, 0x00 };	static char reset_on[3]  = { 0x00, 0x00, 0x00 };	static char write[3]     = { I2C_MSP3400C_DFP + 1, 0x00, 0x1e };	char read[2];	struct i2c_msg reset[2] = {		{ client->addr, I2C_M_IGNORE_NAK, 3, reset_off },		{ client->addr, I2C_M_IGNORE_NAK, 3, reset_on  },	};	struct i2c_msg test[2] = {		{ client->addr, 0,        3, write },		{ client->addr, I2C_M_RD, 2, read  },	};	msp3400_dbg_highvol("msp3400c_reset\n");	if ( (1 != i2c_transfer(client->adapter,&reset[0],1)) ||	     (1 != i2c_transfer(client->adapter,&reset[1],1)) ||	     (2 != i2c_transfer(client->adapter,test,2)) ) {		msp3400_err("chip reset failed\n");		return -1;	}	return 0;}static int msp3400c_read(struct i2c_client *client, int dev, int addr){	int err,retval;	unsigned char write[3];	unsigned char read[2];	struct i2c_msg msgs[2] = {		{ client->addr, 0,        3, write },		{ client->addr, I2C_M_RD, 2, read  }	};	write[0] = dev+1;	write[1] = addr >> 8;	write[2] = addr & 0xff;	for (err = 0; err < 3;) {		if (2 == i2c_transfer(client->adapter,msgs,2))			break;		err++;		msp3400_warn("I/O error #%d (read 0x%02x/0x%02x)\n", err,		       dev, addr);		current->state = TASK_INTERRUPTIBLE;		schedule_timeout(msecs_to_jiffies(10));	}	if (3 == err) {		msp3400_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n");		msp3400c_reset(client);		return -1;	}	retval = read[0] << 8 | read[1];	msp3400_dbg_highvol("msp3400c_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);	return retval;}static int msp3400c_write(struct i2c_client *client, int dev, int addr, int val){	int err;	unsigned char buffer[5];	buffer[0] = dev;	buffer[1] = addr >> 8;	buffer[2] = addr &  0xff;	buffer[3] = val  >> 8;	buffer[4] = val  &  0xff;	msp3400_dbg_highvol("msp3400c_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);	for (err = 0; err < 3;) {		if (5 == i2c_master_send(client, buffer, 5))			break;		err++;		msp3400_warn("I/O error #%d (write 0x%02x/0x%02x)\n", err,		       dev, addr);		current->state = TASK_INTERRUPTIBLE;		schedule_timeout(msecs_to_jiffies(10));	}	if (3 == err) {		msp3400_warn("giving up, reseting chip. Sound will go off, sorry folks :-|\n");		msp3400c_reset(client);		return -1;	}	return 0;}/* ------------------------------------------------------------------------ *//* This macro is allowed for *constants* only, gcc must calculate it   at compile time.  Remember -- no floats in kernel mode */#define MSP_CARRIER(freq) ((int)((float)(freq/18.432)*(1<<24)))#define MSP_MODE_AM_DETECT   0#define MSP_MODE_FM_RADIO    2#define MSP_MODE_FM_TERRA    3#define MSP_MODE_FM_SAT      4#define MSP_MODE_FM_NICAM1   5#define MSP_MODE_FM_NICAM2   6#define MSP_MODE_AM_NICAM    7#define MSP_MODE_BTSC        8#define MSP_MODE_EXTERN      9static struct MSP_INIT_DATA_DEM {	int fir1[6];	int fir2[6];	int cdo1;	int cdo2;	int ad_cv;	int mode_reg;	int dfp_src;	int dfp_matrix;} msp_init_data[] = {	{	/* AM (for carrier detect / msp3400) */		{75, 19, 36, 35, 39, 40},		{75, 19, 36, 35, 39, 40},		MSP_CARRIER(5.5), MSP_CARRIER(5.5),		0x00d0, 0x0500, 0x0020, 0x3000	},{	/* AM (for carrier detect / msp3410) */		{-1, -1, -8, 2, 59, 126},		{-1, -1, -8, 2, 59, 126},		MSP_CARRIER(5.5), MSP_CARRIER(5.5),		0x00d0, 0x0100, 0x0020, 0x3000	},{	/* FM Radio */		{-8, -8, 4, 6, 78, 107},		{-8, -8, 4, 6, 78, 107},		MSP_CARRIER(10.7), MSP_CARRIER(10.7),		0x00d0, 0x0480, 0x0020, 0x3000	},{	/* Terrestial FM-mono + FM-stereo */		{3, 18, 27, 48, 66, 72},		{3, 18, 27, 48, 66, 72},		MSP_CARRIER(5.5), MSP_CARRIER(5.5),		0x00d0, 0x0480, 0x0030, 0x3000	},{	/* Sat FM-mono */		{ 1, 9, 14, 24, 33, 37},		{ 3, 18, 27, 48, 66, 72},		MSP_CARRIER(6.5), MSP_CARRIER(6.5),		0x00c6, 0x0480, 0x0000, 0x3000	},{	/* NICAM/FM --  B/G (5.5/5.85), D/K (6.5/5.85) */		{-2, -8, -10, 10, 50, 86},		{3, 18, 27, 48, 66, 72},		MSP_CARRIER(5.5), MSP_CARRIER(5.5),		0x00d0, 0x0040, 0x0120, 0x3000	},{	/* NICAM/FM -- I (6.0/6.552) */		{2, 4, -6, -4, 40, 94},		{3, 18, 27, 48, 66, 72},		MSP_CARRIER(6.0), MSP_CARRIER(6.0),		0x00d0, 0x0040, 0x0120, 0x3000	},{	/* NICAM/AM -- L (6.5/5.85) */		{-2, -8, -10, 10, 50, 86},		{-4, -12, -9, 23, 79, 126},		MSP_CARRIER(6.5), MSP_CARRIER(6.5),		0x00c6, 0x0140, 0x0120, 0x7c03	},};struct CARRIER_DETECT {	int   cdo;	char *name;};static struct CARRIER_DETECT carrier_detect_main[] = {	/* main carrier */	{ MSP_CARRIER(4.5),        "4.5   NTSC"                   },	{ MSP_CARRIER(5.5),        "5.5   PAL B/G"                },	{ MSP_CARRIER(6.0),        "6.0   PAL I"                  },	{ MSP_CARRIER(6.5),        "6.5   PAL D/K + SAT + SECAM"  }};static struct CARRIER_DETECT carrier_detect_55[] = {	/* PAL B/G */	{ MSP_CARRIER(5.7421875),  "5.742 PAL B/G FM-stereo"     },	{ MSP_CARRIER(5.85),       "5.85  PAL B/G NICAM"         }};static struct CARRIER_DETECT carrier_detect_65[] = {	/* PAL SAT / SECAM */	{ MSP_CARRIER(5.85),       "5.85  PAL D/K + SECAM NICAM" },	{ MSP_CARRIER(6.2578125),  "6.25  PAL D/K1 FM-stereo" },	{ MSP_CARRIER(6.7421875),  "6.74  PAL D/K2 FM-stereo" },	{ MSP_CARRIER(7.02),       "7.02  PAL SAT FM-stereo s/b" },	{ MSP_CARRIER(7.20),       "7.20  PAL SAT FM-stereo s"   },	{ MSP_CARRIER(7.38),       "7.38  PAL SAT FM-stereo b"   },};#define CARRIER_COUNT(x) (sizeof(x)/sizeof(struct CARRIER_DETECT))/* ----------------------------------------------------------------------- * * bits  9  8  5 - SCART DSP input Select: *       0  0  0 - SCART 1 to DSP input (reset position) *       0  1  0 - MONO to DSP input *       1  0  0 - SCART 2 to DSP input *       1  1  1 - Mute DSP input * * bits 11 10  6 - SCART 1 Output Select: *       0  0  0 - undefined (reset position) *       0  1  0 - SCART 2 Input to SCART 1 Output (for devices with 2 SCARTS) *       1  0  0 - MONO input to SCART 1 Output *       1  1  0 - SCART 1 DA to SCART 1 Output *       0  0  1 - SCART 2 DA to SCART 1 Output *       0  1  1 - SCART 1 Input to SCART 1 Output *       1  1  1 - Mute SCART 1 Output * * bits 13 12  7 - SCART 2 Output Select (for devices with 2 Output SCART): *       0  0  0 - SCART 1 DA to SCART 2 Output (reset position) *       0  1  0 - SCART 1 Input to SCART 2 Output *       1  0  0 - MONO input to SCART 2 Output *       0  0  1 - SCART 2 DA to SCART 2 Output *       0  1  1 - SCART 2 Input to SCART 2 Output *       1  1  0 - Mute SCART 2 Output * * Bits 4 to 0 should be zero. * ----------------------------------------------------------------------- */static int scarts[3][9] = {	/* MASK    IN1     IN2     IN1_DA  IN2_DA  IN3     IN4     MONO    MUTE   */	/* SCART DSP Input select */	{ 0x0320, 0x0000, 0x0200, -1,     -1,     0x0300, 0x0020, 0x0100, 0x0320 },	/* SCART1 Output select */	{ 0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },	/* SCART2 Output select */	{ 0x3080, 0x1000, 0x1080, 0x0000, 0x0080, 0x2080, 0x3080, 0x2000, 0x3000 },};static char *scart_names[] = {	"mask", "in1", "in2", "in1 da", "in2 da", "in3", "in4", "mono", "mute"};static void msp3400c_set_scart(struct i2c_client *client, int in, int out){	struct msp3400c *msp = i2c_get_clientdata(client);	msp->in_scart=in;	if (in >= 1 && in <= 8 && out >= 0 && out <= 2) {		if (-1 == scarts[out][in])			return;		msp->acb &= ~scarts[out][SCART_MASK];		msp->acb |=  scarts[out][in];	} else		msp->acb = 0xf60; /* Mute Input and SCART 1 Output */	msp3400_dbg("scart switch: %s => %d (ACB=0x%04x)\n",						scart_names[in], out, msp->acb);	msp3400c_write(client,I2C_MSP3400C_DFP, 0x13, msp->acb);	/* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */	msp3400c_write(client,I2C_MSP3400C_DEM, 0x40, msp->i2s_mode);}/* ------------------------------------------------------------------------ */static void msp3400c_setcarrier(struct i2c_client *client, int cdo1, int cdo2){	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0093, cdo1 & 0xfff);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x009b, cdo1 >> 12);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x00a3, cdo2 & 0xfff);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x00ab, cdo2 >> 12);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/}static void msp3400c_setvolume(struct i2c_client *client,			       int muted, int left, int right) {	int vol = 0, val = 0, balance = 0;	if (!muted) {		/* 0x7f instead if 0x73 here has sound quality issues,		 * probably due to overmodulation + clipping ... */		vol = (left > right) ? left : right;		val = (vol * 0x73 / 65535) << 8;	}	if (vol > 0) {		balance = ((right - left) * 127) / vol;	}	msp3400_dbg("setvolume: mute=%s %d:%d  v=0x%02x b=0x%02x\n",		muted ? "on" : "off", left, right, val >> 8, balance);	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0000, val); /* loudspeaker */	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0006, val); /* headphones  */	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0007,					muted ? 0x1 : (val | 0x1));	msp3400c_write(client, I2C_MSP3400C_DFP, 0x0001, balance << 8);}static void msp3400c_setbass(struct i2c_client *client, int bass){	int val = ((bass-32768) * 0x60 / 65535) << 8;	msp3400_dbg("setbass: %d 0x%02x\n", bass, val >> 8);	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0002, val); /* loudspeaker */}static void msp3400c_settreble(struct i2c_client *client, int treble){	int val = ((treble-32768) * 0x60 / 65535) << 8;	msp3400_dbg("settreble: %d 0x%02x\n",treble, val>>8);	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0003, val); /* loudspeaker */}static void msp3400c_setmode(struct i2c_client *client, int type){	struct msp3400c *msp = i2c_get_clientdata(client);	int i;	msp3400_dbg("setmode: %d\n",type);	msp->mode       = type;	msp->audmode    = V4L2_TUNER_MODE_MONO;	msp->rxsubchans = V4L2_TUNER_SUB_MONO;	msp3400c_write(client,I2C_MSP3400C_DEM, 0x00bb,          /* ad_cv */		       msp_init_data[type].ad_cv);	for (i = 5; i >= 0; i--)                                   /* fir 1 */		msp3400c_write(client,I2C_MSP3400C_DEM, 0x0001,			       msp_init_data[type].fir1[i]);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0004); /* fir 2 */	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0040);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005, 0x0000);	for (i = 5; i >= 0; i--)		msp3400c_write(client,I2C_MSP3400C_DEM, 0x0005,			       msp_init_data[type].fir2[i]);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0083,     /* MODE_REG */		       msp_init_data[type].mode_reg);	msp3400c_setcarrier(client, msp_init_data[type].cdo1,			    msp_init_data[type].cdo2);	msp3400c_write(client,I2C_MSP3400C_DEM, 0x0056, 0); /*LOAD_REG_1/2*/	if (dolby) {		msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,			       0x0520); /* I2S1 */		msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,			       0x0620); /* I2S2 */		msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,			       msp_init_data[type].dfp_src);	} else {		msp3400c_write(client,I2C_MSP3400C_DFP, 0x0008,			       msp_init_data[type].dfp_src);		msp3400c_write(client,I2C_MSP3400C_DFP, 0x0009,			       msp_init_data[type].dfp_src);		msp3400c_write(client,I2C_MSP3400C_DFP, 0x000b,			       msp_init_data[type].dfp_src);	}	msp3400c_write(client,I2C_MSP3400C_DFP, 0x000a,		       msp_init_data[type].dfp_src);	msp3400c_write(client,I2C_MSP3400C_DFP, 0x000e,		       msp_init_data[type].dfp_matrix);

⌨️ 快捷键说明

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