12 #include <linux/i2c.h>
29 "(1=info, 2=xfer, 4=i2c, 8=reg, 16=adv (or-able)).");
39 #define ANT_PATH_AUTO 0
40 #define ANT_PATH_EXTERNAL 1
41 #define ANT_PATH_INTERNAL 2
51 MODULE_PARM_DESC(rfswitch,
"force rf switch position (0=auto, 1=ext, 2=int).");
55 #define deb_info pr_debug
56 #define deb_reg pr_debug
57 #define deb_adv pr_debug
62 u8 cmd,
u8 *wbuf,
int wlen,
u8 *rbuf,
int rlen)
64 int wo = (rbuf ==
NULL || rlen == 0);
68 deb_adv(
"%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
73 memcpy(&sndbuf[1], wbuf, wlen);
84 #define MXL_CMD_REG_READ 0xaa
85 #define MXL_CMD_REG_WRITE 0x55
94 mxl_debug(
"error reading reg: 0x%02x", addr);
101 err(
"invalid response reading reg: 0x%02x != 0x%02x, 0x%02x",
102 addr, buf[0], buf[1]);
106 deb_reg(
"R: (0x%02x, 0x%02x)\n", addr, *data);
116 deb_reg(
"W: (0x%02x, 0x%02x)\n", addr, data);
120 err(
"error writing reg: 0x%02x, val: 0x%02x", addr, data);
137 err(
"error writing addr: 0x%02x, mask: 0x%02x, "
138 "data: 0x%02x, retrying...", addr, mask, data);
161 for (i = 0; ctrl_reg_info[
i].
addr |
162 ctrl_reg_info[
i].
mask |
163 ctrl_reg_info[
i].
data; i++) {
166 ctrl_reg_info[i].
addr,
167 ctrl_reg_info[i].
mask,
168 ctrl_reg_info[i].
data);
170 err(
"failed on reg #%d (0x%02x)", i,
171 ctrl_reg_info[i].addr);
184 char *mxl_chip, *mxl_rev;
201 mxl_chip =
"MxL101SF";
204 mxl_chip =
"MxL111SF";
207 mxl_chip =
"UNKNOWN MxL1X1";
225 mxl_rev =
"UNKNOWN REVISION";
228 info(
"%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver);
233 #define get_chip_info(state) \
236 ___ret = mxl1x1sf_get_chip_info(state); \
237 if (mxl_fail(___ret)) { \
238 mxl_debug("failed to get chip info" \
239 " on first probe attempt"); \
240 ___ret = mxl1x1sf_get_chip_info(state); \
241 if (mxl_fail(___ret)) \
242 err("failed to get chip info during probe"); \
244 mxl_debug("probe needed a retry " \
245 "in order to succeed."); \
260 static int mxl111sf_adap_fe_init(
struct dvb_frontend *fe)
269 mxl_debug(
"driver not yet initialized, exit.");
280 err(
"set interface failed");
306 err = fe->
ops.init(fe);
317 static int mxl111sf_adap_fe_sleep(
struct dvb_frontend *fe)
325 mxl_debug(
"driver not yet initialized, exit.");
347 deb_info(
"%s(%d)\n", __func__, onoff);
366 static int mxl111sf_ep5_streaming_ctrl(
struct dvb_frontend *fe,
int onoff)
371 deb_info(
"%s(%d)\n", __func__, onoff);
392 static int mxl111sf_ep4_streaming_ctrl(
struct dvb_frontend *fe,
int onoff)
397 deb_info(
"%s(%d)\n", __func__, onoff);
410 .i2c_addr = 0xb2 >> 1,
415 .spectral_inversion = 0,
420 static int mxl111sf_lgdt3305_frontend_attach(
struct dvb_usb_adapter *adap,
u8 fe_id)
435 err(
"set interface failed");
468 &hauppauge_lgdt3305_config,
470 if (adap->
fe[fe_id]) {
472 adap_state->
fe_init = adap->
fe[fe_id]->ops.init;
473 adap->
fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
474 adap_state->
fe_sleep = adap->
fe[fe_id]->ops.sleep;
475 adap->
fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
485 .i2c_addr = 0x1c >> 1,
487 .spectral_inversion = 0,
491 static int mxl111sf_lg2160_frontend_attach(
struct dvb_usb_adapter *adap,
u8 fe_id)
506 err(
"set interface failed");
543 &hauppauge_lg2160_config,
545 if (adap->
fe[fe_id]) {
547 adap_state->
fe_init = adap->
fe[fe_id]->ops.init;
548 adap->
fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
549 adap_state->
fe_sleep = adap->
fe[fe_id]->ops.sleep;
550 adap->
fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
560 .i2c_addr = 0x1c >> 1,
562 .spectral_inversion = 0,
569 .i2c_addr = 0x1c >> 1,
571 .spectral_inversion = 0,
576 static int mxl111sf_lg2161_frontend_attach(
struct dvb_usb_adapter *adap,
u8 fe_id)
591 err(
"set interface failed");
629 &hauppauge_lg2161_1040_config :
630 &hauppauge_lg2161_1019_config,
632 if (adap->
fe[fe_id]) {
634 adap_state->
fe_init = adap->
fe[fe_id]->ops.init;
635 adap->
fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
636 adap_state->
fe_sleep = adap->
fe[fe_id]->ops.sleep;
637 adap->
fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
645 static struct lg2160_config hauppauge_lg2161_1019_ep6_config = {
647 .i2c_addr = 0x1c >> 1,
649 .spectral_inversion = 0,
654 static struct lg2160_config hauppauge_lg2161_1040_ep6_config = {
656 .i2c_addr = 0x1c >> 1,
658 .spectral_inversion = 0,
663 static int mxl111sf_lg2161_ep6_frontend_attach(
struct dvb_usb_adapter *adap,
u8 fe_id)
678 err(
"set interface failed");
716 &hauppauge_lg2161_1040_ep6_config :
717 &hauppauge_lg2161_1019_ep6_config,
719 if (adap->
fe[fe_id]) {
721 adap_state->
fe_init = adap->
fe[fe_id]->ops.init;
722 adap->
fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
723 adap_state->
fe_sleep = adap->
fe[fe_id]->ops.sleep;
724 adap->
fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
753 err(
"set interface failed");
783 if (adap->
fe[fe_id]) {
785 adap_state->
fe_init = adap->
fe[fe_id]->ops.init;
786 adap->
fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
787 adap_state->
fe_sleep = adap->
fe[fe_id]->ops.sleep;
788 adap->
fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
796 static inline int mxl111sf_set_ant_path(
struct mxl111sf_state *state,
804 #define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \
805 err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \
806 __func__, __LINE__, \
807 (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \
808 pwr0, pwr1, pwr2, pwr3)
810 #define ANT_HUNT_SLEEP 90
811 #define ANT_EXT_TWEAK 0
818 u16 rxPwrA, rxPwr0, rxPwr1, rxPwr2;
828 fe->
ops.tuner_ops.get_rf_strength(fe, &rxPwrA);
832 fe->
ops.tuner_ops.get_rf_strength(fe, &rxPwr0);
836 fe->
ops.tuner_ops.get_rf_strength(fe, &rxPwr1);
840 fe->
ops.tuner_ops.get_rf_strength(fe, &rxPwr2);
846 rxPwr0, rxPwr1, rxPwr2);
850 rxPwr0, rxPwr1, rxPwr2);
858 .invert_spectrum = 0,
863 .ant_hunt = mxl111sf_ant_hunt,
875 &mxl_tuner_config) ==
NULL)
877 adap->
fe[
i]->ops.read_signal_strength = adap->
fe[
i]->ops.tuner_ops.get_rf_strength;
890 .functionality = mxl111sf_i2c_func,
891 #ifdef NEED_ALGO_CONTROL
892 .algo_control = dummy_algo_control,
905 err(
"failed to get chip info during probe");
919 eeprom + 0xa0 : eeprom + 0x80);
921 switch (state->
tv.model) {
928 "unknown hauppauge model #%d\n",
929 __func__, state->
tv.model);
937 return mxl111sf_attach_demod(adap, 0);
942 return mxl111sf_lgdt3305_frontend_attach(adap, 0);
947 return mxl111sf_lg2160_frontend_attach(adap, 0);
950 static int mxl111sf_frontend_attach_atsc_mh(
struct dvb_usb_adapter *adap)
955 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
959 ret = mxl111sf_attach_demod(adap, 1);
963 ret = mxl111sf_lg2160_frontend_attach(adap, 2);
970 static int mxl111sf_frontend_attach_mercury(
struct dvb_usb_adapter *adap)
975 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
979 ret = mxl111sf_attach_demod(adap, 1);
983 ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 2);
990 static int mxl111sf_frontend_attach_mercury_mh(
struct dvb_usb_adapter *adap)
995 ret = mxl111sf_attach_demod(adap, 0);
1000 ret = mxl111sf_lg2161_frontend_attach(adap, 1);
1002 ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 1);
1009 deb_info(
"%s: endpoint=%d size=8192\n", __func__, endpoint);
1013 stream->
u.
bulk.buffersize = 8192;
1017 u8 endpoint,
int framesperurb,
int framesize)
1019 deb_info(
"%s: endpoint=%d size=%d\n", __func__, endpoint,
1020 framesperurb * framesize);
1024 stream->
u.
isoc.framesperurb = framesperurb;
1025 stream->
u.
isoc.framesize = framesize;
1026 stream->
u.
isoc.interval = 1;
1035 static int mxl111sf_get_stream_config_dvbt(
struct dvb_frontend *fe,
1042 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1044 mxl111sf_stream_config_bulk(stream, 4);
1049 .driver_name = KBUILD_MODNAME,
1054 .generic_bulk_ctrl_endpoint = 0x02,
1055 .generic_bulk_ctrl_endpoint_response = 0x81,
1058 .frontend_attach = mxl111sf_frontend_attach_dvbt,
1059 .tuner_attach = mxl111sf_attach_tuner,
1060 .init = mxl111sf_init,
1061 .streaming_ctrl = mxl111sf_ep4_streaming_ctrl,
1062 .get_stream_config = mxl111sf_get_stream_config_dvbt,
1076 static int mxl111sf_get_stream_config_atsc(
struct dvb_frontend *fe,
1083 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1085 mxl111sf_stream_config_bulk(stream, 6);
1090 .driver_name = KBUILD_MODNAME,
1095 .generic_bulk_ctrl_endpoint = 0x02,
1096 .generic_bulk_ctrl_endpoint_response = 0x81,
1099 .frontend_attach = mxl111sf_frontend_attach_atsc,
1100 .tuner_attach = mxl111sf_attach_tuner,
1101 .init = mxl111sf_init,
1102 .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,
1103 .get_stream_config = mxl111sf_get_stream_config_atsc,
1117 static int mxl111sf_get_stream_config_mh(
struct dvb_frontend *fe,
1124 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1126 mxl111sf_stream_config_bulk(stream, 5);
1131 .driver_name = KBUILD_MODNAME,
1136 .generic_bulk_ctrl_endpoint = 0x02,
1137 .generic_bulk_ctrl_endpoint_response = 0x81,
1140 .frontend_attach = mxl111sf_frontend_attach_mh,
1141 .tuner_attach = mxl111sf_attach_tuner,
1142 .init = mxl111sf_init,
1143 .streaming_ctrl = mxl111sf_ep5_streaming_ctrl,
1144 .get_stream_config = mxl111sf_get_stream_config_mh,
1158 static int mxl111sf_get_stream_config_atsc_mh(
struct dvb_frontend *fe,
1166 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1168 mxl111sf_stream_config_bulk(stream, 6);
1169 }
else if (fe->
id == 1) {
1172 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1174 mxl111sf_stream_config_bulk(stream, 4);
1175 }
else if (fe->
id == 2) {
1178 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1180 mxl111sf_stream_config_bulk(stream, 5);
1185 static int mxl111sf_streaming_ctrl_atsc_mh(
struct dvb_frontend *fe,
int onoff)
1187 deb_info(
"%s: fe=%d onoff=%d\n", __func__, fe->
id, onoff);
1190 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1191 else if (fe->
id == 1)
1192 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1193 else if (fe->
id == 2)
1194 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1199 .driver_name = KBUILD_MODNAME,
1204 .generic_bulk_ctrl_endpoint = 0x02,
1205 .generic_bulk_ctrl_endpoint_response = 0x81,
1208 .frontend_attach = mxl111sf_frontend_attach_atsc_mh,
1209 .tuner_attach = mxl111sf_attach_tuner,
1210 .init = mxl111sf_init,
1211 .streaming_ctrl = mxl111sf_streaming_ctrl_atsc_mh,
1212 .get_stream_config = mxl111sf_get_stream_config_atsc_mh,
1228 static int mxl111sf_get_stream_config_mercury(
struct dvb_frontend *fe,
1236 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1238 mxl111sf_stream_config_bulk(stream, 6);
1239 }
else if (fe->
id == 1) {
1242 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1244 mxl111sf_stream_config_bulk(stream, 4);
1248 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1250 mxl111sf_stream_config_bulk(stream, 5);
1254 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1256 mxl111sf_stream_config_bulk(stream, 6);
1261 static int mxl111sf_streaming_ctrl_mercury(
struct dvb_frontend *fe,
int onoff)
1263 deb_info(
"%s: fe=%d onoff=%d\n", __func__, fe->
id, onoff);
1266 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1267 else if (fe->
id == 1)
1268 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1270 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1272 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1277 .driver_name = KBUILD_MODNAME,
1282 .generic_bulk_ctrl_endpoint = 0x02,
1283 .generic_bulk_ctrl_endpoint_response = 0x81,
1286 .frontend_attach = mxl111sf_frontend_attach_mercury,
1287 .tuner_attach = mxl111sf_attach_tuner,
1288 .init = mxl111sf_init,
1289 .streaming_ctrl = mxl111sf_streaming_ctrl_mercury,
1290 .get_stream_config = mxl111sf_get_stream_config_mercury,
1306 static int mxl111sf_get_stream_config_mercury_mh(
struct dvb_frontend *fe,
1314 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1316 mxl111sf_stream_config_bulk(stream, 4);
1320 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1322 mxl111sf_stream_config_bulk(stream, 5);
1326 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1328 mxl111sf_stream_config_bulk(stream, 6);
1333 static int mxl111sf_streaming_ctrl_mercury_mh(
struct dvb_frontend *fe,
int onoff)
1335 deb_info(
"%s: fe=%d onoff=%d\n", __func__, fe->
id, onoff);
1338 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1340 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1342 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1347 .driver_name = KBUILD_MODNAME,
1352 .generic_bulk_ctrl_endpoint = 0x02,
1353 .generic_bulk_ctrl_endpoint_response = 0x81,
1356 .frontend_attach = mxl111sf_frontend_attach_mercury_mh,
1357 .tuner_attach = mxl111sf_attach_tuner,
1358 .init = mxl111sf_init,
1359 .streaming_ctrl = mxl111sf_streaming_ctrl_mercury_mh,
1360 .get_stream_config = mxl111sf_get_stream_config_mercury_mh,
1409 static struct usb_driver mxl111sf_usb_driver = {
1410 .name = KBUILD_MODNAME,
1411 .id_table = mxl111sf_id_table,