rtl28xxu.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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 "rtl2832_sdr.h"
  26. #include "mn88472.h"
  27. #include "mn88473.h"
  28. #include "qt1010.h"
  29. #include "mt2060.h"
  30. #include "mxl5005s.h"
  31. #include "fc0012.h"
  32. #include "fc0013.h"
  33. #include "e4000.h"
  34. #include "fc2580.h"
  35. #include "tua9001.h"
  36. #include "r820t.h"
  37. #ifdef CONFIG_MEDIA_ATTACH
  38. #define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
  39. void *__r = NULL; \
  40. typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
  41. if (__a) { \
  42. __r = (void *) __a(ARGS); \
  43. if (__r == NULL) \
  44. symbol_put(FUNCTION); \
  45. } \
  46. __r; \
  47. })
  48. #else
  49. #define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
  50. FUNCTION(ARGS); \
  51. })
  52. #endif
  53. static int rtl28xxu_disable_rc;
  54. module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644);
  55. MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller");
  56. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  57. static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
  58. {
  59. int ret;
  60. unsigned int pipe;
  61. u8 requesttype;
  62. u8 *buf;
  63. buf = kmalloc(req->size, GFP_KERNEL);
  64. if (!buf) {
  65. ret = -ENOMEM;
  66. goto err;
  67. }
  68. if (req->index & CMD_WR_FLAG) {
  69. /* write */
  70. memcpy(buf, req->data, req->size);
  71. requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
  72. pipe = usb_sndctrlpipe(d->udev, 0);
  73. } else {
  74. /* read */
  75. requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
  76. pipe = usb_rcvctrlpipe(d->udev, 0);
  77. }
  78. ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
  79. req->index, buf, req->size, 1000);
  80. dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
  81. req->index, buf, req->size);
  82. if (ret > 0)
  83. ret = 0;
  84. /* read request, copy returned data to return buf */
  85. if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
  86. memcpy(req->data, buf, req->size);
  87. kfree(buf);
  88. if (ret)
  89. goto err;
  90. return ret;
  91. err:
  92. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  93. return ret;
  94. }
  95. static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
  96. {
  97. struct rtl28xxu_req req;
  98. if (reg < 0x3000)
  99. req.index = CMD_USB_WR;
  100. else if (reg < 0x4000)
  101. req.index = CMD_SYS_WR;
  102. else
  103. req.index = CMD_IR_WR;
  104. req.value = reg;
  105. req.size = len;
  106. req.data = val;
  107. return rtl28xxu_ctrl_msg(d, &req);
  108. }
  109. static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
  110. {
  111. struct rtl28xxu_req req;
  112. if (reg < 0x3000)
  113. req.index = CMD_USB_RD;
  114. else if (reg < 0x4000)
  115. req.index = CMD_SYS_RD;
  116. else
  117. req.index = CMD_IR_RD;
  118. req.value = reg;
  119. req.size = len;
  120. req.data = val;
  121. return rtl28xxu_ctrl_msg(d, &req);
  122. }
  123. static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
  124. {
  125. return rtl28xx_wr_regs(d, reg, &val, 1);
  126. }
  127. static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
  128. {
  129. return rtl2831_rd_regs(d, reg, val, 1);
  130. }
  131. static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
  132. u8 mask)
  133. {
  134. int ret;
  135. u8 tmp;
  136. /* no need for read if whole reg is written */
  137. if (mask != 0xff) {
  138. ret = rtl28xx_rd_reg(d, reg, &tmp);
  139. if (ret)
  140. return ret;
  141. val &= mask;
  142. tmp &= ~mask;
  143. val |= tmp;
  144. }
  145. return rtl28xx_wr_reg(d, reg, val);
  146. }
  147. /* I2C */
  148. static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  149. int num)
  150. {
  151. int ret;
  152. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  153. struct rtl28xxu_priv *priv = d->priv;
  154. struct rtl28xxu_req req;
  155. /*
  156. * It is not known which are real I2C bus xfer limits, but testing
  157. * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
  158. * TODO: find out RTL2832U lens
  159. */
  160. /*
  161. * I2C adapter logic looks rather complicated due to fact it handles
  162. * three different access methods. Those methods are;
  163. * 1) integrated demod access
  164. * 2) old I2C access
  165. * 3) new I2C access
  166. *
  167. * Used method is selected in order 1, 2, 3. Method 3 can handle all
  168. * requests but there is two reasons why not use it always;
  169. * 1) It is most expensive, usually two USB messages are needed
  170. * 2) At least RTL2831U does not support it
  171. *
  172. * Method 3 is needed in case of I2C write+read (typical register read)
  173. * where write is more than one byte.
  174. */
  175. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  176. return -EAGAIN;
  177. if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
  178. (msg[1].flags & I2C_M_RD)) {
  179. if (msg[0].len > 24 || msg[1].len > 24) {
  180. /* TODO: check msg[0].len max */
  181. ret = -EOPNOTSUPP;
  182. goto err_mutex_unlock;
  183. } else if (msg[0].addr == 0x10) {
  184. /* method 1 - integrated demod */
  185. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  186. req.index = CMD_DEMOD_RD | priv->page;
  187. req.size = msg[1].len;
  188. req.data = &msg[1].buf[0];
  189. ret = rtl28xxu_ctrl_msg(d, &req);
  190. } else if (msg[0].len < 2) {
  191. /* method 2 - old I2C */
  192. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  193. req.index = CMD_I2C_RD;
  194. req.size = msg[1].len;
  195. req.data = &msg[1].buf[0];
  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. if (ret)
  205. goto err_mutex_unlock;
  206. req.value = (msg[0].addr << 1);
  207. req.index = CMD_I2C_DA_RD;
  208. req.size = msg[1].len;
  209. req.data = msg[1].buf;
  210. ret = rtl28xxu_ctrl_msg(d, &req);
  211. }
  212. } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
  213. if (msg[0].len > 22) {
  214. /* TODO: check msg[0].len max */
  215. ret = -EOPNOTSUPP;
  216. goto err_mutex_unlock;
  217. } else if (msg[0].addr == 0x10) {
  218. /* method 1 - integrated demod */
  219. if (msg[0].buf[0] == 0x00) {
  220. /* save demod page for later demod access */
  221. priv->page = msg[0].buf[1];
  222. ret = 0;
  223. } else {
  224. req.value = (msg[0].buf[0] << 8) |
  225. (msg[0].addr << 1);
  226. req.index = CMD_DEMOD_WR | priv->page;
  227. req.size = msg[0].len-1;
  228. req.data = &msg[0].buf[1];
  229. ret = rtl28xxu_ctrl_msg(d, &req);
  230. }
  231. } else if (msg[0].len < 23) {
  232. /* method 2 - old I2C */
  233. req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
  234. req.index = CMD_I2C_WR;
  235. req.size = msg[0].len-1;
  236. req.data = &msg[0].buf[1];
  237. ret = rtl28xxu_ctrl_msg(d, &req);
  238. } else {
  239. /* method 3 - new I2C */
  240. req.value = (msg[0].addr << 1);
  241. req.index = CMD_I2C_DA_WR;
  242. req.size = msg[0].len;
  243. req.data = msg[0].buf;
  244. ret = rtl28xxu_ctrl_msg(d, &req);
  245. }
  246. } else {
  247. ret = -EINVAL;
  248. }
  249. err_mutex_unlock:
  250. mutex_unlock(&d->i2c_mutex);
  251. return ret ? ret : num;
  252. }
  253. static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
  254. {
  255. return I2C_FUNC_I2C;
  256. }
  257. static struct i2c_algorithm rtl28xxu_i2c_algo = {
  258. .master_xfer = rtl28xxu_i2c_xfer,
  259. .functionality = rtl28xxu_i2c_func,
  260. };
  261. static int rtl2831u_read_config(struct dvb_usb_device *d)
  262. {
  263. struct rtl28xxu_priv *priv = d_to_priv(d);
  264. int ret;
  265. u8 buf[1];
  266. /* open RTL2831U/RTL2830 I2C gate */
  267. struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"};
  268. /* tuner probes */
  269. struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
  270. struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
  271. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  272. /*
  273. * RTL2831U GPIOs
  274. * =========================================================
  275. * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
  276. * GPIO2 | LED | 0 off | 1 on |
  277. * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
  278. */
  279. /* GPIO direction */
  280. ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
  281. if (ret)
  282. goto err;
  283. /* enable as output GPIO0, GPIO2, GPIO4 */
  284. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
  285. if (ret)
  286. goto err;
  287. /*
  288. * Probe used tuner. We need to know used tuner before demod attach
  289. * since there is some demod params needed to set according to tuner.
  290. */
  291. /* demod needs some time to wake up */
  292. msleep(20);
  293. priv->tuner_name = "NONE";
  294. /* open demod I2C gate */
  295. ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
  296. if (ret)
  297. goto err;
  298. /* check QT1010 ID(?) register; reg=0f val=2c */
  299. ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
  300. if (ret == 0 && buf[0] == 0x2c) {
  301. priv->tuner = TUNER_RTL2830_QT1010;
  302. priv->tuner_name = "QT1010";
  303. goto found;
  304. }
  305. /* open demod I2C gate */
  306. ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
  307. if (ret)
  308. goto err;
  309. /* check MT2060 ID register; reg=00 val=63 */
  310. ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
  311. if (ret == 0 && buf[0] == 0x63) {
  312. priv->tuner = TUNER_RTL2830_MT2060;
  313. priv->tuner_name = "MT2060";
  314. goto found;
  315. }
  316. /* assume MXL5005S */
  317. priv->tuner = TUNER_RTL2830_MXL5005S;
  318. priv->tuner_name = "MXL5005S";
  319. goto found;
  320. found:
  321. dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
  322. return 0;
  323. err:
  324. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  325. return ret;
  326. }
  327. static int rtl2832u_read_config(struct dvb_usb_device *d)
  328. {
  329. struct rtl28xxu_priv *priv = d_to_priv(d);
  330. int ret;
  331. u8 buf[2];
  332. /* open RTL2832U/RTL2832 I2C gate */
  333. struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
  334. /* close RTL2832U/RTL2832 I2C gate */
  335. struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
  336. /* tuner probes */
  337. struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
  338. struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
  339. struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
  340. struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
  341. struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
  342. struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
  343. struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
  344. struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
  345. struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
  346. struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
  347. struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
  348. struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
  349. struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
  350. struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
  351. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  352. /* enable GPIO3 and GPIO6 as output */
  353. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
  354. if (ret)
  355. goto err;
  356. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
  357. if (ret)
  358. goto err;
  359. /*
  360. * Probe used tuner. We need to know used tuner before demod attach
  361. * since there is some demod params needed to set according to tuner.
  362. */
  363. /* open demod I2C gate */
  364. ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
  365. if (ret)
  366. goto err;
  367. priv->tuner_name = "NONE";
  368. /* check FC0012 ID register; reg=00 val=a1 */
  369. ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
  370. if (ret == 0 && buf[0] == 0xa1) {
  371. priv->tuner = TUNER_RTL2832_FC0012;
  372. priv->tuner_name = "FC0012";
  373. goto tuner_found;
  374. }
  375. /* check FC0013 ID register; reg=00 val=a3 */
  376. ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
  377. if (ret == 0 && buf[0] == 0xa3) {
  378. priv->tuner = TUNER_RTL2832_FC0013;
  379. priv->tuner_name = "FC0013";
  380. goto tuner_found;
  381. }
  382. /* check MT2266 ID register; reg=00 val=85 */
  383. ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
  384. if (ret == 0 && buf[0] == 0x85) {
  385. priv->tuner = TUNER_RTL2832_MT2266;
  386. priv->tuner_name = "MT2266";
  387. goto tuner_found;
  388. }
  389. /* check FC2580 ID register; reg=01 val=56 */
  390. ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
  391. if (ret == 0 && buf[0] == 0x56) {
  392. priv->tuner = TUNER_RTL2832_FC2580;
  393. priv->tuner_name = "FC2580";
  394. goto tuner_found;
  395. }
  396. /* check MT2063 ID register; reg=00 val=9e || 9c */
  397. ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
  398. if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
  399. priv->tuner = TUNER_RTL2832_MT2063;
  400. priv->tuner_name = "MT2063";
  401. goto tuner_found;
  402. }
  403. /* check MAX3543 ID register; reg=00 val=38 */
  404. ret = rtl28xxu_ctrl_msg(d, &req_max3543);
  405. if (ret == 0 && buf[0] == 0x38) {
  406. priv->tuner = TUNER_RTL2832_MAX3543;
  407. priv->tuner_name = "MAX3543";
  408. goto tuner_found;
  409. }
  410. /* check TUA9001 ID register; reg=7e val=2328 */
  411. ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
  412. if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
  413. priv->tuner = TUNER_RTL2832_TUA9001;
  414. priv->tuner_name = "TUA9001";
  415. goto tuner_found;
  416. }
  417. /* check MXL5007R ID register; reg=d9 val=14 */
  418. ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
  419. if (ret == 0 && buf[0] == 0x14) {
  420. priv->tuner = TUNER_RTL2832_MXL5007T;
  421. priv->tuner_name = "MXL5007T";
  422. goto tuner_found;
  423. }
  424. /* check E4000 ID register; reg=02 val=40 */
  425. ret = rtl28xxu_ctrl_msg(d, &req_e4000);
  426. if (ret == 0 && buf[0] == 0x40) {
  427. priv->tuner = TUNER_RTL2832_E4000;
  428. priv->tuner_name = "E4000";
  429. goto tuner_found;
  430. }
  431. /* check TDA18272 ID register; reg=00 val=c760 */
  432. ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
  433. if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
  434. priv->tuner = TUNER_RTL2832_TDA18272;
  435. priv->tuner_name = "TDA18272";
  436. goto tuner_found;
  437. }
  438. /* check R820T ID register; reg=00 val=69 */
  439. ret = rtl28xxu_ctrl_msg(d, &req_r820t);
  440. if (ret == 0 && buf[0] == 0x69) {
  441. priv->tuner = TUNER_RTL2832_R820T;
  442. priv->tuner_name = "R820T";
  443. goto tuner_found;
  444. }
  445. /* check R828D ID register; reg=00 val=69 */
  446. ret = rtl28xxu_ctrl_msg(d, &req_r828d);
  447. if (ret == 0 && buf[0] == 0x69) {
  448. priv->tuner = TUNER_RTL2832_R828D;
  449. priv->tuner_name = "R828D";
  450. goto tuner_found;
  451. }
  452. tuner_found:
  453. dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
  454. /* probe slave demod */
  455. if (priv->tuner == TUNER_RTL2832_R828D) {
  456. /* power on MN88472 demod on GPIO0 */
  457. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
  458. if (ret)
  459. goto err;
  460. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
  461. if (ret)
  462. goto err;
  463. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
  464. if (ret)
  465. goto err;
  466. /* check MN88472 answers */
  467. ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
  468. if (ret == 0 && buf[0] == 0x02) {
  469. dev_dbg(&d->udev->dev, "%s: MN88472 found\n", __func__);
  470. priv->slave_demod = SLAVE_DEMOD_MN88472;
  471. goto demod_found;
  472. }
  473. ret = rtl28xxu_ctrl_msg(d, &req_mn88473);
  474. if (ret == 0 && buf[0] == 0x03) {
  475. dev_dbg(&d->udev->dev, "%s: MN88473 found\n", __func__);
  476. priv->slave_demod = SLAVE_DEMOD_MN88473;
  477. goto demod_found;
  478. }
  479. }
  480. demod_found:
  481. /* close demod I2C gate */
  482. ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
  483. if (ret < 0)
  484. goto err;
  485. return 0;
  486. err:
  487. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  488. return ret;
  489. }
  490. static const struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
  491. .i2c_addr = 0x10, /* 0x20 */
  492. .xtal = 28800000,
  493. .ts_mode = 0,
  494. .spec_inv = 1,
  495. .vtop = 0x20,
  496. .krf = 0x04,
  497. .agc_targ_val = 0x2d,
  498. };
  499. static const struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
  500. .i2c_addr = 0x10, /* 0x20 */
  501. .xtal = 28800000,
  502. .ts_mode = 0,
  503. .spec_inv = 1,
  504. .vtop = 0x20,
  505. .krf = 0x04,
  506. .agc_targ_val = 0x2d,
  507. };
  508. static const struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
  509. .i2c_addr = 0x10, /* 0x20 */
  510. .xtal = 28800000,
  511. .ts_mode = 0,
  512. .spec_inv = 0,
  513. .vtop = 0x3f,
  514. .krf = 0x04,
  515. .agc_targ_val = 0x3e,
  516. };
  517. static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
  518. {
  519. struct dvb_usb_device *d = adap_to_d(adap);
  520. struct rtl28xxu_priv *priv = d_to_priv(d);
  521. const struct rtl2830_config *rtl2830_config;
  522. int ret;
  523. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  524. switch (priv->tuner) {
  525. case TUNER_RTL2830_QT1010:
  526. rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
  527. break;
  528. case TUNER_RTL2830_MT2060:
  529. rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
  530. break;
  531. case TUNER_RTL2830_MXL5005S:
  532. rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
  533. break;
  534. default:
  535. dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
  536. KBUILD_MODNAME, priv->tuner_name);
  537. ret = -ENODEV;
  538. goto err;
  539. }
  540. /* attach demodulator */
  541. adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config, &d->i2c_adap);
  542. if (!adap->fe[0]) {
  543. ret = -ENODEV;
  544. goto err;
  545. }
  546. return 0;
  547. err:
  548. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  549. return ret;
  550. }
  551. static const struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
  552. .i2c_addr = 0x10, /* 0x20 */
  553. .xtal = 28800000,
  554. .tuner = TUNER_RTL2832_FC0012
  555. };
  556. static const struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
  557. .i2c_addr = 0x10, /* 0x20 */
  558. .xtal = 28800000,
  559. .tuner = TUNER_RTL2832_FC0013
  560. };
  561. static const struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
  562. .i2c_addr = 0x10, /* 0x20 */
  563. .xtal = 28800000,
  564. .tuner = TUNER_RTL2832_TUA9001,
  565. };
  566. static const struct rtl2832_config rtl28xxu_rtl2832_e4000_config = {
  567. .i2c_addr = 0x10, /* 0x20 */
  568. .xtal = 28800000,
  569. .tuner = TUNER_RTL2832_E4000,
  570. };
  571. static const struct rtl2832_config rtl28xxu_rtl2832_r820t_config = {
  572. .i2c_addr = 0x10,
  573. .xtal = 28800000,
  574. .tuner = TUNER_RTL2832_R820T,
  575. };
  576. static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
  577. int cmd, int arg)
  578. {
  579. int ret;
  580. u8 val;
  581. dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
  582. switch (cmd) {
  583. case FC_FE_CALLBACK_VHF_ENABLE:
  584. /* set output values */
  585. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
  586. if (ret)
  587. goto err;
  588. if (arg)
  589. val &= 0xbf; /* set GPIO6 low */
  590. else
  591. val |= 0x40; /* set GPIO6 high */
  592. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
  593. if (ret)
  594. goto err;
  595. break;
  596. default:
  597. ret = -EINVAL;
  598. goto err;
  599. }
  600. return 0;
  601. err:
  602. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  603. return ret;
  604. }
  605. static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
  606. int cmd, int arg)
  607. {
  608. int ret;
  609. u8 val;
  610. dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
  611. /*
  612. * CEN always enabled by hardware wiring
  613. * RESETN GPIO4
  614. * RXEN GPIO1
  615. */
  616. switch (cmd) {
  617. case TUA9001_CMD_RESETN:
  618. if (arg)
  619. val = (1 << 4);
  620. else
  621. val = (0 << 4);
  622. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
  623. if (ret)
  624. goto err;
  625. break;
  626. case TUA9001_CMD_RXEN:
  627. if (arg)
  628. val = (1 << 1);
  629. else
  630. val = (0 << 1);
  631. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
  632. if (ret)
  633. goto err;
  634. break;
  635. }
  636. return 0;
  637. err:
  638. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  639. return ret;
  640. }
  641. static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
  642. {
  643. struct rtl28xxu_priv *priv = d->priv;
  644. switch (priv->tuner) {
  645. case TUNER_RTL2832_FC0012:
  646. return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
  647. case TUNER_RTL2832_TUA9001:
  648. return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
  649. default:
  650. break;
  651. }
  652. return 0;
  653. }
  654. static int rtl2832u_frontend_callback(void *adapter_priv, int component,
  655. int cmd, int arg)
  656. {
  657. struct i2c_adapter *adap = adapter_priv;
  658. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  659. dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n",
  660. __func__, component, cmd, arg);
  661. switch (component) {
  662. case DVB_FRONTEND_COMPONENT_TUNER:
  663. return rtl2832u_tuner_callback(d, cmd, arg);
  664. default:
  665. break;
  666. }
  667. return 0;
  668. }
  669. static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
  670. {
  671. int ret;
  672. struct dvb_usb_device *d = adap_to_d(adap);
  673. struct rtl28xxu_priv *priv = d_to_priv(d);
  674. const struct rtl2832_config *rtl2832_config;
  675. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  676. switch (priv->tuner) {
  677. case TUNER_RTL2832_FC0012:
  678. rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
  679. break;
  680. case TUNER_RTL2832_FC0013:
  681. rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
  682. break;
  683. case TUNER_RTL2832_FC2580:
  684. /* FIXME: do not abuse fc0012 settings */
  685. rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
  686. break;
  687. case TUNER_RTL2832_TUA9001:
  688. rtl2832_config = &rtl28xxu_rtl2832_tua9001_config;
  689. break;
  690. case TUNER_RTL2832_E4000:
  691. rtl2832_config = &rtl28xxu_rtl2832_e4000_config;
  692. break;
  693. case TUNER_RTL2832_R820T:
  694. case TUNER_RTL2832_R828D:
  695. rtl2832_config = &rtl28xxu_rtl2832_r820t_config;
  696. break;
  697. default:
  698. dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
  699. KBUILD_MODNAME, priv->tuner_name);
  700. ret = -ENODEV;
  701. goto err;
  702. }
  703. /* attach demodulator */
  704. adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap);
  705. if (!adap->fe[0]) {
  706. ret = -ENODEV;
  707. goto err;
  708. }
  709. /* RTL2832 I2C repeater */
  710. priv->demod_i2c_adapter = rtl2832_get_i2c_adapter(adap->fe[0]);
  711. /* set fe callback */
  712. adap->fe[0]->callback = rtl2832u_frontend_callback;
  713. if (priv->slave_demod) {
  714. struct i2c_board_info info = {};
  715. struct i2c_client *client;
  716. /*
  717. * We continue on reduced mode, without DVB-T2/C, using master
  718. * demod, when slave demod fails.
  719. */
  720. ret = 0;
  721. /* attach slave demodulator */
  722. if (priv->slave_demod == SLAVE_DEMOD_MN88472) {
  723. struct mn88472_config mn88472_config = {};
  724. mn88472_config.fe = &adap->fe[1];
  725. mn88472_config.i2c_wr_max = 22,
  726. strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
  727. info.addr = 0x18;
  728. info.platform_data = &mn88472_config;
  729. request_module(info.type);
  730. client = i2c_new_device(priv->demod_i2c_adapter, &info);
  731. if (client == NULL || client->dev.driver == NULL) {
  732. priv->slave_demod = SLAVE_DEMOD_NONE;
  733. goto err_slave_demod_failed;
  734. }
  735. if (!try_module_get(client->dev.driver->owner)) {
  736. i2c_unregister_device(client);
  737. priv->slave_demod = SLAVE_DEMOD_NONE;
  738. goto err_slave_demod_failed;
  739. }
  740. priv->i2c_client_slave_demod = client;
  741. } else {
  742. struct mn88473_config mn88473_config = {};
  743. mn88473_config.fe = &adap->fe[1];
  744. mn88473_config.i2c_wr_max = 22,
  745. strlcpy(info.type, "mn88473", I2C_NAME_SIZE);
  746. info.addr = 0x18;
  747. info.platform_data = &mn88473_config;
  748. request_module(info.type);
  749. client = i2c_new_device(priv->demod_i2c_adapter, &info);
  750. if (client == NULL || client->dev.driver == NULL) {
  751. priv->slave_demod = SLAVE_DEMOD_NONE;
  752. goto err_slave_demod_failed;
  753. }
  754. if (!try_module_get(client->dev.driver->owner)) {
  755. i2c_unregister_device(client);
  756. priv->slave_demod = SLAVE_DEMOD_NONE;
  757. goto err_slave_demod_failed;
  758. }
  759. priv->i2c_client_slave_demod = client;
  760. }
  761. }
  762. return 0;
  763. err_slave_demod_failed:
  764. err:
  765. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  766. return ret;
  767. }
  768. static struct qt1010_config rtl28xxu_qt1010_config = {
  769. .i2c_address = 0x62, /* 0xc4 */
  770. };
  771. static struct mt2060_config rtl28xxu_mt2060_config = {
  772. .i2c_address = 0x60, /* 0xc0 */
  773. .clock_out = 0,
  774. };
  775. static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
  776. .i2c_address = 0x63, /* 0xc6 */
  777. .if_freq = IF_FREQ_4570000HZ,
  778. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  779. .agc_mode = MXL_SINGLE_AGC,
  780. .tracking_filter = MXL_TF_C_H,
  781. .rssi_enable = MXL_RSSI_ENABLE,
  782. .cap_select = MXL_CAP_SEL_ENABLE,
  783. .div_out = MXL_DIV_OUT_4,
  784. .clock_out = MXL_CLOCK_OUT_DISABLE,
  785. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  786. .top = MXL5005S_TOP_25P2,
  787. .mod_mode = MXL_DIGITAL_MODE,
  788. .if_mode = MXL_ZERO_IF,
  789. .AgcMasterByte = 0x00,
  790. };
  791. static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
  792. {
  793. int ret;
  794. struct dvb_usb_device *d = adap_to_d(adap);
  795. struct rtl28xxu_priv *priv = d_to_priv(d);
  796. struct i2c_adapter *rtl2830_tuner_i2c;
  797. struct dvb_frontend *fe;
  798. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  799. /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
  800. rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
  801. switch (priv->tuner) {
  802. case TUNER_RTL2830_QT1010:
  803. fe = dvb_attach(qt1010_attach, adap->fe[0],
  804. rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
  805. break;
  806. case TUNER_RTL2830_MT2060:
  807. fe = dvb_attach(mt2060_attach, adap->fe[0],
  808. rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
  809. 1220);
  810. break;
  811. case TUNER_RTL2830_MXL5005S:
  812. fe = dvb_attach(mxl5005s_attach, adap->fe[0],
  813. rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
  814. break;
  815. default:
  816. fe = NULL;
  817. dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
  818. priv->tuner);
  819. }
  820. if (fe == NULL) {
  821. ret = -ENODEV;
  822. goto err;
  823. }
  824. return 0;
  825. err:
  826. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  827. return ret;
  828. }
  829. static const struct fc2580_config rtl2832u_fc2580_config = {
  830. .i2c_addr = 0x56,
  831. .clock = 16384000,
  832. };
  833. static struct tua9001_config rtl2832u_tua9001_config = {
  834. .i2c_addr = 0x60,
  835. };
  836. static const struct fc0012_config rtl2832u_fc0012_config = {
  837. .i2c_address = 0x63, /* 0xc6 >> 1 */
  838. .xtal_freq = FC_XTAL_28_8_MHZ,
  839. };
  840. static const struct r820t_config rtl2832u_r820t_config = {
  841. .i2c_addr = 0x1a,
  842. .xtal = 28800000,
  843. .max_i2c_msg_len = 2,
  844. .rafael_chip = CHIP_R820T,
  845. };
  846. static const struct r820t_config rtl2832u_r828d_config = {
  847. .i2c_addr = 0x3a,
  848. .xtal = 16000000,
  849. .max_i2c_msg_len = 2,
  850. .rafael_chip = CHIP_R828D,
  851. };
  852. static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
  853. {
  854. int ret;
  855. struct dvb_usb_device *d = adap_to_d(adap);
  856. struct rtl28xxu_priv *priv = d_to_priv(d);
  857. struct dvb_frontend *fe = NULL;
  858. struct i2c_board_info info;
  859. struct i2c_client *client;
  860. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  861. memset(&info, 0, sizeof(struct i2c_board_info));
  862. switch (priv->tuner) {
  863. case TUNER_RTL2832_FC0012:
  864. fe = dvb_attach(fc0012_attach, adap->fe[0],
  865. &d->i2c_adap, &rtl2832u_fc0012_config);
  866. /* since fc0012 includs reading the signal strength delegate
  867. * that to the tuner driver */
  868. adap->fe[0]->ops.read_signal_strength =
  869. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  870. /* attach SDR */
  871. dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
  872. &rtl28xxu_rtl2832_fc0012_config, NULL);
  873. break;
  874. case TUNER_RTL2832_FC0013:
  875. fe = dvb_attach(fc0013_attach, adap->fe[0],
  876. &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
  877. /* fc0013 also supports signal strength reading */
  878. adap->fe[0]->ops.read_signal_strength =
  879. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  880. /* attach SDR */
  881. dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
  882. &rtl28xxu_rtl2832_fc0013_config, NULL);
  883. break;
  884. case TUNER_RTL2832_E4000: {
  885. struct v4l2_subdev *sd;
  886. struct i2c_adapter *i2c_adap_internal =
  887. rtl2832_get_private_i2c_adapter(adap->fe[0]);
  888. struct e4000_config e4000_config = {
  889. .fe = adap->fe[0],
  890. .clock = 28800000,
  891. };
  892. strlcpy(info.type, "e4000", I2C_NAME_SIZE);
  893. info.addr = 0x64;
  894. info.platform_data = &e4000_config;
  895. request_module(info.type);
  896. client = i2c_new_device(priv->demod_i2c_adapter, &info);
  897. if (client == NULL || client->dev.driver == NULL)
  898. break;
  899. if (!try_module_get(client->dev.driver->owner)) {
  900. i2c_unregister_device(client);
  901. break;
  902. }
  903. priv->i2c_client_tuner = client;
  904. sd = i2c_get_clientdata(client);
  905. i2c_set_adapdata(i2c_adap_internal, d);
  906. /* attach SDR */
  907. dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0],
  908. i2c_adap_internal,
  909. &rtl28xxu_rtl2832_e4000_config, sd);
  910. }
  911. break;
  912. case TUNER_RTL2832_FC2580:
  913. fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
  914. &rtl2832u_fc2580_config);
  915. break;
  916. case TUNER_RTL2832_TUA9001:
  917. /* enable GPIO1 and GPIO4 as output */
  918. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
  919. if (ret)
  920. goto err;
  921. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
  922. if (ret)
  923. goto err;
  924. fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
  925. &rtl2832u_tua9001_config);
  926. break;
  927. case TUNER_RTL2832_R820T:
  928. fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
  929. &rtl2832u_r820t_config);
  930. /* Use tuner to get the signal strength */
  931. adap->fe[0]->ops.read_signal_strength =
  932. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  933. /* attach SDR */
  934. dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
  935. &rtl28xxu_rtl2832_r820t_config, NULL);
  936. break;
  937. case TUNER_RTL2832_R828D:
  938. fe = dvb_attach(r820t_attach, adap->fe[0],
  939. priv->demod_i2c_adapter,
  940. &rtl2832u_r828d_config);
  941. adap->fe[0]->ops.read_signal_strength =
  942. adap->fe[0]->ops.tuner_ops.get_rf_strength;
  943. if (adap->fe[1]) {
  944. fe = dvb_attach(r820t_attach, adap->fe[1],
  945. priv->demod_i2c_adapter,
  946. &rtl2832u_r828d_config);
  947. adap->fe[1]->ops.read_signal_strength =
  948. adap->fe[1]->ops.tuner_ops.get_rf_strength;
  949. }
  950. /* attach SDR */
  951. dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
  952. &rtl28xxu_rtl2832_r820t_config, NULL);
  953. break;
  954. default:
  955. dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
  956. priv->tuner);
  957. }
  958. if (fe == NULL && priv->i2c_client_tuner == NULL) {
  959. ret = -ENODEV;
  960. goto err;
  961. }
  962. return 0;
  963. err:
  964. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  965. return ret;
  966. }
  967. static int rtl28xxu_init(struct dvb_usb_device *d)
  968. {
  969. int ret;
  970. u8 val;
  971. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  972. /* init USB endpoints */
  973. ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
  974. if (ret)
  975. goto err;
  976. /* enable DMA and Full Packet Mode*/
  977. val |= 0x09;
  978. ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
  979. if (ret)
  980. goto err;
  981. /* set EPA maximum packet size to 0x0200 */
  982. ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
  983. if (ret)
  984. goto err;
  985. /* change EPA FIFO length */
  986. ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
  987. if (ret)
  988. goto err;
  989. return ret;
  990. err:
  991. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  992. return ret;
  993. }
  994. static void rtl28xxu_exit(struct dvb_usb_device *d)
  995. {
  996. struct rtl28xxu_priv *priv = d->priv;
  997. struct i2c_client *client;
  998. dev_dbg(&d->udev->dev, "%s:\n", __func__);
  999. /* remove I2C tuner */
  1000. client = priv->i2c_client_tuner;
  1001. if (client) {
  1002. module_put(client->dev.driver->owner);
  1003. i2c_unregister_device(client);
  1004. }
  1005. /* remove I2C slave demod */
  1006. client = priv->i2c_client_slave_demod;
  1007. if (client) {
  1008. module_put(client->dev.driver->owner);
  1009. i2c_unregister_device(client);
  1010. }
  1011. return;
  1012. }
  1013. static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
  1014. {
  1015. int ret;
  1016. u8 gpio, sys0, epa_ctl[2];
  1017. dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
  1018. /* demod adc */
  1019. ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
  1020. if (ret)
  1021. goto err;
  1022. /* tuner power, read GPIOs */
  1023. ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
  1024. if (ret)
  1025. goto err;
  1026. dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
  1027. sys0, gpio);
  1028. if (onoff) {
  1029. gpio |= 0x01; /* GPIO0 = 1 */
  1030. gpio &= (~0x10); /* GPIO4 = 0 */
  1031. gpio |= 0x04; /* GPIO2 = 1, LED on */
  1032. sys0 = sys0 & 0x0f;
  1033. sys0 |= 0xe0;
  1034. epa_ctl[0] = 0x00; /* clear stall */
  1035. epa_ctl[1] = 0x00; /* clear reset */
  1036. } else {
  1037. gpio &= (~0x01); /* GPIO0 = 0 */
  1038. gpio |= 0x10; /* GPIO4 = 1 */
  1039. gpio &= (~0x04); /* GPIO2 = 1, LED off */
  1040. sys0 = sys0 & (~0xc0);
  1041. epa_ctl[0] = 0x10; /* set stall */
  1042. epa_ctl[1] = 0x02; /* set reset */
  1043. }
  1044. dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
  1045. sys0, gpio);
  1046. /* demod adc */
  1047. ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
  1048. if (ret)
  1049. goto err;
  1050. /* tuner power, write GPIOs */
  1051. ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
  1052. if (ret)
  1053. goto err;
  1054. /* streaming EP: stall & reset */
  1055. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
  1056. if (ret)
  1057. goto err;
  1058. if (onoff)
  1059. usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
  1060. return ret;
  1061. err:
  1062. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  1063. return ret;
  1064. }
  1065. static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
  1066. {
  1067. int ret;
  1068. dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
  1069. if (onoff) {
  1070. /* GPIO3=1, GPIO4=0 */
  1071. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
  1072. if (ret)
  1073. goto err;
  1074. /* suspend? */
  1075. ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
  1076. if (ret)
  1077. goto err;
  1078. /* enable PLL */
  1079. ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
  1080. if (ret)
  1081. goto err;
  1082. /* disable reset */
  1083. ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
  1084. if (ret)
  1085. goto err;
  1086. /* streaming EP: clear stall & reset */
  1087. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
  1088. if (ret)
  1089. goto err;
  1090. ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
  1091. if (ret)
  1092. goto err;
  1093. } else {
  1094. /* GPIO4=1 */
  1095. ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
  1096. if (ret)
  1097. goto err;
  1098. /* disable PLL */
  1099. ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
  1100. if (ret)
  1101. goto err;
  1102. /* streaming EP: set stall & reset */
  1103. ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
  1104. if (ret)
  1105. goto err;
  1106. }
  1107. return ret;
  1108. err:
  1109. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  1110. return ret;
  1111. }
  1112. static int rtl2832u_frontend_ctrl(struct dvb_frontend *fe, int onoff)
  1113. {
  1114. struct dvb_usb_device *d = fe_to_d(fe);
  1115. struct dvb_usb_adapter *adap = fe_to_adap(fe);
  1116. int ret;
  1117. u8 val;
  1118. dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
  1119. /* control internal demod ADC */
  1120. if (fe->id == 0 && onoff)
  1121. val = 0x48; /* enable ADC */
  1122. else
  1123. val = 0x00; /* disable ADC */
  1124. ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48);
  1125. if (ret)
  1126. goto err;
  1127. /* bypass slave demod TS through master demod */
  1128. if (fe->id == 1 && onoff) {
  1129. ret = rtl2832_enable_external_ts_if(adap->fe[0]);
  1130. if (ret)
  1131. goto err;
  1132. }
  1133. return 0;
  1134. err:
  1135. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  1136. return ret;
  1137. }
  1138. #if IS_ENABLED(CONFIG_RC_CORE)
  1139. static int rtl2831u_rc_query(struct dvb_usb_device *d)
  1140. {
  1141. int ret, i;
  1142. struct rtl28xxu_priv *priv = d->priv;
  1143. u8 buf[5];
  1144. u32 rc_code;
  1145. struct rtl28xxu_reg_val rc_nec_tab[] = {
  1146. { 0x3033, 0x80 },
  1147. { 0x3020, 0x43 },
  1148. { 0x3021, 0x16 },
  1149. { 0x3022, 0x16 },
  1150. { 0x3023, 0x5a },
  1151. { 0x3024, 0x2d },
  1152. { 0x3025, 0x16 },
  1153. { 0x3026, 0x01 },
  1154. { 0x3028, 0xb0 },
  1155. { 0x3029, 0x04 },
  1156. { 0x302c, 0x88 },
  1157. { 0x302e, 0x13 },
  1158. { 0x3030, 0xdf },
  1159. { 0x3031, 0x05 },
  1160. };
  1161. /* init remote controller */
  1162. if (!priv->rc_active) {
  1163. for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
  1164. ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
  1165. rc_nec_tab[i].val);
  1166. if (ret)
  1167. goto err;
  1168. }
  1169. priv->rc_active = true;
  1170. }
  1171. ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
  1172. if (ret)
  1173. goto err;
  1174. if (buf[4] & 0x01) {
  1175. if (buf[2] == (u8) ~buf[3]) {
  1176. if (buf[0] == (u8) ~buf[1]) {
  1177. /* NEC standard (16 bit) */
  1178. rc_code = RC_SCANCODE_NEC(buf[0], buf[2]);
  1179. } else {
  1180. /* NEC extended (24 bit) */
  1181. rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1],
  1182. buf[2]);
  1183. }
  1184. } else {
  1185. /* NEC full (32 bit) */
  1186. rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 |
  1187. buf[2] << 8 | buf[3]);
  1188. }
  1189. rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0);
  1190. ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
  1191. if (ret)
  1192. goto err;
  1193. /* repeated intentionally to avoid extra keypress */
  1194. ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
  1195. if (ret)
  1196. goto err;
  1197. }
  1198. return ret;
  1199. err:
  1200. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  1201. return ret;
  1202. }
  1203. static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
  1204. struct dvb_usb_rc *rc)
  1205. {
  1206. rc->map_name = RC_MAP_EMPTY;
  1207. rc->allowed_protos = RC_BIT_NEC;
  1208. rc->query = rtl2831u_rc_query;
  1209. rc->interval = 400;
  1210. return 0;
  1211. }
  1212. static int rtl2832u_rc_query(struct dvb_usb_device *d)
  1213. {
  1214. int ret, i, len;
  1215. struct rtl28xxu_priv *priv = d->priv;
  1216. struct ir_raw_event ev;
  1217. u8 buf[128];
  1218. static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
  1219. {IR_RX_IF, 0x03, 0xff},
  1220. {IR_RX_BUF_CTRL, 0x80, 0xff},
  1221. {IR_RX_CTRL, 0x80, 0xff},
  1222. };
  1223. /* init remote controller */
  1224. if (!priv->rc_active) {
  1225. static const struct rtl28xxu_reg_val_mask init_tab[] = {
  1226. {SYS_DEMOD_CTL1, 0x00, 0x04},
  1227. {SYS_DEMOD_CTL1, 0x00, 0x08},
  1228. {USB_CTRL, 0x20, 0x20},
  1229. {SYS_GPIO_DIR, 0x00, 0x08},
  1230. {SYS_GPIO_OUT_EN, 0x08, 0x08},
  1231. {SYS_GPIO_OUT_VAL, 0x08, 0x08},
  1232. {IR_MAX_DURATION0, 0xd0, 0xff},
  1233. {IR_MAX_DURATION1, 0x07, 0xff},
  1234. {IR_IDLE_LEN0, 0xc0, 0xff},
  1235. {IR_IDLE_LEN1, 0x00, 0xff},
  1236. {IR_GLITCH_LEN, 0x03, 0xff},
  1237. {IR_RX_CLK, 0x09, 0xff},
  1238. {IR_RX_CFG, 0x1c, 0xff},
  1239. {IR_MAX_H_TOL_LEN, 0x1e, 0xff},
  1240. {IR_MAX_L_TOL_LEN, 0x1e, 0xff},
  1241. {IR_RX_CTRL, 0x80, 0xff},
  1242. };
  1243. for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
  1244. ret = rtl28xx_wr_reg_mask(d, init_tab[i].reg,
  1245. init_tab[i].val, init_tab[i].mask);
  1246. if (ret)
  1247. goto err;
  1248. }
  1249. priv->rc_active = true;
  1250. }
  1251. ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
  1252. if (ret)
  1253. goto err;
  1254. if (buf[0] != 0x83)
  1255. goto exit;
  1256. ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
  1257. if (ret)
  1258. goto err;
  1259. len = buf[0];
  1260. /* read raw code from hw */
  1261. ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
  1262. if (ret)
  1263. goto err;
  1264. /* let hw receive new code */
  1265. for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
  1266. ret = rtl28xx_wr_reg_mask(d, refresh_tab[i].reg,
  1267. refresh_tab[i].val, refresh_tab[i].mask);
  1268. if (ret)
  1269. goto err;
  1270. }
  1271. /* pass data to Kernel IR decoder */
  1272. init_ir_raw_event(&ev);
  1273. for (i = 0; i < len; i++) {
  1274. ev.pulse = buf[i] >> 7;
  1275. ev.duration = 50800 * (buf[i] & 0x7f);
  1276. ir_raw_event_store_with_filter(d->rc_dev, &ev);
  1277. }
  1278. /* 'flush' ir_raw_event_store_with_filter() */
  1279. ir_raw_event_set_idle(d->rc_dev, true);
  1280. ir_raw_event_handle(d->rc_dev);
  1281. exit:
  1282. return ret;
  1283. err:
  1284. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
  1285. return ret;
  1286. }
  1287. static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
  1288. struct dvb_usb_rc *rc)
  1289. {
  1290. /* disable IR interrupts in order to avoid SDR sample loss */
  1291. if (rtl28xxu_disable_rc)
  1292. return rtl28xx_wr_reg(d, IR_RX_IE, 0x00);
  1293. /* load empty to enable rc */
  1294. if (!rc->map_name)
  1295. rc->map_name = RC_MAP_EMPTY;
  1296. rc->allowed_protos = RC_BIT_ALL;
  1297. rc->driver_type = RC_DRIVER_IR_RAW;
  1298. rc->query = rtl2832u_rc_query;
  1299. rc->interval = 400;
  1300. return 0;
  1301. }
  1302. #else
  1303. #define rtl2831u_get_rc_config NULL
  1304. #define rtl2832u_get_rc_config NULL
  1305. #endif
  1306. static const struct dvb_usb_device_properties rtl2831u_props = {
  1307. .driver_name = KBUILD_MODNAME,
  1308. .owner = THIS_MODULE,
  1309. .adapter_nr = adapter_nr,
  1310. .size_of_priv = sizeof(struct rtl28xxu_priv),
  1311. .power_ctrl = rtl2831u_power_ctrl,
  1312. .i2c_algo = &rtl28xxu_i2c_algo,
  1313. .read_config = rtl2831u_read_config,
  1314. .frontend_attach = rtl2831u_frontend_attach,
  1315. .tuner_attach = rtl2831u_tuner_attach,
  1316. .init = rtl28xxu_init,
  1317. .get_rc_config = rtl2831u_get_rc_config,
  1318. .num_adapters = 1,
  1319. .adapter = {
  1320. {
  1321. .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
  1322. },
  1323. },
  1324. };
  1325. static const struct dvb_usb_device_properties rtl2832u_props = {
  1326. .driver_name = KBUILD_MODNAME,
  1327. .owner = THIS_MODULE,
  1328. .adapter_nr = adapter_nr,
  1329. .size_of_priv = sizeof(struct rtl28xxu_priv),
  1330. .power_ctrl = rtl2832u_power_ctrl,
  1331. .frontend_ctrl = rtl2832u_frontend_ctrl,
  1332. .i2c_algo = &rtl28xxu_i2c_algo,
  1333. .read_config = rtl2832u_read_config,
  1334. .frontend_attach = rtl2832u_frontend_attach,
  1335. .tuner_attach = rtl2832u_tuner_attach,
  1336. .init = rtl28xxu_init,
  1337. .exit = rtl28xxu_exit,
  1338. .get_rc_config = rtl2832u_get_rc_config,
  1339. .num_adapters = 1,
  1340. .adapter = {
  1341. {
  1342. .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
  1343. },
  1344. },
  1345. };
  1346. static const struct usb_device_id rtl28xxu_id_table[] = {
  1347. /* RTL2831U devices: */
  1348. { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
  1349. &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
  1350. { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
  1351. &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
  1352. { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
  1353. &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
  1354. /* RTL2832U devices: */
  1355. { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
  1356. &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
  1357. { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
  1358. &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
  1359. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
  1360. &rtl2832u_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
  1361. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
  1362. &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
  1363. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
  1364. &rtl2832u_props, "TerraTec NOXON DAB Stick", NULL) },
  1365. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
  1366. &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
  1367. { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3,
  1368. &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) },
  1369. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
  1370. &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
  1371. { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
  1372. &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) },
  1373. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680,
  1374. &rtl2832u_props, "DigitalNow Quad DVB-T Receiver", NULL) },
  1375. { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID,
  1376. &rtl2832u_props, "Leadtek Winfast DTV Dongle Mini D", NULL) },
  1377. { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3,
  1378. &rtl2832u_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) },
  1379. { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102,
  1380. &rtl2832u_props, "Dexatek DK mini DVB-T Dongle", NULL) },
  1381. { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
  1382. &rtl2832u_props, "TerraTec Cinergy T Stick+", NULL) },
  1383. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
  1384. &rtl2832u_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
  1385. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
  1386. &rtl2832u_props, "GIGABYTE U7300", NULL) },
  1387. { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
  1388. &rtl2832u_props, "MSI DIGIVOX Micro HD", NULL) },
  1389. { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
  1390. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  1391. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  1392. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  1393. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  1394. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  1395. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  1396. &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
  1397. { DVB_USB_DEVICE(USB_VID_KYE, 0x707f,
  1398. &rtl2832u_props, "Genius TVGo DVB-T03", NULL) },
  1399. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395,
  1400. &rtl2832u_props, "Peak DVB-T USB", NULL) },
  1401. { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U,
  1402. &rtl2832u_props, "Sveon STV20", NULL) },
  1403. { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21,
  1404. &rtl2832u_props, "Sveon STV21", NULL) },
  1405. { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27,
  1406. &rtl2832u_props, "Sveon STV27", NULL) },
  1407. /* RTL2832P devices: */
  1408. { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
  1409. &rtl2832u_props, "Astrometa DVB-T2", NULL) },
  1410. { }
  1411. };
  1412. MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
  1413. static struct usb_driver rtl28xxu_usb_driver = {
  1414. .name = KBUILD_MODNAME,
  1415. .id_table = rtl28xxu_id_table,
  1416. .probe = dvb_usbv2_probe,
  1417. .disconnect = dvb_usbv2_disconnect,
  1418. .suspend = dvb_usbv2_suspend,
  1419. .resume = dvb_usbv2_resume,
  1420. .reset_resume = dvb_usbv2_reset_resume,
  1421. .no_dynamic_id = 1,
  1422. .soft_unbind = 1,
  1423. };
  1424. module_usb_driver(rtl28xxu_usb_driver);
  1425. MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
  1426. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  1427. MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
  1428. MODULE_LICENSE("GPL");