dw2102.c 61 KB

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