mxl111sf.c 40 KB

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