dw2102.c 62 KB

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