1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver
5 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
8 #include "tda10071_priv.h"
10 static const struct dvb_frontend_ops tda10071_ops
;
13 * XXX: regmap_update_bits() does not fit our needs as it does not support
14 * partially volatile registers. Also it performs register read even mask is as
15 * wide as register value.
17 /* write single register with mask */
18 static int tda10071_wr_reg_mask(struct tda10071_dev
*dev
,
19 u8 reg
, u8 val
, u8 mask
)
24 /* no need for read if whole reg is written */
26 ret
= regmap_bulk_read(dev
->regmap
, reg
, &tmp
, 1);
35 return regmap_bulk_write(dev
->regmap
, reg
, &val
, 1);
38 /* execute firmware command */
39 static int tda10071_cmd_execute(struct tda10071_dev
*dev
,
40 struct tda10071_cmd
*cmd
)
42 struct i2c_client
*client
= dev
->client
;
51 mutex_lock(&dev
->cmd_execute_mutex
);
53 /* write cmd and args for firmware */
54 ret
= regmap_bulk_write(dev
->regmap
, 0x00, cmd
->args
, cmd
->len
);
56 goto error_mutex_unlock
;
58 /* start cmd execution */
59 ret
= regmap_write(dev
->regmap
, 0x1f, 1);
61 goto error_mutex_unlock
;
63 /* wait cmd execution terminate */
64 for (i
= 1000, uitmp
= 1; i
&& uitmp
; i
--) {
65 ret
= regmap_read(dev
->regmap
, 0x1f, &uitmp
);
67 goto error_mutex_unlock
;
69 usleep_range(200, 5000);
72 mutex_unlock(&dev
->cmd_execute_mutex
);
73 dev_dbg(&client
->dev
, "loop=%d\n", i
);
82 mutex_unlock(&dev
->cmd_execute_mutex
);
84 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
88 static int tda10071_set_tone(struct dvb_frontend
*fe
,
89 enum fe_sec_tone_mode fe_sec_tone_mode
)
91 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
92 struct i2c_client
*client
= dev
->client
;
93 struct tda10071_cmd cmd
;
102 dev_dbg(&client
->dev
, "tone_mode=%d\n", fe_sec_tone_mode
);
104 switch (fe_sec_tone_mode
) {
112 dev_dbg(&client
->dev
, "invalid fe_sec_tone_mode\n");
117 cmd
.args
[0] = CMD_LNB_PCB_CONFIG
;
123 ret
= tda10071_cmd_execute(dev
, &cmd
);
129 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
133 static int tda10071_set_voltage(struct dvb_frontend
*fe
,
134 enum fe_sec_voltage fe_sec_voltage
)
136 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
137 struct i2c_client
*client
= dev
->client
;
138 struct tda10071_cmd cmd
;
147 dev_dbg(&client
->dev
, "voltage=%d\n", fe_sec_voltage
);
149 switch (fe_sec_voltage
) {
156 case SEC_VOLTAGE_OFF
:
160 dev_dbg(&client
->dev
, "invalid fe_sec_voltage\n");
165 cmd
.args
[0] = CMD_LNB_SET_DC_LEVEL
;
167 cmd
.args
[2] = voltage
;
169 ret
= tda10071_cmd_execute(dev
, &cmd
);
175 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
179 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
180 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
182 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
183 struct i2c_client
*client
= dev
->client
;
184 struct tda10071_cmd cmd
;
193 dev_dbg(&client
->dev
, "msg_len=%d\n", diseqc_cmd
->msg_len
);
195 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
201 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
202 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
205 uitmp
= (uitmp
>> 0) & 1;
206 usleep_range(10000, 20000);
209 dev_dbg(&client
->dev
, "loop=%d\n", i
);
216 ret
= regmap_update_bits(dev
->regmap
, 0x47, 0x01, 0x00);
220 cmd
.args
[0] = CMD_LNB_SEND_DISEQC
;
226 cmd
.args
[6] = diseqc_cmd
->msg_len
;
227 memcpy(&cmd
.args
[7], diseqc_cmd
->msg
, diseqc_cmd
->msg_len
);
228 cmd
.len
= 7 + diseqc_cmd
->msg_len
;
229 ret
= tda10071_cmd_execute(dev
, &cmd
);
235 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
239 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend
*fe
,
240 struct dvb_diseqc_slave_reply
*reply
)
242 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
243 struct i2c_client
*client
= dev
->client
;
244 struct tda10071_cmd cmd
;
253 dev_dbg(&client
->dev
, "\n");
256 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
257 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
260 uitmp
= (uitmp
>> 1) & 1;
261 usleep_range(10000, 20000);
264 dev_dbg(&client
->dev
, "loop=%d\n", i
);
272 ret
= regmap_read(dev
->regmap
, 0x46, &uitmp
);
276 reply
->msg_len
= uitmp
& 0x1f; /* [4:0] */
277 if (reply
->msg_len
> sizeof(reply
->msg
))
278 reply
->msg_len
= sizeof(reply
->msg
); /* truncate API max */
281 cmd
.args
[0] = CMD_LNB_UPDATE_REPLY
;
284 ret
= tda10071_cmd_execute(dev
, &cmd
);
288 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, reply
->msg
,
295 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
299 static int tda10071_diseqc_send_burst(struct dvb_frontend
*fe
,
300 enum fe_sec_mini_cmd fe_sec_mini_cmd
)
302 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
303 struct i2c_client
*client
= dev
->client
;
304 struct tda10071_cmd cmd
;
314 dev_dbg(&client
->dev
, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd
);
316 switch (fe_sec_mini_cmd
) {
324 dev_dbg(&client
->dev
, "invalid fe_sec_mini_cmd\n");
330 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
331 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
334 uitmp
= (uitmp
>> 0) & 1;
335 usleep_range(10000, 20000);
338 dev_dbg(&client
->dev
, "loop=%d\n", i
);
345 ret
= regmap_update_bits(dev
->regmap
, 0x47, 0x01, 0x00);
349 cmd
.args
[0] = CMD_LNB_SEND_TONEBURST
;
353 ret
= tda10071_cmd_execute(dev
, &cmd
);
359 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
363 static int tda10071_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
365 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
366 struct i2c_client
*client
= dev
->client
;
367 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
368 struct tda10071_cmd cmd
;
380 ret
= regmap_read(dev
->regmap
, 0x39, &uitmp
);
384 /* 0x39[0] tuner PLL */
385 if (uitmp
& 0x02) /* demod PLL */
386 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
387 if (uitmp
& 0x04) /* viterbi or LDPC*/
388 *status
|= FE_HAS_VITERBI
;
389 if (uitmp
& 0x08) /* RS or BCH */
390 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
392 dev
->fe_status
= *status
;
394 /* signal strength */
395 if (dev
->fe_status
& FE_HAS_SIGNAL
) {
396 cmd
.args
[0] = CMD_GET_AGCACC
;
399 ret
= tda10071_cmd_execute(dev
, &cmd
);
403 /* input power estimate dBm */
404 ret
= regmap_read(dev
->regmap
, 0x50, &uitmp
);
408 c
->strength
.stat
[0].scale
= FE_SCALE_DECIBEL
;
409 c
->strength
.stat
[0].svalue
= (int) (uitmp
- 256) * 1000;
411 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
415 if (dev
->fe_status
& FE_HAS_VITERBI
) {
417 ret
= regmap_bulk_read(dev
->regmap
, 0x3a, buf
, 2);
421 c
->cnr
.stat
[0].scale
= FE_SCALE_DECIBEL
;
422 c
->cnr
.stat
[0].svalue
= (buf
[0] << 8 | buf
[1] << 0) * 100;
424 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
428 if (dev
->fe_status
& FE_HAS_LOCK
) {
429 /* TODO: report total bits/packets */
430 u8 delivery_system
, reg
, len
;
432 switch (dev
->delivery_system
) {
448 ret
= regmap_read(dev
->regmap
, reg
, &uitmp
);
452 if (dev
->meas_count
== uitmp
) {
453 dev_dbg(&client
->dev
, "meas not ready=%02x\n", uitmp
);
457 dev
->meas_count
= uitmp
;
460 cmd
.args
[0] = CMD_BER_UPDATE_COUNTERS
;
462 cmd
.args
[2] = delivery_system
;
464 ret
= tda10071_cmd_execute(dev
, &cmd
);
468 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, buf
, len
);
472 if (dev
->delivery_system
== SYS_DVBS
) {
473 dev
->dvbv3_ber
= buf
[0] << 24 | buf
[1] << 16 |
474 buf
[2] << 8 | buf
[3] << 0;
475 dev
->post_bit_error
+= buf
[0] << 24 | buf
[1] << 16 |
476 buf
[2] << 8 | buf
[3] << 0;
477 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
478 c
->post_bit_error
.stat
[0].uvalue
= dev
->post_bit_error
;
479 dev
->block_error
+= buf
[4] << 8 | buf
[5] << 0;
480 c
->block_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
481 c
->block_error
.stat
[0].uvalue
= dev
->block_error
;
483 dev
->dvbv3_ber
= buf
[0] << 8 | buf
[1] << 0;
484 dev
->post_bit_error
+= buf
[0] << 8 | buf
[1] << 0;
485 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
486 c
->post_bit_error
.stat
[0].uvalue
= dev
->post_bit_error
;
487 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
490 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
491 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
496 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
500 static int tda10071_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
502 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
504 if (c
->cnr
.stat
[0].scale
== FE_SCALE_DECIBEL
)
505 *snr
= div_s64(c
->cnr
.stat
[0].svalue
, 100);
511 static int tda10071_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
513 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
516 if (c
->strength
.stat
[0].scale
== FE_SCALE_DECIBEL
) {
517 uitmp
= div_s64(c
->strength
.stat
[0].svalue
, 1000) + 256;
518 uitmp
= clamp(uitmp
, 181U, 236U); /* -75dBm - -20dBm */
519 /* scale value to 0x0000-0xffff */
520 *strength
= (uitmp
-181) * 0xffff / (236-181);
527 static int tda10071_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
529 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
531 *ber
= dev
->dvbv3_ber
;
535 static int tda10071_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
537 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
539 if (c
->block_error
.stat
[0].scale
== FE_SCALE_COUNTER
)
540 *ucblocks
= c
->block_error
.stat
[0].uvalue
;
546 static int tda10071_set_frontend(struct dvb_frontend
*fe
)
548 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
549 struct i2c_client
*client
= dev
->client
;
550 struct tda10071_cmd cmd
;
551 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
553 u8 mode
, rolloff
, pilot
, inversion
, div
;
554 enum fe_modulation modulation
;
556 dev_dbg(&client
->dev
,
557 "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
558 c
->delivery_system
, c
->modulation
, c
->frequency
, c
->symbol_rate
,
559 c
->inversion
, c
->pilot
, c
->rolloff
);
561 dev
->delivery_system
= SYS_UNDEFINED
;
568 switch (c
->inversion
) {
576 /* 2 = auto; try first on then off
577 * 3 = auto; try first off then on */
581 dev_dbg(&client
->dev
, "invalid inversion\n");
586 switch (c
->delivery_system
) {
593 modulation
= c
->modulation
;
595 switch (c
->rolloff
) {
607 dev_dbg(&client
->dev
, "invalid rolloff\n");
623 dev_dbg(&client
->dev
, "invalid pilot\n");
629 dev_dbg(&client
->dev
, "invalid delivery_system\n");
634 for (i
= 0, mode
= 0xff; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
635 if (c
->delivery_system
== TDA10071_MODCOD
[i
].delivery_system
&&
636 modulation
== TDA10071_MODCOD
[i
].modulation
&&
637 c
->fec_inner
== TDA10071_MODCOD
[i
].fec
) {
638 mode
= TDA10071_MODCOD
[i
].val
;
639 dev_dbg(&client
->dev
, "mode found=%02x\n", mode
);
645 dev_dbg(&client
->dev
, "invalid parameter combination\n");
650 if (c
->symbol_rate
<= 5000000)
655 ret
= regmap_write(dev
->regmap
, 0x81, div
);
659 ret
= regmap_write(dev
->regmap
, 0xe3, div
);
663 cmd
.args
[0] = CMD_CHANGE_CHANNEL
;
666 cmd
.args
[3] = (c
->frequency
>> 16) & 0xff;
667 cmd
.args
[4] = (c
->frequency
>> 8) & 0xff;
668 cmd
.args
[5] = (c
->frequency
>> 0) & 0xff;
669 cmd
.args
[6] = ((c
->symbol_rate
/ 1000) >> 8) & 0xff;
670 cmd
.args
[7] = ((c
->symbol_rate
/ 1000) >> 0) & 0xff;
671 cmd
.args
[8] = ((tda10071_ops
.info
.frequency_tolerance_hz
/ 1000) >> 8) & 0xff;
672 cmd
.args
[9] = ((tda10071_ops
.info
.frequency_tolerance_hz
/ 1000) >> 0) & 0xff;
673 cmd
.args
[10] = rolloff
;
674 cmd
.args
[11] = inversion
;
675 cmd
.args
[12] = pilot
;
679 ret
= tda10071_cmd_execute(dev
, &cmd
);
683 dev
->delivery_system
= c
->delivery_system
;
687 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
691 static int tda10071_get_frontend(struct dvb_frontend
*fe
,
692 struct dtv_frontend_properties
*c
)
694 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
695 struct i2c_client
*client
= dev
->client
;
699 if (!dev
->warm
|| !(dev
->fe_status
& FE_HAS_LOCK
)) {
704 ret
= regmap_bulk_read(dev
->regmap
, 0x30, buf
, 5);
709 for (i
= 0; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
710 if (tmp
== TDA10071_MODCOD
[i
].val
) {
711 c
->modulation
= TDA10071_MODCOD
[i
].modulation
;
712 c
->fec_inner
= TDA10071_MODCOD
[i
].fec
;
713 c
->delivery_system
= TDA10071_MODCOD
[i
].delivery_system
;
717 switch ((buf
[1] >> 0) & 0x01) {
719 c
->inversion
= INVERSION_ON
;
722 c
->inversion
= INVERSION_OFF
;
726 switch ((buf
[1] >> 7) & 0x01) {
728 c
->pilot
= PILOT_OFF
;
735 c
->frequency
= (buf
[2] << 16) | (buf
[3] << 8) | (buf
[4] << 0);
737 ret
= regmap_bulk_read(dev
->regmap
, 0x52, buf
, 3);
741 c
->symbol_rate
= ((buf
[0] << 16) | (buf
[1] << 8) | (buf
[2] << 0)) * 1000;
745 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
749 static int tda10071_init(struct dvb_frontend
*fe
)
751 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
752 struct i2c_client
*client
= dev
->client
;
753 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
754 struct tda10071_cmd cmd
;
755 int ret
, i
, len
, remaining
, fw_size
;
757 const struct firmware
*fw
;
758 u8
*fw_file
= TDA10071_FIRMWARE
;
760 struct tda10071_reg_val_mask tab
[] = {
761 { 0xcd, 0x00, 0x07 },
762 { 0x80, 0x00, 0x02 },
763 { 0xcd, 0x00, 0xc0 },
764 { 0xce, 0x00, 0x1b },
765 { 0x9d, 0x00, 0x01 },
766 { 0x9d, 0x00, 0x02 },
767 { 0x9e, 0x00, 0x01 },
768 { 0x87, 0x00, 0x80 },
769 { 0xce, 0x00, 0x08 },
770 { 0xce, 0x00, 0x10 },
772 struct tda10071_reg_val_mask tab2
[] = {
773 { 0xf1, 0x70, 0xff },
774 { 0x88, dev
->pll_multiplier
, 0x3f },
775 { 0x89, 0x00, 0x10 },
776 { 0x89, 0x10, 0x10 },
777 { 0xc0, 0x01, 0x01 },
778 { 0xc0, 0x00, 0x01 },
779 { 0xe0, 0xff, 0xff },
780 { 0xe0, 0x00, 0xff },
781 { 0x96, 0x1e, 0x7e },
782 { 0x8b, 0x08, 0x08 },
783 { 0x8b, 0x00, 0x08 },
784 { 0x8f, 0x1a, 0x7e },
785 { 0x8c, 0x68, 0xff },
786 { 0x8d, 0x08, 0xff },
787 { 0x8e, 0x4c, 0xff },
788 { 0x8f, 0x01, 0x01 },
789 { 0x8b, 0x04, 0x04 },
790 { 0x8b, 0x00, 0x04 },
791 { 0x87, 0x05, 0x07 },
792 { 0x80, 0x00, 0x20 },
793 { 0xc8, 0x01, 0xff },
794 { 0xb4, 0x47, 0xff },
795 { 0xb5, 0x9c, 0xff },
796 { 0xb6, 0x7d, 0xff },
797 { 0xba, 0x00, 0x03 },
798 { 0xb7, 0x47, 0xff },
799 { 0xb8, 0x9c, 0xff },
800 { 0xb9, 0x7d, 0xff },
801 { 0xba, 0x00, 0x0c },
802 { 0xc8, 0x00, 0xff },
803 { 0xcd, 0x00, 0x04 },
804 { 0xcd, 0x00, 0x20 },
805 { 0xe8, 0x02, 0xff },
806 { 0xcf, 0x20, 0xff },
807 { 0x9b, 0xd7, 0xff },
808 { 0x9a, 0x01, 0x03 },
809 { 0xa8, 0x05, 0x0f },
810 { 0xa8, 0x65, 0xf0 },
811 { 0xa6, 0xa0, 0xf0 },
812 { 0x9d, 0x50, 0xfc },
813 { 0x9e, 0x20, 0xe0 },
814 { 0xa3, 0x1c, 0x7c },
815 { 0xd5, 0x03, 0x03 },
819 /* warm state - wake up device from sleep */
821 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
822 ret
= tda10071_wr_reg_mask(dev
, tab
[i
].reg
,
823 tab
[i
].val
, tab
[i
].mask
);
828 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
832 ret
= tda10071_cmd_execute(dev
, &cmd
);
836 /* cold state - try to download firmware */
838 /* request the firmware, this will block and timeout */
839 ret
= request_firmware(&fw
, fw_file
, &client
->dev
);
841 dev_err(&client
->dev
,
842 "did not find the firmware file '%s' (status %d). You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware\n",
848 for (i
= 0; i
< ARRAY_SIZE(tab2
); i
++) {
849 ret
= tda10071_wr_reg_mask(dev
, tab2
[i
].reg
,
850 tab2
[i
].val
, tab2
[i
].mask
);
852 goto error_release_firmware
;
855 /* download firmware */
856 ret
= regmap_write(dev
->regmap
, 0xe0, 0x7f);
858 goto error_release_firmware
;
860 ret
= regmap_write(dev
->regmap
, 0xf7, 0x81);
862 goto error_release_firmware
;
864 ret
= regmap_write(dev
->regmap
, 0xf8, 0x00);
866 goto error_release_firmware
;
868 ret
= regmap_write(dev
->regmap
, 0xf9, 0x00);
870 goto error_release_firmware
;
872 dev_info(&client
->dev
,
873 "found a '%s' in cold state, will try to load a firmware\n",
874 tda10071_ops
.info
.name
);
875 dev_info(&client
->dev
, "downloading firmware from file '%s'\n",
878 /* do not download last byte */
879 fw_size
= fw
->size
- 1;
881 for (remaining
= fw_size
; remaining
> 0;
882 remaining
-= (dev
->i2c_wr_max
- 1)) {
884 if (len
> (dev
->i2c_wr_max
- 1))
885 len
= (dev
->i2c_wr_max
- 1);
887 ret
= regmap_bulk_write(dev
->regmap
, 0xfa,
888 (u8
*) &fw
->data
[fw_size
- remaining
], len
);
890 dev_err(&client
->dev
,
891 "firmware download failed=%d\n", ret
);
892 goto error_release_firmware
;
895 release_firmware(fw
);
897 ret
= regmap_write(dev
->regmap
, 0xf7, 0x0c);
901 ret
= regmap_write(dev
->regmap
, 0xe0, 0x00);
905 /* wait firmware start */
908 /* firmware status */
909 ret
= regmap_read(dev
->regmap
, 0x51, &uitmp
);
914 dev_info(&client
->dev
, "firmware did not run\n");
921 cmd
.args
[0] = CMD_GET_FW_VERSION
;
923 ret
= tda10071_cmd_execute(dev
, &cmd
);
927 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, buf
, 4);
931 dev_info(&client
->dev
, "firmware version %d.%d.%d.%d\n",
932 buf
[0], buf
[1], buf
[2], buf
[3]);
933 dev_info(&client
->dev
, "found a '%s' in warm state\n",
934 tda10071_ops
.info
.name
);
936 ret
= regmap_bulk_read(dev
->regmap
, 0x81, buf
, 2);
940 cmd
.args
[0] = CMD_DEMOD_INIT
;
941 cmd
.args
[1] = ((dev
->clk
/ 1000) >> 8) & 0xff;
942 cmd
.args
[2] = ((dev
->clk
/ 1000) >> 0) & 0xff;
943 cmd
.args
[3] = buf
[0];
944 cmd
.args
[4] = buf
[1];
945 cmd
.args
[5] = dev
->pll_multiplier
;
946 cmd
.args
[6] = dev
->spec_inv
;
949 ret
= tda10071_cmd_execute(dev
, &cmd
);
953 if (dev
->tuner_i2c_addr
)
954 tmp
= dev
->tuner_i2c_addr
;
958 cmd
.args
[0] = CMD_TUNER_INIT
;
974 ret
= tda10071_cmd_execute(dev
, &cmd
);
978 cmd
.args
[0] = CMD_MPEG_CONFIG
;
980 cmd
.args
[2] = dev
->ts_mode
;
985 ret
= tda10071_cmd_execute(dev
, &cmd
);
989 ret
= regmap_update_bits(dev
->regmap
, 0xf0, 0x01, 0x01);
993 cmd
.args
[0] = CMD_LNB_CONFIG
;
1005 ret
= tda10071_cmd_execute(dev
, &cmd
);
1009 cmd
.args
[0] = CMD_BER_CONTROL
;
1014 ret
= tda10071_cmd_execute(dev
, &cmd
);
1019 /* init stats here in order signal app which stats are supported */
1020 c
->strength
.len
= 1;
1021 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1023 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1024 c
->post_bit_error
.len
= 1;
1025 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1026 c
->block_error
.len
= 1;
1027 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1030 error_release_firmware
:
1031 release_firmware(fw
);
1033 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1037 static int tda10071_sleep(struct dvb_frontend
*fe
)
1039 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
1040 struct i2c_client
*client
= dev
->client
;
1041 struct tda10071_cmd cmd
;
1043 struct tda10071_reg_val_mask tab
[] = {
1044 { 0xcd, 0x07, 0x07 },
1045 { 0x80, 0x02, 0x02 },
1046 { 0xcd, 0xc0, 0xc0 },
1047 { 0xce, 0x1b, 0x1b },
1048 { 0x9d, 0x01, 0x01 },
1049 { 0x9d, 0x02, 0x02 },
1050 { 0x9e, 0x01, 0x01 },
1051 { 0x87, 0x80, 0x80 },
1052 { 0xce, 0x08, 0x08 },
1053 { 0xce, 0x10, 0x10 },
1061 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
1065 ret
= tda10071_cmd_execute(dev
, &cmd
);
1069 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
1070 ret
= tda10071_wr_reg_mask(dev
, tab
[i
].reg
, tab
[i
].val
,
1078 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1082 static int tda10071_get_tune_settings(struct dvb_frontend
*fe
,
1083 struct dvb_frontend_tune_settings
*s
)
1085 s
->min_delay_ms
= 8000;
1092 static const struct dvb_frontend_ops tda10071_ops
= {
1093 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1095 .name
= "NXP TDA10071",
1096 .frequency_min_hz
= 950 * MHz
,
1097 .frequency_max_hz
= 2150 * MHz
,
1098 .frequency_tolerance_hz
= 5 * MHz
,
1099 .symbol_rate_min
= 1000000,
1100 .symbol_rate_max
= 45000000,
1101 .caps
= FE_CAN_INVERSION_AUTO
|
1113 FE_CAN_2G_MODULATION
1116 .get_tune_settings
= tda10071_get_tune_settings
,
1118 .init
= tda10071_init
,
1119 .sleep
= tda10071_sleep
,
1121 .set_frontend
= tda10071_set_frontend
,
1122 .get_frontend
= tda10071_get_frontend
,
1124 .read_status
= tda10071_read_status
,
1125 .read_snr
= tda10071_read_snr
,
1126 .read_signal_strength
= tda10071_read_signal_strength
,
1127 .read_ber
= tda10071_read_ber
,
1128 .read_ucblocks
= tda10071_read_ucblocks
,
1130 .diseqc_send_master_cmd
= tda10071_diseqc_send_master_cmd
,
1131 .diseqc_recv_slave_reply
= tda10071_diseqc_recv_slave_reply
,
1132 .diseqc_send_burst
= tda10071_diseqc_send_burst
,
1134 .set_tone
= tda10071_set_tone
,
1135 .set_voltage
= tda10071_set_voltage
,
1138 static struct dvb_frontend
*tda10071_get_dvb_frontend(struct i2c_client
*client
)
1140 struct tda10071_dev
*dev
= i2c_get_clientdata(client
);
1142 dev_dbg(&client
->dev
, "\n");
1147 static int tda10071_probe(struct i2c_client
*client
,
1148 const struct i2c_device_id
*id
)
1150 struct tda10071_dev
*dev
;
1151 struct tda10071_platform_data
*pdata
= client
->dev
.platform_data
;
1154 static const struct regmap_config regmap_config
= {
1159 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1165 dev
->client
= client
;
1166 mutex_init(&dev
->cmd_execute_mutex
);
1167 dev
->clk
= pdata
->clk
;
1168 dev
->i2c_wr_max
= pdata
->i2c_wr_max
;
1169 dev
->ts_mode
= pdata
->ts_mode
;
1170 dev
->spec_inv
= pdata
->spec_inv
;
1171 dev
->pll_multiplier
= pdata
->pll_multiplier
;
1172 dev
->tuner_i2c_addr
= pdata
->tuner_i2c_addr
;
1173 dev
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
1174 if (IS_ERR(dev
->regmap
)) {
1175 ret
= PTR_ERR(dev
->regmap
);
1180 ret
= regmap_read(dev
->regmap
, 0xff, &uitmp
);
1183 if (uitmp
!= 0x0f) {
1189 ret
= regmap_read(dev
->regmap
, 0xdd, &uitmp
);
1192 if (uitmp
!= 0x00) {
1198 ret
= regmap_read(dev
->regmap
, 0xfe, &uitmp
);
1201 if (uitmp
!= 0x01) {
1206 /* create dvb_frontend */
1207 memcpy(&dev
->fe
.ops
, &tda10071_ops
, sizeof(struct dvb_frontend_ops
));
1208 dev
->fe
.demodulator_priv
= dev
;
1209 i2c_set_clientdata(client
, dev
);
1211 /* setup callbacks */
1212 pdata
->get_dvb_frontend
= tda10071_get_dvb_frontend
;
1214 dev_info(&client
->dev
, "NXP TDA10071 successfully identified\n");
1219 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1223 static int tda10071_remove(struct i2c_client
*client
)
1225 struct tda10071_dev
*dev
= i2c_get_clientdata(client
);
1227 dev_dbg(&client
->dev
, "\n");
1233 static const struct i2c_device_id tda10071_id_table
[] = {
1234 {"tda10071_cx24118", 0},
1237 MODULE_DEVICE_TABLE(i2c
, tda10071_id_table
);
1239 static struct i2c_driver tda10071_driver
= {
1242 .suppress_bind_attrs
= true,
1244 .probe
= tda10071_probe
,
1245 .remove
= tda10071_remove
,
1246 .id_table
= tda10071_id_table
,
1249 module_i2c_driver(tda10071_driver
);
1251 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1252 MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
1253 MODULE_LICENSE("GPL");
1254 MODULE_FIRMWARE(TDA10071_FIRMWARE
);