mxl111sf.c 39 KB

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