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

📄 msp3400.c

📁 h内核
💻 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 <media/id.h>#include "msp3400.h"#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 */struct msp3400c {	int rev1,rev2;	int opmode;	int mode;	int norm;	int nicam_on;	int acb;	int main, second;	/* sound carrier */	int input;	int source;             /* see msp34xxg_set_source */	/* v4l2 */	int audmode;	int rxsubchans;	int muted;	int volume, balance;	int bass, treble;	/* thread */	struct task_struct   *kthread;	wait_queue_head_t    wq;	int                  restart:1;	int                  watch_stereo:1;};#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 *//* ---------------------------------------------------------------------- */#define dprintk      if (debug >= 1) printk#define d2printk     if (debug >= 2) printk/* 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(once, "No continuous stereo monitoring");MODULE_PARM_DESC(debug, "Enable debug messages");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_DESCRIPTION("device driver for msp34xx TV sound processor");MODULE_AUTHOR("Gerd Knorr");MODULE_LICENSE("Dual BSD/GPL"); /* FreeBSD uses this too *//* ---------------------------------------------------------------------- */#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};static unsigned short normal_i2c_range[] = {I2C_CLIENT_END,I2C_CLIENT_END};I2C_CLIENT_INSMOD;/* ----------------------------------------------------------------------- *//* 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  },	};	if ( (1 != i2c_transfer(client->adapter,&reset[0],1)) ||	     (1 != i2c_transfer(client->adapter,&reset[1],1)) ||	     (2 != i2c_transfer(client->adapter,test,2)) ) {		printk(KERN_ERR "msp3400: chip reset failed\n");		return -1;        }	return 0;}static intmsp3400c_read(struct i2c_client *client, int dev, int addr){	int err;        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++;		printk(KERN_WARNING "msp34xx: I/O error #%d (read 0x%02x/0x%02x)\n",		       err, dev, addr);		msleep(10);	}	if (3 == err) {		printk(KERN_WARNING "msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");		msp3400c_reset(client);		return -1;	}	return read[0] << 8 | read[1];}static intmsp3400c_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;	for (err = 0; err < 3;) {		if (5 == i2c_master_send(client, buffer, 5))			break;		err++;		printk(KERN_WARNING "msp34xx: I/O error #%d (write 0x%02x/0x%02x)\n",		       err, dev, addr);		msleep(10);	}	if (3 == err) {		printk(KERN_WARNING "msp34xx: 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))/* ----------------------------------------------------------------------- */static int scarts[3][9] = {  /* MASK    IN1     IN2     IN1_DA  IN2_DA  IN3     IN4     MONO    MUTE   */  {  0x0320, 0x0000, 0x0200, -1,     -1,     0x0300, 0x0020, 0x0100, 0x0320 },  {  0x0c40, 0x0440, 0x0400, 0x0c00, 0x0040, 0x0000, 0x0840, 0x0800, 0x0c40 },  {  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 voidmsp3400c_set_scart(struct i2c_client *client, int in, int out){	struct msp3400c *msp = i2c_get_clientdata(client);	if (-1 == scarts[out][in])		return;	dprintk(KERN_DEBUG		"msp34xx: scart switch: %s => %d\n",scart_names[in],out);	msp->acb &= ~scarts[out][SCART_MASK];	msp->acb |=  scarts[out][in];	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0013, msp->acb);}/* ------------------------------------------------------------------------ */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 volume, int balance){	int val = 0, bal = 0;	if (!muted) {		val = (volume * 0x7F / 65535) << 8;	}	if (val) {		bal = (balance / 256) - 128;	}	dprintk(KERN_DEBUG		"msp34xx: setvolume: mute=%s %d:%d  v=0x%02x b=0x%02x\n",		muted ? "on" : "off", volume, balance, val>>8, bal);	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 ? 0x01 : (val | 0x01));	msp3400c_write(client,I2C_MSP3400C_DFP, 0x0001, bal << 8);}static void msp3400c_setbass(struct i2c_client *client, int bass){	int val = ((bass-32768) * 0x60 / 65535) << 8;	dprintk(KERN_DEBUG "msp34xx: 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;	dprintk(KERN_DEBUG "msp34xx: 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;	dprintk(KERN_DEBUG "msp3400: 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);	if (HAVE_NICAM(msp)) {		/* nicam prescale */		msp3400c_write(client,I2C_MSP3400C_DFP, 0x0010, 0x5a00); /* was: 0x3000 */	}

⌨️ 快捷键说明

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