mxl111sf.c 39 KB

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