mxl111sf.c 40 KB

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