mxl111sf.c 40 KB

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