rtl28xxu.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /*
  2. * Realtek RTL28xxU DVB USB driver
  3. *
  4. * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
  5. * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
  6. * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include "rtl28xxu.h"
  23. #include "rtl2830.h"
  24. #include "rtl2832.h"
  25. #include "qt1010.h"
  26. #include "mt2060.h"
  27. #include "mxl5005s.h"
  28. #include "fc0012.h"
  29. #include "fc0013.h"
  30. #include "e4000.h"
  31. #include "fc2580.h"
  32. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  33. static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
  34. {
  35. int ret;
  36. unsigned int pipe;
  37. u8 requesttype;
  38. u8 *buf;
  39. buf = kmalloc(req->size, GFP_KERNEL);
  40. if (!buf) {
  41. ret = -ENOMEM;
  42. goto err;
  43. }
  44. if (req->index & CMD_WR_FLAG) {
  45. /* write */
  46. memcpy(buf, req->data, req->size);
  47. requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
  48. pipe = usb_sndctrlpipe(d->udev, 0);
  49. } else {
  50. /* read */
  51. requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
  52. pipe = usb_rcvctrlpipe(d->udev, 0);
  53. }
  54. ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
  55. req->index, buf, req->size, 1000);
  56. dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
  57. req->index, buf, req->size);
  58. if (ret > 0)
  59. ret = 0;
  60. /* read request, copy returned data to return buf */
  61. if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
  62. memcpy(req->data, buf, req->size);
  63. kfree(buf);
  64. if (ret)
  65. goto err;
  66. return ret;
  67. err:
  68. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  69. return ret;
  70. }
  71. static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
  72. {
  73. struct rtl28xxu_req req;
  74. if (reg < 0x3000)
  75. req.index = CMD_USB_WR;
  76. else if (reg < 0x4000)
  77. req.index = CMD_SYS_WR;
  78. else
  79. req.index = CMD_IR_WR;
  80. req.value = reg;
  81. req.size = len;
  82. req.data = val;
  83. return rtl28xxu_ctrl_msg(d, &req);
  84. }
  85. static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
  86. {
  87. struct rtl28xxu_req req;
  88. if (reg < 0x3000)
  89. req.index = CMD_USB_RD;
  90. else if (reg < 0x4000)
  91. req.index = CMD_SYS_RD;
  92. else
  93. req.index = CMD_IR_RD;
  94. req.value = reg;
  95. req.size = len;
  96. req.data = val;
  97. return rtl28xxu_ctrl_msg(d, &req);
  98. }
  99. static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
  100. {
  101. return rtl28xx_wr_regs(d, reg, &val, 1);
  102. }
  103. static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
  104. {
  105. return rtl2831_rd_regs(d, reg, val, 1);
  106. }
  107. /* I2C */
  108. static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  109. int num)
  110. {
  111. int ret;
  112. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  113. struct rtl28xxu_priv *priv = d->priv;
  114. struct rtl28xxu_req req;
  115. /*
  116. * It is not known which are real I2C bus xfer limits, but testing
  117. * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
  118. * TODO: find out RTL2832U lens
  119. */
  120. /*
  121. * I2C adapter logic looks rather complicated due to fact it handles
  122. * three different access methods. Those methods are;
  123. * 1) integrated demod access
  124. * 2) old I2C access
  125. * 3) new I2C access
  126. *
  127. * Used method is selected in order 1, 2, 3. Method 3 can handle all
  128. * requests but there is two reasons why not use it always;
  129. * 1) It is most expensive, usually two USB messages are needed
  130. * 2) At least RTL2831U does not support it
  131. *
  132. * Method 3 is needed in case of I2C write+read (typical register read)
  133. * where write is more than one byte.
  134. */
  135. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  136. return -EAGAIN;
  137. if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
  138. (msg[1].flags & I2C_M_RD)) {
  139. if (msg[0].len > 24 || msg[1].len > 24) {
  140. /* TODO: check msg[0].len max */
  141. ret = -EOPNOTSUPP;
  142. goto err_mutex_unlock;
  143. } else if (msg[0].addr == 0x10) {
  144. /* method 1 - integrated demod */
  145. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  146. req.index = CMD_DEMOD_RD | priv->page;
  147. req.size = msg[1].len;
  148. req.data = &msg[1].buf[0];
  149. ret = rtl28xxu_ctrl_msg(d, &req);
  150. } else if (msg[0].len < 2) {
  151. /* method 2 - old I2C */
  152. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  153. req.index = CMD_I2C_RD;
  154. req.size = msg[1].len;
  155. req.data = &msg[1].buf[0];
  156. ret = rtl28xxu_ctrl_msg(d, &req);
  157. } else {
  158. /* method 3 - new I2C */
  159. req.value = (msg[0].addr << 1);
  160. req.index = CMD_I2C_DA_WR;
  161. req.size = msg[0].len;
  162. req.data = msg[0].buf;
  163. ret = rtl28xxu_ctrl_msg(d, &req);
  164. if (ret)
  165. goto err_mutex_unlock;
  166. req.value = (msg[0].addr << 1);
  167. req.index = CMD_I2C_DA_RD;
  168. req.size = msg[1].len;
  169. req.data = msg[1].buf;
  170. ret = rtl28xxu_ctrl_msg(d, &req);
  171. }
  172. } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
  173. if (msg[0].len > 22) {
  174. /* TODO: check msg[0].len max */
  175. ret = -EOPNOTSUPP;
  176. goto err_mutex_unlock;
  177. } else if (msg[0].addr == 0x10) {
  178. /* method 1 - integrated demod */
  179. if (msg[0].buf[0] == 0x00) {
  180. /* save demod page for later demod access */
  181. priv->page = msg[0].buf[1];
  182. ret = 0;
  183. } else {
  184. req.value = (msg[0].buf[0] << 8) |
  185. (msg[0].addr << 1);
  186. req.index = CMD_DEMOD_WR | priv->page;
  187. req.size = msg[0].len-1;
  188. req.data = &msg[0].buf[1];
  189. ret = rtl28xxu_ctrl_msg(d, &req);
  190. }
  191. } else if (msg[0].len < 23) {
  192. /* method 2 - old I2C */
  193. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  194. req.index = CMD_I2C_WR;
  195. req.size = msg[0].len-1;
  196. req.data = &msg[0].buf[1];
  197. ret = rtl28xxu_ctrl_msg(d, &req);
  198. } else {
  199. /* method 3 - new I2C */
  200. req.value = (msg[0].addr << 1);
  201. req.index = CMD_I2C_DA_WR;
  202. req.size = msg[0].len;
  203. req.data = msg[0].buf;
  204. ret = rtl28xxu_ctrl_msg(d, &req);
  205. }
  206. } else {
  207. ret = -EINVAL;
  208. }
  209. err_mutex_unlock:
  210. mutex_unlock(&d->i2c_mutex);
  211. return ret ? ret : num;
  212. }
  213. static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
  214. {
  215. return I2C_FUNC_I2C;
  216. }
  217. static struct i2c_algorithm rtl28xxu_i2c_algo = {
  218. .master_xfer = rtl28xxu_i2c_xfer,
  219. .functionality = rtl28xxu_i2c_func,
  220. };
  221. static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
  222. .i2c_addr = 0x10, /* 0x20 */
  223. .xtal = 28800000,
  224. .ts_mode = 0,
  225. .spec_inv = 1,
  226. .if_dvbt = 36150000,
  227. .vtop = 0x20,
  228. .krf = 0x04,
  229. .agc_targ_val = 0x2d,
  230. };
  231. static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
  232. .i2c_addr = 0x10, /* 0x20 */
  233. .xtal = 28800000,
  234. .ts_mode = 0,
  235. .spec_inv = 1,
  236. .if_dvbt = 36125000,
  237. .vtop = 0x20,
  238. .krf = 0x04,
  239. .agc_targ_val = 0x2d,
  240. };
  241. static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
  242. .i2c_addr = 0x10, /* 0x20 */
  243. .xtal = 28800000,
  244. .ts_mode = 0,
  245. .spec_inv = 0,
  246. .if_dvbt = 4570000,
  247. .vtop = 0x3f,
  248. .krf = 0x04,
  249. .agc_targ_val = 0x3e,
  250. };
  251. static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
  252. {
  253. int ret;
  254. struct dvb_usb_device *d = adap_to_d(adap);
  255. struct rtl28xxu_priv *priv = d_to_priv(d);
  256. u8 buf[1];
  257. struct rtl2830_config *rtl2830_config;
  258. /* open RTL2831U/RTL2830 I2C gate */
  259. struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" };
  260. /* for MT2060 tuner probe */
  261. struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf };
  262. /* for QT1010 tuner probe */
  263. struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
  264. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  265. /*
  266. * RTL2831U GPIOs
  267. * =========================================================
  268. * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
  269. * GPIO2 | LED | 0 off | 1 on |
  270. * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
  271. */
  272. /* GPIO direction */
  273. ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
  274. if (ret)
  275. goto err;
  276. /* enable as output GPIO0, GPIO2, GPIO4 */
  277. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
  278. if (ret)
  279. goto err;
  280. /*
  281. * Probe used tuner. We need to know used tuner before demod attach
  282. * since there is some demod params needed to set according to tuner.
  283. */
  284. /* demod needs some time to wake up */
  285. msleep(20);
  286. /* open demod I2C gate */
  287. ret = rtl28xxu_ctrl_msg(d, &req_gate);
  288. if (ret)
  289. goto err;
  290. /* check QT1010 ID(?) register; reg=0f val=2c */
  291. ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
  292. if (ret == 0 && buf[0] == 0x2c) {
  293. priv->tuner = TUNER_RTL2830_QT1010;
  294. rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
  295. dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
  296. goto found;
  297. } else {
  298. dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
  299. __func__, ret, buf[0]);
  300. }
  301. /* open demod I2C gate */
  302. ret = rtl28xxu_ctrl_msg(d, &req_gate);
  303. if (ret)
  304. goto err;
  305. /* check MT2060 ID register; reg=00 val=63 */
  306. ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
  307. if (ret == 0 && buf[0] == 0x63) {
  308. priv->tuner = TUNER_RTL2830_MT2060;
  309. rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
  310. dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
  311. goto found;
  312. } else {
  313. dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
  314. __func__, ret, buf[0]);
  315. }
  316. /* assume MXL5005S */
  317. ret = 0;
  318. priv->tuner = TUNER_RTL2830_MXL5005S;
  319. rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
  320. dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
  321. goto found;
  322. found:
  323. /* attach demodulator */
  324. adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
  325. &d->i2c_adap);
  326. if (adap->fe[0] == NULL) {
  327. ret = -ENODEV;
  328. goto err;
  329. }
  330. return ret;
  331. err:
  332. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  333. return ret;
  334. }
  335. static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
  336. .i2c_addr = 0x10, /* 0x20 */
  337. .xtal = 28800000,
  338. .if_dvbt = 0,
  339. .tuner = TUNER_RTL2832_FC0012
  340. };
  341. static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
  342. .i2c_addr = 0x10, /* 0x20 */
  343. .xtal = 28800000,
  344. .if_dvbt = 0,
  345. .tuner = TUNER_RTL2832_FC0013
  346. };
  347. static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
  348. int cmd, int arg)
  349. {
  350. int ret;
  351. u8 val;
  352. dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
  353. switch (cmd) {
  354. case FC_FE_CALLBACK_VHF_ENABLE:
  355. /* set output values */
  356. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
  357. if (ret)
  358. goto err;
  359. if (arg)
  360. val &= 0xbf; /* set GPIO6 low */
  361. else
  362. val |= 0x40; /* set GPIO6 high */
  363. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
  364. if (ret)
  365. goto err;
  366. break;
  367. default:
  368. ret = -EINVAL;
  369. goto err;
  370. }
  371. return 0;
  372. err:
  373. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  374. return ret;
  375. }
  376. static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
  377. int cmd, int arg)
  378. {
  379. /* TODO implement*/
  380. return 0;
  381. }
  382. static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
  383. {
  384. struct rtl28xxu_priv *priv = d->priv;
  385. switch (priv->tuner) {
  386. case TUNER_RTL2832_FC0012:
  387. return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
  388. case TUNER_RTL2832_FC0013:
  389. return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
  390. default:
  391. break;
  392. }
  393. return -ENODEV;
  394. }
  395. static int rtl2832u_frontend_callback(void *adapter_priv, int component,
  396. int cmd, int arg)
  397. {
  398. struct i2c_adapter *adap = adapter_priv;
  399. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  400. switch (component) {
  401. case DVB_FRONTEND_COMPONENT_TUNER:
  402. return rtl2832u_tuner_callback(d, cmd, arg);
  403. default:
  404. break;
  405. }
  406. return -EINVAL;
  407. }
  408. static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
  409. {
  410. int ret;
  411. struct dvb_usb_device *d = adap_to_d(adap);
  412. struct rtl28xxu_priv *priv = d_to_priv(d);
  413. struct rtl2832_config *rtl2832_config;
  414. u8 buf[2], val;
  415. /* open RTL2832U/RTL2832 I2C gate */
  416. struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
  417. /* close RTL2832U/RTL2832 I2C gate */
  418. struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
  419. /* for FC0012 tuner probe */
  420. struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
  421. /* for FC0013 tuner probe */
  422. struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
  423. /* for MT2266 tuner probe */
  424. struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
  425. /* for FC2580 tuner probe */
  426. struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
  427. /* for MT2063 tuner probe */
  428. struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
  429. /* for MAX3543 tuner probe */
  430. struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
  431. /* for TUA9001 tuner probe */
  432. struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
  433. /* for MXL5007T tuner probe */
  434. struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
  435. /* for E4000 tuner probe */
  436. struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
  437. /* for TDA18272 tuner probe */
  438. struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
  439. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  440. ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
  441. if (ret)
  442. goto err;
  443. val &= 0xbf;
  444. ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
  445. if (ret)
  446. goto err;
  447. /* enable as output GPIO3 and GPIO6*/
  448. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
  449. if (ret)
  450. goto err;
  451. val |= 0x48;
  452. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
  453. if (ret)
  454. goto err;
  455. /*
  456. * Probe used tuner. We need to know used tuner before demod attach
  457. * since there is some demod params needed to set according to tuner.
  458. */
  459. /* open demod I2C gate */
  460. ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
  461. if (ret)
  462. goto err;
  463. priv->tuner = TUNER_NONE;
  464. /* check FC0012 ID register; reg=00 val=a1 */
  465. ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
  466. if (ret == 0 && buf[0] == 0xa1) {
  467. priv->tuner = TUNER_RTL2832_FC0012;
  468. rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
  469. dev_info(&d->udev->dev, "%s: FC0012 tuner found",
  470. KBUILD_MODNAME);
  471. goto found;
  472. }
  473. /* check FC0013 ID register; reg=00 val=a3 */
  474. ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
  475. if (ret == 0 && buf[0] == 0xa3) {
  476. priv->tuner = TUNER_RTL2832_FC0013;
  477. rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
  478. dev_info(&d->udev->dev, "%s: FC0013 tuner found",
  479. KBUILD_MODNAME);
  480. goto found;
  481. }
  482. /* check MT2266 ID register; reg=00 val=85 */
  483. ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
  484. if (ret == 0 && buf[0] == 0x85) {
  485. priv->tuner = TUNER_RTL2832_MT2266;
  486. /* TODO implement tuner */
  487. dev_info(&d->udev->dev, "%s: MT2266 tuner found",
  488. KBUILD_MODNAME);
  489. goto unsupported;
  490. }
  491. /* check FC2580 ID register; reg=01 val=56 */
  492. ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
  493. if (ret == 0 && buf[0] == 0x56) {
  494. priv->tuner = TUNER_RTL2832_FC2580;
  495. /* FIXME: do not abuse fc0012 settings */
  496. rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
  497. dev_info(&d->udev->dev, "%s: FC2580 tuner found",
  498. KBUILD_MODNAME);
  499. goto found;
  500. }
  501. /* check MT2063 ID register; reg=00 val=9e || 9c */
  502. ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
  503. if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
  504. priv->tuner = TUNER_RTL2832_MT2063;
  505. /* TODO implement tuner */
  506. dev_info(&d->udev->dev, "%s: MT2063 tuner found",
  507. KBUILD_MODNAME);
  508. goto unsupported;
  509. }
  510. /* check MAX3543 ID register; reg=00 val=38 */
  511. ret = rtl28xxu_ctrl_msg(d, &req_max3543);
  512. if (ret == 0 && buf[0] == 0x38) {
  513. priv->tuner = TUNER_RTL2832_MAX3543;
  514. /* TODO implement tuner */
  515. dev_info(&d->udev->dev, "%s: MAX3534 tuner found",
  516. KBUILD_MODNAME);
  517. goto unsupported;
  518. }
  519. /* check TUA9001 ID register; reg=7e val=2328 */
  520. ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
  521. if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
  522. priv->tuner = TUNER_RTL2832_TUA9001;
  523. /* TODO implement tuner */
  524. dev_info(&d->udev->dev, "%s: TUA9001 tuner found",
  525. KBUILD_MODNAME);
  526. goto unsupported;
  527. }
  528. /* check MXL5007R ID register; reg=d9 val=14 */
  529. ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
  530. if (ret == 0 && buf[0] == 0x14) {
  531. priv->tuner = TUNER_RTL2832_MXL5007T;
  532. /* TODO implement tuner */
  533. dev_info(&d->udev->dev, "%s: MXL5007T tuner found",
  534. KBUILD_MODNAME);
  535. goto unsupported;
  536. }
  537. /* check E4000 ID register; reg=02 val=40 */
  538. ret = rtl28xxu_ctrl_msg(d, &req_e4000);
  539. if (ret == 0 && buf[0] == 0x40) {
  540. priv->tuner = TUNER_RTL2832_E4000;
  541. /* FIXME: do not abuse fc0012 settings */
  542. rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
  543. dev_info(&d->udev->dev, "%s: E4000 tuner found",
  544. KBUILD_MODNAME);
  545. goto found;
  546. }
  547. /* check TDA18272 ID register; reg=00 val=c760 */
  548. ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
  549. if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
  550. priv->tuner = TUNER_RTL2832_TDA18272;
  551. /* TODO implement tuner */
  552. dev_info(&d->udev->dev, "%s: TDA18272 tuner found",
  553. KBUILD_MODNAME);
  554. goto unsupported;
  555. }
  556. unsupported:
  557. /* close demod I2C gate */
  558. ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
  559. if (ret)
  560. goto err;
  561. /* tuner not found */
  562. dev_dbg(&d->udev->dev, "%s: No compatible tuner found\n", __func__);
  563. ret = -ENODEV;
  564. return ret;
  565. found:
  566. /* close demod I2C gate */
  567. ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
  568. if (ret)
  569. goto err;
  570. /* attach demodulator */
  571. adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config,
  572. &d->i2c_adap);
  573. if (adap->fe[0] == NULL) {
  574. ret = -ENODEV;
  575. goto err;
  576. }
  577. /* set fe callbacks */
  578. adap->fe[0]->callback = rtl2832u_frontend_callback;
  579. return ret;
  580. err:
  581. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  582. return ret;
  583. }
  584. static struct qt1010_config rtl28xxu_qt1010_config = {
  585. .i2c_address = 0x62, /* 0xc4 */
  586. };
  587. static struct mt2060_config rtl28xxu_mt2060_config = {
  588. .i2c_address = 0x60, /* 0xc0 */
  589. .clock_out = 0,
  590. };
  591. static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
  592. .i2c_address = 0x63, /* 0xc6 */
  593. .if_freq = IF_FREQ_4570000HZ,
  594. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  595. .agc_mode = MXL_SINGLE_AGC,
  596. .tracking_filter = MXL_TF_C_H,
  597. .rssi_enable = MXL_RSSI_ENABLE,
  598. .cap_select = MXL_CAP_SEL_ENABLE,
  599. .div_out = MXL_DIV_OUT_4,
  600. .clock_out = MXL_CLOCK_OUT_DISABLE,
  601. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  602. .top = MXL5005S_TOP_25P2,
  603. .mod_mode = MXL_DIGITAL_MODE,
  604. .if_mode = MXL_ZERO_IF,
  605. .AgcMasterByte = 0x00,
  606. };
  607. static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
  608. {
  609. int ret;
  610. struct dvb_usb_device *d = adap_to_d(adap);
  611. struct rtl28xxu_priv *priv = d_to_priv(d);
  612. struct i2c_adapter *rtl2830_tuner_i2c;
  613. struct dvb_frontend *fe;
  614. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  615. /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
  616. rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
  617. switch (priv->tuner) {
  618. case TUNER_RTL2830_QT1010:
  619. fe = dvb_attach(qt1010_attach, adap->fe[0],
  620. rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
  621. break;
  622. case TUNER_RTL2830_MT2060:
  623. fe = dvb_attach(mt2060_attach, adap->fe[0],
  624. rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
  625. 1220);
  626. break;
  627. case TUNER_RTL2830_MXL5005S:
  628. fe = dvb_attach(mxl5005s_attach, adap->fe[0],
  629. rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
  630. break;
  631. default:
  632. fe = NULL;
  633. dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
  634. priv->tuner);
  635. }
  636. if (fe == NULL) {
  637. ret = -ENODEV;
  638. goto err;
  639. }
  640. return 0;
  641. err:
  642. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  643. return ret;
  644. }
  645. static const struct e4000_config rtl2832u_e4000_config = {
  646. .i2c_addr = 0x64,
  647. .clock = 28800000,
  648. };
  649. static const struct fc2580_config rtl2832u_fc2580_config = {
  650. .i2c_addr = 0x56,
  651. .clock = 16384000,
  652. };
  653. static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
  654. {
  655. int ret;
  656. struct dvb_usb_device *d = adap_to_d(adap);
  657. struct rtl28xxu_priv *priv = d_to_priv(d);
  658. struct dvb_frontend *fe;
  659. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  660. switch (priv->tuner) {
  661. case TUNER_RTL2832_FC0012:
  662. fe = dvb_attach(fc0012_attach, adap->fe[0],
  663. &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
  664. /* since fc0012 includs reading the signal strength delegate
  665. * that to the tuner driver */
  666. adap->fe[0]->ops.read_signal_strength =
  667. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  668. return 0;
  669. break;
  670. case TUNER_RTL2832_FC0013:
  671. fe = dvb_attach(fc0013_attach, adap->fe[0],
  672. &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
  673. /* fc0013 also supports signal strength reading */
  674. adap->fe[0]->ops.read_signal_strength =
  675. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  676. return 0;
  677. case TUNER_RTL2832_E4000:
  678. fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap,
  679. &rtl2832u_e4000_config);
  680. break;
  681. case TUNER_RTL2832_FC2580:
  682. fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
  683. &rtl2832u_fc2580_config);
  684. break;
  685. default:
  686. fe = NULL;
  687. dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
  688. priv->tuner);
  689. }
  690. if (fe == NULL) {
  691. ret = -ENODEV;
  692. goto err;
  693. }
  694. return 0;
  695. err:
  696. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  697. return ret;
  698. }
  699. static int rtl28xxu_init(struct dvb_usb_device *d)
  700. {
  701. int ret;
  702. u8 val;
  703. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  704. /* init USB endpoints */
  705. ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
  706. if (ret)
  707. goto err;
  708. /* enable DMA and Full Packet Mode*/
  709. val |= 0x09;
  710. ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
  711. if (ret)
  712. goto err;
  713. /* set EPA maximum packet size to 0x0200 */
  714. ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
  715. if (ret)
  716. goto err;
  717. /* change EPA FIFO length */
  718. ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
  719. if (ret)
  720. goto err;
  721. return ret;
  722. err:
  723. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  724. return ret;
  725. }
  726. static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
  727. {
  728. int ret;
  729. u8 gpio, sys0, epa_ctl[2];
  730. dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
  731. /* demod adc */
  732. ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
  733. if (ret)
  734. goto err;
  735. /* tuner power, read GPIOs */
  736. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
  737. if (ret)
  738. goto err;
  739. dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
  740. sys0, gpio);
  741. if (onoff) {
  742. gpio |= 0x01; /* GPIO0 = 1 */
  743. gpio &= (~0x10); /* GPIO4 = 0 */
  744. gpio |= 0x04; /* GPIO2 = 1, LED on */
  745. sys0 = sys0 & 0x0f;
  746. sys0 |= 0xe0;
  747. epa_ctl[0] = 0x00; /* clear stall */
  748. epa_ctl[1] = 0x00; /* clear reset */
  749. } else {
  750. gpio &= (~0x01); /* GPIO0 = 0 */
  751. gpio |= 0x10; /* GPIO4 = 1 */
  752. gpio &= (~0x04); /* GPIO2 = 1, LED off */
  753. sys0 = sys0 & (~0xc0);
  754. epa_ctl[0] = 0x10; /* set stall */
  755. epa_ctl[1] = 0x02; /* set reset */
  756. }
  757. dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
  758. sys0, gpio);
  759. /* demod adc */
  760. ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
  761. if (ret)
  762. goto err;
  763. /* tuner power, write GPIOs */
  764. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
  765. if (ret)
  766. goto err;
  767. /* streaming EP: stall & reset */
  768. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
  769. if (ret)
  770. goto err;
  771. if (onoff)
  772. usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
  773. return ret;
  774. err:
  775. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  776. return ret;
  777. }
  778. static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
  779. {
  780. int ret;
  781. u8 val;
  782. dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
  783. if (onoff) {
  784. /* set output values */
  785. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
  786. if (ret)
  787. goto err;
  788. val |= 0x08;
  789. val &= 0xef;
  790. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
  791. if (ret)
  792. goto err;
  793. /* demod_ctl_1 */
  794. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
  795. if (ret)
  796. goto err;
  797. val &= 0xef;
  798. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
  799. if (ret)
  800. goto err;
  801. /* demod control */
  802. /* PLL enable */
  803. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
  804. if (ret)
  805. goto err;
  806. /* bit 7 to 1 */
  807. val |= 0x80;
  808. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
  809. if (ret)
  810. goto err;
  811. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
  812. if (ret)
  813. goto err;
  814. val |= 0x20;
  815. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
  816. if (ret)
  817. goto err;
  818. mdelay(5);
  819. /*enable ADC_Q and ADC_I */
  820. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
  821. if (ret)
  822. goto err;
  823. val |= 0x48;
  824. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
  825. if (ret)
  826. goto err;
  827. /* streaming EP: clear stall & reset */
  828. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
  829. if (ret)
  830. goto err;
  831. ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
  832. if (ret)
  833. goto err;
  834. } else {
  835. /* demod_ctl_1 */
  836. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
  837. if (ret)
  838. goto err;
  839. val |= 0x0c;
  840. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
  841. if (ret)
  842. goto err;
  843. /* set output values */
  844. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
  845. if (ret)
  846. goto err;
  847. val |= 0x10;
  848. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
  849. if (ret)
  850. goto err;
  851. /* demod control */
  852. ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
  853. if (ret)
  854. goto err;
  855. val &= 0x37;
  856. ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
  857. if (ret)
  858. goto err;
  859. /* streaming EP: set stall & reset */
  860. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
  861. if (ret)
  862. goto err;
  863. }
  864. return ret;
  865. err:
  866. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  867. return ret;
  868. }
  869. static int rtl2831u_rc_query(struct dvb_usb_device *d)
  870. {
  871. int ret, i;
  872. struct rtl28xxu_priv *priv = d->priv;
  873. u8 buf[5];
  874. u32 rc_code;
  875. struct rtl28xxu_reg_val rc_nec_tab[] = {
  876. { 0x3033, 0x80 },
  877. { 0x3020, 0x43 },
  878. { 0x3021, 0x16 },
  879. { 0x3022, 0x16 },
  880. { 0x3023, 0x5a },
  881. { 0x3024, 0x2d },
  882. { 0x3025, 0x16 },
  883. { 0x3026, 0x01 },
  884. { 0x3028, 0xb0 },
  885. { 0x3029, 0x04 },
  886. { 0x302c, 0x88 },
  887. { 0x302e, 0x13 },
  888. { 0x3030, 0xdf },
  889. { 0x3031, 0x05 },
  890. };
  891. /* init remote controller */
  892. if (!priv->rc_active) {
  893. for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
  894. ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
  895. rc_nec_tab[i].val);
  896. if (ret)
  897. goto err;
  898. }
  899. priv->rc_active = true;
  900. }
  901. ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
  902. if (ret)
  903. goto err;
  904. if (buf[4] & 0x01) {
  905. if (buf[2] == (u8) ~buf[3]) {
  906. if (buf[0] == (u8) ~buf[1]) {
  907. /* NEC standard (16 bit) */
  908. rc_code = buf[0] << 8 | buf[2];
  909. } else {
  910. /* NEC extended (24 bit) */
  911. rc_code = buf[0] << 16 |
  912. buf[1] << 8 | buf[2];
  913. }
  914. } else {
  915. /* NEC full (32 bit) */
  916. rc_code = buf[0] << 24 | buf[1] << 16 |
  917. buf[2] << 8 | buf[3];
  918. }
  919. rc_keydown(d->rc_dev, rc_code, 0);
  920. ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
  921. if (ret)
  922. goto err;
  923. /* repeated intentionally to avoid extra keypress */
  924. ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
  925. if (ret)
  926. goto err;
  927. }
  928. return ret;
  929. err:
  930. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  931. return ret;
  932. }
  933. static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
  934. struct dvb_usb_rc *rc)
  935. {
  936. rc->map_name = RC_MAP_EMPTY;
  937. rc->allowed_protos = RC_TYPE_NEC;
  938. rc->query = rtl2831u_rc_query;
  939. rc->interval = 400;
  940. return 0;
  941. }
  942. static int rtl2832u_rc_query(struct dvb_usb_device *d)
  943. {
  944. int ret, i;
  945. struct rtl28xxu_priv *priv = d->priv;
  946. u8 buf[128];
  947. int len;
  948. struct rtl28xxu_reg_val rc_nec_tab[] = {
  949. { IR_RX_CTRL, 0x20 },
  950. { IR_RX_BUF_CTRL, 0x80 },
  951. { IR_RX_IF, 0xff },
  952. { IR_RX_IE, 0xff },
  953. { IR_MAX_DURATION0, 0xd0 },
  954. { IR_MAX_DURATION1, 0x07 },
  955. { IR_IDLE_LEN0, 0xc0 },
  956. { IR_IDLE_LEN1, 0x00 },
  957. { IR_GLITCH_LEN, 0x03 },
  958. { IR_RX_CLK, 0x09 },
  959. { IR_RX_CFG, 0x1c },
  960. { IR_MAX_H_TOL_LEN, 0x1e },
  961. { IR_MAX_L_TOL_LEN, 0x1e },
  962. { IR_RX_CTRL, 0x80 },
  963. };
  964. /* init remote controller */
  965. if (!priv->rc_active) {
  966. for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
  967. ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
  968. rc_nec_tab[i].val);
  969. if (ret)
  970. goto err;
  971. }
  972. priv->rc_active = true;
  973. }
  974. ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
  975. if (ret)
  976. goto err;
  977. if (buf[0] != 0x83)
  978. goto exit;
  979. ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
  980. if (ret)
  981. goto err;
  982. len = buf[0];
  983. ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
  984. /* TODO: pass raw IR to Kernel IR decoder */
  985. ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
  986. ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
  987. ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
  988. exit:
  989. return ret;
  990. err:
  991. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  992. return ret;
  993. }
  994. static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
  995. struct dvb_usb_rc *rc)
  996. {
  997. rc->map_name = RC_MAP_EMPTY;
  998. rc->allowed_protos = RC_TYPE_NEC;
  999. rc->query = rtl2832u_rc_query;
  1000. rc->interval = 400;
  1001. return 0;
  1002. }
  1003. static const struct dvb_usb_device_properties rtl2831u_props = {
  1004. .driver_name = KBUILD_MODNAME,
  1005. .owner = THIS_MODULE,
  1006. .adapter_nr = adapter_nr,
  1007. .size_of_priv = sizeof(struct rtl28xxu_priv),
  1008. .power_ctrl = rtl2831u_power_ctrl,
  1009. .i2c_algo = &rtl28xxu_i2c_algo,
  1010. .frontend_attach = rtl2831u_frontend_attach,
  1011. .tuner_attach = rtl2831u_tuner_attach,
  1012. .init = rtl28xxu_init,
  1013. .get_rc_config = rtl2831u_get_rc_config,
  1014. .num_adapters = 1,
  1015. .adapter = {
  1016. {
  1017. .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
  1018. },
  1019. },
  1020. };
  1021. static const struct dvb_usb_device_properties rtl2832u_props = {
  1022. .driver_name = KBUILD_MODNAME,
  1023. .owner = THIS_MODULE,
  1024. .adapter_nr = adapter_nr,
  1025. .size_of_priv = sizeof(struct rtl28xxu_priv),
  1026. .power_ctrl = rtl2832u_power_ctrl,
  1027. .i2c_algo = &rtl28xxu_i2c_algo,
  1028. .frontend_attach = rtl2832u_frontend_attach,
  1029. .tuner_attach = rtl2832u_tuner_attach,
  1030. .init = rtl28xxu_init,
  1031. .get_rc_config = rtl2832u_get_rc_config,
  1032. .num_adapters = 1,
  1033. .adapter = {
  1034. {
  1035. .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
  1036. },
  1037. },
  1038. };
  1039. static const struct usb_device_id rtl28xxu_id_table[] = {
  1040. { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
  1041. &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
  1042. { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
  1043. &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
  1044. { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
  1045. &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
  1046. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
  1047. &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
  1048. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
  1049. &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
  1050. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
  1051. &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
  1052. { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
  1053. &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
  1054. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
  1055. &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
  1056. { }
  1057. };
  1058. MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
  1059. static struct usb_driver rtl28xxu_usb_driver = {
  1060. .name = KBUILD_MODNAME,
  1061. .id_table = rtl28xxu_id_table,
  1062. .probe = dvb_usbv2_probe,
  1063. .disconnect = dvb_usbv2_disconnect,
  1064. .suspend = dvb_usbv2_suspend,
  1065. .resume = dvb_usbv2_resume,
  1066. .reset_resume = dvb_usbv2_reset_resume,
  1067. .no_dynamic_id = 1,
  1068. .soft_unbind = 1,
  1069. };
  1070. module_usb_driver(rtl28xxu_usb_driver);
  1071. MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
  1072. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  1073. MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
  1074. MODULE_LICENSE("GPL");