af9015.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  1. /*
  2. * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
  3. *
  4. * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
  5. *
  6. * Thanks to Afatech who kindly provided information.
  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
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. */
  23. #include <linux/hash.h>
  24. #include <linux/slab.h>
  25. #include "af9015.h"
  26. #include "af9013.h"
  27. #include "mt2060.h"
  28. #include "qt1010.h"
  29. #include "tda18271.h"
  30. #include "mxl5005s.h"
  31. #include "mc44s803.h"
  32. #include "tda18218.h"
  33. #include "mxl5007t.h"
  34. static int dvb_usb_af9015_debug;
  35. module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
  36. MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
  37. static int dvb_usb_af9015_remote;
  38. module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
  39. MODULE_PARM_DESC(remote, "select remote");
  40. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  41. static DEFINE_MUTEX(af9015_usb_mutex);
  42. static struct af9015_config af9015_config;
  43. static struct dvb_usb_device_properties af9015_properties[3];
  44. static int af9015_properties_count = ARRAY_SIZE(af9015_properties);
  45. static struct af9013_config af9015_af9013_config[] = {
  46. {
  47. .demod_address = AF9015_I2C_DEMOD,
  48. .output_mode = AF9013_OUTPUT_MODE_USB,
  49. .api_version = { 0, 1, 9, 0 },
  50. .gpio[0] = AF9013_GPIO_HI,
  51. .gpio[3] = AF9013_GPIO_TUNER_ON,
  52. }, {
  53. .output_mode = AF9013_OUTPUT_MODE_SERIAL,
  54. .api_version = { 0, 1, 9, 0 },
  55. .gpio[0] = AF9013_GPIO_TUNER_ON,
  56. .gpio[1] = AF9013_GPIO_LO,
  57. }
  58. };
  59. static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
  60. {
  61. #define BUF_LEN 63
  62. #define REQ_HDR_LEN 8 /* send header size */
  63. #define ACK_HDR_LEN 2 /* rece header size */
  64. int act_len, ret;
  65. u8 buf[BUF_LEN];
  66. u8 write = 1;
  67. u8 msg_len = REQ_HDR_LEN;
  68. static u8 seq; /* packet sequence number */
  69. if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
  70. return -EAGAIN;
  71. buf[0] = req->cmd;
  72. buf[1] = seq++;
  73. buf[2] = req->i2c_addr;
  74. buf[3] = req->addr >> 8;
  75. buf[4] = req->addr & 0xff;
  76. buf[5] = req->mbox;
  77. buf[6] = req->addr_len;
  78. buf[7] = req->data_len;
  79. switch (req->cmd) {
  80. case GET_CONFIG:
  81. case READ_MEMORY:
  82. case RECONNECT_USB:
  83. case GET_IR_CODE:
  84. write = 0;
  85. break;
  86. case READ_I2C:
  87. write = 0;
  88. buf[2] |= 0x01; /* set I2C direction */
  89. case WRITE_I2C:
  90. buf[0] = READ_WRITE_I2C;
  91. break;
  92. case WRITE_MEMORY:
  93. if (((req->addr & 0xff00) == 0xff00) ||
  94. ((req->addr & 0xff00) == 0xae00))
  95. buf[0] = WRITE_VIRTUAL_MEMORY;
  96. case WRITE_VIRTUAL_MEMORY:
  97. case COPY_FIRMWARE:
  98. case DOWNLOAD_FIRMWARE:
  99. case BOOT:
  100. break;
  101. default:
  102. err("unknown command:%d", req->cmd);
  103. ret = -1;
  104. goto error_unlock;
  105. }
  106. /* buffer overflow check */
  107. if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
  108. (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
  109. err("too much data; cmd:%d len:%d", req->cmd, req->data_len);
  110. ret = -EINVAL;
  111. goto error_unlock;
  112. }
  113. /* write requested */
  114. if (write) {
  115. memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len);
  116. msg_len += req->data_len;
  117. }
  118. deb_xfer(">>> ");
  119. debug_dump(buf, msg_len, deb_xfer);
  120. /* send req */
  121. ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
  122. &act_len, AF9015_USB_TIMEOUT);
  123. if (ret)
  124. err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
  125. else
  126. if (act_len != msg_len)
  127. ret = -1; /* all data is not send */
  128. if (ret)
  129. goto error_unlock;
  130. /* no ack for those packets */
  131. if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
  132. goto exit_unlock;
  133. /* write receives seq + status = 2 bytes
  134. read receives seq + status + data = 2 + N bytes */
  135. msg_len = ACK_HDR_LEN;
  136. if (!write)
  137. msg_len += req->data_len;
  138. ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
  139. &act_len, AF9015_USB_TIMEOUT);
  140. if (ret) {
  141. err("recv bulk message failed:%d", ret);
  142. ret = -1;
  143. goto error_unlock;
  144. }
  145. deb_xfer("<<< ");
  146. debug_dump(buf, act_len, deb_xfer);
  147. /* remote controller query status is 1 if remote code is not received */
  148. if (req->cmd == GET_IR_CODE && buf[1] == 1) {
  149. buf[1] = 0; /* clear command "error" status */
  150. memset(&buf[2], 0, req->data_len);
  151. buf[3] = 1; /* no remote code received mark */
  152. }
  153. /* check status */
  154. if (buf[1]) {
  155. err("command failed:%d", buf[1]);
  156. ret = -1;
  157. goto error_unlock;
  158. }
  159. /* read request, copy returned data to return buf */
  160. if (!write)
  161. memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);
  162. error_unlock:
  163. exit_unlock:
  164. mutex_unlock(&af9015_usb_mutex);
  165. return ret;
  166. }
  167. static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
  168. {
  169. return af9015_rw_udev(d->udev, req);
  170. }
  171. static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
  172. u8 len)
  173. {
  174. struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
  175. val};
  176. return af9015_ctrl_msg(d, &req);
  177. }
  178. static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
  179. {
  180. return af9015_write_regs(d, addr, &val, 1);
  181. }
  182. static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len)
  183. {
  184. struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
  185. val};
  186. return af9015_ctrl_msg(d, &req);
  187. }
  188. static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
  189. {
  190. return af9015_read_regs(d, addr, val, 1);
  191. }
  192. static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
  193. u8 val)
  194. {
  195. struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
  196. if (addr == af9015_af9013_config[0].demod_address ||
  197. addr == af9015_af9013_config[1].demod_address)
  198. req.addr_len = 3;
  199. return af9015_ctrl_msg(d, &req);
  200. }
  201. static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
  202. u8 *val)
  203. {
  204. struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
  205. if (addr == af9015_af9013_config[0].demod_address ||
  206. addr == af9015_af9013_config[1].demod_address)
  207. req.addr_len = 3;
  208. return af9015_ctrl_msg(d, &req);
  209. }
  210. static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  211. int num)
  212. {
  213. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  214. int ret = 0, i = 0;
  215. u16 addr;
  216. u8 uninitialized_var(mbox), addr_len;
  217. struct req_t req;
  218. /* TODO: implement bus lock
  219. The bus lock is needed because there is two tuners both using same I2C-address.
  220. Due to that the only way to select correct tuner is use demodulator I2C-gate.
  221. ................................................
  222. . AF9015 includes integrated AF9013 demodulator.
  223. . ____________ ____________ . ____________
  224. .| uC | | demod | . | tuner |
  225. .|------------| |------------| . |------------|
  226. .| AF9015 | | AF9013/5 | . | MXL5003 |
  227. .| |--+----I2C-------|-----/ -----|-.-----I2C-------| |
  228. .| | | | addr 0x38 | . | addr 0xc6 |
  229. .|____________| | |____________| . |____________|
  230. .................|..............................
  231. | ____________ ____________
  232. | | demod | | tuner |
  233. | |------------| |------------|
  234. | | AF9013 | | MXL5003 |
  235. +----I2C-------|-----/ -----|-------I2C-------| |
  236. | addr 0x3a | | addr 0xc6 |
  237. |____________| |____________|
  238. */
  239. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  240. return -EAGAIN;
  241. while (i < num) {
  242. if (msg[i].addr == af9015_af9013_config[0].demod_address ||
  243. msg[i].addr == af9015_af9013_config[1].demod_address) {
  244. addr = msg[i].buf[0] << 8;
  245. addr += msg[i].buf[1];
  246. mbox = msg[i].buf[2];
  247. addr_len = 3;
  248. } else {
  249. addr = msg[i].buf[0];
  250. addr_len = 1;
  251. /* mbox is don't care in that case */
  252. }
  253. if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
  254. if (msg[i].addr ==
  255. af9015_af9013_config[0].demod_address)
  256. req.cmd = READ_MEMORY;
  257. else
  258. req.cmd = READ_I2C;
  259. req.i2c_addr = msg[i].addr;
  260. req.addr = addr;
  261. req.mbox = mbox;
  262. req.addr_len = addr_len;
  263. req.data_len = msg[i+1].len;
  264. req.data = &msg[i+1].buf[0];
  265. ret = af9015_ctrl_msg(d, &req);
  266. i += 2;
  267. } else if (msg[i].flags & I2C_M_RD) {
  268. ret = -EINVAL;
  269. if (msg[i].addr ==
  270. af9015_af9013_config[0].demod_address)
  271. goto error;
  272. else
  273. req.cmd = READ_I2C;
  274. req.i2c_addr = msg[i].addr;
  275. req.addr = addr;
  276. req.mbox = mbox;
  277. req.addr_len = addr_len;
  278. req.data_len = msg[i].len;
  279. req.data = &msg[i].buf[0];
  280. ret = af9015_ctrl_msg(d, &req);
  281. i += 1;
  282. } else {
  283. if (msg[i].addr ==
  284. af9015_af9013_config[0].demod_address)
  285. req.cmd = WRITE_MEMORY;
  286. else
  287. req.cmd = WRITE_I2C;
  288. req.i2c_addr = msg[i].addr;
  289. req.addr = addr;
  290. req.mbox = mbox;
  291. req.addr_len = addr_len;
  292. req.data_len = msg[i].len-addr_len;
  293. req.data = &msg[i].buf[addr_len];
  294. ret = af9015_ctrl_msg(d, &req);
  295. i += 1;
  296. }
  297. if (ret)
  298. goto error;
  299. }
  300. ret = i;
  301. error:
  302. mutex_unlock(&d->i2c_mutex);
  303. return ret;
  304. }
  305. static u32 af9015_i2c_func(struct i2c_adapter *adapter)
  306. {
  307. return I2C_FUNC_I2C;
  308. }
  309. static struct i2c_algorithm af9015_i2c_algo = {
  310. .master_xfer = af9015_i2c_xfer,
  311. .functionality = af9015_i2c_func,
  312. };
  313. static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
  314. {
  315. int ret;
  316. u8 val, mask = 0x01;
  317. ret = af9015_read_reg(d, addr, &val);
  318. if (ret)
  319. return ret;
  320. mask <<= bit;
  321. if (op) {
  322. /* set bit */
  323. val |= mask;
  324. } else {
  325. /* clear bit */
  326. mask ^= 0xff;
  327. val &= mask;
  328. }
  329. return af9015_write_reg(d, addr, val);
  330. }
  331. static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
  332. {
  333. return af9015_do_reg_bit(d, addr, bit, 1);
  334. }
  335. static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
  336. {
  337. return af9015_do_reg_bit(d, addr, bit, 0);
  338. }
  339. static int af9015_init_endpoint(struct dvb_usb_device *d)
  340. {
  341. int ret;
  342. u16 frame_size;
  343. u8 packet_size;
  344. deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);
  345. /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0.
  346. We use smaller - about 1/4 from the original, 5 and 87. */
  347. #define TS_PACKET_SIZE 188
  348. #define TS_USB20_PACKET_COUNT 87
  349. #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
  350. #define TS_USB11_PACKET_COUNT 5
  351. #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
  352. #define TS_USB20_MAX_PACKET_SIZE 512
  353. #define TS_USB11_MAX_PACKET_SIZE 64
  354. if (d->udev->speed == USB_SPEED_FULL) {
  355. frame_size = TS_USB11_FRAME_SIZE/4;
  356. packet_size = TS_USB11_MAX_PACKET_SIZE/4;
  357. } else {
  358. frame_size = TS_USB20_FRAME_SIZE/4;
  359. packet_size = TS_USB20_MAX_PACKET_SIZE/4;
  360. }
  361. ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
  362. if (ret)
  363. goto error;
  364. ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
  365. if (ret)
  366. goto error;
  367. ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
  368. if (ret)
  369. goto error;
  370. ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
  371. if (ret)
  372. goto error;
  373. ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
  374. if (ret)
  375. goto error;
  376. if (af9015_config.dual_mode) {
  377. ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
  378. if (ret)
  379. goto error;
  380. }
  381. ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
  382. if (ret)
  383. goto error;
  384. if (af9015_config.dual_mode) {
  385. ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
  386. if (ret)
  387. goto error;
  388. }
  389. /* EP4 xfer length */
  390. ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
  391. if (ret)
  392. goto error;
  393. ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
  394. if (ret)
  395. goto error;
  396. /* EP5 xfer length */
  397. ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
  398. if (ret)
  399. goto error;
  400. ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
  401. if (ret)
  402. goto error;
  403. ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
  404. if (ret)
  405. goto error;
  406. ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
  407. if (ret)
  408. goto error;
  409. ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
  410. if (ret)
  411. goto error;
  412. if (af9015_config.dual_mode) {
  413. ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
  414. if (ret)
  415. goto error;
  416. }
  417. /* enable / disable mp2if2 */
  418. if (af9015_config.dual_mode)
  419. ret = af9015_set_reg_bit(d, 0xd50b, 0);
  420. else
  421. ret = af9015_clear_reg_bit(d, 0xd50b, 0);
  422. error:
  423. if (ret)
  424. err("endpoint init failed:%d", ret);
  425. return ret;
  426. }
  427. static int af9015_copy_firmware(struct dvb_usb_device *d)
  428. {
  429. int ret;
  430. u8 fw_params[4];
  431. u8 val, i;
  432. struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
  433. fw_params };
  434. deb_info("%s:\n", __func__);
  435. fw_params[0] = af9015_config.firmware_size >> 8;
  436. fw_params[1] = af9015_config.firmware_size & 0xff;
  437. fw_params[2] = af9015_config.firmware_checksum >> 8;
  438. fw_params[3] = af9015_config.firmware_checksum & 0xff;
  439. /* wait 2nd demodulator ready */
  440. msleep(100);
  441. ret = af9015_read_reg_i2c(d,
  442. af9015_af9013_config[1].demod_address, 0x98be, &val);
  443. if (ret)
  444. goto error;
  445. else
  446. deb_info("%s: firmware status:%02x\n", __func__, val);
  447. if (val == 0x0c) /* fw is running, no need for download */
  448. goto exit;
  449. /* set I2C master clock to fast (to speed up firmware copy) */
  450. ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
  451. if (ret)
  452. goto error;
  453. msleep(50);
  454. /* copy firmware */
  455. ret = af9015_ctrl_msg(d, &req);
  456. if (ret)
  457. err("firmware copy cmd failed:%d", ret);
  458. deb_info("%s: firmware copy done\n", __func__);
  459. /* set I2C master clock back to normal */
  460. ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
  461. if (ret)
  462. goto error;
  463. /* request boot firmware */
  464. ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,
  465. 0xe205, 1);
  466. deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
  467. if (ret)
  468. goto error;
  469. for (i = 0; i < 15; i++) {
  470. msleep(100);
  471. /* check firmware status */
  472. ret = af9015_read_reg_i2c(d,
  473. af9015_af9013_config[1].demod_address, 0x98be, &val);
  474. deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
  475. __func__, ret, val);
  476. if (ret)
  477. goto error;
  478. if (val == 0x0c || val == 0x04) /* success or fail */
  479. break;
  480. }
  481. if (val == 0x04) {
  482. err("firmware did not run");
  483. ret = -1;
  484. } else if (val != 0x0c) {
  485. err("firmware boot timeout");
  486. ret = -1;
  487. }
  488. error:
  489. exit:
  490. return ret;
  491. }
  492. /* hash (and dump) eeprom */
  493. static int af9015_eeprom_hash(struct usb_device *udev)
  494. {
  495. static const unsigned int eeprom_size = 256;
  496. unsigned int reg;
  497. int ret;
  498. u8 val, *eeprom;
  499. struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
  500. eeprom = kmalloc(eeprom_size, GFP_KERNEL);
  501. if (eeprom == NULL)
  502. return -ENOMEM;
  503. for (reg = 0; reg < eeprom_size; reg++) {
  504. req.addr = reg;
  505. ret = af9015_rw_udev(udev, &req);
  506. if (ret)
  507. goto free;
  508. eeprom[reg] = val;
  509. }
  510. if (dvb_usb_af9015_debug & 0x01)
  511. print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom,
  512. eeprom_size);
  513. BUG_ON(eeprom_size % 4);
  514. af9015_config.eeprom_sum = 0;
  515. for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
  516. af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32;
  517. af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]);
  518. }
  519. deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum);
  520. ret = 0;
  521. free:
  522. kfree(eeprom);
  523. return ret;
  524. }
  525. static int af9015_init(struct dvb_usb_device *d)
  526. {
  527. int ret;
  528. deb_info("%s:\n", __func__);
  529. /* init RC canary */
  530. ret = af9015_write_reg(d, 0x98e9, 0xff);
  531. if (ret)
  532. goto error;
  533. ret = af9015_init_endpoint(d);
  534. if (ret)
  535. goto error;
  536. error:
  537. return ret;
  538. }
  539. static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
  540. {
  541. int ret;
  542. deb_info("%s: onoff:%d\n", __func__, onoff);
  543. if (onoff)
  544. ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);
  545. else
  546. ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);
  547. return ret;
  548. }
  549. static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
  550. int onoff)
  551. {
  552. int ret;
  553. u8 idx;
  554. deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",
  555. __func__, index, pid, onoff);
  556. ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));
  557. if (ret)
  558. goto error;
  559. ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));
  560. if (ret)
  561. goto error;
  562. idx = ((index & 0x1f) | (1 << 5));
  563. ret = af9015_write_reg(adap->dev, 0xd504, idx);
  564. error:
  565. return ret;
  566. }
  567. static int af9015_download_firmware(struct usb_device *udev,
  568. const struct firmware *fw)
  569. {
  570. int i, len, remaining, ret;
  571. struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
  572. u16 checksum = 0;
  573. deb_info("%s:\n", __func__);
  574. /* calc checksum */
  575. for (i = 0; i < fw->size; i++)
  576. checksum += fw->data[i];
  577. af9015_config.firmware_size = fw->size;
  578. af9015_config.firmware_checksum = checksum;
  579. #define FW_ADDR 0x5100 /* firmware start address */
  580. #define LEN_MAX 55 /* max packet size */
  581. for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
  582. len = remaining;
  583. if (len > LEN_MAX)
  584. len = LEN_MAX;
  585. req.data_len = len;
  586. req.data = (u8 *) &fw->data[fw->size - remaining];
  587. req.addr = FW_ADDR + fw->size - remaining;
  588. ret = af9015_rw_udev(udev, &req);
  589. if (ret) {
  590. err("firmware download failed:%d", ret);
  591. goto error;
  592. }
  593. }
  594. /* firmware loaded, request boot */
  595. req.cmd = BOOT;
  596. ret = af9015_rw_udev(udev, &req);
  597. if (ret) {
  598. err("firmware boot failed:%d", ret);
  599. goto error;
  600. }
  601. error:
  602. return ret;
  603. }
  604. struct af9015_rc_setup {
  605. unsigned int id;
  606. char *rc_codes;
  607. };
  608. static char *af9015_rc_setup_match(unsigned int id,
  609. const struct af9015_rc_setup *table)
  610. {
  611. for (; table->rc_codes; table++)
  612. if (table->id == id)
  613. return table->rc_codes;
  614. return NULL;
  615. }
  616. static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
  617. { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },
  618. { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },
  619. { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },
  620. { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },
  621. { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },
  622. { }
  623. };
  624. static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
  625. { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
  626. { 0xa3703d00, RC_MAP_ALINK_DTU_M },
  627. { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
  628. { }
  629. };
  630. static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {
  631. { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_RC,
  632. RC_MAP_TERRATEC_SLIM_2 },
  633. { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
  634. RC_MAP_TERRATEC_SLIM },
  635. { (USB_VID_VISIONPLUS << 16) + USB_PID_AZUREWAVE_AD_TU700,
  636. RC_MAP_AZUREWAVE_AD_TU700 },
  637. { (USB_VID_VISIONPLUS << 16) + USB_PID_TINYTWIN,
  638. RC_MAP_AZUREWAVE_AD_TU700 },
  639. { (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGI_VOX_MINI_III,
  640. RC_MAP_MSI_DIGIVOX_III },
  641. { (USB_VID_LEADTEK << 16) + USB_PID_WINFAST_DTV_DONGLE_GOLD,
  642. RC_MAP_LEADTEK_Y04G0051 },
  643. { (USB_VID_AVERMEDIA << 16) + USB_PID_AVERMEDIA_VOLAR_X,
  644. RC_MAP_AVERMEDIA_M135A },
  645. { (USB_VID_AFATECH << 16) + USB_PID_TREKSTOR_DVBT,
  646. RC_MAP_TREKSTOR },
  647. { (USB_VID_KWORLD_2 << 16) + USB_PID_TINYTWIN_2,
  648. RC_MAP_DIGITALNOW_TINYTWIN },
  649. { (USB_VID_GTEK << 16) + USB_PID_TINYTWIN_3,
  650. RC_MAP_DIGITALNOW_TINYTWIN },
  651. { }
  652. };
  653. static void af9015_set_remote_config(struct usb_device *udev,
  654. struct dvb_usb_device_properties *props)
  655. {
  656. u16 vid = le16_to_cpu(udev->descriptor.idVendor);
  657. u16 pid = le16_to_cpu(udev->descriptor.idProduct);
  658. /* try to load remote based module param */
  659. props->rc.core.rc_codes = af9015_rc_setup_match(
  660. dvb_usb_af9015_remote, af9015_rc_setup_modparam);
  661. /* try to load remote based eeprom hash */
  662. if (!props->rc.core.rc_codes)
  663. props->rc.core.rc_codes = af9015_rc_setup_match(
  664. af9015_config.eeprom_sum, af9015_rc_setup_hashes);
  665. /* try to load remote based USB ID */
  666. if (!props->rc.core.rc_codes)
  667. props->rc.core.rc_codes = af9015_rc_setup_match(
  668. (vid << 16) + pid, af9015_rc_setup_usbids);
  669. /* try to load remote based USB iManufacturer string */
  670. if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) {
  671. /* Check USB manufacturer and product strings and try
  672. to determine correct remote in case of chip vendor
  673. reference IDs are used.
  674. DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */
  675. char manufacturer[10];
  676. memset(manufacturer, 0, sizeof(manufacturer));
  677. usb_string(udev, udev->descriptor.iManufacturer,
  678. manufacturer, sizeof(manufacturer));
  679. if (!strcmp("MSI", manufacturer)) {
  680. /* iManufacturer 1 MSI
  681. iProduct 2 MSI K-VOX */
  682. props->rc.core.rc_codes = af9015_rc_setup_match(
  683. AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
  684. af9015_rc_setup_modparam);
  685. }
  686. }
  687. /* finally load "empty" just for leaving IR receiver enabled */
  688. if (!props->rc.core.rc_codes)
  689. props->rc.core.rc_codes = RC_MAP_EMPTY;
  690. return;
  691. }
  692. static int af9015_read_config(struct usb_device *udev)
  693. {
  694. int ret;
  695. u8 val, i, offset = 0;
  696. struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
  697. /* IR remote controller */
  698. req.addr = AF9015_EEPROM_IR_MODE;
  699. /* first message will timeout often due to possible hw bug */
  700. for (i = 0; i < 4; i++) {
  701. ret = af9015_rw_udev(udev, &req);
  702. if (!ret)
  703. break;
  704. }
  705. if (ret)
  706. goto error;
  707. ret = af9015_eeprom_hash(udev);
  708. if (ret)
  709. goto error;
  710. deb_info("%s: IR mode:%d\n", __func__, val);
  711. for (i = 0; i < af9015_properties_count; i++) {
  712. if (val == AF9015_IR_MODE_DISABLED)
  713. af9015_properties[i].rc.core.rc_codes = NULL;
  714. else
  715. af9015_set_remote_config(udev, &af9015_properties[i]);
  716. }
  717. /* TS mode - one or two receivers */
  718. req.addr = AF9015_EEPROM_TS_MODE;
  719. ret = af9015_rw_udev(udev, &req);
  720. if (ret)
  721. goto error;
  722. af9015_config.dual_mode = val;
  723. deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);
  724. /* Set adapter0 buffer size according to USB port speed, adapter1 buffer
  725. size can be static because it is enabled only USB2.0 */
  726. for (i = 0; i < af9015_properties_count; i++) {
  727. /* USB1.1 set smaller buffersize and disable 2nd adapter */
  728. if (udev->speed == USB_SPEED_FULL) {
  729. af9015_properties[i].adapter[0].stream.u.bulk.buffersize
  730. = TS_USB11_FRAME_SIZE;
  731. /* disable 2nd adapter because we don't have
  732. PID-filters */
  733. af9015_config.dual_mode = 0;
  734. } else {
  735. af9015_properties[i].adapter[0].stream.u.bulk.buffersize
  736. = TS_USB20_FRAME_SIZE;
  737. }
  738. }
  739. if (af9015_config.dual_mode) {
  740. /* read 2nd demodulator I2C address */
  741. req.addr = AF9015_EEPROM_DEMOD2_I2C;
  742. ret = af9015_rw_udev(udev, &req);
  743. if (ret)
  744. goto error;
  745. af9015_af9013_config[1].demod_address = val;
  746. /* enable 2nd adapter */
  747. for (i = 0; i < af9015_properties_count; i++)
  748. af9015_properties[i].num_adapters = 2;
  749. } else {
  750. /* disable 2nd adapter */
  751. for (i = 0; i < af9015_properties_count; i++)
  752. af9015_properties[i].num_adapters = 1;
  753. }
  754. for (i = 0; i < af9015_properties[0].num_adapters; i++) {
  755. if (i == 1)
  756. offset = AF9015_EEPROM_OFFSET;
  757. /* xtal */
  758. req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
  759. ret = af9015_rw_udev(udev, &req);
  760. if (ret)
  761. goto error;
  762. switch (val) {
  763. case 0:
  764. af9015_af9013_config[i].adc_clock = 28800;
  765. break;
  766. case 1:
  767. af9015_af9013_config[i].adc_clock = 20480;
  768. break;
  769. case 2:
  770. af9015_af9013_config[i].adc_clock = 28000;
  771. break;
  772. case 3:
  773. af9015_af9013_config[i].adc_clock = 25000;
  774. break;
  775. };
  776. deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i,
  777. val, af9015_af9013_config[i].adc_clock);
  778. /* tuner IF */
  779. req.addr = AF9015_EEPROM_IF1H + offset;
  780. ret = af9015_rw_udev(udev, &req);
  781. if (ret)
  782. goto error;
  783. af9015_af9013_config[i].tuner_if = val << 8;
  784. req.addr = AF9015_EEPROM_IF1L + offset;
  785. ret = af9015_rw_udev(udev, &req);
  786. if (ret)
  787. goto error;
  788. af9015_af9013_config[i].tuner_if += val;
  789. deb_info("%s: [%d] IF1:%d\n", __func__, i,
  790. af9015_af9013_config[0].tuner_if);
  791. /* MT2060 IF1 */
  792. req.addr = AF9015_EEPROM_MT2060_IF1H + offset;
  793. ret = af9015_rw_udev(udev, &req);
  794. if (ret)
  795. goto error;
  796. af9015_config.mt2060_if1[i] = val << 8;
  797. req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
  798. ret = af9015_rw_udev(udev, &req);
  799. if (ret)
  800. goto error;
  801. af9015_config.mt2060_if1[i] += val;
  802. deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i,
  803. af9015_config.mt2060_if1[i]);
  804. /* tuner */
  805. req.addr = AF9015_EEPROM_TUNER_ID1 + offset;
  806. ret = af9015_rw_udev(udev, &req);
  807. if (ret)
  808. goto error;
  809. switch (val) {
  810. case AF9013_TUNER_ENV77H11D5:
  811. case AF9013_TUNER_MT2060:
  812. case AF9013_TUNER_QT1010:
  813. case AF9013_TUNER_UNKNOWN:
  814. case AF9013_TUNER_MT2060_2:
  815. case AF9013_TUNER_TDA18271:
  816. case AF9013_TUNER_QT1010A:
  817. case AF9013_TUNER_TDA18218:
  818. af9015_af9013_config[i].rf_spec_inv = 1;
  819. break;
  820. case AF9013_TUNER_MXL5003D:
  821. case AF9013_TUNER_MXL5005D:
  822. case AF9013_TUNER_MXL5005R:
  823. case AF9013_TUNER_MXL5007T:
  824. af9015_af9013_config[i].rf_spec_inv = 0;
  825. break;
  826. case AF9013_TUNER_MC44S803:
  827. af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
  828. af9015_af9013_config[i].rf_spec_inv = 1;
  829. break;
  830. default:
  831. warn("tuner id:%d not supported, please report!", val);
  832. return -ENODEV;
  833. };
  834. af9015_af9013_config[i].tuner = val;
  835. deb_info("%s: [%d] tuner id:%d\n", __func__, i, val);
  836. }
  837. error:
  838. if (ret)
  839. err("eeprom read failed:%d", ret);
  840. /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
  841. content :-( Override some wrong values here. Ditto for the
  842. AVerTV Red HD+ (A850T) device. */
  843. if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
  844. ((le16_to_cpu(udev->descriptor.idProduct) ==
  845. USB_PID_AVERMEDIA_A850) ||
  846. (le16_to_cpu(udev->descriptor.idProduct) ==
  847. USB_PID_AVERMEDIA_A850T))) {
  848. deb_info("%s: AverMedia A850: overriding config\n", __func__);
  849. /* disable dual mode */
  850. af9015_config.dual_mode = 0;
  851. /* disable 2nd adapter */
  852. for (i = 0; i < af9015_properties_count; i++)
  853. af9015_properties[i].num_adapters = 1;
  854. /* set correct IF */
  855. af9015_af9013_config[0].tuner_if = 4570;
  856. }
  857. return ret;
  858. }
  859. static int af9015_identify_state(struct usb_device *udev,
  860. struct dvb_usb_device_properties *props,
  861. struct dvb_usb_device_description **desc,
  862. int *cold)
  863. {
  864. int ret;
  865. u8 reply;
  866. struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
  867. ret = af9015_rw_udev(udev, &req);
  868. if (ret)
  869. return ret;
  870. deb_info("%s: reply:%02x\n", __func__, reply);
  871. if (reply == 0x02)
  872. *cold = 0;
  873. else
  874. *cold = 1;
  875. return ret;
  876. }
  877. static int af9015_rc_query(struct dvb_usb_device *d)
  878. {
  879. struct af9015_state *priv = d->priv;
  880. int ret;
  881. u8 buf[17];
  882. /* read registers needed to detect remote controller code */
  883. ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf));
  884. if (ret)
  885. goto error;
  886. /* If any of these are non-zero, assume invalid data */
  887. if (buf[1] || buf[2] || buf[3])
  888. return ret;
  889. /* Check for repeat of previous code */
  890. if ((priv->rc_repeat != buf[6] || buf[0]) &&
  891. !memcmp(&buf[12], priv->rc_last, 4)) {
  892. deb_rc("%s: key repeated\n", __func__);
  893. rc_keydown(d->rc_dev, priv->rc_keycode, 0);
  894. priv->rc_repeat = buf[6];
  895. return ret;
  896. }
  897. /* Only process key if canary killed */
  898. if (buf[16] != 0xff && buf[0] != 0x01) {
  899. deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__,
  900. buf[12], buf[13], buf[14], buf[15]);
  901. /* Reset the canary */
  902. ret = af9015_write_reg(d, 0x98e9, 0xff);
  903. if (ret)
  904. goto error;
  905. /* Remember this key */
  906. memcpy(priv->rc_last, &buf[12], 4);
  907. if (buf[14] == (u8) ~buf[15]) {
  908. if (buf[12] == (u8) ~buf[13]) {
  909. /* NEC */
  910. priv->rc_keycode = buf[12] << 8 | buf[14];
  911. } else {
  912. /* NEC extended*/
  913. priv->rc_keycode = buf[12] << 16 |
  914. buf[13] << 8 | buf[14];
  915. }
  916. } else {
  917. /* 32 bit NEC */
  918. priv->rc_keycode = buf[12] << 24 | buf[13] << 16 |
  919. buf[14] << 8 | buf[15];
  920. }
  921. rc_keydown(d->rc_dev, priv->rc_keycode, 0);
  922. } else {
  923. deb_rc("%s: no key press\n", __func__);
  924. /* Invalidate last keypress */
  925. /* Not really needed, but helps with debug */
  926. priv->rc_last[2] = priv->rc_last[3];
  927. }
  928. priv->rc_repeat = buf[6];
  929. error:
  930. if (ret)
  931. err("%s: failed:%d", __func__, ret);
  932. return ret;
  933. }
  934. /* init 2nd I2C adapter */
  935. static int af9015_i2c_init(struct dvb_usb_device *d)
  936. {
  937. int ret;
  938. struct af9015_state *state = d->priv;
  939. deb_info("%s:\n", __func__);
  940. strncpy(state->i2c_adap.name, d->desc->name,
  941. sizeof(state->i2c_adap.name));
  942. state->i2c_adap.algo = d->props.i2c_algo;
  943. state->i2c_adap.algo_data = NULL;
  944. state->i2c_adap.dev.parent = &d->udev->dev;
  945. i2c_set_adapdata(&state->i2c_adap, d);
  946. ret = i2c_add_adapter(&state->i2c_adap);
  947. if (ret < 0)
  948. err("could not add i2c adapter");
  949. return ret;
  950. }
  951. static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
  952. {
  953. int ret;
  954. struct af9015_state *state = adap->dev->priv;
  955. struct i2c_adapter *i2c_adap;
  956. if (adap->id == 0) {
  957. /* select I2C adapter */
  958. i2c_adap = &adap->dev->i2c_adap;
  959. deb_info("%s: init I2C\n", __func__);
  960. ret = af9015_i2c_init(adap->dev);
  961. } else {
  962. /* select I2C adapter */
  963. i2c_adap = &state->i2c_adap;
  964. /* copy firmware to 2nd demodulator */
  965. if (af9015_config.dual_mode) {
  966. ret = af9015_copy_firmware(adap->dev);
  967. if (ret) {
  968. err("firmware copy to 2nd frontend " \
  969. "failed, will disable it");
  970. af9015_config.dual_mode = 0;
  971. return -ENODEV;
  972. }
  973. } else {
  974. return -ENODEV;
  975. }
  976. }
  977. /* attach demodulator */
  978. adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
  979. i2c_adap);
  980. return adap->fe == NULL ? -ENODEV : 0;
  981. }
  982. static struct mt2060_config af9015_mt2060_config = {
  983. .i2c_address = 0xc0,
  984. .clock_out = 0,
  985. };
  986. static struct qt1010_config af9015_qt1010_config = {
  987. .i2c_address = 0xc4,
  988. };
  989. static struct tda18271_config af9015_tda18271_config = {
  990. .gate = TDA18271_GATE_DIGITAL,
  991. .small_i2c = TDA18271_16_BYTE_CHUNK_INIT,
  992. };
  993. static struct mxl5005s_config af9015_mxl5003_config = {
  994. .i2c_address = 0xc6,
  995. .if_freq = IF_FREQ_4570000HZ,
  996. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  997. .agc_mode = MXL_SINGLE_AGC,
  998. .tracking_filter = MXL_TF_DEFAULT,
  999. .rssi_enable = MXL_RSSI_ENABLE,
  1000. .cap_select = MXL_CAP_SEL_ENABLE,
  1001. .div_out = MXL_DIV_OUT_4,
  1002. .clock_out = MXL_CLOCK_OUT_DISABLE,
  1003. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  1004. .top = MXL5005S_TOP_25P2,
  1005. .mod_mode = MXL_DIGITAL_MODE,
  1006. .if_mode = MXL_ZERO_IF,
  1007. .AgcMasterByte = 0x00,
  1008. };
  1009. static struct mxl5005s_config af9015_mxl5005_config = {
  1010. .i2c_address = 0xc6,
  1011. .if_freq = IF_FREQ_4570000HZ,
  1012. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  1013. .agc_mode = MXL_SINGLE_AGC,
  1014. .tracking_filter = MXL_TF_OFF,
  1015. .rssi_enable = MXL_RSSI_ENABLE,
  1016. .cap_select = MXL_CAP_SEL_ENABLE,
  1017. .div_out = MXL_DIV_OUT_4,
  1018. .clock_out = MXL_CLOCK_OUT_DISABLE,
  1019. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  1020. .top = MXL5005S_TOP_25P2,
  1021. .mod_mode = MXL_DIGITAL_MODE,
  1022. .if_mode = MXL_ZERO_IF,
  1023. .AgcMasterByte = 0x00,
  1024. };
  1025. static struct mc44s803_config af9015_mc44s803_config = {
  1026. .i2c_address = 0xc0,
  1027. .dig_out = 1,
  1028. };
  1029. static struct tda18218_config af9015_tda18218_config = {
  1030. .i2c_address = 0xc0,
  1031. .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
  1032. };
  1033. static struct mxl5007t_config af9015_mxl5007t_config = {
  1034. .xtal_freq_hz = MxL_XTAL_24_MHZ,
  1035. .if_freq_hz = MxL_IF_4_57_MHZ,
  1036. };
  1037. static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
  1038. {
  1039. struct af9015_state *state = adap->dev->priv;
  1040. struct i2c_adapter *i2c_adap;
  1041. int ret;
  1042. deb_info("%s:\n", __func__);
  1043. /* select I2C adapter */
  1044. if (adap->id == 0)
  1045. i2c_adap = &adap->dev->i2c_adap;
  1046. else
  1047. i2c_adap = &state->i2c_adap;
  1048. switch (af9015_af9013_config[adap->id].tuner) {
  1049. case AF9013_TUNER_MT2060:
  1050. case AF9013_TUNER_MT2060_2:
  1051. ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap,
  1052. &af9015_mt2060_config,
  1053. af9015_config.mt2060_if1[adap->id])
  1054. == NULL ? -ENODEV : 0;
  1055. break;
  1056. case AF9013_TUNER_QT1010:
  1057. case AF9013_TUNER_QT1010A:
  1058. ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap,
  1059. &af9015_qt1010_config) == NULL ? -ENODEV : 0;
  1060. break;
  1061. case AF9013_TUNER_TDA18271:
  1062. ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,
  1063. &af9015_tda18271_config) == NULL ? -ENODEV : 0;
  1064. break;
  1065. case AF9013_TUNER_TDA18218:
  1066. ret = dvb_attach(tda18218_attach, adap->fe, i2c_adap,
  1067. &af9015_tda18218_config) == NULL ? -ENODEV : 0;
  1068. break;
  1069. case AF9013_TUNER_MXL5003D:
  1070. ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
  1071. &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
  1072. break;
  1073. case AF9013_TUNER_MXL5005D:
  1074. case AF9013_TUNER_MXL5005R:
  1075. ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
  1076. &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
  1077. break;
  1078. case AF9013_TUNER_ENV77H11D5:
  1079. ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap,
  1080. DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
  1081. break;
  1082. case AF9013_TUNER_MC44S803:
  1083. ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap,
  1084. &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
  1085. break;
  1086. case AF9013_TUNER_MXL5007T:
  1087. ret = dvb_attach(mxl5007t_attach, adap->fe, i2c_adap,
  1088. 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
  1089. break;
  1090. case AF9013_TUNER_UNKNOWN:
  1091. default:
  1092. ret = -ENODEV;
  1093. err("Unknown tuner id:%d",
  1094. af9015_af9013_config[adap->id].tuner);
  1095. }
  1096. return ret;
  1097. }
  1098. static struct usb_device_id af9015_usb_table[] = {
  1099. /* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)},
  1100. {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)},
  1101. {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)},
  1102. {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)},
  1103. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)},
  1104. /* 5 */{USB_DEVICE(USB_VID_VISIONPLUS,
  1105. USB_PID_TINYTWIN)},
  1106. {USB_DEVICE(USB_VID_VISIONPLUS,
  1107. USB_PID_AZUREWAVE_AD_TU700)},
  1108. {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},
  1109. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)},
  1110. {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},
  1111. /* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},
  1112. {USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)},
  1113. {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},
  1114. {USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)},
  1115. {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
  1116. /* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},
  1117. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)},
  1118. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)},
  1119. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3)},
  1120. {USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT)},
  1121. /* 20 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850)},
  1122. {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805)},
  1123. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU)},
  1124. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810)},
  1125. {USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03)},
  1126. /* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)},
  1127. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)},
  1128. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)},
  1129. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)},
  1130. {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},
  1131. /* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},
  1132. {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},
  1133. {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},
  1134. {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC)},
  1135. {USB_DEVICE(USB_VID_TERRATEC,
  1136. USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)},
  1137. /* 35 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)},
  1138. {USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3)},
  1139. {0},
  1140. };
  1141. MODULE_DEVICE_TABLE(usb, af9015_usb_table);
  1142. #define AF9015_RC_INTERVAL 500
  1143. static struct dvb_usb_device_properties af9015_properties[] = {
  1144. {
  1145. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1146. .usb_ctrl = DEVICE_SPECIFIC,
  1147. .download_firmware = af9015_download_firmware,
  1148. .firmware = "dvb-usb-af9015.fw",
  1149. .no_reconnect = 1,
  1150. .size_of_priv = sizeof(struct af9015_state),
  1151. .num_adapters = 2,
  1152. .adapter = {
  1153. {
  1154. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  1155. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  1156. .pid_filter_count = 32,
  1157. .pid_filter = af9015_pid_filter,
  1158. .pid_filter_ctrl = af9015_pid_filter_ctrl,
  1159. .frontend_attach =
  1160. af9015_af9013_frontend_attach,
  1161. .tuner_attach = af9015_tuner_attach,
  1162. .stream = {
  1163. .type = USB_BULK,
  1164. .count = 6,
  1165. .endpoint = 0x84,
  1166. },
  1167. },
  1168. {
  1169. .frontend_attach =
  1170. af9015_af9013_frontend_attach,
  1171. .tuner_attach = af9015_tuner_attach,
  1172. .stream = {
  1173. .type = USB_BULK,
  1174. .count = 6,
  1175. .endpoint = 0x85,
  1176. .u = {
  1177. .bulk = {
  1178. .buffersize =
  1179. TS_USB20_FRAME_SIZE,
  1180. }
  1181. }
  1182. },
  1183. }
  1184. },
  1185. .identify_state = af9015_identify_state,
  1186. .rc.core = {
  1187. .protocol = RC_TYPE_NEC,
  1188. .module_name = "af9015",
  1189. .rc_query = af9015_rc_query,
  1190. .rc_interval = AF9015_RC_INTERVAL,
  1191. .allowed_protos = RC_TYPE_NEC,
  1192. },
  1193. .i2c_algo = &af9015_i2c_algo,
  1194. .num_device_descs = 12, /* check max from dvb-usb.h */
  1195. .devices = {
  1196. {
  1197. .name = "Afatech AF9015 DVB-T USB2.0 stick",
  1198. .cold_ids = {&af9015_usb_table[0],
  1199. &af9015_usb_table[1], NULL},
  1200. .warm_ids = {NULL},
  1201. },
  1202. {
  1203. .name = "Leadtek WinFast DTV Dongle Gold",
  1204. .cold_ids = {&af9015_usb_table[2], NULL},
  1205. .warm_ids = {NULL},
  1206. },
  1207. {
  1208. .name = "Pinnacle PCTV 71e",
  1209. .cold_ids = {&af9015_usb_table[3], NULL},
  1210. .warm_ids = {NULL},
  1211. },
  1212. {
  1213. .name = "KWorld PlusTV Dual DVB-T Stick " \
  1214. "(DVB-T 399U)",
  1215. .cold_ids = {&af9015_usb_table[4],
  1216. &af9015_usb_table[25], NULL},
  1217. .warm_ids = {NULL},
  1218. },
  1219. {
  1220. .name = "DigitalNow TinyTwin DVB-T Receiver",
  1221. .cold_ids = {&af9015_usb_table[5],
  1222. &af9015_usb_table[28],
  1223. &af9015_usb_table[36], NULL},
  1224. .warm_ids = {NULL},
  1225. },
  1226. {
  1227. .name = "TwinHan AzureWave AD-TU700(704J)",
  1228. .cold_ids = {&af9015_usb_table[6], NULL},
  1229. .warm_ids = {NULL},
  1230. },
  1231. {
  1232. .name = "TerraTec Cinergy T USB XE",
  1233. .cold_ids = {&af9015_usb_table[7], NULL},
  1234. .warm_ids = {NULL},
  1235. },
  1236. {
  1237. .name = "KWorld PlusTV Dual DVB-T PCI " \
  1238. "(DVB-T PC160-2T)",
  1239. .cold_ids = {&af9015_usb_table[8], NULL},
  1240. .warm_ids = {NULL},
  1241. },
  1242. {
  1243. .name = "AVerMedia AVerTV DVB-T Volar X",
  1244. .cold_ids = {&af9015_usb_table[9], NULL},
  1245. .warm_ids = {NULL},
  1246. },
  1247. {
  1248. .name = "TerraTec Cinergy T Stick RC",
  1249. .cold_ids = {&af9015_usb_table[33], NULL},
  1250. .warm_ids = {NULL},
  1251. },
  1252. {
  1253. .name = "TerraTec Cinergy T Stick Dual RC",
  1254. .cold_ids = {&af9015_usb_table[34], NULL},
  1255. .warm_ids = {NULL},
  1256. },
  1257. {
  1258. .name = "AverMedia AVerTV Red HD+ (A850T)",
  1259. .cold_ids = {&af9015_usb_table[35], NULL},
  1260. .warm_ids = {NULL},
  1261. },
  1262. }
  1263. }, {
  1264. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1265. .usb_ctrl = DEVICE_SPECIFIC,
  1266. .download_firmware = af9015_download_firmware,
  1267. .firmware = "dvb-usb-af9015.fw",
  1268. .no_reconnect = 1,
  1269. .size_of_priv = sizeof(struct af9015_state),
  1270. .num_adapters = 2,
  1271. .adapter = {
  1272. {
  1273. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  1274. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  1275. .pid_filter_count = 32,
  1276. .pid_filter = af9015_pid_filter,
  1277. .pid_filter_ctrl = af9015_pid_filter_ctrl,
  1278. .frontend_attach =
  1279. af9015_af9013_frontend_attach,
  1280. .tuner_attach = af9015_tuner_attach,
  1281. .stream = {
  1282. .type = USB_BULK,
  1283. .count = 6,
  1284. .endpoint = 0x84,
  1285. },
  1286. },
  1287. {
  1288. .frontend_attach =
  1289. af9015_af9013_frontend_attach,
  1290. .tuner_attach = af9015_tuner_attach,
  1291. .stream = {
  1292. .type = USB_BULK,
  1293. .count = 6,
  1294. .endpoint = 0x85,
  1295. .u = {
  1296. .bulk = {
  1297. .buffersize =
  1298. TS_USB20_FRAME_SIZE,
  1299. }
  1300. }
  1301. },
  1302. }
  1303. },
  1304. .identify_state = af9015_identify_state,
  1305. .rc.core = {
  1306. .protocol = RC_TYPE_NEC,
  1307. .module_name = "af9015",
  1308. .rc_query = af9015_rc_query,
  1309. .rc_interval = AF9015_RC_INTERVAL,
  1310. .allowed_protos = RC_TYPE_NEC,
  1311. },
  1312. .i2c_algo = &af9015_i2c_algo,
  1313. .num_device_descs = 9, /* check max from dvb-usb.h */
  1314. .devices = {
  1315. {
  1316. .name = "Xtensions XD-380",
  1317. .cold_ids = {&af9015_usb_table[10], NULL},
  1318. .warm_ids = {NULL},
  1319. },
  1320. {
  1321. .name = "MSI DIGIVOX Duo",
  1322. .cold_ids = {&af9015_usb_table[11], NULL},
  1323. .warm_ids = {NULL},
  1324. },
  1325. {
  1326. .name = "Fujitsu-Siemens Slim Mobile USB DVB-T",
  1327. .cold_ids = {&af9015_usb_table[12], NULL},
  1328. .warm_ids = {NULL},
  1329. },
  1330. {
  1331. .name = "Telestar Starstick 2",
  1332. .cold_ids = {&af9015_usb_table[13], NULL},
  1333. .warm_ids = {NULL},
  1334. },
  1335. {
  1336. .name = "AVerMedia A309",
  1337. .cold_ids = {&af9015_usb_table[14], NULL},
  1338. .warm_ids = {NULL},
  1339. },
  1340. {
  1341. .name = "MSI Digi VOX mini III",
  1342. .cold_ids = {&af9015_usb_table[15], NULL},
  1343. .warm_ids = {NULL},
  1344. },
  1345. {
  1346. .name = "KWorld USB DVB-T TV Stick II " \
  1347. "(VS-DVB-T 395U)",
  1348. .cold_ids = {&af9015_usb_table[16],
  1349. &af9015_usb_table[17],
  1350. &af9015_usb_table[18],
  1351. &af9015_usb_table[31], NULL},
  1352. .warm_ids = {NULL},
  1353. },
  1354. {
  1355. .name = "TrekStor DVB-T USB Stick",
  1356. .cold_ids = {&af9015_usb_table[19], NULL},
  1357. .warm_ids = {NULL},
  1358. },
  1359. {
  1360. .name = "AverMedia AVerTV Volar Black HD " \
  1361. "(A850)",
  1362. .cold_ids = {&af9015_usb_table[20], NULL},
  1363. .warm_ids = {NULL},
  1364. },
  1365. }
  1366. }, {
  1367. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1368. .usb_ctrl = DEVICE_SPECIFIC,
  1369. .download_firmware = af9015_download_firmware,
  1370. .firmware = "dvb-usb-af9015.fw",
  1371. .no_reconnect = 1,
  1372. .size_of_priv = sizeof(struct af9015_state),
  1373. .num_adapters = 2,
  1374. .adapter = {
  1375. {
  1376. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  1377. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  1378. .pid_filter_count = 32,
  1379. .pid_filter = af9015_pid_filter,
  1380. .pid_filter_ctrl = af9015_pid_filter_ctrl,
  1381. .frontend_attach =
  1382. af9015_af9013_frontend_attach,
  1383. .tuner_attach = af9015_tuner_attach,
  1384. .stream = {
  1385. .type = USB_BULK,
  1386. .count = 6,
  1387. .endpoint = 0x84,
  1388. },
  1389. },
  1390. {
  1391. .frontend_attach =
  1392. af9015_af9013_frontend_attach,
  1393. .tuner_attach = af9015_tuner_attach,
  1394. .stream = {
  1395. .type = USB_BULK,
  1396. .count = 6,
  1397. .endpoint = 0x85,
  1398. .u = {
  1399. .bulk = {
  1400. .buffersize =
  1401. TS_USB20_FRAME_SIZE,
  1402. }
  1403. }
  1404. },
  1405. }
  1406. },
  1407. .identify_state = af9015_identify_state,
  1408. .rc.core = {
  1409. .protocol = RC_TYPE_NEC,
  1410. .module_name = "af9015",
  1411. .rc_query = af9015_rc_query,
  1412. .rc_interval = AF9015_RC_INTERVAL,
  1413. .allowed_protos = RC_TYPE_NEC,
  1414. },
  1415. .i2c_algo = &af9015_i2c_algo,
  1416. .num_device_descs = 9, /* check max from dvb-usb.h */
  1417. .devices = {
  1418. {
  1419. .name = "AverMedia AVerTV Volar GPS 805 (A805)",
  1420. .cold_ids = {&af9015_usb_table[21], NULL},
  1421. .warm_ids = {NULL},
  1422. },
  1423. {
  1424. .name = "Conceptronic USB2.0 DVB-T CTVDIGRCU " \
  1425. "V3.0",
  1426. .cold_ids = {&af9015_usb_table[22], NULL},
  1427. .warm_ids = {NULL},
  1428. },
  1429. {
  1430. .name = "KWorld Digial MC-810",
  1431. .cold_ids = {&af9015_usb_table[23], NULL},
  1432. .warm_ids = {NULL},
  1433. },
  1434. {
  1435. .name = "Genius TVGo DVB-T03",
  1436. .cold_ids = {&af9015_usb_table[24], NULL},
  1437. .warm_ids = {NULL},
  1438. },
  1439. {
  1440. .name = "KWorld PlusTV DVB-T PCI Pro Card " \
  1441. "(DVB-T PC160-T)",
  1442. .cold_ids = {&af9015_usb_table[26], NULL},
  1443. .warm_ids = {NULL},
  1444. },
  1445. {
  1446. .name = "Sveon STV20 Tuner USB DVB-T HDTV",
  1447. .cold_ids = {&af9015_usb_table[27], NULL},
  1448. .warm_ids = {NULL},
  1449. },
  1450. {
  1451. .name = "Leadtek WinFast DTV2000DS",
  1452. .cold_ids = {&af9015_usb_table[29], NULL},
  1453. .warm_ids = {NULL},
  1454. },
  1455. {
  1456. .name = "KWorld USB DVB-T Stick Mobile " \
  1457. "(UB383-T)",
  1458. .cold_ids = {&af9015_usb_table[30], NULL},
  1459. .warm_ids = {NULL},
  1460. },
  1461. {
  1462. .name = "AverMedia AVerTV Volar M (A815Mac)",
  1463. .cold_ids = {&af9015_usb_table[32], NULL},
  1464. .warm_ids = {NULL},
  1465. },
  1466. }
  1467. },
  1468. };
  1469. static int af9015_usb_probe(struct usb_interface *intf,
  1470. const struct usb_device_id *id)
  1471. {
  1472. int ret = 0;
  1473. struct dvb_usb_device *d = NULL;
  1474. struct usb_device *udev = interface_to_usbdev(intf);
  1475. u8 i;
  1476. deb_info("%s: interface:%d\n", __func__,
  1477. intf->cur_altsetting->desc.bInterfaceNumber);
  1478. /* interface 0 is used by DVB-T receiver and
  1479. interface 1 is for remote controller (HID) */
  1480. if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
  1481. ret = af9015_read_config(udev);
  1482. if (ret)
  1483. return ret;
  1484. for (i = 0; i < af9015_properties_count; i++) {
  1485. ret = dvb_usb_device_init(intf, &af9015_properties[i],
  1486. THIS_MODULE, &d, adapter_nr);
  1487. if (!ret)
  1488. break;
  1489. if (ret != -ENODEV)
  1490. return ret;
  1491. }
  1492. if (ret)
  1493. return ret;
  1494. if (d)
  1495. ret = af9015_init(d);
  1496. }
  1497. return ret;
  1498. }
  1499. static void af9015_i2c_exit(struct dvb_usb_device *d)
  1500. {
  1501. struct af9015_state *state = d->priv;
  1502. deb_info("%s:\n", __func__);
  1503. /* remove 2nd I2C adapter */
  1504. if (d->state & DVB_USB_STATE_I2C)
  1505. i2c_del_adapter(&state->i2c_adap);
  1506. }
  1507. static void af9015_usb_device_exit(struct usb_interface *intf)
  1508. {
  1509. struct dvb_usb_device *d = usb_get_intfdata(intf);
  1510. deb_info("%s:\n", __func__);
  1511. /* remove 2nd I2C adapter */
  1512. if (d != NULL && d->desc != NULL)
  1513. af9015_i2c_exit(d);
  1514. dvb_usb_device_exit(intf);
  1515. }
  1516. /* usb specific object needed to register this driver with the usb subsystem */
  1517. static struct usb_driver af9015_usb_driver = {
  1518. .name = "dvb_usb_af9015",
  1519. .probe = af9015_usb_probe,
  1520. .disconnect = af9015_usb_device_exit,
  1521. .id_table = af9015_usb_table,
  1522. };
  1523. /* module stuff */
  1524. static int __init af9015_usb_module_init(void)
  1525. {
  1526. int ret;
  1527. ret = usb_register(&af9015_usb_driver);
  1528. if (ret)
  1529. err("module init failed:%d", ret);
  1530. return ret;
  1531. }
  1532. static void __exit af9015_usb_module_exit(void)
  1533. {
  1534. /* deregister this driver from the USB subsystem */
  1535. usb_deregister(&af9015_usb_driver);
  1536. }
  1537. module_init(af9015_usb_module_init);
  1538. module_exit(af9015_usb_module_exit);
  1539. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  1540. MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T");
  1541. MODULE_LICENSE("GPL");