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 /* Max transfer size done by I2C transfer functions */
24 #define MAX_XFER_SIZE 64
26 static struct dvb_frontend_ops tda10071_ops
;
28 /* write multiple registers */
29 static int tda10071_wr_regs(struct tda10071_priv
*priv
, u8 reg
, u8
*val
,
33 u8 buf
[MAX_XFER_SIZE
];
34 struct i2c_msg msg
[1] = {
36 .addr
= priv
->cfg
.demod_i2c_addr
,
43 if (1 + len
> sizeof(buf
)) {
44 dev_warn(&priv
->i2c
->dev
,
45 "%s: i2c wr reg=%04x: len=%d is too big!\n",
46 KBUILD_MODNAME
, reg
, len
);
51 memcpy(&buf
[1], val
, len
);
53 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
57 dev_warn(&priv
->i2c
->dev
, "%s: i2c wr failed=%d reg=%02x " \
58 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
64 /* read multiple registers */
65 static int tda10071_rd_regs(struct tda10071_priv
*priv
, u8 reg
, u8
*val
,
69 u8 buf
[MAX_XFER_SIZE
];
70 struct i2c_msg msg
[2] = {
72 .addr
= priv
->cfg
.demod_i2c_addr
,
77 .addr
= priv
->cfg
.demod_i2c_addr
,
84 if (len
> sizeof(buf
)) {
85 dev_warn(&priv
->i2c
->dev
,
86 "%s: i2c wr reg=%04x: len=%d is too big!\n",
87 KBUILD_MODNAME
, reg
, len
);
91 ret
= i2c_transfer(priv
->i2c
, msg
, 2);
93 memcpy(val
, buf
, len
);
96 dev_warn(&priv
->i2c
->dev
, "%s: i2c rd failed=%d reg=%02x " \
97 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
103 /* write single register */
104 static int tda10071_wr_reg(struct tda10071_priv
*priv
, u8 reg
, u8 val
)
106 return tda10071_wr_regs(priv
, reg
, &val
, 1);
109 /* read single register */
110 static int tda10071_rd_reg(struct tda10071_priv
*priv
, u8 reg
, u8
*val
)
112 return tda10071_rd_regs(priv
, reg
, val
, 1);
115 /* write single register with mask */
116 static int tda10071_wr_reg_mask(struct tda10071_priv
*priv
,
117 u8 reg
, u8 val
, u8 mask
)
122 /* no need for read if whole reg is written */
124 ret
= tda10071_rd_regs(priv
, reg
, &tmp
, 1);
133 return tda10071_wr_regs(priv
, reg
, &val
, 1);
136 /* read single register with mask */
137 static int tda10071_rd_reg_mask(struct tda10071_priv
*priv
,
138 u8 reg
, u8
*val
, u8 mask
)
143 ret
= tda10071_rd_regs(priv
, reg
, &tmp
, 1);
149 /* find position of the first bit */
150 for (i
= 0; i
< 8; i
++) {
151 if ((mask
>> i
) & 0x01)
159 /* execute firmware command */
160 static int tda10071_cmd_execute(struct tda10071_priv
*priv
,
161 struct tda10071_cmd
*cmd
)
171 /* write cmd and args for firmware */
172 ret
= tda10071_wr_regs(priv
, 0x00, cmd
->args
, cmd
->len
);
176 /* start cmd execution */
177 ret
= tda10071_wr_reg(priv
, 0x1f, 1);
181 /* wait cmd execution terminate */
182 for (i
= 1000, tmp
= 1; i
&& tmp
; i
--) {
183 ret
= tda10071_rd_reg(priv
, 0x1f, &tmp
);
187 usleep_range(200, 5000);
190 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
199 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
203 static int tda10071_set_tone(struct dvb_frontend
*fe
,
204 fe_sec_tone_mode_t fe_sec_tone_mode
)
206 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
207 struct tda10071_cmd cmd
;
216 dev_dbg(&priv
->i2c
->dev
, "%s: tone_mode=%d\n", __func__
,
219 switch (fe_sec_tone_mode
) {
227 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_tone_mode\n",
233 cmd
.args
[0] = CMD_LNB_PCB_CONFIG
;
239 ret
= tda10071_cmd_execute(priv
, &cmd
);
245 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
249 static int tda10071_set_voltage(struct dvb_frontend
*fe
,
250 fe_sec_voltage_t fe_sec_voltage
)
252 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
253 struct tda10071_cmd cmd
;
262 dev_dbg(&priv
->i2c
->dev
, "%s: voltage=%d\n", __func__
, fe_sec_voltage
);
264 switch (fe_sec_voltage
) {
271 case SEC_VOLTAGE_OFF
:
275 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_voltage\n",
281 cmd
.args
[0] = CMD_LNB_SET_DC_LEVEL
;
283 cmd
.args
[2] = voltage
;
285 ret
= tda10071_cmd_execute(priv
, &cmd
);
291 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
295 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
296 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
298 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
299 struct tda10071_cmd cmd
;
308 dev_dbg(&priv
->i2c
->dev
, "%s: msg_len=%d\n", __func__
,
309 diseqc_cmd
->msg_len
);
311 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
317 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
318 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x01);
322 usleep_range(10000, 20000);
325 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
332 ret
= tda10071_wr_reg_mask(priv
, 0x47, 0x00, 0x01);
336 cmd
.args
[0] = CMD_LNB_SEND_DISEQC
;
342 cmd
.args
[6] = diseqc_cmd
->msg_len
;
343 memcpy(&cmd
.args
[7], diseqc_cmd
->msg
, diseqc_cmd
->msg_len
);
344 cmd
.len
= 7 + diseqc_cmd
->msg_len
;
345 ret
= tda10071_cmd_execute(priv
, &cmd
);
351 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
355 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend
*fe
,
356 struct dvb_diseqc_slave_reply
*reply
)
358 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
359 struct tda10071_cmd cmd
;
368 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
371 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
372 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x02);
376 usleep_range(10000, 20000);
379 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
387 ret
= tda10071_rd_reg(priv
, 0x46, &tmp
);
391 reply
->msg_len
= tmp
& 0x1f; /* [4:0] */
392 if (reply
->msg_len
> sizeof(reply
->msg
))
393 reply
->msg_len
= sizeof(reply
->msg
); /* truncate API max */
396 cmd
.args
[0] = CMD_LNB_UPDATE_REPLY
;
399 ret
= tda10071_cmd_execute(priv
, &cmd
);
403 ret
= tda10071_rd_regs(priv
, cmd
.len
, reply
->msg
, reply
->msg_len
);
409 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
413 static int tda10071_diseqc_send_burst(struct dvb_frontend
*fe
,
414 fe_sec_mini_cmd_t fe_sec_mini_cmd
)
416 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
417 struct tda10071_cmd cmd
;
426 dev_dbg(&priv
->i2c
->dev
, "%s: fe_sec_mini_cmd=%d\n", __func__
,
429 switch (fe_sec_mini_cmd
) {
437 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_mini_cmd\n",
444 for (i
= 500, tmp
= 0; i
&& !tmp
; i
--) {
445 ret
= tda10071_rd_reg_mask(priv
, 0x47, &tmp
, 0x01);
449 usleep_range(10000, 20000);
452 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
459 ret
= tda10071_wr_reg_mask(priv
, 0x47, 0x00, 0x01);
463 cmd
.args
[0] = CMD_LNB_SEND_TONEBURST
;
467 ret
= tda10071_cmd_execute(priv
, &cmd
);
473 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
477 static int tda10071_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
479 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
490 ret
= tda10071_rd_reg(priv
, 0x39, &tmp
);
494 if (tmp
& 0x01) /* tuner PLL */
495 *status
|= FE_HAS_SIGNAL
;
496 if (tmp
& 0x02) /* demod PLL */
497 *status
|= FE_HAS_CARRIER
;
498 if (tmp
& 0x04) /* viterbi or LDPC*/
499 *status
|= FE_HAS_VITERBI
;
500 if (tmp
& 0x08) /* RS or BCH */
501 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
503 priv
->fe_status
= *status
;
507 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
511 static int tda10071_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
513 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
517 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
523 ret
= tda10071_rd_regs(priv
, 0x3a, buf
, 2);
528 *snr
= buf
[0] << 8 | buf
[1];
532 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
536 static int tda10071_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
538 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
539 struct tda10071_cmd cmd
;
543 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
549 cmd
.args
[0] = CMD_GET_AGCACC
;
552 ret
= tda10071_cmd_execute(priv
, &cmd
);
556 /* input power estimate dBm */
557 ret
= tda10071_rd_reg(priv
, 0x50, &tmp
);
562 tmp
= 181; /* -75 dBm */
564 tmp
= 236; /* -20 dBm */
566 /* scale value to 0x0000-0xffff */
567 *strength
= (tmp
-181) * 0xffff / (236-181);
571 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
575 static int tda10071_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
577 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
578 struct tda10071_cmd cmd
;
582 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
583 *ber
= priv
->ber
= 0;
588 switch (priv
->delivery_system
) {
600 *ber
= priv
->ber
= 0;
604 ret
= tda10071_rd_reg(priv
, reg
, &tmp
);
608 if (priv
->meas_count
[i
] == tmp
) {
609 dev_dbg(&priv
->i2c
->dev
, "%s: meas not ready=%02x\n", __func__
,
614 priv
->meas_count
[i
] = tmp
;
617 cmd
.args
[0] = CMD_BER_UPDATE_COUNTERS
;
621 ret
= tda10071_cmd_execute(priv
, &cmd
);
625 ret
= tda10071_rd_regs(priv
, cmd
.len
, buf
, len
);
629 if (priv
->delivery_system
== SYS_DVBS
) {
630 *ber
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
631 priv
->ucb
+= (buf
[4] << 8) | buf
[5];
633 *ber
= (buf
[0] << 8) | buf
[1];
639 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
643 static int tda10071_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
645 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
648 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
653 /* UCB is updated when BER is read. Assume BER is read anyway. */
655 *ucblocks
= priv
->ucb
;
659 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
663 static int tda10071_set_frontend(struct dvb_frontend
*fe
)
665 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
666 struct tda10071_cmd cmd
;
667 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
669 u8 mode
, rolloff
, pilot
, inversion
, div
;
671 dev_dbg(&priv
->i2c
->dev
, "%s: delivery_system=%d modulation=%d " \
672 "frequency=%d symbol_rate=%d inversion=%d pilot=%d " \
673 "rolloff=%d\n", __func__
, c
->delivery_system
, c
->modulation
,
674 c
->frequency
, c
->symbol_rate
, c
->inversion
, c
->pilot
,
677 priv
->delivery_system
= SYS_UNDEFINED
;
684 switch (c
->inversion
) {
692 /* 2 = auto; try first on then off
693 * 3 = auto; try first off then on */
697 dev_dbg(&priv
->i2c
->dev
, "%s: invalid inversion\n", __func__
);
702 switch (c
->delivery_system
) {
708 switch (c
->rolloff
) {
720 dev_dbg(&priv
->i2c
->dev
, "%s: invalid rolloff\n",
737 dev_dbg(&priv
->i2c
->dev
, "%s: invalid pilot\n",
744 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
750 for (i
= 0, mode
= 0xff; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
751 if (c
->delivery_system
== TDA10071_MODCOD
[i
].delivery_system
&&
752 c
->modulation
== TDA10071_MODCOD
[i
].modulation
&&
753 c
->fec_inner
== TDA10071_MODCOD
[i
].fec
) {
754 mode
= TDA10071_MODCOD
[i
].val
;
755 dev_dbg(&priv
->i2c
->dev
, "%s: mode found=%02x\n",
762 dev_dbg(&priv
->i2c
->dev
, "%s: invalid parameter combination\n",
768 if (c
->symbol_rate
<= 5000000)
773 ret
= tda10071_wr_reg(priv
, 0x81, div
);
777 ret
= tda10071_wr_reg(priv
, 0xe3, div
);
781 cmd
.args
[0] = CMD_CHANGE_CHANNEL
;
784 cmd
.args
[3] = (c
->frequency
>> 16) & 0xff;
785 cmd
.args
[4] = (c
->frequency
>> 8) & 0xff;
786 cmd
.args
[5] = (c
->frequency
>> 0) & 0xff;
787 cmd
.args
[6] = ((c
->symbol_rate
/ 1000) >> 8) & 0xff;
788 cmd
.args
[7] = ((c
->symbol_rate
/ 1000) >> 0) & 0xff;
789 cmd
.args
[8] = (tda10071_ops
.info
.frequency_tolerance
>> 8) & 0xff;
790 cmd
.args
[9] = (tda10071_ops
.info
.frequency_tolerance
>> 0) & 0xff;
791 cmd
.args
[10] = rolloff
;
792 cmd
.args
[11] = inversion
;
793 cmd
.args
[12] = pilot
;
797 ret
= tda10071_cmd_execute(priv
, &cmd
);
801 priv
->delivery_system
= c
->delivery_system
;
805 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
809 static int tda10071_get_frontend(struct dvb_frontend
*fe
)
811 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
812 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
816 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
821 ret
= tda10071_rd_regs(priv
, 0x30, buf
, 5);
826 for (i
= 0; i
< ARRAY_SIZE(TDA10071_MODCOD
); i
++) {
827 if (tmp
== TDA10071_MODCOD
[i
].val
) {
828 c
->modulation
= TDA10071_MODCOD
[i
].modulation
;
829 c
->fec_inner
= TDA10071_MODCOD
[i
].fec
;
830 c
->delivery_system
= TDA10071_MODCOD
[i
].delivery_system
;
834 switch ((buf
[1] >> 0) & 0x01) {
836 c
->inversion
= INVERSION_OFF
;
839 c
->inversion
= INVERSION_ON
;
843 switch ((buf
[1] >> 7) & 0x01) {
845 c
->pilot
= PILOT_OFF
;
852 c
->frequency
= (buf
[2] << 16) | (buf
[3] << 8) | (buf
[4] << 0);
854 ret
= tda10071_rd_regs(priv
, 0x52, buf
, 3);
858 c
->symbol_rate
= (buf
[0] << 16) | (buf
[1] << 8) | (buf
[2] << 0);
862 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
866 static int tda10071_init(struct dvb_frontend
*fe
)
868 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
869 struct tda10071_cmd cmd
;
870 int ret
, i
, len
, remaining
, fw_size
;
871 const struct firmware
*fw
;
872 u8
*fw_file
= TDA10071_FIRMWARE
;
874 struct tda10071_reg_val_mask tab
[] = {
875 { 0xcd, 0x00, 0x07 },
876 { 0x80, 0x00, 0x02 },
877 { 0xcd, 0x00, 0xc0 },
878 { 0xce, 0x00, 0x1b },
879 { 0x9d, 0x00, 0x01 },
880 { 0x9d, 0x00, 0x02 },
881 { 0x9e, 0x00, 0x01 },
882 { 0x87, 0x00, 0x80 },
883 { 0xce, 0x00, 0x08 },
884 { 0xce, 0x00, 0x10 },
886 struct tda10071_reg_val_mask tab2
[] = {
887 { 0xf1, 0x70, 0xff },
888 { 0x88, priv
->cfg
.pll_multiplier
, 0x3f },
889 { 0x89, 0x00, 0x10 },
890 { 0x89, 0x10, 0x10 },
891 { 0xc0, 0x01, 0x01 },
892 { 0xc0, 0x00, 0x01 },
893 { 0xe0, 0xff, 0xff },
894 { 0xe0, 0x00, 0xff },
895 { 0x96, 0x1e, 0x7e },
896 { 0x8b, 0x08, 0x08 },
897 { 0x8b, 0x00, 0x08 },
898 { 0x8f, 0x1a, 0x7e },
899 { 0x8c, 0x68, 0xff },
900 { 0x8d, 0x08, 0xff },
901 { 0x8e, 0x4c, 0xff },
902 { 0x8f, 0x01, 0x01 },
903 { 0x8b, 0x04, 0x04 },
904 { 0x8b, 0x00, 0x04 },
905 { 0x87, 0x05, 0x07 },
906 { 0x80, 0x00, 0x20 },
907 { 0xc8, 0x01, 0xff },
908 { 0xb4, 0x47, 0xff },
909 { 0xb5, 0x9c, 0xff },
910 { 0xb6, 0x7d, 0xff },
911 { 0xba, 0x00, 0x03 },
912 { 0xb7, 0x47, 0xff },
913 { 0xb8, 0x9c, 0xff },
914 { 0xb9, 0x7d, 0xff },
915 { 0xba, 0x00, 0x0c },
916 { 0xc8, 0x00, 0xff },
917 { 0xcd, 0x00, 0x04 },
918 { 0xcd, 0x00, 0x20 },
919 { 0xe8, 0x02, 0xff },
920 { 0xcf, 0x20, 0xff },
921 { 0x9b, 0xd7, 0xff },
922 { 0x9a, 0x01, 0x03 },
923 { 0xa8, 0x05, 0x0f },
924 { 0xa8, 0x65, 0xf0 },
925 { 0xa6, 0xa0, 0xf0 },
926 { 0x9d, 0x50, 0xfc },
927 { 0x9e, 0x20, 0xe0 },
928 { 0xa3, 0x1c, 0x7c },
929 { 0xd5, 0x03, 0x03 },
933 /* warm state - wake up device from sleep */
935 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
936 ret
= tda10071_wr_reg_mask(priv
, tab
[i
].reg
,
937 tab
[i
].val
, tab
[i
].mask
);
942 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
946 ret
= tda10071_cmd_execute(priv
, &cmd
);
950 /* cold state - try to download firmware */
952 /* request the firmware, this will block and timeout */
953 ret
= request_firmware(&fw
, fw_file
, priv
->i2c
->dev
.parent
);
955 dev_err(&priv
->i2c
->dev
, "%s: did not find the " \
956 "firmware file. (%s) Please see " \
957 "linux/Documentation/dvb/ for more " \
958 "details on firmware-problems. (%d)\n",
959 KBUILD_MODNAME
, fw_file
, ret
);
964 for (i
= 0; i
< ARRAY_SIZE(tab2
); i
++) {
965 ret
= tda10071_wr_reg_mask(priv
, tab2
[i
].reg
,
966 tab2
[i
].val
, tab2
[i
].mask
);
968 goto error_release_firmware
;
971 /* download firmware */
972 ret
= tda10071_wr_reg(priv
, 0xe0, 0x7f);
974 goto error_release_firmware
;
976 ret
= tda10071_wr_reg(priv
, 0xf7, 0x81);
978 goto error_release_firmware
;
980 ret
= tda10071_wr_reg(priv
, 0xf8, 0x00);
982 goto error_release_firmware
;
984 ret
= tda10071_wr_reg(priv
, 0xf9, 0x00);
986 goto error_release_firmware
;
988 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in cold state, " \
989 "will try to load a firmware\n", KBUILD_MODNAME
,
990 tda10071_ops
.info
.name
);
991 dev_info(&priv
->i2c
->dev
, "%s: downloading firmware from " \
992 "file '%s'\n", KBUILD_MODNAME
, fw_file
);
994 /* do not download last byte */
995 fw_size
= fw
->size
- 1;
997 for (remaining
= fw_size
; remaining
> 0;
998 remaining
-= (priv
->cfg
.i2c_wr_max
- 1)) {
1000 if (len
> (priv
->cfg
.i2c_wr_max
- 1))
1001 len
= (priv
->cfg
.i2c_wr_max
- 1);
1003 ret
= tda10071_wr_regs(priv
, 0xfa,
1004 (u8
*) &fw
->data
[fw_size
- remaining
], len
);
1006 dev_err(&priv
->i2c
->dev
, "%s: firmware " \
1007 "download failed=%d\n",
1008 KBUILD_MODNAME
, ret
);
1010 goto error_release_firmware
;
1013 release_firmware(fw
);
1015 ret
= tda10071_wr_reg(priv
, 0xf7, 0x0c);
1019 ret
= tda10071_wr_reg(priv
, 0xe0, 0x00);
1023 /* wait firmware start */
1026 /* firmware status */
1027 ret
= tda10071_rd_reg(priv
, 0x51, &tmp
);
1032 dev_info(&priv
->i2c
->dev
, "%s: firmware did not run\n",
1040 cmd
.args
[0] = CMD_GET_FW_VERSION
;
1042 ret
= tda10071_cmd_execute(priv
, &cmd
);
1046 ret
= tda10071_rd_regs(priv
, cmd
.len
, buf
, 4);
1050 dev_info(&priv
->i2c
->dev
, "%s: firmware version %d.%d.%d.%d\n",
1051 KBUILD_MODNAME
, buf
[0], buf
[1], buf
[2], buf
[3]);
1052 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in warm state\n",
1053 KBUILD_MODNAME
, tda10071_ops
.info
.name
);
1055 ret
= tda10071_rd_regs(priv
, 0x81, buf
, 2);
1059 cmd
.args
[0] = CMD_DEMOD_INIT
;
1060 cmd
.args
[1] = ((priv
->cfg
.xtal
/ 1000) >> 8) & 0xff;
1061 cmd
.args
[2] = ((priv
->cfg
.xtal
/ 1000) >> 0) & 0xff;
1062 cmd
.args
[3] = buf
[0];
1063 cmd
.args
[4] = buf
[1];
1064 cmd
.args
[5] = priv
->cfg
.pll_multiplier
;
1065 cmd
.args
[6] = priv
->cfg
.spec_inv
;
1068 ret
= tda10071_cmd_execute(priv
, &cmd
);
1072 cmd
.args
[0] = CMD_TUNER_INIT
;
1077 cmd
.args
[5] = (priv
->cfg
.tuner_i2c_addr
) ? priv
->cfg
.tuner_i2c_addr
: 0x14;
1082 cmd
.args
[10] = 0x00;
1083 cmd
.args
[11] = 0x00;
1084 cmd
.args
[12] = 0x00;
1085 cmd
.args
[13] = 0x00;
1086 cmd
.args
[14] = 0x00;
1088 ret
= tda10071_cmd_execute(priv
, &cmd
);
1092 cmd
.args
[0] = CMD_MPEG_CONFIG
;
1094 cmd
.args
[2] = priv
->cfg
.ts_mode
;
1099 ret
= tda10071_cmd_execute(priv
, &cmd
);
1103 ret
= tda10071_wr_reg_mask(priv
, 0xf0, 0x01, 0x01);
1107 cmd
.args
[0] = CMD_LNB_CONFIG
;
1119 ret
= tda10071_cmd_execute(priv
, &cmd
);
1123 cmd
.args
[0] = CMD_BER_CONTROL
;
1128 ret
= tda10071_cmd_execute(priv
, &cmd
);
1134 error_release_firmware
:
1135 release_firmware(fw
);
1137 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1141 static int tda10071_sleep(struct dvb_frontend
*fe
)
1143 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
1144 struct tda10071_cmd cmd
;
1146 struct tda10071_reg_val_mask tab
[] = {
1147 { 0xcd, 0x07, 0x07 },
1148 { 0x80, 0x02, 0x02 },
1149 { 0xcd, 0xc0, 0xc0 },
1150 { 0xce, 0x1b, 0x1b },
1151 { 0x9d, 0x01, 0x01 },
1152 { 0x9d, 0x02, 0x02 },
1153 { 0x9e, 0x01, 0x01 },
1154 { 0x87, 0x80, 0x80 },
1155 { 0xce, 0x08, 0x08 },
1156 { 0xce, 0x10, 0x10 },
1164 cmd
.args
[0] = CMD_SET_SLEEP_MODE
;
1168 ret
= tda10071_cmd_execute(priv
, &cmd
);
1172 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
1173 ret
= tda10071_wr_reg_mask(priv
, tab
[i
].reg
, tab
[i
].val
,
1181 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1185 static int tda10071_get_tune_settings(struct dvb_frontend
*fe
,
1186 struct dvb_frontend_tune_settings
*s
)
1188 s
->min_delay_ms
= 8000;
1195 static void tda10071_release(struct dvb_frontend
*fe
)
1197 struct tda10071_priv
*priv
= fe
->demodulator_priv
;
1201 struct dvb_frontend
*tda10071_attach(const struct tda10071_config
*config
,
1202 struct i2c_adapter
*i2c
)
1205 struct tda10071_priv
*priv
= NULL
;
1208 /* allocate memory for the internal priv */
1209 priv
= kzalloc(sizeof(struct tda10071_priv
), GFP_KERNEL
);
1215 /* make sure demod i2c address is specified */
1216 if (!config
->demod_i2c_addr
) {
1217 dev_dbg(&i2c
->dev
, "%s: invalid demod i2c address!\n", __func__
);
1222 /* make sure tuner i2c address is specified */
1223 if (!config
->tuner_i2c_addr
) {
1224 dev_dbg(&i2c
->dev
, "%s: invalid tuner i2c address!\n", __func__
);
1229 /* setup the priv */
1231 memcpy(&priv
->cfg
, config
, sizeof(struct tda10071_config
));
1234 ret
= tda10071_rd_reg(priv
, 0xff, &tmp
);
1235 if (ret
|| tmp
!= 0x0f)
1239 ret
= tda10071_rd_reg(priv
, 0xdd, &tmp
);
1240 if (ret
|| tmp
!= 0x00)
1244 ret
= tda10071_rd_reg(priv
, 0xfe, &tmp
);
1245 if (ret
|| tmp
!= 0x01)
1248 /* create dvb_frontend */
1249 memcpy(&priv
->fe
.ops
, &tda10071_ops
, sizeof(struct dvb_frontend_ops
));
1250 priv
->fe
.demodulator_priv
= priv
;
1254 dev_dbg(&i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1258 EXPORT_SYMBOL(tda10071_attach
);
1260 static struct dvb_frontend_ops tda10071_ops
= {
1261 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1263 .name
= "NXP TDA10071",
1264 .frequency_min
= 950000,
1265 .frequency_max
= 2150000,
1266 .frequency_tolerance
= 5000,
1267 .symbol_rate_min
= 1000000,
1268 .symbol_rate_max
= 45000000,
1269 .caps
= FE_CAN_INVERSION_AUTO
|
1281 FE_CAN_2G_MODULATION
1284 .release
= tda10071_release
,
1286 .get_tune_settings
= tda10071_get_tune_settings
,
1288 .init
= tda10071_init
,
1289 .sleep
= tda10071_sleep
,
1291 .set_frontend
= tda10071_set_frontend
,
1292 .get_frontend
= tda10071_get_frontend
,
1294 .read_status
= tda10071_read_status
,
1295 .read_snr
= tda10071_read_snr
,
1296 .read_signal_strength
= tda10071_read_signal_strength
,
1297 .read_ber
= tda10071_read_ber
,
1298 .read_ucblocks
= tda10071_read_ucblocks
,
1300 .diseqc_send_master_cmd
= tda10071_diseqc_send_master_cmd
,
1301 .diseqc_recv_slave_reply
= tda10071_diseqc_recv_slave_reply
,
1302 .diseqc_send_burst
= tda10071_diseqc_send_burst
,
1304 .set_tone
= tda10071_set_tone
,
1305 .set_voltage
= tda10071_set_voltage
,
1308 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1309 MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
1310 MODULE_LICENSE("GPL");
1311 MODULE_FIRMWARE(TDA10071_FIRMWARE
);