33 .addr = priv->
cfg.i2c_address,
47 dev_warn(&priv->
i2c->dev,
"%s: i2c wr failed=%d reg=%02x " \
48 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
67 .addr = priv->
cfg.i2c_address,
79 dev_warn(&priv->
i2c->dev,
"%s: i2c rd failed=%d reg=%02x " \
80 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
89 return tda10071_wr_regs(priv, reg, &val, 1);
95 return tda10071_rd_regs(priv, reg, val, 1);
106 ret = tda10071_rd_regs(priv, reg, &tmp, 1);
115 return tda10071_wr_regs(priv, reg, &val, 1);
124 ret = tda10071_rd_regs(priv, reg, &tmp, 1);
131 for (i = 0; i < 8; i++) {
132 if ((mask >> i) & 0x01)
153 ret = tda10071_wr_regs(priv, 0x00, cmd->
args, cmd->
len);
158 ret = tda10071_wr_reg(priv, 0x1f, 1);
163 for (i = 1000, tmp = 1; i &&
tmp; i--) {
164 ret = tda10071_rd_reg(priv, 0x1f, &tmp);
171 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
180 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
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",
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,
243 dev_dbg(&priv->
i2c->dev,
"%s: voltage=%d\n", __func__, fe_sec_voltage);
245 switch (fe_sec_voltage) {
256 dev_dbg(&priv->
i2c->dev,
"%s: invalid fe_sec_voltage\n",
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,
289 dev_dbg(&priv->
i2c->dev,
"%s: msg_len=%d\n", __func__,
298 for (i = 500, tmp = 0; i && !
tmp; i--) {
306 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
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,
352 for (i = 500, tmp = 0; i && !
tmp; i--) {
360 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
368 ret = tda10071_rd_reg(priv, 0x46, &tmp);
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,
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--) {
433 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
448 ret = tda10071_cmd_execute(priv, &cmd);
454 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
471 ret = tda10071_rd_reg(priv, 0x39, &tmp);
488 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
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)
533 ret = tda10071_cmd_execute(priv, &cmd);
538 ret = tda10071_rd_reg(priv, 0x50, &tmp);
548 *strength = (tmp-181) * 0xffff / (236-181);
552 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
564 *ber = priv->
ber = 0;
581 *ber = priv->
ber = 0;
585 ret = tda10071_rd_reg(priv, reg, &tmp);
590 dev_dbg(&priv->
i2c->dev,
"%s: meas not ready=%02x\n", __func__,
602 ret = tda10071_cmd_execute(priv, &cmd);
606 ret = tda10071_rd_regs(priv, cmd.
len, buf, len);
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)
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)
652 dev_dbg(&priv->
i2c->dev,
"%s: delivery_system=%d modulation=%d " \
653 "frequency=%d symbol_rate=%d inversion=%d pilot=%d " \
678 dev_dbg(&priv->
i2c->dev,
"%s: invalid inversion\n", __func__);
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++) {
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",
754 ret = tda10071_wr_reg(priv, 0x81, div);
758 ret = tda10071_wr_reg(priv, 0xe3, div);
770 cmd.
args[8] = (tda10071_ops.info.frequency_tolerance >> 8) & 0xff;
771 cmd.
args[9] = (tda10071_ops.info.frequency_tolerance >> 0) & 0xff;
778 ret = tda10071_cmd_execute(priv, &cmd);
786 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
790 static int tda10071_get_frontend(
struct dvb_frontend *fe)
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) {
815 switch ((buf[1] >> 0) & 0x01) {
824 switch ((buf[1] >> 7) & 0x01) {
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);
851 int ret,
i,
len, remaining, fw_size;
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 },
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 },
914 ret = tda10071_rd_reg(priv, 0x51, &tmp);
924 tab[i].val, tab[i].
mask);
933 ret = tda10071_cmd_execute(priv, &cmd);
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);
954 tab2[i].val, tab2[i].
mask);
956 goto error_release_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);
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);
995 "download failed=%d\n",
996 KBUILD_MODNAME, ret);
998 goto error_release_firmware;
1003 ret = tda10071_wr_reg(priv, 0xf7, 0x0c);
1007 ret = tda10071_wr_reg(priv, 0xe0, 0x00);
1015 ret = tda10071_rd_reg(priv, 0x51, &tmp);
1020 dev_info(&priv->
i2c->dev,
"%s: firmware did not run\n",
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);
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);
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);
1082 cmd.
args[2] = priv->
cfg.ts_mode;
1087 ret = tda10071_cmd_execute(priv, &cmd);
1107 ret = tda10071_cmd_execute(priv, &cmd);
1116 ret = tda10071_cmd_execute(priv, &cmd);
1122 error_release_firmware:
1125 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
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 },
1156 ret = tda10071_cmd_execute(priv, &cmd);
1169 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
1173 static int tda10071_get_tune_settings(
struct dvb_frontend *fe,
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)
1224 priv->
fe.demodulator_priv =
priv;
1228 dev_dbg(&i2c->
dev,
"%s: failed=%d\n", __func__, ret);
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,
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,