cx23885-dvb.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/device.h>
  20. #include <linux/fs.h>
  21. #include <linux/kthread.h>
  22. #include <linux/file.h>
  23. #include <linux/suspend.h>
  24. #include "cx23885.h"
  25. #include <media/v4l2-common.h>
  26. #include "dvb_ca_en50221.h"
  27. #include "s5h1409.h"
  28. #include "s5h1411.h"
  29. #include "mt2131.h"
  30. #include "tda8290.h"
  31. #include "tda18271.h"
  32. #include "lgdt330x.h"
  33. #include "xc4000.h"
  34. #include "xc5000.h"
  35. #include "max2165.h"
  36. #include "tda10048.h"
  37. #include "tuner-xc2028.h"
  38. #include "tuner-simple.h"
  39. #include "dib7000p.h"
  40. #include "dib0070.h"
  41. #include "dibx000_common.h"
  42. #include "zl10353.h"
  43. #include "stv0900.h"
  44. #include "stv0900_reg.h"
  45. #include "stv6110.h"
  46. #include "lnbh24.h"
  47. #include "cx24116.h"
  48. #include "cx24117.h"
  49. #include "cimax2.h"
  50. #include "lgs8gxx.h"
  51. #include "netup-eeprom.h"
  52. #include "netup-init.h"
  53. #include "lgdt3305.h"
  54. #include "atbm8830.h"
  55. #include "ts2020.h"
  56. #include "ds3000.h"
  57. #include "cx23885-f300.h"
  58. #include "altera-ci.h"
  59. #include "stv0367.h"
  60. #include "drxk.h"
  61. #include "mt2063.h"
  62. #include "stv090x.h"
  63. #include "stb6100.h"
  64. #include "stb6100_cfg.h"
  65. #include "tda10071.h"
  66. #include "a8293.h"
  67. #include "mb86a20s.h"
  68. #include "si2165.h"
  69. #include "si2168.h"
  70. #include "si2157.h"
  71. #include "sp2.h"
  72. #include "m88ds3103.h"
  73. #include "m88rs6000t.h"
  74. #include "lgdt3306a.h"
  75. static unsigned int debug;
  76. #define dprintk(level, fmt, arg...)\
  77. do { if (debug >= level)\
  78. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  79. } while (0)
  80. /* ------------------------------------------------------------------ */
  81. static unsigned int alt_tuner;
  82. module_param(alt_tuner, int, 0644);
  83. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  84. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  85. /* ------------------------------------------------------------------ */
  86. static int queue_setup(struct vb2_queue *q,
  87. unsigned int *num_buffers, unsigned int *num_planes,
  88. unsigned int sizes[], struct device *alloc_devs[])
  89. {
  90. struct cx23885_tsport *port = q->drv_priv;
  91. port->ts_packet_size = 188 * 4;
  92. port->ts_packet_count = 32;
  93. *num_planes = 1;
  94. sizes[0] = port->ts_packet_size * port->ts_packet_count;
  95. *num_buffers = 32;
  96. return 0;
  97. }
  98. static int buffer_prepare(struct vb2_buffer *vb)
  99. {
  100. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  101. struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
  102. struct cx23885_buffer *buf =
  103. container_of(vbuf, struct cx23885_buffer, vb);
  104. return cx23885_buf_prepare(buf, port);
  105. }
  106. static void buffer_finish(struct vb2_buffer *vb)
  107. {
  108. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  109. struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
  110. struct cx23885_dev *dev = port->dev;
  111. struct cx23885_buffer *buf = container_of(vbuf,
  112. struct cx23885_buffer, vb);
  113. cx23885_free_buffer(dev, buf);
  114. }
  115. static void buffer_queue(struct vb2_buffer *vb)
  116. {
  117. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  118. struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
  119. struct cx23885_buffer *buf = container_of(vbuf,
  120. struct cx23885_buffer, vb);
  121. cx23885_buf_queue(port, buf);
  122. }
  123. static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)
  124. {
  125. struct vb2_dvb_frontends *f;
  126. struct vb2_dvb_frontend *fe;
  127. f = &port->frontends;
  128. if (f->gate <= 1) /* undefined or fe0 */
  129. fe = vb2_dvb_get_frontend(f, 1);
  130. else
  131. fe = vb2_dvb_get_frontend(f, f->gate);
  132. if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
  133. fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
  134. }
  135. static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count)
  136. {
  137. struct cx23885_tsport *port = q->drv_priv;
  138. struct cx23885_dmaqueue *dmaq = &port->mpegq;
  139. struct cx23885_buffer *buf = list_entry(dmaq->active.next,
  140. struct cx23885_buffer, queue);
  141. cx23885_start_dma(port, dmaq, buf);
  142. return 0;
  143. }
  144. static void cx23885_stop_streaming(struct vb2_queue *q)
  145. {
  146. struct cx23885_tsport *port = q->drv_priv;
  147. cx23885_cancel_buffers(port);
  148. }
  149. static const struct vb2_ops dvb_qops = {
  150. .queue_setup = queue_setup,
  151. .buf_prepare = buffer_prepare,
  152. .buf_finish = buffer_finish,
  153. .buf_queue = buffer_queue,
  154. .wait_prepare = vb2_ops_wait_prepare,
  155. .wait_finish = vb2_ops_wait_finish,
  156. .start_streaming = cx23885_start_streaming,
  157. .stop_streaming = cx23885_stop_streaming,
  158. };
  159. static struct s5h1409_config hauppauge_generic_config = {
  160. .demod_address = 0x32 >> 1,
  161. .output_mode = S5H1409_SERIAL_OUTPUT,
  162. .gpio = S5H1409_GPIO_ON,
  163. .qam_if = 44000,
  164. .inversion = S5H1409_INVERSION_OFF,
  165. .status_mode = S5H1409_DEMODLOCKING,
  166. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  167. };
  168. static struct tda10048_config hauppauge_hvr1200_config = {
  169. .demod_address = 0x10 >> 1,
  170. .output_mode = TDA10048_SERIAL_OUTPUT,
  171. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  172. .inversion = TDA10048_INVERSION_ON,
  173. .dtv6_if_freq_khz = TDA10048_IF_3300,
  174. .dtv7_if_freq_khz = TDA10048_IF_3800,
  175. .dtv8_if_freq_khz = TDA10048_IF_4300,
  176. .clk_freq_khz = TDA10048_CLK_16000,
  177. };
  178. static struct tda10048_config hauppauge_hvr1210_config = {
  179. .demod_address = 0x10 >> 1,
  180. .output_mode = TDA10048_SERIAL_OUTPUT,
  181. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  182. .inversion = TDA10048_INVERSION_ON,
  183. .dtv6_if_freq_khz = TDA10048_IF_3300,
  184. .dtv7_if_freq_khz = TDA10048_IF_3500,
  185. .dtv8_if_freq_khz = TDA10048_IF_4000,
  186. .clk_freq_khz = TDA10048_CLK_16000,
  187. };
  188. static struct s5h1409_config hauppauge_ezqam_config = {
  189. .demod_address = 0x32 >> 1,
  190. .output_mode = S5H1409_SERIAL_OUTPUT,
  191. .gpio = S5H1409_GPIO_OFF,
  192. .qam_if = 4000,
  193. .inversion = S5H1409_INVERSION_ON,
  194. .status_mode = S5H1409_DEMODLOCKING,
  195. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  196. };
  197. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  198. .demod_address = 0x32 >> 1,
  199. .output_mode = S5H1409_SERIAL_OUTPUT,
  200. .gpio = S5H1409_GPIO_OFF,
  201. .qam_if = 44000,
  202. .inversion = S5H1409_INVERSION_OFF,
  203. .status_mode = S5H1409_DEMODLOCKING,
  204. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  205. };
  206. static struct s5h1409_config hauppauge_hvr1500_config = {
  207. .demod_address = 0x32 >> 1,
  208. .output_mode = S5H1409_SERIAL_OUTPUT,
  209. .gpio = S5H1409_GPIO_OFF,
  210. .inversion = S5H1409_INVERSION_OFF,
  211. .status_mode = S5H1409_DEMODLOCKING,
  212. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  213. };
  214. static struct mt2131_config hauppauge_generic_tunerconfig = {
  215. 0x61
  216. };
  217. static struct lgdt330x_config fusionhdtv_5_express = {
  218. .demod_address = 0x0e,
  219. .demod_chip = LGDT3303,
  220. .serial_mpeg = 0x40,
  221. };
  222. static struct s5h1409_config hauppauge_hvr1500q_config = {
  223. .demod_address = 0x32 >> 1,
  224. .output_mode = S5H1409_SERIAL_OUTPUT,
  225. .gpio = S5H1409_GPIO_ON,
  226. .qam_if = 44000,
  227. .inversion = S5H1409_INVERSION_OFF,
  228. .status_mode = S5H1409_DEMODLOCKING,
  229. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  230. };
  231. static struct s5h1409_config dvico_s5h1409_config = {
  232. .demod_address = 0x32 >> 1,
  233. .output_mode = S5H1409_SERIAL_OUTPUT,
  234. .gpio = S5H1409_GPIO_ON,
  235. .qam_if = 44000,
  236. .inversion = S5H1409_INVERSION_OFF,
  237. .status_mode = S5H1409_DEMODLOCKING,
  238. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  239. };
  240. static struct s5h1411_config dvico_s5h1411_config = {
  241. .output_mode = S5H1411_SERIAL_OUTPUT,
  242. .gpio = S5H1411_GPIO_ON,
  243. .qam_if = S5H1411_IF_44000,
  244. .vsb_if = S5H1411_IF_44000,
  245. .inversion = S5H1411_INVERSION_OFF,
  246. .status_mode = S5H1411_DEMODLOCKING,
  247. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  248. };
  249. static struct s5h1411_config hcw_s5h1411_config = {
  250. .output_mode = S5H1411_SERIAL_OUTPUT,
  251. .gpio = S5H1411_GPIO_OFF,
  252. .vsb_if = S5H1411_IF_44000,
  253. .qam_if = S5H1411_IF_4000,
  254. .inversion = S5H1411_INVERSION_ON,
  255. .status_mode = S5H1411_DEMODLOCKING,
  256. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  257. };
  258. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  259. .i2c_address = 0x61,
  260. .if_khz = 5380,
  261. };
  262. static struct xc5000_config dvico_xc5000_tunerconfig = {
  263. .i2c_address = 0x64,
  264. .if_khz = 5380,
  265. };
  266. static struct tda829x_config tda829x_no_probe = {
  267. .probe_tuner = TDA829X_DONT_PROBE,
  268. };
  269. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  270. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  271. .if_lvl = 6, .rfagc_top = 0x37 },
  272. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  273. .if_lvl = 6, .rfagc_top = 0x37 },
  274. };
  275. static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
  276. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  277. .if_lvl = 1, .rfagc_top = 0x37, },
  278. .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
  279. .if_lvl = 1, .rfagc_top = 0x37, },
  280. .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
  281. .if_lvl = 1, .rfagc_top = 0x37, },
  282. };
  283. static struct tda18271_config hauppauge_tda18271_config = {
  284. .std_map = &hauppauge_tda18271_std_map,
  285. .gate = TDA18271_GATE_ANALOG,
  286. .output_opt = TDA18271_OUTPUT_LT_OFF,
  287. };
  288. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  289. .std_map = &hauppauge_hvr1200_tda18271_std_map,
  290. .gate = TDA18271_GATE_ANALOG,
  291. .output_opt = TDA18271_OUTPUT_LT_OFF,
  292. };
  293. static struct tda18271_config hauppauge_hvr1210_tuner_config = {
  294. .gate = TDA18271_GATE_DIGITAL,
  295. .output_opt = TDA18271_OUTPUT_LT_OFF,
  296. };
  297. static struct tda18271_config hauppauge_hvr4400_tuner_config = {
  298. .gate = TDA18271_GATE_DIGITAL,
  299. .output_opt = TDA18271_OUTPUT_LT_OFF,
  300. };
  301. static struct tda18271_std_map hauppauge_hvr127x_std_map = {
  302. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
  303. .if_lvl = 1, .rfagc_top = 0x58 },
  304. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  305. .if_lvl = 1, .rfagc_top = 0x58 },
  306. };
  307. static struct tda18271_config hauppauge_hvr127x_config = {
  308. .std_map = &hauppauge_hvr127x_std_map,
  309. .output_opt = TDA18271_OUTPUT_LT_OFF,
  310. };
  311. static struct lgdt3305_config hauppauge_lgdt3305_config = {
  312. .i2c_addr = 0x0e,
  313. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  314. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  315. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  316. .deny_i2c_rptr = 1,
  317. .spectral_inversion = 1,
  318. .qam_if_khz = 4000,
  319. .vsb_if_khz = 3250,
  320. };
  321. static struct dibx000_agc_config xc3028_agc_config = {
  322. BAND_VHF | BAND_UHF, /* band_caps */
  323. /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
  324. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
  325. * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
  326. * P_agc_nb_est=2, P_agc_write=0
  327. */
  328. (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
  329. (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
  330. 712, /* inv_gain */
  331. 21, /* time_stabiliz */
  332. 0, /* alpha_level */
  333. 118, /* thlock */
  334. 0, /* wbd_inv */
  335. 2867, /* wbd_ref */
  336. 0, /* wbd_sel */
  337. 2, /* wbd_alpha */
  338. 0, /* agc1_max */
  339. 0, /* agc1_min */
  340. 39718, /* agc2_max */
  341. 9930, /* agc2_min */
  342. 0, /* agc1_pt1 */
  343. 0, /* agc1_pt2 */
  344. 0, /* agc1_pt3 */
  345. 0, /* agc1_slope1 */
  346. 0, /* agc1_slope2 */
  347. 0, /* agc2_pt1 */
  348. 128, /* agc2_pt2 */
  349. 29, /* agc2_slope1 */
  350. 29, /* agc2_slope2 */
  351. 17, /* alpha_mant */
  352. 27, /* alpha_exp */
  353. 23, /* beta_mant */
  354. 51, /* beta_exp */
  355. 1, /* perform_agc_softsplit */
  356. };
  357. /* PLL Configuration for COFDM BW_MHz = 8.000000
  358. * With external clock = 30.000000 */
  359. static struct dibx000_bandwidth_config xc3028_bw_config = {
  360. 60000, /* internal */
  361. 30000, /* sampling */
  362. 1, /* pll_cfg: prediv */
  363. 8, /* pll_cfg: ratio */
  364. 3, /* pll_cfg: range */
  365. 1, /* pll_cfg: reset */
  366. 0, /* pll_cfg: bypass */
  367. 0, /* misc: refdiv */
  368. 0, /* misc: bypclk_div */
  369. 1, /* misc: IO_CLK_en_core */
  370. 1, /* misc: ADClkSrc */
  371. 0, /* misc: modulo */
  372. (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
  373. (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
  374. 20452225, /* timf */
  375. 30000000 /* xtal_hz */
  376. };
  377. static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
  378. .output_mpeg2_in_188_bytes = 1,
  379. .hostbus_diversity = 1,
  380. .tuner_is_baseband = 0,
  381. .update_lna = NULL,
  382. .agc_config_count = 1,
  383. .agc = &xc3028_agc_config,
  384. .bw = &xc3028_bw_config,
  385. .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
  386. .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
  387. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  388. .pwm_freq_div = 0,
  389. .agc_control = NULL,
  390. .spur_protect = 0,
  391. .output_mode = OUTMODE_MPEG2_SERIAL,
  392. };
  393. static struct zl10353_config dvico_fusionhdtv_xc3028 = {
  394. .demod_address = 0x0f,
  395. .if2 = 45600,
  396. .no_tuner = 1,
  397. .disable_i2c_gate_ctrl = 1,
  398. };
  399. static struct stv0900_reg stv0900_ts_regs[] = {
  400. { R0900_TSGENERAL, 0x00 },
  401. { R0900_P1_TSSPEED, 0x40 },
  402. { R0900_P2_TSSPEED, 0x40 },
  403. { R0900_P1_TSCFGM, 0xc0 },
  404. { R0900_P2_TSCFGM, 0xc0 },
  405. { R0900_P1_TSCFGH, 0xe0 },
  406. { R0900_P2_TSCFGH, 0xe0 },
  407. { R0900_P1_TSCFGL, 0x20 },
  408. { R0900_P2_TSCFGL, 0x20 },
  409. { 0xffff, 0xff }, /* terminate */
  410. };
  411. static struct stv0900_config netup_stv0900_config = {
  412. .demod_address = 0x68,
  413. .demod_mode = 1, /* dual */
  414. .xtal = 8000000,
  415. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  416. .diseqc_mode = 2,/* 2/3 PWM */
  417. .ts_config_regs = stv0900_ts_regs,
  418. .tun1_maddress = 0,/* 0x60 */
  419. .tun2_maddress = 3,/* 0x63 */
  420. .tun1_adc = 1,/* 1 Vpp */
  421. .tun2_adc = 1,/* 1 Vpp */
  422. };
  423. static struct stv6110_config netup_stv6110_tunerconfig_a = {
  424. .i2c_address = 0x60,
  425. .mclk = 16000000,
  426. .clk_div = 1,
  427. .gain = 8, /* +16 dB - maximum gain */
  428. };
  429. static struct stv6110_config netup_stv6110_tunerconfig_b = {
  430. .i2c_address = 0x63,
  431. .mclk = 16000000,
  432. .clk_div = 1,
  433. .gain = 8, /* +16 dB - maximum gain */
  434. };
  435. static struct cx24116_config tbs_cx24116_config = {
  436. .demod_address = 0x55,
  437. };
  438. static struct cx24117_config tbs_cx24117_config = {
  439. .demod_address = 0x55,
  440. };
  441. static struct ds3000_config tevii_ds3000_config = {
  442. .demod_address = 0x68,
  443. };
  444. static struct ts2020_config tevii_ts2020_config = {
  445. .tuner_address = 0x60,
  446. .clk_out_div = 1,
  447. .frequency_div = 1146000,
  448. };
  449. static struct cx24116_config dvbworld_cx24116_config = {
  450. .demod_address = 0x05,
  451. };
  452. static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
  453. .prod = LGS8GXX_PROD_LGS8GL5,
  454. .demod_address = 0x19,
  455. .serial_ts = 0,
  456. .ts_clk_pol = 1,
  457. .ts_clk_gated = 1,
  458. .if_clk_freq = 30400, /* 30.4 MHz */
  459. .if_freq = 5380, /* 5.38 MHz */
  460. .if_neg_center = 1,
  461. .ext_adc = 0,
  462. .adc_signed = 0,
  463. .if_neg_edge = 0,
  464. };
  465. static struct xc5000_config mygica_x8506_xc5000_config = {
  466. .i2c_address = 0x61,
  467. .if_khz = 5380,
  468. };
  469. static struct mb86a20s_config mygica_x8507_mb86a20s_config = {
  470. .demod_address = 0x10,
  471. };
  472. static struct xc5000_config mygica_x8507_xc5000_config = {
  473. .i2c_address = 0x61,
  474. .if_khz = 4000,
  475. };
  476. static struct stv090x_config prof_8000_stv090x_config = {
  477. .device = STV0903,
  478. .demod_mode = STV090x_SINGLE,
  479. .clk_mode = STV090x_CLK_EXT,
  480. .xtal = 27000000,
  481. .address = 0x6A,
  482. .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED,
  483. .repeater_level = STV090x_RPTLEVEL_64,
  484. .adc1_range = STV090x_ADC_2Vpp,
  485. .diseqc_envelope_mode = false,
  486. .tuner_get_frequency = stb6100_get_frequency,
  487. .tuner_set_frequency = stb6100_set_frequency,
  488. .tuner_set_bandwidth = stb6100_set_bandwidth,
  489. .tuner_get_bandwidth = stb6100_get_bandwidth,
  490. };
  491. static struct stb6100_config prof_8000_stb6100_config = {
  492. .tuner_address = 0x60,
  493. .refclock = 27000000,
  494. };
  495. static struct lgdt3306a_config hauppauge_quadHD_ATSC_a_config = {
  496. .i2c_addr = 0x59,
  497. .qam_if_khz = 4000,
  498. .vsb_if_khz = 3250,
  499. .deny_i2c_rptr = 1, /* Disabled */
  500. .spectral_inversion = 0, /* Disabled */
  501. .mpeg_mode = LGDT3306A_MPEG_SERIAL,
  502. .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
  503. .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
  504. .xtalMHz = 25, /* 24 or 25 */
  505. };
  506. static struct lgdt3306a_config hauppauge_quadHD_ATSC_b_config = {
  507. .i2c_addr = 0x0e,
  508. .qam_if_khz = 4000,
  509. .vsb_if_khz = 3250,
  510. .deny_i2c_rptr = 1, /* Disabled */
  511. .spectral_inversion = 0, /* Disabled */
  512. .mpeg_mode = LGDT3306A_MPEG_SERIAL,
  513. .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
  514. .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
  515. .xtalMHz = 25, /* 24 or 25 */
  516. };
  517. static int p8000_set_voltage(struct dvb_frontend *fe,
  518. enum fe_sec_voltage voltage)
  519. {
  520. struct cx23885_tsport *port = fe->dvb->priv;
  521. struct cx23885_dev *dev = port->dev;
  522. if (voltage == SEC_VOLTAGE_18)
  523. cx_write(MC417_RWD, 0x00001e00);
  524. else if (voltage == SEC_VOLTAGE_13)
  525. cx_write(MC417_RWD, 0x00001a00);
  526. else
  527. cx_write(MC417_RWD, 0x00001800);
  528. return 0;
  529. }
  530. static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe,
  531. enum fe_sec_voltage voltage)
  532. {
  533. struct cx23885_tsport *port = fe->dvb->priv;
  534. struct cx23885_dev *dev = port->dev;
  535. cx23885_gpio_enable(dev, GPIO_0 | GPIO_1, 1);
  536. switch (voltage) {
  537. case SEC_VOLTAGE_13:
  538. cx23885_gpio_set(dev, GPIO_1);
  539. cx23885_gpio_clear(dev, GPIO_0);
  540. break;
  541. case SEC_VOLTAGE_18:
  542. cx23885_gpio_set(dev, GPIO_1);
  543. cx23885_gpio_set(dev, GPIO_0);
  544. break;
  545. case SEC_VOLTAGE_OFF:
  546. cx23885_gpio_clear(dev, GPIO_1);
  547. cx23885_gpio_clear(dev, GPIO_0);
  548. break;
  549. }
  550. /* call the frontend set_voltage function */
  551. port->fe_set_voltage(fe, voltage);
  552. return 0;
  553. }
  554. static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe,
  555. enum fe_sec_voltage voltage)
  556. {
  557. struct cx23885_tsport *port = fe->dvb->priv;
  558. struct cx23885_dev *dev = port->dev;
  559. cx23885_gpio_enable(dev, GPIO_12 | GPIO_13, 1);
  560. switch (voltage) {
  561. case SEC_VOLTAGE_13:
  562. cx23885_gpio_set(dev, GPIO_13);
  563. cx23885_gpio_clear(dev, GPIO_12);
  564. break;
  565. case SEC_VOLTAGE_18:
  566. cx23885_gpio_set(dev, GPIO_13);
  567. cx23885_gpio_set(dev, GPIO_12);
  568. break;
  569. case SEC_VOLTAGE_OFF:
  570. cx23885_gpio_clear(dev, GPIO_13);
  571. cx23885_gpio_clear(dev, GPIO_12);
  572. break;
  573. }
  574. /* call the frontend set_voltage function */
  575. return port->fe_set_voltage(fe, voltage);
  576. }
  577. static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr,
  578. u8 data, int *mem)
  579. {
  580. /* MC417 */
  581. #define SP2_DATA 0x000000ff
  582. #define SP2_WR 0x00008000
  583. #define SP2_RD 0x00004000
  584. #define SP2_ACK 0x00001000
  585. #define SP2_ADHI 0x00000800
  586. #define SP2_ADLO 0x00000400
  587. #define SP2_CS1 0x00000200
  588. #define SP2_CS0 0x00000100
  589. #define SP2_EN_ALL 0x00001000
  590. #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD)
  591. struct cx23885_tsport *port = priv;
  592. struct cx23885_dev *dev = port->dev;
  593. int ret;
  594. int tmp = 0;
  595. unsigned long timeout;
  596. mutex_lock(&dev->gpio_lock);
  597. /* write addr */
  598. cx_write(MC417_OEN, SP2_EN_ALL);
  599. cx_write(MC417_RWD, SP2_CTRL_OFF |
  600. SP2_ADLO | (0xff & addr));
  601. cx_clear(MC417_RWD, SP2_ADLO);
  602. cx_write(MC417_RWD, SP2_CTRL_OFF |
  603. SP2_ADHI | (0xff & (addr >> 8)));
  604. cx_clear(MC417_RWD, SP2_ADHI);
  605. if (read)
  606. /* data in */
  607. cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA);
  608. else
  609. /* data out */
  610. cx_write(MC417_RWD, SP2_CTRL_OFF | data);
  611. /* chip select 0 */
  612. cx_clear(MC417_RWD, SP2_CS0);
  613. /* read/write */
  614. cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR);
  615. /* wait for a maximum of 1 msec */
  616. timeout = jiffies + msecs_to_jiffies(1);
  617. while (!time_after(jiffies, timeout)) {
  618. tmp = cx_read(MC417_RWD);
  619. if ((tmp & SP2_ACK) == 0)
  620. break;
  621. usleep_range(50, 100);
  622. }
  623. cx_set(MC417_RWD, SP2_CTRL_OFF);
  624. *mem = tmp & 0xff;
  625. mutex_unlock(&dev->gpio_lock);
  626. if (!read) {
  627. if (*mem < 0) {
  628. ret = -EREMOTEIO;
  629. goto err;
  630. }
  631. }
  632. return 0;
  633. err:
  634. return ret;
  635. }
  636. static int cx23885_dvb_set_frontend(struct dvb_frontend *fe)
  637. {
  638. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  639. struct cx23885_tsport *port = fe->dvb->priv;
  640. struct cx23885_dev *dev = port->dev;
  641. switch (dev->board) {
  642. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  643. switch (p->modulation) {
  644. case VSB_8:
  645. cx23885_gpio_clear(dev, GPIO_5);
  646. break;
  647. case QAM_64:
  648. case QAM_256:
  649. default:
  650. cx23885_gpio_set(dev, GPIO_5);
  651. break;
  652. }
  653. break;
  654. case CX23885_BOARD_MYGICA_X8506:
  655. case CX23885_BOARD_MYGICA_X8507:
  656. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  657. /* Select Digital TV */
  658. cx23885_gpio_set(dev, GPIO_0);
  659. break;
  660. }
  661. /* Call the real set_frontend */
  662. if (port->set_frontend)
  663. return port->set_frontend(fe);
  664. return 0;
  665. }
  666. static void cx23885_set_frontend_hook(struct cx23885_tsport *port,
  667. struct dvb_frontend *fe)
  668. {
  669. port->set_frontend = fe->ops.set_frontend;
  670. fe->ops.set_frontend = cx23885_dvb_set_frontend;
  671. }
  672. static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
  673. .prod = LGS8GXX_PROD_LGS8G75,
  674. .demod_address = 0x19,
  675. .serial_ts = 0,
  676. .ts_clk_pol = 1,
  677. .ts_clk_gated = 1,
  678. .if_clk_freq = 30400, /* 30.4 MHz */
  679. .if_freq = 6500, /* 6.50 MHz */
  680. .if_neg_center = 1,
  681. .ext_adc = 0,
  682. .adc_signed = 1,
  683. .adc_vpp = 2, /* 1.6 Vpp */
  684. .if_neg_edge = 1,
  685. };
  686. static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
  687. .i2c_address = 0x61,
  688. .if_khz = 6500,
  689. };
  690. static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
  691. .prod = ATBM8830_PROD_8830,
  692. .demod_address = 0x44,
  693. .serial_ts = 0,
  694. .ts_sampling_edge = 1,
  695. .ts_clk_gated = 0,
  696. .osc_clk_freq = 30400, /* in kHz */
  697. .if_freq = 0, /* zero IF */
  698. .zif_swap_iq = 1,
  699. .agc_min = 0x2E,
  700. .agc_max = 0xFF,
  701. .agc_hold_loop = 0,
  702. };
  703. static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
  704. .i2c_address = 0x60,
  705. .osc_clk = 20
  706. };
  707. static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
  708. .prod = ATBM8830_PROD_8830,
  709. .demod_address = 0x44,
  710. .serial_ts = 1,
  711. .ts_sampling_edge = 1,
  712. .ts_clk_gated = 0,
  713. .osc_clk_freq = 30400, /* in kHz */
  714. .if_freq = 0, /* zero IF */
  715. .zif_swap_iq = 1,
  716. .agc_min = 0x2E,
  717. .agc_max = 0xFF,
  718. .agc_hold_loop = 0,
  719. };
  720. static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
  721. .i2c_address = 0x60,
  722. .osc_clk = 20
  723. };
  724. static struct stv0367_config netup_stv0367_config[] = {
  725. {
  726. .demod_address = 0x1c,
  727. .xtal = 27000000,
  728. .if_khz = 4500,
  729. .if_iq_mode = 0,
  730. .ts_mode = 1,
  731. .clk_pol = 0,
  732. }, {
  733. .demod_address = 0x1d,
  734. .xtal = 27000000,
  735. .if_khz = 4500,
  736. .if_iq_mode = 0,
  737. .ts_mode = 1,
  738. .clk_pol = 0,
  739. },
  740. };
  741. static struct xc5000_config netup_xc5000_config[] = {
  742. {
  743. .i2c_address = 0x61,
  744. .if_khz = 4500,
  745. }, {
  746. .i2c_address = 0x64,
  747. .if_khz = 4500,
  748. },
  749. };
  750. static struct drxk_config terratec_drxk_config[] = {
  751. {
  752. .adr = 0x29,
  753. .no_i2c_bridge = 1,
  754. }, {
  755. .adr = 0x2a,
  756. .no_i2c_bridge = 1,
  757. },
  758. };
  759. static struct mt2063_config terratec_mt2063_config[] = {
  760. {
  761. .tuner_address = 0x60,
  762. }, {
  763. .tuner_address = 0x67,
  764. },
  765. };
  766. static const struct tda10071_platform_data hauppauge_tda10071_pdata = {
  767. .clk = 40444000, /* 40.444 MHz */
  768. .i2c_wr_max = 64,
  769. .ts_mode = TDA10071_TS_SERIAL,
  770. .pll_multiplier = 20,
  771. .tuner_i2c_addr = 0x54,
  772. };
  773. static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = {
  774. .i2c_addr = 0x68,
  775. .clock = 27000000,
  776. .i2c_wr_max = 33,
  777. .clock_out = 0,
  778. .ts_mode = M88DS3103_TS_PARALLEL,
  779. .ts_clk = 16000,
  780. .ts_clk_pol = 1,
  781. .lnb_en_pol = 1,
  782. .lnb_hv_pol = 0,
  783. .agc = 0x99,
  784. };
  785. static const struct m88ds3103_config dvbsky_s950c_m88ds3103_config = {
  786. .i2c_addr = 0x68,
  787. .clock = 27000000,
  788. .i2c_wr_max = 33,
  789. .clock_out = 0,
  790. .ts_mode = M88DS3103_TS_CI,
  791. .ts_clk = 10000,
  792. .ts_clk_pol = 1,
  793. .lnb_en_pol = 1,
  794. .lnb_hv_pol = 0,
  795. .agc = 0x99,
  796. };
  797. static const struct m88ds3103_config dvbsky_s952_portc_m88ds3103_config = {
  798. .i2c_addr = 0x68,
  799. .clock = 27000000,
  800. .i2c_wr_max = 33,
  801. .clock_out = 0,
  802. .ts_mode = M88DS3103_TS_SERIAL,
  803. .ts_clk = 96000,
  804. .ts_clk_pol = 0,
  805. .lnb_en_pol = 1,
  806. .lnb_hv_pol = 0,
  807. .agc = 0x99,
  808. };
  809. static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = {
  810. .i2c_addr = 0x69,
  811. .clock = 27000000,
  812. .i2c_wr_max = 33,
  813. .ts_mode = M88DS3103_TS_PARALLEL,
  814. .ts_clk = 16000,
  815. .ts_clk_pol = 1,
  816. .agc = 0x99,
  817. };
  818. static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
  819. {
  820. struct cx23885_dev *dev = (struct cx23885_dev *)device;
  821. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  822. uint32_t mem = 0;
  823. mem = cx_read(MC417_RWD);
  824. if (read)
  825. cx_set(MC417_OEN, ALT_DATA);
  826. else {
  827. cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
  828. mem &= ~ALT_DATA;
  829. mem |= (data & ALT_DATA);
  830. }
  831. if (flag)
  832. mem |= ALT_AD_RG;
  833. else
  834. mem &= ~ALT_AD_RG;
  835. mem &= ~ALT_CS;
  836. if (read)
  837. mem = (mem & ~ALT_RD) | ALT_WR;
  838. else
  839. mem = (mem & ~ALT_WR) | ALT_RD;
  840. cx_write(MC417_RWD, mem); /* start RW cycle */
  841. for (;;) {
  842. mem = cx_read(MC417_RWD);
  843. if ((mem & ALT_RDY) == 0)
  844. break;
  845. if (time_after(jiffies, timeout))
  846. break;
  847. udelay(1);
  848. }
  849. cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
  850. if (read)
  851. return mem & ALT_DATA;
  852. return 0;
  853. };
  854. static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
  855. {
  856. struct dib7000p_ops *dib7000p_ops = fe->sec_priv;
  857. return dib7000p_ops->set_gpio(fe, 8, 0, !onoff);
  858. }
  859. static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
  860. {
  861. return 0;
  862. }
  863. static struct dib0070_config dib7070p_dib0070_config = {
  864. .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
  865. .reset = dib7070_tuner_reset,
  866. .sleep = dib7070_tuner_sleep,
  867. .clock_khz = 12000,
  868. .freq_offset_khz_vhf = 550,
  869. /* .flip_chip = 1, */
  870. };
  871. /* DIB7070 generic */
  872. static struct dibx000_agc_config dib7070_agc_config = {
  873. .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
  874. /*
  875. * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
  876. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
  877. * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
  878. */
  879. .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
  880. (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
  881. .inv_gain = 600,
  882. .time_stabiliz = 10,
  883. .alpha_level = 0,
  884. .thlock = 118,
  885. .wbd_inv = 0,
  886. .wbd_ref = 3530,
  887. .wbd_sel = 1,
  888. .wbd_alpha = 5,
  889. .agc1_max = 65535,
  890. .agc1_min = 0,
  891. .agc2_max = 65535,
  892. .agc2_min = 0,
  893. .agc1_pt1 = 0,
  894. .agc1_pt2 = 40,
  895. .agc1_pt3 = 183,
  896. .agc1_slope1 = 206,
  897. .agc1_slope2 = 255,
  898. .agc2_pt1 = 72,
  899. .agc2_pt2 = 152,
  900. .agc2_slope1 = 88,
  901. .agc2_slope2 = 90,
  902. .alpha_mant = 17,
  903. .alpha_exp = 27,
  904. .beta_mant = 23,
  905. .beta_exp = 51,
  906. .perform_agc_softsplit = 0,
  907. };
  908. static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
  909. .internal = 60000,
  910. .sampling = 15000,
  911. .pll_prediv = 1,
  912. .pll_ratio = 20,
  913. .pll_range = 3,
  914. .pll_reset = 1,
  915. .pll_bypass = 0,
  916. .enable_refdiv = 0,
  917. .bypclk_div = 0,
  918. .IO_CLK_en_core = 1,
  919. .ADClkSrc = 1,
  920. .modulo = 2,
  921. /* refsel, sel, freq_15k */
  922. .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
  923. .ifreq = (0 << 25) | 0,
  924. .timf = 20452225,
  925. .xtal_hz = 12000000,
  926. };
  927. static struct dib7000p_config dib7070p_dib7000p_config = {
  928. /* .output_mode = OUTMODE_MPEG2_FIFO, */
  929. .output_mode = OUTMODE_MPEG2_SERIAL,
  930. /* .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK, */
  931. .output_mpeg2_in_188_bytes = 1,
  932. .agc_config_count = 1,
  933. .agc = &dib7070_agc_config,
  934. .bw = &dib7070_bw_config_12_mhz,
  935. .tuner_is_baseband = 1,
  936. .spur_protect = 1,
  937. .gpio_dir = 0xfcef, /* DIB7000P_GPIO_DEFAULT_DIRECTIONS, */
  938. .gpio_val = 0x0110, /* DIB7000P_GPIO_DEFAULT_VALUES, */
  939. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  940. .hostbus_diversity = 1,
  941. };
  942. static int dvb_register_ci_mac(struct cx23885_tsport *port)
  943. {
  944. struct cx23885_dev *dev = port->dev;
  945. struct i2c_client *client_ci = NULL;
  946. struct vb2_dvb_frontend *fe0;
  947. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  948. if (!fe0)
  949. return -EINVAL;
  950. switch (dev->board) {
  951. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
  952. static struct netup_card_info cinfo;
  953. netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
  954. memcpy(port->frontends.adapter.proposed_mac,
  955. cinfo.port[port->nr - 1].mac, 6);
  956. printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
  957. port->nr, port->frontends.adapter.proposed_mac);
  958. netup_ci_init(port);
  959. return 0;
  960. }
  961. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
  962. struct altera_ci_config netup_ci_cfg = {
  963. .dev = dev,/* magic number to identify*/
  964. .adapter = &port->frontends.adapter,/* for CI */
  965. .demux = &fe0->dvb.demux,/* for hw pid filter */
  966. .fpga_rw = netup_altera_fpga_rw,
  967. };
  968. altera_ci_init(&netup_ci_cfg, port->nr);
  969. return 0;
  970. }
  971. case CX23885_BOARD_TEVII_S470: {
  972. u8 eeprom[256]; /* 24C02 i2c eeprom */
  973. if (port->nr != 1)
  974. return 0;
  975. /* Read entire EEPROM */
  976. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  977. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
  978. printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
  979. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
  980. return 0;
  981. }
  982. case CX23885_BOARD_DVBSKY_T9580:
  983. case CX23885_BOARD_DVBSKY_S950:
  984. case CX23885_BOARD_DVBSKY_S952:
  985. case CX23885_BOARD_DVBSKY_T982: {
  986. u8 eeprom[256]; /* 24C02 i2c eeprom */
  987. if (port->nr > 2)
  988. return 0;
  989. /* Read entire EEPROM */
  990. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  991. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
  992. sizeof(eeprom));
  993. printk(KERN_INFO "%s port %d MAC address: %pM\n",
  994. cx23885_boards[dev->board].name, port->nr,
  995. eeprom + 0xc0 + (port->nr-1) * 8);
  996. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
  997. (port->nr-1) * 8, 6);
  998. return 0;
  999. }
  1000. case CX23885_BOARD_DVBSKY_S950C:
  1001. case CX23885_BOARD_DVBSKY_T980C:
  1002. case CX23885_BOARD_TT_CT2_4500_CI: {
  1003. u8 eeprom[256]; /* 24C02 i2c eeprom */
  1004. struct sp2_config sp2_config;
  1005. struct i2c_board_info info;
  1006. struct cx23885_i2c *i2c_bus = &dev->i2c_bus[0];
  1007. /* attach CI */
  1008. memset(&sp2_config, 0, sizeof(sp2_config));
  1009. sp2_config.dvb_adap = &port->frontends.adapter;
  1010. sp2_config.priv = port;
  1011. sp2_config.ci_control = cx23885_sp2_ci_ctrl;
  1012. memset(&info, 0, sizeof(struct i2c_board_info));
  1013. strlcpy(info.type, "sp2", I2C_NAME_SIZE);
  1014. info.addr = 0x40;
  1015. info.platform_data = &sp2_config;
  1016. request_module(info.type);
  1017. client_ci = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1018. if (client_ci == NULL || client_ci->dev.driver == NULL)
  1019. return -ENODEV;
  1020. if (!try_module_get(client_ci->dev.driver->owner)) {
  1021. i2c_unregister_device(client_ci);
  1022. return -ENODEV;
  1023. }
  1024. port->i2c_client_ci = client_ci;
  1025. if (port->nr != 1)
  1026. return 0;
  1027. /* Read entire EEPROM */
  1028. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  1029. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
  1030. sizeof(eeprom));
  1031. printk(KERN_INFO "%s MAC address: %pM\n",
  1032. cx23885_boards[dev->board].name, eeprom + 0xc0);
  1033. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6);
  1034. return 0;
  1035. }
  1036. }
  1037. return 0;
  1038. }
  1039. static int dvb_register(struct cx23885_tsport *port)
  1040. {
  1041. struct dib7000p_ops dib7000p_ops;
  1042. struct cx23885_dev *dev = port->dev;
  1043. struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
  1044. struct vb2_dvb_frontend *fe0, *fe1 = NULL;
  1045. struct si2168_config si2168_config;
  1046. struct si2165_platform_data si2165_pdata;
  1047. struct si2157_config si2157_config;
  1048. struct ts2020_config ts2020_config;
  1049. struct i2c_board_info info;
  1050. struct i2c_adapter *adapter;
  1051. struct i2c_client *client_demod = NULL, *client_tuner = NULL;
  1052. struct i2c_client *client_sec = NULL;
  1053. const struct m88ds3103_config *p_m88ds3103_config = NULL;
  1054. int (*p_set_voltage)(struct dvb_frontend *fe,
  1055. enum fe_sec_voltage voltage) = NULL;
  1056. int mfe_shared = 0; /* bus not shared by default */
  1057. int ret;
  1058. /* Get the first frontend */
  1059. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  1060. if (!fe0)
  1061. return -EINVAL;
  1062. /* init struct vb2_dvb */
  1063. fe0->dvb.name = dev->name;
  1064. /* multi-frontend gate control is undefined or defaults to fe0 */
  1065. port->frontends.gate = 0;
  1066. /* Sets the gate control callback to be used by i2c command calls */
  1067. port->gate_ctrl = cx23885_dvb_gate_ctrl;
  1068. /* init frontend */
  1069. switch (dev->board) {
  1070. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  1071. i2c_bus = &dev->i2c_bus[0];
  1072. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1073. &hauppauge_generic_config,
  1074. &i2c_bus->i2c_adap);
  1075. if (fe0->dvb.frontend == NULL)
  1076. break;
  1077. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  1078. &i2c_bus->i2c_adap,
  1079. &hauppauge_generic_tunerconfig, 0);
  1080. break;
  1081. case CX23885_BOARD_HAUPPAUGE_HVR1270:
  1082. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  1083. i2c_bus = &dev->i2c_bus[0];
  1084. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  1085. &hauppauge_lgdt3305_config,
  1086. &i2c_bus->i2c_adap);
  1087. if (fe0->dvb.frontend == NULL)
  1088. break;
  1089. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1090. 0x60, &dev->i2c_bus[1].i2c_adap,
  1091. &hauppauge_hvr127x_config);
  1092. if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275)
  1093. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1094. break;
  1095. case CX23885_BOARD_HAUPPAUGE_HVR1255:
  1096. case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
  1097. i2c_bus = &dev->i2c_bus[0];
  1098. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1099. &hcw_s5h1411_config,
  1100. &i2c_bus->i2c_adap);
  1101. if (fe0->dvb.frontend == NULL)
  1102. break;
  1103. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1104. 0x60, &dev->i2c_bus[1].i2c_adap,
  1105. &hauppauge_tda18271_config);
  1106. tda18271_attach(&dev->ts1.analog_fe,
  1107. 0x60, &dev->i2c_bus[1].i2c_adap,
  1108. &hauppauge_tda18271_config);
  1109. break;
  1110. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  1111. i2c_bus = &dev->i2c_bus[0];
  1112. switch (alt_tuner) {
  1113. case 1:
  1114. fe0->dvb.frontend =
  1115. dvb_attach(s5h1409_attach,
  1116. &hauppauge_ezqam_config,
  1117. &i2c_bus->i2c_adap);
  1118. if (fe0->dvb.frontend == NULL)
  1119. break;
  1120. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1121. &dev->i2c_bus[1].i2c_adap, 0x42,
  1122. &tda829x_no_probe);
  1123. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1124. 0x60, &dev->i2c_bus[1].i2c_adap,
  1125. &hauppauge_tda18271_config);
  1126. break;
  1127. case 0:
  1128. default:
  1129. fe0->dvb.frontend =
  1130. dvb_attach(s5h1409_attach,
  1131. &hauppauge_generic_config,
  1132. &i2c_bus->i2c_adap);
  1133. if (fe0->dvb.frontend == NULL)
  1134. break;
  1135. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  1136. &i2c_bus->i2c_adap,
  1137. &hauppauge_generic_tunerconfig, 0);
  1138. }
  1139. break;
  1140. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  1141. i2c_bus = &dev->i2c_bus[0];
  1142. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1143. &hauppauge_hvr1800lp_config,
  1144. &i2c_bus->i2c_adap);
  1145. if (fe0->dvb.frontend == NULL)
  1146. break;
  1147. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  1148. &i2c_bus->i2c_adap,
  1149. &hauppauge_generic_tunerconfig, 0);
  1150. break;
  1151. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  1152. i2c_bus = &dev->i2c_bus[0];
  1153. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1154. &fusionhdtv_5_express,
  1155. &i2c_bus->i2c_adap);
  1156. if (fe0->dvb.frontend == NULL)
  1157. break;
  1158. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1159. &i2c_bus->i2c_adap, 0x61,
  1160. TUNER_LG_TDVS_H06XF);
  1161. break;
  1162. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  1163. i2c_bus = &dev->i2c_bus[1];
  1164. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1165. &hauppauge_hvr1500q_config,
  1166. &dev->i2c_bus[0].i2c_adap);
  1167. if (fe0->dvb.frontend == NULL)
  1168. break;
  1169. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1170. &i2c_bus->i2c_adap,
  1171. &hauppauge_hvr1500q_tunerconfig);
  1172. break;
  1173. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  1174. i2c_bus = &dev->i2c_bus[1];
  1175. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1176. &hauppauge_hvr1500_config,
  1177. &dev->i2c_bus[0].i2c_adap);
  1178. if (fe0->dvb.frontend != NULL) {
  1179. struct dvb_frontend *fe;
  1180. struct xc2028_config cfg = {
  1181. .i2c_adap = &i2c_bus->i2c_adap,
  1182. .i2c_addr = 0x61,
  1183. };
  1184. static struct xc2028_ctrl ctl = {
  1185. .fname = XC2028_DEFAULT_FIRMWARE,
  1186. .max_len = 64,
  1187. .demod = XC3028_FE_OREN538,
  1188. };
  1189. fe = dvb_attach(xc2028_attach,
  1190. fe0->dvb.frontend, &cfg);
  1191. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1192. fe->ops.tuner_ops.set_config(fe, &ctl);
  1193. }
  1194. break;
  1195. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  1196. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  1197. i2c_bus = &dev->i2c_bus[0];
  1198. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1199. &hauppauge_hvr1200_config,
  1200. &i2c_bus->i2c_adap);
  1201. if (fe0->dvb.frontend == NULL)
  1202. break;
  1203. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1204. &dev->i2c_bus[1].i2c_adap, 0x42,
  1205. &tda829x_no_probe);
  1206. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1207. 0x60, &dev->i2c_bus[1].i2c_adap,
  1208. &hauppauge_hvr1200_tuner_config);
  1209. break;
  1210. case CX23885_BOARD_HAUPPAUGE_HVR1210:
  1211. i2c_bus = &dev->i2c_bus[0];
  1212. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1213. &hauppauge_hvr1210_config,
  1214. &i2c_bus->i2c_adap);
  1215. if (fe0->dvb.frontend != NULL) {
  1216. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1217. 0x60, &dev->i2c_bus[1].i2c_adap,
  1218. &hauppauge_hvr1210_tuner_config);
  1219. }
  1220. break;
  1221. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  1222. i2c_bus = &dev->i2c_bus[0];
  1223. if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
  1224. return -ENODEV;
  1225. fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap,
  1226. 0x12, &hauppauge_hvr1400_dib7000_config);
  1227. if (fe0->dvb.frontend != NULL) {
  1228. struct dvb_frontend *fe;
  1229. struct xc2028_config cfg = {
  1230. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  1231. .i2c_addr = 0x64,
  1232. };
  1233. static struct xc2028_ctrl ctl = {
  1234. .fname = XC3028L_DEFAULT_FIRMWARE,
  1235. .max_len = 64,
  1236. .demod = XC3028_FE_DIBCOM52,
  1237. /* This is true for all demods with
  1238. v36 firmware? */
  1239. .type = XC2028_D2633,
  1240. };
  1241. fe = dvb_attach(xc2028_attach,
  1242. fe0->dvb.frontend, &cfg);
  1243. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1244. fe->ops.tuner_ops.set_config(fe, &ctl);
  1245. }
  1246. break;
  1247. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  1248. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1249. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1250. &dvico_s5h1409_config,
  1251. &i2c_bus->i2c_adap);
  1252. if (fe0->dvb.frontend == NULL)
  1253. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1254. &dvico_s5h1411_config,
  1255. &i2c_bus->i2c_adap);
  1256. if (fe0->dvb.frontend != NULL)
  1257. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1258. &i2c_bus->i2c_adap,
  1259. &dvico_xc5000_tunerconfig);
  1260. break;
  1261. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
  1262. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1263. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1264. &dvico_fusionhdtv_xc3028,
  1265. &i2c_bus->i2c_adap);
  1266. if (fe0->dvb.frontend != NULL) {
  1267. struct dvb_frontend *fe;
  1268. struct xc2028_config cfg = {
  1269. .i2c_adap = &i2c_bus->i2c_adap,
  1270. .i2c_addr = 0x61,
  1271. };
  1272. static struct xc2028_ctrl ctl = {
  1273. .fname = XC2028_DEFAULT_FIRMWARE,
  1274. .max_len = 64,
  1275. .demod = XC3028_FE_ZARLINK456,
  1276. };
  1277. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  1278. &cfg);
  1279. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1280. fe->ops.tuner_ops.set_config(fe, &ctl);
  1281. }
  1282. break;
  1283. }
  1284. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2: {
  1285. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1286. /* cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); */
  1287. /* cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); */
  1288. if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
  1289. return -ENODEV;
  1290. if (dib7000p_ops.i2c_enumeration(&i2c_bus->i2c_adap, 1, 0x12, &dib7070p_dib7000p_config) < 0) {
  1291. printk(KERN_WARNING "Unable to enumerate dib7000p\n");
  1292. return -ENODEV;
  1293. }
  1294. fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 0x80, &dib7070p_dib7000p_config);
  1295. if (fe0->dvb.frontend != NULL) {
  1296. struct i2c_adapter *tun_i2c;
  1297. fe0->dvb.frontend->sec_priv = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL);
  1298. memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops));
  1299. tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
  1300. if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
  1301. return -ENODEV;
  1302. }
  1303. break;
  1304. }
  1305. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
  1306. case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
  1307. case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
  1308. i2c_bus = &dev->i2c_bus[0];
  1309. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1310. &dvico_fusionhdtv_xc3028,
  1311. &i2c_bus->i2c_adap);
  1312. if (fe0->dvb.frontend != NULL) {
  1313. struct dvb_frontend *fe;
  1314. struct xc2028_config cfg = {
  1315. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  1316. .i2c_addr = 0x61,
  1317. };
  1318. static struct xc2028_ctrl ctl = {
  1319. .fname = XC2028_DEFAULT_FIRMWARE,
  1320. .max_len = 64,
  1321. .demod = XC3028_FE_ZARLINK456,
  1322. };
  1323. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  1324. &cfg);
  1325. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1326. fe->ops.tuner_ops.set_config(fe, &ctl);
  1327. }
  1328. break;
  1329. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
  1330. i2c_bus = &dev->i2c_bus[0];
  1331. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1332. &dvico_fusionhdtv_xc3028,
  1333. &i2c_bus->i2c_adap);
  1334. if (fe0->dvb.frontend != NULL) {
  1335. struct dvb_frontend *fe;
  1336. struct xc4000_config cfg = {
  1337. .i2c_address = 0x61,
  1338. .default_pm = 0,
  1339. .dvb_amplitude = 134,
  1340. .set_smoothedcvbs = 1,
  1341. .if_khz = 4560
  1342. };
  1343. fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
  1344. &dev->i2c_bus[1].i2c_adap, &cfg);
  1345. if (!fe) {
  1346. printk(KERN_ERR "%s/2: xc4000 attach failed\n",
  1347. dev->name);
  1348. goto frontend_detach;
  1349. }
  1350. }
  1351. break;
  1352. case CX23885_BOARD_TBS_6920:
  1353. i2c_bus = &dev->i2c_bus[1];
  1354. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1355. &tbs_cx24116_config,
  1356. &i2c_bus->i2c_adap);
  1357. if (fe0->dvb.frontend != NULL)
  1358. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  1359. break;
  1360. case CX23885_BOARD_TBS_6980:
  1361. case CX23885_BOARD_TBS_6981:
  1362. i2c_bus = &dev->i2c_bus[1];
  1363. switch (port->nr) {
  1364. /* PORT B */
  1365. case 1:
  1366. fe0->dvb.frontend = dvb_attach(cx24117_attach,
  1367. &tbs_cx24117_config,
  1368. &i2c_bus->i2c_adap);
  1369. break;
  1370. /* PORT C */
  1371. case 2:
  1372. fe0->dvb.frontend = dvb_attach(cx24117_attach,
  1373. &tbs_cx24117_config,
  1374. &i2c_bus->i2c_adap);
  1375. break;
  1376. }
  1377. break;
  1378. case CX23885_BOARD_TEVII_S470:
  1379. i2c_bus = &dev->i2c_bus[1];
  1380. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  1381. &tevii_ds3000_config,
  1382. &i2c_bus->i2c_adap);
  1383. if (fe0->dvb.frontend != NULL) {
  1384. dvb_attach(ts2020_attach, fe0->dvb.frontend,
  1385. &tevii_ts2020_config, &i2c_bus->i2c_adap);
  1386. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  1387. }
  1388. break;
  1389. case CX23885_BOARD_DVBWORLD_2005:
  1390. i2c_bus = &dev->i2c_bus[1];
  1391. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1392. &dvbworld_cx24116_config,
  1393. &i2c_bus->i2c_adap);
  1394. break;
  1395. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  1396. i2c_bus = &dev->i2c_bus[0];
  1397. switch (port->nr) {
  1398. /* port B */
  1399. case 1:
  1400. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  1401. &netup_stv0900_config,
  1402. &i2c_bus->i2c_adap, 0);
  1403. if (fe0->dvb.frontend != NULL) {
  1404. if (dvb_attach(stv6110_attach,
  1405. fe0->dvb.frontend,
  1406. &netup_stv6110_tunerconfig_a,
  1407. &i2c_bus->i2c_adap)) {
  1408. if (!dvb_attach(lnbh24_attach,
  1409. fe0->dvb.frontend,
  1410. &i2c_bus->i2c_adap,
  1411. LNBH24_PCL | LNBH24_TTX,
  1412. LNBH24_TEN, 0x09))
  1413. printk(KERN_ERR
  1414. "No LNBH24 found!\n");
  1415. }
  1416. }
  1417. break;
  1418. /* port C */
  1419. case 2:
  1420. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  1421. &netup_stv0900_config,
  1422. &i2c_bus->i2c_adap, 1);
  1423. if (fe0->dvb.frontend != NULL) {
  1424. if (dvb_attach(stv6110_attach,
  1425. fe0->dvb.frontend,
  1426. &netup_stv6110_tunerconfig_b,
  1427. &i2c_bus->i2c_adap)) {
  1428. if (!dvb_attach(lnbh24_attach,
  1429. fe0->dvb.frontend,
  1430. &i2c_bus->i2c_adap,
  1431. LNBH24_PCL | LNBH24_TTX,
  1432. LNBH24_TEN, 0x0a))
  1433. printk(KERN_ERR
  1434. "No LNBH24 found!\n");
  1435. }
  1436. }
  1437. break;
  1438. }
  1439. break;
  1440. case CX23885_BOARD_MYGICA_X8506:
  1441. i2c_bus = &dev->i2c_bus[0];
  1442. i2c_bus2 = &dev->i2c_bus[1];
  1443. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1444. &mygica_x8506_lgs8gl5_config,
  1445. &i2c_bus->i2c_adap);
  1446. if (fe0->dvb.frontend == NULL)
  1447. break;
  1448. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1449. &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config);
  1450. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1451. break;
  1452. case CX23885_BOARD_MYGICA_X8507:
  1453. i2c_bus = &dev->i2c_bus[0];
  1454. i2c_bus2 = &dev->i2c_bus[1];
  1455. fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
  1456. &mygica_x8507_mb86a20s_config,
  1457. &i2c_bus->i2c_adap);
  1458. if (fe0->dvb.frontend == NULL)
  1459. break;
  1460. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1461. &i2c_bus2->i2c_adap,
  1462. &mygica_x8507_xc5000_config);
  1463. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1464. break;
  1465. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  1466. i2c_bus = &dev->i2c_bus[0];
  1467. i2c_bus2 = &dev->i2c_bus[1];
  1468. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1469. &magicpro_prohdtve2_lgs8g75_config,
  1470. &i2c_bus->i2c_adap);
  1471. if (fe0->dvb.frontend == NULL)
  1472. break;
  1473. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1474. &i2c_bus2->i2c_adap,
  1475. &magicpro_prohdtve2_xc5000_config);
  1476. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1477. break;
  1478. case CX23885_BOARD_HAUPPAUGE_HVR1850:
  1479. i2c_bus = &dev->i2c_bus[0];
  1480. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1481. &hcw_s5h1411_config,
  1482. &i2c_bus->i2c_adap);
  1483. if (fe0->dvb.frontend == NULL)
  1484. break;
  1485. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1486. 0x60, &dev->i2c_bus[0].i2c_adap,
  1487. &hauppauge_tda18271_config);
  1488. tda18271_attach(&dev->ts1.analog_fe,
  1489. 0x60, &dev->i2c_bus[1].i2c_adap,
  1490. &hauppauge_tda18271_config);
  1491. break;
  1492. case CX23885_BOARD_HAUPPAUGE_HVR1290:
  1493. i2c_bus = &dev->i2c_bus[0];
  1494. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1495. &hcw_s5h1411_config,
  1496. &i2c_bus->i2c_adap);
  1497. if (fe0->dvb.frontend == NULL)
  1498. break;
  1499. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1500. 0x60, &dev->i2c_bus[0].i2c_adap,
  1501. &hauppauge_tda18271_config);
  1502. break;
  1503. case CX23885_BOARD_MYGICA_X8558PRO:
  1504. switch (port->nr) {
  1505. /* port B */
  1506. case 1:
  1507. i2c_bus = &dev->i2c_bus[0];
  1508. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  1509. &mygica_x8558pro_atbm8830_cfg1,
  1510. &i2c_bus->i2c_adap);
  1511. if (fe0->dvb.frontend == NULL)
  1512. break;
  1513. dvb_attach(max2165_attach, fe0->dvb.frontend,
  1514. &i2c_bus->i2c_adap,
  1515. &mygic_x8558pro_max2165_cfg1);
  1516. break;
  1517. /* port C */
  1518. case 2:
  1519. i2c_bus = &dev->i2c_bus[1];
  1520. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  1521. &mygica_x8558pro_atbm8830_cfg2,
  1522. &i2c_bus->i2c_adap);
  1523. if (fe0->dvb.frontend == NULL)
  1524. break;
  1525. dvb_attach(max2165_attach, fe0->dvb.frontend,
  1526. &i2c_bus->i2c_adap,
  1527. &mygic_x8558pro_max2165_cfg2);
  1528. }
  1529. break;
  1530. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  1531. if (port->nr > 2)
  1532. return 0;
  1533. i2c_bus = &dev->i2c_bus[0];
  1534. mfe_shared = 1;/* MFE */
  1535. port->frontends.gate = 0;/* not clear for me yet */
  1536. /* ports B, C */
  1537. /* MFE frontend 1 DVB-T */
  1538. fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
  1539. &netup_stv0367_config[port->nr - 1],
  1540. &i2c_bus->i2c_adap);
  1541. if (fe0->dvb.frontend == NULL)
  1542. break;
  1543. if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1544. &i2c_bus->i2c_adap,
  1545. &netup_xc5000_config[port->nr - 1]))
  1546. goto frontend_detach;
  1547. /* load xc5000 firmware */
  1548. fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
  1549. /* MFE frontend 2 */
  1550. fe1 = vb2_dvb_get_frontend(&port->frontends, 2);
  1551. if (fe1 == NULL)
  1552. goto frontend_detach;
  1553. /* DVB-C init */
  1554. fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
  1555. &netup_stv0367_config[port->nr - 1],
  1556. &i2c_bus->i2c_adap);
  1557. if (fe1->dvb.frontend == NULL)
  1558. break;
  1559. fe1->dvb.frontend->id = 1;
  1560. if (NULL == dvb_attach(xc5000_attach,
  1561. fe1->dvb.frontend,
  1562. &i2c_bus->i2c_adap,
  1563. &netup_xc5000_config[port->nr - 1]))
  1564. goto frontend_detach;
  1565. break;
  1566. case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
  1567. i2c_bus = &dev->i2c_bus[0];
  1568. i2c_bus2 = &dev->i2c_bus[1];
  1569. switch (port->nr) {
  1570. /* port b */
  1571. case 1:
  1572. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1573. &terratec_drxk_config[0],
  1574. &i2c_bus->i2c_adap);
  1575. if (fe0->dvb.frontend == NULL)
  1576. break;
  1577. if (!dvb_attach(mt2063_attach,
  1578. fe0->dvb.frontend,
  1579. &terratec_mt2063_config[0],
  1580. &i2c_bus2->i2c_adap))
  1581. goto frontend_detach;
  1582. break;
  1583. /* port c */
  1584. case 2:
  1585. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1586. &terratec_drxk_config[1],
  1587. &i2c_bus->i2c_adap);
  1588. if (fe0->dvb.frontend == NULL)
  1589. break;
  1590. if (!dvb_attach(mt2063_attach,
  1591. fe0->dvb.frontend,
  1592. &terratec_mt2063_config[1],
  1593. &i2c_bus2->i2c_adap))
  1594. goto frontend_detach;
  1595. break;
  1596. }
  1597. break;
  1598. case CX23885_BOARD_TEVII_S471:
  1599. i2c_bus = &dev->i2c_bus[1];
  1600. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  1601. &tevii_ds3000_config,
  1602. &i2c_bus->i2c_adap);
  1603. if (fe0->dvb.frontend == NULL)
  1604. break;
  1605. dvb_attach(ts2020_attach, fe0->dvb.frontend,
  1606. &tevii_ts2020_config, &i2c_bus->i2c_adap);
  1607. break;
  1608. case CX23885_BOARD_PROF_8000:
  1609. i2c_bus = &dev->i2c_bus[0];
  1610. fe0->dvb.frontend = dvb_attach(stv090x_attach,
  1611. &prof_8000_stv090x_config,
  1612. &i2c_bus->i2c_adap,
  1613. STV090x_DEMODULATOR_0);
  1614. if (fe0->dvb.frontend == NULL)
  1615. break;
  1616. if (!dvb_attach(stb6100_attach,
  1617. fe0->dvb.frontend,
  1618. &prof_8000_stb6100_config,
  1619. &i2c_bus->i2c_adap))
  1620. goto frontend_detach;
  1621. fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
  1622. break;
  1623. case CX23885_BOARD_HAUPPAUGE_HVR4400: {
  1624. struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
  1625. struct a8293_platform_data a8293_pdata = {};
  1626. i2c_bus = &dev->i2c_bus[0];
  1627. i2c_bus2 = &dev->i2c_bus[1];
  1628. switch (port->nr) {
  1629. /* port b */
  1630. case 1:
  1631. /* attach demod + tuner combo */
  1632. memset(&info, 0, sizeof(info));
  1633. strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
  1634. info.addr = 0x05;
  1635. info.platform_data = &tda10071_pdata;
  1636. request_module("tda10071");
  1637. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1638. if (!client_demod || !client_demod->dev.driver)
  1639. goto frontend_detach;
  1640. if (!try_module_get(client_demod->dev.driver->owner)) {
  1641. i2c_unregister_device(client_demod);
  1642. goto frontend_detach;
  1643. }
  1644. fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
  1645. port->i2c_client_demod = client_demod;
  1646. /* attach SEC */
  1647. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1648. memset(&info, 0, sizeof(info));
  1649. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  1650. info.addr = 0x0b;
  1651. info.platform_data = &a8293_pdata;
  1652. request_module("a8293");
  1653. client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1654. if (!client_sec || !client_sec->dev.driver)
  1655. goto frontend_detach;
  1656. if (!try_module_get(client_sec->dev.driver->owner)) {
  1657. i2c_unregister_device(client_sec);
  1658. goto frontend_detach;
  1659. }
  1660. port->i2c_client_sec = client_sec;
  1661. break;
  1662. /* port c */
  1663. case 2:
  1664. /* attach frontend */
  1665. memset(&si2165_pdata, 0, sizeof(si2165_pdata));
  1666. si2165_pdata.fe = &fe0->dvb.frontend;
  1667. si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
  1668. si2165_pdata.ref_freq_Hz = 16000000,
  1669. memset(&info, 0, sizeof(struct i2c_board_info));
  1670. strlcpy(info.type, "si2165", I2C_NAME_SIZE);
  1671. info.addr = 0x64;
  1672. info.platform_data = &si2165_pdata;
  1673. request_module(info.type);
  1674. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1675. if (client_demod == NULL ||
  1676. client_demod->dev.driver == NULL)
  1677. goto frontend_detach;
  1678. if (!try_module_get(client_demod->dev.driver->owner)) {
  1679. i2c_unregister_device(client_demod);
  1680. goto frontend_detach;
  1681. }
  1682. port->i2c_client_demod = client_demod;
  1683. if (fe0->dvb.frontend == NULL)
  1684. break;
  1685. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1686. if (!dvb_attach(tda18271_attach,
  1687. fe0->dvb.frontend,
  1688. 0x60, &i2c_bus2->i2c_adap,
  1689. &hauppauge_hvr4400_tuner_config))
  1690. goto frontend_detach;
  1691. break;
  1692. }
  1693. break;
  1694. }
  1695. case CX23885_BOARD_HAUPPAUGE_STARBURST: {
  1696. struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
  1697. struct a8293_platform_data a8293_pdata = {};
  1698. i2c_bus = &dev->i2c_bus[0];
  1699. /* attach demod + tuner combo */
  1700. memset(&info, 0, sizeof(info));
  1701. strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
  1702. info.addr = 0x05;
  1703. info.platform_data = &tda10071_pdata;
  1704. request_module("tda10071");
  1705. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1706. if (!client_demod || !client_demod->dev.driver)
  1707. goto frontend_detach;
  1708. if (!try_module_get(client_demod->dev.driver->owner)) {
  1709. i2c_unregister_device(client_demod);
  1710. goto frontend_detach;
  1711. }
  1712. fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
  1713. port->i2c_client_demod = client_demod;
  1714. /* attach SEC */
  1715. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1716. memset(&info, 0, sizeof(info));
  1717. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  1718. info.addr = 0x0b;
  1719. info.platform_data = &a8293_pdata;
  1720. request_module("a8293");
  1721. client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1722. if (!client_sec || !client_sec->dev.driver)
  1723. goto frontend_detach;
  1724. if (!try_module_get(client_sec->dev.driver->owner)) {
  1725. i2c_unregister_device(client_sec);
  1726. goto frontend_detach;
  1727. }
  1728. port->i2c_client_sec = client_sec;
  1729. break;
  1730. }
  1731. case CX23885_BOARD_DVBSKY_T9580:
  1732. case CX23885_BOARD_DVBSKY_S950:
  1733. i2c_bus = &dev->i2c_bus[0];
  1734. i2c_bus2 = &dev->i2c_bus[1];
  1735. switch (port->nr) {
  1736. /* port b - satellite */
  1737. case 1:
  1738. /* attach frontend */
  1739. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1740. &dvbsky_t9580_m88ds3103_config,
  1741. &i2c_bus2->i2c_adap, &adapter);
  1742. if (fe0->dvb.frontend == NULL)
  1743. break;
  1744. /* attach tuner */
  1745. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1746. ts2020_config.fe = fe0->dvb.frontend;
  1747. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1748. memset(&info, 0, sizeof(struct i2c_board_info));
  1749. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1750. info.addr = 0x60;
  1751. info.platform_data = &ts2020_config;
  1752. request_module(info.type);
  1753. client_tuner = i2c_new_device(adapter, &info);
  1754. if (client_tuner == NULL ||
  1755. client_tuner->dev.driver == NULL)
  1756. goto frontend_detach;
  1757. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1758. i2c_unregister_device(client_tuner);
  1759. goto frontend_detach;
  1760. }
  1761. /* delegate signal strength measurement to tuner */
  1762. fe0->dvb.frontend->ops.read_signal_strength =
  1763. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1764. /*
  1765. * for setting the voltage we need to set GPIOs on
  1766. * the card.
  1767. */
  1768. port->fe_set_voltage =
  1769. fe0->dvb.frontend->ops.set_voltage;
  1770. fe0->dvb.frontend->ops.set_voltage =
  1771. dvbsky_t9580_set_voltage;
  1772. port->i2c_client_tuner = client_tuner;
  1773. break;
  1774. /* port c - terrestrial/cable */
  1775. case 2:
  1776. /* attach frontend */
  1777. memset(&si2168_config, 0, sizeof(si2168_config));
  1778. si2168_config.i2c_adapter = &adapter;
  1779. si2168_config.fe = &fe0->dvb.frontend;
  1780. si2168_config.ts_mode = SI2168_TS_SERIAL;
  1781. memset(&info, 0, sizeof(struct i2c_board_info));
  1782. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1783. info.addr = 0x64;
  1784. info.platform_data = &si2168_config;
  1785. request_module(info.type);
  1786. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1787. if (client_demod == NULL ||
  1788. client_demod->dev.driver == NULL)
  1789. goto frontend_detach;
  1790. if (!try_module_get(client_demod->dev.driver->owner)) {
  1791. i2c_unregister_device(client_demod);
  1792. goto frontend_detach;
  1793. }
  1794. port->i2c_client_demod = client_demod;
  1795. /* attach tuner */
  1796. memset(&si2157_config, 0, sizeof(si2157_config));
  1797. si2157_config.fe = fe0->dvb.frontend;
  1798. si2157_config.if_port = 1;
  1799. memset(&info, 0, sizeof(struct i2c_board_info));
  1800. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1801. info.addr = 0x60;
  1802. info.platform_data = &si2157_config;
  1803. request_module(info.type);
  1804. client_tuner = i2c_new_device(adapter, &info);
  1805. if (client_tuner == NULL ||
  1806. client_tuner->dev.driver == NULL)
  1807. goto frontend_detach;
  1808. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1809. i2c_unregister_device(client_tuner);
  1810. goto frontend_detach;
  1811. }
  1812. port->i2c_client_tuner = client_tuner;
  1813. break;
  1814. }
  1815. break;
  1816. case CX23885_BOARD_DVBSKY_T980C:
  1817. case CX23885_BOARD_TT_CT2_4500_CI:
  1818. i2c_bus = &dev->i2c_bus[0];
  1819. i2c_bus2 = &dev->i2c_bus[1];
  1820. /* attach frontend */
  1821. memset(&si2168_config, 0, sizeof(si2168_config));
  1822. si2168_config.i2c_adapter = &adapter;
  1823. si2168_config.fe = &fe0->dvb.frontend;
  1824. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1825. memset(&info, 0, sizeof(struct i2c_board_info));
  1826. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1827. info.addr = 0x64;
  1828. info.platform_data = &si2168_config;
  1829. request_module(info.type);
  1830. client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info);
  1831. if (client_demod == NULL || client_demod->dev.driver == NULL)
  1832. goto frontend_detach;
  1833. if (!try_module_get(client_demod->dev.driver->owner)) {
  1834. i2c_unregister_device(client_demod);
  1835. goto frontend_detach;
  1836. }
  1837. port->i2c_client_demod = client_demod;
  1838. /* attach tuner */
  1839. memset(&si2157_config, 0, sizeof(si2157_config));
  1840. si2157_config.fe = fe0->dvb.frontend;
  1841. si2157_config.if_port = 1;
  1842. memset(&info, 0, sizeof(struct i2c_board_info));
  1843. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1844. info.addr = 0x60;
  1845. info.platform_data = &si2157_config;
  1846. request_module(info.type);
  1847. client_tuner = i2c_new_device(adapter, &info);
  1848. if (client_tuner == NULL ||
  1849. client_tuner->dev.driver == NULL)
  1850. goto frontend_detach;
  1851. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1852. i2c_unregister_device(client_tuner);
  1853. goto frontend_detach;
  1854. }
  1855. port->i2c_client_tuner = client_tuner;
  1856. break;
  1857. case CX23885_BOARD_DVBSKY_S950C:
  1858. i2c_bus = &dev->i2c_bus[0];
  1859. i2c_bus2 = &dev->i2c_bus[1];
  1860. /* attach frontend */
  1861. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1862. &dvbsky_s950c_m88ds3103_config,
  1863. &i2c_bus2->i2c_adap, &adapter);
  1864. if (fe0->dvb.frontend == NULL)
  1865. break;
  1866. /* attach tuner */
  1867. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1868. ts2020_config.fe = fe0->dvb.frontend;
  1869. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1870. memset(&info, 0, sizeof(struct i2c_board_info));
  1871. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1872. info.addr = 0x60;
  1873. info.platform_data = &ts2020_config;
  1874. request_module(info.type);
  1875. client_tuner = i2c_new_device(adapter, &info);
  1876. if (client_tuner == NULL || client_tuner->dev.driver == NULL)
  1877. goto frontend_detach;
  1878. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1879. i2c_unregister_device(client_tuner);
  1880. goto frontend_detach;
  1881. }
  1882. /* delegate signal strength measurement to tuner */
  1883. fe0->dvb.frontend->ops.read_signal_strength =
  1884. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1885. port->i2c_client_tuner = client_tuner;
  1886. break;
  1887. case CX23885_BOARD_DVBSKY_S952:
  1888. switch (port->nr) {
  1889. /* port b */
  1890. case 1:
  1891. i2c_bus = &dev->i2c_bus[1];
  1892. p_m88ds3103_config = &dvbsky_t9580_m88ds3103_config;
  1893. p_set_voltage = dvbsky_t9580_set_voltage;
  1894. break;
  1895. /* port c */
  1896. case 2:
  1897. i2c_bus = &dev->i2c_bus[0];
  1898. p_m88ds3103_config = &dvbsky_s952_portc_m88ds3103_config;
  1899. p_set_voltage = dvbsky_s952_portc_set_voltage;
  1900. break;
  1901. }
  1902. /* attach frontend */
  1903. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1904. p_m88ds3103_config,
  1905. &i2c_bus->i2c_adap, &adapter);
  1906. if (fe0->dvb.frontend == NULL)
  1907. break;
  1908. /* attach tuner */
  1909. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1910. ts2020_config.fe = fe0->dvb.frontend;
  1911. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1912. memset(&info, 0, sizeof(struct i2c_board_info));
  1913. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1914. info.addr = 0x60;
  1915. info.platform_data = &ts2020_config;
  1916. request_module(info.type);
  1917. client_tuner = i2c_new_device(adapter, &info);
  1918. if (client_tuner == NULL || client_tuner->dev.driver == NULL)
  1919. goto frontend_detach;
  1920. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1921. i2c_unregister_device(client_tuner);
  1922. goto frontend_detach;
  1923. }
  1924. /* delegate signal strength measurement to tuner */
  1925. fe0->dvb.frontend->ops.read_signal_strength =
  1926. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1927. /*
  1928. * for setting the voltage we need to set GPIOs on
  1929. * the card.
  1930. */
  1931. port->fe_set_voltage =
  1932. fe0->dvb.frontend->ops.set_voltage;
  1933. fe0->dvb.frontend->ops.set_voltage = p_set_voltage;
  1934. port->i2c_client_tuner = client_tuner;
  1935. break;
  1936. case CX23885_BOARD_DVBSKY_T982:
  1937. memset(&si2168_config, 0, sizeof(si2168_config));
  1938. switch (port->nr) {
  1939. /* port b */
  1940. case 1:
  1941. i2c_bus = &dev->i2c_bus[1];
  1942. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1943. break;
  1944. /* port c */
  1945. case 2:
  1946. i2c_bus = &dev->i2c_bus[0];
  1947. si2168_config.ts_mode = SI2168_TS_SERIAL;
  1948. break;
  1949. }
  1950. /* attach frontend */
  1951. si2168_config.i2c_adapter = &adapter;
  1952. si2168_config.fe = &fe0->dvb.frontend;
  1953. memset(&info, 0, sizeof(struct i2c_board_info));
  1954. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1955. info.addr = 0x64;
  1956. info.platform_data = &si2168_config;
  1957. request_module(info.type);
  1958. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1959. if (client_demod == NULL || client_demod->dev.driver == NULL)
  1960. goto frontend_detach;
  1961. if (!try_module_get(client_demod->dev.driver->owner)) {
  1962. i2c_unregister_device(client_demod);
  1963. goto frontend_detach;
  1964. }
  1965. port->i2c_client_demod = client_demod;
  1966. /* attach tuner */
  1967. memset(&si2157_config, 0, sizeof(si2157_config));
  1968. si2157_config.fe = fe0->dvb.frontend;
  1969. si2157_config.if_port = 1;
  1970. memset(&info, 0, sizeof(struct i2c_board_info));
  1971. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1972. info.addr = 0x60;
  1973. info.platform_data = &si2157_config;
  1974. request_module(info.type);
  1975. client_tuner = i2c_new_device(adapter, &info);
  1976. if (client_tuner == NULL ||
  1977. client_tuner->dev.driver == NULL)
  1978. goto frontend_detach;
  1979. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1980. i2c_unregister_device(client_tuner);
  1981. goto frontend_detach;
  1982. }
  1983. port->i2c_client_tuner = client_tuner;
  1984. break;
  1985. case CX23885_BOARD_HAUPPAUGE_HVR5525: {
  1986. struct m88rs6000t_config m88rs6000t_config;
  1987. struct a8293_platform_data a8293_pdata = {};
  1988. switch (port->nr) {
  1989. /* port b - satellite */
  1990. case 1:
  1991. /* attach frontend */
  1992. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1993. &hauppauge_hvr5525_m88ds3103_config,
  1994. &dev->i2c_bus[0].i2c_adap, &adapter);
  1995. if (fe0->dvb.frontend == NULL)
  1996. break;
  1997. /* attach SEC */
  1998. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1999. memset(&info, 0, sizeof(info));
  2000. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  2001. info.addr = 0x0b;
  2002. info.platform_data = &a8293_pdata;
  2003. request_module("a8293");
  2004. client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2005. if (!client_sec || !client_sec->dev.driver)
  2006. goto frontend_detach;
  2007. if (!try_module_get(client_sec->dev.driver->owner)) {
  2008. i2c_unregister_device(client_sec);
  2009. goto frontend_detach;
  2010. }
  2011. port->i2c_client_sec = client_sec;
  2012. /* attach tuner */
  2013. memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
  2014. m88rs6000t_config.fe = fe0->dvb.frontend;
  2015. memset(&info, 0, sizeof(struct i2c_board_info));
  2016. strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
  2017. info.addr = 0x21;
  2018. info.platform_data = &m88rs6000t_config;
  2019. request_module("%s", info.type);
  2020. client_tuner = i2c_new_device(adapter, &info);
  2021. if (!client_tuner || !client_tuner->dev.driver)
  2022. goto frontend_detach;
  2023. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2024. i2c_unregister_device(client_tuner);
  2025. goto frontend_detach;
  2026. }
  2027. port->i2c_client_tuner = client_tuner;
  2028. /* delegate signal strength measurement to tuner */
  2029. fe0->dvb.frontend->ops.read_signal_strength =
  2030. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  2031. break;
  2032. /* port c - terrestrial/cable */
  2033. case 2:
  2034. /* attach frontend */
  2035. memset(&si2168_config, 0, sizeof(si2168_config));
  2036. si2168_config.i2c_adapter = &adapter;
  2037. si2168_config.fe = &fe0->dvb.frontend;
  2038. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2039. memset(&info, 0, sizeof(struct i2c_board_info));
  2040. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2041. info.addr = 0x64;
  2042. info.platform_data = &si2168_config;
  2043. request_module("%s", info.type);
  2044. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2045. if (!client_demod || !client_demod->dev.driver)
  2046. goto frontend_detach;
  2047. if (!try_module_get(client_demod->dev.driver->owner)) {
  2048. i2c_unregister_device(client_demod);
  2049. goto frontend_detach;
  2050. }
  2051. port->i2c_client_demod = client_demod;
  2052. /* attach tuner */
  2053. memset(&si2157_config, 0, sizeof(si2157_config));
  2054. si2157_config.fe = fe0->dvb.frontend;
  2055. si2157_config.if_port = 1;
  2056. memset(&info, 0, sizeof(struct i2c_board_info));
  2057. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2058. info.addr = 0x60;
  2059. info.platform_data = &si2157_config;
  2060. request_module("%s", info.type);
  2061. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2062. if (!client_tuner || !client_tuner->dev.driver) {
  2063. module_put(client_demod->dev.driver->owner);
  2064. i2c_unregister_device(client_demod);
  2065. port->i2c_client_demod = NULL;
  2066. goto frontend_detach;
  2067. }
  2068. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2069. i2c_unregister_device(client_tuner);
  2070. module_put(client_demod->dev.driver->owner);
  2071. i2c_unregister_device(client_demod);
  2072. port->i2c_client_demod = NULL;
  2073. goto frontend_detach;
  2074. }
  2075. port->i2c_client_tuner = client_tuner;
  2076. break;
  2077. }
  2078. break;
  2079. }
  2080. case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB:
  2081. switch (port->nr) {
  2082. /* port b - Terrestrial/cable */
  2083. case 1:
  2084. /* attach frontend */
  2085. memset(&si2168_config, 0, sizeof(si2168_config));
  2086. si2168_config.i2c_adapter = &adapter;
  2087. si2168_config.fe = &fe0->dvb.frontend;
  2088. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2089. memset(&info, 0, sizeof(struct i2c_board_info));
  2090. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2091. info.addr = 0x64;
  2092. info.platform_data = &si2168_config;
  2093. request_module("%s", info.type);
  2094. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2095. if (!client_demod || !client_demod->dev.driver)
  2096. goto frontend_detach;
  2097. if (!try_module_get(client_demod->dev.driver->owner)) {
  2098. i2c_unregister_device(client_demod);
  2099. goto frontend_detach;
  2100. }
  2101. port->i2c_client_demod = client_demod;
  2102. /* attach tuner */
  2103. memset(&si2157_config, 0, sizeof(si2157_config));
  2104. si2157_config.fe = fe0->dvb.frontend;
  2105. si2157_config.if_port = 1;
  2106. memset(&info, 0, sizeof(struct i2c_board_info));
  2107. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2108. info.addr = 0x60;
  2109. info.platform_data = &si2157_config;
  2110. request_module("%s", info.type);
  2111. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2112. if (!client_tuner || !client_tuner->dev.driver) {
  2113. module_put(client_demod->dev.driver->owner);
  2114. i2c_unregister_device(client_demod);
  2115. port->i2c_client_demod = NULL;
  2116. goto frontend_detach;
  2117. }
  2118. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2119. i2c_unregister_device(client_tuner);
  2120. module_put(client_demod->dev.driver->owner);
  2121. i2c_unregister_device(client_demod);
  2122. port->i2c_client_demod = NULL;
  2123. goto frontend_detach;
  2124. }
  2125. port->i2c_client_tuner = client_tuner;
  2126. break;
  2127. /* port c - terrestrial/cable */
  2128. case 2:
  2129. /* attach frontend */
  2130. memset(&si2168_config, 0, sizeof(si2168_config));
  2131. si2168_config.i2c_adapter = &adapter;
  2132. si2168_config.fe = &fe0->dvb.frontend;
  2133. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2134. memset(&info, 0, sizeof(struct i2c_board_info));
  2135. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2136. info.addr = 0x66;
  2137. info.platform_data = &si2168_config;
  2138. request_module("%s", info.type);
  2139. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2140. if (!client_demod || !client_demod->dev.driver)
  2141. goto frontend_detach;
  2142. if (!try_module_get(client_demod->dev.driver->owner)) {
  2143. i2c_unregister_device(client_demod);
  2144. goto frontend_detach;
  2145. }
  2146. port->i2c_client_demod = client_demod;
  2147. /* attach tuner */
  2148. memset(&si2157_config, 0, sizeof(si2157_config));
  2149. si2157_config.fe = fe0->dvb.frontend;
  2150. si2157_config.if_port = 1;
  2151. memset(&info, 0, sizeof(struct i2c_board_info));
  2152. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2153. info.addr = 0x62;
  2154. info.platform_data = &si2157_config;
  2155. request_module("%s", info.type);
  2156. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2157. if (!client_tuner || !client_tuner->dev.driver) {
  2158. module_put(client_demod->dev.driver->owner);
  2159. i2c_unregister_device(client_demod);
  2160. port->i2c_client_demod = NULL;
  2161. goto frontend_detach;
  2162. }
  2163. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2164. i2c_unregister_device(client_tuner);
  2165. module_put(client_demod->dev.driver->owner);
  2166. i2c_unregister_device(client_demod);
  2167. port->i2c_client_demod = NULL;
  2168. goto frontend_detach;
  2169. }
  2170. port->i2c_client_tuner = client_tuner;
  2171. break;
  2172. }
  2173. break;
  2174. case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC:
  2175. switch (port->nr) {
  2176. /* port b - Terrestrial/cable */
  2177. case 1:
  2178. /* attach frontend */
  2179. i2c_bus = &dev->i2c_bus[0];
  2180. fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
  2181. &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap);
  2182. if (fe0->dvb.frontend == NULL)
  2183. break;
  2184. /* attach tuner */
  2185. memset(&si2157_config, 0, sizeof(si2157_config));
  2186. si2157_config.fe = fe0->dvb.frontend;
  2187. si2157_config.if_port = 1;
  2188. si2157_config.inversion = 1;
  2189. memset(&info, 0, sizeof(struct i2c_board_info));
  2190. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2191. info.addr = 0x60;
  2192. info.platform_data = &si2157_config;
  2193. request_module("%s", info.type);
  2194. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2195. if (!client_tuner || !client_tuner->dev.driver) {
  2196. module_put(client_demod->dev.driver->owner);
  2197. i2c_unregister_device(client_demod);
  2198. port->i2c_client_demod = NULL;
  2199. goto frontend_detach;
  2200. }
  2201. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2202. i2c_unregister_device(client_tuner);
  2203. module_put(client_demod->dev.driver->owner);
  2204. i2c_unregister_device(client_demod);
  2205. port->i2c_client_demod = NULL;
  2206. goto frontend_detach;
  2207. }
  2208. port->i2c_client_tuner = client_tuner;
  2209. break;
  2210. /* port c - terrestrial/cable */
  2211. case 2:
  2212. /* attach frontend */
  2213. i2c_bus = &dev->i2c_bus[0];
  2214. fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
  2215. &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap);
  2216. if (fe0->dvb.frontend == NULL)
  2217. break;
  2218. /* attach tuner */
  2219. memset(&si2157_config, 0, sizeof(si2157_config));
  2220. si2157_config.fe = fe0->dvb.frontend;
  2221. si2157_config.if_port = 1;
  2222. si2157_config.inversion = 1;
  2223. memset(&info, 0, sizeof(struct i2c_board_info));
  2224. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2225. info.addr = 0x62;
  2226. info.platform_data = &si2157_config;
  2227. request_module("%s", info.type);
  2228. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2229. if (!client_tuner || !client_tuner->dev.driver) {
  2230. module_put(client_demod->dev.driver->owner);
  2231. i2c_unregister_device(client_demod);
  2232. port->i2c_client_demod = NULL;
  2233. goto frontend_detach;
  2234. }
  2235. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2236. i2c_unregister_device(client_tuner);
  2237. module_put(client_demod->dev.driver->owner);
  2238. i2c_unregister_device(client_demod);
  2239. port->i2c_client_demod = NULL;
  2240. goto frontend_detach;
  2241. }
  2242. port->i2c_client_tuner = client_tuner;
  2243. break;
  2244. }
  2245. break;
  2246. default:
  2247. printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
  2248. " isn't supported yet\n",
  2249. dev->name);
  2250. break;
  2251. }
  2252. if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
  2253. printk(KERN_ERR "%s: frontend initialization failed\n",
  2254. dev->name);
  2255. goto frontend_detach;
  2256. }
  2257. /* define general-purpose callback pointer */
  2258. fe0->dvb.frontend->callback = cx23885_tuner_callback;
  2259. if (fe1)
  2260. fe1->dvb.frontend->callback = cx23885_tuner_callback;
  2261. #if 0
  2262. /* Ensure all frontends negotiate bus access */
  2263. fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  2264. if (fe1)
  2265. fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  2266. #endif
  2267. /* Put the analog decoder in standby to keep it quiet */
  2268. call_all(dev, core, s_power, 0);
  2269. if (fe0->dvb.frontend->ops.analog_ops.standby)
  2270. fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
  2271. /* register everything */
  2272. ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port,
  2273. &dev->pci->dev, NULL,
  2274. adapter_nr, mfe_shared);
  2275. if (ret)
  2276. goto frontend_detach;
  2277. ret = dvb_register_ci_mac(port);
  2278. if (ret)
  2279. goto frontend_detach;
  2280. return 0;
  2281. frontend_detach:
  2282. /* remove I2C client for SEC */
  2283. client_sec = port->i2c_client_sec;
  2284. if (client_sec) {
  2285. module_put(client_sec->dev.driver->owner);
  2286. i2c_unregister_device(client_sec);
  2287. port->i2c_client_sec = NULL;
  2288. }
  2289. /* remove I2C client for tuner */
  2290. client_tuner = port->i2c_client_tuner;
  2291. if (client_tuner) {
  2292. module_put(client_tuner->dev.driver->owner);
  2293. i2c_unregister_device(client_tuner);
  2294. port->i2c_client_tuner = NULL;
  2295. }
  2296. /* remove I2C client for demodulator */
  2297. client_demod = port->i2c_client_demod;
  2298. if (client_demod) {
  2299. module_put(client_demod->dev.driver->owner);
  2300. i2c_unregister_device(client_demod);
  2301. port->i2c_client_demod = NULL;
  2302. }
  2303. port->gate_ctrl = NULL;
  2304. vb2_dvb_dealloc_frontends(&port->frontends);
  2305. return -EINVAL;
  2306. }
  2307. int cx23885_dvb_register(struct cx23885_tsport *port)
  2308. {
  2309. struct vb2_dvb_frontend *fe0;
  2310. struct cx23885_dev *dev = port->dev;
  2311. int err, i;
  2312. /* Here we need to allocate the correct number of frontends,
  2313. * as reflected in the cards struct. The reality is that currently
  2314. * no cx23885 boards support this - yet. But, if we don't modify this
  2315. * code then the second frontend would never be allocated (later)
  2316. * and fail with error before the attach in dvb_register().
  2317. * Without these changes we risk an OOPS later. The changes here
  2318. * are for safety, and should provide a good foundation for the
  2319. * future addition of any multi-frontend cx23885 based boards.
  2320. */
  2321. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  2322. port->num_frontends);
  2323. for (i = 1; i <= port->num_frontends; i++) {
  2324. struct vb2_queue *q;
  2325. if (vb2_dvb_alloc_frontend(
  2326. &port->frontends, i) == NULL) {
  2327. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  2328. return -ENOMEM;
  2329. }
  2330. fe0 = vb2_dvb_get_frontend(&port->frontends, i);
  2331. if (!fe0)
  2332. return -EINVAL;
  2333. dprintk(1, "%s\n", __func__);
  2334. dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
  2335. dev->board,
  2336. dev->name,
  2337. dev->pci_bus,
  2338. dev->pci_slot);
  2339. err = -ENODEV;
  2340. /* dvb stuff */
  2341. /* We have to init the queue for each frontend on a port. */
  2342. printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
  2343. q = &fe0->dvb.dvbq;
  2344. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  2345. q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
  2346. q->gfp_flags = GFP_DMA32;
  2347. q->min_buffers_needed = 2;
  2348. q->drv_priv = port;
  2349. q->buf_struct_size = sizeof(struct cx23885_buffer);
  2350. q->ops = &dvb_qops;
  2351. q->mem_ops = &vb2_dma_sg_memops;
  2352. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  2353. q->lock = &dev->lock;
  2354. q->dev = &dev->pci->dev;
  2355. err = vb2_queue_init(q);
  2356. if (err < 0)
  2357. return err;
  2358. }
  2359. err = dvb_register(port);
  2360. if (err != 0)
  2361. printk(KERN_ERR "%s() dvb_register failed err = %d\n",
  2362. __func__, err);
  2363. return err;
  2364. }
  2365. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  2366. {
  2367. struct vb2_dvb_frontend *fe0;
  2368. struct i2c_client *client;
  2369. /* remove I2C client for CI */
  2370. client = port->i2c_client_ci;
  2371. if (client) {
  2372. module_put(client->dev.driver->owner);
  2373. i2c_unregister_device(client);
  2374. }
  2375. /* remove I2C client for SEC */
  2376. client = port->i2c_client_sec;
  2377. if (client) {
  2378. module_put(client->dev.driver->owner);
  2379. i2c_unregister_device(client);
  2380. }
  2381. /* remove I2C client for tuner */
  2382. client = port->i2c_client_tuner;
  2383. if (client) {
  2384. module_put(client->dev.driver->owner);
  2385. i2c_unregister_device(client);
  2386. }
  2387. /* remove I2C client for demodulator */
  2388. client = port->i2c_client_demod;
  2389. if (client) {
  2390. module_put(client->dev.driver->owner);
  2391. i2c_unregister_device(client);
  2392. }
  2393. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  2394. if (fe0 && fe0->dvb.frontend)
  2395. vb2_dvb_unregister_bus(&port->frontends);
  2396. switch (port->dev->board) {
  2397. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  2398. netup_ci_exit(port);
  2399. break;
  2400. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  2401. altera_ci_release(port->dev, port->nr);
  2402. break;
  2403. }
  2404. port->gate_ctrl = NULL;
  2405. return 0;
  2406. }