aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Boettcher <pb@linuxtv.org>2008-03-29 20:01:12 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 13:07:56 -0400
commitca06fa79a5babc21f0240979e5b1dd34dcc3c6e4 (patch)
tree363a53a37c8ac6dd30b11ca2ce825a37fd40de15
parent6394cf53abc0b3a2db9e8b947ef5c77b16861ec8 (diff)
V4L/DVB (7470): CX24123: preparing support for CX24113 tuner
To support a new device based on CX24123 (using the CX24113-tuner) the following was done: - added two parameters to de-select the internal PLL-driver (for CX24108) and a AGC-function callback. - added a virtual i2c-adapter which allow simple access behind the i2c-gate - cleanup up some code Signed-off-by: Patrick Boettcher <pb@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r--drivers/media/dvb/frontends/cx24123.c304
-rw-r--r--drivers/media/dvb/frontends/cx24123.h21
2 files changed, 220 insertions, 105 deletions
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index d74fdbd63361..7f68d78c6558 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -1,24 +1,26 @@
1/* 1/*
2 Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver 2 * Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver
3 3 *
4 Copyright (C) 2005 Steven Toth <stoth@hauppauge.com> 4 * Copyright (C) 2005 Steven Toth <stoth@hauppauge.com>
5 5 *
6 Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc> 6 * Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * Support for CX24123/CX24113-NIM by Patrick Boettcher <pb@linuxtv.org>
9 it under the terms of the GNU General Public License as published by 9 *
10 the Free Software Foundation; either version 2 of the License, or 10 * This program is free software; you can redistribute it and/or
11 (at your option) any later version. 11 * modify it under the terms of the GNU General Public License as
12 12 * published by the Free Software Foundation; either version 2 of
13 This program is distributed in the hope that it will be useful, 13 * the License, or (at your option) any later version.
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 *
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * This program is distributed in the hope that it will be useful,
16 GNU General Public License for more details. 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 You should have received a copy of the GNU General Public License 18 * General Public License for more details.
19 along with this program; if not, write to the Free Software 19 *
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * You should have received a copy of the GNU General Public License
21*/ 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
22 24
23#include <linux/slab.h> 25#include <linux/slab.h>
24#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -32,9 +34,16 @@
32 34
33static int force_band; 35static int force_band;
34static int debug; 36static int debug;
37
38#define info(args...) do { printk(KERN_INFO "CX24123: " args); } while (0)
39#define err(args...) do { printk(KERN_ERR "CX24123: " args); } while (0)
40
35#define dprintk(args...) \ 41#define dprintk(args...) \
36 do { \ 42 do { \
37 if (debug) printk (KERN_DEBUG "cx24123: " args); \ 43 if (debug) { \
44 printk(KERN_DEBUG "CX24123: %s: ", __func__); \
45 printk(args); \
46 } \
38 } while (0) 47 } while (0)
39 48
40struct cx24123_state 49struct cx24123_state
@@ -51,6 +60,10 @@ struct cx24123_state
51 u32 pllarg; 60 u32 pllarg;
52 u32 FILTune; 61 u32 FILTune;
53 62
63 struct i2c_adapter tuner_i2c_adapter;
64
65 u8 demod_rev;
66
54 /* The Demod/Tuner can't easily provide these, we cache them */ 67 /* The Demod/Tuner can't easily provide these, we cache them */
55 u32 currentfreq; 68 u32 currentfreq;
56 u32 currentsymbolrate; 69 u32 currentsymbolrate;
@@ -225,48 +238,52 @@ static struct {
225 {0x67, 0x83}, /* Non-DCII symbol clock */ 238 {0x67, 0x83}, /* Non-DCII symbol clock */
226}; 239};
227 240
228static int cx24123_writereg(struct cx24123_state* state, int reg, int data) 241static int cx24123_i2c_writereg(struct cx24123_state *state,
242 u8 i2c_addr, int reg, int data)
229{ 243{
230 u8 buf[] = { reg, data }; 244 u8 buf[] = { reg, data };
231 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; 245 struct i2c_msg msg = {
246 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
247 };
232 int err; 248 int err;
233 249
234 if (debug>1) 250 /* printk(KERN_DEBUG "wr(%02x): %02x %02x\n", i2c_addr, reg, data); */
235 printk("cx24123: %s: write reg 0x%02x, value 0x%02x\n",
236 __FUNCTION__,reg, data);
237 251
238 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 252 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
239 printk("%s: writereg error(err == %i, reg == 0x%02x," 253 printk("%s: writereg error(err == %i, reg == 0x%02x,"
240 " data == 0x%02x)\n", __FUNCTION__, err, reg, data); 254 " data == 0x%02x)\n", __func__, err, reg, data);
241 return -EREMOTEIO; 255 return err;
242 } 256 }
243 257
244 return 0; 258 return 0;
245} 259}
246 260
247static int cx24123_readreg(struct cx24123_state* state, u8 reg) 261static int cx24123_i2c_readreg(struct cx24123_state *state, u8 i2c_addr, u8 reg)
248{ 262{
249 int ret; 263 int ret;
250 u8 b0[] = { reg }; 264 u8 b = 0;
251 u8 b1[] = { 0 };
252 struct i2c_msg msg[] = { 265 struct i2c_msg msg[] = {
253 { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, 266 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
254 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } 267 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &b, .len = 1 }
255 }; 268 };
256 269
257 ret = i2c_transfer(state->i2c, msg, 2); 270 ret = i2c_transfer(state->i2c, msg, 2);
258 271
259 if (ret != 2) { 272 if (ret != 2) {
260 printk("%s: reg=0x%x (error=%d)\n", __FUNCTION__, reg, ret); 273 err("%s: reg=0x%x (error=%d)\n", __func__, reg, ret);
261 return ret; 274 return ret;
262 } 275 }
263 276
264 if (debug>1) 277 /* printk(KERN_DEBUG "rd(%02x): %02x %02x\n", i2c_addr, reg, b); */
265 printk("cx24123: read reg 0x%02x, value 0x%02x\n",reg, ret);
266 278
267 return b1[0]; 279 return b;
268} 280}
269 281
282#define cx24123_readreg(state, reg) \
283 cx24123_i2c_readreg(state, state->config->demod_address, reg)
284#define cx24123_writereg(state, reg, val) \
285 cx24123_i2c_writereg(state, state->config->demod_address, reg, val)
286
270static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_inversion_t inversion) 287static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_inversion_t inversion)
271{ 288{
272 u8 nom_reg = cx24123_readreg(state, 0x0e); 289 u8 nom_reg = cx24123_readreg(state, 0x0e);
@@ -274,17 +291,17 @@ static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_invers
274 291
275 switch (inversion) { 292 switch (inversion) {
276 case INVERSION_OFF: 293 case INVERSION_OFF:
277 dprintk("%s: inversion off\n",__FUNCTION__); 294 dprintk("inversion off\n");
278 cx24123_writereg(state, 0x0e, nom_reg & ~0x80); 295 cx24123_writereg(state, 0x0e, nom_reg & ~0x80);
279 cx24123_writereg(state, 0x10, auto_reg | 0x80); 296 cx24123_writereg(state, 0x10, auto_reg | 0x80);
280 break; 297 break;
281 case INVERSION_ON: 298 case INVERSION_ON:
282 dprintk("%s: inversion on\n",__FUNCTION__); 299 dprintk("inversion on\n");
283 cx24123_writereg(state, 0x0e, nom_reg | 0x80); 300 cx24123_writereg(state, 0x0e, nom_reg | 0x80);
284 cx24123_writereg(state, 0x10, auto_reg | 0x80); 301 cx24123_writereg(state, 0x10, auto_reg | 0x80);
285 break; 302 break;
286 case INVERSION_AUTO: 303 case INVERSION_AUTO:
287 dprintk("%s: inversion auto\n",__FUNCTION__); 304 dprintk("inversion auto\n");
288 cx24123_writereg(state, 0x10, auto_reg & ~0x80); 305 cx24123_writereg(state, 0x10, auto_reg & ~0x80);
289 break; 306 break;
290 default: 307 default:
@@ -301,10 +318,10 @@ static int cx24123_get_inversion(struct cx24123_state* state, fe_spectral_invers
301 val = cx24123_readreg(state, 0x1b) >> 7; 318 val = cx24123_readreg(state, 0x1b) >> 7;
302 319
303 if (val == 0) { 320 if (val == 0) {
304 dprintk("%s: read inversion off\n",__FUNCTION__); 321 dprintk("read inversion off\n");
305 *inversion = INVERSION_OFF; 322 *inversion = INVERSION_OFF;
306 } else { 323 } else {
307 dprintk("%s: read inversion on\n",__FUNCTION__); 324 dprintk("read inversion on\n");
308 *inversion = INVERSION_ON; 325 *inversion = INVERSION_ON;
309 } 326 }
310 327
@@ -326,42 +343,42 @@ static int cx24123_set_fec(struct cx24123_state* state, fe_code_rate_t fec)
326 343
327 switch (fec) { 344 switch (fec) {
328 case FEC_1_2: 345 case FEC_1_2:
329 dprintk("%s: set FEC to 1/2\n",__FUNCTION__); 346 dprintk("set FEC to 1/2\n");
330 cx24123_writereg(state, 0x0e, nom_reg | 0x01); 347 cx24123_writereg(state, 0x0e, nom_reg | 0x01);
331 cx24123_writereg(state, 0x0f, 0x02); 348 cx24123_writereg(state, 0x0f, 0x02);
332 break; 349 break;
333 case FEC_2_3: 350 case FEC_2_3:
334 dprintk("%s: set FEC to 2/3\n",__FUNCTION__); 351 dprintk("set FEC to 2/3\n");
335 cx24123_writereg(state, 0x0e, nom_reg | 0x02); 352 cx24123_writereg(state, 0x0e, nom_reg | 0x02);
336 cx24123_writereg(state, 0x0f, 0x04); 353 cx24123_writereg(state, 0x0f, 0x04);
337 break; 354 break;
338 case FEC_3_4: 355 case FEC_3_4:
339 dprintk("%s: set FEC to 3/4\n",__FUNCTION__); 356 dprintk("set FEC to 3/4\n");
340 cx24123_writereg(state, 0x0e, nom_reg | 0x03); 357 cx24123_writereg(state, 0x0e, nom_reg | 0x03);
341 cx24123_writereg(state, 0x0f, 0x08); 358 cx24123_writereg(state, 0x0f, 0x08);
342 break; 359 break;
343 case FEC_4_5: 360 case FEC_4_5:
344 dprintk("%s: set FEC to 4/5\n",__FUNCTION__); 361 dprintk("set FEC to 4/5\n");
345 cx24123_writereg(state, 0x0e, nom_reg | 0x04); 362 cx24123_writereg(state, 0x0e, nom_reg | 0x04);
346 cx24123_writereg(state, 0x0f, 0x10); 363 cx24123_writereg(state, 0x0f, 0x10);
347 break; 364 break;
348 case FEC_5_6: 365 case FEC_5_6:
349 dprintk("%s: set FEC to 5/6\n",__FUNCTION__); 366 dprintk("set FEC to 5/6\n");
350 cx24123_writereg(state, 0x0e, nom_reg | 0x05); 367 cx24123_writereg(state, 0x0e, nom_reg | 0x05);
351 cx24123_writereg(state, 0x0f, 0x20); 368 cx24123_writereg(state, 0x0f, 0x20);
352 break; 369 break;
353 case FEC_6_7: 370 case FEC_6_7:
354 dprintk("%s: set FEC to 6/7\n",__FUNCTION__); 371 dprintk("set FEC to 6/7\n");
355 cx24123_writereg(state, 0x0e, nom_reg | 0x06); 372 cx24123_writereg(state, 0x0e, nom_reg | 0x06);
356 cx24123_writereg(state, 0x0f, 0x40); 373 cx24123_writereg(state, 0x0f, 0x40);
357 break; 374 break;
358 case FEC_7_8: 375 case FEC_7_8:
359 dprintk("%s: set FEC to 7/8\n",__FUNCTION__); 376 dprintk("set FEC to 7/8\n");
360 cx24123_writereg(state, 0x0e, nom_reg | 0x07); 377 cx24123_writereg(state, 0x0e, nom_reg | 0x07);
361 cx24123_writereg(state, 0x0f, 0x80); 378 cx24123_writereg(state, 0x0f, 0x80);
362 break; 379 break;
363 case FEC_AUTO: 380 case FEC_AUTO:
364 dprintk("%s: set FEC to auto\n",__FUNCTION__); 381 dprintk("set FEC to auto\n");
365 cx24123_writereg(state, 0x0f, 0xfe); 382 cx24123_writereg(state, 0x0f, 0xfe);
366 break; 383 break;
367 default: 384 default:
@@ -490,7 +507,8 @@ static int cx24123_set_symbolrate(struct cx24123_state* state, u32 srate)
490 tmp = cx24123_readreg(state, 0x0c) & ~0xe0; 507 tmp = cx24123_readreg(state, 0x0c) & ~0xe0;
491 cx24123_writereg(state, 0x0c, tmp | sample_gain << 5); 508 cx24123_writereg(state, 0x0c, tmp | sample_gain << 5);
492 509
493 dprintk("%s: srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n", __FUNCTION__, srate, ratio, sample_rate, sample_gain); 510 dprintk("srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n",
511 srate, ratio, sample_rate, sample_gain);
494 512
495 return 0; 513 return 0;
496} 514}
@@ -570,7 +588,7 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
570 struct cx24123_state *state = fe->demodulator_priv; 588 struct cx24123_state *state = fe->demodulator_priv;
571 unsigned long timeout; 589 unsigned long timeout;
572 590
573 dprintk("%s: pll writereg called, data=0x%08x\n",__FUNCTION__,data); 591 dprintk("pll writereg called, data=0x%08x\n", data);
574 592
575 /* align the 21 bytes into to bit23 boundary */ 593 /* align the 21 bytes into to bit23 boundary */
576 data = data << 3; 594 data = data << 3;
@@ -583,7 +601,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
583 cx24123_writereg(state, 0x22, (data >> 16) & 0xff); 601 cx24123_writereg(state, 0x22, (data >> 16) & 0xff);
584 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { 602 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) {
585 if (time_after(jiffies, timeout)) { 603 if (time_after(jiffies, timeout)) {
586 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 604 err("%s: demodulator is not responding, "\
605 "possibly hung, aborting.\n", __func__);
587 return -EREMOTEIO; 606 return -EREMOTEIO;
588 } 607 }
589 msleep(10); 608 msleep(10);
@@ -594,7 +613,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
594 cx24123_writereg(state, 0x22, (data>>8) & 0xff ); 613 cx24123_writereg(state, 0x22, (data>>8) & 0xff );
595 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { 614 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) {
596 if (time_after(jiffies, timeout)) { 615 if (time_after(jiffies, timeout)) {
597 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 616 err("%s: demodulator is not responding, "\
617 "possibly hung, aborting.\n", __func__);
598 return -EREMOTEIO; 618 return -EREMOTEIO;
599 } 619 }
600 msleep(10); 620 msleep(10);
@@ -605,7 +625,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
605 cx24123_writereg(state, 0x22, (data) & 0xff ); 625 cx24123_writereg(state, 0x22, (data) & 0xff );
606 while ((cx24123_readreg(state, 0x20) & 0x80)) { 626 while ((cx24123_readreg(state, 0x20) & 0x80)) {
607 if (time_after(jiffies, timeout)) { 627 if (time_after(jiffies, timeout)) {
608 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 628 err("%s: demodulator is not responding," \
629 "possibly hung, aborting.\n", __func__);
609 return -EREMOTEIO; 630 return -EREMOTEIO;
610 } 631 }
611 msleep(10); 632 msleep(10);
@@ -626,7 +647,7 @@ static int cx24123_pll_tune(struct dvb_frontend* fe, struct dvb_frontend_paramet
626 dprintk("frequency=%i\n", p->frequency); 647 dprintk("frequency=%i\n", p->frequency);
627 648
628 if (cx24123_pll_calculate(fe, p) != 0) { 649 if (cx24123_pll_calculate(fe, p) != 0) {
629 printk("%s: cx24123_pll_calcutate failed\n",__FUNCTION__); 650 err("%s: cx24123_pll_calcutate failed\n", __func__);
630 return -EINVAL; 651 return -EINVAL;
631 } 652 }
632 653
@@ -643,18 +664,38 @@ static int cx24123_pll_tune(struct dvb_frontend* fe, struct dvb_frontend_paramet
643 cx24123_writereg(state, 0x27, state->FILTune >> 2); 664 cx24123_writereg(state, 0x27, state->FILTune >> 2);
644 cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3)); 665 cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3));
645 666
646 dprintk("%s: pll tune VCA=%d, band=%d, pll=%d\n",__FUNCTION__,state->VCAarg, 667 dprintk("pll tune VCA=%d, band=%d, pll=%d\n", state->VCAarg,
647 state->bandselectarg,state->pllarg); 668 state->bandselectarg, state->pllarg);
648 669
649 return 0; 670 return 0;
650} 671}
651 672
673
674/*
675 * 0x23:
676 * [7:7] = BTI enabled
677 * [6:6] = I2C repeater enabled
678 * [5:5] = I2C repeater start
679 * [0:0] = BTI start
680 */
681
682/* mode == 1 -> i2c-repeater, 0 -> bti */
683static int cx24123_repeater_mode(struct cx24123_state *state, u8 mode, u8 start)
684{
685 u8 r = cx24123_readreg(state, 0x23) & 0x1e;
686 if (mode)
687 r |= (1 << 6) | (start << 5);
688 else
689 r |= (1 << 7) | (start);
690 return cx24123_writereg(state, 0x23, r);
691}
692
652static int cx24123_initfe(struct dvb_frontend* fe) 693static int cx24123_initfe(struct dvb_frontend* fe)
653{ 694{
654 struct cx24123_state *state = fe->demodulator_priv; 695 struct cx24123_state *state = fe->demodulator_priv;
655 int i; 696 int i;
656 697
657 dprintk("%s: init frontend\n",__FUNCTION__); 698 dprintk("init frontend\n");
658 699
659 /* Configure the demod to a good set of defaults */ 700 /* Configure the demod to a good set of defaults */
660 for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++) 701 for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
@@ -664,6 +705,9 @@ static int cx24123_initfe(struct dvb_frontend* fe)
664 if(state->config->lnb_polarity) 705 if(state->config->lnb_polarity)
665 cx24123_writereg(state, 0x32, cx24123_readreg(state, 0x32) | 0x02); 706 cx24123_writereg(state, 0x32, cx24123_readreg(state, 0x32) | 0x02);
666 707
708 if (state->config->dont_use_pll)
709 cx24123_repeater_mode(state, 1, 0);
710
667 return 0; 711 return 0;
668} 712}
669 713
@@ -676,10 +720,10 @@ static int cx24123_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage
676 720
677 switch (voltage) { 721 switch (voltage) {
678 case SEC_VOLTAGE_13: 722 case SEC_VOLTAGE_13:
679 dprintk("%s: setting voltage 13V\n", __FUNCTION__); 723 dprintk("setting voltage 13V\n");
680 return cx24123_writereg(state, 0x29, val & 0x7f); 724 return cx24123_writereg(state, 0x29, val & 0x7f);
681 case SEC_VOLTAGE_18: 725 case SEC_VOLTAGE_18:
682 dprintk("%s: setting voltage 18V\n", __FUNCTION__); 726 dprintk("setting voltage 18V\n");
683 return cx24123_writereg(state, 0x29, val | 0x80); 727 return cx24123_writereg(state, 0x29, val | 0x80);
684 case SEC_VOLTAGE_OFF: 728 case SEC_VOLTAGE_OFF:
685 /* already handled in cx88-dvb */ 729 /* already handled in cx88-dvb */
@@ -697,7 +741,8 @@ static void cx24123_wait_for_diseqc(struct cx24123_state *state)
697 unsigned long timeout = jiffies + msecs_to_jiffies(200); 741 unsigned long timeout = jiffies + msecs_to_jiffies(200);
698 while (!(cx24123_readreg(state, 0x29) & 0x40)) { 742 while (!(cx24123_readreg(state, 0x29) & 0x40)) {
699 if(time_after(jiffies, timeout)) { 743 if(time_after(jiffies, timeout)) {
700 printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__); 744 err("%s: diseqc queue not ready, " \
745 "command may be lost.\n", __func__);
701 break; 746 break;
702 } 747 }
703 msleep(10); 748 msleep(10);
@@ -709,7 +754,7 @@ static int cx24123_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_ma
709 struct cx24123_state *state = fe->demodulator_priv; 754 struct cx24123_state *state = fe->demodulator_priv;
710 int i, val, tone; 755 int i, val, tone;
711 756
712 dprintk("%s:\n",__FUNCTION__); 757 dprintk("\n");
713 758
714 /* stop continuous tone if enabled */ 759 /* stop continuous tone if enabled */
715 tone = cx24123_readreg(state, 0x29); 760 tone = cx24123_readreg(state, 0x29);
@@ -744,7 +789,7 @@ static int cx24123_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
744 struct cx24123_state *state = fe->demodulator_priv; 789 struct cx24123_state *state = fe->demodulator_priv;
745 int val, tone; 790 int val, tone;
746 791
747 dprintk("%s:\n", __FUNCTION__); 792 dprintk("\n");
748 793
749 /* stop continuous tone if enabled */ 794 /* stop continuous tone if enabled */
750 tone = cx24123_readreg(state, 0x29); 795 tone = cx24123_readreg(state, 0x29);
@@ -778,13 +823,21 @@ static int cx24123_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
778static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status) 823static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status)
779{ 824{
780 struct cx24123_state *state = fe->demodulator_priv; 825 struct cx24123_state *state = fe->demodulator_priv;
781
782 int sync = cx24123_readreg(state, 0x14); 826 int sync = cx24123_readreg(state, 0x14);
783 int lock = cx24123_readreg(state, 0x20);
784 827
785 *status = 0; 828 *status = 0;
786 if (lock & 0x01) 829 if (state->config->dont_use_pll) {
787 *status |= FE_HAS_SIGNAL; 830 u32 tun_status = 0;
831 if (fe->ops.tuner_ops.get_status)
832 fe->ops.tuner_ops.get_status(fe, &tun_status);
833 if (tun_status & TUNER_STATUS_LOCKED)
834 *status |= FE_HAS_SIGNAL;
835 } else {
836 int lock = cx24123_readreg(state, 0x20);
837 if (lock & 0x01)
838 *status |= FE_HAS_SIGNAL;
839 }
840
788 if (sync & 0x02) 841 if (sync & 0x02)
789 *status |= FE_HAS_CARRIER; /* Phase locked */ 842 *status |= FE_HAS_CARRIER; /* Phase locked */
790 if (sync & 0x04) 843 if (sync & 0x04)
@@ -803,7 +856,7 @@ static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status)
803 * Configured to return the measurement of errors in blocks, because no UCBLOCKS value 856 * Configured to return the measurement of errors in blocks, because no UCBLOCKS value
804 * is available, so this value doubles up to satisfy both measurements 857 * is available, so this value doubles up to satisfy both measurements
805 */ 858 */
806static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber) 859static int cx24123_read_ber(struct dvb_frontend *fe, u32 *ber)
807{ 860{
808 struct cx24123_state *state = fe->demodulator_priv; 861 struct cx24123_state *state = fe->demodulator_priv;
809 862
@@ -813,23 +866,24 @@ static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber)
813 (cx24123_readreg(state, 0x1d) << 8 | 866 (cx24123_readreg(state, 0x1d) << 8 |
814 cx24123_readreg(state, 0x1e)); 867 cx24123_readreg(state, 0x1e));
815 868
816 dprintk("%s: BER = %d\n",__FUNCTION__,*ber); 869 dprintk("BER = %d\n", *ber);
817 870
818 return 0; 871 return 0;
819} 872}
820 873
821static int cx24123_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 874static int cx24123_read_signal_strength(struct dvb_frontend *fe,
875 u16 *signal_strength)
822{ 876{
823 struct cx24123_state *state = fe->demodulator_priv; 877 struct cx24123_state *state = fe->demodulator_priv;
824 878
825 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */ 879 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */
826 880
827 dprintk("%s: Signal strength = %d\n",__FUNCTION__,*signal_strength); 881 dprintk("Signal strength = %d\n", *signal_strength);
828 882
829 return 0; 883 return 0;
830} 884}
831 885
832static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr) 886static int cx24123_read_snr(struct dvb_frontend *fe, u16 *snr)
833{ 887{
834 struct cx24123_state *state = fe->demodulator_priv; 888 struct cx24123_state *state = fe->demodulator_priv;
835 889
@@ -838,16 +892,17 @@ static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr)
838 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) | 892 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) |
839 (u16)cx24123_readreg(state, 0x19)); 893 (u16)cx24123_readreg(state, 0x19));
840 894
841 dprintk("%s: read S/N index = %d\n",__FUNCTION__,*snr); 895 dprintk("read S/N index = %d\n", *snr);
842 896
843 return 0; 897 return 0;
844} 898}
845 899
846static int cx24123_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 900static int cx24123_set_frontend(struct dvb_frontend *fe,
901 struct dvb_frontend_parameters *p)
847{ 902{
848 struct cx24123_state *state = fe->demodulator_priv; 903 struct cx24123_state *state = fe->demodulator_priv;
849 904
850 dprintk("%s: set_frontend\n",__FUNCTION__); 905 dprintk("\n");
851 906
852 if (state->config->set_ts_params) 907 if (state->config->set_ts_params)
853 state->config->set_ts_params(fe, 0); 908 state->config->set_ts_params(fe, 0);
@@ -858,13 +913,22 @@ static int cx24123_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
858 cx24123_set_inversion(state, p->inversion); 913 cx24123_set_inversion(state, p->inversion);
859 cx24123_set_fec(state, p->u.qpsk.fec_inner); 914 cx24123_set_fec(state, p->u.qpsk.fec_inner);
860 cx24123_set_symbolrate(state, p->u.qpsk.symbol_rate); 915 cx24123_set_symbolrate(state, p->u.qpsk.symbol_rate);
861 cx24123_pll_tune(fe, p); 916
917 if (!state->config->dont_use_pll)
918 cx24123_pll_tune(fe, p);
919 else if (fe->ops.tuner_ops.set_params)
920 fe->ops.tuner_ops.set_params(fe, p);
921 else
922 err("it seems I don't have a tuner...");
862 923
863 /* Enable automatic aquisition and reset cycle */ 924 /* Enable automatic aquisition and reset cycle */
864 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07)); 925 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07));
865 cx24123_writereg(state, 0x00, 0x10); 926 cx24123_writereg(state, 0x00, 0x10);
866 cx24123_writereg(state, 0x00, 0); 927 cx24123_writereg(state, 0x00, 0);
867 928
929 if (state->config->agc_callback)
930 state->config->agc_callback(fe);
931
868 return 0; 932 return 0;
869} 933}
870 934
@@ -872,14 +936,14 @@ static int cx24123_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
872{ 936{
873 struct cx24123_state *state = fe->demodulator_priv; 937 struct cx24123_state *state = fe->demodulator_priv;
874 938
875 dprintk("%s: get_frontend\n",__FUNCTION__); 939 dprintk("\n");
876 940
877 if (cx24123_get_inversion(state, &p->inversion) != 0) { 941 if (cx24123_get_inversion(state, &p->inversion) != 0) {
878 printk("%s: Failed to get inversion status\n",__FUNCTION__); 942 err("%s: Failed to get inversion status\n", __func__);
879 return -EREMOTEIO; 943 return -EREMOTEIO;
880 } 944 }
881 if (cx24123_get_fec(state, &p->u.qpsk.fec_inner) != 0) { 945 if (cx24123_get_fec(state, &p->u.qpsk.fec_inner) != 0) {
882 printk("%s: Failed to get fec status\n",__FUNCTION__); 946 err("%s: Failed to get fec status\n", __func__);
883 return -EREMOTEIO; 947 return -EREMOTEIO;
884 } 948 }
885 p->frequency = state->currentfreq; 949 p->frequency = state->currentfreq;
@@ -900,13 +964,13 @@ static int cx24123_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
900 964
901 switch (tone) { 965 switch (tone) {
902 case SEC_TONE_ON: 966 case SEC_TONE_ON:
903 dprintk("%s: setting tone on\n", __FUNCTION__); 967 dprintk("setting tone on\n");
904 return cx24123_writereg(state, 0x29, val | 0x10); 968 return cx24123_writereg(state, 0x29, val | 0x10);
905 case SEC_TONE_OFF: 969 case SEC_TONE_OFF:
906 dprintk("%s: setting tone off\n",__FUNCTION__); 970 dprintk("setting tone off\n");
907 return cx24123_writereg(state, 0x29, val & 0xef); 971 return cx24123_writereg(state, 0x29, val & 0xef);
908 default: 972 default:
909 printk("%s: CASE reached default with tone=%d\n", __FUNCTION__, tone); 973 err("CASE reached default with tone=%d\n", tone);
910 return -EINVAL; 974 return -EINVAL;
911 } 975 }
912 976
@@ -939,47 +1003,86 @@ static int cx24123_get_algo(struct dvb_frontend *fe)
939static void cx24123_release(struct dvb_frontend* fe) 1003static void cx24123_release(struct dvb_frontend* fe)
940{ 1004{
941 struct cx24123_state* state = fe->demodulator_priv; 1005 struct cx24123_state* state = fe->demodulator_priv;
942 dprintk("%s\n",__FUNCTION__); 1006 dprintk("\n");
1007 i2c_del_adapter(&state->tuner_i2c_adapter);
943 kfree(state); 1008 kfree(state);
944} 1009}
945 1010
1011static int cx24123_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap,
1012 struct i2c_msg msg[], int num)
1013{
1014 struct cx24123_state *state = i2c_get_adapdata(i2c_adap);
1015 /* this repeater closes after the first stop */
1016 cx24123_repeater_mode(state, 1, 1);
1017 return i2c_transfer(state->i2c, msg, num);
1018}
1019
1020static u32 cx24123_tuner_i2c_func(struct i2c_adapter *adapter)
1021{
1022 return I2C_FUNC_I2C;
1023}
1024
1025static struct i2c_algorithm cx24123_tuner_i2c_algo = {
1026 .master_xfer = cx24123_tuner_i2c_tuner_xfer,
1027 .functionality = cx24123_tuner_i2c_func,
1028};
1029
1030struct i2c_adapter *
1031 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe)
1032{
1033 struct cx24123_state *state = fe->demodulator_priv;
1034 return &state->tuner_i2c_adapter;
1035}
1036EXPORT_SYMBOL(cx24123_get_tuner_i2c_adapter);
1037
946static struct dvb_frontend_ops cx24123_ops; 1038static struct dvb_frontend_ops cx24123_ops;
947 1039
948struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 1040struct dvb_frontend* cx24123_attach(const struct cx24123_config* config,
949 struct i2c_adapter* i2c) 1041 struct i2c_adapter* i2c)
950{ 1042{
951 struct cx24123_state* state = NULL; 1043 struct cx24123_state *state =
952 int ret; 1044 kzalloc(sizeof(struct cx24123_state), GFP_KERNEL);
953
954 dprintk("%s\n",__FUNCTION__);
955 1045
1046 dprintk("\n");
956 /* allocate memory for the internal state */ 1047 /* allocate memory for the internal state */
957 state = kmalloc(sizeof(struct cx24123_state), GFP_KERNEL);
958 if (state == NULL) { 1048 if (state == NULL) {
959 printk("Unable to kmalloc\n"); 1049 err("Unable to kmalloc\n");
960 goto error; 1050 goto error;
961 } 1051 }
962 1052
963 /* setup the state */ 1053 /* setup the state */
964 state->config = config; 1054 state->config = config;
965 state->i2c = i2c; 1055 state->i2c = i2c;
966 state->VCAarg = 0;
967 state->VGAarg = 0;
968 state->bandselectarg = 0;
969 state->pllarg = 0;
970 state->currentfreq = 0;
971 state->currentsymbolrate = 0;
972 1056
973 /* check if the demod is there */ 1057 /* check if the demod is there */
974 ret = cx24123_readreg(state, 0x00); 1058 state->demod_rev = cx24123_readreg(state, 0x00);
975 if ((ret != 0xd1) && (ret != 0xe1)) { 1059 switch (state->demod_rev) {
976 printk("Version != d1 or e1\n"); 1060 case 0xe1: info("detected CX24123C\n"); break;
1061 case 0xd1: info("detected CX24123\n"); break;
1062 default:
1063 err("wrong demod revision: %x\n", state->demod_rev);
977 goto error; 1064 goto error;
978 } 1065 }
979 1066
980 /* create dvb_frontend */ 1067 /* create dvb_frontend */
981 memcpy(&state->frontend.ops, &cx24123_ops, sizeof(struct dvb_frontend_ops)); 1068 memcpy(&state->frontend.ops, &cx24123_ops, sizeof(struct dvb_frontend_ops));
982 state->frontend.demodulator_priv = state; 1069 state->frontend.demodulator_priv = state;
1070
1071 /* create tuner i2c adapter */
1072 if (config->dont_use_pll)
1073 cx24123_repeater_mode(state, 1, 0);
1074
1075 strncpy(state->tuner_i2c_adapter.name,
1076 "CX24123 tuner I2C bus", I2C_NAME_SIZE);
1077 state->tuner_i2c_adapter.class = I2C_CLASS_TV_DIGITAL,
1078 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo;
1079 state->tuner_i2c_adapter.algo_data = NULL;
1080 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
1081 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) {
1082 err("tuner i2c bus could not be initialized\n");
1083 goto error;
1084 }
1085
983 return &state->frontend; 1086 return &state->frontend;
984 1087
985error: 1088error:
@@ -1029,7 +1132,8 @@ MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
1029module_param(force_band, int, 0644); 1132module_param(force_band, int, 0644);
1030MODULE_PARM_DESC(force_band, "Force a specific band select (1-9, default:off)."); 1133MODULE_PARM_DESC(force_band, "Force a specific band select (1-9, default:off).");
1031 1134
1032MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24123/cx24109 hardware"); 1135MODULE_DESCRIPTION("DVB Frontend module for Conexant " \
1136 "CX24123/CX24109/CX24113 hardware");
1033MODULE_AUTHOR("Steven Toth"); 1137MODULE_AUTHOR("Steven Toth");
1034MODULE_LICENSE("GPL"); 1138MODULE_LICENSE("GPL");
1035 1139
diff --git a/drivers/media/dvb/frontends/cx24123.h b/drivers/media/dvb/frontends/cx24123.h
index 84f9e4f5c15e..81ebc3d2f19f 100644
--- a/drivers/media/dvb/frontends/cx24123.h
+++ b/drivers/media/dvb/frontends/cx24123.h
@@ -33,16 +33,27 @@ struct cx24123_config
33 33
34 /* 0 = LNB voltage normal, 1 = LNB voltage inverted */ 34 /* 0 = LNB voltage normal, 1 = LNB voltage inverted */
35 int lnb_polarity; 35 int lnb_polarity;
36
37 /* this device has another tuner */
38 u8 dont_use_pll;
39 void (*agc_callback) (struct dvb_frontend *);
36}; 40};
37 41
38#if defined(CONFIG_DVB_CX24123) || (defined(CONFIG_DVB_CX24123_MODULE) && defined(MODULE)) 42#if defined(CONFIG_DVB_CX24123) || (defined(CONFIG_DVB_CX24123_MODULE) && defined(MODULE))
39extern struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 43extern struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
40 struct i2c_adapter* i2c); 44 struct i2c_adapter *i2c);
45extern struct i2c_adapter *cx24123_get_tuner_i2c_adapter(struct dvb_frontend *);
41#else 46#else
42static inline struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 47static inline struct dvb_frontend *cx24123_attach(
43 struct i2c_adapter* i2c) 48 const struct cx24123_config *config, struct i2c_adapter *i2c)
49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL;
52}
53static struct i2c_adapter *
54 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe)
44{ 55{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL; 57 return NULL;
47} 58}
48#endif // CONFIG_DVB_CX24123 59#endif // CONFIG_DVB_CX24123