diff options
author | Gerd Knorr <devnull@localhost> | 2004-04-06 15:24:05 +0000 |
---|---|---|
committer | Gerd Knorr <devnull@localhost> | 2004-04-06 15:24:05 +0000 |
commit | 80587bd9cacb93bf547305f6cc85095b2b03ea87 (patch) | |
tree | 5325def45fd7e95cd03834f08868af9887eb2b74 /linux | |
parent | b5aa034313ae40531a19b51b4945be00ab571a5b (diff) | |
download | mediapointer-dvb-s2-80587bd9cacb93bf547305f6cc85095b2b03ea87.tar.gz mediapointer-dvb-s2-80587bd9cacb93bf547305f6cc85095b2b03ea87.tar.bz2 |
- major rewrite of the tda9887 module.
- start switching over tuner + tda9887 to v4l2.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/drivers/media/video/tda9887.c | 547 | ||||
-rw-r--r-- | linux/include/linux/videodev2.h | 2 |
2 files changed, 285 insertions, 264 deletions
diff --git a/linux/drivers/media/video/tda9887.c b/linux/drivers/media/video/tda9887.c index 2490d41e4..4d07eb2b6 100644 --- a/linux/drivers/media/video/tda9887.c +++ b/linux/drivers/media/video/tda9887.c @@ -39,23 +39,29 @@ static unsigned short normal_i2c_range[] = {I2C_CLIENT_END,I2C_CLIENT_END}; I2C_CLIENT_INSMOD; /* insmod options */ -static int debug = 0; -static char *pal = "b"; -static char *secam = "l"; +static unsigned int debug = 0; MODULE_PARM(debug,"i"); -MODULE_PARM(pal,"s"); -MODULE_PARM(secam,"s"); MODULE_LICENSE("GPL"); /* ---------------------------------------------------------------------- */ +#define UNSET (-1U) #define PREFIX "tda9885/6/7: " #define dprintk if (debug) printk struct tda9887 { - struct i2c_client client; - int radio,tvnorm; - int pinnacle_id; + struct i2c_client client; + v4l2_std_id std; + unsigned int radio; + unsigned int pinnacle_id; +}; + +struct tvnorm { + v4l2_std_id std; + char *name; + unsigned char b; + unsigned char c; + unsigned char e; }; static struct i2c_driver driver; @@ -63,7 +69,147 @@ static struct i2c_client client_template; /* ---------------------------------------------------------------------- */ -#if 0 +// +// TDA defines +// + +//// first reg (b) +#define cVideoTrapBypassOFF 0x00 // bit b0 +#define cVideoTrapBypassON 0x01 // bit b0 + +#define cAutoMuteFmInactive 0x00 // bit b1 +#define cAutoMuteFmActive 0x02 // bit b1 + +#define cIntercarrier 0x00 // bit b2 +#define cQSS 0x04 // bit b2 + +#define cPositiveAmTV 0x00 // bit b3:4 +#define cFmRadio 0x08 // bit b3:4 +#define cNegativeFmTV 0x10 // bit b3:4 + + +#define cForcedMuteAudioON 0x20 // bit b5 +#define cForcedMuteAudioOFF 0x00 // bit b5 + +#define cOutputPort1Active 0x00 // bit b6 +#define cOutputPort1Inactive 0x40 // bit b6 + +#define cOutputPort2Active 0x00 // bit b7 +#define cOutputPort2Inactive 0x80 // bit b7 + + +//// second reg (c) +#define cDeemphasisOFF 0x00 // bit c5 +#define cDeemphasisON 0x20 // bit c5 + +#define cDeemphasis75 0x00 // bit c6 +#define cDeemphasis50 0x40 // bit c6 + +#define cAudioGain0 0x00 // bit c7 +#define cAudioGain6 0x80 // bit c7 + + +//// third reg (e) +#define cAudioIF_4_5 0x00 // bit e0:1 +#define cAudioIF_5_5 0x01 // bit e0:1 +#define cAudioIF_6_0 0x02 // bit e0:1 +#define cAudioIF_6_5 0x03 // bit e0:1 + + +#define cVideoIF_58_75 0x00 // bit e2:4 +#define cVideoIF_45_75 0x04 // bit e2:4 +#define cVideoIF_38_90 0x08 // bit e2:4 +#define cVideoIF_38_00 0x0C // bit e2:4 +#define cVideoIF_33_90 0x10 // bit e2:4 +#define cVideoIF_33_40 0x14 // bit e2:4 +#define cRadioIF_45_75 0x18 // bit e2:4 +#define cRadioIF_38_90 0x1C // bit e2:4 + + +#define cTunerGainNormal 0x00 // bit e5 +#define cTunerGainLow 0x20 // bit e5 + +#define cGating_18 0x00 // bit e6 +#define cGating_36 0x40 // bit e6 + +#define cAgcOutON 0x80 // bit e7 +#define cAgcOutOFF 0x00 // bit e7 + +/* ---------------------------------------------------------------------- */ + +static struct tvnorm tvnorms[] = { + { + .std = V4L2_STD_PAL_BG, + .name = "PAL-BG", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cAudioIF_5_5 | + cVideoIF_38_90 ), + },{ + .std = V4L2_STD_PAL_I, + .name = "PAL-I", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cAudioIF_6_0 | + cVideoIF_38_90 ), + },{ + .std = V4L2_STD_PAL_DK, + .name = "PAL-DK", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cAudioIF_6_5 | + cVideoIF_38_00 ), + },{ + .std = V4L2_STD_PAL_M | V4L2_STD_PAL_N, + .name = "PAL-M/N", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis75 ), + .e = ( cAudioIF_4_5 | + cVideoIF_45_75 ), + },{ + .std = V4L2_STD_SECAM_L, + .name = "SECAM-L", + .b = ( cPositiveAmTV | + cQSS ), + .e = ( cAudioIF_6_5 | + cVideoIF_38_90 ), + },{ + .std = V4L2_STD_NTSC_M, + .name = "NTSC-M", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cGating_36 | + cAudioIF_4_5 | + cVideoIF_45_75 ), + },{ + .std = V4L2_STD_NTSC_M_JP, + .name = "NTSC-JP", + .b = ( cNegativeFmTV ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cGating_36 | + cAudioIF_4_5 | + cVideoIF_58_75 ), + } +}; + +static struct tvnorm radio = { + .name = "radio", + .b = ( cFmRadio | + cQSS ), + .c = ( cDeemphasisON | + cDeemphasis50 ), + .e = ( cAudioIF_5_5 | + cRadioIF_38_90 ), +}; + +/* ---------------------------------------------------------------------- */ + static void dump_read_message(unsigned char *buf) { static char *afc[16] = { @@ -74,7 +220,7 @@ static void dump_read_message(unsigned char *buf) "-112.5 kHz", "-137.5 kHz", "-162.5 kHz", - "-187.5 kHz [mix]", + "-187.5 kHz [min]", "+187.5 kHz [max]", "+162.5 kHz", "+137.5 kHz", @@ -90,7 +236,6 @@ static void dump_read_message(unsigned char *buf) printk(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out"); printk(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low"); } -#endif static void dump_write_message(unsigned char *buf) { @@ -188,192 +333,68 @@ static void dump_write_message(unsigned char *buf) /* ---------------------------------------------------------------------- */ -// -// TDA defines -// - -//// first reg -#define cVideoTrapBypassOFF 0x00 // bit b0 -#define cVideoTrapBypassON 0x01 // bit b0 - -#define cAutoMuteFmInactive 0x00 // bit b1 -#define cAutoMuteFmActive 0x02 // bit b1 - -#define cIntercarrier 0x00 // bit b2 -#define cQSS 0x04 // bit b2 - -#define cPositiveAmTV 0x00 // bit b3:4 -#define cFmRadio 0x08 // bit b3:4 -#define cNegativeFmTV 0x10 // bit b3:4 - - -#define cForcedMuteAudioON 0x20 // bit b5 -#define cForcedMuteAudioOFF 0x00 // bit b5 - -#define cOutputPort1Active 0x00 // bit b6 -#define cOutputPort1Inactive 0x40 // bit b6 - -#define cOutputPort2Active 0x00 // bit b7 -#define cOutputPort2Inactive 0x80 // bit b7 - - -//// second reg -#define cDeemphasisOFF 0x00 // bit c5 -#define cDeemphasisON 0x20 // bit c5 - -#define cDeemphasis75 0x00 // bit c6 -#define cDeemphasis50 0x40 // bit c6 - -#define cAudioGain0 0x00 // bit c7 -#define cAudioGain6 0x80 // bit c7 - - -//// third reg -#define cAudioIF_4_5 0x00 // bit e0:1 -#define cAudioIF_5_5 0x01 // bit e0:1 -#define cAudioIF_6_0 0x02 // bit e0:1 -#define cAudioIF_6_5 0x03 // bit e0:1 - - -#define cVideoIF_58_75 0x00 // bit e2:4 -#define cVideoIF_45_75 0x04 // bit e2:4 -#define cVideoIF_38_90 0x08 // bit e2:4 -#define cVideoIF_38_00 0x0C // bit e2:4 -#define cVideoIF_33_90 0x10 // bit e2:4 -#define cVideoIF_33_40 0x14 // bit e2:4 -#define cRadioIF_45_75 0x18 // bit e2:4 -#define cRadioIF_38_90 0x1C // bit e2:4 - +static int tda9887_set_tvnorm(struct tda9887 *t, char *buf) +{ + struct tvnorm *norm = NULL; + int i; -#define cTunerGainNormal 0x00 // bit e5 -#define cTunerGainLow 0x20 // bit e5 + if (t->radio) { + norm = &radio; + } else { + for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { + if (tvnorms[i].std & t->std) { + norm = tvnorms+i; + break; + } + } + } + if (NULL == norm) { + dprintk(PREFIX "Oops: no tvnorm entry found\n"); + return -1; + } -#define cGating_18 0x00 // bit e6 -#define cGating_36 0x40 // bit e6 + dprintk(PREFIX "configure for: %s\n",norm->name); + buf[1] = norm->b; + buf[2] = norm->c; + buf[3] = norm->e; + return 0; +} -#define cAgcOutON 0x80 // bit e7 -#define cAgcOutOFF 0x00 // bit e7 +static unsigned int port1 = 1; +static unsigned int port2 = 1; +static unsigned int qss = 0; +static unsigned int adjust = 0x10; +MODULE_PARM(port1,"i"); +MODULE_PARM(port2,"i"); +MODULE_PARM(qss,"i"); +MODULE_PARM(adjust,"i"); -static int tda9887_miro(struct tda9887 *t) +static int tda9887_set_insmod(struct tda9887 *t, char *buf) { - int rc; - u8 bData[4] = { 0 }; - u8 bVideoIF = 0; - u8 bAudioIF = 0; - u8 bDeEmphasis = 0; - u8 bDeEmphVal = 0; - u8 bModulation = 0; - u8 bCarrierMode = 0; - u8 bOutPort1 = cOutputPort1Inactive; -#if 0 - u8 bOutPort2 = cOutputPort2Inactive & mbTADState; // store i2c tuner state -#else - u8 bOutPort2 = cOutputPort2Inactive; -#endif - u8 bVideoTrap = cVideoTrapBypassOFF; -#if 1 - u8 bTopAdjust = 0x0e /* -2dB */; -#else - u8 bTopAdjust = 0; -#endif + if (port1) + buf[1] |= cOutputPort1Inactive; + if (port2) + buf[1] |= cOutputPort2Inactive; + if (qss) + buf[1] |= cQSS; + if (adjust >= 0x00 && adjust < 0x20) + buf[2] |= adjust; +} -#if 0 - if (mParams.fVideoTrap) - bVideoTrap = cVideoTrapBypassON; -#endif +/* ---------------------------------------------------------------------- */ - if (t->radio) { - bVideoTrap = cVideoTrapBypassOFF; - bCarrierMode = cQSS; - bModulation = cFmRadio; - bOutPort1 = cOutputPort1Inactive; - bDeEmphasis = cDeemphasisON; - if (3 == t->pinnacle_id) { - /* ntsc */ - bDeEmphVal = cDeemphasis75; - bAudioIF = cAudioIF_4_5; - bVideoIF = cRadioIF_45_75; - } else { - /* pal */ - bAudioIF = cAudioIF_5_5; - bVideoIF = cRadioIF_38_90; - bDeEmphVal = cDeemphasis50; - } +static int tda9887_set_pinnacle(struct tda9887 *t, char *buf) +{ + unsigned int bCarrierMode = UNSET; - } else if (t->tvnorm == VIDEO_MODE_PAL) { - bDeEmphasis = cDeemphasisON; - bDeEmphVal = cDeemphasis50; - bModulation = cNegativeFmTV; - bOutPort1 = cOutputPort1Inactive; + if (t->std & V4L2_STD_PAL) { if ((1 == t->pinnacle_id) || (7 == t->pinnacle_id)) { bCarrierMode = cIntercarrier; } else { - // stereo boards bCarrierMode = cQSS; } - switch (pal[0]) { - case 'b': - case 'g': - case 'h': - bVideoIF = cVideoIF_38_90; - bAudioIF = cAudioIF_5_5; - break; - case 'd': - bVideoIF = cVideoIF_38_00; - bAudioIF = cAudioIF_6_5; - break; - case 'i': - bVideoIF = cVideoIF_38_90; - bAudioIF = cAudioIF_6_0; - break; - case 'm': - case 'n': - bVideoIF = cVideoIF_45_75; - bAudioIF = cAudioIF_4_5; - bDeEmphVal = cDeemphasis75; - if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) { - bCarrierMode = cIntercarrier; - } else { - bCarrierMode = cQSS; - } - break; - } - - } else if (t->tvnorm == VIDEO_MODE_SECAM) { - bAudioIF = cAudioIF_6_5; - bDeEmphasis = cDeemphasisON; - bDeEmphVal = cDeemphasis50; - bModulation = cNegativeFmTV; - bCarrierMode = cQSS; - bOutPort1 = cOutputPort1Inactive; - switch (secam[0]) { - case 'd': - bVideoIF = cVideoIF_38_00; - break; - case 'k': - bVideoIF = cVideoIF_38_90; - break; - case 'l': - bVideoIF = cVideoIF_38_90; - bDeEmphasis = cDeemphasisOFF; - bDeEmphVal = cDeemphasis75; - bModulation = cPositiveAmTV; - break; - case 'L' /* L1 */: - bVideoIF = cVideoIF_33_90; - bDeEmphasis = cDeemphasisOFF; - bDeEmphVal = cDeemphasis75; - bModulation = cPositiveAmTV; - break; - } - - } else if (t->tvnorm == VIDEO_MODE_NTSC) { - bVideoIF = cVideoIF_45_75; - bAudioIF = cAudioIF_4_5; - bDeEmphasis = cDeemphasisON; - bDeEmphVal = cDeemphasis75; - bModulation = cNegativeFmTV; - bOutPort1 = cOutputPort1Inactive; + } + if (t->std & V4L2_STD_NTSC) { if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) { bCarrierMode = cIntercarrier; } else { @@ -381,101 +402,80 @@ static int tda9887_miro(struct tda9887 *t) } } - bData[1] = bVideoTrap | // B0: video trap bypass - cAutoMuteFmInactive | // B1: auto mute - bCarrierMode | // B2: InterCarrier for PAL else QSS - bModulation | // B3 - B4: positive AM TV for SECAM only - cForcedMuteAudioOFF | // B5: forced Audio Mute (off) - bOutPort1 | // B6: Out Port 1 - bOutPort2; // B7: Out Port 2 - bData[2] = bTopAdjust | // C0 - C4: Top Adjust 0 == -16dB 31 == 15dB - bDeEmphasis | // C5: De-emphasis on/off - bDeEmphVal | // C6: De-emphasis 50/75 microsec - cAudioGain0; // C7: normal audio gain - bData[3] = bAudioIF | // E0 - E1: Sound IF - bVideoIF | // E2 - E4: Video IF - cTunerGainNormal | // E5: Tuner gain (normal) - cGating_18 | // E6: Gating (18%) - cAgcOutOFF; // E7: VAGC (off) - - dprintk(PREFIX "0x%02x 0x%02x 0x%02x [pinnacle_id=%d]\n", - bData[1],bData[2],bData[3],t->pinnacle_id); - if (debug > 1) - dump_write_message(bData); - if (4 != (rc = i2c_master_send(&t->client,bData,4))) - printk(PREFIX "i2c i/o error: rc == %d (should be 4)\n",rc); + if (bCarrierMode != UNSET) { + buf[1] &= ~0x04; + buf[1] |= bCarrierMode; + } return 0; } /* ---------------------------------------------------------------------- */ -static unsigned char buf_pal_bg[] = { 0x00, 0xd4, 0x70, 0x09 }; -static unsigned char buf_pal_i[] = { 0x00, 0xd4, 0x70, 0x0a }; -static unsigned char buf_pal_dk[] = { 0x00, 0xd4, 0x70, 0x0b }; -static unsigned char buf_pal_l[] = { 0x00, 0xc4, 0x10, 0x0b }; -//static unsigned char buf_pal_l2[] = { 0x00, 0x84, 0x10, 0x13 }; - -static unsigned char buf_ntsc[] = { 0x00, 0x96, 0x70, 0x44 }; -static unsigned char buf_ntsc_jp[] = { 0x00, 0x96, 0x70, 0x40 }; - -//static unsigned char buf_fm_mono[] = { 0x00, 0xdc, 0x70, 0x1d }; -static unsigned char buf_fm_stereo[] = { 0x00, 0xdc, 0x10, 0x1d }; +static char *pal = "-"; +MODULE_PARM(pal,"s"); -static int tda9887_configure(struct tda9887 *t) +static int tda9887_fixup_std(struct tda9887 *t) { - unsigned char *buf = NULL; - int rc; - - if (t->radio) { - dprintk(PREFIX "FM Radio mode\n"); - buf = buf_fm_stereo; - - } else if (t->tvnorm == VIDEO_MODE_PAL) { - dprintk(PREFIX "PAL-%c mode\n",pal[0]); + if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { + /* get more precise norm info from insmod option */ switch (pal[0]) { case 'b': + case 'B': case 'g': - buf = buf_pal_bg; + case 'G': + dprintk("insmod fixup: PAL => PAL-BG\n"); + t->std = V4L2_STD_PAL_BG; break; case 'i': - buf = buf_pal_i; + case 'I': + dprintk("insmod fixup: PAL => PAL-I\n"); + t->std = V4L2_STD_PAL_I; break; case 'd': + case 'D': case 'k': - buf = buf_pal_dk; - break; - case 'l': - buf = buf_pal_l; + case 'K': + dprintk("insmod fixup: PAL => PAL-DK\n"); + t->std = V4L2_STD_PAL_DK; break; } + } + return 0; +} - } else if (t->tvnorm == VIDEO_MODE_NTSC) { - dprintk(PREFIX "NTSC mode\n"); - buf = buf_ntsc; - - } else if (t->tvnorm == VIDEO_MODE_SECAM) { - dprintk(PREFIX "SECAM mode\n"); - buf = buf_pal_l; - - } else if (t->tvnorm == 6 /* BTTV hack */) { - dprintk(PREFIX "NTSC-Japan mode\n"); - buf = buf_ntsc_jp; - } +static int tda9887_configure(struct tda9887 *t) +{ + unsigned char buf[4]; + int rc; - if (NULL == buf) { - printk(PREFIX "unknown norm=%d\n",t->tvnorm); - return 0; + memset(buf,0,sizeof(buf)); + tda9887_set_tvnorm(t,buf); + if (UNSET != t->pinnacle_id) { + tda9887_set_pinnacle(t,buf); } + tda9887_set_insmod(t,buf); - dprintk(PREFIX "0x%02x 0x%02x 0x%02x\n", + dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n", buf[1],buf[2],buf[3]); if (debug > 1) dump_write_message(buf); + if (4 != (rc = i2c_master_send(&t->client,buf,4))) printk(PREFIX "i2c i/o error: rc == %d (should be 4)\n",rc); return 0; } +static int tda9887_status(struct tda9887 *t) +{ + unsigned char buf[1]; + int rc; + + memset(buf,0,sizeof(buf)); + if (1 != (rc = i2c_master_recv(&t->client,buf,1))) + printk(PREFIX "i2c i/o error: rc == %d (should be 1)\n",rc); + dump_read_message(buf); +} + /* ---------------------------------------------------------------------- */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) @@ -495,9 +495,9 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL))) return -ENOMEM; memset(t,0,sizeof(*t)); - t->client = client_template; - t->pinnacle_id = -1; - t->tvnorm=VIDEO_MODE_PAL; + t->client = client_template; + t->std = 0;; + t->pinnacle_id = UNSET; i2c_set_clientdata(&t->client, t); i2c_attach_client(&t->client); @@ -546,10 +546,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) /* --- configuration --- */ case AUDC_SET_RADIO: t->radio = 1; - if (-1 != t->pinnacle_id) - tda9887_miro(t); - else - tda9887_configure(t); + tda9887_configure(t); break; case AUDC_CONFIG_PINNACLE: @@ -557,7 +554,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) int *i = arg; t->pinnacle_id = *i; - tda9887_miro(t); + tda9887_configure(t); break; } /* --- v4l ioctls --- */ @@ -565,14 +562,36 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg) kernel pointer here... */ case VIDIOCSCHAN: { + static const v4l2_std_id map[] = { + [ VIDEO_MODE_PAL ] = V4L2_STD_PAL, + [ VIDEO_MODE_NTSC ] = V4L2_STD_NTSC_M, + [ VIDEO_MODE_SECAM ] = V4L2_STD_SECAM, + [ 4 /* bttv */ ] = V4L2_STD_PAL_M, + [ 5 /* bttv */ ] = V4L2_STD_PAL_N, + [ 6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, + }; struct video_channel *vc = arg; - t->radio = 0; - t->tvnorm = vc->norm; - if (-1 != t->pinnacle_id) - tda9887_miro(t); - else - tda9887_configure(t); + t->radio = 0; + if (vc->norm < ARRAY_SIZE(map)) + t->std = map[vc->norm]; + tda9887_fixup_std(t); + tda9887_configure(t); + if (debug > 2) { + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(HZ); + tda9887_status(t); + } + break; + } + case VIDIOC_S_STD: + { + v4l2_std_id *id = arg; + + t->radio = 0; + t->std = *id; + tda9887_fixup_std(t); + tda9887_configure(t); break; } default: diff --git a/linux/include/linux/videodev2.h b/linux/include/linux/videodev2.h index 0fc702180..05d2f893d 100644 --- a/linux/include/linux/videodev2.h +++ b/linux/include/linux/videodev2.h @@ -545,6 +545,8 @@ typedef __u64 v4l2_std_id; V4L2_STD_PAL_N |\ V4L2_STD_PAL_Nc |\ V4L2_STD_SECAM) +#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\ + V4L2_STD_ATSC_16_VSB) #define V4L2_STD_UNKNOWN 0 #define V4L2_STD_ALL (V4L2_STD_525_60 |\ |