Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Dec 2005 11:11:32 +0100 (CET)
From:      "Bojan Petrovic" <bpetrovi@f.bg.ac.yu>
To:        <freebsd-multimedia@freebsd.org>
Subject:   Re: A new detection routine for Microtune MT2032 an MT2050 tuners
Message-ID:  <33943.147.91.1.43.1134641492.squirrel@webmail.f.bg.ac.yu>
In-Reply-To: <20051214062316.046E246C8@spamproxy.f.bg.ac.yu>
References:  <Pine.LNX.4.44.0512121408270.23639-100000@dekart.f.bg.ac.yu> <20051214062316.046E246C8@spamproxy.f.bg.ac.yu>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi.
I have attached the patch (again, the diff is from the
CURRENT source files) which should enable you to change
the channels (I think it won't work on NTSC).

The problems i've noticed so far:
Some channels that look good in Linux (tvtime) look snowy
or washed out in bktr (fxtv). The frequencies sent to the
tuner are a little bit off from the tvtime frequencies,
so you might need a program which has a manual fine tune
option. Or maybe you could set the correct freq. set
somewhere (by sysctl maybe, I didn't have time to look at
this)

Sometimes there are no channels at all, in Linux or in
FreeBSD, and switching the computer off and on helped.

Please tell me if you had any problems.
Bojan.

PS. I currently don't have much time to work on this,
so I'll get back to it in a month or so.



[-- Attachment #2 --]
diff -u current/bktr_card.c newest/bktr_card.c
--- current/bktr_card.c	Sun Dec  4 11:06:04 2005
+++ newest/bktr_card.c	Wed Dec 14 22:44:39 2005
@@ -636,6 +636,7 @@
 	u_char 		eeprom[256];
 	int 		tuner_i2c_address = -1;
 	int 		eeprom_i2c_address = -1;
+	int		microtune_tuner;
 
 	/* Select all GPIO bits as inputs */
 	OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
@@ -914,11 +915,19 @@
 checkTuner:
 
 #if !defined( BKTR_OVERRIDE_TUNER )
-	if (card == CARD_MIRO && mt2032_init(bktr) == 0 &&
-	    bktr->bt848_tuner == -1) {
+	if (card == CARD_MIRO && bktr->bt848_tuner == -1) {
 		bktr->card = cards[ (card = CARD_PINNACLE_PCTV_RAVE) ];
-		select_tuner( bktr, TUNER_MT2032 );
-		goto checkDBX;
+		microtune_tuner = microtune_init(bktr);
+		switch (microtune_tuner) {
+		case (TUNER_MT2032):
+			select_tuner(bktr, TUNER_MT2032);
+			goto checkDBX;
+			break;
+		case TUNER_MT2050:
+			select_tuner(bktr, TUNER_MT2050);
+			goto checkDBX;
+			break;
+		}
 	}
 #endif
 
diff -u current/bktr_tuner.c newest/bktr_tuner.c
--- current/bktr_tuner.c	Sun Nov 13 14:26:38 2005
+++ newest/bktr_tuner.c	Thu Dec 15 11:37:32 2005
@@ -136,6 +136,7 @@
 
 
 static void mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq);
+static void mt2050_set_tv_freq(bktr_ptr_t bktr, unsigned int freq);
 
 
 static const struct TUNER tuners[] = {
@@ -299,6 +300,17 @@
 	     0x00 },
 	   { 0x00, 0x00 },                      /* band-switch crosspoints */
 	   { 0xa0, 0x90, 0x30, 0x8e } },        /* the band-switch values */
+
+
+	/* MT2050 Microtune */
+	{ "MT2050",				/* the 'name' */
+	   TTYPE_PAL,				/* input type */
+	   { TSA552x_SCONTROL,			/* control byte for Tuner PLL */
+	     TSA552x_SCONTROL,
+	     TSA552x_SCONTROL,
+	     0x00 },
+	   { 0x00, 0x00 },			/* band-switch crosspoints */
+	   { 0xa0, 0x90, 0x30, 0x00 } },	/* the band-switch values */
 };
 
 
@@ -815,6 +827,10 @@
 		mt2032_set_tv_freq(bktr, frequency);
 		return 0;
 	}
+	if (tuner == &tuners[TUNER_MT2050]) {
+		mt2050_set_tv_freq(bktr, frequency);
+		return 0;
+	}
 	if (type == TV_FREQUENCY) {
 		/*
 		 * select the band based on frequency
@@ -1002,7 +1018,8 @@
  * Get the Tuner status and signal strength
  */
 int     get_tuner_status( bktr_ptr_t bktr ) {
-	if (bktr->card.tuner == &tuners[TUNER_MT2032])
+	if (bktr->card.tuner == &tuners[TUNER_MT2032] ||
+		bktr->card.tuner == &tuners[TUNER_MT2050])
 		return 0;
 	return i2cRead( bktr, bktr->card.tuner_pllAddr + 1 );
 }
@@ -1109,32 +1126,10 @@
 #define	MT2032_GetRegister(r)		_MT2032_GetRegister(bktr,r)
 #define	MT2032_SetRegister(r,d)		_MT2032_SetRegister(bktr,r,d)
 
-
-int 
+static void
 mt2032_init(bktr_ptr_t bktr)
 {
-	u_char            rdbuf[22];
 	int             xogc, xok = 0;
-	int             i;
-	int		x;
-
-	TDA9887_init(bktr, 0);
-
-	for (i = 0; i < 21; i++) {
-		if ((x = MT2032_GetRegister(i)) == -1)
-			break;
-		rdbuf[i] = x;
-	}
-	if (i < 21)
-		return -1;
-
-	printf("%s: MT2032: Companycode=%02x%02x Part=%02x Revision=%02x\n",
-		bktr_name(bktr),
-		rdbuf[0x11], rdbuf[0x12], rdbuf[0x13], rdbuf[0x14]);
-	if (rdbuf[0x13] != 4) {
-		printf("%s: MT2032 not found or unknown type\n", bktr_name(bktr));
-		return -1;
-	}
 
 	/* Initialize Registers per spec. */
 	MT2032_SetRegister(2, 0xff);
@@ -1167,7 +1162,53 @@
 
 	MT2032_XOGC = xogc;
 
-	return 0;
+}
+
+static void
+mt2050_init(bktr_ptr_t bktr)
+{
+	int result;
+	MT2032_SetRegister(6, 0x10);
+	MT2032_SetRegister(0x0f, 0x0f);
+	result = MT2032_GetRegister(0x0d);
+}
+
+
+int
+microtune_init(bktr_ptr_t bktr) {
+	u_char            rdbuf[22];
+	int             i;
+	int		x;
+	int		tuner;
+
+	TDA9887_init(bktr, 0);
+
+	for (i = 0; i < 21; i++) {
+		if ((x = MT2032_GetRegister(i)) == -1)
+			break;
+		rdbuf[i] = x;
+	}
+	if (i < 21)
+		return -1;
+	
+	tuner=-1;
+	if (rdbuf[0x13]==4) {
+		mt2032_init(bktr);
+		tuner=TUNER_MT2032;
+		select_tuner(bktr, TUNER_MT2032);
+	} else if (rdbuf[0]==0x42) {
+		mt2050_init(bktr);
+		tuner=TUNER_MT2050;
+		select_tuner(bktr, TUNER_MT2050);
+	}
+	printf("%s: MT20xx: Companycode=%02x%02x Part=%02x Revision=%02x\n",
+		bktr_name(bktr),
+		rdbuf[0x11], rdbuf[0x12], (tuner==TUNER_MT2050) ? rdbuf[0] : rdbuf[0x13] , rdbuf[0x14]);
+
+	if ((tuner != TUNER_MT2050) && (tuner != TUNER_MT2032)) {
+		printf("%s: MT20xx not found or unknown type\n", bktr_name(bktr));
+	}
+	return(tuner);
 }
 
 static int 
@@ -1422,5 +1463,68 @@
 		if (bootverbose)
 			printf("%s: frequency set to %d, st = %#x, tad = %#x\n",
 				bktr_name(bktr), freq*62500, stat, tad);
+	}
+}
+
+static int
+MT2050_SetIFFreq(bktr_ptr_t bktr, int freq, int if2)
+{
+	unsigned int if1, f_lo1, f_lo2, lo1, lo2, f_lo1_modulo, f_lo2_modulo, num1, num2, div1a, div1b, div2a, div2b;
+	unsigned char buf[6];
+	int i;
+	printf("\nsetting mt2050 freq %d\n", freq);
+	if1=1218*1000*1000;
+	f_lo1=freq+if1;
+	f_lo1=(f_lo1/1000000)*1000000;
+
+	f_lo2=f_lo1-freq-if2;
+	f_lo2=(f_lo2/50000)*50000;
+
+	lo1=f_lo1/4000000;
+	lo2=f_lo2/4000000;
+
+	f_lo1_modulo= f_lo1-(lo1*4000000);
+	f_lo2_modulo= f_lo2-(lo2*4000000);
+
+	num1=4*f_lo1_modulo/4000000;
+	num2=4096*(f_lo2_modulo/1000)/4000;
+
+	div1a=(lo1/12)-1;
+	div1b=lo1-(div1a+1)*12;
+	div2a=(lo2/8)-1;
+	div2b=lo2-(div2a+1)*8;
+
+	buf[0]=1;
+	buf[1]=4*div1b+num1;
+	if(freq<275*1000*1000) buf[1] = buf[1]|0x80;
+
+	buf[2]=div1a;
+	buf[3]=32*div2b + num2/256;
+	buf[4]=num2-(num2/256)*256;
+	buf[5]=div2a;
+	if(num2!=0) buf[5]=buf[5]|0x40;
+
+	MT2032_SetRegister(1,buf[1]);
+	MT2032_SetRegister(2,buf[2]);
+	MT2032_SetRegister(3,buf[3]);
+	MT2032_SetRegister(4,buf[4]);
+	MT2032_SetRegister(5,buf[5]);
+	return 0;
+}
+
+static void
+mt2050_set_tv_freq(bktr_ptr_t bktr, unsigned int freq)
+{
+	int if2;
+
+#ifdef MT2032_NTSC
+	if2=45750*1000;
+#else
+	if2=38900*1000;
+#endif
+
+	if (MT2050_SetIFFreq(bktr, freq*62500 /* freq*1000*1000/16 */,
+		if2) == 0) {
+		bktr->tuner.frequency = freq;
 	}
 }
diff -u current/bktr_tuner.h newest/bktr_tuner.h
--- current/bktr_tuner.h	Sun Nov 13 14:26:38 2005
+++ newest/bktr_tuner.h	Wed Dec 14 21:43:04 2005
@@ -61,7 +61,8 @@
 #define ALPS_TSBH1		13
 #define TUNER_MT2032		14
 #define	LG_TPI8PSB12P_PAL	15
-#define Bt848_MAX_TUNER		16
+#define TUNER_MT2050		16
+#define Bt848_MAX_TUNER		17
 
 /* experimental code for Automatic Frequency Control */ 
 #define TUNER_AFC
@@ -93,7 +94,7 @@
 int	do_afc( bktr_ptr_t bktr, int addr, int frequency );
 #endif /* TUNER_AFC */
 
-int mt2032_init(bktr_ptr_t bktr);
+int microtune_init(bktr_ptr_t bktr);
 
 /* 
  * This is for start-up convenience only, NOT mandatory.

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33943.147.91.1.43.1134641492.squirrel>