cx23885-dvb.c 75 KB

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