dw2102.c 58 KB

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