dw2102.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159
  1. /* DVB USB framework compliant Linux driver for the
  2. * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
  3. * TeVii S600, S630, S650, S660, S480, S421, S632
  4. * Prof 1100, 7500,
  5. * Geniatech SU3000, T220 Cards
  6. * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, version 2.
  11. *
  12. * see Documentation/dvb/README.dvb-usb for more information
  13. */
  14. #include "dw2102.h"
  15. #include "si21xx.h"
  16. #include "stv0299.h"
  17. #include "z0194a.h"
  18. #include "stv0288.h"
  19. #include "stb6000.h"
  20. #include "eds1547.h"
  21. #include "cx24116.h"
  22. #include "tda1002x.h"
  23. #include "mt312.h"
  24. #include "zl10039.h"
  25. #include "ts2020.h"
  26. #include "ds3000.h"
  27. #include "stv0900.h"
  28. #include "stv6110.h"
  29. #include "stb6100.h"
  30. #include "stb6100_proc.h"
  31. #include "m88rs2000.h"
  32. #include "tda18271.h"
  33. #include "cxd2820r.h"
  34. /* Max transfer size done by I2C transfer functions */
  35. #define MAX_XFER_SIZE 64
  36. #ifndef USB_PID_DW2102
  37. #define USB_PID_DW2102 0x2102
  38. #endif
  39. #ifndef USB_PID_DW2104
  40. #define USB_PID_DW2104 0x2104
  41. #endif
  42. #ifndef USB_PID_DW3101
  43. #define USB_PID_DW3101 0x3101
  44. #endif
  45. #ifndef USB_PID_CINERGY_S
  46. #define USB_PID_CINERGY_S 0x0064
  47. #endif
  48. #ifndef USB_PID_TEVII_S630
  49. #define USB_PID_TEVII_S630 0xd630
  50. #endif
  51. #ifndef USB_PID_TEVII_S650
  52. #define USB_PID_TEVII_S650 0xd650
  53. #endif
  54. #ifndef USB_PID_TEVII_S660
  55. #define USB_PID_TEVII_S660 0xd660
  56. #endif
  57. #ifndef USB_PID_TEVII_S480_1
  58. #define USB_PID_TEVII_S480_1 0xd481
  59. #endif
  60. #ifndef USB_PID_TEVII_S480_2
  61. #define USB_PID_TEVII_S480_2 0xd482
  62. #endif
  63. #ifndef USB_PID_PROF_1100
  64. #define USB_PID_PROF_1100 0xb012
  65. #endif
  66. #ifndef USB_PID_TEVII_S421
  67. #define USB_PID_TEVII_S421 0xd421
  68. #endif
  69. #ifndef USB_PID_TEVII_S632
  70. #define USB_PID_TEVII_S632 0xd632
  71. #endif
  72. #ifndef USB_PID_GOTVIEW_SAT_HD
  73. #define USB_PID_GOTVIEW_SAT_HD 0x5456
  74. #endif
  75. #define DW210X_READ_MSG 0
  76. #define DW210X_WRITE_MSG 1
  77. #define REG_1F_SYMBOLRATE_BYTE0 0x1f
  78. #define REG_20_SYMBOLRATE_BYTE1 0x20
  79. #define REG_21_SYMBOLRATE_BYTE2 0x21
  80. /* on my own*/
  81. #define DW2102_VOLTAGE_CTRL (0x1800)
  82. #define SU3000_STREAM_CTRL (0x1900)
  83. #define DW2102_RC_QUERY (0x1a00)
  84. #define DW2102_LED_CTRL (0x1b00)
  85. #define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
  86. #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
  87. #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
  88. #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
  89. #define S630_FIRMWARE "dvb-usb-s630.fw"
  90. #define S660_FIRMWARE "dvb-usb-s660.fw"
  91. #define P1100_FIRMWARE "dvb-usb-p1100.fw"
  92. #define P7500_FIRMWARE "dvb-usb-p7500.fw"
  93. #define err_str "did not find the firmware file. (%s) " \
  94. "Please see linux/Documentation/dvb/ for more details " \
  95. "on firmware-problems."
  96. struct su3000_state {
  97. u8 initialized;
  98. };
  99. struct s6x0_state {
  100. int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
  101. };
  102. /* debug */
  103. static int dvb_usb_dw2102_debug;
  104. module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
  105. MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
  106. DVB_USB_DEBUG_STATUS);
  107. /* demod probe */
  108. static int demod_probe = 1;
  109. module_param_named(demod, demod_probe, int, 0644);
  110. MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
  111. "4=stv0903+stb6100(or-able)).");
  112. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  113. static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
  114. u16 index, u8 * data, u16 len, int flags)
  115. {
  116. int ret;
  117. u8 *u8buf;
  118. unsigned int pipe = (flags == DW210X_READ_MSG) ?
  119. usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
  120. u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
  121. u8buf = kmalloc(len, GFP_KERNEL);
  122. if (!u8buf)
  123. return -ENOMEM;
  124. if (flags == DW210X_WRITE_MSG)
  125. memcpy(u8buf, data, len);
  126. ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
  127. value, index , u8buf, len, 2000);
  128. if (flags == DW210X_READ_MSG)
  129. memcpy(data, u8buf, len);
  130. kfree(u8buf);
  131. return ret;
  132. }
  133. /* I2C */
  134. static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  135. int num)
  136. {
  137. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  138. int i = 0;
  139. u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
  140. u16 value;
  141. if (!d)
  142. return -ENODEV;
  143. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  144. return -EAGAIN;
  145. switch (num) {
  146. case 2:
  147. /* read stv0299 register */
  148. value = msg[0].buf[0];/* register */
  149. for (i = 0; i < msg[1].len; i++) {
  150. dw210x_op_rw(d->udev, 0xb5, value + i, 0,
  151. buf6, 2, DW210X_READ_MSG);
  152. msg[1].buf[i] = buf6[0];
  153. }
  154. break;
  155. case 1:
  156. switch (msg[0].addr) {
  157. case 0x68:
  158. /* write to stv0299 register */
  159. buf6[0] = 0x2a;
  160. buf6[1] = msg[0].buf[0];
  161. buf6[2] = msg[0].buf[1];
  162. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  163. buf6, 3, DW210X_WRITE_MSG);
  164. break;
  165. case 0x60:
  166. if (msg[0].flags == 0) {
  167. /* write to tuner pll */
  168. buf6[0] = 0x2c;
  169. buf6[1] = 5;
  170. buf6[2] = 0xc0;
  171. buf6[3] = msg[0].buf[0];
  172. buf6[4] = msg[0].buf[1];
  173. buf6[5] = msg[0].buf[2];
  174. buf6[6] = msg[0].buf[3];
  175. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  176. buf6, 7, DW210X_WRITE_MSG);
  177. } else {
  178. /* read from tuner */
  179. dw210x_op_rw(d->udev, 0xb5, 0, 0,
  180. buf6, 1, DW210X_READ_MSG);
  181. msg[0].buf[0] = buf6[0];
  182. }
  183. break;
  184. case (DW2102_RC_QUERY):
  185. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  186. buf6, 2, DW210X_READ_MSG);
  187. msg[0].buf[0] = buf6[0];
  188. msg[0].buf[1] = buf6[1];
  189. break;
  190. case (DW2102_VOLTAGE_CTRL):
  191. buf6[0] = 0x30;
  192. buf6[1] = msg[0].buf[0];
  193. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  194. buf6, 2, DW210X_WRITE_MSG);
  195. break;
  196. }
  197. break;
  198. }
  199. mutex_unlock(&d->i2c_mutex);
  200. return num;
  201. }
  202. static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
  203. struct i2c_msg msg[], int num)
  204. {
  205. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  206. u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
  207. if (!d)
  208. return -ENODEV;
  209. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  210. return -EAGAIN;
  211. switch (num) {
  212. case 2:
  213. /* read si2109 register by number */
  214. buf6[0] = msg[0].addr << 1;
  215. buf6[1] = msg[0].len;
  216. buf6[2] = msg[0].buf[0];
  217. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  218. buf6, msg[0].len + 2, DW210X_WRITE_MSG);
  219. /* read si2109 register */
  220. dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
  221. buf6, msg[1].len + 2, DW210X_READ_MSG);
  222. memcpy(msg[1].buf, buf6 + 2, msg[1].len);
  223. break;
  224. case 1:
  225. switch (msg[0].addr) {
  226. case 0x68:
  227. /* write to si2109 register */
  228. buf6[0] = msg[0].addr << 1;
  229. buf6[1] = msg[0].len;
  230. memcpy(buf6 + 2, msg[0].buf, msg[0].len);
  231. dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
  232. msg[0].len + 2, DW210X_WRITE_MSG);
  233. break;
  234. case(DW2102_RC_QUERY):
  235. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  236. buf6, 2, DW210X_READ_MSG);
  237. msg[0].buf[0] = buf6[0];
  238. msg[0].buf[1] = buf6[1];
  239. break;
  240. case(DW2102_VOLTAGE_CTRL):
  241. buf6[0] = 0x30;
  242. buf6[1] = msg[0].buf[0];
  243. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  244. buf6, 2, DW210X_WRITE_MSG);
  245. break;
  246. }
  247. break;
  248. }
  249. mutex_unlock(&d->i2c_mutex);
  250. return num;
  251. }
  252. static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
  253. {
  254. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  255. int ret;
  256. if (!d)
  257. return -ENODEV;
  258. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  259. return -EAGAIN;
  260. switch (num) {
  261. case 2: {
  262. /* read */
  263. /* first write first register number */
  264. u8 ibuf[MAX_XFER_SIZE], obuf[3];
  265. if (2 + msg[1].len > sizeof(ibuf)) {
  266. warn("i2c rd: len=%d is too big!\n",
  267. msg[1].len);
  268. ret = -EOPNOTSUPP;
  269. goto unlock;
  270. }
  271. obuf[0] = msg[0].addr << 1;
  272. obuf[1] = msg[0].len;
  273. obuf[2] = msg[0].buf[0];
  274. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  275. obuf, msg[0].len + 2, DW210X_WRITE_MSG);
  276. /* second read registers */
  277. dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
  278. ibuf, msg[1].len + 2, DW210X_READ_MSG);
  279. memcpy(msg[1].buf, ibuf + 2, msg[1].len);
  280. break;
  281. }
  282. case 1:
  283. switch (msg[0].addr) {
  284. case 0x68: {
  285. /* write to register */
  286. u8 obuf[MAX_XFER_SIZE];
  287. if (2 + msg[0].len > sizeof(obuf)) {
  288. warn("i2c wr: len=%d is too big!\n",
  289. msg[1].len);
  290. ret = -EOPNOTSUPP;
  291. goto unlock;
  292. }
  293. obuf[0] = msg[0].addr << 1;
  294. obuf[1] = msg[0].len;
  295. memcpy(obuf + 2, msg[0].buf, msg[0].len);
  296. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  297. obuf, msg[0].len + 2, DW210X_WRITE_MSG);
  298. break;
  299. }
  300. case 0x61: {
  301. /* write to tuner */
  302. u8 obuf[MAX_XFER_SIZE];
  303. if (2 + msg[0].len > sizeof(obuf)) {
  304. warn("i2c wr: len=%d is too big!\n",
  305. msg[1].len);
  306. ret = -EOPNOTSUPP;
  307. goto unlock;
  308. }
  309. obuf[0] = msg[0].addr << 1;
  310. obuf[1] = msg[0].len;
  311. memcpy(obuf + 2, msg[0].buf, msg[0].len);
  312. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  313. obuf, msg[0].len + 2, DW210X_WRITE_MSG);
  314. break;
  315. }
  316. case(DW2102_RC_QUERY): {
  317. u8 ibuf[2];
  318. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  319. ibuf, 2, DW210X_READ_MSG);
  320. memcpy(msg[0].buf, ibuf , 2);
  321. break;
  322. }
  323. case(DW2102_VOLTAGE_CTRL): {
  324. u8 obuf[2];
  325. obuf[0] = 0x30;
  326. obuf[1] = msg[0].buf[0];
  327. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  328. obuf, 2, DW210X_WRITE_MSG);
  329. break;
  330. }
  331. }
  332. break;
  333. }
  334. ret = num;
  335. unlock:
  336. mutex_unlock(&d->i2c_mutex);
  337. return ret;
  338. }
  339. static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
  340. {
  341. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  342. int len, i, j, ret;
  343. if (!d)
  344. return -ENODEV;
  345. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  346. return -EAGAIN;
  347. for (j = 0; j < num; j++) {
  348. switch (msg[j].addr) {
  349. case(DW2102_RC_QUERY): {
  350. u8 ibuf[2];
  351. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  352. ibuf, 2, DW210X_READ_MSG);
  353. memcpy(msg[j].buf, ibuf , 2);
  354. break;
  355. }
  356. case(DW2102_VOLTAGE_CTRL): {
  357. u8 obuf[2];
  358. obuf[0] = 0x30;
  359. obuf[1] = msg[j].buf[0];
  360. dw210x_op_rw(d->udev, 0xb2, 0, 0,
  361. obuf, 2, DW210X_WRITE_MSG);
  362. break;
  363. }
  364. /*case 0x55: cx24116
  365. case 0x6a: stv0903
  366. case 0x68: ds3000, stv0903
  367. case 0x60: ts2020, stv6110, stb6100 */
  368. default: {
  369. if (msg[j].flags == I2C_M_RD) {
  370. /* read registers */
  371. u8 ibuf[MAX_XFER_SIZE];
  372. if (2 + msg[j].len > sizeof(ibuf)) {
  373. warn("i2c rd: len=%d is too big!\n",
  374. msg[j].len);
  375. ret = -EOPNOTSUPP;
  376. goto unlock;
  377. }
  378. dw210x_op_rw(d->udev, 0xc3,
  379. (msg[j].addr << 1) + 1, 0,
  380. ibuf, msg[j].len + 2,
  381. DW210X_READ_MSG);
  382. memcpy(msg[j].buf, ibuf + 2, msg[j].len);
  383. mdelay(10);
  384. } else if (((msg[j].buf[0] == 0xb0) &&
  385. (msg[j].addr == 0x68)) ||
  386. ((msg[j].buf[0] == 0xf7) &&
  387. (msg[j].addr == 0x55))) {
  388. /* write firmware */
  389. u8 obuf[19];
  390. obuf[0] = msg[j].addr << 1;
  391. obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
  392. obuf[2] = msg[j].buf[0];
  393. len = msg[j].len - 1;
  394. i = 1;
  395. do {
  396. memcpy(obuf + 3, msg[j].buf + i,
  397. (len > 16 ? 16 : len));
  398. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  399. obuf, (len > 16 ? 16 : len) + 3,
  400. DW210X_WRITE_MSG);
  401. i += 16;
  402. len -= 16;
  403. } while (len > 0);
  404. } else {
  405. /* write registers */
  406. u8 obuf[MAX_XFER_SIZE];
  407. if (2 + msg[j].len > sizeof(obuf)) {
  408. warn("i2c wr: len=%d is too big!\n",
  409. msg[j].len);
  410. ret = -EOPNOTSUPP;
  411. goto unlock;
  412. }
  413. obuf[0] = msg[j].addr << 1;
  414. obuf[1] = msg[j].len;
  415. memcpy(obuf + 2, msg[j].buf, msg[j].len);
  416. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  417. obuf, msg[j].len + 2,
  418. DW210X_WRITE_MSG);
  419. }
  420. break;
  421. }
  422. }
  423. }
  424. ret = num;
  425. unlock:
  426. mutex_unlock(&d->i2c_mutex);
  427. return ret;
  428. }
  429. static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  430. int num)
  431. {
  432. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  433. int ret;
  434. int i;
  435. if (!d)
  436. return -ENODEV;
  437. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  438. return -EAGAIN;
  439. switch (num) {
  440. case 2: {
  441. /* read */
  442. /* first write first register number */
  443. u8 ibuf[MAX_XFER_SIZE], obuf[3];
  444. if (2 + msg[1].len > sizeof(ibuf)) {
  445. warn("i2c rd: len=%d is too big!\n",
  446. msg[1].len);
  447. ret = -EOPNOTSUPP;
  448. goto unlock;
  449. }
  450. obuf[0] = msg[0].addr << 1;
  451. obuf[1] = msg[0].len;
  452. obuf[2] = msg[0].buf[0];
  453. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  454. obuf, msg[0].len + 2, DW210X_WRITE_MSG);
  455. /* second read registers */
  456. dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
  457. ibuf, msg[1].len + 2, DW210X_READ_MSG);
  458. memcpy(msg[1].buf, ibuf + 2, msg[1].len);
  459. break;
  460. }
  461. case 1:
  462. switch (msg[0].addr) {
  463. case 0x60:
  464. case 0x0c: {
  465. /* write to register */
  466. u8 obuf[MAX_XFER_SIZE];
  467. if (2 + msg[0].len > sizeof(obuf)) {
  468. warn("i2c wr: len=%d is too big!\n",
  469. msg[0].len);
  470. ret = -EOPNOTSUPP;
  471. goto unlock;
  472. }
  473. obuf[0] = msg[0].addr << 1;
  474. obuf[1] = msg[0].len;
  475. memcpy(obuf + 2, msg[0].buf, msg[0].len);
  476. dw210x_op_rw(d->udev, 0xc2, 0, 0,
  477. obuf, msg[0].len + 2, DW210X_WRITE_MSG);
  478. break;
  479. }
  480. case(DW2102_RC_QUERY): {
  481. u8 ibuf[2];
  482. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  483. ibuf, 2, DW210X_READ_MSG);
  484. memcpy(msg[0].buf, ibuf , 2);
  485. break;
  486. }
  487. }
  488. break;
  489. }
  490. for (i = 0; i < num; i++) {
  491. deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
  492. msg[i].flags == 0 ? ">>>" : "<<<");
  493. debug_dump(msg[i].buf, msg[i].len, deb_xfer);
  494. }
  495. ret = num;
  496. unlock:
  497. mutex_unlock(&d->i2c_mutex);
  498. return ret;
  499. }
  500. static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  501. int num)
  502. {
  503. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  504. struct usb_device *udev;
  505. int len, i, j, ret;
  506. if (!d)
  507. return -ENODEV;
  508. udev = d->udev;
  509. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  510. return -EAGAIN;
  511. for (j = 0; j < num; j++) {
  512. switch (msg[j].addr) {
  513. case (DW2102_RC_QUERY): {
  514. u8 ibuf[5];
  515. dw210x_op_rw(d->udev, 0xb8, 0, 0,
  516. ibuf, 5, DW210X_READ_MSG);
  517. memcpy(msg[j].buf, ibuf + 3, 2);
  518. break;
  519. }
  520. case (DW2102_VOLTAGE_CTRL): {
  521. u8 obuf[2];
  522. obuf[0] = 1;
  523. obuf[1] = msg[j].buf[1];/* off-on */
  524. dw210x_op_rw(d->udev, 0x8a, 0, 0,
  525. obuf, 2, DW210X_WRITE_MSG);
  526. obuf[0] = 3;
  527. obuf[1] = msg[j].buf[0];/* 13v-18v */
  528. dw210x_op_rw(d->udev, 0x8a, 0, 0,
  529. obuf, 2, DW210X_WRITE_MSG);
  530. break;
  531. }
  532. case (DW2102_LED_CTRL): {
  533. u8 obuf[2];
  534. obuf[0] = 5;
  535. obuf[1] = msg[j].buf[0];
  536. dw210x_op_rw(d->udev, 0x8a, 0, 0,
  537. obuf, 2, DW210X_WRITE_MSG);
  538. break;
  539. }
  540. /*case 0x55: cx24116
  541. case 0x6a: stv0903
  542. case 0x68: ds3000, stv0903, rs2000
  543. case 0x60: ts2020, stv6110, stb6100
  544. case 0xa0: eeprom */
  545. default: {
  546. if (msg[j].flags == I2C_M_RD) {
  547. /* read registers */
  548. u8 ibuf[MAX_XFER_SIZE];
  549. if (msg[j].len > sizeof(ibuf)) {
  550. warn("i2c rd: len=%d is too big!\n",
  551. msg[j].len);
  552. ret = -EOPNOTSUPP;
  553. goto unlock;
  554. }
  555. dw210x_op_rw(d->udev, 0x91, 0, 0,
  556. ibuf, msg[j].len,
  557. DW210X_READ_MSG);
  558. memcpy(msg[j].buf, ibuf, msg[j].len);
  559. break;
  560. } else if ((msg[j].buf[0] == 0xb0) &&
  561. (msg[j].addr == 0x68)) {
  562. /* write firmware */
  563. u8 obuf[19];
  564. obuf[0] = (msg[j].len > 16 ?
  565. 18 : msg[j].len + 1);
  566. obuf[1] = msg[j].addr << 1;
  567. obuf[2] = msg[j].buf[0];
  568. len = msg[j].len - 1;
  569. i = 1;
  570. do {
  571. memcpy(obuf + 3, msg[j].buf + i,
  572. (len > 16 ? 16 : len));
  573. dw210x_op_rw(d->udev, 0x80, 0, 0,
  574. obuf, (len > 16 ? 16 : len) + 3,
  575. DW210X_WRITE_MSG);
  576. i += 16;
  577. len -= 16;
  578. } while (len > 0);
  579. } else if (j < (num - 1)) {
  580. /* write register addr before read */
  581. u8 obuf[MAX_XFER_SIZE];
  582. if (2 + msg[j].len > sizeof(obuf)) {
  583. warn("i2c wr: len=%d is too big!\n",
  584. msg[j].len);
  585. ret = -EOPNOTSUPP;
  586. goto unlock;
  587. }
  588. obuf[0] = msg[j + 1].len;
  589. obuf[1] = (msg[j].addr << 1);
  590. memcpy(obuf + 2, msg[j].buf, msg[j].len);
  591. dw210x_op_rw(d->udev,
  592. udev->descriptor.idProduct ==
  593. 0x7500 ? 0x92 : 0x90, 0, 0,
  594. obuf, msg[j].len + 2,
  595. DW210X_WRITE_MSG);
  596. break;
  597. } else {
  598. /* write registers */
  599. u8 obuf[MAX_XFER_SIZE];
  600. if (2 + msg[j].len > sizeof(obuf)) {
  601. warn("i2c wr: len=%d is too big!\n",
  602. msg[j].len);
  603. ret = -EOPNOTSUPP;
  604. goto unlock;
  605. }
  606. obuf[0] = msg[j].len + 1;
  607. obuf[1] = (msg[j].addr << 1);
  608. memcpy(obuf + 2, msg[j].buf, msg[j].len);
  609. dw210x_op_rw(d->udev, 0x80, 0, 0,
  610. obuf, msg[j].len + 2,
  611. DW210X_WRITE_MSG);
  612. break;
  613. }
  614. break;
  615. }
  616. }
  617. }
  618. ret = num;
  619. unlock:
  620. mutex_unlock(&d->i2c_mutex);
  621. return ret;
  622. }
  623. static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  624. int num)
  625. {
  626. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  627. u8 obuf[0x40], ibuf[0x40];
  628. if (!d)
  629. return -ENODEV;
  630. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  631. return -EAGAIN;
  632. switch (num) {
  633. case 1:
  634. switch (msg[0].addr) {
  635. case SU3000_STREAM_CTRL:
  636. obuf[0] = msg[0].buf[0] + 0x36;
  637. obuf[1] = 3;
  638. obuf[2] = 0;
  639. if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
  640. err("i2c transfer failed.");
  641. break;
  642. case DW2102_RC_QUERY:
  643. obuf[0] = 0x10;
  644. if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
  645. err("i2c transfer failed.");
  646. msg[0].buf[1] = ibuf[0];
  647. msg[0].buf[0] = ibuf[1];
  648. break;
  649. default:
  650. /* always i2c write*/
  651. obuf[0] = 0x08;
  652. obuf[1] = msg[0].addr;
  653. obuf[2] = msg[0].len;
  654. memcpy(&obuf[3], msg[0].buf, msg[0].len);
  655. if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
  656. ibuf, 1, 0) < 0)
  657. err("i2c transfer failed.");
  658. }
  659. break;
  660. case 2:
  661. /* always i2c read */
  662. obuf[0] = 0x09;
  663. obuf[1] = msg[0].len;
  664. obuf[2] = msg[1].len;
  665. obuf[3] = msg[0].addr;
  666. memcpy(&obuf[4], msg[0].buf, msg[0].len);
  667. if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
  668. ibuf, msg[1].len + 1, 0) < 0)
  669. err("i2c transfer failed.");
  670. memcpy(msg[1].buf, &ibuf[1], msg[1].len);
  671. break;
  672. default:
  673. warn("more than 2 i2c messages at a time is not handled yet.");
  674. break;
  675. }
  676. mutex_unlock(&d->i2c_mutex);
  677. return num;
  678. }
  679. static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
  680. {
  681. return I2C_FUNC_I2C;
  682. }
  683. static struct i2c_algorithm dw2102_i2c_algo = {
  684. .master_xfer = dw2102_i2c_transfer,
  685. .functionality = dw210x_i2c_func,
  686. };
  687. static struct i2c_algorithm dw2102_serit_i2c_algo = {
  688. .master_xfer = dw2102_serit_i2c_transfer,
  689. .functionality = dw210x_i2c_func,
  690. };
  691. static struct i2c_algorithm dw2102_earda_i2c_algo = {
  692. .master_xfer = dw2102_earda_i2c_transfer,
  693. .functionality = dw210x_i2c_func,
  694. };
  695. static struct i2c_algorithm dw2104_i2c_algo = {
  696. .master_xfer = dw2104_i2c_transfer,
  697. .functionality = dw210x_i2c_func,
  698. };
  699. static struct i2c_algorithm dw3101_i2c_algo = {
  700. .master_xfer = dw3101_i2c_transfer,
  701. .functionality = dw210x_i2c_func,
  702. };
  703. static struct i2c_algorithm s6x0_i2c_algo = {
  704. .master_xfer = s6x0_i2c_transfer,
  705. .functionality = dw210x_i2c_func,
  706. };
  707. static struct i2c_algorithm su3000_i2c_algo = {
  708. .master_xfer = su3000_i2c_transfer,
  709. .functionality = dw210x_i2c_func,
  710. };
  711. static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
  712. {
  713. int i;
  714. u8 ibuf[] = {0, 0};
  715. u8 eeprom[256], eepromline[16];
  716. for (i = 0; i < 256; i++) {
  717. if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
  718. err("read eeprom failed.");
  719. return -1;
  720. } else {
  721. eepromline[i%16] = ibuf[0];
  722. eeprom[i] = ibuf[0];
  723. }
  724. if ((i % 16) == 15) {
  725. deb_xfer("%02x: ", i - 15);
  726. debug_dump(eepromline, 16, deb_xfer);
  727. }
  728. }
  729. memcpy(mac, eeprom + 8, 6);
  730. return 0;
  731. };
  732. static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
  733. {
  734. int i, ret;
  735. u8 ibuf[] = { 0 }, obuf[] = { 0 };
  736. u8 eeprom[256], eepromline[16];
  737. struct i2c_msg msg[] = {
  738. {
  739. .addr = 0xa0 >> 1,
  740. .flags = 0,
  741. .buf = obuf,
  742. .len = 1,
  743. }, {
  744. .addr = 0xa0 >> 1,
  745. .flags = I2C_M_RD,
  746. .buf = ibuf,
  747. .len = 1,
  748. }
  749. };
  750. for (i = 0; i < 256; i++) {
  751. obuf[0] = i;
  752. ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
  753. if (ret != 2) {
  754. err("read eeprom failed.");
  755. return -1;
  756. } else {
  757. eepromline[i % 16] = ibuf[0];
  758. eeprom[i] = ibuf[0];
  759. }
  760. if ((i % 16) == 15) {
  761. deb_xfer("%02x: ", i - 15);
  762. debug_dump(eepromline, 16, deb_xfer);
  763. }
  764. }
  765. memcpy(mac, eeprom + 16, 6);
  766. return 0;
  767. };
  768. static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  769. {
  770. static u8 command_start[] = {0x00};
  771. static u8 command_stop[] = {0x01};
  772. struct i2c_msg msg = {
  773. .addr = SU3000_STREAM_CTRL,
  774. .flags = 0,
  775. .buf = onoff ? command_start : command_stop,
  776. .len = 1
  777. };
  778. i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
  779. return 0;
  780. }
  781. static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
  782. {
  783. struct su3000_state *state = (struct su3000_state *)d->priv;
  784. u8 obuf[] = {0xde, 0};
  785. info("%s: %d, initialized %d\n", __func__, i, state->initialized);
  786. if (i && !state->initialized) {
  787. state->initialized = 1;
  788. /* reset board */
  789. dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
  790. }
  791. return 0;
  792. }
  793. static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
  794. {
  795. int i;
  796. u8 obuf[] = { 0x1f, 0xf0 };
  797. u8 ibuf[] = { 0 };
  798. struct i2c_msg msg[] = {
  799. {
  800. .addr = 0x51,
  801. .flags = 0,
  802. .buf = obuf,
  803. .len = 2,
  804. }, {
  805. .addr = 0x51,
  806. .flags = I2C_M_RD,
  807. .buf = ibuf,
  808. .len = 1,
  809. }
  810. };
  811. for (i = 0; i < 6; i++) {
  812. obuf[1] = 0xf0 + i;
  813. if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
  814. break;
  815. else
  816. mac[i] = ibuf[0];
  817. debug_dump(mac, 6, printk);
  818. }
  819. return 0;
  820. }
  821. static int su3000_identify_state(struct usb_device *udev,
  822. struct dvb_usb_device_properties *props,
  823. struct dvb_usb_device_description **desc,
  824. int *cold)
  825. {
  826. info("%s\n", __func__);
  827. *cold = 0;
  828. return 0;
  829. }
  830. static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  831. {
  832. static u8 command_13v[] = {0x00, 0x01};
  833. static u8 command_18v[] = {0x01, 0x01};
  834. static u8 command_off[] = {0x00, 0x00};
  835. struct i2c_msg msg = {
  836. .addr = DW2102_VOLTAGE_CTRL,
  837. .flags = 0,
  838. .buf = command_off,
  839. .len = 2,
  840. };
  841. struct dvb_usb_adapter *udev_adap =
  842. (struct dvb_usb_adapter *)(fe->dvb->priv);
  843. if (voltage == SEC_VOLTAGE_18)
  844. msg.buf = command_18v;
  845. else if (voltage == SEC_VOLTAGE_13)
  846. msg.buf = command_13v;
  847. i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
  848. return 0;
  849. }
  850. static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  851. {
  852. struct dvb_usb_adapter *d =
  853. (struct dvb_usb_adapter *)(fe->dvb->priv);
  854. struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
  855. dw210x_set_voltage(fe, voltage);
  856. if (st->old_set_voltage)
  857. st->old_set_voltage(fe, voltage);
  858. return 0;
  859. }
  860. static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
  861. {
  862. static u8 led_off[] = { 0 };
  863. static u8 led_on[] = { 1 };
  864. struct i2c_msg msg = {
  865. .addr = DW2102_LED_CTRL,
  866. .flags = 0,
  867. .buf = led_off,
  868. .len = 1
  869. };
  870. struct dvb_usb_adapter *udev_adap =
  871. (struct dvb_usb_adapter *)(fe->dvb->priv);
  872. if (offon)
  873. msg.buf = led_on;
  874. i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
  875. }
  876. static struct stv0299_config sharp_z0194a_config = {
  877. .demod_address = 0x68,
  878. .inittab = sharp_z0194a_inittab,
  879. .mclk = 88000000UL,
  880. .invert = 1,
  881. .skip_reinit = 0,
  882. .lock_output = STV0299_LOCKOUTPUT_1,
  883. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  884. .min_delay_ms = 100,
  885. .set_symbol_rate = sharp_z0194a_set_symbol_rate,
  886. };
  887. static struct cx24116_config dw2104_config = {
  888. .demod_address = 0x55,
  889. .mpg_clk_pos_pol = 0x01,
  890. };
  891. static struct si21xx_config serit_sp1511lhb_config = {
  892. .demod_address = 0x68,
  893. .min_delay_ms = 100,
  894. };
  895. static struct tda10023_config dw3101_tda10023_config = {
  896. .demod_address = 0x0c,
  897. .invert = 1,
  898. };
  899. static struct mt312_config zl313_config = {
  900. .demod_address = 0x0e,
  901. };
  902. static struct ds3000_config dw2104_ds3000_config = {
  903. .demod_address = 0x68,
  904. };
  905. static struct ts2020_config dw2104_ts2020_config = {
  906. .tuner_address = 0x60,
  907. .clk_out_div = 1,
  908. .frequency_div = 1060000,
  909. };
  910. static struct ds3000_config s660_ds3000_config = {
  911. .demod_address = 0x68,
  912. .ci_mode = 1,
  913. .set_lock_led = dw210x_led_ctrl,
  914. };
  915. static struct ts2020_config s660_ts2020_config = {
  916. .tuner_address = 0x60,
  917. .clk_out_div = 1,
  918. .frequency_div = 1146000,
  919. };
  920. static struct stv0900_config dw2104a_stv0900_config = {
  921. .demod_address = 0x6a,
  922. .demod_mode = 0,
  923. .xtal = 27000000,
  924. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  925. .diseqc_mode = 2,/* 2/3 PWM */
  926. .tun1_maddress = 0,/* 0x60 */
  927. .tun1_adc = 0,/* 2 Vpp */
  928. .path1_mode = 3,
  929. };
  930. static struct stb6100_config dw2104a_stb6100_config = {
  931. .tuner_address = 0x60,
  932. .refclock = 27000000,
  933. };
  934. static struct stv0900_config dw2104_stv0900_config = {
  935. .demod_address = 0x68,
  936. .demod_mode = 0,
  937. .xtal = 8000000,
  938. .clkmode = 3,
  939. .diseqc_mode = 2,
  940. .tun1_maddress = 0,
  941. .tun1_adc = 1,/* 1 Vpp */
  942. .path1_mode = 3,
  943. };
  944. static struct stv6110_config dw2104_stv6110_config = {
  945. .i2c_address = 0x60,
  946. .mclk = 16000000,
  947. .clk_div = 1,
  948. };
  949. static struct stv0900_config prof_7500_stv0900_config = {
  950. .demod_address = 0x6a,
  951. .demod_mode = 0,
  952. .xtal = 27000000,
  953. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  954. .diseqc_mode = 2,/* 2/3 PWM */
  955. .tun1_maddress = 0,/* 0x60 */
  956. .tun1_adc = 0,/* 2 Vpp */
  957. .path1_mode = 3,
  958. .tun1_type = 3,
  959. .set_lock_led = dw210x_led_ctrl,
  960. };
  961. static struct ds3000_config su3000_ds3000_config = {
  962. .demod_address = 0x68,
  963. .ci_mode = 1,
  964. .set_lock_led = dw210x_led_ctrl,
  965. };
  966. static struct cxd2820r_config cxd2820r_config = {
  967. .i2c_address = 0x6c, /* (0xd8 >> 1) */
  968. .ts_mode = 0x38,
  969. };
  970. static struct tda18271_config tda18271_config = {
  971. .output_opt = TDA18271_OUTPUT_LT_OFF,
  972. .gate = TDA18271_GATE_DIGITAL,
  973. };
  974. static u8 m88rs2000_inittab[] = {
  975. DEMOD_WRITE, 0x9a, 0x30,
  976. DEMOD_WRITE, 0x00, 0x01,
  977. WRITE_DELAY, 0x19, 0x00,
  978. DEMOD_WRITE, 0x00, 0x00,
  979. DEMOD_WRITE, 0x9a, 0xb0,
  980. DEMOD_WRITE, 0x81, 0xc1,
  981. DEMOD_WRITE, 0x81, 0x81,
  982. DEMOD_WRITE, 0x86, 0xc6,
  983. DEMOD_WRITE, 0x9a, 0x30,
  984. DEMOD_WRITE, 0xf0, 0x80,
  985. DEMOD_WRITE, 0xf1, 0xbf,
  986. DEMOD_WRITE, 0xb0, 0x45,
  987. DEMOD_WRITE, 0xb2, 0x01,
  988. DEMOD_WRITE, 0x9a, 0xb0,
  989. 0xff, 0xaa, 0xff
  990. };
  991. static struct m88rs2000_config s421_m88rs2000_config = {
  992. .demod_addr = 0x68,
  993. .inittab = m88rs2000_inittab,
  994. };
  995. static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
  996. {
  997. struct dvb_tuner_ops *tuner_ops = NULL;
  998. if (demod_probe & 4) {
  999. d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
  1000. &d->dev->i2c_adap, 0);
  1001. if (d->fe_adap[0].fe != NULL) {
  1002. if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
  1003. &dw2104a_stb6100_config,
  1004. &d->dev->i2c_adap)) {
  1005. tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
  1006. tuner_ops->set_frequency = stb6100_set_freq;
  1007. tuner_ops->get_frequency = stb6100_get_freq;
  1008. tuner_ops->set_bandwidth = stb6100_set_bandw;
  1009. tuner_ops->get_bandwidth = stb6100_get_bandw;
  1010. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1011. info("Attached STV0900+STB6100!\n");
  1012. return 0;
  1013. }
  1014. }
  1015. }
  1016. if (demod_probe & 2) {
  1017. d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
  1018. &d->dev->i2c_adap, 0);
  1019. if (d->fe_adap[0].fe != NULL) {
  1020. if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
  1021. &dw2104_stv6110_config,
  1022. &d->dev->i2c_adap)) {
  1023. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1024. info("Attached STV0900+STV6110A!\n");
  1025. return 0;
  1026. }
  1027. }
  1028. }
  1029. if (demod_probe & 1) {
  1030. d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
  1031. &d->dev->i2c_adap);
  1032. if (d->fe_adap[0].fe != NULL) {
  1033. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1034. info("Attached cx24116!\n");
  1035. return 0;
  1036. }
  1037. }
  1038. d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
  1039. &d->dev->i2c_adap);
  1040. if (d->fe_adap[0].fe != NULL) {
  1041. dvb_attach(ts2020_attach, d->fe_adap[0].fe,
  1042. &dw2104_ts2020_config, &d->dev->i2c_adap);
  1043. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1044. info("Attached DS3000!\n");
  1045. return 0;
  1046. }
  1047. return -EIO;
  1048. }
  1049. static struct dvb_usb_device_properties dw2102_properties;
  1050. static struct dvb_usb_device_properties dw2104_properties;
  1051. static struct dvb_usb_device_properties s6x0_properties;
  1052. static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
  1053. {
  1054. if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
  1055. /*dw2102_properties.adapter->tuner_attach = NULL;*/
  1056. d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
  1057. &d->dev->i2c_adap);
  1058. if (d->fe_adap[0].fe != NULL) {
  1059. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1060. info("Attached si21xx!\n");
  1061. return 0;
  1062. }
  1063. }
  1064. if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
  1065. d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
  1066. &d->dev->i2c_adap);
  1067. if (d->fe_adap[0].fe != NULL) {
  1068. if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
  1069. &d->dev->i2c_adap)) {
  1070. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1071. info("Attached stv0288!\n");
  1072. return 0;
  1073. }
  1074. }
  1075. }
  1076. if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
  1077. /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
  1078. d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
  1079. &d->dev->i2c_adap);
  1080. if (d->fe_adap[0].fe != NULL) {
  1081. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1082. info("Attached stv0299!\n");
  1083. return 0;
  1084. }
  1085. }
  1086. return -EIO;
  1087. }
  1088. static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
  1089. {
  1090. d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
  1091. &d->dev->i2c_adap, 0x48);
  1092. if (d->fe_adap[0].fe != NULL) {
  1093. info("Attached tda10023!\n");
  1094. return 0;
  1095. }
  1096. return -EIO;
  1097. }
  1098. static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
  1099. {
  1100. d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
  1101. &d->dev->i2c_adap);
  1102. if (d->fe_adap[0].fe != NULL) {
  1103. if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
  1104. &d->dev->i2c_adap)) {
  1105. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1106. info("Attached zl100313+zl10039!\n");
  1107. return 0;
  1108. }
  1109. }
  1110. return -EIO;
  1111. }
  1112. static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
  1113. {
  1114. u8 obuf[] = {7, 1};
  1115. d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
  1116. &d->dev->i2c_adap);
  1117. if (d->fe_adap[0].fe == NULL)
  1118. return -EIO;
  1119. if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
  1120. return -EIO;
  1121. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1122. dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
  1123. info("Attached stv0288+stb6000!\n");
  1124. return 0;
  1125. }
  1126. static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
  1127. {
  1128. struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
  1129. u8 obuf[] = {7, 1};
  1130. d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
  1131. &d->dev->i2c_adap);
  1132. if (d->fe_adap[0].fe == NULL)
  1133. return -EIO;
  1134. dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
  1135. &d->dev->i2c_adap);
  1136. st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
  1137. d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
  1138. dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
  1139. info("Attached ds3000+ts2020!\n");
  1140. return 0;
  1141. }
  1142. static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
  1143. {
  1144. u8 obuf[] = {7, 1};
  1145. d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
  1146. &d->dev->i2c_adap, 0);
  1147. if (d->fe_adap[0].fe == NULL)
  1148. return -EIO;
  1149. d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
  1150. dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
  1151. info("Attached STV0900+STB6100A!\n");
  1152. return 0;
  1153. }
  1154. static int su3000_frontend_attach(struct dvb_usb_adapter *d)
  1155. {
  1156. u8 obuf[3] = { 0xe, 0x80, 0 };
  1157. u8 ibuf[] = { 0 };
  1158. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1159. err("command 0x0e transfer failed.");
  1160. obuf[0] = 0xe;
  1161. obuf[1] = 0x02;
  1162. obuf[2] = 1;
  1163. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1164. err("command 0x0e transfer failed.");
  1165. msleep(300);
  1166. obuf[0] = 0xe;
  1167. obuf[1] = 0x83;
  1168. obuf[2] = 0;
  1169. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1170. err("command 0x0e transfer failed.");
  1171. obuf[0] = 0xe;
  1172. obuf[1] = 0x83;
  1173. obuf[2] = 1;
  1174. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1175. err("command 0x0e transfer failed.");
  1176. obuf[0] = 0x51;
  1177. if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
  1178. err("command 0x51 transfer failed.");
  1179. d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
  1180. &d->dev->i2c_adap);
  1181. if (d->fe_adap[0].fe == NULL)
  1182. return -EIO;
  1183. if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
  1184. &dw2104_ts2020_config,
  1185. &d->dev->i2c_adap)) {
  1186. info("Attached DS3000/TS2020!\n");
  1187. return 0;
  1188. }
  1189. info("Failed to attach DS3000/TS2020!\n");
  1190. return -EIO;
  1191. }
  1192. static int t220_frontend_attach(struct dvb_usb_adapter *d)
  1193. {
  1194. u8 obuf[3] = { 0xe, 0x80, 0 };
  1195. u8 ibuf[] = { 0 };
  1196. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1197. err("command 0x0e transfer failed.");
  1198. obuf[0] = 0xe;
  1199. obuf[1] = 0x83;
  1200. obuf[2] = 0;
  1201. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1202. err("command 0x0e transfer failed.");
  1203. msleep(100);
  1204. obuf[0] = 0xe;
  1205. obuf[1] = 0x80;
  1206. obuf[2] = 1;
  1207. if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
  1208. err("command 0x0e transfer failed.");
  1209. obuf[0] = 0x51;
  1210. if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
  1211. err("command 0x51 transfer failed.");
  1212. d->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
  1213. &d->dev->i2c_adap, NULL);
  1214. if (d->fe_adap[0].fe != NULL) {
  1215. if (dvb_attach(tda18271_attach, d->fe_adap[0].fe, 0x60,
  1216. &d->dev->i2c_adap, &tda18271_config)) {
  1217. info("Attached TDA18271HD/CXD2820R!\n");
  1218. return 0;
  1219. }
  1220. }
  1221. info("Failed to attach TDA18271HD/CXD2820R!\n");
  1222. return -EIO;
  1223. }
  1224. static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d)
  1225. {
  1226. u8 obuf[] = { 0x51 };
  1227. u8 ibuf[] = { 0 };
  1228. if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
  1229. err("command 0x51 transfer failed.");
  1230. d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config,
  1231. &d->dev->i2c_adap);
  1232. if (d->fe_adap[0].fe == NULL)
  1233. return -EIO;
  1234. if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
  1235. &dw2104_ts2020_config,
  1236. &d->dev->i2c_adap)) {
  1237. info("Attached RS2000/TS2020!\n");
  1238. return 0;
  1239. }
  1240. info("Failed to attach RS2000/TS2020!\n");
  1241. return -EIO;
  1242. }
  1243. static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
  1244. {
  1245. dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
  1246. &adap->dev->i2c_adap, DVB_PLL_OPERA1);
  1247. return 0;
  1248. }
  1249. static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
  1250. {
  1251. dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
  1252. &adap->dev->i2c_adap, DVB_PLL_TUA6034);
  1253. return 0;
  1254. }
  1255. static int dw2102_rc_query(struct dvb_usb_device *d)
  1256. {
  1257. u8 key[2];
  1258. struct i2c_msg msg = {
  1259. .addr = DW2102_RC_QUERY,
  1260. .flags = I2C_M_RD,
  1261. .buf = key,
  1262. .len = 2
  1263. };
  1264. if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
  1265. if (msg.buf[0] != 0xff) {
  1266. deb_rc("%s: rc code: %x, %x\n",
  1267. __func__, key[0], key[1]);
  1268. rc_keydown(d->rc_dev, key[0], 1);
  1269. }
  1270. }
  1271. return 0;
  1272. }
  1273. static int prof_rc_query(struct dvb_usb_device *d)
  1274. {
  1275. u8 key[2];
  1276. struct i2c_msg msg = {
  1277. .addr = DW2102_RC_QUERY,
  1278. .flags = I2C_M_RD,
  1279. .buf = key,
  1280. .len = 2
  1281. };
  1282. if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
  1283. if (msg.buf[0] != 0xff) {
  1284. deb_rc("%s: rc code: %x, %x\n",
  1285. __func__, key[0], key[1]);
  1286. rc_keydown(d->rc_dev, key[0]^0xff, 1);
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. static int su3000_rc_query(struct dvb_usb_device *d)
  1292. {
  1293. u8 key[2];
  1294. struct i2c_msg msg = {
  1295. .addr = DW2102_RC_QUERY,
  1296. .flags = I2C_M_RD,
  1297. .buf = key,
  1298. .len = 2
  1299. };
  1300. if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
  1301. if (msg.buf[0] != 0xff) {
  1302. deb_rc("%s: rc code: %x, %x\n",
  1303. __func__, key[0], key[1]);
  1304. rc_keydown(d->rc_dev, key[1] << 8 | key[0], 1);
  1305. }
  1306. }
  1307. return 0;
  1308. }
  1309. enum dw2102_table_entry {
  1310. CYPRESS_DW2102,
  1311. CYPRESS_DW2101,
  1312. CYPRESS_DW2104,
  1313. TEVII_S650,
  1314. TERRATEC_CINERGY_S,
  1315. CYPRESS_DW3101,
  1316. TEVII_S630,
  1317. PROF_1100,
  1318. TEVII_S660,
  1319. PROF_7500,
  1320. GENIATECH_SU3000,
  1321. TERRATEC_CINERGY_S2,
  1322. TEVII_S480_1,
  1323. TEVII_S480_2,
  1324. X3M_SPC1400HD,
  1325. TEVII_S421,
  1326. TEVII_S632,
  1327. TERRATEC_CINERGY_S2_R2,
  1328. GOTVIEW_SAT_HD,
  1329. GENIATECH_T220,
  1330. };
  1331. static struct usb_device_id dw2102_table[] = {
  1332. [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
  1333. [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
  1334. [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
  1335. [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
  1336. [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
  1337. [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
  1338. [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
  1339. [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
  1340. [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
  1341. [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
  1342. [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
  1343. [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
  1344. [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
  1345. [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
  1346. [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
  1347. [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
  1348. [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
  1349. [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00b0)},
  1350. [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
  1351. [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
  1352. { }
  1353. };
  1354. MODULE_DEVICE_TABLE(usb, dw2102_table);
  1355. static int dw2102_load_firmware(struct usb_device *dev,
  1356. const struct firmware *frmwr)
  1357. {
  1358. u8 *b, *p;
  1359. int ret = 0, i;
  1360. u8 reset;
  1361. u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
  1362. const struct firmware *fw;
  1363. switch (dev->descriptor.idProduct) {
  1364. case 0x2101:
  1365. ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
  1366. if (ret != 0) {
  1367. err(err_str, DW2101_FIRMWARE);
  1368. return ret;
  1369. }
  1370. break;
  1371. default:
  1372. fw = frmwr;
  1373. break;
  1374. }
  1375. info("start downloading DW210X firmware");
  1376. p = kmalloc(fw->size, GFP_KERNEL);
  1377. reset = 1;
  1378. /*stop the CPU*/
  1379. dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
  1380. dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
  1381. if (p != NULL) {
  1382. memcpy(p, fw->data, fw->size);
  1383. for (i = 0; i < fw->size; i += 0x40) {
  1384. b = (u8 *) p + i;
  1385. if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
  1386. DW210X_WRITE_MSG) != 0x40) {
  1387. err("error while transferring firmware");
  1388. ret = -EINVAL;
  1389. break;
  1390. }
  1391. }
  1392. /* restart the CPU */
  1393. reset = 0;
  1394. if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
  1395. DW210X_WRITE_MSG) != 1) {
  1396. err("could not restart the USB controller CPU.");
  1397. ret = -EINVAL;
  1398. }
  1399. if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
  1400. DW210X_WRITE_MSG) != 1) {
  1401. err("could not restart the USB controller CPU.");
  1402. ret = -EINVAL;
  1403. }
  1404. /* init registers */
  1405. switch (dev->descriptor.idProduct) {
  1406. case USB_PID_TEVII_S650:
  1407. dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
  1408. case USB_PID_DW2104:
  1409. reset = 1;
  1410. dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
  1411. DW210X_WRITE_MSG);
  1412. /* break omitted intentionally */
  1413. case USB_PID_DW3101:
  1414. reset = 0;
  1415. dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
  1416. DW210X_WRITE_MSG);
  1417. break;
  1418. case USB_PID_CINERGY_S:
  1419. case USB_PID_DW2102:
  1420. dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
  1421. DW210X_WRITE_MSG);
  1422. dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
  1423. DW210X_READ_MSG);
  1424. /* check STV0299 frontend */
  1425. dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
  1426. DW210X_READ_MSG);
  1427. if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
  1428. dw2102_properties.i2c_algo = &dw2102_i2c_algo;
  1429. dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
  1430. break;
  1431. } else {
  1432. /* check STV0288 frontend */
  1433. reset16[0] = 0xd0;
  1434. reset16[1] = 1;
  1435. reset16[2] = 0;
  1436. dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
  1437. DW210X_WRITE_MSG);
  1438. dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
  1439. DW210X_READ_MSG);
  1440. if (reset16[2] == 0x11) {
  1441. dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
  1442. break;
  1443. }
  1444. }
  1445. case 0x2101:
  1446. dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
  1447. DW210X_READ_MSG);
  1448. dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
  1449. DW210X_READ_MSG);
  1450. dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
  1451. DW210X_READ_MSG);
  1452. dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
  1453. DW210X_READ_MSG);
  1454. break;
  1455. }
  1456. msleep(100);
  1457. kfree(p);
  1458. }
  1459. return ret;
  1460. }
  1461. static struct dvb_usb_device_properties dw2102_properties = {
  1462. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1463. .usb_ctrl = DEVICE_SPECIFIC,
  1464. .firmware = DW2102_FIRMWARE,
  1465. .no_reconnect = 1,
  1466. .i2c_algo = &dw2102_serit_i2c_algo,
  1467. .rc.core = {
  1468. .rc_interval = 150,
  1469. .rc_codes = RC_MAP_DM1105_NEC,
  1470. .module_name = "dw2102",
  1471. .allowed_protos = RC_BIT_NEC,
  1472. .rc_query = dw2102_rc_query,
  1473. },
  1474. .generic_bulk_ctrl_endpoint = 0x81,
  1475. /* parameter for the MPEG2-data transfer */
  1476. .num_adapters = 1,
  1477. .download_firmware = dw2102_load_firmware,
  1478. .read_mac_address = dw210x_read_mac_address,
  1479. .adapter = {
  1480. {
  1481. .num_frontends = 1,
  1482. .fe = {{
  1483. .frontend_attach = dw2102_frontend_attach,
  1484. .stream = {
  1485. .type = USB_BULK,
  1486. .count = 8,
  1487. .endpoint = 0x82,
  1488. .u = {
  1489. .bulk = {
  1490. .buffersize = 4096,
  1491. }
  1492. }
  1493. },
  1494. }},
  1495. }
  1496. },
  1497. .num_device_descs = 3,
  1498. .devices = {
  1499. {"DVBWorld DVB-S 2102 USB2.0",
  1500. {&dw2102_table[CYPRESS_DW2102], NULL},
  1501. {NULL},
  1502. },
  1503. {"DVBWorld DVB-S 2101 USB2.0",
  1504. {&dw2102_table[CYPRESS_DW2101], NULL},
  1505. {NULL},
  1506. },
  1507. {"TerraTec Cinergy S USB",
  1508. {&dw2102_table[TERRATEC_CINERGY_S], NULL},
  1509. {NULL},
  1510. },
  1511. }
  1512. };
  1513. static struct dvb_usb_device_properties dw2104_properties = {
  1514. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1515. .usb_ctrl = DEVICE_SPECIFIC,
  1516. .firmware = DW2104_FIRMWARE,
  1517. .no_reconnect = 1,
  1518. .i2c_algo = &dw2104_i2c_algo,
  1519. .rc.core = {
  1520. .rc_interval = 150,
  1521. .rc_codes = RC_MAP_DM1105_NEC,
  1522. .module_name = "dw2102",
  1523. .allowed_protos = RC_BIT_NEC,
  1524. .rc_query = dw2102_rc_query,
  1525. },
  1526. .generic_bulk_ctrl_endpoint = 0x81,
  1527. /* parameter for the MPEG2-data transfer */
  1528. .num_adapters = 1,
  1529. .download_firmware = dw2102_load_firmware,
  1530. .read_mac_address = dw210x_read_mac_address,
  1531. .adapter = {
  1532. {
  1533. .num_frontends = 1,
  1534. .fe = {{
  1535. .frontend_attach = dw2104_frontend_attach,
  1536. .stream = {
  1537. .type = USB_BULK,
  1538. .count = 8,
  1539. .endpoint = 0x82,
  1540. .u = {
  1541. .bulk = {
  1542. .buffersize = 4096,
  1543. }
  1544. }
  1545. },
  1546. }},
  1547. }
  1548. },
  1549. .num_device_descs = 2,
  1550. .devices = {
  1551. { "DVBWorld DW2104 USB2.0",
  1552. {&dw2102_table[CYPRESS_DW2104], NULL},
  1553. {NULL},
  1554. },
  1555. { "TeVii S650 USB2.0",
  1556. {&dw2102_table[TEVII_S650], NULL},
  1557. {NULL},
  1558. },
  1559. }
  1560. };
  1561. static struct dvb_usb_device_properties dw3101_properties = {
  1562. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1563. .usb_ctrl = DEVICE_SPECIFIC,
  1564. .firmware = DW3101_FIRMWARE,
  1565. .no_reconnect = 1,
  1566. .i2c_algo = &dw3101_i2c_algo,
  1567. .rc.core = {
  1568. .rc_interval = 150,
  1569. .rc_codes = RC_MAP_DM1105_NEC,
  1570. .module_name = "dw2102",
  1571. .allowed_protos = RC_BIT_NEC,
  1572. .rc_query = dw2102_rc_query,
  1573. },
  1574. .generic_bulk_ctrl_endpoint = 0x81,
  1575. /* parameter for the MPEG2-data transfer */
  1576. .num_adapters = 1,
  1577. .download_firmware = dw2102_load_firmware,
  1578. .read_mac_address = dw210x_read_mac_address,
  1579. .adapter = {
  1580. {
  1581. .num_frontends = 1,
  1582. .fe = {{
  1583. .frontend_attach = dw3101_frontend_attach,
  1584. .tuner_attach = dw3101_tuner_attach,
  1585. .stream = {
  1586. .type = USB_BULK,
  1587. .count = 8,
  1588. .endpoint = 0x82,
  1589. .u = {
  1590. .bulk = {
  1591. .buffersize = 4096,
  1592. }
  1593. }
  1594. },
  1595. }},
  1596. }
  1597. },
  1598. .num_device_descs = 1,
  1599. .devices = {
  1600. { "DVBWorld DVB-C 3101 USB2.0",
  1601. {&dw2102_table[CYPRESS_DW3101], NULL},
  1602. {NULL},
  1603. },
  1604. }
  1605. };
  1606. static struct dvb_usb_device_properties s6x0_properties = {
  1607. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1608. .usb_ctrl = DEVICE_SPECIFIC,
  1609. .size_of_priv = sizeof(struct s6x0_state),
  1610. .firmware = S630_FIRMWARE,
  1611. .no_reconnect = 1,
  1612. .i2c_algo = &s6x0_i2c_algo,
  1613. .rc.core = {
  1614. .rc_interval = 150,
  1615. .rc_codes = RC_MAP_TEVII_NEC,
  1616. .module_name = "dw2102",
  1617. .allowed_protos = RC_BIT_NEC,
  1618. .rc_query = dw2102_rc_query,
  1619. },
  1620. .generic_bulk_ctrl_endpoint = 0x81,
  1621. .num_adapters = 1,
  1622. .download_firmware = dw2102_load_firmware,
  1623. .read_mac_address = s6x0_read_mac_address,
  1624. .adapter = {
  1625. {
  1626. .num_frontends = 1,
  1627. .fe = {{
  1628. .frontend_attach = zl100313_frontend_attach,
  1629. .stream = {
  1630. .type = USB_BULK,
  1631. .count = 8,
  1632. .endpoint = 0x82,
  1633. .u = {
  1634. .bulk = {
  1635. .buffersize = 4096,
  1636. }
  1637. }
  1638. },
  1639. }},
  1640. }
  1641. },
  1642. .num_device_descs = 1,
  1643. .devices = {
  1644. {"TeVii S630 USB",
  1645. {&dw2102_table[TEVII_S630], NULL},
  1646. {NULL},
  1647. },
  1648. }
  1649. };
  1650. struct dvb_usb_device_properties *p1100;
  1651. static struct dvb_usb_device_description d1100 = {
  1652. "Prof 1100 USB ",
  1653. {&dw2102_table[PROF_1100], NULL},
  1654. {NULL},
  1655. };
  1656. struct dvb_usb_device_properties *s660;
  1657. static struct dvb_usb_device_description d660 = {
  1658. "TeVii S660 USB",
  1659. {&dw2102_table[TEVII_S660], NULL},
  1660. {NULL},
  1661. };
  1662. static struct dvb_usb_device_description d480_1 = {
  1663. "TeVii S480.1 USB",
  1664. {&dw2102_table[TEVII_S480_1], NULL},
  1665. {NULL},
  1666. };
  1667. static struct dvb_usb_device_description d480_2 = {
  1668. "TeVii S480.2 USB",
  1669. {&dw2102_table[TEVII_S480_2], NULL},
  1670. {NULL},
  1671. };
  1672. struct dvb_usb_device_properties *p7500;
  1673. static struct dvb_usb_device_description d7500 = {
  1674. "Prof 7500 USB DVB-S2",
  1675. {&dw2102_table[PROF_7500], NULL},
  1676. {NULL},
  1677. };
  1678. struct dvb_usb_device_properties *s421;
  1679. static struct dvb_usb_device_description d421 = {
  1680. "TeVii S421 PCI",
  1681. {&dw2102_table[TEVII_S421], NULL},
  1682. {NULL},
  1683. };
  1684. static struct dvb_usb_device_description d632 = {
  1685. "TeVii S632 USB",
  1686. {&dw2102_table[TEVII_S632], NULL},
  1687. {NULL},
  1688. };
  1689. static struct dvb_usb_device_properties su3000_properties = {
  1690. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1691. .usb_ctrl = DEVICE_SPECIFIC,
  1692. .size_of_priv = sizeof(struct su3000_state),
  1693. .power_ctrl = su3000_power_ctrl,
  1694. .num_adapters = 1,
  1695. .identify_state = su3000_identify_state,
  1696. .i2c_algo = &su3000_i2c_algo,
  1697. .rc.core = {
  1698. .rc_interval = 150,
  1699. .rc_codes = RC_MAP_SU3000,
  1700. .module_name = "dw2102",
  1701. .allowed_protos = RC_BIT_RC5,
  1702. .rc_query = su3000_rc_query,
  1703. },
  1704. .read_mac_address = su3000_read_mac_address,
  1705. .generic_bulk_ctrl_endpoint = 0x01,
  1706. .adapter = {
  1707. {
  1708. .num_frontends = 1,
  1709. .fe = {{
  1710. .streaming_ctrl = su3000_streaming_ctrl,
  1711. .frontend_attach = su3000_frontend_attach,
  1712. .stream = {
  1713. .type = USB_BULK,
  1714. .count = 8,
  1715. .endpoint = 0x82,
  1716. .u = {
  1717. .bulk = {
  1718. .buffersize = 4096,
  1719. }
  1720. }
  1721. }
  1722. }},
  1723. }
  1724. },
  1725. .num_device_descs = 5,
  1726. .devices = {
  1727. { "SU3000HD DVB-S USB2.0",
  1728. { &dw2102_table[GENIATECH_SU3000], NULL },
  1729. { NULL },
  1730. },
  1731. { "Terratec Cinergy S2 USB HD",
  1732. { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
  1733. { NULL },
  1734. },
  1735. { "X3M TV SPC1400HD PCI",
  1736. { &dw2102_table[X3M_SPC1400HD], NULL },
  1737. { NULL },
  1738. },
  1739. { "Terratec Cinergy S2 USB HD Rev.2",
  1740. { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
  1741. { NULL },
  1742. },
  1743. { "GOTVIEW Satellite HD",
  1744. { &dw2102_table[GOTVIEW_SAT_HD], NULL },
  1745. { NULL },
  1746. },
  1747. }
  1748. };
  1749. static struct dvb_usb_device_properties t220_properties = {
  1750. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1751. .usb_ctrl = DEVICE_SPECIFIC,
  1752. .size_of_priv = sizeof(struct su3000_state),
  1753. .power_ctrl = su3000_power_ctrl,
  1754. .num_adapters = 1,
  1755. .identify_state = su3000_identify_state,
  1756. .i2c_algo = &su3000_i2c_algo,
  1757. .rc.core = {
  1758. .rc_interval = 150,
  1759. .rc_codes = RC_MAP_SU3000,
  1760. .module_name = "dw2102",
  1761. .allowed_protos = RC_BIT_RC5,
  1762. .rc_query = su3000_rc_query,
  1763. },
  1764. .read_mac_address = su3000_read_mac_address,
  1765. .generic_bulk_ctrl_endpoint = 0x01,
  1766. .adapter = {
  1767. {
  1768. .num_frontends = 1,
  1769. .fe = { {
  1770. .streaming_ctrl = su3000_streaming_ctrl,
  1771. .frontend_attach = t220_frontend_attach,
  1772. .stream = {
  1773. .type = USB_BULK,
  1774. .count = 8,
  1775. .endpoint = 0x82,
  1776. .u = {
  1777. .bulk = {
  1778. .buffersize = 4096,
  1779. }
  1780. }
  1781. }
  1782. } },
  1783. }
  1784. },
  1785. .num_device_descs = 1,
  1786. .devices = {
  1787. { "Geniatech T220 DVB-T/T2 USB2.0",
  1788. { &dw2102_table[GENIATECH_T220], NULL },
  1789. { NULL },
  1790. },
  1791. }
  1792. };
  1793. static int dw2102_probe(struct usb_interface *intf,
  1794. const struct usb_device_id *id)
  1795. {
  1796. p1100 = kmemdup(&s6x0_properties,
  1797. sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
  1798. if (!p1100)
  1799. return -ENOMEM;
  1800. /* copy default structure */
  1801. /* fill only different fields */
  1802. p1100->firmware = P1100_FIRMWARE;
  1803. p1100->devices[0] = d1100;
  1804. p1100->rc.core.rc_query = prof_rc_query;
  1805. p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
  1806. p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
  1807. s660 = kmemdup(&s6x0_properties,
  1808. sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
  1809. if (!s660) {
  1810. kfree(p1100);
  1811. return -ENOMEM;
  1812. }
  1813. s660->firmware = S660_FIRMWARE;
  1814. s660->num_device_descs = 3;
  1815. s660->devices[0] = d660;
  1816. s660->devices[1] = d480_1;
  1817. s660->devices[2] = d480_2;
  1818. s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
  1819. p7500 = kmemdup(&s6x0_properties,
  1820. sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
  1821. if (!p7500) {
  1822. kfree(p1100);
  1823. kfree(s660);
  1824. return -ENOMEM;
  1825. }
  1826. p7500->firmware = P7500_FIRMWARE;
  1827. p7500->devices[0] = d7500;
  1828. p7500->rc.core.rc_query = prof_rc_query;
  1829. p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
  1830. p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
  1831. s421 = kmemdup(&su3000_properties,
  1832. sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
  1833. if (!s421) {
  1834. kfree(p1100);
  1835. kfree(s660);
  1836. kfree(p7500);
  1837. return -ENOMEM;
  1838. }
  1839. s421->num_device_descs = 2;
  1840. s421->devices[0] = d421;
  1841. s421->devices[1] = d632;
  1842. s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
  1843. if (0 == dvb_usb_device_init(intf, &dw2102_properties,
  1844. THIS_MODULE, NULL, adapter_nr) ||
  1845. 0 == dvb_usb_device_init(intf, &dw2104_properties,
  1846. THIS_MODULE, NULL, adapter_nr) ||
  1847. 0 == dvb_usb_device_init(intf, &dw3101_properties,
  1848. THIS_MODULE, NULL, adapter_nr) ||
  1849. 0 == dvb_usb_device_init(intf, &s6x0_properties,
  1850. THIS_MODULE, NULL, adapter_nr) ||
  1851. 0 == dvb_usb_device_init(intf, p1100,
  1852. THIS_MODULE, NULL, adapter_nr) ||
  1853. 0 == dvb_usb_device_init(intf, s660,
  1854. THIS_MODULE, NULL, adapter_nr) ||
  1855. 0 == dvb_usb_device_init(intf, p7500,
  1856. THIS_MODULE, NULL, adapter_nr) ||
  1857. 0 == dvb_usb_device_init(intf, s421,
  1858. THIS_MODULE, NULL, adapter_nr) ||
  1859. 0 == dvb_usb_device_init(intf, &su3000_properties,
  1860. THIS_MODULE, NULL, adapter_nr) ||
  1861. 0 == dvb_usb_device_init(intf, &t220_properties,
  1862. THIS_MODULE, NULL, adapter_nr))
  1863. return 0;
  1864. return -ENODEV;
  1865. }
  1866. static struct usb_driver dw2102_driver = {
  1867. .name = "dw2102",
  1868. .probe = dw2102_probe,
  1869. .disconnect = dvb_usb_device_exit,
  1870. .id_table = dw2102_table,
  1871. };
  1872. module_usb_driver(dw2102_driver);
  1873. MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
  1874. MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
  1875. " DVB-C 3101 USB2.0,"
  1876. " TeVii S600, S630, S650, S660, S480, S421, S632"
  1877. " Prof 1100, 7500 USB2.0,"
  1878. " Geniatech SU3000, T220 devices");
  1879. MODULE_VERSION("0.1");
  1880. MODULE_LICENSE("GPL");
  1881. MODULE_FIRMWARE(DW2101_FIRMWARE);
  1882. MODULE_FIRMWARE(DW2102_FIRMWARE);
  1883. MODULE_FIRMWARE(DW2104_FIRMWARE);
  1884. MODULE_FIRMWARE(DW3101_FIRMWARE);
  1885. MODULE_FIRMWARE(S630_FIRMWARE);
  1886. MODULE_FIRMWARE(S660_FIRMWARE);
  1887. MODULE_FIRMWARE(P1100_FIRMWARE);
  1888. MODULE_FIRMWARE(P7500_FIRMWARE);