mxl111sf.c 40 KB

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