dw2102.c 58 KB

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