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 struct dvb_frontend_ops tda10071_ops
;
25 /* write multiple registers */
26 static int tda10071_wr_regs(struct tda10071_priv
*priv
, u8 reg
, u8
*val
,
31 struct i2c_msg msg
[1] = {
33 .addr
= priv
->cfg
.i2c_address
,
41 memcpy(&buf
[1], val
, len
);
43 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
47 dev_warn(&priv
->i2c
->dev
, "%s: i2c wr failed=%d reg=%02x " \
48 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
54 /* read multiple registers */
55 static int tda10071_rd_regs(struct tda10071_priv
*priv
, u8 reg
, u8
*val
,
60 struct i2c_msg msg
[2] = {
62 .addr
= priv
->cfg
.i2c_address
,
67 .addr
= priv
->cfg
.i2c_address
,
74 ret
= i2c_transfer(priv
->i2c
, msg
, 2);
76 memcpy(val
, buf
, len
);
79 dev_warn(&priv
->i2c
->dev
, "%s: i2c rd failed=%d reg=%02x " \
80 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
86 /* write single register */
87 static int tda10071_wr_reg(struct tda10071_priv
*priv
, u8 reg
, u8 val
)
89 return tda10071_wr_regs(priv
, reg
, &val
, 1);
92 /* read single register */
93 static int tda10071_rd_reg(struct tda10071_priv
*priv
, u8 reg
, u8
*val
)
95 return tda10071_rd_regs(priv
, reg
, val
, 1);
98 /* write single register with mask */
99 int tda10071_wr_reg_mask(struct tda10071_priv
*priv
, u8 reg
, u8 val
, u8 mask
)
104 /* no need for read if whole reg is written */
106 ret
= tda10071_rd_regs(priv
, reg
, &tmp
, 1);
115 return tda10071_wr_regs(priv
, reg
, &val
, 1);
118 /* read single register with mask */
119 int tda10071_rd_reg_mask(struct tda10071_priv
*priv
, u8 reg
, u8
*val
, u8 mask
)
124 ret
= tda10071_rd_regs(priv
, reg
, &tmp
, 1);
130 /* find position of the first bit */
131 for (i
= 0; i
< 8; i
++) {
132 if ((mask
>> i
) & 0x01)
140 /* execute firmware command */
141 static int tda10071_cmd_execute(struct tda10071_priv
*priv
,
142 struct tda10071_cmd
*cmd
)
152 /* write cmd and args for firmware */
153 ret
= tda10071_wr_regs(priv
, 0x00, cmd
->args
, cmd
->len
);
157 /* start cmd execution */
158 ret
= tda10071_wr_reg(priv
, 0x1f, 1);
162 /* wait cmd execution terminate */
163 for (i
= 1000, tmp
= 1; i
&& tmp
; i
--) {
164 ret
= tda10071_rd_reg(priv
, 0x1f, &tmp
);
168 usleep_range(200, 5000);
171 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
180 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
184 static int tda10071_set_tone(struct dvb_frontend
*fe
,
185 fe_sec_tone_mode_t fe_sec_tone_mode
)
187 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
188 struct tda10071_cmd cmd
;
197 dev_dbg(&priv
->i2c
->dev
, "%s: tone_mode=%d\n", __func__
,
200 switch (fe_sec_tone_mode
) {
208 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_tone_mode\n",
214 cmd
.args
[0] = CMD_LNB_PCB_CONFIG
;
220 ret
= tda10071_cmd_execute(priv
, &cmd
);
226 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
230 static int tda10071_set_voltage(struct dvb_frontend
*fe
,
231 fe_sec_voltage_t fe_sec_voltage
)
233 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
234 struct tda10071_cmd cmd
;
243 dev_dbg(&priv
->i2c
->dev
, "%s: voltage=%d\n", __func__
, fe_sec_voltage
);
245 switch (fe_sec_voltage
) {
252 case SEC_VOLTAGE_OFF
:
256 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_voltage\n",
262 cmd
.args
[0] = CMD_LNB_SET_DC_LEVEL
;
264 cmd
.args
[2] = voltage
;
266 ret
= tda10071_cmd_execute(priv
, &cmd
);
272 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
276 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
277 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
279 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
280 struct tda10071_cmd cmd
;
289 dev_dbg(&priv
->i2c
->dev
, "%s: msg_len=%d\n", __func__
,
290 diseqc_cmd
->msg_len
);
292 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
298 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
299 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x01);
303 usleep_range(10000, 20000);
306 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
313 ret
= tda10071_wr_reg_mask(priv
, 0x47, 0x00, 0x01);
317 cmd
.args
[0] = CMD_LNB_SEND_DISEQC
;
323 cmd
.args
[6] = diseqc_cmd
->msg_len
;
324 memcpy(&cmd
.args
[7], diseqc_cmd
->msg
, diseqc_cmd
->msg_len
);
325 cmd
.len
= 7 + diseqc_cmd
->msg_len
;
326 ret
= tda10071_cmd_execute(priv
, &cmd
);
332 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
336 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend
*fe
,
337 struct dvb_diseqc_slave_reply
*reply
)
339 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
340 struct tda10071_cmd cmd
;
349 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
352 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
353 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x02);
357 usleep_range(10000, 20000);
360 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
368 ret
= tda10071_rd_reg(priv
, 0x46, &tmp
);
372 reply
->msg_len
= tmp
& 0x1f; /* [4:0] */;
373 if (reply
->msg_len
> sizeof(reply
->msg
))
374 reply
->msg_len
= sizeof(reply
->msg
); /* truncate API max */
377 cmd
.args
[0] = CMD_LNB_UPDATE_REPLY
;
380 ret
= tda10071_cmd_execute(priv
, &cmd
);
384 ret
= tda10071_rd_regs(priv
, cmd
.len
, reply
->msg
, reply
->msg_len
);
390 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
394 static int tda10071_diseqc_send_burst(struct dvb_frontend
*fe
,
395 fe_sec_mini_cmd_t fe_sec_mini_cmd
)
397 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
398 struct tda10071_cmd cmd
;
407 dev_dbg(&priv
->i2c
->dev
, "%s: fe_sec_mini_cmd=%d\n", __func__
,
410 switch (fe_sec_mini_cmd
) {
418 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_mini_cmd\n",
425 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
426 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x01);
430 usleep_range(10000, 20000);
433 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
440 ret
= tda10071_wr_reg_mask(priv
, 0x47, 0x00, 0x01);
444 cmd
.args
[0] = CMD_LNB_SEND_TONEBURST
;
448 ret
= tda10071_cmd_execute(priv
, &cmd
);
454 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
458 static int tda10071_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
460 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
471 ret
= tda10071_rd_reg(priv
, 0x39, &tmp
);
475 if (tmp
& 0x01) /* tuner PLL */
476 *status
|= FE_HAS_SIGNAL
;
477 if (tmp
& 0x02) /* demod PLL */
478 *status
|= FE_HAS_CARRIER
;
479 if (tmp
& 0x04) /* viterbi or LDPC*/
480 *status
|= FE_HAS_VITERBI
;
481 if (tmp
& 0x08) /* RS or BCH */
482 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
484 priv
->fe_status
= *status
;
488 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
492 static int tda10071_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
494 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
498 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
504 ret
= tda10071_rd_regs(priv
, 0x3a, buf
, 2);
509 *snr
= buf
[0] << 8 | buf
[1];
513 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
517 static int tda10071_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
519 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
520 struct tda10071_cmd cmd
;
524 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
530 cmd
.args
[0] = CMD_GET_AGCACC
;
533 ret
= tda10071_cmd_execute(priv
, &cmd
);
537 /* input power estimate dBm */
538 ret
= tda10071_rd_reg(priv
, 0x50, &tmp
);
543 tmp
= 181; /* -75 dBm */
545 tmp
= 236; /* -20 dBm */
547 /* scale value to 0x0000-0xffff */
548 *strength
= (tmp
-181) * 0xffff / (236-181);
552 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
556 static int tda10071_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
558 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
559 struct tda10071_cmd cmd
;
563 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
564 *ber
= priv
->ber
= 0;
569 switch (priv
->delivery_system
) {
581 *ber
= priv
->ber
= 0;
585 ret
= tda10071_rd_reg(priv
, reg
, &tmp
);
589 if (priv
->meas_count
[i
] == tmp
) {
590 dev_dbg(&priv
->i2c
->dev
, "%s: meas not ready=%02x\n", __func__
,
595 priv
->meas_count
[i
] = tmp
;
598 cmd
.args
[0] = CMD_BER_UPDATE_COUNTERS
;
602 ret
= tda10071_cmd_execute(priv
, &cmd
);
606 ret
= tda10071_rd_regs(priv
, cmd
.len
, buf
, len
);
610 if (priv
->delivery_system
== SYS_DVBS
) {
611 *ber
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
612 priv
->ucb
+= (buf
[4] << 8) | buf
[5];
614 *ber
= (buf
[0] << 8) | buf
[1];
620 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
624 static int tda10071_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
626 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
629 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
634 /* UCB is updated when BER is read. Assume BER is read anyway. */
636 *ucblocks
= priv
->ucb
;
640 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
644 static int tda10071_set_frontend(struct dvb_frontend
*fe
)
646 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
647 struct tda10071_cmd cmd
;
648 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
650 u8 mode
, rolloff
, pilot
, inversion
, div
;
652 dev_dbg(&priv
->i2c
->dev
, "%s: delivery_system=%d modulation=%d " \
653 "frequency=%d symbol_rate=%d inversion=%d pilot=%d " \
654 "rolloff=%d\n", __func__
, c
->delivery_system
, c
->modulation
,
655 c
->frequency
, c
->symbol_rate
, c
->inversion
, c
->pilot
,
658 priv
->delivery_system
= SYS_UNDEFINED
;
665 switch (c
->inversion
) {
673 /* 2 = auto; try first on then off
674 * 3 = auto; try first off then on */
678 dev_dbg(&priv
->i2c
->dev
, "%s: invalid inversion\n", __func__
);
683 switch (c
->delivery_system
) {
689 switch (c
->rolloff
) {
701 dev_dbg(&priv
->i2c
->dev
, "%s: invalid rolloff\n",
718 dev_dbg(&priv
->i2c
->dev
, "%s: invalid pilot\n",
725 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
731 for (i
= 0, mode
= 0xff; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
732 if (c
->delivery_system
== TDA10071_MODCOD
[i
].delivery_system
&&
733 c
->modulation
== TDA10071_MODCOD
[i
].modulation
&&
734 c
->fec_inner
== TDA10071_MODCOD
[i
].fec
) {
735 mode
= TDA10071_MODCOD
[i
].val
;
736 dev_dbg(&priv
->i2c
->dev
, "%s: mode found=%02x\n",
743 dev_dbg(&priv
->i2c
->dev
, "%s: invalid parameter combination\n",
749 if (c
->symbol_rate
<= 5000000)
754 ret
= tda10071_wr_reg(priv
, 0x81, div
);
758 ret
= tda10071_wr_reg(priv
, 0xe3, div
);
762 cmd
.args
[0] = CMD_CHANGE_CHANNEL
;
765 cmd
.args
[3] = (c
->frequency
>> 16) & 0xff;
766 cmd
.args
[4] = (c
->frequency
>> 8) & 0xff;
767 cmd
.args
[5] = (c
->frequency
>> 0) & 0xff;
768 cmd
.args
[6] = ((c
->symbol_rate
/ 1000) >> 8) & 0xff;
769 cmd
.args
[7] = ((c
->symbol_rate
/ 1000) >> 0) & 0xff;
770 cmd
.args
[8] = (tda10071_ops
.info
.frequency_tolerance
>> 8) & 0xff;
771 cmd
.args
[9] = (tda10071_ops
.info
.frequency_tolerance
>> 0) & 0xff;
772 cmd
.args
[10] = rolloff
;
773 cmd
.args
[11] = inversion
;
774 cmd
.args
[12] = pilot
;
778 ret
= tda10071_cmd_execute(priv
, &cmd
);
782 priv
->delivery_system
= c
->delivery_system
;
786 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
790 static int tda10071_get_frontend(struct dvb_frontend
*fe
)
792 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
793 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
797 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
802 ret
= tda10071_rd_regs(priv
, 0x30, buf
, 5);
807 for (i
= 0; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
808 if (tmp
== TDA10071_MODCOD
[i
].val
) {
809 c
->modulation
= TDA10071_MODCOD
[i
].modulation
;
810 c
->fec_inner
= TDA10071_MODCOD
[i
].fec
;
811 c
->delivery_system
= TDA10071_MODCOD
[i
].delivery_system
;
815 switch ((buf
[1] >> 0) & 0x01) {
817 c
->inversion
= INVERSION_OFF
;
820 c
->inversion
= INVERSION_ON
;
824 switch ((buf
[1] >> 7) & 0x01) {
826 c
->pilot
= PILOT_OFF
;
833 c
->frequency
= (buf
[2] << 16) | (buf
[3] << 8) | (buf
[4] << 0);
835 ret
= tda10071_rd_regs(priv
, 0x52, buf
, 3);
839 c
->symbol_rate
= (buf
[0] << 16) | (buf
[1] << 8) | (buf
[2] << 0);
843 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
847 static int tda10071_init(struct dvb_frontend
*fe
)
849 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
850 struct tda10071_cmd cmd
;
851 int ret
, i
, len
, remaining
, fw_size
;
852 const struct firmware
*fw
;
853 u8
*fw_file
= TDA10071_DEFAULT_FIRMWARE
;
855 struct tda10071_reg_val_mask tab
[] = {
856 { 0xcd, 0x00, 0x07 },
857 { 0x80, 0x00, 0x02 },
858 { 0xcd, 0x00, 0xc0 },
859 { 0xce, 0x00, 0x1b },
860 { 0x9d, 0x00, 0x01 },
861 { 0x9d, 0x00, 0x02 },
862 { 0x9e, 0x00, 0x01 },
863 { 0x87, 0x00, 0x80 },
864 { 0xce, 0x00, 0x08 },
865 { 0xce, 0x00, 0x10 },
867 struct tda10071_reg_val_mask tab2
[] = {
868 { 0xf1, 0x70, 0xff },
869 { 0x88, priv
->cfg
.pll_multiplier
, 0x3f },
870 { 0x89, 0x00, 0x10 },
871 { 0x89, 0x10, 0x10 },
872 { 0xc0, 0x01, 0x01 },
873 { 0xc0, 0x00, 0x01 },
874 { 0xe0, 0xff, 0xff },
875 { 0xe0, 0x00, 0xff },
876 { 0x96, 0x1e, 0x7e },
877 { 0x8b, 0x08, 0x08 },
878 { 0x8b, 0x00, 0x08 },
879 { 0x8f, 0x1a, 0x7e },
880 { 0x8c, 0x68, 0xff },
881 { 0x8d, 0x08, 0xff },
882 { 0x8e, 0x4c, 0xff },
883 { 0x8f, 0x01, 0x01 },
884 { 0x8b, 0x04, 0x04 },
885 { 0x8b, 0x00, 0x04 },
886 { 0x87, 0x05, 0x07 },
887 { 0x80, 0x00, 0x20 },
888 { 0xc8, 0x01, 0xff },
889 { 0xb4, 0x47, 0xff },
890 { 0xb5, 0x9c, 0xff },
891 { 0xb6, 0x7d, 0xff },
892 { 0xba, 0x00, 0x03 },
893 { 0xb7, 0x47, 0xff },
894 { 0xb8, 0x9c, 0xff },
895 { 0xb9, 0x7d, 0xff },
896 { 0xba, 0x00, 0x0c },
897 { 0xc8, 0x00, 0xff },
898 { 0xcd, 0x00, 0x04 },
899 { 0xcd, 0x00, 0x20 },
900 { 0xe8, 0x02, 0xff },
901 { 0xcf, 0x20, 0xff },
902 { 0x9b, 0xd7, 0xff },
903 { 0x9a, 0x01, 0x03 },
904 { 0xa8, 0x05, 0x0f },
905 { 0xa8, 0x65, 0xf0 },
906 { 0xa6, 0xa0, 0xf0 },
907 { 0x9d, 0x50, 0xfc },
908 { 0x9e, 0x20, 0xe0 },
909 { 0xa3, 0x1c, 0x7c },
910 { 0xd5, 0x03, 0x03 },
913 /* firmware status */
914 ret
= tda10071_rd_reg(priv
, 0x51, &tmp
);
919 /* warm state - wake up device from sleep */
922 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
923 ret
= tda10071_wr_reg_mask(priv
, tab
[i
].reg
,
924 tab
[i
].val
, tab
[i
].mask
);
929 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
933 ret
= tda10071_cmd_execute(priv
, &cmd
);
937 /* cold state - try to download firmware */
940 /* request the firmware, this will block and timeout */
941 ret
= request_firmware(&fw
, fw_file
, priv
->i2c
->dev
.parent
);
943 dev_err(&priv
->i2c
->dev
, "%s: did not find the " \
944 "firmware file. (%s) Please see " \
945 "linux/Documentation/dvb/ for more " \
946 "details on firmware-problems. (%d)\n",
947 KBUILD_MODNAME
, fw_file
, ret
);
952 for (i
= 0; i
< ARRAY_SIZE(tab2
); i
++) {
953 ret
= tda10071_wr_reg_mask(priv
, tab2
[i
].reg
,
954 tab2
[i
].val
, tab2
[i
].mask
);
956 goto error_release_firmware
;
959 /* download firmware */
960 ret
= tda10071_wr_reg(priv
, 0xe0, 0x7f);
962 goto error_release_firmware
;
964 ret
= tda10071_wr_reg(priv
, 0xf7, 0x81);
966 goto error_release_firmware
;
968 ret
= tda10071_wr_reg(priv
, 0xf8, 0x00);
970 goto error_release_firmware
;
972 ret
= tda10071_wr_reg(priv
, 0xf9, 0x00);
974 goto error_release_firmware
;
976 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in cold state, " \
977 "will try to load a firmware\n", KBUILD_MODNAME
,
978 tda10071_ops
.info
.name
);
979 dev_info(&priv
->i2c
->dev
, "%s: downloading firmware from " \
980 "file '%s'\n", KBUILD_MODNAME
, fw_file
);
982 /* do not download last byte */
983 fw_size
= fw
->size
- 1;
985 for (remaining
= fw_size
; remaining
> 0;
986 remaining
-= (priv
->cfg
.i2c_wr_max
- 1)) {
988 if (len
> (priv
->cfg
.i2c_wr_max
- 1))
989 len
= (priv
->cfg
.i2c_wr_max
- 1);
991 ret
= tda10071_wr_regs(priv
, 0xfa,
992 (u8
*) &fw
->data
[fw_size
- remaining
], len
);
994 dev_err(&priv
->i2c
->dev
, "%s: firmware " \
995 "download failed=%d\n",
996 KBUILD_MODNAME
, ret
);
998 goto error_release_firmware
;
1001 release_firmware(fw
);
1003 ret
= tda10071_wr_reg(priv
, 0xf7, 0x0c);
1007 ret
= tda10071_wr_reg(priv
, 0xe0, 0x00);
1011 /* wait firmware start */
1014 /* firmware status */
1015 ret
= tda10071_rd_reg(priv
, 0x51, &tmp
);
1020 dev_info(&priv
->i2c
->dev
, "%s: firmware did not run\n",
1028 cmd
.args
[0] = CMD_GET_FW_VERSION
;
1030 ret
= tda10071_cmd_execute(priv
, &cmd
);
1034 ret
= tda10071_rd_regs(priv
, cmd
.len
, buf
, 4);
1038 dev_info(&priv
->i2c
->dev
, "%s: firmware version %d.%d.%d.%d\n",
1039 KBUILD_MODNAME
, buf
[0], buf
[1], buf
[2], buf
[3]);
1040 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in warm state\n",
1041 KBUILD_MODNAME
, tda10071_ops
.info
.name
);
1043 ret
= tda10071_rd_regs(priv
, 0x81, buf
, 2);
1047 cmd
.args
[0] = CMD_DEMOD_INIT
;
1048 cmd
.args
[1] = ((priv
->cfg
.xtal
/ 1000) >> 8) & 0xff;
1049 cmd
.args
[2] = ((priv
->cfg
.xtal
/ 1000) >> 0) & 0xff;
1050 cmd
.args
[3] = buf
[0];
1051 cmd
.args
[4] = buf
[1];
1052 cmd
.args
[5] = priv
->cfg
.pll_multiplier
;
1053 cmd
.args
[6] = priv
->cfg
.spec_inv
;
1056 ret
= tda10071_cmd_execute(priv
, &cmd
);
1060 cmd
.args
[0] = CMD_TUNER_INIT
;
1070 cmd
.args
[10] = 0x00;
1071 cmd
.args
[11] = 0x00;
1072 cmd
.args
[12] = 0x00;
1073 cmd
.args
[13] = 0x00;
1074 cmd
.args
[14] = 0x00;
1076 ret
= tda10071_cmd_execute(priv
, &cmd
);
1080 cmd
.args
[0] = CMD_MPEG_CONFIG
;
1082 cmd
.args
[2] = priv
->cfg
.ts_mode
;
1087 ret
= tda10071_cmd_execute(priv
, &cmd
);
1091 ret
= tda10071_wr_reg_mask(priv
, 0xf0, 0x01, 0x01);
1095 cmd
.args
[0] = CMD_LNB_CONFIG
;
1107 ret
= tda10071_cmd_execute(priv
, &cmd
);
1111 cmd
.args
[0] = CMD_BER_CONTROL
;
1116 ret
= tda10071_cmd_execute(priv
, &cmd
);
1122 error_release_firmware
:
1123 release_firmware(fw
);
1125 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1129 static int tda10071_sleep(struct dvb_frontend
*fe
)
1131 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
1132 struct tda10071_cmd cmd
;
1134 struct tda10071_reg_val_mask tab
[] = {
1135 { 0xcd, 0x07, 0x07 },
1136 { 0x80, 0x02, 0x02 },
1137 { 0xcd, 0xc0, 0xc0 },
1138 { 0xce, 0x1b, 0x1b },
1139 { 0x9d, 0x01, 0x01 },
1140 { 0x9d, 0x02, 0x02 },
1141 { 0x9e, 0x01, 0x01 },
1142 { 0x87, 0x80, 0x80 },
1143 { 0xce, 0x08, 0x08 },
1144 { 0xce, 0x10, 0x10 },
1152 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
1156 ret
= tda10071_cmd_execute(priv
, &cmd
);
1160 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
1161 ret
= tda10071_wr_reg_mask(priv
, tab
[i
].reg
, tab
[i
].val
,
1169 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1173 static int tda10071_get_tune_settings(struct dvb_frontend
*fe
,
1174 struct dvb_frontend_tune_settings
*s
)
1176 s
->min_delay_ms
= 8000;
1183 static void tda10071_release(struct dvb_frontend
*fe
)
1185 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
1189 struct dvb_frontend
*tda10071_attach(const struct tda10071_config
*config
,
1190 struct i2c_adapter
*i2c
)
1193 struct tda10071_priv
*priv
= NULL
;
1196 /* allocate memory for the internal priv */
1197 priv
= kzalloc(sizeof(struct tda10071_priv
), GFP_KERNEL
);
1203 /* setup the priv */
1205 memcpy(&priv
->cfg
, config
, sizeof(struct tda10071_config
));
1208 ret
= tda10071_rd_reg(priv
, 0xff, &tmp
);
1209 if (ret
|| tmp
!= 0x0f)
1213 ret
= tda10071_rd_reg(priv
, 0xdd, &tmp
);
1214 if (ret
|| tmp
!= 0x00)
1218 ret
= tda10071_rd_reg(priv
, 0xfe, &tmp
);
1219 if (ret
|| tmp
!= 0x01)
1222 /* create dvb_frontend */
1223 memcpy(&priv
->fe
.ops
, &tda10071_ops
, sizeof(struct dvb_frontend_ops
));
1224 priv
->fe
.demodulator_priv
= priv
;
1228 dev_dbg(&i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1232 EXPORT_SYMBOL(tda10071_attach
);
1234 static struct dvb_frontend_ops tda10071_ops
= {
1235 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1237 .name
= "NXP TDA10071",
1238 .frequency_min
= 950000,
1239 .frequency_max
= 2150000,
1240 .frequency_tolerance
= 5000,
1241 .symbol_rate_min
= 1000000,
1242 .symbol_rate_max
= 45000000,
1243 .caps
= FE_CAN_INVERSION_AUTO
|
1255 FE_CAN_2G_MODULATION
1258 .release
= tda10071_release
,
1260 .get_tune_settings
= tda10071_get_tune_settings
,
1262 .init
= tda10071_init
,
1263 .sleep
= tda10071_sleep
,
1265 .set_frontend
= tda10071_set_frontend
,
1266 .get_frontend
= tda10071_get_frontend
,
1268 .read_status
= tda10071_read_status
,
1269 .read_snr
= tda10071_read_snr
,
1270 .read_signal_strength
= tda10071_read_signal_strength
,
1271 .read_ber
= tda10071_read_ber
,
1272 .read_ucblocks
= tda10071_read_ucblocks
,
1274 .diseqc_send_master_cmd
= tda10071_diseqc_send_master_cmd
,
1275 .diseqc_recv_slave_reply
= tda10071_diseqc_recv_slave_reply
,
1276 .diseqc_send_burst
= tda10071_diseqc_send_burst
,
1278 .set_tone
= tda10071_set_tone
,
1279 .set_voltage
= tda10071_set_voltage
,
1282 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1283 MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
1284 MODULE_LICENSE("GPL");