mxl111sf.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  1. /*
  2. * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation, version 2.
  7. *
  8. * see Documentation/dvb/README.dvb-usb for more information
  9. */
  10. #include <linux/vmalloc.h>
  11. #include <linux/i2c.h>
  12. #include "mxl111sf.h"
  13. #include "mxl111sf-reg.h"
  14. #include "mxl111sf-phy.h"
  15. #include "mxl111sf-i2c.h"
  16. #include "mxl111sf-gpio.h"
  17. #include "mxl111sf-demod.h"
  18. #include "mxl111sf-tuner.h"
  19. #include "lgdt3305.h"
  20. #include "lg2160.h"
  21. /* Max transfer size done by I2C transfer functions */
  22. #define MAX_XFER_SIZE 64
  23. int dvb_usb_mxl111sf_debug;
  24. module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
  25. MODULE_PARM_DESC(debug, "set debugging level "
  26. "(1=info, 2=xfer, 4=i2c, 8=reg, 16=adv (or-able)).");
  27. 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. 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. 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, *data);
  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;
  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, "
  109. "data: 0x%02x, retrying...", 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 didnt 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. mxl111sf_enable_usb_output(state);
  239. mxl_fail(err);
  240. 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 didnt 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 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 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. int i;
  723. pr_debug("%s()\n", __func__);
  724. for (i = 0; i < state->num_frontends; i++) {
  725. if (dvb_attach(mxl111sf_tuner_attach, adap->fe[i], state,
  726. &mxl_tuner_config) == NULL)
  727. return -EIO;
  728. adap->fe[i]->ops.read_signal_strength = adap->fe[i]->ops.tuner_ops.get_rf_strength;
  729. }
  730. return 0;
  731. }
  732. static u32 mxl111sf_i2c_func(struct i2c_adapter *adapter)
  733. {
  734. return I2C_FUNC_I2C;
  735. }
  736. struct i2c_algorithm mxl111sf_i2c_algo = {
  737. .master_xfer = mxl111sf_i2c_xfer,
  738. .functionality = mxl111sf_i2c_func,
  739. #ifdef NEED_ALGO_CONTROL
  740. .algo_control = dummy_algo_control,
  741. #endif
  742. };
  743. static int mxl111sf_init(struct dvb_usb_device *d)
  744. {
  745. struct mxl111sf_state *state = d_to_priv(d);
  746. int ret;
  747. static u8 eeprom[256];
  748. struct i2c_client c;
  749. ret = get_chip_info(state);
  750. if (mxl_fail(ret))
  751. pr_err("failed to get chip info during probe");
  752. mutex_init(&state->fe_lock);
  753. if (state->chip_rev > MXL111SF_V6)
  754. mxl111sf_config_pin_mux_modes(state, PIN_MUX_TS_SPI_IN_MODE_1);
  755. c.adapter = &d->i2c_adap;
  756. c.addr = 0xa0 >> 1;
  757. ret = tveeprom_read(&c, eeprom, sizeof(eeprom));
  758. if (mxl_fail(ret))
  759. return 0;
  760. tveeprom_hauppauge_analog(&c, &state->tv, (0x84 == eeprom[0xa0]) ?
  761. eeprom + 0xa0 : eeprom + 0x80);
  762. #if 0
  763. switch (state->tv.model) {
  764. case 117001:
  765. case 126001:
  766. case 138001:
  767. break;
  768. default:
  769. printk(KERN_WARNING "%s: warning: "
  770. "unknown hauppauge model #%d\n",
  771. __func__, state->tv.model);
  772. }
  773. #endif
  774. return 0;
  775. }
  776. static int mxl111sf_frontend_attach_dvbt(struct dvb_usb_adapter *adap)
  777. {
  778. return mxl111sf_attach_demod(adap, 0);
  779. }
  780. static int mxl111sf_frontend_attach_atsc(struct dvb_usb_adapter *adap)
  781. {
  782. return mxl111sf_lgdt3305_frontend_attach(adap, 0);
  783. }
  784. static int mxl111sf_frontend_attach_mh(struct dvb_usb_adapter *adap)
  785. {
  786. return mxl111sf_lg2160_frontend_attach(adap, 0);
  787. }
  788. static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap)
  789. {
  790. int ret;
  791. pr_debug("%s\n", __func__);
  792. ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
  793. if (ret < 0)
  794. return ret;
  795. ret = mxl111sf_attach_demod(adap, 1);
  796. if (ret < 0)
  797. return ret;
  798. ret = mxl111sf_lg2160_frontend_attach(adap, 2);
  799. if (ret < 0)
  800. return ret;
  801. return ret;
  802. }
  803. static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap)
  804. {
  805. int ret;
  806. pr_debug("%s\n", __func__);
  807. ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
  808. if (ret < 0)
  809. return ret;
  810. ret = mxl111sf_attach_demod(adap, 1);
  811. if (ret < 0)
  812. return ret;
  813. ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 2);
  814. if (ret < 0)
  815. return ret;
  816. return ret;
  817. }
  818. static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap)
  819. {
  820. int ret;
  821. pr_debug("%s\n", __func__);
  822. ret = mxl111sf_attach_demod(adap, 0);
  823. if (ret < 0)
  824. return ret;
  825. if (dvb_usb_mxl111sf_spi)
  826. ret = mxl111sf_lg2161_frontend_attach(adap, 1);
  827. else
  828. ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 1);
  829. return ret;
  830. }
  831. static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *stream, u8 endpoint)
  832. {
  833. pr_debug("%s: endpoint=%d size=8192\n", __func__, endpoint);
  834. stream->type = USB_BULK;
  835. stream->count = 5;
  836. stream->endpoint = endpoint;
  837. stream->u.bulk.buffersize = 8192;
  838. }
  839. static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *stream,
  840. u8 endpoint, int framesperurb, int framesize)
  841. {
  842. pr_debug("%s: endpoint=%d size=%d\n", __func__, endpoint,
  843. framesperurb * framesize);
  844. stream->type = USB_ISOC;
  845. stream->count = 5;
  846. stream->endpoint = endpoint;
  847. stream->u.isoc.framesperurb = framesperurb;
  848. stream->u.isoc.framesize = framesize;
  849. stream->u.isoc.interval = 1;
  850. }
  851. /* DVB USB Driver stuff */
  852. /* dvbt mxl111sf
  853. * bulk EP4/BULK/5/8192
  854. * isoc EP4/ISOC/5/96/564
  855. */
  856. static int mxl111sf_get_stream_config_dvbt(struct dvb_frontend *fe,
  857. u8 *ts_type, struct usb_data_stream_properties *stream)
  858. {
  859. pr_debug("%s: fe=%d\n", __func__, fe->id);
  860. *ts_type = DVB_USB_FE_TS_TYPE_188;
  861. if (dvb_usb_mxl111sf_isoc)
  862. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  863. else
  864. mxl111sf_stream_config_bulk(stream, 4);
  865. return 0;
  866. }
  867. static struct dvb_usb_device_properties mxl111sf_props_dvbt = {
  868. .driver_name = KBUILD_MODNAME,
  869. .owner = THIS_MODULE,
  870. .adapter_nr = adapter_nr,
  871. .size_of_priv = sizeof(struct mxl111sf_state),
  872. .generic_bulk_ctrl_endpoint = 0x02,
  873. .generic_bulk_ctrl_endpoint_response = 0x81,
  874. .i2c_algo = &mxl111sf_i2c_algo,
  875. .frontend_attach = mxl111sf_frontend_attach_dvbt,
  876. .tuner_attach = mxl111sf_attach_tuner,
  877. .init = mxl111sf_init,
  878. .streaming_ctrl = mxl111sf_ep4_streaming_ctrl,
  879. .get_stream_config = mxl111sf_get_stream_config_dvbt,
  880. .num_adapters = 1,
  881. .adapter = {
  882. {
  883. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  884. }
  885. }
  886. };
  887. /* atsc lgdt3305
  888. * bulk EP6/BULK/5/8192
  889. * isoc EP6/ISOC/5/24/3072
  890. */
  891. static int mxl111sf_get_stream_config_atsc(struct dvb_frontend *fe,
  892. u8 *ts_type, struct usb_data_stream_properties *stream)
  893. {
  894. pr_debug("%s: fe=%d\n", __func__, fe->id);
  895. *ts_type = DVB_USB_FE_TS_TYPE_188;
  896. if (dvb_usb_mxl111sf_isoc)
  897. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  898. else
  899. mxl111sf_stream_config_bulk(stream, 6);
  900. return 0;
  901. }
  902. static struct dvb_usb_device_properties mxl111sf_props_atsc = {
  903. .driver_name = KBUILD_MODNAME,
  904. .owner = THIS_MODULE,
  905. .adapter_nr = adapter_nr,
  906. .size_of_priv = sizeof(struct mxl111sf_state),
  907. .generic_bulk_ctrl_endpoint = 0x02,
  908. .generic_bulk_ctrl_endpoint_response = 0x81,
  909. .i2c_algo = &mxl111sf_i2c_algo,
  910. .frontend_attach = mxl111sf_frontend_attach_atsc,
  911. .tuner_attach = mxl111sf_attach_tuner,
  912. .init = mxl111sf_init,
  913. .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,
  914. .get_stream_config = mxl111sf_get_stream_config_atsc,
  915. .num_adapters = 1,
  916. .adapter = {
  917. {
  918. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  919. }
  920. }
  921. };
  922. /* mh lg2160
  923. * bulk EP5/BULK/5/8192/RAW
  924. * isoc EP5/ISOC/5/96/200/RAW
  925. */
  926. static int mxl111sf_get_stream_config_mh(struct dvb_frontend *fe,
  927. u8 *ts_type, struct usb_data_stream_properties *stream)
  928. {
  929. pr_debug("%s: fe=%d\n", __func__, fe->id);
  930. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  931. if (dvb_usb_mxl111sf_isoc)
  932. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  933. else
  934. mxl111sf_stream_config_bulk(stream, 5);
  935. return 0;
  936. }
  937. static struct dvb_usb_device_properties mxl111sf_props_mh = {
  938. .driver_name = KBUILD_MODNAME,
  939. .owner = THIS_MODULE,
  940. .adapter_nr = adapter_nr,
  941. .size_of_priv = sizeof(struct mxl111sf_state),
  942. .generic_bulk_ctrl_endpoint = 0x02,
  943. .generic_bulk_ctrl_endpoint_response = 0x81,
  944. .i2c_algo = &mxl111sf_i2c_algo,
  945. .frontend_attach = mxl111sf_frontend_attach_mh,
  946. .tuner_attach = mxl111sf_attach_tuner,
  947. .init = mxl111sf_init,
  948. .streaming_ctrl = mxl111sf_ep5_streaming_ctrl,
  949. .get_stream_config = mxl111sf_get_stream_config_mh,
  950. .num_adapters = 1,
  951. .adapter = {
  952. {
  953. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  954. }
  955. }
  956. };
  957. /* atsc mh lgdt3305 mxl111sf lg2160
  958. * bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  959. * isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  960. */
  961. static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe,
  962. u8 *ts_type, struct usb_data_stream_properties *stream)
  963. {
  964. pr_debug("%s: fe=%d\n", __func__, fe->id);
  965. if (fe->id == 0) {
  966. *ts_type = DVB_USB_FE_TS_TYPE_188;
  967. if (dvb_usb_mxl111sf_isoc)
  968. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  969. else
  970. mxl111sf_stream_config_bulk(stream, 6);
  971. } else if (fe->id == 1) {
  972. *ts_type = DVB_USB_FE_TS_TYPE_188;
  973. if (dvb_usb_mxl111sf_isoc)
  974. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  975. else
  976. mxl111sf_stream_config_bulk(stream, 4);
  977. } else if (fe->id == 2) {
  978. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  979. if (dvb_usb_mxl111sf_isoc)
  980. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  981. else
  982. mxl111sf_stream_config_bulk(stream, 5);
  983. }
  984. return 0;
  985. }
  986. static int mxl111sf_streaming_ctrl_atsc_mh(struct dvb_frontend *fe, int onoff)
  987. {
  988. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  989. if (fe->id == 0)
  990. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  991. else if (fe->id == 1)
  992. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  993. else if (fe->id == 2)
  994. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  995. return 0;
  996. }
  997. static struct dvb_usb_device_properties mxl111sf_props_atsc_mh = {
  998. .driver_name = KBUILD_MODNAME,
  999. .owner = THIS_MODULE,
  1000. .adapter_nr = adapter_nr,
  1001. .size_of_priv = sizeof(struct mxl111sf_state),
  1002. .generic_bulk_ctrl_endpoint = 0x02,
  1003. .generic_bulk_ctrl_endpoint_response = 0x81,
  1004. .i2c_algo = &mxl111sf_i2c_algo,
  1005. .frontend_attach = mxl111sf_frontend_attach_atsc_mh,
  1006. .tuner_attach = mxl111sf_attach_tuner,
  1007. .init = mxl111sf_init,
  1008. .streaming_ctrl = mxl111sf_streaming_ctrl_atsc_mh,
  1009. .get_stream_config = mxl111sf_get_stream_config_atsc_mh,
  1010. .num_adapters = 1,
  1011. .adapter = {
  1012. {
  1013. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1014. }
  1015. }
  1016. };
  1017. /* mercury lgdt3305 mxl111sf lg2161
  1018. * tp bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
  1019. * tp isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
  1020. * spi bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  1021. * spi isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  1022. */
  1023. static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe,
  1024. u8 *ts_type, struct usb_data_stream_properties *stream)
  1025. {
  1026. pr_debug("%s: fe=%d\n", __func__, fe->id);
  1027. if (fe->id == 0) {
  1028. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1029. if (dvb_usb_mxl111sf_isoc)
  1030. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1031. else
  1032. mxl111sf_stream_config_bulk(stream, 6);
  1033. } else if (fe->id == 1) {
  1034. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1035. if (dvb_usb_mxl111sf_isoc)
  1036. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  1037. else
  1038. mxl111sf_stream_config_bulk(stream, 4);
  1039. } else if (fe->id == 2 && dvb_usb_mxl111sf_spi) {
  1040. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1041. if (dvb_usb_mxl111sf_isoc)
  1042. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  1043. else
  1044. mxl111sf_stream_config_bulk(stream, 5);
  1045. } else if (fe->id == 2 && !dvb_usb_mxl111sf_spi) {
  1046. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1047. if (dvb_usb_mxl111sf_isoc)
  1048. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1049. else
  1050. mxl111sf_stream_config_bulk(stream, 6);
  1051. }
  1052. return 0;
  1053. }
  1054. static int mxl111sf_streaming_ctrl_mercury(struct dvb_frontend *fe, int onoff)
  1055. {
  1056. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1057. if (fe->id == 0)
  1058. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1059. else if (fe->id == 1)
  1060. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  1061. else if (fe->id == 2 && dvb_usb_mxl111sf_spi)
  1062. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  1063. else if (fe->id == 2 && !dvb_usb_mxl111sf_spi)
  1064. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1065. return 0;
  1066. }
  1067. static struct dvb_usb_device_properties mxl111sf_props_mercury = {
  1068. .driver_name = KBUILD_MODNAME,
  1069. .owner = THIS_MODULE,
  1070. .adapter_nr = adapter_nr,
  1071. .size_of_priv = sizeof(struct mxl111sf_state),
  1072. .generic_bulk_ctrl_endpoint = 0x02,
  1073. .generic_bulk_ctrl_endpoint_response = 0x81,
  1074. .i2c_algo = &mxl111sf_i2c_algo,
  1075. .frontend_attach = mxl111sf_frontend_attach_mercury,
  1076. .tuner_attach = mxl111sf_attach_tuner,
  1077. .init = mxl111sf_init,
  1078. .streaming_ctrl = mxl111sf_streaming_ctrl_mercury,
  1079. .get_stream_config = mxl111sf_get_stream_config_mercury,
  1080. .num_adapters = 1,
  1081. .adapter = {
  1082. {
  1083. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1084. }
  1085. }
  1086. };
  1087. /* mercury mh mxl111sf lg2161
  1088. * tp bulk EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
  1089. * tp isoc EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
  1090. * spi bulk EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
  1091. * spi isoc EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
  1092. */
  1093. static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe,
  1094. u8 *ts_type, struct usb_data_stream_properties *stream)
  1095. {
  1096. pr_debug("%s: fe=%d\n", __func__, fe->id);
  1097. if (fe->id == 0) {
  1098. *ts_type = DVB_USB_FE_TS_TYPE_188;
  1099. if (dvb_usb_mxl111sf_isoc)
  1100. mxl111sf_stream_config_isoc(stream, 4, 96, 564);
  1101. else
  1102. mxl111sf_stream_config_bulk(stream, 4);
  1103. } else if (fe->id == 1 && dvb_usb_mxl111sf_spi) {
  1104. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1105. if (dvb_usb_mxl111sf_isoc)
  1106. mxl111sf_stream_config_isoc(stream, 5, 96, 200);
  1107. else
  1108. mxl111sf_stream_config_bulk(stream, 5);
  1109. } else if (fe->id == 1 && !dvb_usb_mxl111sf_spi) {
  1110. *ts_type = DVB_USB_FE_TS_TYPE_RAW;
  1111. if (dvb_usb_mxl111sf_isoc)
  1112. mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
  1113. else
  1114. mxl111sf_stream_config_bulk(stream, 6);
  1115. }
  1116. return 0;
  1117. }
  1118. static int mxl111sf_streaming_ctrl_mercury_mh(struct dvb_frontend *fe, int onoff)
  1119. {
  1120. pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1121. if (fe->id == 0)
  1122. return mxl111sf_ep4_streaming_ctrl(fe, onoff);
  1123. else if (fe->id == 1 && dvb_usb_mxl111sf_spi)
  1124. return mxl111sf_ep5_streaming_ctrl(fe, onoff);
  1125. else if (fe->id == 1 && !dvb_usb_mxl111sf_spi)
  1126. return mxl111sf_ep6_streaming_ctrl(fe, onoff);
  1127. return 0;
  1128. }
  1129. static struct dvb_usb_device_properties mxl111sf_props_mercury_mh = {
  1130. .driver_name = KBUILD_MODNAME,
  1131. .owner = THIS_MODULE,
  1132. .adapter_nr = adapter_nr,
  1133. .size_of_priv = sizeof(struct mxl111sf_state),
  1134. .generic_bulk_ctrl_endpoint = 0x02,
  1135. .generic_bulk_ctrl_endpoint_response = 0x81,
  1136. .i2c_algo = &mxl111sf_i2c_algo,
  1137. .frontend_attach = mxl111sf_frontend_attach_mercury_mh,
  1138. .tuner_attach = mxl111sf_attach_tuner,
  1139. .init = mxl111sf_init,
  1140. .streaming_ctrl = mxl111sf_streaming_ctrl_mercury_mh,
  1141. .get_stream_config = mxl111sf_get_stream_config_mercury_mh,
  1142. .num_adapters = 1,
  1143. .adapter = {
  1144. {
  1145. .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
  1146. }
  1147. }
  1148. };
  1149. static const struct usb_device_id mxl111sf_id_table[] = {
  1150. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc600, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1151. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc601, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1152. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc602, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
  1153. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc603, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1154. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc604, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
  1155. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc609, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1156. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60a, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
  1157. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1158. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60c, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
  1159. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc653, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1160. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc65b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
  1161. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb700, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1162. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb701, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
  1163. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb702, &mxl111sf_props_mh, "HCW 117xxx", NULL) },
  1164. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb703, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1165. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb704, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
  1166. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb753, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1167. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb763, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1168. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb764, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
  1169. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd853, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1170. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd854, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1171. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd863, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1172. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd864, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1173. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1174. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1175. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1176. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
  1177. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8ff, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
  1178. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc612, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
  1179. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc613, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
  1180. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61a, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
  1181. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61b, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
  1182. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb757, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1183. { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb767, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
  1184. { }
  1185. };
  1186. MODULE_DEVICE_TABLE(usb, mxl111sf_id_table);
  1187. static struct usb_driver mxl111sf_usb_driver = {
  1188. .name = KBUILD_MODNAME,
  1189. .id_table = mxl111sf_id_table,
  1190. .probe = dvb_usbv2_probe,
  1191. .disconnect = dvb_usbv2_disconnect,
  1192. .suspend = dvb_usbv2_suspend,
  1193. .resume = dvb_usbv2_resume,
  1194. .no_dynamic_id = 1,
  1195. .soft_unbind = 1,
  1196. };
  1197. module_usb_driver(mxl111sf_usb_driver);
  1198. MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
  1199. MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
  1200. MODULE_VERSION("1.0");
  1201. MODULE_LICENSE("GPL");
  1202. /*
  1203. * Local variables:
  1204. * c-basic-offset: 8
  1205. * End:
  1206. */