2 * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver
4 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "tda10071_priv.h"
23 static const struct dvb_frontend_ops tda10071_ops
;
26 * XXX: regmap_update_bits() does not fit our needs as it does not support
27 * partially volatile registers. Also it performs register read even mask is as
28 * wide as register value.
30 /* write single register with mask */
31 static int tda10071_wr_reg_mask(struct tda10071_dev
*dev
,
32 u8 reg
, u8 val
, u8 mask
)
37 /* no need for read if whole reg is written */
39 ret
= regmap_bulk_read(dev
->regmap
, reg
, &tmp
, 1);
48 return regmap_bulk_write(dev
->regmap
, reg
, &val
, 1);
51 /* execute firmware command */
52 static int tda10071_cmd_execute(struct tda10071_dev
*dev
,
53 struct tda10071_cmd
*cmd
)
55 struct i2c_client
*client
= dev
->client
;
64 mutex_lock(&dev
->cmd_execute_mutex
);
66 /* write cmd and args for firmware */
67 ret
= regmap_bulk_write(dev
->regmap
, 0x00, cmd
->args
, cmd
->len
);
69 goto error_mutex_unlock
;
71 /* start cmd execution */
72 ret
= regmap_write(dev
->regmap
, 0x1f, 1);
74 goto error_mutex_unlock
;
76 /* wait cmd execution terminate */
77 for (i
= 1000, uitmp
= 1; i
&& uitmp
; i
--) {
78 ret
= regmap_read(dev
->regmap
, 0x1f, &uitmp
);
80 goto error_mutex_unlock
;
82 usleep_range(200, 5000);
85 mutex_unlock(&dev
->cmd_execute_mutex
);
86 dev_dbg(&client
->dev
, "loop=%d\n", i
);
95 mutex_unlock(&dev
->cmd_execute_mutex
);
97 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
101 static int tda10071_set_tone(struct dvb_frontend
*fe
,
102 enum fe_sec_tone_mode fe_sec_tone_mode
)
104 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
105 struct i2c_client
*client
= dev
->client
;
106 struct tda10071_cmd cmd
;
115 dev_dbg(&client
->dev
, "tone_mode=%d\n", fe_sec_tone_mode
);
117 switch (fe_sec_tone_mode
) {
125 dev_dbg(&client
->dev
, "invalid fe_sec_tone_mode\n");
130 cmd
.args
[0] = CMD_LNB_PCB_CONFIG
;
136 ret
= tda10071_cmd_execute(dev
, &cmd
);
142 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
146 static int tda10071_set_voltage(struct dvb_frontend
*fe
,
147 enum fe_sec_voltage fe_sec_voltage
)
149 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
150 struct i2c_client
*client
= dev
->client
;
151 struct tda10071_cmd cmd
;
160 dev_dbg(&client
->dev
, "voltage=%d\n", fe_sec_voltage
);
162 switch (fe_sec_voltage
) {
169 case SEC_VOLTAGE_OFF
:
173 dev_dbg(&client
->dev
, "invalid fe_sec_voltage\n");
178 cmd
.args
[0] = CMD_LNB_SET_DC_LEVEL
;
180 cmd
.args
[2] = voltage
;
182 ret
= tda10071_cmd_execute(dev
, &cmd
);
188 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
192 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
193 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
195 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
196 struct i2c_client
*client
= dev
->client
;
197 struct tda10071_cmd cmd
;
206 dev_dbg(&client
->dev
, "msg_len=%d\n", diseqc_cmd
->msg_len
);
208 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
214 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
215 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
218 uitmp
= (uitmp
>> 0) & 1;
219 usleep_range(10000, 20000);
222 dev_dbg(&client
->dev
, "loop=%d\n", i
);
229 ret
= regmap_update_bits(dev
->regmap
, 0x47, 0x01, 0x00);
233 cmd
.args
[0] = CMD_LNB_SEND_DISEQC
;
239 cmd
.args
[6] = diseqc_cmd
->msg_len
;
240 memcpy(&cmd
.args
[7], diseqc_cmd
->msg
, diseqc_cmd
->msg_len
);
241 cmd
.len
= 7 + diseqc_cmd
->msg_len
;
242 ret
= tda10071_cmd_execute(dev
, &cmd
);
248 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
252 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend
*fe
,
253 struct dvb_diseqc_slave_reply
*reply
)
255 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
256 struct i2c_client
*client
= dev
->client
;
257 struct tda10071_cmd cmd
;
266 dev_dbg(&client
->dev
, "\n");
269 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
270 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
273 uitmp
= (uitmp
>> 1) & 1;
274 usleep_range(10000, 20000);
277 dev_dbg(&client
->dev
, "loop=%d\n", i
);
285 ret
= regmap_read(dev
->regmap
, 0x46, &uitmp
);
289 reply
->msg_len
= uitmp
& 0x1f; /* [4:0] */
290 if (reply
->msg_len
> sizeof(reply
->msg
))
291 reply
->msg_len
= sizeof(reply
->msg
); /* truncate API max */
294 cmd
.args
[0] = CMD_LNB_UPDATE_REPLY
;
297 ret
= tda10071_cmd_execute(dev
, &cmd
);
301 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, reply
->msg
,
308 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
312 static int tda10071_diseqc_send_burst(struct dvb_frontend
*fe
,
313 enum fe_sec_mini_cmd fe_sec_mini_cmd
)
315 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
316 struct i2c_client
*client
= dev
->client
;
317 struct tda10071_cmd cmd
;
327 dev_dbg(&client
->dev
, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd
);
329 switch (fe_sec_mini_cmd
) {
337 dev_dbg(&client
->dev
, "invalid fe_sec_mini_cmd\n");
343 for (i
= 500, uitmp
= 0; i
&& !uitmp
; i
--) {
344 ret
= regmap_read(dev
->regmap
, 0x47, &uitmp
);
347 uitmp
= (uitmp
>> 0) & 1;
348 usleep_range(10000, 20000);
351 dev_dbg(&client
->dev
, "loop=%d\n", i
);
358 ret
= regmap_update_bits(dev
->regmap
, 0x47, 0x01, 0x00);
362 cmd
.args
[0] = CMD_LNB_SEND_TONEBURST
;
366 ret
= tda10071_cmd_execute(dev
, &cmd
);
372 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
376 static int tda10071_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
378 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
379 struct i2c_client
*client
= dev
->client
;
380 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
381 struct tda10071_cmd cmd
;
393 ret
= regmap_read(dev
->regmap
, 0x39, &uitmp
);
397 /* 0x39[0] tuner PLL */
398 if (uitmp
& 0x02) /* demod PLL */
399 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
400 if (uitmp
& 0x04) /* viterbi or LDPC*/
401 *status
|= FE_HAS_VITERBI
;
402 if (uitmp
& 0x08) /* RS or BCH */
403 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
405 dev
->fe_status
= *status
;
407 /* signal strength */
408 if (dev
->fe_status
& FE_HAS_SIGNAL
) {
409 cmd
.args
[0] = CMD_GET_AGCACC
;
412 ret
= tda10071_cmd_execute(dev
, &cmd
);
416 /* input power estimate dBm */
417 ret
= regmap_read(dev
->regmap
, 0x50, &uitmp
);
421 c
->strength
.stat
[0].scale
= FE_SCALE_DECIBEL
;
422 c
->strength
.stat
[0].svalue
= (int) (uitmp
- 256) * 1000;
424 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
428 if (dev
->fe_status
& FE_HAS_VITERBI
) {
430 ret
= regmap_bulk_read(dev
->regmap
, 0x3a, buf
, 2);
434 c
->cnr
.stat
[0].scale
= FE_SCALE_DECIBEL
;
435 c
->cnr
.stat
[0].svalue
= (buf
[0] << 8 | buf
[1] << 0) * 100;
437 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
441 if (dev
->fe_status
& FE_HAS_LOCK
) {
442 /* TODO: report total bits/packets */
443 u8 delivery_system
, reg
, len
;
445 switch (dev
->delivery_system
) {
461 ret
= regmap_read(dev
->regmap
, reg
, &uitmp
);
465 if (dev
->meas_count
== uitmp
) {
466 dev_dbg(&client
->dev
, "meas not ready=%02x\n", uitmp
);
470 dev
->meas_count
= uitmp
;
473 cmd
.args
[0] = CMD_BER_UPDATE_COUNTERS
;
475 cmd
.args
[2] = delivery_system
;
477 ret
= tda10071_cmd_execute(dev
, &cmd
);
481 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, buf
, len
);
485 if (dev
->delivery_system
== SYS_DVBS
) {
486 dev
->dvbv3_ber
= buf
[0] << 24 | buf
[1] << 16 |
487 buf
[2] << 8 | buf
[3] << 0;
488 dev
->post_bit_error
+= buf
[0] << 24 | buf
[1] << 16 |
489 buf
[2] << 8 | buf
[3] << 0;
490 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
491 c
->post_bit_error
.stat
[0].uvalue
= dev
->post_bit_error
;
492 dev
->block_error
+= buf
[4] << 8 | buf
[5] << 0;
493 c
->block_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
494 c
->block_error
.stat
[0].uvalue
= dev
->block_error
;
496 dev
->dvbv3_ber
= buf
[0] << 8 | buf
[1] << 0;
497 dev
->post_bit_error
+= buf
[0] << 8 | buf
[1] << 0;
498 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
499 c
->post_bit_error
.stat
[0].uvalue
= dev
->post_bit_error
;
500 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
503 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
504 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
509 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
513 static int tda10071_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
515 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
517 if (c
->cnr
.stat
[0].scale
== FE_SCALE_DECIBEL
)
518 *snr
= div_s64(c
->cnr
.stat
[0].svalue
, 100);
524 static int tda10071_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
526 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
529 if (c
->strength
.stat
[0].scale
== FE_SCALE_DECIBEL
) {
530 uitmp
= div_s64(c
->strength
.stat
[0].svalue
, 1000) + 256;
531 uitmp
= clamp(uitmp
, 181U, 236U); /* -75dBm - -20dBm */
532 /* scale value to 0x0000-0xffff */
533 *strength
= (uitmp
-181) * 0xffff / (236-181);
540 static int tda10071_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
542 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
544 *ber
= dev
->dvbv3_ber
;
548 static int tda10071_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
550 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
552 if (c
->block_error
.stat
[0].scale
== FE_SCALE_COUNTER
)
553 *ucblocks
= c
->block_error
.stat
[0].uvalue
;
559 static int tda10071_set_frontend(struct dvb_frontend
*fe
)
561 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
562 struct i2c_client
*client
= dev
->client
;
563 struct tda10071_cmd cmd
;
564 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
566 u8 mode
, rolloff
, pilot
, inversion
, div
;
567 enum fe_modulation modulation
;
569 dev_dbg(&client
->dev
,
570 "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
571 c
->delivery_system
, c
->modulation
, c
->frequency
, c
->symbol_rate
,
572 c
->inversion
, c
->pilot
, c
->rolloff
);
574 dev
->delivery_system
= SYS_UNDEFINED
;
581 switch (c
->inversion
) {
589 /* 2 = auto; try first on then off
590 * 3 = auto; try first off then on */
594 dev_dbg(&client
->dev
, "invalid inversion\n");
599 switch (c
->delivery_system
) {
606 modulation
= c
->modulation
;
608 switch (c
->rolloff
) {
620 dev_dbg(&client
->dev
, "invalid rolloff\n");
636 dev_dbg(&client
->dev
, "invalid pilot\n");
642 dev_dbg(&client
->dev
, "invalid delivery_system\n");
647 for (i
= 0, mode
= 0xff; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
648 if (c
->delivery_system
== TDA10071_MODCOD
[i
].delivery_system
&&
649 modulation
== TDA10071_MODCOD
[i
].modulation
&&
650 c
->fec_inner
== TDA10071_MODCOD
[i
].fec
) {
651 mode
= TDA10071_MODCOD
[i
].val
;
652 dev_dbg(&client
->dev
, "mode found=%02x\n", mode
);
658 dev_dbg(&client
->dev
, "invalid parameter combination\n");
663 if (c
->symbol_rate
<= 5000000)
668 ret
= regmap_write(dev
->regmap
, 0x81, div
);
672 ret
= regmap_write(dev
->regmap
, 0xe3, div
);
676 cmd
.args
[0] = CMD_CHANGE_CHANNEL
;
679 cmd
.args
[3] = (c
->frequency
>> 16) & 0xff;
680 cmd
.args
[4] = (c
->frequency
>> 8) & 0xff;
681 cmd
.args
[5] = (c
->frequency
>> 0) & 0xff;
682 cmd
.args
[6] = ((c
->symbol_rate
/ 1000) >> 8) & 0xff;
683 cmd
.args
[7] = ((c
->symbol_rate
/ 1000) >> 0) & 0xff;
684 cmd
.args
[8] = (tda10071_ops
.info
.frequency_tolerance
>> 8) & 0xff;
685 cmd
.args
[9] = (tda10071_ops
.info
.frequency_tolerance
>> 0) & 0xff;
686 cmd
.args
[10] = rolloff
;
687 cmd
.args
[11] = inversion
;
688 cmd
.args
[12] = pilot
;
692 ret
= tda10071_cmd_execute(dev
, &cmd
);
696 dev
->delivery_system
= c
->delivery_system
;
700 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
704 static int tda10071_get_frontend(struct dvb_frontend
*fe
,
705 struct dtv_frontend_properties
*c
)
707 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
708 struct i2c_client
*client
= dev
->client
;
712 if (!dev
->warm
|| !(dev
->fe_status
& FE_HAS_LOCK
)) {
717 ret
= regmap_bulk_read(dev
->regmap
, 0x30, buf
, 5);
722 for (i
= 0; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
723 if (tmp
== TDA10071_MODCOD
[i
].val
) {
724 c
->modulation
= TDA10071_MODCOD
[i
].modulation
;
725 c
->fec_inner
= TDA10071_MODCOD
[i
].fec
;
726 c
->delivery_system
= TDA10071_MODCOD
[i
].delivery_system
;
730 switch ((buf
[1] >> 0) & 0x01) {
732 c
->inversion
= INVERSION_ON
;
735 c
->inversion
= INVERSION_OFF
;
739 switch ((buf
[1] >> 7) & 0x01) {
741 c
->pilot
= PILOT_OFF
;
748 c
->frequency
= (buf
[2] << 16) | (buf
[3] << 8) | (buf
[4] << 0);
750 ret
= regmap_bulk_read(dev
->regmap
, 0x52, buf
, 3);
754 c
->symbol_rate
= ((buf
[0] << 16) | (buf
[1] << 8) | (buf
[2] << 0)) * 1000;
758 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
762 static int tda10071_init(struct dvb_frontend
*fe
)
764 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
765 struct i2c_client
*client
= dev
->client
;
766 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
767 struct tda10071_cmd cmd
;
768 int ret
, i
, len
, remaining
, fw_size
;
770 const struct firmware
*fw
;
771 u8
*fw_file
= TDA10071_FIRMWARE
;
773 struct tda10071_reg_val_mask tab
[] = {
774 { 0xcd, 0x00, 0x07 },
775 { 0x80, 0x00, 0x02 },
776 { 0xcd, 0x00, 0xc0 },
777 { 0xce, 0x00, 0x1b },
778 { 0x9d, 0x00, 0x01 },
779 { 0x9d, 0x00, 0x02 },
780 { 0x9e, 0x00, 0x01 },
781 { 0x87, 0x00, 0x80 },
782 { 0xce, 0x00, 0x08 },
783 { 0xce, 0x00, 0x10 },
785 struct tda10071_reg_val_mask tab2
[] = {
786 { 0xf1, 0x70, 0xff },
787 { 0x88, dev
->pll_multiplier
, 0x3f },
788 { 0x89, 0x00, 0x10 },
789 { 0x89, 0x10, 0x10 },
790 { 0xc0, 0x01, 0x01 },
791 { 0xc0, 0x00, 0x01 },
792 { 0xe0, 0xff, 0xff },
793 { 0xe0, 0x00, 0xff },
794 { 0x96, 0x1e, 0x7e },
795 { 0x8b, 0x08, 0x08 },
796 { 0x8b, 0x00, 0x08 },
797 { 0x8f, 0x1a, 0x7e },
798 { 0x8c, 0x68, 0xff },
799 { 0x8d, 0x08, 0xff },
800 { 0x8e, 0x4c, 0xff },
801 { 0x8f, 0x01, 0x01 },
802 { 0x8b, 0x04, 0x04 },
803 { 0x8b, 0x00, 0x04 },
804 { 0x87, 0x05, 0x07 },
805 { 0x80, 0x00, 0x20 },
806 { 0xc8, 0x01, 0xff },
807 { 0xb4, 0x47, 0xff },
808 { 0xb5, 0x9c, 0xff },
809 { 0xb6, 0x7d, 0xff },
810 { 0xba, 0x00, 0x03 },
811 { 0xb7, 0x47, 0xff },
812 { 0xb8, 0x9c, 0xff },
813 { 0xb9, 0x7d, 0xff },
814 { 0xba, 0x00, 0x0c },
815 { 0xc8, 0x00, 0xff },
816 { 0xcd, 0x00, 0x04 },
817 { 0xcd, 0x00, 0x20 },
818 { 0xe8, 0x02, 0xff },
819 { 0xcf, 0x20, 0xff },
820 { 0x9b, 0xd7, 0xff },
821 { 0x9a, 0x01, 0x03 },
822 { 0xa8, 0x05, 0x0f },
823 { 0xa8, 0x65, 0xf0 },
824 { 0xa6, 0xa0, 0xf0 },
825 { 0x9d, 0x50, 0xfc },
826 { 0x9e, 0x20, 0xe0 },
827 { 0xa3, 0x1c, 0x7c },
828 { 0xd5, 0x03, 0x03 },
832 /* warm state - wake up device from sleep */
834 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
835 ret
= tda10071_wr_reg_mask(dev
, tab
[i
].reg
,
836 tab
[i
].val
, tab
[i
].mask
);
841 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
845 ret
= tda10071_cmd_execute(dev
, &cmd
);
849 /* cold state - try to download firmware */
851 /* request the firmware, this will block and timeout */
852 ret
= request_firmware(&fw
, fw_file
, &client
->dev
);
854 dev_err(&client
->dev
,
855 "did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n",
861 for (i
= 0; i
< ARRAY_SIZE(tab2
); i
++) {
862 ret
= tda10071_wr_reg_mask(dev
, tab2
[i
].reg
,
863 tab2
[i
].val
, tab2
[i
].mask
);
865 goto error_release_firmware
;
868 /* download firmware */
869 ret
= regmap_write(dev
->regmap
, 0xe0, 0x7f);
871 goto error_release_firmware
;
873 ret
= regmap_write(dev
->regmap
, 0xf7, 0x81);
875 goto error_release_firmware
;
877 ret
= regmap_write(dev
->regmap
, 0xf8, 0x00);
879 goto error_release_firmware
;
881 ret
= regmap_write(dev
->regmap
, 0xf9, 0x00);
883 goto error_release_firmware
;
885 dev_info(&client
->dev
,
886 "found a '%s' in cold state, will try to load a firmware\n",
887 tda10071_ops
.info
.name
);
888 dev_info(&client
->dev
, "downloading firmware from file '%s'\n",
891 /* do not download last byte */
892 fw_size
= fw
->size
- 1;
894 for (remaining
= fw_size
; remaining
> 0;
895 remaining
-= (dev
->i2c_wr_max
- 1)) {
897 if (len
> (dev
->i2c_wr_max
- 1))
898 len
= (dev
->i2c_wr_max
- 1);
900 ret
= regmap_bulk_write(dev
->regmap
, 0xfa,
901 (u8
*) &fw
->data
[fw_size
- remaining
], len
);
903 dev_err(&client
->dev
,
904 "firmware download failed=%d\n", ret
);
905 goto error_release_firmware
;
908 release_firmware(fw
);
910 ret
= regmap_write(dev
->regmap
, 0xf7, 0x0c);
914 ret
= regmap_write(dev
->regmap
, 0xe0, 0x00);
918 /* wait firmware start */
921 /* firmware status */
922 ret
= regmap_read(dev
->regmap
, 0x51, &uitmp
);
927 dev_info(&client
->dev
, "firmware did not run\n");
934 cmd
.args
[0] = CMD_GET_FW_VERSION
;
936 ret
= tda10071_cmd_execute(dev
, &cmd
);
940 ret
= regmap_bulk_read(dev
->regmap
, cmd
.len
, buf
, 4);
944 dev_info(&client
->dev
, "firmware version %d.%d.%d.%d\n",
945 buf
[0], buf
[1], buf
[2], buf
[3]);
946 dev_info(&client
->dev
, "found a '%s' in warm state\n",
947 tda10071_ops
.info
.name
);
949 ret
= regmap_bulk_read(dev
->regmap
, 0x81, buf
, 2);
953 cmd
.args
[0] = CMD_DEMOD_INIT
;
954 cmd
.args
[1] = ((dev
->clk
/ 1000) >> 8) & 0xff;
955 cmd
.args
[2] = ((dev
->clk
/ 1000) >> 0) & 0xff;
956 cmd
.args
[3] = buf
[0];
957 cmd
.args
[4] = buf
[1];
958 cmd
.args
[5] = dev
->pll_multiplier
;
959 cmd
.args
[6] = dev
->spec_inv
;
962 ret
= tda10071_cmd_execute(dev
, &cmd
);
966 if (dev
->tuner_i2c_addr
)
967 tmp
= dev
->tuner_i2c_addr
;
971 cmd
.args
[0] = CMD_TUNER_INIT
;
987 ret
= tda10071_cmd_execute(dev
, &cmd
);
991 cmd
.args
[0] = CMD_MPEG_CONFIG
;
993 cmd
.args
[2] = dev
->ts_mode
;
998 ret
= tda10071_cmd_execute(dev
, &cmd
);
1002 ret
= regmap_update_bits(dev
->regmap
, 0xf0, 0x01, 0x01);
1006 cmd
.args
[0] = CMD_LNB_CONFIG
;
1018 ret
= tda10071_cmd_execute(dev
, &cmd
);
1022 cmd
.args
[0] = CMD_BER_CONTROL
;
1027 ret
= tda10071_cmd_execute(dev
, &cmd
);
1032 /* init stats here in order signal app which stats are supported */
1033 c
->strength
.len
= 1;
1034 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1036 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1037 c
->post_bit_error
.len
= 1;
1038 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1039 c
->block_error
.len
= 1;
1040 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1043 error_release_firmware
:
1044 release_firmware(fw
);
1046 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1050 static int tda10071_sleep(struct dvb_frontend
*fe
)
1052 struct tda10071_dev
*dev
= fe
->demodulator_priv
;
1053 struct i2c_client
*client
= dev
->client
;
1054 struct tda10071_cmd cmd
;
1056 struct tda10071_reg_val_mask tab
[] = {
1057 { 0xcd, 0x07, 0x07 },
1058 { 0x80, 0x02, 0x02 },
1059 { 0xcd, 0xc0, 0xc0 },
1060 { 0xce, 0x1b, 0x1b },
1061 { 0x9d, 0x01, 0x01 },
1062 { 0x9d, 0x02, 0x02 },
1063 { 0x9e, 0x01, 0x01 },
1064 { 0x87, 0x80, 0x80 },
1065 { 0xce, 0x08, 0x08 },
1066 { 0xce, 0x10, 0x10 },
1074 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
1078 ret
= tda10071_cmd_execute(dev
, &cmd
);
1082 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
1083 ret
= tda10071_wr_reg_mask(dev
, tab
[i
].reg
, tab
[i
].val
,
1091 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1095 static int tda10071_get_tune_settings(struct dvb_frontend
*fe
,
1096 struct dvb_frontend_tune_settings
*s
)
1098 s
->min_delay_ms
= 8000;
1105 static const struct dvb_frontend_ops tda10071_ops
= {
1106 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1108 .name
= "NXP TDA10071",
1109 .frequency_min
= 950000,
1110 .frequency_max
= 2150000,
1111 .frequency_tolerance
= 5000,
1112 .symbol_rate_min
= 1000000,
1113 .symbol_rate_max
= 45000000,
1114 .caps
= FE_CAN_INVERSION_AUTO
|
1126 FE_CAN_2G_MODULATION
1129 .get_tune_settings
= tda10071_get_tune_settings
,
1131 .init
= tda10071_init
,
1132 .sleep
= tda10071_sleep
,
1134 .set_frontend
= tda10071_set_frontend
,
1135 .get_frontend
= tda10071_get_frontend
,
1137 .read_status
= tda10071_read_status
,
1138 .read_snr
= tda10071_read_snr
,
1139 .read_signal_strength
= tda10071_read_signal_strength
,
1140 .read_ber
= tda10071_read_ber
,
1141 .read_ucblocks
= tda10071_read_ucblocks
,
1143 .diseqc_send_master_cmd
= tda10071_diseqc_send_master_cmd
,
1144 .diseqc_recv_slave_reply
= tda10071_diseqc_recv_slave_reply
,
1145 .diseqc_send_burst
= tda10071_diseqc_send_burst
,
1147 .set_tone
= tda10071_set_tone
,
1148 .set_voltage
= tda10071_set_voltage
,
1151 static struct dvb_frontend
*tda10071_get_dvb_frontend(struct i2c_client
*client
)
1153 struct tda10071_dev
*dev
= i2c_get_clientdata(client
);
1155 dev_dbg(&client
->dev
, "\n");
1160 static int tda10071_probe(struct i2c_client
*client
,
1161 const struct i2c_device_id
*id
)
1163 struct tda10071_dev
*dev
;
1164 struct tda10071_platform_data
*pdata
= client
->dev
.platform_data
;
1167 static const struct regmap_config regmap_config
= {
1172 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1178 dev
->client
= client
;
1179 mutex_init(&dev
->cmd_execute_mutex
);
1180 dev
->clk
= pdata
->clk
;
1181 dev
->i2c_wr_max
= pdata
->i2c_wr_max
;
1182 dev
->ts_mode
= pdata
->ts_mode
;
1183 dev
->spec_inv
= pdata
->spec_inv
;
1184 dev
->pll_multiplier
= pdata
->pll_multiplier
;
1185 dev
->tuner_i2c_addr
= pdata
->tuner_i2c_addr
;
1186 dev
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
1187 if (IS_ERR(dev
->regmap
)) {
1188 ret
= PTR_ERR(dev
->regmap
);
1193 ret
= regmap_read(dev
->regmap
, 0xff, &uitmp
);
1196 if (uitmp
!= 0x0f) {
1202 ret
= regmap_read(dev
->regmap
, 0xdd, &uitmp
);
1205 if (uitmp
!= 0x00) {
1211 ret
= regmap_read(dev
->regmap
, 0xfe, &uitmp
);
1214 if (uitmp
!= 0x01) {
1219 /* create dvb_frontend */
1220 memcpy(&dev
->fe
.ops
, &tda10071_ops
, sizeof(struct dvb_frontend_ops
));
1221 dev
->fe
.demodulator_priv
= dev
;
1222 i2c_set_clientdata(client
, dev
);
1224 /* setup callbacks */
1225 pdata
->get_dvb_frontend
= tda10071_get_dvb_frontend
;
1227 dev_info(&client
->dev
, "NXP TDA10071 successfully identified\n");
1232 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1236 static int tda10071_remove(struct i2c_client
*client
)
1238 struct tda10071_dev
*dev
= i2c_get_clientdata(client
);
1240 dev_dbg(&client
->dev
, "\n");
1246 static const struct i2c_device_id tda10071_id_table
[] = {
1247 {"tda10071_cx24118", 0},
1250 MODULE_DEVICE_TABLE(i2c
, tda10071_id_table
);
1252 static struct i2c_driver tda10071_driver
= {
1255 .suppress_bind_attrs
= true,
1257 .probe
= tda10071_probe
,
1258 .remove
= tda10071_remove
,
1259 .id_table
= tda10071_id_table
,
1262 module_i2c_driver(tda10071_driver
);
1264 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1265 MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
1266 MODULE_LICENSE("GPL");
1267 MODULE_FIRMWARE(TDA10071_FIRMWARE
);