rtl28xxu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "rtl28xxu.h"
  22. #include "rtl2830.h"
  23. #include "qt1010.h"
  24. #include "mt2060.h"
  25. #include "mxl5005s.h"
  26. /* debug */
  27. static int dvb_usb_rtl28xxu_debug;
  28. module_param_named(debug, dvb_usb_rtl28xxu_debug, int, 0644);
  29. MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
  30. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  31. static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
  32. {
  33. int ret;
  34. unsigned int pipe;
  35. u8 requesttype;
  36. u8 *buf;
  37. buf = kmalloc(req->size, GFP_KERNEL);
  38. if (!buf) {
  39. ret = -ENOMEM;
  40. goto err;
  41. }
  42. if (req->index & CMD_WR_FLAG) {
  43. /* write */
  44. memcpy(buf, req->data, req->size);
  45. requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
  46. pipe = usb_sndctrlpipe(d->udev, 0);
  47. } else {
  48. /* read */
  49. requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
  50. pipe = usb_rcvctrlpipe(d->udev, 0);
  51. }
  52. ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
  53. req->index, buf, req->size, 1000);
  54. deb_dump(0, requesttype, req->value, req->index, buf, req->size,
  55. deb_xfer);
  56. if (ret < 0)
  57. goto err_dealloc;
  58. else
  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. return ret;
  65. err_dealloc:
  66. kfree(buf);
  67. err:
  68. deb_info("%s: failed=%d\n", __func__, ret);
  69. return ret;
  70. }
  71. static int rtl2831_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
  77. req.index = CMD_SYS_WR;
  78. req.value = reg;
  79. req.size = len;
  80. req.data = val;
  81. return rtl28xxu_ctrl_msg(d, &req);
  82. }
  83. static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
  84. {
  85. struct rtl28xxu_req req;
  86. if (reg < 0x3000)
  87. req.index = CMD_USB_RD;
  88. else
  89. req.index = CMD_SYS_RD;
  90. req.value = reg;
  91. req.size = len;
  92. req.data = val;
  93. return rtl28xxu_ctrl_msg(d, &req);
  94. }
  95. static int rtl2831_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
  96. {
  97. return rtl2831_wr_regs(d, reg, &val, 1);
  98. }
  99. static int rtl2831_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
  100. {
  101. return rtl2831_rd_regs(d, reg, val, 1);
  102. }
  103. /* I2C */
  104. static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  105. int num)
  106. {
  107. int ret;
  108. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  109. struct rtl28xxu_req req;
  110. /*
  111. * It is not known which are real I2C bus xfer limits, but testing
  112. * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
  113. */
  114. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  115. return -EAGAIN;
  116. if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
  117. (msg[1].flags & I2C_M_RD)) {
  118. if (msg[0].len > 2 || msg[1].len > 24) {
  119. ret = -EOPNOTSUPP;
  120. goto err_unlock;
  121. }
  122. if (msg[0].addr == 0x10) {
  123. /* integrated demod */
  124. req.value = (msg[0].buf[1] << 8) | (msg[0].addr << 1);
  125. req.index = CMD_DEMOD_RD | msg[0].buf[0];
  126. req.size = msg[1].len;
  127. req.data = &msg[1].buf[0];
  128. ret = rtl28xxu_ctrl_msg(d, &req);
  129. } else {
  130. /* real I2C */
  131. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  132. req.index = CMD_I2C_RD;
  133. req.size = msg[1].len;
  134. req.data = &msg[1].buf[0];
  135. ret = rtl28xxu_ctrl_msg(d, &req);
  136. }
  137. } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
  138. if (msg[0].len > 22) {
  139. ret = -EOPNOTSUPP;
  140. goto err_unlock;
  141. }
  142. if (msg[0].addr == 0x10) {
  143. /* integrated demod */
  144. req.value = (msg[0].buf[1] << 8) | (msg[0].addr << 1);
  145. req.index = CMD_DEMOD_WR | msg[0].buf[0];
  146. req.size = msg[0].len-2;
  147. req.data = &msg[0].buf[2];
  148. ret = rtl28xxu_ctrl_msg(d, &req);
  149. } else {
  150. /* real I2C */
  151. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  152. req.index = CMD_I2C_WR;
  153. req.size = msg[0].len-1;
  154. req.data = &msg[0].buf[1];
  155. ret = rtl28xxu_ctrl_msg(d, &req);
  156. }
  157. } else {
  158. ret = -EINVAL;
  159. }
  160. err_unlock:
  161. mutex_unlock(&d->i2c_mutex);
  162. return ret ? ret : num;
  163. }
  164. static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
  165. {
  166. return I2C_FUNC_I2C;
  167. }
  168. static struct i2c_algorithm rtl28xxu_i2c_algo = {
  169. .master_xfer = rtl28xxu_i2c_xfer,
  170. .functionality = rtl28xxu_i2c_func,
  171. };
  172. static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
  173. .i2c_addr = 0x10, /* 0x20 */
  174. .xtal = 28800000,
  175. .ts_mode = 0,
  176. .spec_inv = 1,
  177. .if_dvbt = 36150000,
  178. .vtop = 0x20,
  179. .krf = 0x04,
  180. .agc_targ_val = 0x2d,
  181. };
  182. static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
  183. .i2c_addr = 0x10, /* 0x20 */
  184. .xtal = 28800000,
  185. .ts_mode = 0,
  186. .spec_inv = 1,
  187. .if_dvbt = 36125000,
  188. .vtop = 0x20,
  189. .krf = 0x04,
  190. .agc_targ_val = 0x2d,
  191. };
  192. static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
  193. .i2c_addr = 0x10, /* 0x20 */
  194. .xtal = 28800000,
  195. .ts_mode = 0,
  196. .spec_inv = 0,
  197. .if_dvbt = 4570000,
  198. .vtop = 0x3f,
  199. .krf = 0x04,
  200. .agc_targ_val = 0x3e,
  201. };
  202. static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap)
  203. {
  204. int ret;
  205. struct rtl28xxu_priv *priv = adap->dev->priv;
  206. u8 buf[1];
  207. struct rtl2830_config *rtl2830_config;
  208. /* for MT2060 tuner probe */
  209. struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
  210. /* for QT1010 tuner probe */
  211. struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
  212. /* open RTL2831U/RTL2830 I2C gate */
  213. struct rtl28xxu_req req_gate = {0x0120, 0x0011, 0x0001, "\x08"};
  214. deb_info("%s:\n", __func__);
  215. /*
  216. * RTL2831U GPIOs
  217. * =========================================================
  218. * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
  219. * GPIO2 | LED | 0 off | 1 on |
  220. * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
  221. */
  222. /* GPIO direction */
  223. ret = rtl2831_wr_reg(adap->dev, SYS_GPIO_DIR, 0x0a);
  224. if (ret)
  225. goto err;
  226. /* enable as output GPIO0, GPIO2, GPIO4 */
  227. ret = rtl2831_wr_reg(adap->dev, SYS_GPIO_OUT_EN, 0x15);
  228. if (ret)
  229. goto err;
  230. /*
  231. * Probe used tuner. We need to know used tuner before demod attach
  232. * since there is some demod params needed to set according to tuner.
  233. */
  234. /* open demod I2C gate */
  235. ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate);
  236. if (ret)
  237. goto err;
  238. /* check QT1010 ID(?) register; reg=0f val=2c */
  239. ret = rtl28xxu_ctrl_msg(adap->dev, &req_qt1010);
  240. if (ret == 0 && buf[0] == 0x2c) {
  241. priv->tuner = TUNER_RTL2830_QT1010;
  242. rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
  243. deb_info("%s: QT1010\n", __func__);
  244. goto found;
  245. } else {
  246. deb_info("%s: QT1010 probe failed=%d - %02x\n",
  247. __func__, ret, buf[0]);
  248. }
  249. /* open demod I2C gate */
  250. ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate);
  251. if (ret)
  252. goto err;
  253. /* check MT2060 ID register; reg=00 val=63 */
  254. ret = rtl28xxu_ctrl_msg(adap->dev, &req_mt2060);
  255. if (ret == 0 && buf[0] == 0x63) {
  256. priv->tuner = TUNER_RTL2830_MT2060;
  257. rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
  258. deb_info("%s: MT2060\n", __func__);
  259. goto found;
  260. } else {
  261. deb_info("%s: MT2060 probe failed=%d - %02x\n",
  262. __func__, ret, buf[0]);
  263. }
  264. /* assume MXL5005S */
  265. priv->tuner = TUNER_RTL2830_MXL5005S;
  266. rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
  267. deb_info("%s: MXL5005S\n", __func__);
  268. goto found;
  269. found:
  270. /* attach demodulator */
  271. adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
  272. &adap->dev->i2c_adap);
  273. if (adap->fe[0] == NULL) {
  274. ret = -ENODEV;
  275. goto err;
  276. }
  277. return ret;
  278. err:
  279. deb_info("%s: failed=%d\n", __func__, ret);
  280. return ret;
  281. }
  282. static struct qt1010_config rtl28xxu_qt1010_config = {
  283. .i2c_address = 0x62, /* 0xc4 */
  284. };
  285. static struct mt2060_config rtl28xxu_mt2060_config = {
  286. .i2c_address = 0x60, /* 0xc0 */
  287. .clock_out = 0,
  288. };
  289. static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
  290. .i2c_address = 0x63, /* 0xc6 */
  291. .if_freq = IF_FREQ_4570000HZ,
  292. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  293. .agc_mode = MXL_SINGLE_AGC,
  294. .tracking_filter = MXL_TF_C_H,
  295. .rssi_enable = MXL_RSSI_ENABLE,
  296. .cap_select = MXL_CAP_SEL_ENABLE,
  297. .div_out = MXL_DIV_OUT_4,
  298. .clock_out = MXL_CLOCK_OUT_DISABLE,
  299. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  300. .top = MXL5005S_TOP_25P2,
  301. .mod_mode = MXL_DIGITAL_MODE,
  302. .if_mode = MXL_ZERO_IF,
  303. .AgcMasterByte = 0x00,
  304. };
  305. static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap)
  306. {
  307. int ret;
  308. struct rtl28xxu_priv *priv = adap->dev->priv;
  309. struct i2c_adapter *rtl2830_tuner_i2c;
  310. struct dvb_frontend *fe = NULL;
  311. deb_info("%s:\n", __func__);
  312. /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
  313. rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
  314. switch (priv->tuner) {
  315. case TUNER_RTL2830_QT1010:
  316. fe = dvb_attach(qt1010_attach, adap->fe[0], rtl2830_tuner_i2c,
  317. &rtl28xxu_qt1010_config);
  318. break;
  319. case TUNER_RTL2830_MT2060:
  320. fe = dvb_attach(mt2060_attach, adap->fe[0], rtl2830_tuner_i2c,
  321. &rtl28xxu_mt2060_config, 1220);
  322. break;
  323. case TUNER_RTL2830_MXL5005S:
  324. fe = dvb_attach(mxl5005s_attach, adap->fe[0], rtl2830_tuner_i2c,
  325. &rtl28xxu_mxl5005s_config);
  326. break;
  327. default:
  328. err("unknown tuner=%d", priv->tuner);
  329. }
  330. if (fe == NULL) {
  331. ret = -ENODEV;
  332. goto err;
  333. }
  334. return 0;
  335. err:
  336. deb_info("%s: failed=%d\n", __func__, ret);
  337. return ret;
  338. }
  339. static int rtl28xxu_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff)
  340. {
  341. int ret;
  342. u8 buf[2], gpio;
  343. deb_info("%s: onoff=%d\n", __func__, onoff);
  344. ret = rtl2831_rd_reg(adap->dev, SYS_GPIO_OUT_VAL, &gpio);
  345. if (ret)
  346. goto err;
  347. if (onoff) {
  348. buf[0] = 0x00;
  349. buf[1] = 0x00;
  350. gpio |= 0x04; /* LED on */
  351. } else {
  352. buf[0] = 0x10; /* stall EPA */
  353. buf[1] = 0x02; /* reset EPA */
  354. gpio &= (~0x04); /* LED off */
  355. }
  356. ret = rtl2831_wr_reg(adap->dev, SYS_GPIO_OUT_VAL, gpio);
  357. if (ret)
  358. goto err;
  359. ret = rtl2831_wr_regs(adap->dev, USB_EPA_CTL, buf, 2);
  360. if (ret)
  361. goto err;
  362. return ret;
  363. err:
  364. deb_info("%s: failed=%d\n", __func__, ret);
  365. return ret;
  366. }
  367. static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff)
  368. {
  369. int ret;
  370. u8 gpio, sys0;
  371. deb_info("%s: onoff=%d\n", __func__, onoff);
  372. /* demod adc */
  373. ret = rtl2831_rd_reg(d, SYS_SYS0, &sys0);
  374. if (ret)
  375. goto err;
  376. /* tuner power, read GPIOs */
  377. ret = rtl2831_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
  378. if (ret)
  379. goto err;
  380. deb_info("%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio);
  381. if (onoff) {
  382. gpio |= 0x01; /* GPIO0 = 1 */
  383. gpio &= (~0x10); /* GPIO4 = 0 */
  384. sys0 = sys0 & 0x0f;
  385. sys0 |= 0xe0;
  386. } else {
  387. #if 0 /* keep */
  388. /*
  389. * FIXME: Use .fe_ioctl_override() to prevent demod
  390. * IOCTLs in case of device is powered off.
  391. *
  392. * For now we cannot power off device because most FE IOCTLs
  393. * can be performed only when device is powered.
  394. * Using IOCTLs when device is powered off will result errors
  395. * because register access to demod fails.
  396. */
  397. gpio &= (~0x01); /* GPIO0 = 0 */
  398. gpio |= 0x10; /* GPIO4 = 1 */
  399. sys0 = sys0 & (~0xc0);
  400. #endif
  401. }
  402. deb_info("%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio);
  403. /* demod adc */
  404. ret = rtl2831_wr_reg(d, SYS_SYS0, sys0);
  405. if (ret)
  406. goto err;
  407. /* tuner power, write GPIOs */
  408. ret = rtl2831_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
  409. if (ret)
  410. goto err;
  411. return ret;
  412. err:
  413. deb_info("%s: failed=%d\n", __func__, ret);
  414. return ret;
  415. }
  416. static int rtl28xxu_rc_query(struct dvb_usb_device *d)
  417. {
  418. int ret;
  419. u8 buf[5];
  420. u32 rc_code;
  421. ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
  422. if (ret)
  423. goto err;
  424. if (buf[4] & 0x01) {
  425. if (buf[2] == (u8) ~buf[3]) {
  426. if (buf[0] == (u8) ~buf[1]) {
  427. /* NEC standard (16 bit) */
  428. rc_code = buf[0] << 8 | buf[2];
  429. } else {
  430. /* NEC extended (24 bit) */
  431. rc_code = buf[0] << 16 |
  432. buf[1] << 8 | buf[2];
  433. }
  434. } else {
  435. /* NEC full (32 bit) */
  436. rc_code = buf[0] << 24 | buf[1] << 16 |
  437. buf[2] << 8 | buf[3];
  438. }
  439. rc_keydown(d->rc_dev, rc_code, 0);
  440. ret = rtl2831_wr_reg(d, SYS_IRRC_SR, 1);
  441. if (ret)
  442. goto err;
  443. /* repeated intentionally to avoid extra keypress */
  444. ret = rtl2831_wr_reg(d, SYS_IRRC_SR, 1);
  445. if (ret)
  446. goto err;
  447. }
  448. return ret;
  449. err:
  450. deb_info("%s: failed=%d\n", __func__, ret);
  451. return ret;
  452. }
  453. /* DVB USB Driver stuff */
  454. #define USB_VID_REALTEK 0x0bda
  455. #define USB_PID_RTL2831U 0x2831
  456. #define USB_PID_FREECOM 0x0160
  457. #define RTL2831U_0BDA_2831 0
  458. #define RTL2831U_14AA_0160 1
  459. static struct usb_device_id rtl28xxu_table[] = {
  460. [RTL2831U_0BDA_2831] = {
  461. USB_DEVICE(USB_VID_REALTEK, USB_PID_RTL2831U)},
  462. [RTL2831U_14AA_0160] = {
  463. USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM)},
  464. {} /* terminating entry */
  465. };
  466. MODULE_DEVICE_TABLE(usb, rtl28xxu_table);
  467. static struct dvb_usb_device_properties rtl28xxu_properties[] = {
  468. {
  469. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  470. .usb_ctrl = DEVICE_SPECIFIC,
  471. .no_reconnect = 1,
  472. .size_of_priv = sizeof(struct rtl28xxu_priv),
  473. .num_adapters = 1,
  474. .adapter = {
  475. {
  476. .frontend_attach = rtl28xxu_frontend_attach,
  477. .tuner_attach = rtl28xxu_tuner_attach,
  478. .streaming_ctrl = rtl28xxu_streaming_ctrl,
  479. .stream = {
  480. .type = USB_BULK,
  481. .count = 6,
  482. .endpoint = 0x81,
  483. .u = {
  484. .bulk = {
  485. .buffersize = 4096,
  486. }
  487. }
  488. },
  489. }
  490. },
  491. .power_ctrl = rtl28xxu_power_ctrl,
  492. .rc.core = {
  493. .protocol = RC_TYPE_NEC,
  494. .module_name = "rtl28xxu",
  495. .rc_query = rtl28xxu_rc_query,
  496. .rc_interval = 400,
  497. .allowed_protos = RC_TYPE_NEC,
  498. .rc_codes = RC_MAP_EMPTY,
  499. },
  500. .i2c_algo = &rtl28xxu_i2c_algo,
  501. .num_device_descs = 2,
  502. .devices = {
  503. {
  504. .name = "Realtek RTL2831U reference design",
  505. .cold_ids = {NULL},
  506. .warm_ids = {
  507. &rtl28xxu_table[RTL2831U_0BDA_2831], NULL},
  508. },
  509. {
  510. .name = "Freecom USB2.0 DVB-T",
  511. .cold_ids = {NULL},
  512. .warm_ids = {
  513. &rtl28xxu_table[RTL2831U_14AA_0160], NULL},
  514. },
  515. }
  516. },
  517. };
  518. static int rtl28xxu_probe(struct usb_interface *intf,
  519. const struct usb_device_id *id)
  520. {
  521. int ret, i;
  522. int properties_count = ARRAY_SIZE(rtl28xxu_properties);
  523. struct dvb_usb_device *d = NULL;
  524. struct rtl28xxu_reg_val rc_nec_tab[] = {
  525. { 0x3033, 0x80 },
  526. { 0x3020, 0x43 },
  527. { 0x3021, 0x16 },
  528. { 0x3022, 0x16 },
  529. { 0x3023, 0x5a },
  530. { 0x3024, 0x2d },
  531. { 0x3025, 0x16 },
  532. { 0x3026, 0x01 },
  533. { 0x3028, 0xb0 },
  534. { 0x3029, 0x04 },
  535. { 0x302c, 0x88 },
  536. { 0x302e, 0x13 },
  537. { 0x3030, 0xdf },
  538. { 0x3031, 0x05 },
  539. };
  540. deb_info("%s: interface=%d\n", __func__,
  541. intf->cur_altsetting->desc.bInterfaceNumber);
  542. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  543. return 0;
  544. for (i = 0; i < properties_count; i++) {
  545. ret = dvb_usb_device_init(intf, &rtl28xxu_properties[i],
  546. THIS_MODULE, &d, adapter_nr);
  547. if (ret == 0 || ret != -ENODEV)
  548. break;
  549. }
  550. if (ret)
  551. goto err;
  552. /* init USB endpoints */
  553. ret = rtl2831_wr_reg(d, USB_SYSCTL_0, 0x09);
  554. if (ret)
  555. goto err;
  556. ret = rtl2831_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
  557. if (ret)
  558. goto err;
  559. ret = rtl2831_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
  560. if (ret)
  561. goto err;
  562. /* init remote controller */
  563. for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
  564. ret = rtl2831_wr_reg(d, rc_nec_tab[i].reg, rc_nec_tab[i].val);
  565. if (ret)
  566. goto err;
  567. }
  568. return ret;
  569. err:
  570. deb_info("%s: failed=%d\n", __func__, ret);
  571. return ret;
  572. }
  573. static struct usb_driver rtl28xxu_driver = {
  574. .name = "dvb_usb_rtl28xxu",
  575. .probe = rtl28xxu_probe,
  576. .disconnect = dvb_usb_device_exit,
  577. .id_table = rtl28xxu_table,
  578. };
  579. /* module stuff */
  580. static int __init rtl28xxu_module_init(void)
  581. {
  582. int ret;
  583. deb_info("%s:\n", __func__);
  584. ret = usb_register(&rtl28xxu_driver);
  585. if (ret)
  586. err("usb_register failed=%d", ret);
  587. return ret;
  588. }
  589. static void __exit rtl28xxu_module_exit(void)
  590. {
  591. deb_info("%s:\n", __func__);
  592. /* deregister this driver from the USB subsystem */
  593. usb_deregister(&rtl28xxu_driver);
  594. }
  595. module_init(rtl28xxu_module_init);
  596. module_exit(rtl28xxu_module_exit);
  597. MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
  598. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  599. MODULE_LICENSE("GPL");