mxl111sf.c 40 KB

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