2 Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver
4 Copyright (C) 2006-2008 Steven Toth <stoth@hauppauge.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Updates by Darron Broad 2007.
26 * Added diseqc support.
27 * Added corrected signal strength support.
30 * Sync with legacy version.
33 /* Updates by Igor Liplianin
36 * Fixed locking on high symbol rates (>30000).
39 #include <linux/slab.h>
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <linux/moduleparam.h>
43 #include <linux/init.h>
44 #include <linux/firmware.h>
46 #include "dvb_frontend.h"
50 * Fetch firmware in the following manner.
53 * wget ftp://167.206.143.11/outgoing/Oxford/88x_2_117_24275_1_INF.zip
54 * unzip 88x_2_117_24275_1_INF.zip
55 * dd if=Driver88/hcw88bda.sys of=dvb-fe-cx24116.fw skip=81768 bs=1 count=32522
57 #define CX24116_DEFAULT_FIRMWARE "dvb-fe-cx24116.fw"
58 #define CX24116_SEARCH_RANGE_KHZ 5000
60 /* registers (TO BE COMPLETED) */
61 #define CX24116_REG_SIGNAL (0xd5)
64 #define CX24116_ARGLEN (0x1e)
66 /* arg offset for DiSEqC */
67 #define CX24116_DISEQC_BURST (1)
68 #define CX24116_DISEQC_ARG2_2 (2) /* unknown value=2 */
69 #define CX24116_DISEQC_ARG3_0 (3) /* unknown value=0 */
70 #define CX24116_DISEQC_ARG4_0 (4) /* unknown value=0 */
71 #define CX24116_DISEQC_MSGLEN (5)
72 #define CX24116_DISEQC_MSGOFS (6)
75 #define CX24116_DISEQC_MINI_A (0)
76 #define CX24116_DISEQC_MINI_B (1)
79 #define dprintk(args...) \
81 if (debug) printk ("cx24116: " args); \
86 CMD_INIT_CMD10
= 0x10,
87 CMD_TUNEREQUEST
= 0x11,
88 CMD_INIT_CMD13
= 0x13,
89 CMD_INIT_CMD14
= 0x14,
90 CMD_SEND_DISEQC
= 0x21,
91 CMD_SET_TONEPRE
= 0x22,
95 /* The Demod/Tuner can't easily provide these, we cache them */
100 fe_spectral_inversion_t inversion
;
103 fe_modulation_t modulation
;
111 /* Basic commands that are sent to the firmware */
115 u8 args
[CX24116_ARGLEN
];
120 struct i2c_adapter
* i2c
;
121 const struct cx24116_config
* config
;
123 struct dvb_frontend frontend
;
125 struct cx24116_tuning dcur
;
126 struct cx24116_tuning dnxt
;
132 static int cx24116_writereg(struct cx24116_state
* state
, int reg
, int data
)
134 u8 buf
[] = { reg
, data
};
135 struct i2c_msg msg
= { .addr
= state
->config
->demod_address
,
136 .flags
= 0, .buf
= buf
, .len
= 2 };
140 printk("cx24116: %s: write reg 0x%02x, value 0x%02x\n",
143 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) != 1) {
144 printk("%s: writereg error(err == %i, reg == 0x%02x,"
145 " value == 0x%02x)\n", __func__
, err
, reg
, data
);
152 /* Bulk byte writes to a single I2C address, for 32k firmware load */
153 static int cx24116_writeregN(struct cx24116_state
* state
, int reg
, u8
*data
, u16 len
)
155 int ret
= -EREMOTEIO
;
159 buf
= kmalloc(len
+ 1, GFP_KERNEL
);
161 printk("Unable to kmalloc\n");
167 memcpy(buf
+ 1, data
, len
);
169 msg
.addr
= state
->config
->demod_address
;
175 printk("cx24116: %s: write regN 0x%02x, len = %d\n",
178 if ((ret
= i2c_transfer(state
->i2c
, &msg
, 1)) != 1) {
179 printk("%s: writereg error(err == %i, reg == 0x%02x\n",
190 static int cx24116_readreg(struct cx24116_state
* state
, u8 reg
)
195 struct i2c_msg msg
[] = {
196 { .addr
= state
->config
->demod_address
, .flags
= 0, .buf
= b0
, .len
= 1 },
197 { .addr
= state
->config
->demod_address
, .flags
= I2C_M_RD
, .buf
= b1
, .len
= 1 }
200 ret
= i2c_transfer(state
->i2c
, msg
, 2);
203 printk("%s: reg=0x%x (error=%d)\n", __func__
, reg
, ret
);
208 printk("cx24116: read reg 0x%02x, value 0x%02x\n",reg
, b1
[0]);
213 static int cx24116_set_inversion(struct cx24116_state
* state
, fe_spectral_inversion_t inversion
)
215 dprintk("%s(%d)\n", __func__
, inversion
);
219 state
->dnxt
.inversion_val
= 0x00;
222 state
->dnxt
.inversion_val
= 0x04;
225 state
->dnxt
.inversion_val
= 0x0C;
231 state
->dnxt
.inversion
= inversion
;
236 /* A table of modulation, fec and configuration bytes for the demod.
237 * Not all S2 mmodulation schemes are support and not all rates with
238 * a scheme are support. Especially, no auto detect when in S2 mode.
240 struct cx24116_modfec
{
241 fe_modulation_t modulation
;
243 u8 mask
; /* In DVBS mode this is used to autodetect */
244 u8 val
; /* Passed to the firmware to indicate mode selection */
245 } CX24116_MODFEC_MODES
[] = {
246 /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
247 { QPSK
, FEC_NONE
, 0xfe, 0x30 },
248 { QPSK
, FEC_1_2
, 0x02, 0x2e },
249 { QPSK
, FEC_2_3
, 0x04, 0x2f },
250 { QPSK
, FEC_3_4
, 0x08, 0x30 },
251 { QPSK
, FEC_4_5
, 0xfe, 0x30 },
252 { QPSK
, FEC_5_6
, 0x20, 0x31 },
253 { QPSK
, FEC_6_7
, 0xfe, 0x30 },
254 { QPSK
, FEC_7_8
, 0x80, 0x32 },
255 { QPSK
, FEC_8_9
, 0xfe, 0x30 },
256 { QPSK
, FEC_AUTO
, 0xfe, 0x30 },
258 { NBC_QPSK
, FEC_1_2
, 0x00, 0x04 },
259 { NBC_QPSK
, FEC_3_5
, 0x00, 0x05 },
260 { NBC_QPSK
, FEC_2_3
, 0x00, 0x06 },
261 { NBC_QPSK
, FEC_3_4
, 0x00, 0x07 },
262 { NBC_QPSK
, FEC_4_5
, 0x00, 0x08 },
263 { NBC_QPSK
, FEC_5_6
, 0x00, 0x09 },
264 { NBC_QPSK
, FEC_8_9
, 0x00, 0x0a },
265 { NBC_QPSK
, FEC_9_10
, 0x00, 0x0b },
267 { _8PSK
, FEC_3_5
, 0x00, 0x0c },
268 { _8PSK
, FEC_2_3
, 0x00, 0x0d },
269 { _8PSK
, FEC_3_4
, 0x00, 0x0e },
270 { _8PSK
, FEC_5_6
, 0x00, 0x0f },
271 { _8PSK
, FEC_9_10
, 0x00, 0x11 },
274 static int cx24116_lookup_fecmod(struct cx24116_state
* state
,
275 fe_modulation_t m
, fe_code_rate_t f
)
277 int i
, ret
= -EOPNOTSUPP
;
279 for(i
=0 ; i
< sizeof(CX24116_MODFEC_MODES
) / sizeof(struct cx24116_modfec
) ; i
++)
281 if( (m
== CX24116_MODFEC_MODES
[i
].modulation
) &&
282 (f
== CX24116_MODFEC_MODES
[i
].fec
) )
292 static int cx24116_set_fec(struct cx24116_state
* state
, fe_modulation_t mod
, fe_code_rate_t fec
)
295 dprintk("%s()\n", __func__
);
297 ret
= cx24116_lookup_fecmod(state
, mod
, fec
);
302 state
->dnxt
.fec_val
= CX24116_MODFEC_MODES
[ret
].val
;
303 state
->dnxt
.fec_mask
= CX24116_MODFEC_MODES
[ret
].mask
;
304 dprintk("%s() fec_val/mask = 0x%02x/0x%02x\n", __func__
,
305 state
->dnxt
.fec_val
, state
->dnxt
.fec_mask
);
310 static int cx24116_set_symbolrate(struct cx24116_state
* state
, u32 rate
)
314 dprintk("%s()\n", __func__
);
316 state
->dnxt
.symbol_rate
= rate
;
318 dprintk("%s() symbol_rate = %d\n", __func__
, state
->dnxt
.symbol_rate
);
320 /* check if symbol rate is within limits */
321 if ((state
->dnxt
.symbol_rate
> state
->frontend
.ops
.info
.symbol_rate_max
) ||
322 (state
->dnxt
.symbol_rate
< state
->frontend
.ops
.info
.symbol_rate_min
))
328 static int cx24116_load_firmware (struct dvb_frontend
* fe
, const struct firmware
*fw
);
330 static int cx24116_firmware_ondemand(struct dvb_frontend
* fe
)
332 struct cx24116_state
*state
= fe
->demodulator_priv
;
333 const struct firmware
*fw
;
336 dprintk("%s()\n",__func__
);
338 if (cx24116_readreg(state
, 0x20) > 0)
341 if (state
->skip_fw_load
)
345 /* request the firmware, this will block until someone uploads it */
346 printk("%s: Waiting for firmware upload (%s)...\n", __func__
, CX24116_DEFAULT_FIRMWARE
);
347 ret
= request_firmware(&fw
, CX24116_DEFAULT_FIRMWARE
, &state
->i2c
->dev
);
348 printk("%s: Waiting for firmware upload(2)...\n", __func__
);
350 printk("%s: No firmware uploaded (timeout or file not found?)\n", __func__
);
354 /* Make sure we don't recurse back through here during loading */
355 state
->skip_fw_load
= 1;
357 ret
= cx24116_load_firmware(fe
, fw
);
359 printk("%s: Writing firmware to device failed\n", __func__
);
361 release_firmware(fw
);
363 printk("%s: Firmware upload %s\n", __func__
, ret
== 0 ? "complete" : "failed");
365 /* Ensure firmware is always loaded if required */
366 state
->skip_fw_load
= 0;
372 /* Take a basic firmware command structure, format it and forward it for processing */
373 static int cx24116_cmd_execute(struct dvb_frontend
* fe
, struct cx24116_cmd
*cmd
)
375 struct cx24116_state
*state
= fe
->demodulator_priv
;
378 dprintk("%s()\n", __func__
);
380 /* Load the firmware if required */
381 if ( (ret
= cx24116_firmware_ondemand(fe
)) != 0)
383 printk("%s(): Unable initialise the firmware\n", __func__
);
387 /* Write the command */
388 for(i
= 0; i
< cmd
->len
; i
++)
390 dprintk("%s: 0x%02x == 0x%02x\n", __func__
, i
, cmd
->args
[i
]);
391 cx24116_writereg(state
, i
, cmd
->args
[i
]);
394 /* Start execution and wait for cmd to terminate */
395 cx24116_writereg(state
, 0x1f, 0x01);
396 while( cx24116_readreg(state
, 0x1f) )
401 /* Avoid looping forever if the firmware does no respond */
402 printk("%s() Firmware not responding\n", __func__
);
409 static int cx24116_load_firmware (struct dvb_frontend
* fe
, const struct firmware
*fw
)
411 struct cx24116_state
* state
= fe
->demodulator_priv
;
412 struct cx24116_cmd cmd
;
415 dprintk("%s\n", __func__
);
416 dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n"
420 ,fw
->data
[ fw
->size
-2 ]
421 ,fw
->data
[ fw
->size
-1 ]
424 /* Toggle 88x SRST pin to reset demod */
425 if (state
->config
->reset_device
)
426 state
->config
->reset_device(fe
);
428 /* Begin the firmware load process */
429 /* Prepare the demod, load the firmware, cleanup after load */
430 cx24116_writereg(state
, 0xF1, 0x08);
431 cx24116_writereg(state
, 0xF2, cx24116_readreg(state
, 0xF2) | 0x03);
432 cx24116_writereg(state
, 0xF3, 0x46);
433 cx24116_writereg(state
, 0xF9, 0x00);
435 cx24116_writereg(state
, 0xF0, 0x03);
436 cx24116_writereg(state
, 0xF4, 0x81);
437 cx24116_writereg(state
, 0xF5, 0x00);
438 cx24116_writereg(state
, 0xF6, 0x00);
440 /* write the entire firmware as one transaction */
441 cx24116_writeregN(state
, 0xF7, fw
->data
, fw
->size
);
443 cx24116_writereg(state
, 0xF4, 0x10);
444 cx24116_writereg(state
, 0xF0, 0x00);
445 cx24116_writereg(state
, 0xF8, 0x06);
447 /* Firmware CMD 10: Chip config? */
448 cmd
.args
[0x00] = CMD_INIT_CMD10
;
449 cmd
.args
[0x01] = 0x05;
450 cmd
.args
[0x02] = 0xdc;
451 cmd
.args
[0x03] = 0xda;
452 cmd
.args
[0x04] = 0xae;
453 cmd
.args
[0x05] = 0xaa;
454 cmd
.args
[0x06] = 0x04;
455 cmd
.args
[0x07] = 0x9d;
456 cmd
.args
[0x08] = 0xfc;
457 cmd
.args
[0x09] = 0x06;
459 ret
= cx24116_cmd_execute(fe
, &cmd
);
463 cx24116_writereg(state
, 0x9d, 0x00);
465 /* Firmware CMD 14: Unknown */
466 cmd
.args
[0x00] = CMD_INIT_CMD14
;
467 cmd
.args
[0x01] = 0x00;
468 cmd
.args
[0x02] = 0x00;
470 ret
= cx24116_cmd_execute(fe
, &cmd
);
474 cx24116_writereg(state
, 0xe5, 0x00);
476 /* Firmware CMD 13: Unknown - Firmware config? */
477 cmd
.args
[0x00] = CMD_INIT_CMD13
;
478 cmd
.args
[0x01] = 0x01;
479 cmd
.args
[0x02] = 0x75;
480 cmd
.args
[0x03] = 0x00;
481 if (state
->config
->mpg_clk_pos_pol
)
482 cmd
.args
[0x04] = state
->config
->mpg_clk_pos_pol
;
484 cmd
.args
[0x04] = 0x02;
485 cmd
.args
[0x05] = 0x00;
487 ret
= cx24116_cmd_execute(fe
, &cmd
);
494 static int cx24116_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
496 /* The isl6421 module will override this function in the fops. */
497 dprintk("%s() This should never appear if the isl6421 module is loaded correctly\n",__func__
);
502 static int cx24116_read_status(struct dvb_frontend
* fe
, fe_status_t
* status
)
504 struct cx24116_state
*state
= fe
->demodulator_priv
;
506 int lock
= cx24116_readreg(state
, 0x9d);
508 dprintk("%s: status = 0x%02x\n", __func__
, lock
);
513 *status
|= FE_HAS_SIGNAL
;
515 *status
|= FE_HAS_CARRIER
;
517 *status
|= FE_HAS_VITERBI
;
519 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
524 /* TODO: Not clear how we do this */
525 static int cx24116_read_ber(struct dvb_frontend
* fe
, u32
* ber
)
527 //struct cx24116_state *state = fe->demodulator_priv;
528 dprintk("%s()\n", __func__
);
534 /* Signal strength (0..100)% = (sig & 0xf0) * 10 + (sig & 0x0f) * 10 / 16 */
535 static int cx24116_read_signal_strength(struct dvb_frontend
* fe
, u16
* signal_strength
)
537 struct cx24116_state
*state
= fe
->demodulator_priv
;
539 static const u32 strength_tab
[] = { /* 10 x Table (rounded up) */
540 0x00000,0x0199A,0x03333,0x04ccD,0x06667,0x08000,0x0999A,0x0b333,0x0cccD,0x0e667,
541 0x10000,0x1199A,0x13333,0x14ccD,0x16667,0x18000 };
543 dprintk("%s()\n", __func__
);
545 strength_reg
= cx24116_readreg(state
, CX24116_REG_SIGNAL
);
547 if(strength_reg
< 0xa0)
548 *signal_strength
= strength_tab
[ ( strength_reg
& 0xf0 ) >> 4 ] +
549 ( strength_tab
[ ( strength_reg
& 0x0f ) ] >> 4 );
551 *signal_strength
= 0xffff;
553 dprintk("%s: Signal strength (raw / cooked) = (0x%02x / 0x%04x)\n",
554 __func__
,strength_reg
,*signal_strength
);
559 /* TODO: Not clear how we do this */
560 static int cx24116_read_snr(struct dvb_frontend
* fe
, u16
* snr
)
562 //struct cx24116_state *state = fe->demodulator_priv;
563 dprintk("%s()\n", __func__
);
569 /* TODO: Not clear how we do this */
570 static int cx24116_read_ucblocks(struct dvb_frontend
* fe
, u32
* ucblocks
)
572 //struct cx24116_state *state = fe->demodulator_priv;
573 dprintk("%s()\n", __func__
);
579 /* Overwrite the current tuning params, we are about to tune */
580 static void cx24116_clone_params(struct dvb_frontend
* fe
)
582 struct cx24116_state
*state
= fe
->demodulator_priv
;
583 memcpy(&state
->dcur
, &state
->dnxt
, sizeof(state
->dcur
));
586 static int cx24116_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
588 struct cx24116_cmd cmd
;
591 dprintk("%s(%d)\n", __func__
, tone
);
592 if ( (tone
!= SEC_TONE_ON
) && (tone
!= SEC_TONE_OFF
) ) {
593 printk("%s: Invalid, tone=%d\n", __func__
, tone
);
597 /* This is always done before the tone is set */
598 cmd
.args
[0x00] = CMD_SET_TONEPRE
;
599 cmd
.args
[0x01] = 0x00;
601 ret
= cx24116_cmd_execute(fe
, &cmd
);
605 /* Now we set the tone */
606 cmd
.args
[0x00] = CMD_SET_TONE
;
607 cmd
.args
[0x01] = 0x00;
608 cmd
.args
[0x02] = 0x00;
612 dprintk("%s: setting tone on\n", __func__
);
613 cmd
.args
[0x03] = 0x01;
616 dprintk("%s: setting tone off\n",__func__
);
617 cmd
.args
[0x03] = 0x00;
622 return cx24116_cmd_execute(fe
, &cmd
);
625 /* Initialise DiSEqC */
626 static int cx24116_diseqc_init(struct dvb_frontend
* fe
)
628 struct cx24116_state
*state
= fe
->demodulator_priv
;
630 /* Default DiSEqC burst state */
631 state
->burst
= CX24116_DISEQC_MINI_A
;
636 /* Send DiSEqC message with derived burst (hack) || previous burst */
637 static int cx24116_send_diseqc_msg(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
*d
)
639 struct cx24116_state
*state
= fe
->demodulator_priv
;
640 struct cx24116_cmd cmd
;
643 /* Dump DiSEqC message */
645 printk("cx24116: %s(", __func__
);
646 for(i
= 0 ; i
< d
->msg_len
;) {
647 printk("0x%02x", d
->msg
[i
]);
654 if(d
->msg_len
> (CX24116_ARGLEN
- CX24116_DISEQC_MSGOFS
))
657 cmd
.args
[0x00] = CMD_SEND_DISEQC
;
658 cmd
.args
[CX24116_DISEQC_ARG2_2
] = 0x02;
659 cmd
.args
[CX24116_DISEQC_ARG3_0
] = 0x00;
660 cmd
.args
[CX24116_DISEQC_ARG4_0
] = 0x00;
663 for (i
= 0; i
< d
->msg_len
; i
++)
664 cmd
.args
[CX24116_DISEQC_MSGOFS
+ i
] = d
->msg
[i
];
666 /* Hack: Derive burst from command else use previous burst */
667 if(d
->msg_len
>= 4 && d
->msg
[2] == 0x38)
668 cmd
.args
[CX24116_DISEQC_BURST
] = (d
->msg
[3] >> 2) & 1;
670 cmd
.args
[CX24116_DISEQC_BURST
] = state
->burst
;
672 cmd
.args
[CX24116_DISEQC_MSGLEN
] = d
->msg_len
;
673 cmd
.len
= CX24116_DISEQC_MSGOFS
+ d
->msg_len
;
675 ret
= cx24116_cmd_execute(fe
, &cmd
);
677 /* Firmware command duration is unknown, so guess...
687 msleep( (cmd
.args
[CX24116_DISEQC_MSGLEN
] << 4) + 60 );
692 /* Send DiSEqC burst */
693 static int cx24116_diseqc_send_burst(struct dvb_frontend
* fe
, fe_sec_mini_cmd_t burst
)
695 struct cx24116_state
*state
= fe
->demodulator_priv
;
696 struct cx24116_cmd cmd
;
699 dprintk("%s(%d)\n",__func__
,(int)burst
);
701 cmd
.args
[0x00] = CMD_SEND_DISEQC
;
702 cmd
.args
[CX24116_DISEQC_ARG2_2
] = 0x02;
703 cmd
.args
[CX24116_DISEQC_ARG3_0
] = 0x00;
704 cmd
.args
[CX24116_DISEQC_ARG4_0
] = 0x00;
706 if (burst
== SEC_MINI_A
)
707 cmd
.args
[CX24116_DISEQC_BURST
] = CX24116_DISEQC_MINI_A
;
708 else if(burst
== SEC_MINI_B
)
709 cmd
.args
[CX24116_DISEQC_BURST
] = CX24116_DISEQC_MINI_B
;
713 /* Cache as previous burst state */
714 state
->burst
= cmd
.args
[CX24116_DISEQC_BURST
];
716 cmd
.args
[CX24116_DISEQC_MSGLEN
] = 0x00;
717 cmd
.len
= CX24116_DISEQC_MSGOFS
;
719 ret
= cx24116_cmd_execute(fe
, &cmd
);
721 /* Firmware command duration is unknown, so guess... */
728 static void cx24116_release(struct dvb_frontend
* fe
)
730 struct cx24116_state
* state
= fe
->demodulator_priv
;
731 dprintk("%s\n",__func__
);
735 static struct dvb_frontend_ops cx24116_ops
;
737 struct dvb_frontend
* cx24116_attach(const struct cx24116_config
* config
,
738 struct i2c_adapter
* i2c
)
740 struct cx24116_state
* state
= NULL
;
743 dprintk("%s\n",__func__
);
745 /* allocate memory for the internal state */
746 state
= kmalloc(sizeof(struct cx24116_state
), GFP_KERNEL
);
748 printk("Unable to kmalloc\n");
752 /* setup the state */
753 memset(state
, 0, sizeof(struct cx24116_state
));
755 state
->config
= config
;
758 /* check if the demod is present */
759 ret
= (cx24116_readreg(state
, 0xFF) << 8) | cx24116_readreg(state
, 0xFE);
761 printk("Invalid probe, probably not a CX24116 device\n");
765 /* create dvb_frontend */
766 memcpy(&state
->frontend
.ops
, &cx24116_ops
, sizeof(struct dvb_frontend_ops
));
767 state
->frontend
.demodulator_priv
= state
;
768 return &state
->frontend
;
776 static int cx24116_get_params(struct dvb_frontend
* fe
)
778 struct cx24116_state
*state
= fe
->demodulator_priv
;
779 struct tv_frontend_properties
*cache
= &fe
->tv_property_cache
;
781 dprintk("%s()\n",__func__
);
783 cache
->frequency
= state
->dcur
.frequency
;
784 cache
->inversion
= state
->dcur
.inversion
;
785 cache
->modulation
= state
->dcur
.modulation
;
786 cache
->fec_inner
= state
->dcur
.fec
;
787 cache
->symbol_rate
= state
->dcur
.symbol_rate
;
792 static int cx24116_initfe(struct dvb_frontend
* fe
)
794 dprintk("%s()\n",__func__
);
796 return cx24116_diseqc_init(fe
);
799 static int cx24116_set_property(struct dvb_frontend
*fe
, tv_property_t
* tvp
)
801 dprintk("%s(..)\n", __func__
);
805 static int cx24116_set_params(struct dvb_frontend
*fe
)
807 dprintk("%s(..) We were notified that a tune request may occur\n", __func__
);
811 /* dvb-core told us to tune, the tv property cache will be complete,
812 * it's safe for is to pull values and use them for tuning purposes.
814 static int cx24116_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
816 struct cx24116_state
*state
= fe
->demodulator_priv
;
817 struct tv_frontend_properties
*c
= &fe
->tv_property_cache
;
818 struct cx24116_cmd cmd
;
819 fe_status_t tunerstat
;
820 int ret
, above30msps
;
823 dprintk("%s()\n",__func__
);
825 state
->dnxt
.modulation
= c
->modulation
;
826 state
->dnxt
.frequency
= c
->frequency
;
828 if ((ret
= cx24116_set_inversion(state
, c
->inversion
)) != 0)
831 if ((ret
= cx24116_set_fec(state
, c
->modulation
, c
->fec_inner
)) != 0)
834 if ((ret
= cx24116_set_symbolrate(state
, c
->symbol_rate
)) != 0)
837 /* discard the 'current' tuning parameters and prepare to tune */
838 cx24116_clone_params(fe
);
840 dprintk("%s: frequency = %d\n", __func__
, state
->dcur
.frequency
);
841 dprintk("%s: symbol_rate = %d\n", __func__
, state
->dcur
.symbol_rate
);
842 dprintk("%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__
,
843 state
->dcur
.fec
, state
->dcur
.fec_mask
, state
->dcur
.fec_val
);
844 dprintk("%s: Inversion = %d (val = 0x%02x)\n", __func__
,
845 state
->dcur
.inversion
, state
->dcur
.inversion_val
);
847 if (state
->config
->set_ts_params
)
848 state
->config
->set_ts_params(fe
, 0);
850 above30msps
= (state
->dcur
.symbol_rate
> 30000000);
853 cx24116_writereg(state
, 0xF9, 0x01);
854 cx24116_writereg(state
, 0xF3, 0x44);
856 cx24116_writereg(state
, 0xF9, 0x00);
857 cx24116_writereg(state
, 0xF3, 0x46);
860 /* Prepare a tune request */
861 cmd
.args
[0x00] = CMD_TUNEREQUEST
;
864 cmd
.args
[0x01] = (state
->dcur
.frequency
& 0xff0000) >> 16;
865 cmd
.args
[0x02] = (state
->dcur
.frequency
& 0x00ff00) >> 8;
866 cmd
.args
[0x03] = (state
->dcur
.frequency
& 0x0000ff);
869 cmd
.args
[0x04] = ((state
->dcur
.symbol_rate
/ 1000) & 0xff00) >> 8;
870 cmd
.args
[0x05] = ((state
->dcur
.symbol_rate
/ 1000) & 0x00ff);
872 /* Automatic Inversion */
873 cmd
.args
[0x06] = state
->dcur
.inversion_val
;
875 /* Modulation / FEC & Pilot Off */
876 cmd
.args
[0x07] = state
->dcur
.fec_val
;
878 if (c
->pilot
== PILOT_ON
)
879 cmd
.args
[0x07] |= 0x40;
881 cmd
.args
[0x08] = CX24116_SEARCH_RANGE_KHZ
>> 8;
882 cmd
.args
[0x09] = CX24116_SEARCH_RANGE_KHZ
& 0xff;
883 cmd
.args
[0x0a] = 0x00;
884 cmd
.args
[0x0b] = 0x00;
885 cmd
.args
[0x0c] = 0x02;
886 cmd
.args
[0x0d] = state
->dcur
.fec_mask
;
889 cmd
.args
[0x0e] = 0x04;
890 cmd
.args
[0x0f] = 0x00;
891 cmd
.args
[0x10] = 0x01;
892 cmd
.args
[0x11] = 0x77;
893 cmd
.args
[0x12] = 0x36;
895 cmd
.args
[0x0e] = 0x06;
896 cmd
.args
[0x0f] = 0x00;
897 cmd
.args
[0x10] = 0x00;
898 cmd
.args
[0x11] = 0xFA;
899 cmd
.args
[0x12] = 0x24;
904 /* We need to support pilot and non-pilot tuning in the
905 * driver automatically. This is a workaround for because
906 * the demod does not support autodetect.
909 /* Reset status register? */
910 cx24116_writereg(state
, 0x9d, 0xc1);
913 ret
= cx24116_cmd_execute(fe
, &cmd
);
917 /* The hardware can take time to lock, wait a while */
920 cx24116_read_status(fe
, &tunerstat
);
921 if(tunerstat
& FE_HAS_SIGNAL
) {
922 if(tunerstat
& FE_HAS_SYNC
)
925 else if(c
->pilot
== PILOT_AUTO
)
926 /* Toggle pilot bit */
927 cmd
.args
[0x07] ^= 0x40;
935 static struct dvb_frontend_ops cx24116_ops
= {
938 .name
= "Conexant CX24116/CX24118",
940 .frequency_min
= 950000,
941 .frequency_max
= 2150000,
942 .frequency_stepsize
= 1011, /* kHz for QPSK frontends */
943 .frequency_tolerance
= 5000,
944 .symbol_rate_min
= 1000000,
945 .symbol_rate_max
= 45000000,
946 .caps
= FE_CAN_INVERSION_AUTO
|
947 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
948 FE_CAN_FEC_4_5
| FE_CAN_FEC_5_6
| FE_CAN_FEC_6_7
|
949 FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
950 FE_CAN_QPSK
| FE_CAN_RECOVER
953 .release
= cx24116_release
,
955 .init
= cx24116_initfe
,
956 .read_status
= cx24116_read_status
,
957 .read_ber
= cx24116_read_ber
,
958 .read_signal_strength
= cx24116_read_signal_strength
,
959 .read_snr
= cx24116_read_snr
,
960 .read_ucblocks
= cx24116_read_ucblocks
,
961 .set_tone
= cx24116_set_tone
,
962 .set_voltage
= cx24116_set_voltage
,
963 .diseqc_send_master_cmd
= cx24116_send_diseqc_msg
,
964 .diseqc_send_burst
= cx24116_diseqc_send_burst
,
966 .set_property
= cx24116_set_property
,
967 .set_params
= cx24116_set_params
,
968 .set_frontend
= cx24116_set_frontend
,
971 module_param(debug
, int, 0644);
972 MODULE_PARM_DESC(debug
, "Activates frontend debugging (default:0)");
974 MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24116/cx24118 hardware");
975 MODULE_AUTHOR("Steven Toth");
976 MODULE_LICENSE("GPL");
978 EXPORT_SYMBOL(cx24116_attach
);