af9015.c 50 KB

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