rtl28xxu.c 30 KB

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