Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] Re: [rfc/patch] pll handling and cx22702 update



> > Don't be scared because of yet another redesign, the old and new stuff
> > can live in parallel, so can have a more smooth switchover than with
> > the frontend refactoring ;)
> 
> Basically I like your approach, but your patch gets a ton of rejects
> in cx22702.c against dvb-kernel CVS :-(

Patch is build against a pretty fresh (post-fe-refactor-merge) bk
snapshot of the kernel, not against linuxtv cvs.  I assumed they are
close enougth that it fits in neverless, but seems that isn't the case.

Should I just mail my current cx22702.[ch] files?  The diff likely isn't
much smaller anyway ...

> The improvements in code readablity are also not easy to see from your
> patch since it mixes the PLL cleanup with a lot of other changes.

Have a look at the patch below (rdiff from video4linux cvs, 5 days ago
against now).  That one also has some small unrelated fixes in, but the
actual pll-related changes should be much more clear ;)

  Gerd

Index: video4linux/cx22702.c
diff -u video4linux/cx22702.c:1.7 video4linux/cx22702.c:1.9
--- video4linux/cx22702.c:1.7	Wed Oct 20 19:44:23 2004
+++ video4linux/cx22702.c	Thu Dec  9 14:26:53 2004
@@ -33,6 +33,7 @@
 #include <linux/delay.h>
 
 #include "dvb_frontend.h"
+#include "dvb-pll.h"
 #include "cx22702.h"
 
 #define FRONTEND_NAME "dvbfe_cx22702"
@@ -40,7 +41,7 @@
 #define dprintk	if (debug) printk
 
 static int debug = 0;
-module_param(debug, int, 644);
+module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Enable verbose debug messages");
 
 /* ------------------------------------------------------------------ */
@@ -48,10 +49,10 @@
 struct cx22702_state {
 	struct i2c_client               demod;
 	struct i2c_client               pll;
+	struct dvb_pll_desc             *pll_desc;
 	struct dvb_frontend             fe;
 	struct dvb_frontend_ops         ops;
 	struct dvb_frontend_parameters  p;
-	int (*set_pll)(struct i2c_client *c, u32 freq, int bandwidth);
 	u8 prevUCBlocks;
 };
 
@@ -122,11 +123,11 @@
 	return rd[0];
 }
 
+/* ------------------------------------------------------------------ */
+
 #define PLL_ENABLE(cx)  writereg(&cx->demod, 0x0D, readreg(&cx->demod, 0x0D) & 0xfe)
 #define PLL_DISABLE(cx) writereg(&cx->demod, 0x0D, readreg(&cx->demod, 0x0D) | 0x01)
 
-/* ------------------------------------------------------------------ */
-
 static int pll_write4(struct i2c_client *c, u8 *data)
 {
 	int ret;
@@ -140,120 +141,6 @@
 	return 0;
 }
 
-static int pll_dtt759x_set_tv_freq(struct i2c_client *c, u32 freq, int bandwidth)
-{
-	int ret;
-	u32 div = (freq + 36166667) / 166666;
-
-	/* dividerhigh, dividerlow, control, bandwidth switch tuner args */
-	unsigned char buf [4] = {
-		(div >> 8) & 0x7f,
-		div & 0xff,
-		0x84,
-		0x00
-	};
-
-	if(freq < 470000000) {
-		buf[3] = 0x02;
-	} else {
-		buf[3] = 0x08;
-	}
-
-	if(bandwidth == BANDWIDTH_7_MHZ) {
-		buf[3] |= 0x10;
-	}
-
-	// Now compensate for the charge pump osc
-	if(freq <= 264000000) {
-		buf[2] = buf[2] | 0x30;
-	} else if (freq <= 735000000) {
-		buf[2] = buf[2] | 0x38;
-	} else if (freq <= 835000000) {
-		buf[2] = buf[2] | 0x70;
-	} else if (freq <= 896000000) {
-		buf[2] = buf[2] | 0x78;
-	}
-
-	dprintk ("%s: freq == %i, div == 0x%04x\n", __FUNCTION__, (int) freq, (int) div);
-
-	ret = pll_write4(c, buf);
-	if(ret<0) {
-		dprintk ("%s: first pll_write failed\n",__FUNCTION__);
-		return ret;
-	}
-
-	/* Set the AGC during search */
-	buf[2]=(buf[2] & 0xc7) | 0x18;
-	buf[3]=0xa0;
-	ret = pll_write4(c, buf);
-	if(ret<0) {
-		dprintk ("%s: second pll_write failed\n",__FUNCTION__);
-		return ret;
-	}
-
-	/* Tuner needs a small amount of time */
-	msleep(100);
-
-	/* Set the AGC post-search */
-	buf[3]=0x20;
-	ret=pll_write4(c, buf);
-	if(ret<0) {
-		dprintk ("%s: third pll_write failed\n",__FUNCTION__);
-		return ret;
-	}
-
-	return ret;
-}
-
-static int pll_dtt7579_set_tv_freq(struct i2c_client *c, u32 freq, int bandwidth)
-{
-	int ret;
-	u32 div = (freq + 36166667) / 166666;
-
-	/* dividerhigh, dividerlow */
-	unsigned char buf [4] = {
-		div >> 8,
-		div & 0xff,
-		0x00,
-		0x00
-	};
-
-	// FIXME: bandwidth setting unknown
-
-	// Now compensate for the charge pump osc
-	if(freq <= 506000000) {
-		buf[2] = 0xb4;
-	   	buf[3] = 0x02;
-	} else if (freq <= 735000000) {
-   		buf[2] = 0xbc;
-	   	buf[3] = 0x08;
-	} else if (freq <= 835000000) {
-      		buf[2] = 0xf4;
-	   	buf[3] = 0x08;
-	} else if (freq <= 896000000) {
-		buf[2] = 0xfc;
-	   	buf[3] = 0x08;
-	}
-
-	dprintk ("%s: freq == %i, div == 0x%04x\n", __FUNCTION__, (int) freq, (int) div);
-
-	ret = pll_write4(c, buf);
-	if (ret<0) {
-		dprintk ("%s: first pll_write failed\n",__FUNCTION__);
-		return ret;
-	}
-
-	/* Set the AGC to search */
-	buf[2]=(buf[2] & 0xdc) | 0x9c;
-	buf[3]=0xa0;
-	ret = pll_write4(c, buf);
-	if(ret<0) {
-		dprintk ("%s: second pll_write failed\n",__FUNCTION__);
-		return ret;
-	}
-	return ret;
-}
-
 /* ------------------------------------------------------------------ */
 
 static int cx22702_reset(struct cx22702_state *state)
@@ -294,11 +181,16 @@
 static int cx22702_set_tps(struct cx22702_state *state)
 {
 	u8 val;
+	u8 pllbuf[4];
 
 	dprintk("%s\n",__FUNCTION__);
+
 	/* set PLL */
+	dvb_pll_configure(state->pll_desc, pllbuf,
+			  state->p.frequency,
+			  state->p.u.ofdm.bandwidth);
 	PLL_ENABLE(state);
-	state->set_pll(&state->pll, state->p.frequency, state->p.u.ofdm.bandwidth);
+	pll_write4(&state->pll,pllbuf);
 	PLL_DISABLE(state);
 
 	/* set inversion */
@@ -492,12 +384,6 @@
 	PLL_ENABLE(state);
 	result = readreg(&state->pll,0xc2);
 	PLL_DISABLE(state);
-
-	if(result < 0)
-		return result;
-	if((result >= 0) && (result&0x30))
-		return 0;
-
 	return result;
 }
 
@@ -511,12 +397,19 @@
 	return 0;
 }
 
-#if 0
 static int cx22702_sleep(struct dvb_frontend* fe)
 {
 	struct cx22702_state *state = fe->demodulator_priv;
+	u8 pllbuf[4];
+
+	dprintk("%s\n",__FUNCTION__);
+
+	dvb_pll_configure(state->pll_desc, pllbuf, 0, 0);
+	PLL_ENABLE(state);
+	pll_write4(&state->pll,pllbuf);
+	PLL_DISABLE(state);
+	return 0;
 }
-#endif
 
 static int cx22702_set_frontend(struct dvb_frontend* fe,
 				struct dvb_frontend_parameters* params)
@@ -643,6 +536,7 @@
 		FE_CAN_RECOVER,
 	},
 	.init                 = cx22702_init,
+	.sleep                = cx22702_sleep,
 	.set_frontend         = cx22702_set_frontend,
 	.get_frontend         = cx22702_get_frontend,
 	.read_status          = cx22702_read_status,
@@ -654,7 +548,7 @@
 };
 
 void* cx22702_create(struct i2c_adapter *i2c,
-		     int pll_addr, int pll_type,
+		     int pll_addr, struct dvb_pll_desc *pll_desc,
 		     int demod_addr)
 {
 	struct cx22702_state *state;
@@ -666,6 +560,7 @@
 	memset(state, 0, sizeof(*state));
 
 	state->ops                 = cx22702_fe_ops;
+	state->pll_desc            = pll_desc;
 	state->fe.demodulator_priv = state;
 	state->fe.ops              = &state->ops;
 
@@ -673,26 +568,12 @@
 	state->demod.adapter = i2c;
 	state->demod.addr    = demod_addr;
 	state->pll           = pll_template;
+	strlcpy(state->pll.name, pll_desc->name, sizeof(state->pll.name));
 	state->pll.adapter   = i2c;
 	state->pll.addr      = pll_addr;
 	i2c_set_clientdata(&state->demod, state);
 	i2c_set_clientdata(&state->pll, state);
 
-	switch (pll_type) {
-	case PLLTYPE_DTT7579:
-		state->set_pll = pll_dtt7579_set_tv_freq;
-		state->ops.info.frequency_min = 177000000;
-		break;
-	case PLLTYPE_DTT7592:
-		state->set_pll = pll_dtt759x_set_tv_freq;
-		state->ops.info.frequency_min = 474000000;
-		break;
-	case PLLTYPE_DTT7595:
-		state->set_pll = pll_dtt759x_set_tv_freq;
-		state->ops.info.frequency_min = 177000000;
-		break;
-	}
-
 	/* verify devices */
 	ret=cx22702_validate_demod(&state->demod);
 	if (ret < 0)
@@ -729,10 +610,8 @@
 	struct i2c_client *c = container_of(dev, struct i2c_client, dev);
 	struct cx22702_state *st = i2c_get_clientdata(c);
 
-	if (c != &st->demod)
-		return 0;
 	dprintk("cx22702: suspend\n");
-	/* power down ??? */
+	cx22702_sleep(&st->fe);
 	return 0;
 }
 
@@ -741,8 +620,6 @@
 	struct i2c_client *c = container_of(dev, struct i2c_client, dev);
 	struct cx22702_state *st = i2c_get_clientdata(c);
 
-	if (c != &st->demod)
-		return 0;
 	dprintk("cx22702: resume\n");
 	cx22702_reset(st);
 	if (st->p.frequency != 0)
@@ -773,7 +650,7 @@
 	.id    = I2C_DRIVERID_DVBFE_CX22702,
 };
 static struct i2c_client pll_template = {
-	.name   = "Thomson DTT 75xx",
+	.name   = "unset",
 	.flags  = I2C_CLIENT_ALLOW_USE,
 	.driver = &pll_driver,
 };
@@ -794,8 +671,9 @@
 module_init (init_cx22702);
 module_exit (exit_cx22702);
 
-MODULE_DESCRIPTION("CX22702 / Thomson DTT 75xx PLL DVB Frontend driver");
+MODULE_DESCRIPTION("CX22702 DVB Frontend driver");
 MODULE_AUTHOR("Steven Toth");
+MODULE_AUTHOR("Gerd Knorr");
 MODULE_LICENSE("GPL");
 
 /*
Index: video4linux/cx22702.h
diff -u video4linux/cx22702.h:1.2 video4linux/cx22702.h:1.3
--- video4linux/cx22702.h:1.2	Wed Oct 20 19:44:24 2004
+++ video4linux/cx22702.h	Thu Dec  9 13:51:35 2004
@@ -1,8 +1,4 @@
-#define PLLTYPE_DTT7592 1
-#define PLLTYPE_DTT7595 2
-#define PLLTYPE_DTT7579 3
-
 void* cx22702_create(struct i2c_adapter *i2c,
-		     int pll_addr, int pll_type,
+		     int pll_addr, struct dvb_pll_desc *pll,
 		     int demod_addr);
 int cx22702_destroy(void*);




Home | Main Index | Thread Index