Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Dec 2005 13:42:40 +0100 (CET)
From:      "Bojan Petrovic" <bpetrovi@f.bg.ac.yu>
To:        <freebsd-multimedia@freebsd.org>
Subject:   A new detection routine for Microtune MT2032 an MT2050 tuners
Message-ID:  <33731.147.91.1.45.1134391360.squirrel@webmail.f.bg.ac.yu>

next in thread | raw e-mail | index | archive | help
I have a Pinnacle PCTV card with a (I think) Microtune MT2050 tuner.
It doesn't get detected properly, but one of the tuner registers has a
value of 0x42 which should be the MT2050 identifier.

I think that the problem might be in the detection code.  The tuner
identification codes are obtained by reading first (all?) 21 tuner
registers and looking at last four values.  For MT2032 the register
0x13 should read 0x04, for MT2050, 0x42.

The current detection routine reads the registers by calling
MT2032_GetRegister() function 21 times in a row.

In the Linux bttv driver, the register values are obtained by first
sending the 0x00 to the tuner (which I think addresses the first
register), doing 21 i2c reads, and finally raising the i2c STOP
condition.

I'm unable to get any Microtune documentation, but I'm guessing that
something changed with the MT2050.

It would be great if someone with a MT2032 or a MT2050 tuner could try
the following patch. The files patched are from the CURRENT tree
(src/dev/bktr/).

I would like to know if it breaks the MT2032 detection, and if it
succeeds in detecting the MT2050 (it will be written in the kernel
log). Also, the kernel log will contain the register values obtained
from the old detection code, and values from the new detection code.
I'd like to know if there is any difference between the two. If
everything goes well, i will send the routines for changing the
frequencies of the MT2050.

Bojan

diff -u current/bktr_core.c currentmod/bktr_core.c
--- current/bktr_core.c	Mon Dec 12 12:55:39 2005
+++ currentmod/bktr_core.c	Mon Dec 12 12:59:42 2005
@@ -442,7 +442,8 @@
  */
 static int	common_ioctl( bktr_ptr_t bktr, ioctl_cmd_t cmd, caddr_t arg );

-
+/* We need these for the new Microtune detection routine, so they won't
be static */
+#if 0
 #if !defined(BKTR_USE_FREEBSD_SMBUS)
 /*
  * i2c primitives for low level control of i2c bus. Added for MSP34xx
control
@@ -452,7 +453,7 @@
 static int      i2c_write_byte( bktr_ptr_t bktr, unsigned char data);
 static int      i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int
last );
 #endif
-
+#endif


 /*
@@ -4070,20 +4071,20 @@
 /* from the Linux BTTV i2c driver by Gerd Knorr <kraxel@cs.tu-berlin.de> */

 #define BITD    40
-static void i2c_start( bktr_ptr_t bktr) {
+void i2c_start( bktr_ptr_t bktr) {
         OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release data */
         OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release clock */
         OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* lower data */
         OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock */
 }

-static void i2c_stop( bktr_ptr_t bktr) {
+void i2c_stop( bktr_ptr_t bktr) {
         OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock &
data */
         OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* release clock */
         OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release data */
 }

-static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data) {
+int i2c_write_byte( bktr_ptr_t bktr, unsigned char data) {
         int x;
         int status;

@@ -4116,7 +4117,7 @@
         return( status );
 }

-static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ) {
+int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ) {
         int x;
         int bit;
         int byte = 0;
diff -u current/bktr_core.h currentmod/bktr_core.h
--- current/bktr_core.h	Thu Jan  6 02:42:32 2005
+++ currentmod/bktr_core.h	Mon Dec 12 12:59:42 2005
@@ -52,6 +52,11 @@
 int		i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 );
 int		i2cRead( bktr_ptr_t bktr, int addr );

+void     i2c_start( bktr_ptr_t bktr);
+void     i2c_stop( bktr_ptr_t bktr);
+int      i2c_write_byte( bktr_ptr_t bktr, unsigned char data);
+int      i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last );
+
 void            msp_dpl_reset( bktr_ptr_t bktr, int i2d_addr );
 unsigned int    msp_dpl_read( bktr_ptr_t bktr, int i2c_addr, unsigned
char dev, unsigned int addr );
 void            msp_dpl_write( bktr_ptr_t bktr, int i2c_addr, unsigned
char dev,
@@ -75,6 +80,7 @@
 void	common_bktr_attach( bktr_ptr_t bktr, int unit,
 			u_long pci_id, u_int rev );
 int	common_bktr_intr( void *arg );
+


 /* Prototypes for open, close, read, mmap and ioctl calls */
diff -u current/bktr_tuner.c currentmod/bktr_tuner.c
--- current/bktr_tuner.c	Sun Nov 13 14:26:38 2005
+++ currentmod/bktr_tuner.c	Mon Dec 12 13:10:38 2005
@@ -1120,11 +1120,29 @@

 	TDA9887_init(bktr, 0);

+	printf("%s: MT20xx: Reg. dump (old detection):", bktr_name(bktr));
 	for (i = 0; i < 21; i++) {
 		if ((x = MT2032_GetRegister(i)) == -1)
 			break;
+		printf(" %02x",x);
 		rdbuf[i] = x;
 	}
+
+	if (i < 21)
+		return -1;
+
+	printf("\n%s: MT20xx: Reg. dump (new detection):", bktr_name(bktr));
+	i2c_start(bktr);
+	i2c_write_byte(bktr,0xc0);
+	i2c_write_byte(bktr,0x00);
+	i2c_start(bktr);
+	i2c_write_byte(bktr,0xc1);
+	for (i=0;i<21;i++) {
+		i2c_read_byte(bktr,&rdbuf[i],i==20);
+		printf(" %02x",rdbuf[i]);
+	}
+	i2c_stop(bktr);
+	if (rdbuf[0x13]==0x42) printf("\n%s: This might be the MT2050\n",
bktr_name(bktr));
 	if (i < 21)
 		return -1;







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