mxl111sf.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. /*
  2. * Copyright (C) 2010-2014 Michael Krufky (mkrufky@linuxtv.org)
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation, version 2.
  7. *
  8. * see Documentation/dvb/README.dvb-usb for more information
  9. */
  10. #include <linux/vmalloc.h>
  11. #include <linux/i2c.h>
  12. #include <media/tuner.h>
  13. #include "mxl111sf.h"
  14. #include "mxl111sf-reg.h"
  15. #include "mxl111sf-phy.h"
  16. #include "mxl111sf-i2c.h"
  17. #include "mxl111sf-gpio.h"
  18. #include "mxl111sf-demod.h"
  19. #include "mxl111sf-tuner.h"
  20. #include "lgdt3305.h"
  21. #include "lg2160.h"
  22. /* Max transfer size done by I2C transfer functions */
  23. #define MAX_XFER_SIZE 64
  24. int dvb_usb_mxl111sf_debug;
  25. module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
  26. MODULE_PARM_DESC(debug, "set debugging level (1=info, 2=xfer, 4=i2c, 8=reg, 16=adv (or-able)).");
  27. static int dvb_usb_mxl111sf_isoc;
  28. module_param_named(isoc, dvb_usb_mxl111sf_isoc, int, 0644);
  29. MODULE_PARM_DESC(isoc, "enable usb isoc xfer (0=bulk, 1=isoc).");
  30. static int dvb_usb_mxl111sf_spi;
  31. module_param_named(spi, dvb_usb_mxl111sf_spi, int, 0644);
  32. MODULE_PARM_DESC(spi, "use spi rather than tp for data xfer (0=tp, 1=spi).");
  33. #define ANT_PATH_AUTO 0
  34. #define ANT_PATH_EXTERNAL 1
  35. #define ANT_PATH_INTERNAL 2
  36. static int dvb_usb_mxl111sf_rfswitch =
  37. #if 0
  38. ANT_PATH_AUTO;
  39. #else
  40. ANT_PATH_EXTERNAL;
  41. #endif
  42. module_param_named(rfswitch, dvb_usb_mxl111sf_rfswitch, int, 0644);
  43. MODULE_PARM_DESC(rfswitch, "force rf switch position (0=auto, 1=ext, 2=int).");
  44. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  45. int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
  46. u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  47. {
  48. int wo = (rbuf == NULL || rlen == 0); /* write-only */
  49. int ret;
  50. u8 sndbuf[MAX_XFER_SIZE];
  51. if (1 + wlen > sizeof(sndbuf)) {
  52. pr_warn("%s: len=%d is too big!\n", __func__, wlen);
  53. return -EOPNOTSUPP;
  54. }
  55. pr_debug("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
  56. memset(sndbuf, 0, 1+wlen);
  57. sndbuf[0] = cmd;
  58. memcpy(&sndbuf[1], wbuf, wlen);
  59. ret = (wo) ? dvb_usbv2_generic_write(d, sndbuf, 1+wlen) :
  60. dvb_usbv2_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen);
  61. mxl_fail(ret);
  62. return ret;
  63. }
  64. /* ------------------------------------------------------------------------ */
  65. #define MXL_CMD_REG_READ 0xaa
  66. #define MXL_CMD_REG_WRITE 0x55
  67. int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data)
  68. {
  69. u8 buf[2];
  70. int ret;
  71. ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_READ, &addr, 1, buf, 2);
  72. if (mxl_fail(ret)) {
  73. mxl_debug("error reading reg: 0x%02x", addr);
  74. goto fail;
  75. }
  76. if (buf[0] == addr)
  77. *data = buf[1];
  78. else {
  79. pr_err("invalid response reading reg: 0x%02x != 0x%02x, 0x%02x",
  80. addr, buf[0], buf[1]);
  81. ret = -EINVAL;
  82. }
  83. pr_debug("R: (0x%02x, 0x%02x)\n", addr, buf[1]);
  84. fail:
  85. return ret;
  86. }
  87. int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data)
  88. {
  89. u8 buf[] = { addr, data };
  90. int ret;
  91. pr_debug("W: (0x%02x, 0x%02x)\n", addr, data);
  92. ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_WRITE, buf, 2, NULL, 0);
  93. if (mxl_fail(ret))
  94. pr_err("error writing reg: 0x%02x, val: 0x%02x", addr, data);
  95. return ret;
  96. }
  97. /* ------------------------------------------------------------------------ */
  98. int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
  99. u8 addr, u8 mask, u8 data)
  100. {
  101. int ret;
  102. u8 val = 0;
  103. if (mask != 0xff) {
  104. ret = mxl111sf_read_reg(state, addr, &val);
  105. #if 1
  106. /* dont know why this usually errors out on the first try */
  107. if (mxl_fail(ret))
  108. pr_err("error writing addr: 0x%02x, mask: 0x%02x, data: 0x%02x, retrying...",
  109. addr, mask, data);
  110. ret = mxl111sf_read_reg(state, addr, &val);
  111. #endif
  112. if (mxl_fail(ret))
  113. goto fail;
  114. }
  115. val &= ~mask;
  116. val |= data;
  117. ret = mxl111sf_write_reg(state, addr, val);
  118. mxl_fail(ret);
  119. fail:
  120. return ret;
  121. }
  122. /* ------------------------------------------------------------------------ */
  123. int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
  124. struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
  125. {
  126. int i, ret = 0;
  127. for (i = 0; ctrl_reg_info[i].addr |
  128. ctrl_reg_info[i].mask |
  129. ctrl_reg_info[i].data; i++) {
  130. ret = mxl111sf_write_reg_mask(state,
  131. ctrl_reg_info[i].addr,
  132. ctrl_reg_info[i].mask,
  133. ctrl_reg_info[i].data);
  134. if (mxl_fail(ret)) {
  135. pr_err("failed on reg #%d (0x%02x)", i,
  136. ctrl_reg_info[i].addr);
  137. break;
  138. }
  139. }
  140. return ret;
  141. }
  142. /* ------------------------------------------------------------------------ */
  143. static int mxl1x1sf_get_chip_info(struct mxl111sf_state *state)
  144. {
  145. int ret;
  146. u8 id, ver;
  147. char *mxl_chip, *mxl_rev;
  148. if ((state->chip_id) && (state->chip_ver))
  149. return 0;
  150. ret = mxl111sf_read_reg(state, CHIP_ID_REG, &id);
  151. if (mxl_fail(ret))
  152. goto fail;
  153. state->chip_id = id;
  154. ret = mxl111sf_read_reg(state, TOP_CHIP_REV_ID_REG, &ver);
  155. if (mxl_fail(ret))
  156. goto fail;
  157. state->chip_ver = ver;
  158. switch (id) {
  159. case 0x61:
  160. mxl_chip = "MxL101SF";
  161. break;
  162. case 0x63:
  163. mxl_chip = "MxL111SF";
  164. break;
  165. default:
  166. mxl_chip = "UNKNOWN MxL1X1";
  167. break;
  168. }
  169. switch (ver) {
  170. case 0x36:
  171. state->chip_rev = MXL111SF_V6;
  172. mxl_rev = "v6";
  173. break;
  174. case 0x08:
  175. state->chip_rev = MXL111SF_V8_100;
  176. mxl_rev = "v8_100";
  177. break;
  178. case 0x18:
  179. state->chip_rev = MXL111SF_V8_200;
  180. mxl_rev = "v8_200";
  181. break;
  182. default:
  183. state->chip_rev = 0;
  184. mxl_rev = "UNKNOWN REVISION";
  185. break;
  186. }
  187. pr_info("%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver);
  188. fail:
  189. return ret;
  190. }
  191. #define get_chip_info(state) \
  192. ({ \
  193. int ___ret; \
  194. ___ret = mxl1x1sf_get_chip_info(state); \
  195. if (mxl_fail(___ret)) { \
  196. mxl_debug("failed to get chip info" \
  197. " on first probe attempt"); \
  198. ___ret = mxl1x1sf_get_chip_info(state); \
  199. if (mxl_fail(___ret)) \
  200. pr_err("failed to get chip info during probe"); \
  201. else \
  202. mxl_debug("probe needed a retry " \
  203. "in order to succeed."); \
  204. } \
  205. ___ret; \
  206. })
  207. /* ------------------------------------------------------------------------ */
  208. #if 0
  209. static int mxl111sf_power_ctrl(struct dvb_usb_device *d, int onoff)
  210. {
  211. /* power control depends on which adapter is being woken:
  212. * save this for init, instead, via mxl111sf_adap_fe_init */
  213. return 0;
  214. }
  215. #endif
  216. static int mxl111sf_adap_fe_init(struct dvb_frontend *fe)
  217. {
  218. struct dvb_usb_device *d = fe_to_d(fe);
  219. struct mxl111sf_state *state = fe_to_priv(fe);
  220. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
  221. int err;
  222. /* exit if we didn't initialize the driver yet */
  223. if (!state->chip_id) {
  224. mxl_debug("driver not yet initialized, exit.");
  225. goto fail;
  226. }
  227. pr_debug("%s()\n", __func__);
  228. mutex_lock(&state->fe_lock);
  229. state->alt_mode = adap_state->alt_mode;
  230. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  231. pr_err("set interface failed");
  232. err = mxl1x1sf_soft_reset(state);
  233. mxl_fail(err);
  234. err = mxl111sf_init_tuner_demod(state);
  235. mxl_fail(err);
  236. err = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  237. mxl_fail(err);
  238. err = mxl111sf_enable_usb_output(state);
  239. mxl_fail(err);
  240. err = mxl1x1sf_top_master_ctrl(state, 1);
  241. mxl_fail(err);
  242. if ((MXL111SF_GPIO_MOD_DVBT != adap_state->gpio_mode) &&
  243. (state->chip_rev > MXL111SF_V6)) {
  244. mxl111sf_config_pin_mux_modes(state,
  245. PIN_MUX_TS_SPI_IN_MODE_1);
  246. mxl_fail(err);
  247. }
  248. err = mxl111sf_init_port_expander(state);
  249. if (!mxl_fail(err)) {
  250. state->gpio_mode = adap_state->gpio_mode;
  251. err = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
  252. mxl_fail(err);
  253. #if 0
  254. err = fe->ops.init(fe);
  255. #endif
  256. msleep(100); /* add short delay after enabling
  257. * the demod before touching it */
  258. }
  259. return (adap_state->fe_init) ? adap_state->fe_init(fe) : 0;
  260. fail:
  261. return -ENODEV;
  262. }
  263. static int mxl111sf_adap_fe_sleep(struct dvb_frontend *fe)
  264. {
  265. struct mxl111sf_state *state = fe_to_priv(fe);
  266. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
  267. int err;
  268. /* exit if we didn't initialize the driver yet */
  269. if (!state->chip_id) {
  270. mxl_debug("driver not yet initialized, exit.");
  271. goto fail;
  272. }
  273. pr_debug("%s()\n", __func__);
  274. err = (adap_state->fe_sleep) ? adap_state->fe_sleep(fe) : 0;
  275. mutex_unlock(&state->fe_lock);
  276. return err;
  277. fail:
  278. return -ENODEV;
  279. }
  280. static int mxl111sf_ep6_streaming_ctrl(struct dvb_frontend *fe, int onoff)
  281. {
  282. struct mxl111sf_state *state = fe_to_priv(fe);
  283. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
  284. int ret = 0;
  285. pr_debug("%s(%d)\n", __func__, onoff);
  286. if (onoff) {
  287. ret = mxl111sf_enable_usb_output(state);
  288. mxl_fail(ret);
  289. ret = mxl111sf_config_mpeg_in(state, 1, 1,
  290. adap_state->ep6_clockphase,
  291. 0, 0);
  292. mxl_fail(ret);
  293. #if 0
  294. } else {
  295. ret = mxl111sf_disable_656_port(state);
  296. mxl_fail(ret);
  297. #endif
  298. }
  299. return ret;
  300. }
  301. static int mxl111sf_ep5_streaming_ctrl(struct dvb_frontend *fe, int onoff)
  302. {
  303. struct mxl111sf_state *state = fe_to_priv(fe);
  304. int ret = 0;
  305. pr_debug("%s(%d)\n", __func__, onoff);
  306. if (onoff) {
  307. ret = mxl111sf_enable_usb_output(state);
  308. mxl_fail(ret);
  309. ret = mxl111sf_init_i2s_port(state, 200);
  310. mxl_fail(ret);
  311. ret = mxl111sf_config_i2s(state, 0, 15);
  312. mxl_fail(ret);
  313. } else {
  314. ret = mxl111sf_disable_i2s_port(state);
  315. mxl_fail(ret);
  316. }
  317. if (state->chip_rev > MXL111SF_V6)
  318. ret = mxl111sf_config_spi(state, onoff);
  319. mxl_fail(ret);
  320. return ret;
  321. }
  322. static int mxl111sf_ep4_streaming_ctrl(struct dvb_frontend *fe, int onoff)
  323. {
  324. struct mxl111sf_state *state = fe_to_priv(fe);
  325. int ret = 0;
  326. pr_debug("%s(%d)\n", __func__, onoff);
  327. if (onoff) {
  328. ret = mxl111sf_enable_usb_output(state);
  329. mxl_fail(ret);
  330. }
  331. return ret;
  332. }
  333. /* ------------------------------------------------------------------------ */
  334. static struct lgdt3305_config hauppauge_lgdt3305_config = {
  335. .i2c_addr = 0xb2 >> 1,
  336. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  337. .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
  338. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  339. .deny_i2c_rptr = 1,
  340. .spectral_inversion = 0,
  341. .qam_if_khz = 6000,
  342. .vsb_if_khz = 6000,
  343. };
  344. static int mxl111sf_lgdt3305_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
  345. {
  346. struct dvb_usb_device *d = adap_to_d(adap);
  347. struct mxl111sf_state *state = d_to_priv(d);
  348. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
  349. int ret;
  350. pr_debug("%s()\n", __func__);
  351. /* save a pointer to the dvb_usb_device in device state */
  352. state->d = d;
  353. adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
  354. state->alt_mode = adap_state->alt_mode;
  355. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  356. pr_err("set interface failed");
  357. state->gpio_mode = MXL111SF_GPIO_MOD_ATSC;
  358. adap_state->gpio_mode = state->gpio_mode;
  359. adap_state->device_mode = MXL_TUNER_MODE;
  360. adap_state->ep6_clockphase = 1;
  361. ret = mxl1x1sf_soft_reset(state);
  362. if (mxl_fail(ret))
  363. goto fail;
  364. ret = mxl111sf_init_tuner_demod(state);
  365. if (mxl_fail(ret))
  366. goto fail;
  367. ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  368. if (mxl_fail(ret))
  369. goto fail;
  370. ret = mxl111sf_enable_usb_output(state);
  371. if (mxl_fail(ret))
  372. goto fail;
  373. ret = mxl1x1sf_top_master_ctrl(state, 1);
  374. if (mxl_fail(ret))
  375. goto fail;
  376. ret = mxl111sf_init_port_expander(state);
  377. if (mxl_fail(ret))
  378. goto fail;
  379. ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
  380. if (mxl_fail(ret))
  381. goto fail;
  382. adap->fe[fe_id] = dvb_attach(lgdt3305_attach,
  383. &hauppauge_lgdt3305_config,
  384. &d->i2c_adap);
  385. if (adap->fe[fe_id]) {
  386. state->num_frontends++;
  387. adap_state->fe_init = adap->fe[fe_id]->ops.init;
  388. adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
  389. adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
  390. adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
  391. return 0;
  392. }
  393. ret = -EIO;
  394. fail:
  395. return ret;
  396. }
  397. static struct lg2160_config hauppauge_lg2160_config = {
  398. .lg_chip = LG2160,
  399. .i2c_addr = 0x1c >> 1,
  400. .deny_i2c_rptr = 1,
  401. .spectral_inversion = 0,
  402. .if_khz = 6000,
  403. };
  404. static int mxl111sf_lg2160_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
  405. {
  406. struct dvb_usb_device *d = adap_to_d(adap);
  407. struct mxl111sf_state *state = d_to_priv(d);
  408. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
  409. int ret;
  410. pr_debug("%s()\n", __func__);
  411. /* save a pointer to the dvb_usb_device in device state */
  412. state->d = d;
  413. adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
  414. state->alt_mode = adap_state->alt_mode;
  415. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  416. pr_err("set interface failed");
  417. state->gpio_mode = MXL111SF_GPIO_MOD_MH;
  418. adap_state->gpio_mode = state->gpio_mode;
  419. adap_state->device_mode = MXL_TUNER_MODE;
  420. adap_state->ep6_clockphase = 1;
  421. ret = mxl1x1sf_soft_reset(state);
  422. if (mxl_fail(ret))
  423. goto fail;
  424. ret = mxl111sf_init_tuner_demod(state);
  425. if (mxl_fail(ret))
  426. goto fail;
  427. ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  428. if (mxl_fail(ret))
  429. goto fail;
  430. ret = mxl111sf_enable_usb_output(state);
  431. if (mxl_fail(ret))
  432. goto fail;
  433. ret = mxl1x1sf_top_master_ctrl(state, 1);
  434. if (mxl_fail(ret))
  435. goto fail;
  436. ret = mxl111sf_init_port_expander(state);
  437. if (mxl_fail(ret))
  438. goto fail;
  439. ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
  440. if (mxl_fail(ret))
  441. goto fail;
  442. ret = get_chip_info(state);
  443. if (mxl_fail(ret))
  444. goto fail;
  445. adap->fe[fe_id] = dvb_attach(lg2160_attach,
  446. &hauppauge_lg2160_config,
  447. &d->i2c_adap);
  448. if (adap->fe[fe_id]) {
  449. state->num_frontends++;
  450. adap_state->fe_init = adap->fe[fe_id]->ops.init;
  451. adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
  452. adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
  453. adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
  454. return 0;
  455. }
  456. ret = -EIO;
  457. fail:
  458. return ret;
  459. }
  460. static struct lg2160_config hauppauge_lg2161_1019_config = {
  461. .lg_chip = LG2161_1019,
  462. .i2c_addr = 0x1c >> 1,
  463. .deny_i2c_rptr = 1,
  464. .spectral_inversion = 0,
  465. .if_khz = 6000,
  466. .output_if = 2, /* LG2161_OIF_SPI_MAS */
  467. };
  468. static struct lg2160_config hauppauge_lg2161_1040_config = {
  469. .lg_chip = LG2161_1040,
  470. .i2c_addr = 0x1c >> 1,
  471. .deny_i2c_rptr = 1,
  472. .spectral_inversion = 0,
  473. .if_khz = 6000,
  474. .output_if = 4, /* LG2161_OIF_SPI_MAS */
  475. };
  476. static int mxl111sf_lg2161_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
  477. {
  478. struct dvb_usb_device *d = adap_to_d(adap);
  479. struct mxl111sf_state *state = d_to_priv(d);
  480. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
  481. int ret;
  482. pr_debug("%s()\n", __func__);
  483. /* save a pointer to the dvb_usb_device in device state */
  484. state->d = d;
  485. adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
  486. state->alt_mode = adap_state->alt_mode;
  487. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  488. pr_err("set interface failed");
  489. state->gpio_mode = MXL111SF_GPIO_MOD_MH;
  490. adap_state->gpio_mode = state->gpio_mode;
  491. adap_state->device_mode = MXL_TUNER_MODE;
  492. adap_state->ep6_clockphase = 1;
  493. ret = mxl1x1sf_soft_reset(state);
  494. if (mxl_fail(ret))
  495. goto fail;
  496. ret = mxl111sf_init_tuner_demod(state);
  497. if (mxl_fail(ret))
  498. goto fail;
  499. ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  500. if (mxl_fail(ret))
  501. goto fail;
  502. ret = mxl111sf_enable_usb_output(state);
  503. if (mxl_fail(ret))
  504. goto fail;
  505. ret = mxl1x1sf_top_master_ctrl(state, 1);
  506. if (mxl_fail(ret))
  507. goto fail;
  508. ret = mxl111sf_init_port_expander(state);
  509. if (mxl_fail(ret))
  510. goto fail;
  511. ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
  512. if (mxl_fail(ret))
  513. goto fail;
  514. ret = get_chip_info(state);
  515. if (mxl_fail(ret))
  516. goto fail;
  517. adap->fe[fe_id] = dvb_attach(lg2160_attach,
  518. (MXL111SF_V8_200 == state->chip_rev) ?
  519. &hauppauge_lg2161_1040_config :
  520. &hauppauge_lg2161_1019_config,
  521. &d->i2c_adap);
  522. if (adap->fe[fe_id]) {
  523. state->num_frontends++;
  524. adap_state->fe_init = adap->fe[fe_id]->ops.init;
  525. adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
  526. adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
  527. adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
  528. return 0;
  529. }
  530. ret = -EIO;
  531. fail:
  532. return ret;
  533. }
  534. static struct lg2160_config hauppauge_lg2161_1019_ep6_config = {
  535. .lg_chip = LG2161_1019,
  536. .i2c_addr = 0x1c >> 1,
  537. .deny_i2c_rptr = 1,
  538. .spectral_inversion = 0,
  539. .if_khz = 6000,
  540. .output_if = 1, /* LG2161_OIF_SERIAL_TS */
  541. };
  542. static struct lg2160_config hauppauge_lg2161_1040_ep6_config = {
  543. .lg_chip = LG2161_1040,
  544. .i2c_addr = 0x1c >> 1,
  545. .deny_i2c_rptr = 1,
  546. .spectral_inversion = 0,
  547. .if_khz = 6000,
  548. .output_if = 7, /* LG2161_OIF_SERIAL_TS */
  549. };
  550. static int mxl111sf_lg2161_ep6_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
  551. {
  552. struct dvb_usb_device *d = adap_to_d(adap);
  553. struct mxl111sf_state *state = d_to_priv(d);
  554. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
  555. int ret;
  556. pr_debug("%s()\n", __func__);
  557. /* save a pointer to the dvb_usb_device in device state */
  558. state->d = d;
  559. adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
  560. state->alt_mode = adap_state->alt_mode;
  561. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  562. pr_err("set interface failed");
  563. state->gpio_mode = MXL111SF_GPIO_MOD_MH;
  564. adap_state->gpio_mode = state->gpio_mode;
  565. adap_state->device_mode = MXL_TUNER_MODE;
  566. adap_state->ep6_clockphase = 0;
  567. ret = mxl1x1sf_soft_reset(state);
  568. if (mxl_fail(ret))
  569. goto fail;
  570. ret = mxl111sf_init_tuner_demod(state);
  571. if (mxl_fail(ret))
  572. goto fail;
  573. ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  574. if (mxl_fail(ret))
  575. goto fail;
  576. ret = mxl111sf_enable_usb_output(state);
  577. if (mxl_fail(ret))
  578. goto fail;
  579. ret = mxl1x1sf_top_master_ctrl(state, 1);
  580. if (mxl_fail(ret))
  581. goto fail;
  582. ret = mxl111sf_init_port_expander(state);
  583. if (mxl_fail(ret))
  584. goto fail;
  585. ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
  586. if (mxl_fail(ret))
  587. goto fail;
  588. ret = get_chip_info(state);
  589. if (mxl_fail(ret))
  590. goto fail;
  591. adap->fe[fe_id] = dvb_attach(lg2160_attach,
  592. (MXL111SF_V8_200 == state->chip_rev) ?
  593. &hauppauge_lg2161_1040_ep6_config :
  594. &hauppauge_lg2161_1019_ep6_config,
  595. &d->i2c_adap);
  596. if (adap->fe[fe_id]) {
  597. state->num_frontends++;
  598. adap_state->fe_init = adap->fe[fe_id]->ops.init;
  599. adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
  600. adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
  601. adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
  602. return 0;
  603. }
  604. ret = -EIO;
  605. fail:
  606. return ret;
  607. }
  608. static const struct mxl111sf_demod_config mxl_demod_config = {
  609. .read_reg = mxl111sf_read_reg,
  610. .write_reg = mxl111sf_write_reg,
  611. .program_regs = mxl111sf_ctrl_program_regs,
  612. };
  613. static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap, u8 fe_id)
  614. {
  615. struct dvb_usb_device *d = adap_to_d(adap);
  616. struct mxl111sf_state *state = d_to_priv(d);
  617. struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
  618. int ret;
  619. pr_debug("%s()\n", __func__);
  620. /* save a pointer to the dvb_usb_device in device state */
  621. state->d = d;
  622. adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 1 : 2;
  623. state->alt_mode = adap_state->alt_mode;
  624. if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
  625. pr_err("set interface failed");
  626. state->gpio_mode = MXL111SF_GPIO_MOD_DVBT;
  627. adap_state->gpio_mode = state->gpio_mode;
  628. adap_state->device_mode = MXL_SOC_MODE;
  629. adap_state->ep6_clockphase = 1;
  630. ret = mxl1x1sf_soft_reset(state);
  631. if (mxl_fail(ret))
  632. goto fail;
  633. ret = mxl111sf_init_tuner_demod(state);
  634. if (mxl_fail(ret))
  635. goto fail;
  636. ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
  637. if (mxl_fail(ret))
  638. goto fail;
  639. ret = mxl111sf_enable_usb_output(state);
  640. if (mxl_fail(ret))
  641. goto fail;
  642. ret = mxl1x1sf_top_master_ctrl(state, 1);
  643. if (mxl_fail(ret))
  644. goto fail;
  645. /* dont care if this fails */
  646. mxl111sf_init_port_expander(state);
  647. adap->fe[fe_id] = dvb_attach(mxl111sf_demod_attach, state,
  648. &mxl_demod_config);
  649. if (adap->fe[fe_id]) {
  650. state->num_frontends++;
  651. adap_state->fe_init = adap->fe[fe_id]->ops.init;
  652. adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
  653. adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
  654. adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
  655. return 0;
  656. }
  657. ret = -EIO;
  658. fail:
  659. return ret;
  660. }
  661. static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
  662. int antpath)
  663. {
  664. return mxl111sf_idac_config(state, 1, 1,
  665. (antpath == ANT_PATH_INTERNAL) ?
  666. 0x3f : 0x00, 0);
  667. }
  668. #define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \
  669. pr_err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \
  670. __func__, __LINE__, \
  671. (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \
  672. pwr0, pwr1, pwr2, pwr3)
  673. #define ANT_HUNT_SLEEP 90
  674. #define ANT_EXT_TWEAK 0
  675. static int mxl111sf_ant_hunt(struct dvb_frontend *fe)
  676. {
  677. struct mxl111sf_state *state = fe_to_priv(fe);
  678. int antctrl = dvb_usb_mxl111sf_rfswitch;
  679. u16 rxPwrA, rxPwr0, rxPwr1, rxPwr2;
  680. /* FIXME: must force EXTERNAL for QAM - done elsewhere */
  681. mxl111sf_set_ant_path(state, antctrl == ANT_PATH_AUTO ?
  682. ANT_PATH_EXTERNAL : antctrl);
  683. if (antctrl == ANT_PATH_AUTO) {
  684. #if 0
  685. msleep(ANT_HUNT_SLEEP);
  686. #endif
  687. fe->ops.tuner_ops.get_rf_strength(fe, &rxPwrA);
  688. mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
  689. msleep(ANT_HUNT_SLEEP);
  690. fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr0);
  691. mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
  692. msleep(ANT_HUNT_SLEEP);
  693. fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr1);
  694. mxl111sf_set_ant_path(state, ANT_PATH_INTERNAL);
  695. msleep(ANT_HUNT_SLEEP);
  696. fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr2);
  697. if (rxPwr1+ANT_EXT_TWEAK >= rxPwr2) {
  698. /* return with EXTERNAL enabled */
  699. mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
  700. DbgAntHunt(ANT_PATH_EXTERNAL, rxPwrA,
  701. rxPwr0, rxPwr1, rxPwr2);
  702. } else {
  703. /* return with INTERNAL enabled */
  704. DbgAntHunt(ANT_PATH_INTERNAL, rxPwrA,
  705. rxPwr0, rxPwr1, rxPwr2);
  706. }
  707. }
  708. return 0;
  709. }
  710. static const struct mxl111sf_tuner_config mxl_tuner_config = {
  711. .if_freq = MXL_IF_6_0, /* applies to external IF output, only */
  712. .invert_spectrum = 0,
  713. .read_reg = mxl111sf_read_reg,
  714. .write_reg = mxl111sf_write_reg,
  715. .program_regs = mxl111sf_ctrl_program_regs,
  716. .top_master_ctrl = mxl1x1sf_top_master_ctrl,
  717. .ant_hunt = mxl111sf_ant_hunt,
  718. };
  719. static int mxl111sf_attach_tuner(struct dvb_usb_adapter *adap)
  720. {
  721. struct mxl111sf_state *state = adap_to_priv(adap);
  722. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  723. struct media_device *mdev = dvb_get_media_controller(&adap->dvb_adap);
  724. int ret;
  725. #endif
  726. int i;
  727. pr_debug("%s()\n", __func__);
  728. for (i = 0; i < state->num_frontends; i++) {
  729. if (dvb_attach(mxl111sf_tuner_attach, adap->fe[i], state,
  730. &mxl_tuner_config) == NULL)
  731. return -EIO;
  732. adap->fe[i]->ops.read_signal_strength = adap->fe[i]->ops.tuner_ops.get_rf_strength;
  733. }
  734. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  735. state->tuner.function = MEDIA_ENT_F_TUNER;
  736. state->tuner.name = "mxl111sf tuner";
  737. state->tuner_pads[TUNER_PAD_RF_INPUT].flags = MEDIA_PAD_FL_SINK;
  738. state->tuner_pads[TUNER_PAD_OUTPUT].flags = MEDIA_PAD_FL_SOURCE;
  739. ret = media_entity_pads_init(&state->tuner,
  740. TUNER_NUM_PADS, state->tuner_pads);
  741. if (ret)
  742. return ret;
  743. ret = media_device_register_entity(mdev, &state->tuner);
  744. if (ret)
  745. return ret;
  746. #endif
  747. return 0;
  748. }
  749. static u32 mxl111sf_i2c_func(struct i2c_adapter *adapter)
  750. {
  751. return I2C_FUNC_I2C;
  752. }
  753. static struct i2c_algorithm mxl111sf_i2c_algo = {
  754. .master_xfer = mxl111sf_i2c_xfer,
  755. .functionality = mxl111sf_i2c_func,
  756. #ifdef NEED_ALGO_CONTROL
  757. .algo_control = dummy_algo_control,
  758. #endif
  759. };
  760. static int mxl111sf_init(struct dvb_usb_device *d)
  761. {
  762. struct mxl111sf_state *state = d_to_priv(d);
  763. int ret;
  764. static u8 eeprom[256];
  765. u8 reg = 0;
  766. struct i2c_msg msg[2] = {
  767. { .addr = 0xa0 >> 1, .len = 1, .buf = &reg },
  768. { .addr = 0xa0 >> 1, .flags = I2C_M_RD,
  769. .len = sizeof(eeprom), .buf = eeprom },
  770. };
  771. ret = get_chip_info(state);
  772. if (mxl_fail(ret))
  773. pr_err("failed to get chip info during probe");
  774. mutex_init(&state->fe_lock);
  775. if (state->chip_rev > MXL111SF_V6)
  776. mxl111sf_config_pin_mux_modes(state, PIN_MUX_TS_SPI_IN_MODE_1);
  777. ret = i2c_transfer(&d->i2c_adap, msg, 2);
  778. if (mxl_fail(ret))
  779. return 0;
  780. tveeprom_hauppauge_analog(&state->tv, (0x84 == eeprom[0xa0]) ?
  781. eeprom + 0xa0 : eeprom + 0x80);
  782. #if 0
  783. switch (state->tv.model) {
  784. case 117001:
  785. case 126001:
  786. case 138001:
  787. break;
  788. default:
  789. printk(KERN_WARNING "%s: warning: unknown hauppauge model #%d\n",
  790. __func__, state->tv.model);
  791. }
  792. #endif
  793. return 0;
  794. }
  795. static int mxl111sf_frontend_attach_dvbt(struct dvb_usb_adapter *adap)
  796. {
  797. return mxl111sf_attach_demod(adap, 0);
  798. }
  799. static int mxl111sf_frontend_attach_atsc(struct dvb_usb_adapter *adap)
  800. {
  801. return mxl111sf_lgdt3305_frontend_attach(adap, 0);
  802. }
  803. static int mxl111sf_frontend_attach_mh(struct dvb_usb_adapter *adap)
  804. {
  805. return mxl111sf_lg2160_frontend_attach(adap, 0);
  806. }
  807. static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap)
  808. {
  809. int ret;
  810. pr_debug("%s\n", __func__);
  811. ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
  812. if (ret < 0)
  813. return ret;
  814. ret = mxl111sf_attach_demod(adap, 1);
  815. if (ret < 0)
  816. return ret;
  817. ret = mxl111sf_lg2160_frontend_attach(adap, 2);
  818. if (ret < 0)
  819. return ret;
  820. return ret;
  821. }
  822. static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap)
  823. {
  824. int ret;
  825. pr_debug("%s\n", __func__);
  826. ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
  827. if (ret < 0)
  828. return ret;
  829. ret = mxl111sf_attach_demod(adap, 1);
  830. if (ret < 0)
  831. return ret;
  832. ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 2);
  833. if (ret < 0)
  834. return ret;
  835. return ret;
  836. }
  837. static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap)
  838. {
  839. int ret;
  840. pr_debug("%s\n", __func__);
  841. ret = mxl111sf_attach_demod(adap, 0);
  842. if (ret < 0)
  843. return ret;
  844. if (dvb_usb_mxl111sf_spi)
  845. ret = mxl111sf_lg2161_frontend_attach(adap, 1);
  846. else
  847. ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 1);
  848. return ret;
  849. }
  850. static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *stream, u8 endpoint)
  851. {
  852. pr_debug("%s: endpoint=%d size=8192\n", __func__, endpoint);
  853. stream->type = USB_BULK;
  854. stream->count = 5;
  855. stream->endpoint = endpoint;
  856. stream->u.bulk.buffersize = 8192;
  857. }
  858. static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *stream,
  859. u8 endpoint, int framesperurb, int framesize)
  860. {
  861. pr_debug("%s: endpoint=%d size=%d\n", __func__, endpoint,
  862. framesperurb * framesize);
  863. stream->type = USB_ISOC;
  864. stream->count = 5;
  865. stream->endpoint = endpoint;
  866. stream->u.isoc.framesperurb = framesperurb;
  867. stream->u.isoc.framesize = framesize;
  868. stream->u.isoc.interval = 1;
  869. }
  870. /* DVB USB Driver stuff */
  871. /* dvbt mxl111sf
  872. * bulk EP4/BULK/5/8192
  873. * isoc EP4/ISOC/5/96/564
  874. */
  875. static int mxl111sf_get_stream_config_dvbt(struct dvb_frontend *fe,
  876. u8 *ts_type, struct usb_data_stream_properties *stream)
  877. {
  878. pr_debug("%s: fe=%d\n", __func__, fe->id);
  879. *ts_type = DVB_USB_FE_TS_TYPE_188;
  880. if (dvb_usb_mxl111sf_isoc)
  881. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  882. else
  883. mxl111sf_stream_config_bulk(stream, 4);
  884. return 0;
  885. }
  886. static struct dvb_usb_device_properties mxl111sf_props_dvbt = {
  887. .driver_name = KBUILD_MODNAME,
  888. .owner = THIS_MODULE,
  889. .adapter_nr = adapter_nr,
  890. .size_of_priv = sizeof(struct mxl111sf_state),
  891. .generic_bulk_ctrl_endpoint = 0x02,
  892. .generic_bulk_ctrl_endpoint_response = 0x81,
  893. .i2c_algo = &mxl111sf_i2c_algo,
  894. .frontend_attach = mxl111sf_frontend_attach_dvbt,
  895. .tuner_attach = mxl111sf_attach_tuner,
  896. .init = mxl111sf_init,
  897. .streaming_ctrl = mxl111sf_ep4_streaming_ctrl,
  898. .get_stream_config = mxl111sf_get_stream_config_dvbt,
  899. .num_adapters = 1,
  900. .adapter = {
  901. {
  902. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  903. }
  904. }
  905. };
  906. /* atsc lgdt3305
  907. * bulk EP6/BULK/5/8192
  908. * isoc EP6/ISOC/5/24/3072
  909. */
  910. static int mxl111sf_get_stream_config_atsc(struct dvb_frontend *fe,
  911. u8 *ts_type, struct usb_data_stream_properties *stream)
  912. {
  913. pr_debug("%s: fe=%d\n", __func__, fe->id);
  914. *ts_type = DVB_USB_FE_TS_TYPE_188;
  915. if (dvb_usb_mxl111sf_isoc)
  916. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  917. else
  918. mxl111sf_stream_config_bulk(stream, 6);
  919. return 0;
  920. }
  921. static struct dvb_usb_device_properties mxl111sf_props_atsc = {
  922. .driver_name = KBUILD_MODNAME,
  923. .owner = THIS_MODULE,
  924. .adapter_nr = adapter_nr,
  925. .size_of_priv = sizeof(struct mxl111sf_state),
  926. .generic_bulk_ctrl_endpoint = 0x02,
  927. .generic_bulk_ctrl_endpoint_response = 0x81,
  928. .i2c_algo = &mxl111sf_i2c_algo,
  929. .frontend_attach = mxl111sf_frontend_attach_atsc,
  930. .tuner_attach = mxl111sf_attach_tuner,
  931. .init = mxl111sf_init,
  932. .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,
  933. .get_stream_config = mxl111sf_get_stream_config_atsc,
  934. .num_adapters = 1,
  935. .adapter = {
  936. {
  937. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  938. }
  939. }
  940. };
  941. /* mh lg2160
  942. * bulk EP5/BULK/5/8192/RAW
  943. * isoc EP5/ISOC/5/96/200/RAW
  944. */
  945. static int mxl111sf_get_stream_config_mh(struct dvb_frontend *fe,
  946. u8 *ts_type, struct usb_data_stream_properties *stream)
  947. {
  948. pr_debug("%s: fe=%d\n", __func__, fe->id);
  949. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  950. if (dvb_usb_mxl111sf_isoc)
  951. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  952. else
  953. mxl111sf_stream_config_bulk(stream, 5);
  954. return 0;
  955. }
  956. static struct dvb_usb_device_properties mxl111sf_props_mh = {
  957. .driver_name = KBUILD_MODNAME,
  958. .owner = THIS_MODULE,
  959. .adapter_nr = adapter_nr,
  960. .size_of_priv = sizeof(struct mxl111sf_state),
  961. .generic_bulk_ctrl_endpoint = 0x02,
  962. .generic_bulk_ctrl_endpoint_response = 0x81,
  963. .i2c_algo = &mxl111sf_i2c_algo,
  964. .frontend_attach = mxl111sf_frontend_attach_mh,
  965. .tuner_attach = mxl111sf_attach_tuner,
  966. .init = mxl111sf_init,
  967. .streaming_ctrl = mxl111sf_ep5_streaming_ctrl,
  968. .get_stream_config = mxl111sf_get_stream_config_mh,
  969. .num_adapters = 1,
  970. .adapter = {
  971. {
  972. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  973. }
  974. }
  975. };
  976. /* atsc mh lgdt3305 mxl111sf lg2160
  977. * bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  978. * isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  979. */
  980. static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe,
  981. u8 *ts_type, struct usb_data_stream_properties *stream)
  982. {
  983. pr_debug("%s: fe=%d\n", __func__, fe->id);
  984. if (fe->id == 0) {
  985. *ts_type = DVB_USB_FE_TS_TYPE_188;
  986. if (dvb_usb_mxl111sf_isoc)
  987. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  988. else
  989. mxl111sf_stream_config_bulk(stream, 6);
  990. } else if (fe->id == 1) {
  991. *ts_type = DVB_USB_FE_TS_TYPE_188;
  992. if (dvb_usb_mxl111sf_isoc)
  993. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  994. else
  995. mxl111sf_stream_config_bulk(stream, 4);
  996. } else if (fe->id == 2) {
  997. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  998. if (dvb_usb_mxl111sf_isoc)
  999. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  1000. else
  1001. mxl111sf_stream_config_bulk(stream, 5);
  1002. }
  1003. return 0;
  1004. }
  1005. static int mxl111sf_streaming_ctrl_atsc_mh(struct dvb_frontend *fe, int onoff)
  1006. {
  1007. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1008. if (fe->id == 0)
  1009. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1010. else if (fe->id == 1)
  1011. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  1012. else if (fe->id == 2)
  1013. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  1014. return 0;
  1015. }
  1016. static struct dvb_usb_device_properties mxl111sf_props_atsc_mh = {
  1017. .driver_name = KBUILD_MODNAME,
  1018. .owner = THIS_MODULE,
  1019. .adapter_nr = adapter_nr,
  1020. .size_of_priv = sizeof(struct mxl111sf_state),
  1021. .generic_bulk_ctrl_endpoint = 0x02,
  1022. .generic_bulk_ctrl_endpoint_response = 0x81,
  1023. .i2c_algo = &mxl111sf_i2c_algo,
  1024. .frontend_attach = mxl111sf_frontend_attach_atsc_mh,
  1025. .tuner_attach = mxl111sf_attach_tuner,
  1026. .init = mxl111sf_init,
  1027. .streaming_ctrl = mxl111sf_streaming_ctrl_atsc_mh,
  1028. .get_stream_config = mxl111sf_get_stream_config_atsc_mh,
  1029. .num_adapters = 1,
  1030. .adapter = {
  1031. {
  1032. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1033. }
  1034. }
  1035. };
  1036. /* mercury lgdt3305 mxl111sf lg2161
  1037. * tp bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
  1038. * tp isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
  1039. * spi bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  1040. * spi isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  1041. */
  1042. static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe,
  1043. u8 *ts_type, struct usb_data_stream_properties *stream)
  1044. {
  1045. pr_debug("%s: fe=%d\n", __func__, fe->id);
  1046. if (fe->id == 0) {
  1047. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1048. if (dvb_usb_mxl111sf_isoc)
  1049. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1050. else
  1051. mxl111sf_stream_config_bulk(stream, 6);
  1052. } else if (fe->id == 1) {
  1053. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1054. if (dvb_usb_mxl111sf_isoc)
  1055. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  1056. else
  1057. mxl111sf_stream_config_bulk(stream, 4);
  1058. } else if (fe->id == 2 && dvb_usb_mxl111sf_spi) {
  1059. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1060. if (dvb_usb_mxl111sf_isoc)
  1061. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  1062. else
  1063. mxl111sf_stream_config_bulk(stream, 5);
  1064. } else if (fe->id == 2 && !dvb_usb_mxl111sf_spi) {
  1065. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1066. if (dvb_usb_mxl111sf_isoc)
  1067. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1068. else
  1069. mxl111sf_stream_config_bulk(stream, 6);
  1070. }
  1071. return 0;
  1072. }
  1073. static int mxl111sf_streaming_ctrl_mercury(struct dvb_frontend *fe, int onoff)
  1074. {
  1075. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1076. if (fe->id == 0)
  1077. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1078. else if (fe->id == 1)
  1079. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  1080. else if (fe->id == 2 && dvb_usb_mxl111sf_spi)
  1081. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  1082. else if (fe->id == 2 && !dvb_usb_mxl111sf_spi)
  1083. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1084. return 0;
  1085. }
  1086. static struct dvb_usb_device_properties mxl111sf_props_mercury = {
  1087. .driver_name = KBUILD_MODNAME,
  1088. .owner = THIS_MODULE,
  1089. .adapter_nr = adapter_nr,
  1090. .size_of_priv = sizeof(struct mxl111sf_state),
  1091. .generic_bulk_ctrl_endpoint = 0x02,
  1092. .generic_bulk_ctrl_endpoint_response = 0x81,
  1093. .i2c_algo = &mxl111sf_i2c_algo,
  1094. .frontend_attach = mxl111sf_frontend_attach_mercury,
  1095. .tuner_attach = mxl111sf_attach_tuner,
  1096. .init = mxl111sf_init,
  1097. .streaming_ctrl = mxl111sf_streaming_ctrl_mercury,
  1098. .get_stream_config = mxl111sf_get_stream_config_mercury,
  1099. .num_adapters = 1,
  1100. .adapter = {
  1101. {
  1102. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1103. }
  1104. }
  1105. };
  1106. /* mercury mh mxl111sf lg2161
  1107. * tp bulk EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
  1108. * tp isoc EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
  1109. * spi bulk EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  1110. * spi isoc EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  1111. */
  1112. static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe,
  1113. u8 *ts_type, struct usb_data_stream_properties *stream)
  1114. {
  1115. pr_debug("%s: fe=%d\n", __func__, fe->id);
  1116. if (fe->id == 0) {
  1117. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1118. if (dvb_usb_mxl111sf_isoc)
  1119. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  1120. else
  1121. mxl111sf_stream_config_bulk(stream, 4);
  1122. } else if (fe->id == 1 && dvb_usb_mxl111sf_spi) {
  1123. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1124. if (dvb_usb_mxl111sf_isoc)
  1125. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  1126. else
  1127. mxl111sf_stream_config_bulk(stream, 5);
  1128. } else if (fe->id == 1 && !dvb_usb_mxl111sf_spi) {
  1129. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1130. if (dvb_usb_mxl111sf_isoc)
  1131. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1132. else
  1133. mxl111sf_stream_config_bulk(stream, 6);
  1134. }
  1135. return 0;
  1136. }
  1137. static int mxl111sf_streaming_ctrl_mercury_mh(struct dvb_frontend *fe, int onoff)
  1138. {
  1139. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1140. if (fe->id == 0)
  1141. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  1142. else if (fe->id == 1 && dvb_usb_mxl111sf_spi)
  1143. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  1144. else if (fe->id == 1 && !dvb_usb_mxl111sf_spi)
  1145. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1146. return 0;
  1147. }
  1148. static struct dvb_usb_device_properties mxl111sf_props_mercury_mh = {
  1149. .driver_name = KBUILD_MODNAME,
  1150. .owner = THIS_MODULE,
  1151. .adapter_nr = adapter_nr,
  1152. .size_of_priv = sizeof(struct mxl111sf_state),
  1153. .generic_bulk_ctrl_endpoint = 0x02,
  1154. .generic_bulk_ctrl_endpoint_response = 0x81,
  1155. .i2c_algo = &mxl111sf_i2c_algo,
  1156. .frontend_attach = mxl111sf_frontend_attach_mercury_mh,
  1157. .tuner_attach = mxl111sf_attach_tuner,
  1158. .init = mxl111sf_init,
  1159. .streaming_ctrl = mxl111sf_streaming_ctrl_mercury_mh,
  1160. .get_stream_config = mxl111sf_get_stream_config_mercury_mh,
  1161. .num_adapters = 1,
  1162. .adapter = {
  1163. {
  1164. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1165. }
  1166. }
  1167. };
  1168. static const struct usb_device_id mxl111sf_id_table[] = {
  1169. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc600, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1170. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc601, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1171. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc602, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
  1172. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc603, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1173. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc604, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
  1174. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc609, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1175. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60a, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
  1176. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1177. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60c, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
  1178. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc653, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1179. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc65b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1180. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb700, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1181. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb701, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1182. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb702, &mxl111sf_props_mh, "HCW 117xxx", NULL) },
  1183. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb703, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1184. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb704, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
  1185. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb753, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1186. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb763, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1187. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb764, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
  1188. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd853, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1189. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd854, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1190. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd863, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1191. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd864, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1192. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1193. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1194. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1195. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1196. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8ff, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1197. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc612, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
  1198. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc613, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
  1199. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61a, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
  1200. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61b, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
  1201. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb757, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1202. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb767, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1203. { }
  1204. };
  1205. MODULE_DEVICE_TABLE(usb, mxl111sf_id_table);
  1206. static struct usb_driver mxl111sf_usb_driver = {
  1207. .name = KBUILD_MODNAME,
  1208. .id_table = mxl111sf_id_table,
  1209. .probe = dvb_usbv2_probe,
  1210. .disconnect = dvb_usbv2_disconnect,
  1211. .suspend = dvb_usbv2_suspend,
  1212. .resume = dvb_usbv2_resume,
  1213. .no_dynamic_id = 1,
  1214. .soft_unbind = 1,
  1215. };
  1216. module_usb_driver(mxl111sf_usb_driver);
  1217. MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
  1218. MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
  1219. MODULE_VERSION("1.0");
  1220. MODULE_LICENSE("GPL");