1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Conexant cx24117/cx24132 - Dual DVBS/S2 Satellite demod/tuner driver
7 First release based on cx24116 driver by:
8 Steven Toth and Georg Acher, Darron Broad, Igor Liplianin
9 Cards currently supported:
10 TBS6980 - Dual DVBS/S2 PCIe card
11 TBS6981 - Dual DVBS/S2 PCIe card
15 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/init.h>
20 #include <linux/firmware.h>
22 #include "tuner-i2c.h"
23 #include <media/dvb_frontend.h>
27 #define CX24117_DEFAULT_FIRMWARE "dvb-fe-cx24117.fw"
28 #define CX24117_SEARCH_RANGE_KHZ 5000
31 #define CX24117_REG_COMMAND (0x00) /* command buffer */
32 #define CX24117_REG_EXECUTE (0x1f) /* execute command */
34 #define CX24117_REG_FREQ3_0 (0x34) /* frequency */
35 #define CX24117_REG_FREQ2_0 (0x35)
36 #define CX24117_REG_FREQ1_0 (0x36)
37 #define CX24117_REG_STATE0 (0x39)
38 #define CX24117_REG_SSTATUS0 (0x3a) /* demod0 signal high / status */
39 #define CX24117_REG_SIGNAL0 (0x3b)
40 #define CX24117_REG_FREQ5_0 (0x3c) /* +-freq */
41 #define CX24117_REG_FREQ6_0 (0x3d)
42 #define CX24117_REG_SRATE2_0 (0x3e) /* +- 1000 * srate */
43 #define CX24117_REG_SRATE1_0 (0x3f)
44 #define CX24117_REG_QUALITY2_0 (0x40)
45 #define CX24117_REG_QUALITY1_0 (0x41)
47 #define CX24117_REG_BER4_0 (0x47)
48 #define CX24117_REG_BER3_0 (0x48)
49 #define CX24117_REG_BER2_0 (0x49)
50 #define CX24117_REG_BER1_0 (0x4a)
51 #define CX24117_REG_DVBS_UCB2_0 (0x4b)
52 #define CX24117_REG_DVBS_UCB1_0 (0x4c)
53 #define CX24117_REG_DVBS2_UCB2_0 (0x50)
54 #define CX24117_REG_DVBS2_UCB1_0 (0x51)
55 #define CX24117_REG_QSTATUS0 (0x93)
56 #define CX24117_REG_CLKDIV0 (0xe6)
57 #define CX24117_REG_RATEDIV0 (0xf0)
60 #define CX24117_REG_FREQ3_1 (0x55) /* frequency */
61 #define CX24117_REG_FREQ2_1 (0x56)
62 #define CX24117_REG_FREQ1_1 (0x57)
63 #define CX24117_REG_STATE1 (0x5a)
64 #define CX24117_REG_SSTATUS1 (0x5b) /* demod1 signal high / status */
65 #define CX24117_REG_SIGNAL1 (0x5c)
66 #define CX24117_REG_FREQ5_1 (0x5d) /* +- freq */
67 #define CX24117_REG_FREQ4_1 (0x5e)
68 #define CX24117_REG_SRATE2_1 (0x5f)
69 #define CX24117_REG_SRATE1_1 (0x60)
70 #define CX24117_REG_QUALITY2_1 (0x61)
71 #define CX24117_REG_QUALITY1_1 (0x62)
72 #define CX24117_REG_BER4_1 (0x68)
73 #define CX24117_REG_BER3_1 (0x69)
74 #define CX24117_REG_BER2_1 (0x6a)
75 #define CX24117_REG_BER1_1 (0x6b)
76 #define CX24117_REG_DVBS_UCB2_1 (0x6c)
77 #define CX24117_REG_DVBS_UCB1_1 (0x6d)
78 #define CX24117_REG_DVBS2_UCB2_1 (0x71)
79 #define CX24117_REG_DVBS2_UCB1_1 (0x72)
80 #define CX24117_REG_QSTATUS1 (0x9f)
81 #define CX24117_REG_CLKDIV1 (0xe7)
82 #define CX24117_REG_RATEDIV1 (0xf1)
86 #define CX24117_ARGLEN (0x1e)
89 #define CX24117_ROLLOFF_020 (0x00)
90 #define CX24117_ROLLOFF_025 (0x01)
91 #define CX24117_ROLLOFF_035 (0x02)
94 #define CX24117_PILOT_OFF (0x00)
95 #define CX24117_PILOT_ON (0x40)
96 #define CX24117_PILOT_AUTO (0x80)
99 #define CX24117_HAS_SIGNAL (0x01)
100 #define CX24117_HAS_CARRIER (0x02)
101 #define CX24117_HAS_VITERBI (0x04)
102 #define CX24117_HAS_SYNCLOCK (0x08)
103 #define CX24117_STATUS_MASK (0x0f)
104 #define CX24117_SIGNAL_MASK (0xc0)
107 /* arg offset for DiSEqC */
108 #define CX24117_DISEQC_DEMOD (1)
109 #define CX24117_DISEQC_BURST (2)
110 #define CX24117_DISEQC_ARG3_2 (3) /* unknown value=2 */
111 #define CX24117_DISEQC_ARG4_0 (4) /* unknown value=0 */
112 #define CX24117_DISEQC_ARG5_0 (5) /* unknown value=0 */
113 #define CX24117_DISEQC_MSGLEN (6)
114 #define CX24117_DISEQC_MSGOFS (7)
117 #define CX24117_DISEQC_MINI_A (0)
118 #define CX24117_DISEQC_MINI_B (1)
121 #define CX24117_PNE (0) /* 0 disabled / 2 enabled */
122 #define CX24117_OCC (1) /* 0 disabled / 1 enabled */
126 CMD_SET_VCOFREQ = 0x10,
127 CMD_TUNEREQUEST = 0x11,
128 CMD_GLOBAL_MPEGCFG = 0x13,
130 CMD_TUNERINIT = 0x15,
131 CMD_GET_SRATE = 0x18,
132 CMD_SET_GOLDCODE = 0x19,
133 CMD_GET_AGCACC = 0x1a,
134 CMD_DEMODINIT = 0x1b,
135 CMD_GETCTLACC = 0x1c,
137 CMD_LNBCONFIG = 0x20,
139 CMD_LNBDCLEVEL = 0x22,
140 CMD_LNBPCBCONFIG = 0x23,
141 CMD_LNBSENDTONEBST = 0x24,
142 CMD_LNBUPDREPLY = 0x25,
144 CMD_SET_GPIOMODE = 0x30,
145 CMD_SET_GPIOEN = 0x31,
146 CMD_SET_GPIODIR = 0x32,
147 CMD_SET_GPIOOUT = 0x33,
148 CMD_ENABLERSCORR = 0x34,
149 CMD_FWVERSION = 0x35,
150 CMD_SET_SLEEPMODE = 0x36,
152 CMD_EVENTCTRL = 0x3d,
155 static LIST_HEAD(hybrid_tuner_instance_list);
156 static DEFINE_MUTEX(cx24117_list_mutex);
158 /* The Demod/Tuner can't easily provide these, we cache them */
159 struct cx24117_tuning {
162 enum fe_spectral_inversion inversion;
163 enum fe_code_rate fec;
165 enum fe_delivery_system delsys;
166 enum fe_modulation modulation;
168 enum fe_rolloff rolloff;
178 /* Basic commands that are sent to the firmware */
181 u8 args[CX24117_ARGLEN];
184 /* common to both fe's */
185 struct cx24117_priv {
187 struct i2c_adapter *i2c;
189 struct mutex fe_lock;
191 /* Used for sharing this struct between demods */
192 struct tuner_i2c_props i2c_props;
193 struct list_head hybrid_tuner_instance_list;
196 /* one per each fe */
197 struct cx24117_state {
198 struct cx24117_priv *priv;
199 struct dvb_frontend frontend;
201 struct cx24117_tuning dcur;
202 struct cx24117_tuning dnxt;
203 struct cx24117_cmd dsec_cmd;
208 /* modfec (modulation and FEC) lookup table */
209 /* Check cx24116.c for a detailed description of each field */
210 static struct cx24117_modfec {
211 enum fe_delivery_system delivery_system;
212 enum fe_modulation modulation;
213 enum fe_code_rate fec;
214 u8 mask; /* In DVBS mode this is used to autodetect */
215 u8 val; /* Passed to the firmware to indicate mode selection */
216 } cx24117_modfec_modes[] = {
217 /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
219 /*mod fec mask val */
220 { SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },
221 { SYS_DVBS, QPSK, FEC_1_2, 0x02, 0x2e }, /* 00000010 00101110 */
222 { SYS_DVBS, QPSK, FEC_2_3, 0x04, 0x2f }, /* 00000100 00101111 */
223 { SYS_DVBS, QPSK, FEC_3_4, 0x08, 0x30 }, /* 00001000 00110000 */
224 { SYS_DVBS, QPSK, FEC_4_5, 0xfe, 0x30 }, /* 000?0000 ? */
225 { SYS_DVBS, QPSK, FEC_5_6, 0x20, 0x31 }, /* 00100000 00110001 */
226 { SYS_DVBS, QPSK, FEC_6_7, 0xfe, 0x30 }, /* 0?000000 ? */
227 { SYS_DVBS, QPSK, FEC_7_8, 0x80, 0x32 }, /* 10000000 00110010 */
228 { SYS_DVBS, QPSK, FEC_8_9, 0xfe, 0x30 }, /* 0000000? ? */
229 { SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },
231 { SYS_DVBS2, QPSK, FEC_NONE, 0x00, 0x00 },
232 { SYS_DVBS2, QPSK, FEC_1_2, 0x00, 0x04 },
233 { SYS_DVBS2, QPSK, FEC_3_5, 0x00, 0x05 },
234 { SYS_DVBS2, QPSK, FEC_2_3, 0x00, 0x06 },
235 { SYS_DVBS2, QPSK, FEC_3_4, 0x00, 0x07 },
236 { SYS_DVBS2, QPSK, FEC_4_5, 0x00, 0x08 },
237 { SYS_DVBS2, QPSK, FEC_5_6, 0x00, 0x09 },
238 { SYS_DVBS2, QPSK, FEC_8_9, 0x00, 0x0a },
239 { SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },
240 { SYS_DVBS2, QPSK, FEC_AUTO, 0x00, 0x00 },
242 { SYS_DVBS2, PSK_8, FEC_NONE, 0x00, 0x00 },
243 { SYS_DVBS2, PSK_8, FEC_3_5, 0x00, 0x0c },
244 { SYS_DVBS2, PSK_8, FEC_2_3, 0x00, 0x0d },
245 { SYS_DVBS2, PSK_8, FEC_3_4, 0x00, 0x0e },
246 { SYS_DVBS2, PSK_8, FEC_5_6, 0x00, 0x0f },
247 { SYS_DVBS2, PSK_8, FEC_8_9, 0x00, 0x10 },
248 { SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },
249 { SYS_DVBS2, PSK_8, FEC_AUTO, 0x00, 0x00 },
251 * 'val' can be found in the FECSTATUS register when tuning.
252 * FECSTATUS will give the actual FEC in use if tuning was successful.
257 static int cx24117_writereg(struct cx24117_state *state, u8 reg, u8 data)
259 u8 buf[] = { reg, data };
260 struct i2c_msg msg = { .addr = state->priv->demod_address,
261 .flags = 0, .buf = buf, .len = 2 };
264 dev_dbg(&state->priv->i2c->dev,
265 "%s() demod%d i2c wr @0x%02x=0x%02x\n",
266 __func__, state->demod, reg, data);
268 ret = i2c_transfer(state->priv->i2c, &msg, 1);
270 dev_warn(&state->priv->i2c->dev,
271 "%s: demod%d i2c wr err(%i) @0x%02x=0x%02x\n",
272 KBUILD_MODNAME, state->demod, ret, reg, data);
278 static int cx24117_writecmd(struct cx24117_state *state,
279 struct cx24117_cmd *cmd)
282 u8 buf[CX24117_ARGLEN+1];
285 dev_dbg(&state->priv->i2c->dev,
286 "%s() demod%d i2c wr cmd len=%d\n",
287 __func__, state->demod, cmd->len);
289 buf[0] = CX24117_REG_COMMAND;
290 memcpy(&buf[1], cmd->args, cmd->len);
292 msg.addr = state->priv->demod_address;
294 msg.len = cmd->len+1;
296 ret = i2c_transfer(state->priv->i2c, &msg, 1);
298 dev_warn(&state->priv->i2c->dev,
299 "%s: demod%d i2c wr cmd err(%i) len=%d\n",
300 KBUILD_MODNAME, state->demod, ret, cmd->len);
306 static int cx24117_readreg(struct cx24117_state *state, u8 reg)
310 struct i2c_msg msg[] = {
311 { .addr = state->priv->demod_address, .flags = 0,
312 .buf = ®, .len = 1 },
313 { .addr = state->priv->demod_address, .flags = I2C_M_RD,
314 .buf = &recv, .len = 1 }
317 ret = i2c_transfer(state->priv->i2c, msg, 2);
319 dev_warn(&state->priv->i2c->dev,
320 "%s: demod%d i2c rd err(%d) @0x%x\n",
321 KBUILD_MODNAME, state->demod, ret, reg);
325 dev_dbg(&state->priv->i2c->dev, "%s() demod%d i2c rd @0x%02x=0x%02x\n",
326 __func__, state->demod, reg, recv);
331 static int cx24117_readregN(struct cx24117_state *state,
332 u8 reg, u8 *buf, int len)
335 struct i2c_msg msg[] = {
336 { .addr = state->priv->demod_address, .flags = 0,
337 .buf = ®, .len = 1 },
338 { .addr = state->priv->demod_address, .flags = I2C_M_RD,
339 .buf = buf, .len = len }
342 ret = i2c_transfer(state->priv->i2c, msg, 2);
344 dev_warn(&state->priv->i2c->dev,
345 "%s: demod%d i2c rd err(%d) @0x%x\n",
346 KBUILD_MODNAME, state->demod, ret, reg);
352 static int cx24117_set_inversion(struct cx24117_state *state,
353 enum fe_spectral_inversion inversion)
355 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
356 __func__, inversion, state->demod);
360 state->dnxt.inversion_val = 0x00;
363 state->dnxt.inversion_val = 0x04;
366 state->dnxt.inversion_val = 0x0C;
372 state->dnxt.inversion = inversion;
377 static int cx24117_lookup_fecmod(struct cx24117_state *state,
378 enum fe_delivery_system d, enum fe_modulation m, enum fe_code_rate f)
380 int i, ret = -EINVAL;
382 dev_dbg(&state->priv->i2c->dev,
383 "%s(demod(0x%02x,0x%02x) demod%d\n",
384 __func__, m, f, state->demod);
386 for (i = 0; i < ARRAY_SIZE(cx24117_modfec_modes); i++) {
387 if ((d == cx24117_modfec_modes[i].delivery_system) &&
388 (m == cx24117_modfec_modes[i].modulation) &&
389 (f == cx24117_modfec_modes[i].fec)) {
398 static int cx24117_set_fec(struct cx24117_state *state,
399 enum fe_delivery_system delsys,
400 enum fe_modulation mod,
401 enum fe_code_rate fec)
405 dev_dbg(&state->priv->i2c->dev,
406 "%s(0x%02x,0x%02x) demod%d\n",
407 __func__, mod, fec, state->demod);
409 ret = cx24117_lookup_fecmod(state, delsys, mod, fec);
413 state->dnxt.fec = fec;
414 state->dnxt.fec_val = cx24117_modfec_modes[ret].val;
415 state->dnxt.fec_mask = cx24117_modfec_modes[ret].mask;
416 dev_dbg(&state->priv->i2c->dev,
417 "%s() demod%d mask/val = 0x%02x/0x%02x\n", __func__,
418 state->demod, state->dnxt.fec_mask, state->dnxt.fec_val);
423 static int cx24117_set_symbolrate(struct cx24117_state *state, u32 rate)
425 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
426 __func__, rate, state->demod);
428 state->dnxt.symbol_rate = rate;
430 dev_dbg(&state->priv->i2c->dev,
431 "%s() demod%d symbol_rate = %d\n",
432 __func__, state->demod, rate);
437 static int cx24117_load_firmware(struct dvb_frontend *fe,
438 const struct firmware *fw);
440 static int cx24117_firmware_ondemand(struct dvb_frontend *fe)
442 struct cx24117_state *state = fe->demodulator_priv;
443 const struct firmware *fw;
446 dev_dbg(&state->priv->i2c->dev, "%s() demod%d skip_fw_load=%d\n",
447 __func__, state->demod, state->priv->skip_fw_load);
449 if (state->priv->skip_fw_load)
452 /* check if firmware is already running */
453 if (cx24117_readreg(state, 0xeb) != 0xa) {
455 /* request the firmware, this will block until loaded */
456 dev_dbg(&state->priv->i2c->dev,
457 "%s: Waiting for firmware upload (%s)...\n",
458 __func__, CX24117_DEFAULT_FIRMWARE);
459 ret = request_firmware(&fw, CX24117_DEFAULT_FIRMWARE,
460 state->priv->i2c->dev.parent);
461 dev_dbg(&state->priv->i2c->dev,
462 "%s: Waiting for firmware upload(2)...\n", __func__);
464 dev_err(&state->priv->i2c->dev,
465 "%s: No firmware uploaded (timeout or file not found?)\n",
470 /* Make sure we don't recurse back through here
472 state->priv->skip_fw_load = 1;
474 ret = cx24117_load_firmware(fe, fw);
476 dev_err(&state->priv->i2c->dev,
477 "%s: Writing firmware failed\n", __func__);
478 release_firmware(fw);
480 dev_info(&state->priv->i2c->dev,
481 "%s: Firmware upload %s\n", __func__,
482 ret == 0 ? "complete" : "failed");
484 /* Ensure firmware is always loaded if required */
485 state->priv->skip_fw_load = 0;
491 /* Take a basic firmware command structure, format it
492 * and forward it for processing
494 static int cx24117_cmd_execute_nolock(struct dvb_frontend *fe,
495 struct cx24117_cmd *cmd)
497 struct cx24117_state *state = fe->demodulator_priv;
500 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
501 __func__, state->demod);
503 /* Load the firmware if required */
504 ret = cx24117_firmware_ondemand(fe);
508 /* Write the command */
509 cx24117_writecmd(state, cmd);
511 /* Start execution and wait for cmd to terminate */
512 cx24117_writereg(state, CX24117_REG_EXECUTE, 0x01);
514 while (cx24117_readreg(state, CX24117_REG_EXECUTE)) {
517 /* Avoid looping forever if the firmware does
519 dev_warn(&state->priv->i2c->dev,
520 "%s() Firmware not responding\n", __func__);
527 static int cx24117_cmd_execute(struct dvb_frontend *fe, struct cx24117_cmd *cmd)
529 struct cx24117_state *state = fe->demodulator_priv;
532 mutex_lock(&state->priv->fe_lock);
533 ret = cx24117_cmd_execute_nolock(fe, cmd);
534 mutex_unlock(&state->priv->fe_lock);
539 static int cx24117_load_firmware(struct dvb_frontend *fe,
540 const struct firmware *fw)
542 struct cx24117_state *state = fe->demodulator_priv;
543 struct cx24117_cmd cmd;
545 unsigned char vers[4];
550 dev_dbg(&state->priv->i2c->dev,
551 "%s() demod%d FW is %zu bytes (%02x %02x .. %02x %02x)\n",
552 __func__, state->demod, fw->size, fw->data[0], fw->data[1],
553 fw->data[fw->size - 2], fw->data[fw->size - 1]);
555 cx24117_writereg(state, 0xea, 0x00);
556 cx24117_writereg(state, 0xea, 0x01);
557 cx24117_writereg(state, 0xea, 0x00);
559 cx24117_writereg(state, 0xce, 0x92);
561 cx24117_writereg(state, 0xfb, 0x00);
562 cx24117_writereg(state, 0xfc, 0x00);
564 cx24117_writereg(state, 0xc3, 0x04);
565 cx24117_writereg(state, 0xc4, 0x04);
567 cx24117_writereg(state, 0xce, 0x00);
568 cx24117_writereg(state, 0xcf, 0x00);
570 cx24117_writereg(state, 0xea, 0x00);
571 cx24117_writereg(state, 0xeb, 0x0c);
572 cx24117_writereg(state, 0xec, 0x06);
573 cx24117_writereg(state, 0xed, 0x05);
574 cx24117_writereg(state, 0xee, 0x03);
575 cx24117_writereg(state, 0xef, 0x05);
577 cx24117_writereg(state, 0xf3, 0x03);
578 cx24117_writereg(state, 0xf4, 0x44);
580 cx24117_writereg(state, CX24117_REG_RATEDIV0, 0x04);
581 cx24117_writereg(state, CX24117_REG_CLKDIV0, 0x02);
583 cx24117_writereg(state, CX24117_REG_RATEDIV1, 0x04);
584 cx24117_writereg(state, CX24117_REG_CLKDIV1, 0x02);
586 cx24117_writereg(state, 0xf2, 0x04);
587 cx24117_writereg(state, 0xe8, 0x02);
588 cx24117_writereg(state, 0xea, 0x01);
589 cx24117_writereg(state, 0xc8, 0x00);
590 cx24117_writereg(state, 0xc9, 0x00);
591 cx24117_writereg(state, 0xca, 0x00);
592 cx24117_writereg(state, 0xcb, 0x00);
593 cx24117_writereg(state, 0xcc, 0x00);
594 cx24117_writereg(state, 0xcd, 0x00);
595 cx24117_writereg(state, 0xe4, 0x03);
596 cx24117_writereg(state, 0xeb, 0x0a);
598 cx24117_writereg(state, 0xfb, 0x00);
599 cx24117_writereg(state, 0xe0, 0x76);
600 cx24117_writereg(state, 0xf7, 0x81);
601 cx24117_writereg(state, 0xf8, 0x00);
602 cx24117_writereg(state, 0xf9, 0x00);
604 buf = kmalloc(fw->size + 1, GFP_KERNEL);
606 state->priv->skip_fw_load = 0;
612 memcpy(&buf[1], fw->data, fw->size);
614 /* prepare i2c message to send */
615 msg.addr = state->priv->demod_address;
617 msg.len = fw->size + 1;
621 ret = i2c_transfer(state->priv->i2c, &msg, 1);
629 cx24117_writereg(state, 0xf7, 0x0c);
630 cx24117_writereg(state, 0xe0, 0x00);
632 /* Init demodulator */
633 cmd.args[0] = CMD_DEMODINIT;
638 ret = cx24117_cmd_execute_nolock(fe, &cmd);
642 /* Set VCO frequency */
643 cmd.args[0] = CMD_SET_VCOFREQ;
657 ret = cx24117_cmd_execute_nolock(fe, &cmd);
662 cmd.args[0] = CMD_TUNERINIT;
676 ret = cx24117_cmd_execute_nolock(fe, &cmd);
680 /* Global MPEG config */
681 cmd.args[0] = CMD_GLOBAL_MPEGCFG;
688 ret = cx24117_cmd_execute_nolock(fe, &cmd);
692 /* MPEG config for each demod */
693 for (i = 0; i < 2; i++) {
694 cmd.args[0] = CMD_MPEGCFG;
695 cmd.args[1] = (u8) i;
703 ret = cx24117_cmd_execute_nolock(fe, &cmd);
708 cx24117_writereg(state, 0xce, 0xc0);
709 cx24117_writereg(state, 0xcf, 0x00);
710 cx24117_writereg(state, 0xe5, 0x04);
712 /* Get firmware version */
713 cmd.args[0] = CMD_FWVERSION;
715 for (i = 0; i < 4; i++) {
717 ret = cx24117_cmd_execute_nolock(fe, &cmd);
720 vers[i] = cx24117_readreg(state, 0x33);
722 dev_info(&state->priv->i2c->dev,
723 "%s: FW version %i.%i.%i.%i\n", __func__,
724 vers[0], vers[1], vers[2], vers[3]);
727 state->priv->skip_fw_load = 0;
728 dev_err(&state->priv->i2c->dev, "%s() Error running FW.\n", __func__);
732 static int cx24117_read_status(struct dvb_frontend *fe, enum fe_status *status)
734 struct cx24117_state *state = fe->demodulator_priv;
737 lock = cx24117_readreg(state,
738 (state->demod == 0) ? CX24117_REG_SSTATUS0 :
739 CX24117_REG_SSTATUS1) &
742 dev_dbg(&state->priv->i2c->dev, "%s() demod%d status = 0x%02x\n",
743 __func__, state->demod, lock);
747 if (lock & CX24117_HAS_SIGNAL)
748 *status |= FE_HAS_SIGNAL;
749 if (lock & CX24117_HAS_CARRIER)
750 *status |= FE_HAS_CARRIER;
751 if (lock & CX24117_HAS_VITERBI)
752 *status |= FE_HAS_VITERBI;
753 if (lock & CX24117_HAS_SYNCLOCK)
754 *status |= FE_HAS_SYNC | FE_HAS_LOCK;
759 static int cx24117_read_ber(struct dvb_frontend *fe, u32 *ber)
761 struct cx24117_state *state = fe->demodulator_priv;
764 u8 base_reg = (state->demod == 0) ?
768 ret = cx24117_readregN(state, base_reg, buf, 4);
772 *ber = (buf[0] << 24) | (buf[1] << 16) |
773 (buf[1] << 8) | buf[0];
775 dev_dbg(&state->priv->i2c->dev, "%s() demod%d ber=0x%04x\n",
776 __func__, state->demod, *ber);
781 static int cx24117_read_signal_strength(struct dvb_frontend *fe,
782 u16 *signal_strength)
784 struct cx24117_state *state = fe->demodulator_priv;
785 struct cx24117_cmd cmd;
789 u8 reg = (state->demod == 0) ?
790 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1;
792 /* Read AGC accumulator register */
793 cmd.args[0] = CMD_GET_AGCACC;
794 cmd.args[1] = (u8) state->demod;
796 ret = cx24117_cmd_execute(fe, &cmd);
800 ret = cx24117_readregN(state, reg, buf, 2);
803 sig_reading = ((buf[0] & CX24117_SIGNAL_MASK) << 2) | buf[1];
805 *signal_strength = -100 * sig_reading + 94324;
807 dev_dbg(&state->priv->i2c->dev,
808 "%s() demod%d raw / cooked = 0x%04x / 0x%04x\n",
809 __func__, state->demod, sig_reading, *signal_strength);
814 static int cx24117_read_snr(struct dvb_frontend *fe, u16 *snr)
816 struct cx24117_state *state = fe->demodulator_priv;
819 u8 reg = (state->demod == 0) ?
820 CX24117_REG_QUALITY2_0 : CX24117_REG_QUALITY2_1;
822 ret = cx24117_readregN(state, reg, buf, 2);
826 *snr = (buf[0] << 8) | buf[1];
828 dev_dbg(&state->priv->i2c->dev,
829 "%s() demod%d snr = 0x%04x\n",
830 __func__, state->demod, *snr);
835 static int cx24117_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
837 struct cx24117_state *state = fe->demodulator_priv;
838 enum fe_delivery_system delsys = fe->dtv_property_cache.delivery_system;
841 u8 reg = (state->demod == 0) ?
842 CX24117_REG_DVBS_UCB2_0 :
843 CX24117_REG_DVBS_UCB2_1;
849 reg += (CX24117_REG_DVBS2_UCB2_0 - CX24117_REG_DVBS_UCB2_0);
855 ret = cx24117_readregN(state, reg, buf, 2);
858 *ucblocks = (buf[0] << 8) | buf[1];
860 dev_dbg(&state->priv->i2c->dev, "%s() demod%d ucb=0x%04x\n",
861 __func__, state->demod, *ucblocks);
866 /* Overwrite the current tuning params, we are about to tune */
867 static void cx24117_clone_params(struct dvb_frontend *fe)
869 struct cx24117_state *state = fe->demodulator_priv;
870 state->dcur = state->dnxt;
874 static int cx24117_wait_for_lnb(struct dvb_frontend *fe)
876 struct cx24117_state *state = fe->demodulator_priv;
878 u8 val, reg = (state->demod == 0) ? CX24117_REG_QSTATUS0 :
879 CX24117_REG_QSTATUS1;
881 dev_dbg(&state->priv->i2c->dev, "%s() demod%d qstatus = 0x%02x\n",
882 __func__, state->demod, cx24117_readreg(state, reg));
884 /* Wait for up to 300 ms */
885 for (i = 0; i < 10; i++) {
886 val = cx24117_readreg(state, reg) & 0x01;
892 dev_warn(&state->priv->i2c->dev, "%s: demod%d LNB not ready\n",
893 KBUILD_MODNAME, state->demod);
895 return -ETIMEDOUT; /* -EBUSY ? */
898 static int cx24117_set_voltage(struct dvb_frontend *fe,
899 enum fe_sec_voltage voltage)
901 struct cx24117_state *state = fe->demodulator_priv;
902 struct cx24117_cmd cmd;
904 u8 reg = (state->demod == 0) ? 0x10 : 0x20;
906 dev_dbg(&state->priv->i2c->dev, "%s() demod%d %s\n",
907 __func__, state->demod,
908 voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
909 voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" :
912 /* Prepare a set GPIO logic level CMD */
913 cmd.args[0] = CMD_SET_GPIOOUT;
914 cmd.args[2] = reg; /* mask */
917 if ((voltage == SEC_VOLTAGE_13) ||
918 (voltage == SEC_VOLTAGE_18)) {
921 ret = cx24117_cmd_execute(fe, &cmd);
925 ret = cx24117_wait_for_lnb(fe);
929 /* Wait for voltage/min repeat delay */
932 /* Set 13V/18V select pin */
933 cmd.args[0] = CMD_LNBDCLEVEL;
934 cmd.args[1] = state->demod ? 0 : 1;
935 cmd.args[2] = (voltage == SEC_VOLTAGE_18 ? 0x01 : 0x00);
937 ret = cx24117_cmd_execute(fe, &cmd);
939 /* Min delay time before DiSEqC send */
944 ret = cx24117_cmd_execute(fe, &cmd);
950 static int cx24117_set_tone(struct dvb_frontend *fe,
951 enum fe_sec_tone_mode tone)
953 struct cx24117_state *state = fe->demodulator_priv;
954 struct cx24117_cmd cmd;
957 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
958 __func__, state->demod, tone);
959 if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {
960 dev_warn(&state->priv->i2c->dev, "%s: demod%d invalid tone=%d\n",
961 KBUILD_MODNAME, state->demod, tone);
965 /* Wait for LNB ready */
966 ret = cx24117_wait_for_lnb(fe);
970 /* Min delay time after DiSEqC send */
974 cmd.args[0] = CMD_LNBPCBCONFIG;
975 cmd.args[1] = (state->demod ? 0 : 1);
990 return cx24117_cmd_execute(fe, &cmd);
993 /* Initialise DiSEqC */
994 static int cx24117_diseqc_init(struct dvb_frontend *fe)
996 struct cx24117_state *state = fe->demodulator_priv;
998 /* Prepare a DiSEqC command */
999 state->dsec_cmd.args[0] = CMD_LNBSEND;
1002 state->dsec_cmd.args[CX24117_DISEQC_DEMOD] = state->demod ? 0 : 1;
1005 state->dsec_cmd.args[CX24117_DISEQC_BURST] = CX24117_DISEQC_MINI_A;
1008 state->dsec_cmd.args[CX24117_DISEQC_ARG3_2] = 0x02;
1009 state->dsec_cmd.args[CX24117_DISEQC_ARG4_0] = 0x00;
1011 /* Continuation flag? */
1012 state->dsec_cmd.args[CX24117_DISEQC_ARG5_0] = 0x00;
1014 /* DiSEqC message length */
1015 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = 0x00;
1017 /* Command length */
1018 state->dsec_cmd.len = 7;
1023 /* Send DiSEqC message */
1024 static int cx24117_send_diseqc_msg(struct dvb_frontend *fe,
1025 struct dvb_diseqc_master_cmd *d)
1027 struct cx24117_state *state = fe->demodulator_priv;
1030 /* Dump DiSEqC message */
1031 dev_dbg(&state->priv->i2c->dev, "%s: demod %d (",
1032 __func__, state->demod);
1033 for (i = 0; i < d->msg_len; i++)
1034 dev_dbg(&state->priv->i2c->dev, "0x%02x ", d->msg[i]);
1035 dev_dbg(&state->priv->i2c->dev, ")\n");
1037 /* Validate length */
1038 if (d->msg_len > sizeof(d->msg))
1041 /* DiSEqC message */
1042 for (i = 0; i < d->msg_len; i++)
1043 state->dsec_cmd.args[CX24117_DISEQC_MSGOFS + i] = d->msg[i];
1045 /* DiSEqC message length */
1046 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = d->msg_len;
1048 /* Command length */
1049 state->dsec_cmd.len = CX24117_DISEQC_MSGOFS +
1050 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN];
1053 * Message is sent with derived else cached burst
1055 * WRITE PORT GROUP COMMAND 38
1057 * 0/A/A: E0 10 38 F0..F3
1058 * 1/B/B: E0 10 38 F4..F7
1059 * 2/C/A: E0 10 38 F8..FB
1060 * 3/D/B: E0 10 38 FC..FF
1062 * databyte[3]= 8421:8421
1066 * WX= PORT SELECT 0..3 (X=TONEBURST)
1067 * Y = VOLTAGE (0=13V, 1=18V)
1068 * Z = BAND (0=LOW, 1=HIGH(22K))
1070 if (d->msg_len >= 4 && d->msg[2] == 0x38)
1071 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1072 ((d->msg[3] & 4) >> 2);
1074 dev_dbg(&state->priv->i2c->dev, "%s() demod%d burst=%d\n",
1075 __func__, state->demod,
1076 state->dsec_cmd.args[CX24117_DISEQC_BURST]);
1078 /* Wait for LNB ready */
1079 ret = cx24117_wait_for_lnb(fe);
1083 /* Wait for voltage/min repeat delay */
1087 ret = cx24117_cmd_execute(fe, &state->dsec_cmd);
1094 * >15ms delay + (XXX determine if FW does this, see set_tone)
1098 * >15ms delay (XXX determine if FW does this, see set_tone)
1100 msleep((state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] << 4) + 60);
1105 /* Send DiSEqC burst */
1106 static int cx24117_diseqc_send_burst(struct dvb_frontend *fe,
1107 enum fe_sec_mini_cmd burst)
1109 struct cx24117_state *state = fe->demodulator_priv;
1111 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod=%d\n",
1112 __func__, burst, state->demod);
1115 if (burst == SEC_MINI_A)
1116 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1117 CX24117_DISEQC_MINI_A;
1118 else if (burst == SEC_MINI_B)
1119 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1120 CX24117_DISEQC_MINI_B;
1127 static int cx24117_get_priv(struct cx24117_priv **priv,
1128 struct i2c_adapter *i2c, u8 client_address)
1132 mutex_lock(&cx24117_list_mutex);
1133 ret = hybrid_tuner_request_state(struct cx24117_priv, (*priv),
1134 hybrid_tuner_instance_list, i2c, client_address, "cx24117");
1135 mutex_unlock(&cx24117_list_mutex);
1140 static void cx24117_release_priv(struct cx24117_priv *priv)
1142 mutex_lock(&cx24117_list_mutex);
1144 hybrid_tuner_release_state(priv);
1145 mutex_unlock(&cx24117_list_mutex);
1148 static void cx24117_release(struct dvb_frontend *fe)
1150 struct cx24117_state *state = fe->demodulator_priv;
1151 dev_dbg(&state->priv->i2c->dev, "%s demod%d\n",
1152 __func__, state->demod);
1153 cx24117_release_priv(state->priv);
1157 static const struct dvb_frontend_ops cx24117_ops;
1159 struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
1160 struct i2c_adapter *i2c)
1162 struct cx24117_state *state = NULL;
1163 struct cx24117_priv *priv = NULL;
1166 /* get the common data struct for both demods */
1167 demod = cx24117_get_priv(&priv, i2c, config->demod_address);
1172 "%s: Error attaching frontend %d\n",
1173 KBUILD_MODNAME, demod);
1176 /* new priv instance */
1178 priv->demod_address = config->demod_address;
1179 mutex_init(&priv->fe_lock);
1182 /* existing priv instance */
1186 /* allocate memory for the internal state */
1187 state = kzalloc(sizeof(struct cx24117_state), GFP_KERNEL);
1191 state->demod = demod - 1;
1194 dev_info(&state->priv->i2c->dev,
1195 "%s: Attaching frontend %d\n",
1196 KBUILD_MODNAME, state->demod);
1198 /* create dvb_frontend */
1199 memcpy(&state->frontend.ops, &cx24117_ops,
1200 sizeof(struct dvb_frontend_ops));
1201 state->frontend.demodulator_priv = state;
1202 return &state->frontend;
1205 cx24117_release_priv(priv);
1209 EXPORT_SYMBOL_GPL(cx24117_attach);
1212 * Initialise or wake up device
1214 * Power config will reset and load initial firmware if required
1216 static int cx24117_initfe(struct dvb_frontend *fe)
1218 struct cx24117_state *state = fe->demodulator_priv;
1219 struct cx24117_cmd cmd;
1222 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1223 __func__, state->demod);
1225 mutex_lock(&state->priv->fe_lock);
1227 /* Set sleep mode off */
1228 cmd.args[0] = CMD_SET_SLEEPMODE;
1229 cmd.args[1] = (state->demod ? 1 : 0);
1232 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1236 ret = cx24117_diseqc_init(fe);
1240 /* Set BER control */
1241 cmd.args[0] = CMD_BERCTRL;
1242 cmd.args[1] = (state->demod ? 1 : 0);
1246 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1250 /* Set RS correction (enable/disable) */
1251 cmd.args[0] = CMD_ENABLERSCORR;
1252 cmd.args[1] = (state->demod ? 1 : 0);
1253 cmd.args[2] = CX24117_OCC;
1255 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1259 /* Set GPIO direction */
1260 /* Set as output - controls LNB power on/off */
1261 cmd.args[0] = CMD_SET_GPIODIR;
1265 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1268 mutex_unlock(&state->priv->fe_lock);
1274 * Put device to sleep
1276 static int cx24117_sleep(struct dvb_frontend *fe)
1278 struct cx24117_state *state = fe->demodulator_priv;
1279 struct cx24117_cmd cmd;
1281 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1282 __func__, state->demod);
1284 /* Set sleep mode on */
1285 cmd.args[0] = CMD_SET_SLEEPMODE;
1286 cmd.args[1] = (state->demod ? 1 : 0);
1289 return cx24117_cmd_execute(fe, &cmd);
1292 /* dvb-core told us to tune, the tv property cache will be complete,
1293 * it's safe for is to pull values and use them for tuning purposes.
1295 static int cx24117_set_frontend(struct dvb_frontend *fe)
1297 struct cx24117_state *state = fe->demodulator_priv;
1298 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1299 struct cx24117_cmd cmd;
1300 enum fe_status tunerstat;
1301 int i, status, ret, retune = 1;
1302 u8 reg_clkdiv, reg_ratediv;
1304 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1305 __func__, state->demod);
1307 switch (c->delivery_system) {
1309 dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S\n",
1310 __func__, state->demod);
1312 /* Only QPSK is supported for DVB-S */
1313 if (c->modulation != QPSK) {
1314 dev_dbg(&state->priv->i2c->dev,
1315 "%s() demod%d unsupported modulation (%d)\n",
1316 __func__, state->demod, c->modulation);
1320 /* Pilot doesn't exist in DVB-S, turn bit off */
1321 state->dnxt.pilot_val = CX24117_PILOT_OFF;
1323 /* DVB-S only supports 0.35 */
1324 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1328 dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S2\n",
1329 __func__, state->demod);
1332 * NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,
1333 * but not hardware auto detection
1335 if (c->modulation != PSK_8 && c->modulation != QPSK) {
1336 dev_dbg(&state->priv->i2c->dev,
1337 "%s() demod%d unsupported modulation (%d)\n",
1338 __func__, state->demod, c->modulation);
1344 state->dnxt.pilot_val = CX24117_PILOT_AUTO;
1347 state->dnxt.pilot_val = CX24117_PILOT_OFF;
1350 state->dnxt.pilot_val = CX24117_PILOT_ON;
1353 dev_dbg(&state->priv->i2c->dev,
1354 "%s() demod%d unsupported pilot mode (%d)\n",
1355 __func__, state->demod, c->pilot);
1359 switch (c->rolloff) {
1361 state->dnxt.rolloff_val = CX24117_ROLLOFF_020;
1364 state->dnxt.rolloff_val = CX24117_ROLLOFF_025;
1367 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1370 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1371 /* soft-auto rolloff */
1375 dev_warn(&state->priv->i2c->dev,
1376 "%s: demod%d unsupported rolloff (%d)\n",
1377 KBUILD_MODNAME, state->demod, c->rolloff);
1383 dev_warn(&state->priv->i2c->dev,
1384 "%s: demod %d unsupported delivery system (%d)\n",
1385 KBUILD_MODNAME, state->demod, c->delivery_system);
1389 state->dnxt.delsys = c->delivery_system;
1390 state->dnxt.modulation = c->modulation;
1391 state->dnxt.frequency = c->frequency;
1392 state->dnxt.pilot = c->pilot;
1393 state->dnxt.rolloff = c->rolloff;
1395 ret = cx24117_set_inversion(state, c->inversion);
1399 ret = cx24117_set_fec(state,
1400 c->delivery_system, c->modulation, c->fec_inner);
1404 ret = cx24117_set_symbolrate(state, c->symbol_rate);
1408 /* discard the 'current' tuning parameters and prepare to tune */
1409 cx24117_clone_params(fe);
1411 dev_dbg(&state->priv->i2c->dev,
1412 "%s: delsys = %d\n", __func__, state->dcur.delsys);
1413 dev_dbg(&state->priv->i2c->dev,
1414 "%s: modulation = %d\n", __func__, state->dcur.modulation);
1415 dev_dbg(&state->priv->i2c->dev,
1416 "%s: frequency = %d\n", __func__, state->dcur.frequency);
1417 dev_dbg(&state->priv->i2c->dev,
1418 "%s: pilot = %d (val = 0x%02x)\n", __func__,
1419 state->dcur.pilot, state->dcur.pilot_val);
1420 dev_dbg(&state->priv->i2c->dev,
1421 "%s: retune = %d\n", __func__, retune);
1422 dev_dbg(&state->priv->i2c->dev,
1423 "%s: rolloff = %d (val = 0x%02x)\n", __func__,
1424 state->dcur.rolloff, state->dcur.rolloff_val);
1425 dev_dbg(&state->priv->i2c->dev,
1426 "%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate);
1427 dev_dbg(&state->priv->i2c->dev,
1428 "%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
1429 state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
1430 dev_dbg(&state->priv->i2c->dev,
1431 "%s: Inversion = %d (val = 0x%02x)\n", __func__,
1432 state->dcur.inversion, state->dcur.inversion_val);
1434 /* Prepare a tune request */
1435 cmd.args[0] = CMD_TUNEREQUEST;
1438 cmd.args[1] = state->demod;
1441 cmd.args[2] = (state->dcur.frequency & 0xff0000) >> 16;
1442 cmd.args[3] = (state->dcur.frequency & 0x00ff00) >> 8;
1443 cmd.args[4] = (state->dcur.frequency & 0x0000ff);
1446 cmd.args[5] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
1447 cmd.args[6] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
1449 /* Automatic Inversion */
1450 cmd.args[7] = state->dcur.inversion_val;
1452 /* Modulation / FEC / Pilot */
1453 cmd.args[8] = state->dcur.fec_val | state->dcur.pilot_val;
1455 cmd.args[9] = CX24117_SEARCH_RANGE_KHZ >> 8;
1456 cmd.args[10] = CX24117_SEARCH_RANGE_KHZ & 0xff;
1458 cmd.args[11] = state->dcur.rolloff_val;
1459 cmd.args[12] = state->dcur.fec_mask;
1461 if (state->dcur.symbol_rate > 30000000) {
1464 } else if (state->dcur.symbol_rate > 10000000) {
1472 cmd.args[13] = reg_ratediv;
1473 cmd.args[14] = reg_clkdiv;
1475 cx24117_writereg(state, (state->demod == 0) ?
1476 CX24117_REG_CLKDIV0 : CX24117_REG_CLKDIV1, reg_clkdiv);
1477 cx24117_writereg(state, (state->demod == 0) ?
1478 CX24117_REG_RATEDIV0 : CX24117_REG_RATEDIV1, reg_ratediv);
1480 cmd.args[15] = CX24117_PNE;
1484 /* Reset status register */
1485 status = cx24117_readreg(state, (state->demod == 0) ?
1486 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1) &
1487 CX24117_SIGNAL_MASK;
1489 dev_dbg(&state->priv->i2c->dev,
1490 "%s() demod%d status_setfe = %02x\n",
1491 __func__, state->demod, status);
1493 cx24117_writereg(state, (state->demod == 0) ?
1494 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1, status);
1497 ret = cx24117_cmd_execute(fe, &cmd);
1502 * Wait for up to 500 ms before retrying
1504 * If we are able to tune then generally it occurs within 100ms.
1505 * If it takes longer, try a different rolloff setting.
1507 for (i = 0; i < 50; i++) {
1508 cx24117_read_status(fe, &tunerstat);
1509 status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);
1510 if (status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {
1511 dev_dbg(&state->priv->i2c->dev,
1512 "%s() demod%d tuned\n",
1513 __func__, state->demod);
1519 dev_dbg(&state->priv->i2c->dev, "%s() demod%d not tuned\n",
1520 __func__, state->demod);
1522 /* try next rolloff value */
1523 if (state->dcur.rolloff == 3)
1530 static int cx24117_tune(struct dvb_frontend *fe, bool re_tune,
1531 unsigned int mode_flags, unsigned int *delay, enum fe_status *status)
1533 struct cx24117_state *state = fe->demodulator_priv;
1535 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1536 __func__, state->demod);
1540 int ret = cx24117_set_frontend(fe);
1544 return cx24117_read_status(fe, status);
1547 static enum dvbfe_algo cx24117_get_algo(struct dvb_frontend *fe)
1549 return DVBFE_ALGO_HW;
1552 static int cx24117_get_frontend(struct dvb_frontend *fe,
1553 struct dtv_frontend_properties *c)
1555 struct cx24117_state *state = fe->demodulator_priv;
1556 struct cx24117_cmd cmd;
1560 short srate_os, freq_os;
1564 /* Read current tune parameters */
1565 cmd.args[0] = CMD_GETCTLACC;
1566 cmd.args[1] = (u8) state->demod;
1568 ret = cx24117_cmd_execute(fe, &cmd);
1572 /* read all required regs at once */
1573 reg = (state->demod == 0) ? CX24117_REG_FREQ3_0 : CX24117_REG_FREQ3_1;
1574 ret = cx24117_readregN(state, reg, buf, 0x1f-4);
1580 /* get spectral inversion */
1581 inv = (((state->demod == 0) ? ~st : st) >> 6) & 1;
1583 c->inversion = INVERSION_OFF;
1585 c->inversion = INVERSION_ON;
1587 /* modulation and fec */
1589 if (c->delivery_system == SYS_DVBS2) {
1596 c->modulation = cx24117_modfec_modes[idx].modulation;
1597 c->fec_inner = cx24117_modfec_modes[idx].fec;
1600 freq = (buf[0] << 16) | (buf[1] << 8) | buf[2];
1601 freq_os = (buf[8] << 8) | buf[9];
1602 c->frequency = freq + freq_os;
1605 srate_os = (buf[10] << 8) | buf[11];
1606 c->symbol_rate = -1000 * srate_os + state->dcur.symbol_rate;
1610 static const struct dvb_frontend_ops cx24117_ops = {
1611 .delsys = { SYS_DVBS, SYS_DVBS2 },
1613 .name = "Conexant CX24117/CX24132",
1614 .frequency_min_hz = 950 * MHz,
1615 .frequency_max_hz = 2150 * MHz,
1616 .frequency_stepsize_hz = 1011 * kHz,
1617 .frequency_tolerance_hz = 5 * MHz,
1618 .symbol_rate_min = 1000000,
1619 .symbol_rate_max = 45000000,
1620 .caps = FE_CAN_INVERSION_AUTO |
1621 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1622 FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
1623 FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1624 FE_CAN_2G_MODULATION |
1625 FE_CAN_QPSK | FE_CAN_RECOVER
1628 .release = cx24117_release,
1630 .init = cx24117_initfe,
1631 .sleep = cx24117_sleep,
1632 .read_status = cx24117_read_status,
1633 .read_ber = cx24117_read_ber,
1634 .read_signal_strength = cx24117_read_signal_strength,
1635 .read_snr = cx24117_read_snr,
1636 .read_ucblocks = cx24117_read_ucblocks,
1637 .set_tone = cx24117_set_tone,
1638 .set_voltage = cx24117_set_voltage,
1639 .diseqc_send_master_cmd = cx24117_send_diseqc_msg,
1640 .diseqc_send_burst = cx24117_diseqc_send_burst,
1641 .get_frontend_algo = cx24117_get_algo,
1642 .tune = cx24117_tune,
1644 .set_frontend = cx24117_set_frontend,
1645 .get_frontend = cx24117_get_frontend,
1649 MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24117/cx24132 hardware");
1651 MODULE_LICENSE("GPL");
1652 MODULE_VERSION("1.1");
1653 MODULE_FIRMWARE(CX24117_DEFAULT_FIRMWARE);