cx23885-dvb.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675
  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 dvbsky_s952_portc_m88ds3103_config = {
  799. .i2c_addr = 0x68,
  800. .clock = 27000000,
  801. .i2c_wr_max = 33,
  802. .clock_out = 0,
  803. .ts_mode = M88DS3103_TS_SERIAL,
  804. .ts_clk = 96000,
  805. .ts_clk_pol = 0,
  806. .lnb_en_pol = 1,
  807. .lnb_hv_pol = 0,
  808. .agc = 0x99,
  809. };
  810. static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = {
  811. .i2c_addr = 0x69,
  812. .clock = 27000000,
  813. .i2c_wr_max = 33,
  814. .ts_mode = M88DS3103_TS_PARALLEL,
  815. .ts_clk = 16000,
  816. .ts_clk_pol = 1,
  817. .agc = 0x99,
  818. };
  819. static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
  820. {
  821. struct cx23885_dev *dev = (struct cx23885_dev *)device;
  822. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  823. uint32_t mem = 0;
  824. mem = cx_read(MC417_RWD);
  825. if (read)
  826. cx_set(MC417_OEN, ALT_DATA);
  827. else {
  828. cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
  829. mem &= ~ALT_DATA;
  830. mem |= (data & ALT_DATA);
  831. }
  832. if (flag)
  833. mem |= ALT_AD_RG;
  834. else
  835. mem &= ~ALT_AD_RG;
  836. mem &= ~ALT_CS;
  837. if (read)
  838. mem = (mem & ~ALT_RD) | ALT_WR;
  839. else
  840. mem = (mem & ~ALT_WR) | ALT_RD;
  841. cx_write(MC417_RWD, mem); /* start RW cycle */
  842. for (;;) {
  843. mem = cx_read(MC417_RWD);
  844. if ((mem & ALT_RDY) == 0)
  845. break;
  846. if (time_after(jiffies, timeout))
  847. break;
  848. udelay(1);
  849. }
  850. cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
  851. if (read)
  852. return mem & ALT_DATA;
  853. return 0;
  854. };
  855. static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
  856. {
  857. struct dib7000p_ops *dib7000p_ops = fe->sec_priv;
  858. return dib7000p_ops->set_gpio(fe, 8, 0, !onoff);
  859. }
  860. static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
  861. {
  862. return 0;
  863. }
  864. static struct dib0070_config dib7070p_dib0070_config = {
  865. .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
  866. .reset = dib7070_tuner_reset,
  867. .sleep = dib7070_tuner_sleep,
  868. .clock_khz = 12000,
  869. .freq_offset_khz_vhf = 550,
  870. /* .flip_chip = 1, */
  871. };
  872. /* DIB7070 generic */
  873. static struct dibx000_agc_config dib7070_agc_config = {
  874. .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
  875. /*
  876. * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
  877. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
  878. * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
  879. */
  880. .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
  881. (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
  882. .inv_gain = 600,
  883. .time_stabiliz = 10,
  884. .alpha_level = 0,
  885. .thlock = 118,
  886. .wbd_inv = 0,
  887. .wbd_ref = 3530,
  888. .wbd_sel = 1,
  889. .wbd_alpha = 5,
  890. .agc1_max = 65535,
  891. .agc1_min = 0,
  892. .agc2_max = 65535,
  893. .agc2_min = 0,
  894. .agc1_pt1 = 0,
  895. .agc1_pt2 = 40,
  896. .agc1_pt3 = 183,
  897. .agc1_slope1 = 206,
  898. .agc1_slope2 = 255,
  899. .agc2_pt1 = 72,
  900. .agc2_pt2 = 152,
  901. .agc2_slope1 = 88,
  902. .agc2_slope2 = 90,
  903. .alpha_mant = 17,
  904. .alpha_exp = 27,
  905. .beta_mant = 23,
  906. .beta_exp = 51,
  907. .perform_agc_softsplit = 0,
  908. };
  909. static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
  910. .internal = 60000,
  911. .sampling = 15000,
  912. .pll_prediv = 1,
  913. .pll_ratio = 20,
  914. .pll_range = 3,
  915. .pll_reset = 1,
  916. .pll_bypass = 0,
  917. .enable_refdiv = 0,
  918. .bypclk_div = 0,
  919. .IO_CLK_en_core = 1,
  920. .ADClkSrc = 1,
  921. .modulo = 2,
  922. /* refsel, sel, freq_15k */
  923. .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
  924. .ifreq = (0 << 25) | 0,
  925. .timf = 20452225,
  926. .xtal_hz = 12000000,
  927. };
  928. static struct dib7000p_config dib7070p_dib7000p_config = {
  929. /* .output_mode = OUTMODE_MPEG2_FIFO, */
  930. .output_mode = OUTMODE_MPEG2_SERIAL,
  931. /* .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK, */
  932. .output_mpeg2_in_188_bytes = 1,
  933. .agc_config_count = 1,
  934. .agc = &dib7070_agc_config,
  935. .bw = &dib7070_bw_config_12_mhz,
  936. .tuner_is_baseband = 1,
  937. .spur_protect = 1,
  938. .gpio_dir = 0xfcef, /* DIB7000P_GPIO_DEFAULT_DIRECTIONS, */
  939. .gpio_val = 0x0110, /* DIB7000P_GPIO_DEFAULT_VALUES, */
  940. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  941. .hostbus_diversity = 1,
  942. };
  943. static int dvb_register_ci_mac(struct cx23885_tsport *port)
  944. {
  945. struct cx23885_dev *dev = port->dev;
  946. struct i2c_client *client_ci = NULL;
  947. struct vb2_dvb_frontend *fe0;
  948. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  949. if (!fe0)
  950. return -EINVAL;
  951. switch (dev->board) {
  952. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
  953. static struct netup_card_info cinfo;
  954. netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
  955. memcpy(port->frontends.adapter.proposed_mac,
  956. cinfo.port[port->nr - 1].mac, 6);
  957. pr_info("NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
  958. port->nr, port->frontends.adapter.proposed_mac);
  959. netup_ci_init(port);
  960. return 0;
  961. }
  962. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
  963. struct altera_ci_config netup_ci_cfg = {
  964. .dev = dev,/* magic number to identify*/
  965. .adapter = &port->frontends.adapter,/* for CI */
  966. .demux = &fe0->dvb.demux,/* for hw pid filter */
  967. .fpga_rw = netup_altera_fpga_rw,
  968. };
  969. altera_ci_init(&netup_ci_cfg, port->nr);
  970. return 0;
  971. }
  972. case CX23885_BOARD_TEVII_S470: {
  973. u8 eeprom[256]; /* 24C02 i2c eeprom */
  974. if (port->nr != 1)
  975. return 0;
  976. /* Read entire EEPROM */
  977. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  978. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
  979. pr_info("TeVii S470 MAC= %pM\n", eeprom + 0xa0);
  980. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
  981. return 0;
  982. }
  983. case CX23885_BOARD_DVBSKY_T9580:
  984. case CX23885_BOARD_DVBSKY_S950:
  985. case CX23885_BOARD_DVBSKY_S952:
  986. case CX23885_BOARD_DVBSKY_T982: {
  987. u8 eeprom[256]; /* 24C02 i2c eeprom */
  988. if (port->nr > 2)
  989. return 0;
  990. /* Read entire EEPROM */
  991. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  992. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
  993. sizeof(eeprom));
  994. pr_info("%s port %d MAC address: %pM\n",
  995. cx23885_boards[dev->board].name, port->nr,
  996. eeprom + 0xc0 + (port->nr-1) * 8);
  997. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
  998. (port->nr-1) * 8, 6);
  999. return 0;
  1000. }
  1001. case CX23885_BOARD_DVBSKY_S950C:
  1002. case CX23885_BOARD_DVBSKY_T980C:
  1003. case CX23885_BOARD_TT_CT2_4500_CI: {
  1004. u8 eeprom[256]; /* 24C02 i2c eeprom */
  1005. struct sp2_config sp2_config;
  1006. struct i2c_board_info info;
  1007. struct cx23885_i2c *i2c_bus = &dev->i2c_bus[0];
  1008. /* attach CI */
  1009. memset(&sp2_config, 0, sizeof(sp2_config));
  1010. sp2_config.dvb_adap = &port->frontends.adapter;
  1011. sp2_config.priv = port;
  1012. sp2_config.ci_control = cx23885_sp2_ci_ctrl;
  1013. memset(&info, 0, sizeof(struct i2c_board_info));
  1014. strlcpy(info.type, "sp2", I2C_NAME_SIZE);
  1015. info.addr = 0x40;
  1016. info.platform_data = &sp2_config;
  1017. request_module(info.type);
  1018. client_ci = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1019. if (client_ci == NULL || client_ci->dev.driver == NULL)
  1020. return -ENODEV;
  1021. if (!try_module_get(client_ci->dev.driver->owner)) {
  1022. i2c_unregister_device(client_ci);
  1023. return -ENODEV;
  1024. }
  1025. port->i2c_client_ci = client_ci;
  1026. if (port->nr != 1)
  1027. return 0;
  1028. /* Read entire EEPROM */
  1029. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  1030. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
  1031. sizeof(eeprom));
  1032. pr_info("%s MAC address: %pM\n",
  1033. cx23885_boards[dev->board].name, eeprom + 0xc0);
  1034. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6);
  1035. return 0;
  1036. }
  1037. }
  1038. return 0;
  1039. }
  1040. static int dvb_register(struct cx23885_tsport *port)
  1041. {
  1042. struct dib7000p_ops dib7000p_ops;
  1043. struct cx23885_dev *dev = port->dev;
  1044. struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
  1045. struct vb2_dvb_frontend *fe0, *fe1 = NULL;
  1046. struct si2168_config si2168_config;
  1047. struct si2165_platform_data si2165_pdata;
  1048. struct si2157_config si2157_config;
  1049. struct ts2020_config ts2020_config;
  1050. struct i2c_board_info info;
  1051. struct i2c_adapter *adapter;
  1052. struct i2c_client *client_demod = NULL, *client_tuner = NULL;
  1053. struct i2c_client *client_sec = NULL;
  1054. const struct m88ds3103_config *p_m88ds3103_config = NULL;
  1055. int (*p_set_voltage)(struct dvb_frontend *fe,
  1056. enum fe_sec_voltage voltage) = NULL;
  1057. int mfe_shared = 0; /* bus not shared by default */
  1058. int ret;
  1059. /* Get the first frontend */
  1060. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  1061. if (!fe0)
  1062. return -EINVAL;
  1063. /* init struct vb2_dvb */
  1064. fe0->dvb.name = dev->name;
  1065. /* multi-frontend gate control is undefined or defaults to fe0 */
  1066. port->frontends.gate = 0;
  1067. /* Sets the gate control callback to be used by i2c command calls */
  1068. port->gate_ctrl = cx23885_dvb_gate_ctrl;
  1069. /* init frontend */
  1070. switch (dev->board) {
  1071. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  1072. i2c_bus = &dev->i2c_bus[0];
  1073. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1074. &hauppauge_generic_config,
  1075. &i2c_bus->i2c_adap);
  1076. if (fe0->dvb.frontend == NULL)
  1077. break;
  1078. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  1079. &i2c_bus->i2c_adap,
  1080. &hauppauge_generic_tunerconfig, 0);
  1081. break;
  1082. case CX23885_BOARD_HAUPPAUGE_HVR1270:
  1083. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  1084. i2c_bus = &dev->i2c_bus[0];
  1085. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  1086. &hauppauge_lgdt3305_config,
  1087. &i2c_bus->i2c_adap);
  1088. if (fe0->dvb.frontend == NULL)
  1089. break;
  1090. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1091. 0x60, &dev->i2c_bus[1].i2c_adap,
  1092. &hauppauge_hvr127x_config);
  1093. if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275)
  1094. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1095. break;
  1096. case CX23885_BOARD_HAUPPAUGE_HVR1255:
  1097. case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
  1098. i2c_bus = &dev->i2c_bus[0];
  1099. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1100. &hcw_s5h1411_config,
  1101. &i2c_bus->i2c_adap);
  1102. if (fe0->dvb.frontend == NULL)
  1103. break;
  1104. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1105. 0x60, &dev->i2c_bus[1].i2c_adap,
  1106. &hauppauge_tda18271_config);
  1107. tda18271_attach(&dev->ts1.analog_fe,
  1108. 0x60, &dev->i2c_bus[1].i2c_adap,
  1109. &hauppauge_tda18271_config);
  1110. break;
  1111. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  1112. i2c_bus = &dev->i2c_bus[0];
  1113. switch (alt_tuner) {
  1114. case 1:
  1115. fe0->dvb.frontend =
  1116. dvb_attach(s5h1409_attach,
  1117. &hauppauge_ezqam_config,
  1118. &i2c_bus->i2c_adap);
  1119. if (fe0->dvb.frontend == NULL)
  1120. break;
  1121. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1122. &dev->i2c_bus[1].i2c_adap, 0x42,
  1123. &tda829x_no_probe);
  1124. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1125. 0x60, &dev->i2c_bus[1].i2c_adap,
  1126. &hauppauge_tda18271_config);
  1127. break;
  1128. case 0:
  1129. default:
  1130. fe0->dvb.frontend =
  1131. dvb_attach(s5h1409_attach,
  1132. &hauppauge_generic_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. }
  1140. break;
  1141. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  1142. i2c_bus = &dev->i2c_bus[0];
  1143. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1144. &hauppauge_hvr1800lp_config,
  1145. &i2c_bus->i2c_adap);
  1146. if (fe0->dvb.frontend == NULL)
  1147. break;
  1148. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  1149. &i2c_bus->i2c_adap,
  1150. &hauppauge_generic_tunerconfig, 0);
  1151. break;
  1152. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  1153. i2c_bus = &dev->i2c_bus[0];
  1154. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1155. &fusionhdtv_5_express,
  1156. &i2c_bus->i2c_adap);
  1157. if (fe0->dvb.frontend == NULL)
  1158. break;
  1159. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1160. &i2c_bus->i2c_adap, 0x61,
  1161. TUNER_LG_TDVS_H06XF);
  1162. break;
  1163. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  1164. i2c_bus = &dev->i2c_bus[1];
  1165. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1166. &hauppauge_hvr1500q_config,
  1167. &dev->i2c_bus[0].i2c_adap);
  1168. if (fe0->dvb.frontend == NULL)
  1169. break;
  1170. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1171. &i2c_bus->i2c_adap,
  1172. &hauppauge_hvr1500q_tunerconfig);
  1173. break;
  1174. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  1175. i2c_bus = &dev->i2c_bus[1];
  1176. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1177. &hauppauge_hvr1500_config,
  1178. &dev->i2c_bus[0].i2c_adap);
  1179. if (fe0->dvb.frontend != NULL) {
  1180. struct dvb_frontend *fe;
  1181. struct xc2028_config cfg = {
  1182. .i2c_adap = &i2c_bus->i2c_adap,
  1183. .i2c_addr = 0x61,
  1184. };
  1185. static struct xc2028_ctrl ctl = {
  1186. .fname = XC2028_DEFAULT_FIRMWARE,
  1187. .max_len = 64,
  1188. .demod = XC3028_FE_OREN538,
  1189. };
  1190. fe = dvb_attach(xc2028_attach,
  1191. fe0->dvb.frontend, &cfg);
  1192. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1193. fe->ops.tuner_ops.set_config(fe, &ctl);
  1194. }
  1195. break;
  1196. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  1197. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  1198. i2c_bus = &dev->i2c_bus[0];
  1199. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1200. &hauppauge_hvr1200_config,
  1201. &i2c_bus->i2c_adap);
  1202. if (fe0->dvb.frontend == NULL)
  1203. break;
  1204. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1205. &dev->i2c_bus[1].i2c_adap, 0x42,
  1206. &tda829x_no_probe);
  1207. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1208. 0x60, &dev->i2c_bus[1].i2c_adap,
  1209. &hauppauge_hvr1200_tuner_config);
  1210. break;
  1211. case CX23885_BOARD_HAUPPAUGE_HVR1210:
  1212. i2c_bus = &dev->i2c_bus[0];
  1213. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1214. &hauppauge_hvr1210_config,
  1215. &i2c_bus->i2c_adap);
  1216. if (fe0->dvb.frontend != NULL) {
  1217. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1218. 0x60, &dev->i2c_bus[1].i2c_adap,
  1219. &hauppauge_hvr1210_tuner_config);
  1220. }
  1221. break;
  1222. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  1223. i2c_bus = &dev->i2c_bus[0];
  1224. if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
  1225. return -ENODEV;
  1226. fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap,
  1227. 0x12, &hauppauge_hvr1400_dib7000_config);
  1228. if (fe0->dvb.frontend != NULL) {
  1229. struct dvb_frontend *fe;
  1230. struct xc2028_config cfg = {
  1231. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  1232. .i2c_addr = 0x64,
  1233. };
  1234. static struct xc2028_ctrl ctl = {
  1235. .fname = XC3028L_DEFAULT_FIRMWARE,
  1236. .max_len = 64,
  1237. .demod = XC3028_FE_DIBCOM52,
  1238. /* This is true for all demods with
  1239. v36 firmware? */
  1240. .type = XC2028_D2633,
  1241. };
  1242. fe = dvb_attach(xc2028_attach,
  1243. fe0->dvb.frontend, &cfg);
  1244. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1245. fe->ops.tuner_ops.set_config(fe, &ctl);
  1246. }
  1247. break;
  1248. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  1249. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1250. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1251. &dvico_s5h1409_config,
  1252. &i2c_bus->i2c_adap);
  1253. if (fe0->dvb.frontend == NULL)
  1254. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1255. &dvico_s5h1411_config,
  1256. &i2c_bus->i2c_adap);
  1257. if (fe0->dvb.frontend != NULL)
  1258. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1259. &i2c_bus->i2c_adap,
  1260. &dvico_xc5000_tunerconfig);
  1261. break;
  1262. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
  1263. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1264. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1265. &dvico_fusionhdtv_xc3028,
  1266. &i2c_bus->i2c_adap);
  1267. if (fe0->dvb.frontend != NULL) {
  1268. struct dvb_frontend *fe;
  1269. struct xc2028_config cfg = {
  1270. .i2c_adap = &i2c_bus->i2c_adap,
  1271. .i2c_addr = 0x61,
  1272. };
  1273. static struct xc2028_ctrl ctl = {
  1274. .fname = XC2028_DEFAULT_FIRMWARE,
  1275. .max_len = 64,
  1276. .demod = XC3028_FE_ZARLINK456,
  1277. };
  1278. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  1279. &cfg);
  1280. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1281. fe->ops.tuner_ops.set_config(fe, &ctl);
  1282. }
  1283. break;
  1284. }
  1285. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2: {
  1286. i2c_bus = &dev->i2c_bus[port->nr - 1];
  1287. /* cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); */
  1288. /* cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); */
  1289. if (!dvb_attach(dib7000p_attach, &dib7000p_ops))
  1290. return -ENODEV;
  1291. if (dib7000p_ops.i2c_enumeration(&i2c_bus->i2c_adap, 1, 0x12, &dib7070p_dib7000p_config) < 0) {
  1292. pr_warn("Unable to enumerate dib7000p\n");
  1293. return -ENODEV;
  1294. }
  1295. fe0->dvb.frontend = dib7000p_ops.init(&i2c_bus->i2c_adap, 0x80, &dib7070p_dib7000p_config);
  1296. if (fe0->dvb.frontend != NULL) {
  1297. struct i2c_adapter *tun_i2c;
  1298. fe0->dvb.frontend->sec_priv = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL);
  1299. memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops));
  1300. tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
  1301. if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
  1302. return -ENODEV;
  1303. }
  1304. break;
  1305. }
  1306. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
  1307. case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
  1308. case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
  1309. i2c_bus = &dev->i2c_bus[0];
  1310. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1311. &dvico_fusionhdtv_xc3028,
  1312. &i2c_bus->i2c_adap);
  1313. if (fe0->dvb.frontend != NULL) {
  1314. struct dvb_frontend *fe;
  1315. struct xc2028_config cfg = {
  1316. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  1317. .i2c_addr = 0x61,
  1318. };
  1319. static struct xc2028_ctrl ctl = {
  1320. .fname = XC2028_DEFAULT_FIRMWARE,
  1321. .max_len = 64,
  1322. .demod = XC3028_FE_ZARLINK456,
  1323. };
  1324. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  1325. &cfg);
  1326. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1327. fe->ops.tuner_ops.set_config(fe, &ctl);
  1328. }
  1329. break;
  1330. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
  1331. i2c_bus = &dev->i2c_bus[0];
  1332. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1333. &dvico_fusionhdtv_xc3028,
  1334. &i2c_bus->i2c_adap);
  1335. if (fe0->dvb.frontend != NULL) {
  1336. struct dvb_frontend *fe;
  1337. struct xc4000_config cfg = {
  1338. .i2c_address = 0x61,
  1339. .default_pm = 0,
  1340. .dvb_amplitude = 134,
  1341. .set_smoothedcvbs = 1,
  1342. .if_khz = 4560
  1343. };
  1344. fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
  1345. &dev->i2c_bus[1].i2c_adap, &cfg);
  1346. if (!fe) {
  1347. pr_err("%s/2: xc4000 attach failed\n",
  1348. dev->name);
  1349. goto frontend_detach;
  1350. }
  1351. }
  1352. break;
  1353. case CX23885_BOARD_TBS_6920:
  1354. i2c_bus = &dev->i2c_bus[1];
  1355. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1356. &tbs_cx24116_config,
  1357. &i2c_bus->i2c_adap);
  1358. if (fe0->dvb.frontend != NULL)
  1359. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  1360. break;
  1361. case CX23885_BOARD_TBS_6980:
  1362. case CX23885_BOARD_TBS_6981:
  1363. i2c_bus = &dev->i2c_bus[1];
  1364. switch (port->nr) {
  1365. /* PORT B */
  1366. case 1:
  1367. fe0->dvb.frontend = dvb_attach(cx24117_attach,
  1368. &tbs_cx24117_config,
  1369. &i2c_bus->i2c_adap);
  1370. break;
  1371. /* PORT C */
  1372. case 2:
  1373. fe0->dvb.frontend = dvb_attach(cx24117_attach,
  1374. &tbs_cx24117_config,
  1375. &i2c_bus->i2c_adap);
  1376. break;
  1377. }
  1378. break;
  1379. case CX23885_BOARD_TEVII_S470:
  1380. i2c_bus = &dev->i2c_bus[1];
  1381. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  1382. &tevii_ds3000_config,
  1383. &i2c_bus->i2c_adap);
  1384. if (fe0->dvb.frontend != NULL) {
  1385. dvb_attach(ts2020_attach, fe0->dvb.frontend,
  1386. &tevii_ts2020_config, &i2c_bus->i2c_adap);
  1387. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  1388. }
  1389. break;
  1390. case CX23885_BOARD_DVBWORLD_2005:
  1391. i2c_bus = &dev->i2c_bus[1];
  1392. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1393. &dvbworld_cx24116_config,
  1394. &i2c_bus->i2c_adap);
  1395. break;
  1396. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  1397. i2c_bus = &dev->i2c_bus[0];
  1398. switch (port->nr) {
  1399. /* port B */
  1400. case 1:
  1401. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  1402. &netup_stv0900_config,
  1403. &i2c_bus->i2c_adap, 0);
  1404. if (fe0->dvb.frontend != NULL) {
  1405. if (dvb_attach(stv6110_attach,
  1406. fe0->dvb.frontend,
  1407. &netup_stv6110_tunerconfig_a,
  1408. &i2c_bus->i2c_adap)) {
  1409. if (!dvb_attach(lnbh24_attach,
  1410. fe0->dvb.frontend,
  1411. &i2c_bus->i2c_adap,
  1412. LNBH24_PCL | LNBH24_TTX,
  1413. LNBH24_TEN, 0x09))
  1414. pr_err("No LNBH24 found!\n");
  1415. }
  1416. }
  1417. break;
  1418. /* port C */
  1419. case 2:
  1420. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  1421. &netup_stv0900_config,
  1422. &i2c_bus->i2c_adap, 1);
  1423. if (fe0->dvb.frontend != NULL) {
  1424. if (dvb_attach(stv6110_attach,
  1425. fe0->dvb.frontend,
  1426. &netup_stv6110_tunerconfig_b,
  1427. &i2c_bus->i2c_adap)) {
  1428. if (!dvb_attach(lnbh24_attach,
  1429. fe0->dvb.frontend,
  1430. &i2c_bus->i2c_adap,
  1431. LNBH24_PCL | LNBH24_TTX,
  1432. LNBH24_TEN, 0x0a))
  1433. pr_err("No LNBH24 found!\n");
  1434. }
  1435. }
  1436. break;
  1437. }
  1438. break;
  1439. case CX23885_BOARD_MYGICA_X8506:
  1440. i2c_bus = &dev->i2c_bus[0];
  1441. i2c_bus2 = &dev->i2c_bus[1];
  1442. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1443. &mygica_x8506_lgs8gl5_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, &mygica_x8506_xc5000_config);
  1449. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1450. break;
  1451. case CX23885_BOARD_MYGICA_X8507:
  1452. i2c_bus = &dev->i2c_bus[0];
  1453. i2c_bus2 = &dev->i2c_bus[1];
  1454. fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
  1455. &mygica_x8507_mb86a20s_config,
  1456. &i2c_bus->i2c_adap);
  1457. if (fe0->dvb.frontend == NULL)
  1458. break;
  1459. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1460. &i2c_bus2->i2c_adap,
  1461. &mygica_x8507_xc5000_config);
  1462. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1463. break;
  1464. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  1465. i2c_bus = &dev->i2c_bus[0];
  1466. i2c_bus2 = &dev->i2c_bus[1];
  1467. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1468. &magicpro_prohdtve2_lgs8g75_config,
  1469. &i2c_bus->i2c_adap);
  1470. if (fe0->dvb.frontend == NULL)
  1471. break;
  1472. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1473. &i2c_bus2->i2c_adap,
  1474. &magicpro_prohdtve2_xc5000_config);
  1475. cx23885_set_frontend_hook(port, fe0->dvb.frontend);
  1476. break;
  1477. case CX23885_BOARD_HAUPPAUGE_HVR1850:
  1478. i2c_bus = &dev->i2c_bus[0];
  1479. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1480. &hcw_s5h1411_config,
  1481. &i2c_bus->i2c_adap);
  1482. if (fe0->dvb.frontend == NULL)
  1483. break;
  1484. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1485. 0x60, &dev->i2c_bus[0].i2c_adap,
  1486. &hauppauge_tda18271_config);
  1487. tda18271_attach(&dev->ts1.analog_fe,
  1488. 0x60, &dev->i2c_bus[1].i2c_adap,
  1489. &hauppauge_tda18271_config);
  1490. break;
  1491. case CX23885_BOARD_HAUPPAUGE_HVR1290:
  1492. i2c_bus = &dev->i2c_bus[0];
  1493. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1494. &hcw_s5h1411_config,
  1495. &i2c_bus->i2c_adap);
  1496. if (fe0->dvb.frontend == NULL)
  1497. break;
  1498. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1499. 0x60, &dev->i2c_bus[0].i2c_adap,
  1500. &hauppauge_tda18271_config);
  1501. break;
  1502. case CX23885_BOARD_MYGICA_X8558PRO:
  1503. switch (port->nr) {
  1504. /* port B */
  1505. case 1:
  1506. i2c_bus = &dev->i2c_bus[0];
  1507. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  1508. &mygica_x8558pro_atbm8830_cfg1,
  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_cfg1);
  1515. break;
  1516. /* port C */
  1517. case 2:
  1518. i2c_bus = &dev->i2c_bus[1];
  1519. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  1520. &mygica_x8558pro_atbm8830_cfg2,
  1521. &i2c_bus->i2c_adap);
  1522. if (fe0->dvb.frontend == NULL)
  1523. break;
  1524. dvb_attach(max2165_attach, fe0->dvb.frontend,
  1525. &i2c_bus->i2c_adap,
  1526. &mygic_x8558pro_max2165_cfg2);
  1527. }
  1528. break;
  1529. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  1530. if (port->nr > 2)
  1531. return 0;
  1532. i2c_bus = &dev->i2c_bus[0];
  1533. mfe_shared = 1;/* MFE */
  1534. port->frontends.gate = 0;/* not clear for me yet */
  1535. /* ports B, C */
  1536. /* MFE frontend 1 DVB-T */
  1537. fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
  1538. &netup_stv0367_config[port->nr - 1],
  1539. &i2c_bus->i2c_adap);
  1540. if (fe0->dvb.frontend == NULL)
  1541. break;
  1542. if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1543. &i2c_bus->i2c_adap,
  1544. &netup_xc5000_config[port->nr - 1]))
  1545. goto frontend_detach;
  1546. /* load xc5000 firmware */
  1547. fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
  1548. /* MFE frontend 2 */
  1549. fe1 = vb2_dvb_get_frontend(&port->frontends, 2);
  1550. if (fe1 == NULL)
  1551. goto frontend_detach;
  1552. /* DVB-C init */
  1553. fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
  1554. &netup_stv0367_config[port->nr - 1],
  1555. &i2c_bus->i2c_adap);
  1556. if (fe1->dvb.frontend == NULL)
  1557. break;
  1558. fe1->dvb.frontend->id = 1;
  1559. if (NULL == dvb_attach(xc5000_attach,
  1560. fe1->dvb.frontend,
  1561. &i2c_bus->i2c_adap,
  1562. &netup_xc5000_config[port->nr - 1]))
  1563. goto frontend_detach;
  1564. break;
  1565. case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
  1566. i2c_bus = &dev->i2c_bus[0];
  1567. i2c_bus2 = &dev->i2c_bus[1];
  1568. switch (port->nr) {
  1569. /* port b */
  1570. case 1:
  1571. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1572. &terratec_drxk_config[0],
  1573. &i2c_bus->i2c_adap);
  1574. if (fe0->dvb.frontend == NULL)
  1575. break;
  1576. if (!dvb_attach(mt2063_attach,
  1577. fe0->dvb.frontend,
  1578. &terratec_mt2063_config[0],
  1579. &i2c_bus2->i2c_adap))
  1580. goto frontend_detach;
  1581. break;
  1582. /* port c */
  1583. case 2:
  1584. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1585. &terratec_drxk_config[1],
  1586. &i2c_bus->i2c_adap);
  1587. if (fe0->dvb.frontend == NULL)
  1588. break;
  1589. if (!dvb_attach(mt2063_attach,
  1590. fe0->dvb.frontend,
  1591. &terratec_mt2063_config[1],
  1592. &i2c_bus2->i2c_adap))
  1593. goto frontend_detach;
  1594. break;
  1595. }
  1596. break;
  1597. case CX23885_BOARD_TEVII_S471:
  1598. i2c_bus = &dev->i2c_bus[1];
  1599. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  1600. &tevii_ds3000_config,
  1601. &i2c_bus->i2c_adap);
  1602. if (fe0->dvb.frontend == NULL)
  1603. break;
  1604. dvb_attach(ts2020_attach, fe0->dvb.frontend,
  1605. &tevii_ts2020_config, &i2c_bus->i2c_adap);
  1606. break;
  1607. case CX23885_BOARD_PROF_8000:
  1608. i2c_bus = &dev->i2c_bus[0];
  1609. fe0->dvb.frontend = dvb_attach(stv090x_attach,
  1610. &prof_8000_stv090x_config,
  1611. &i2c_bus->i2c_adap,
  1612. STV090x_DEMODULATOR_0);
  1613. if (fe0->dvb.frontend == NULL)
  1614. break;
  1615. if (!dvb_attach(stb6100_attach,
  1616. fe0->dvb.frontend,
  1617. &prof_8000_stb6100_config,
  1618. &i2c_bus->i2c_adap))
  1619. goto frontend_detach;
  1620. fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
  1621. break;
  1622. case CX23885_BOARD_HAUPPAUGE_HVR4400: {
  1623. struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
  1624. struct a8293_platform_data a8293_pdata = {};
  1625. i2c_bus = &dev->i2c_bus[0];
  1626. i2c_bus2 = &dev->i2c_bus[1];
  1627. switch (port->nr) {
  1628. /* port b */
  1629. case 1:
  1630. /* attach demod + tuner combo */
  1631. memset(&info, 0, sizeof(info));
  1632. strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
  1633. info.addr = 0x05;
  1634. info.platform_data = &tda10071_pdata;
  1635. request_module("tda10071");
  1636. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1637. if (!client_demod || !client_demod->dev.driver)
  1638. goto frontend_detach;
  1639. if (!try_module_get(client_demod->dev.driver->owner)) {
  1640. i2c_unregister_device(client_demod);
  1641. goto frontend_detach;
  1642. }
  1643. fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
  1644. port->i2c_client_demod = client_demod;
  1645. /* attach SEC */
  1646. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1647. memset(&info, 0, sizeof(info));
  1648. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  1649. info.addr = 0x0b;
  1650. info.platform_data = &a8293_pdata;
  1651. request_module("a8293");
  1652. client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1653. if (!client_sec || !client_sec->dev.driver)
  1654. goto frontend_detach;
  1655. if (!try_module_get(client_sec->dev.driver->owner)) {
  1656. i2c_unregister_device(client_sec);
  1657. goto frontend_detach;
  1658. }
  1659. port->i2c_client_sec = client_sec;
  1660. break;
  1661. /* port c */
  1662. case 2:
  1663. /* attach frontend */
  1664. memset(&si2165_pdata, 0, sizeof(si2165_pdata));
  1665. si2165_pdata.fe = &fe0->dvb.frontend;
  1666. si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
  1667. si2165_pdata.ref_freq_Hz = 16000000,
  1668. memset(&info, 0, sizeof(struct i2c_board_info));
  1669. strlcpy(info.type, "si2165", I2C_NAME_SIZE);
  1670. info.addr = 0x64;
  1671. info.platform_data = &si2165_pdata;
  1672. request_module(info.type);
  1673. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1674. if (client_demod == NULL ||
  1675. client_demod->dev.driver == NULL)
  1676. goto frontend_detach;
  1677. if (!try_module_get(client_demod->dev.driver->owner)) {
  1678. i2c_unregister_device(client_demod);
  1679. goto frontend_detach;
  1680. }
  1681. port->i2c_client_demod = client_demod;
  1682. if (fe0->dvb.frontend == NULL)
  1683. break;
  1684. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1685. if (!dvb_attach(tda18271_attach,
  1686. fe0->dvb.frontend,
  1687. 0x60, &i2c_bus2->i2c_adap,
  1688. &hauppauge_hvr4400_tuner_config))
  1689. goto frontend_detach;
  1690. break;
  1691. }
  1692. break;
  1693. }
  1694. case CX23885_BOARD_HAUPPAUGE_STARBURST: {
  1695. struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
  1696. struct a8293_platform_data a8293_pdata = {};
  1697. i2c_bus = &dev->i2c_bus[0];
  1698. /* attach demod + tuner combo */
  1699. memset(&info, 0, sizeof(info));
  1700. strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
  1701. info.addr = 0x05;
  1702. info.platform_data = &tda10071_pdata;
  1703. request_module("tda10071");
  1704. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1705. if (!client_demod || !client_demod->dev.driver)
  1706. goto frontend_detach;
  1707. if (!try_module_get(client_demod->dev.driver->owner)) {
  1708. i2c_unregister_device(client_demod);
  1709. goto frontend_detach;
  1710. }
  1711. fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
  1712. port->i2c_client_demod = client_demod;
  1713. /* attach SEC */
  1714. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1715. memset(&info, 0, sizeof(info));
  1716. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  1717. info.addr = 0x0b;
  1718. info.platform_data = &a8293_pdata;
  1719. request_module("a8293");
  1720. client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1721. if (!client_sec || !client_sec->dev.driver)
  1722. goto frontend_detach;
  1723. if (!try_module_get(client_sec->dev.driver->owner)) {
  1724. i2c_unregister_device(client_sec);
  1725. goto frontend_detach;
  1726. }
  1727. port->i2c_client_sec = client_sec;
  1728. break;
  1729. }
  1730. case CX23885_BOARD_DVBSKY_T9580:
  1731. case CX23885_BOARD_DVBSKY_S950:
  1732. i2c_bus = &dev->i2c_bus[0];
  1733. i2c_bus2 = &dev->i2c_bus[1];
  1734. switch (port->nr) {
  1735. /* port b - satellite */
  1736. case 1:
  1737. /* attach frontend */
  1738. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1739. &dvbsky_t9580_m88ds3103_config,
  1740. &i2c_bus2->i2c_adap, &adapter);
  1741. if (fe0->dvb.frontend == NULL)
  1742. break;
  1743. /* attach tuner */
  1744. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1745. ts2020_config.fe = fe0->dvb.frontend;
  1746. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1747. memset(&info, 0, sizeof(struct i2c_board_info));
  1748. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1749. info.addr = 0x60;
  1750. info.platform_data = &ts2020_config;
  1751. request_module(info.type);
  1752. client_tuner = i2c_new_device(adapter, &info);
  1753. if (client_tuner == NULL ||
  1754. client_tuner->dev.driver == NULL)
  1755. goto frontend_detach;
  1756. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1757. i2c_unregister_device(client_tuner);
  1758. goto frontend_detach;
  1759. }
  1760. /* delegate signal strength measurement to tuner */
  1761. fe0->dvb.frontend->ops.read_signal_strength =
  1762. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1763. /*
  1764. * for setting the voltage we need to set GPIOs on
  1765. * the card.
  1766. */
  1767. port->fe_set_voltage =
  1768. fe0->dvb.frontend->ops.set_voltage;
  1769. fe0->dvb.frontend->ops.set_voltage =
  1770. dvbsky_t9580_set_voltage;
  1771. port->i2c_client_tuner = client_tuner;
  1772. break;
  1773. /* port c - terrestrial/cable */
  1774. case 2:
  1775. /* attach frontend */
  1776. memset(&si2168_config, 0, sizeof(si2168_config));
  1777. si2168_config.i2c_adapter = &adapter;
  1778. si2168_config.fe = &fe0->dvb.frontend;
  1779. si2168_config.ts_mode = SI2168_TS_SERIAL;
  1780. memset(&info, 0, sizeof(struct i2c_board_info));
  1781. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1782. info.addr = 0x64;
  1783. info.platform_data = &si2168_config;
  1784. request_module(info.type);
  1785. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1786. if (client_demod == NULL ||
  1787. client_demod->dev.driver == NULL)
  1788. goto frontend_detach;
  1789. if (!try_module_get(client_demod->dev.driver->owner)) {
  1790. i2c_unregister_device(client_demod);
  1791. goto frontend_detach;
  1792. }
  1793. port->i2c_client_demod = client_demod;
  1794. /* attach tuner */
  1795. memset(&si2157_config, 0, sizeof(si2157_config));
  1796. si2157_config.fe = fe0->dvb.frontend;
  1797. si2157_config.if_port = 1;
  1798. memset(&info, 0, sizeof(struct i2c_board_info));
  1799. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1800. info.addr = 0x60;
  1801. info.platform_data = &si2157_config;
  1802. request_module(info.type);
  1803. client_tuner = i2c_new_device(adapter, &info);
  1804. if (client_tuner == NULL ||
  1805. client_tuner->dev.driver == NULL)
  1806. goto frontend_detach;
  1807. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1808. i2c_unregister_device(client_tuner);
  1809. goto frontend_detach;
  1810. }
  1811. port->i2c_client_tuner = client_tuner;
  1812. break;
  1813. }
  1814. break;
  1815. case CX23885_BOARD_DVBSKY_T980C:
  1816. case CX23885_BOARD_TT_CT2_4500_CI:
  1817. i2c_bus = &dev->i2c_bus[0];
  1818. i2c_bus2 = &dev->i2c_bus[1];
  1819. /* attach frontend */
  1820. memset(&si2168_config, 0, sizeof(si2168_config));
  1821. si2168_config.i2c_adapter = &adapter;
  1822. si2168_config.fe = &fe0->dvb.frontend;
  1823. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1824. memset(&info, 0, sizeof(struct i2c_board_info));
  1825. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1826. info.addr = 0x64;
  1827. info.platform_data = &si2168_config;
  1828. request_module(info.type);
  1829. client_demod = i2c_new_device(&i2c_bus2->i2c_adap, &info);
  1830. if (client_demod == NULL || client_demod->dev.driver == NULL)
  1831. goto frontend_detach;
  1832. if (!try_module_get(client_demod->dev.driver->owner)) {
  1833. i2c_unregister_device(client_demod);
  1834. goto frontend_detach;
  1835. }
  1836. port->i2c_client_demod = client_demod;
  1837. /* attach tuner */
  1838. memset(&si2157_config, 0, sizeof(si2157_config));
  1839. si2157_config.fe = fe0->dvb.frontend;
  1840. si2157_config.if_port = 1;
  1841. memset(&info, 0, sizeof(struct i2c_board_info));
  1842. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1843. info.addr = 0x60;
  1844. info.platform_data = &si2157_config;
  1845. request_module(info.type);
  1846. client_tuner = i2c_new_device(adapter, &info);
  1847. if (client_tuner == NULL ||
  1848. client_tuner->dev.driver == NULL)
  1849. goto frontend_detach;
  1850. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1851. i2c_unregister_device(client_tuner);
  1852. goto frontend_detach;
  1853. }
  1854. port->i2c_client_tuner = client_tuner;
  1855. break;
  1856. case CX23885_BOARD_DVBSKY_S950C:
  1857. i2c_bus = &dev->i2c_bus[0];
  1858. i2c_bus2 = &dev->i2c_bus[1];
  1859. /* attach frontend */
  1860. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1861. &dvbsky_s950c_m88ds3103_config,
  1862. &i2c_bus2->i2c_adap, &adapter);
  1863. if (fe0->dvb.frontend == NULL)
  1864. break;
  1865. /* attach tuner */
  1866. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1867. ts2020_config.fe = fe0->dvb.frontend;
  1868. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1869. memset(&info, 0, sizeof(struct i2c_board_info));
  1870. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1871. info.addr = 0x60;
  1872. info.platform_data = &ts2020_config;
  1873. request_module(info.type);
  1874. client_tuner = i2c_new_device(adapter, &info);
  1875. if (client_tuner == NULL || client_tuner->dev.driver == NULL)
  1876. goto frontend_detach;
  1877. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1878. i2c_unregister_device(client_tuner);
  1879. goto frontend_detach;
  1880. }
  1881. /* delegate signal strength measurement to tuner */
  1882. fe0->dvb.frontend->ops.read_signal_strength =
  1883. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1884. port->i2c_client_tuner = client_tuner;
  1885. break;
  1886. case CX23885_BOARD_DVBSKY_S952:
  1887. switch (port->nr) {
  1888. /* port b */
  1889. case 1:
  1890. i2c_bus = &dev->i2c_bus[1];
  1891. p_m88ds3103_config = &dvbsky_t9580_m88ds3103_config;
  1892. p_set_voltage = dvbsky_t9580_set_voltage;
  1893. break;
  1894. /* port c */
  1895. case 2:
  1896. i2c_bus = &dev->i2c_bus[0];
  1897. p_m88ds3103_config = &dvbsky_s952_portc_m88ds3103_config;
  1898. p_set_voltage = dvbsky_s952_portc_set_voltage;
  1899. break;
  1900. }
  1901. /* attach frontend */
  1902. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1903. p_m88ds3103_config,
  1904. &i2c_bus->i2c_adap, &adapter);
  1905. if (fe0->dvb.frontend == NULL)
  1906. break;
  1907. /* attach tuner */
  1908. memset(&ts2020_config, 0, sizeof(ts2020_config));
  1909. ts2020_config.fe = fe0->dvb.frontend;
  1910. ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
  1911. memset(&info, 0, sizeof(struct i2c_board_info));
  1912. strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
  1913. info.addr = 0x60;
  1914. info.platform_data = &ts2020_config;
  1915. request_module(info.type);
  1916. client_tuner = i2c_new_device(adapter, &info);
  1917. if (client_tuner == NULL || client_tuner->dev.driver == NULL)
  1918. goto frontend_detach;
  1919. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1920. i2c_unregister_device(client_tuner);
  1921. goto frontend_detach;
  1922. }
  1923. /* delegate signal strength measurement to tuner */
  1924. fe0->dvb.frontend->ops.read_signal_strength =
  1925. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  1926. /*
  1927. * for setting the voltage we need to set GPIOs on
  1928. * the card.
  1929. */
  1930. port->fe_set_voltage =
  1931. fe0->dvb.frontend->ops.set_voltage;
  1932. fe0->dvb.frontend->ops.set_voltage = p_set_voltage;
  1933. port->i2c_client_tuner = client_tuner;
  1934. break;
  1935. case CX23885_BOARD_DVBSKY_T982:
  1936. memset(&si2168_config, 0, sizeof(si2168_config));
  1937. switch (port->nr) {
  1938. /* port b */
  1939. case 1:
  1940. i2c_bus = &dev->i2c_bus[1];
  1941. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1942. break;
  1943. /* port c */
  1944. case 2:
  1945. i2c_bus = &dev->i2c_bus[0];
  1946. si2168_config.ts_mode = SI2168_TS_SERIAL;
  1947. break;
  1948. }
  1949. /* attach frontend */
  1950. si2168_config.i2c_adapter = &adapter;
  1951. si2168_config.fe = &fe0->dvb.frontend;
  1952. memset(&info, 0, sizeof(struct i2c_board_info));
  1953. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1954. info.addr = 0x64;
  1955. info.platform_data = &si2168_config;
  1956. request_module(info.type);
  1957. client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
  1958. if (client_demod == NULL || client_demod->dev.driver == NULL)
  1959. goto frontend_detach;
  1960. if (!try_module_get(client_demod->dev.driver->owner)) {
  1961. i2c_unregister_device(client_demod);
  1962. goto frontend_detach;
  1963. }
  1964. port->i2c_client_demod = client_demod;
  1965. /* attach tuner */
  1966. memset(&si2157_config, 0, sizeof(si2157_config));
  1967. si2157_config.fe = fe0->dvb.frontend;
  1968. si2157_config.if_port = 1;
  1969. memset(&info, 0, sizeof(struct i2c_board_info));
  1970. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1971. info.addr = 0x60;
  1972. info.platform_data = &si2157_config;
  1973. request_module(info.type);
  1974. client_tuner = i2c_new_device(adapter, &info);
  1975. if (client_tuner == NULL ||
  1976. client_tuner->dev.driver == NULL)
  1977. goto frontend_detach;
  1978. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1979. i2c_unregister_device(client_tuner);
  1980. goto frontend_detach;
  1981. }
  1982. port->i2c_client_tuner = client_tuner;
  1983. break;
  1984. case CX23885_BOARD_HAUPPAUGE_HVR5525: {
  1985. struct m88rs6000t_config m88rs6000t_config;
  1986. struct a8293_platform_data a8293_pdata = {};
  1987. switch (port->nr) {
  1988. /* port b - satellite */
  1989. case 1:
  1990. /* attach frontend */
  1991. fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
  1992. &hauppauge_hvr5525_m88ds3103_config,
  1993. &dev->i2c_bus[0].i2c_adap, &adapter);
  1994. if (fe0->dvb.frontend == NULL)
  1995. break;
  1996. /* attach SEC */
  1997. a8293_pdata.dvb_frontend = fe0->dvb.frontend;
  1998. memset(&info, 0, sizeof(info));
  1999. strlcpy(info.type, "a8293", I2C_NAME_SIZE);
  2000. info.addr = 0x0b;
  2001. info.platform_data = &a8293_pdata;
  2002. request_module("a8293");
  2003. client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2004. if (!client_sec || !client_sec->dev.driver)
  2005. goto frontend_detach;
  2006. if (!try_module_get(client_sec->dev.driver->owner)) {
  2007. i2c_unregister_device(client_sec);
  2008. goto frontend_detach;
  2009. }
  2010. port->i2c_client_sec = client_sec;
  2011. /* attach tuner */
  2012. memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
  2013. m88rs6000t_config.fe = fe0->dvb.frontend;
  2014. memset(&info, 0, sizeof(struct i2c_board_info));
  2015. strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
  2016. info.addr = 0x21;
  2017. info.platform_data = &m88rs6000t_config;
  2018. request_module("%s", info.type);
  2019. client_tuner = i2c_new_device(adapter, &info);
  2020. if (!client_tuner || !client_tuner->dev.driver)
  2021. goto frontend_detach;
  2022. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2023. i2c_unregister_device(client_tuner);
  2024. goto frontend_detach;
  2025. }
  2026. port->i2c_client_tuner = client_tuner;
  2027. /* delegate signal strength measurement to tuner */
  2028. fe0->dvb.frontend->ops.read_signal_strength =
  2029. fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
  2030. break;
  2031. /* port c - terrestrial/cable */
  2032. case 2:
  2033. /* attach frontend */
  2034. memset(&si2168_config, 0, sizeof(si2168_config));
  2035. si2168_config.i2c_adapter = &adapter;
  2036. si2168_config.fe = &fe0->dvb.frontend;
  2037. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2038. memset(&info, 0, sizeof(struct i2c_board_info));
  2039. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2040. info.addr = 0x64;
  2041. info.platform_data = &si2168_config;
  2042. request_module("%s", info.type);
  2043. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2044. if (!client_demod || !client_demod->dev.driver)
  2045. goto frontend_detach;
  2046. if (!try_module_get(client_demod->dev.driver->owner)) {
  2047. i2c_unregister_device(client_demod);
  2048. goto frontend_detach;
  2049. }
  2050. port->i2c_client_demod = client_demod;
  2051. /* attach tuner */
  2052. memset(&si2157_config, 0, sizeof(si2157_config));
  2053. si2157_config.fe = fe0->dvb.frontend;
  2054. si2157_config.if_port = 1;
  2055. memset(&info, 0, sizeof(struct i2c_board_info));
  2056. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2057. info.addr = 0x60;
  2058. info.platform_data = &si2157_config;
  2059. request_module("%s", info.type);
  2060. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2061. if (!client_tuner || !client_tuner->dev.driver) {
  2062. module_put(client_demod->dev.driver->owner);
  2063. i2c_unregister_device(client_demod);
  2064. port->i2c_client_demod = NULL;
  2065. goto frontend_detach;
  2066. }
  2067. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2068. i2c_unregister_device(client_tuner);
  2069. module_put(client_demod->dev.driver->owner);
  2070. i2c_unregister_device(client_demod);
  2071. port->i2c_client_demod = NULL;
  2072. goto frontend_detach;
  2073. }
  2074. port->i2c_client_tuner = client_tuner;
  2075. break;
  2076. }
  2077. break;
  2078. }
  2079. case CX23885_BOARD_HAUPPAUGE_QUADHD_DVB:
  2080. switch (port->nr) {
  2081. /* port b - Terrestrial/cable */
  2082. case 1:
  2083. /* attach frontend */
  2084. memset(&si2168_config, 0, sizeof(si2168_config));
  2085. si2168_config.i2c_adapter = &adapter;
  2086. si2168_config.fe = &fe0->dvb.frontend;
  2087. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2088. memset(&info, 0, sizeof(struct i2c_board_info));
  2089. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2090. info.addr = 0x64;
  2091. info.platform_data = &si2168_config;
  2092. request_module("%s", info.type);
  2093. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2094. if (!client_demod || !client_demod->dev.driver)
  2095. goto frontend_detach;
  2096. if (!try_module_get(client_demod->dev.driver->owner)) {
  2097. i2c_unregister_device(client_demod);
  2098. goto frontend_detach;
  2099. }
  2100. port->i2c_client_demod = client_demod;
  2101. /* attach tuner */
  2102. memset(&si2157_config, 0, sizeof(si2157_config));
  2103. si2157_config.fe = fe0->dvb.frontend;
  2104. si2157_config.if_port = 1;
  2105. memset(&info, 0, sizeof(struct i2c_board_info));
  2106. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2107. info.addr = 0x60;
  2108. info.platform_data = &si2157_config;
  2109. request_module("%s", info.type);
  2110. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2111. if (!client_tuner || !client_tuner->dev.driver) {
  2112. module_put(client_demod->dev.driver->owner);
  2113. i2c_unregister_device(client_demod);
  2114. port->i2c_client_demod = NULL;
  2115. goto frontend_detach;
  2116. }
  2117. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2118. i2c_unregister_device(client_tuner);
  2119. module_put(client_demod->dev.driver->owner);
  2120. i2c_unregister_device(client_demod);
  2121. port->i2c_client_demod = NULL;
  2122. goto frontend_detach;
  2123. }
  2124. port->i2c_client_tuner = client_tuner;
  2125. break;
  2126. /* port c - terrestrial/cable */
  2127. case 2:
  2128. /* attach frontend */
  2129. memset(&si2168_config, 0, sizeof(si2168_config));
  2130. si2168_config.i2c_adapter = &adapter;
  2131. si2168_config.fe = &fe0->dvb.frontend;
  2132. si2168_config.ts_mode = SI2168_TS_SERIAL;
  2133. memset(&info, 0, sizeof(struct i2c_board_info));
  2134. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  2135. info.addr = 0x66;
  2136. info.platform_data = &si2168_config;
  2137. request_module("%s", info.type);
  2138. client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
  2139. if (!client_demod || !client_demod->dev.driver)
  2140. goto frontend_detach;
  2141. if (!try_module_get(client_demod->dev.driver->owner)) {
  2142. i2c_unregister_device(client_demod);
  2143. goto frontend_detach;
  2144. }
  2145. port->i2c_client_demod = client_demod;
  2146. /* attach tuner */
  2147. memset(&si2157_config, 0, sizeof(si2157_config));
  2148. si2157_config.fe = fe0->dvb.frontend;
  2149. si2157_config.if_port = 1;
  2150. memset(&info, 0, sizeof(struct i2c_board_info));
  2151. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2152. info.addr = 0x62;
  2153. info.platform_data = &si2157_config;
  2154. request_module("%s", info.type);
  2155. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2156. if (!client_tuner || !client_tuner->dev.driver) {
  2157. module_put(client_demod->dev.driver->owner);
  2158. i2c_unregister_device(client_demod);
  2159. port->i2c_client_demod = NULL;
  2160. goto frontend_detach;
  2161. }
  2162. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2163. i2c_unregister_device(client_tuner);
  2164. module_put(client_demod->dev.driver->owner);
  2165. i2c_unregister_device(client_demod);
  2166. port->i2c_client_demod = NULL;
  2167. goto frontend_detach;
  2168. }
  2169. port->i2c_client_tuner = client_tuner;
  2170. break;
  2171. }
  2172. break;
  2173. case CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC:
  2174. switch (port->nr) {
  2175. /* port b - Terrestrial/cable */
  2176. case 1:
  2177. /* attach frontend */
  2178. i2c_bus = &dev->i2c_bus[0];
  2179. fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
  2180. &hauppauge_quadHD_ATSC_a_config, &i2c_bus->i2c_adap);
  2181. if (fe0->dvb.frontend == NULL)
  2182. break;
  2183. /* attach tuner */
  2184. memset(&si2157_config, 0, sizeof(si2157_config));
  2185. si2157_config.fe = fe0->dvb.frontend;
  2186. si2157_config.if_port = 1;
  2187. si2157_config.inversion = 1;
  2188. memset(&info, 0, sizeof(struct i2c_board_info));
  2189. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2190. info.addr = 0x60;
  2191. info.platform_data = &si2157_config;
  2192. request_module("%s", info.type);
  2193. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2194. if (!client_tuner || !client_tuner->dev.driver) {
  2195. module_put(client_demod->dev.driver->owner);
  2196. i2c_unregister_device(client_demod);
  2197. port->i2c_client_demod = NULL;
  2198. goto frontend_detach;
  2199. }
  2200. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2201. i2c_unregister_device(client_tuner);
  2202. module_put(client_demod->dev.driver->owner);
  2203. i2c_unregister_device(client_demod);
  2204. port->i2c_client_demod = NULL;
  2205. goto frontend_detach;
  2206. }
  2207. port->i2c_client_tuner = client_tuner;
  2208. break;
  2209. /* port c - terrestrial/cable */
  2210. case 2:
  2211. /* attach frontend */
  2212. i2c_bus = &dev->i2c_bus[0];
  2213. fe0->dvb.frontend = dvb_attach(lgdt3306a_attach,
  2214. &hauppauge_quadHD_ATSC_b_config, &i2c_bus->i2c_adap);
  2215. if (fe0->dvb.frontend == NULL)
  2216. break;
  2217. /* attach tuner */
  2218. memset(&si2157_config, 0, sizeof(si2157_config));
  2219. si2157_config.fe = fe0->dvb.frontend;
  2220. si2157_config.if_port = 1;
  2221. si2157_config.inversion = 1;
  2222. memset(&info, 0, sizeof(struct i2c_board_info));
  2223. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  2224. info.addr = 0x62;
  2225. info.platform_data = &si2157_config;
  2226. request_module("%s", info.type);
  2227. client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
  2228. if (!client_tuner || !client_tuner->dev.driver) {
  2229. module_put(client_demod->dev.driver->owner);
  2230. i2c_unregister_device(client_demod);
  2231. port->i2c_client_demod = NULL;
  2232. goto frontend_detach;
  2233. }
  2234. if (!try_module_get(client_tuner->dev.driver->owner)) {
  2235. i2c_unregister_device(client_tuner);
  2236. module_put(client_demod->dev.driver->owner);
  2237. i2c_unregister_device(client_demod);
  2238. port->i2c_client_demod = NULL;
  2239. goto frontend_detach;
  2240. }
  2241. port->i2c_client_tuner = client_tuner;
  2242. break;
  2243. }
  2244. break;
  2245. default:
  2246. pr_info("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  2247. dev->name);
  2248. break;
  2249. }
  2250. if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
  2251. pr_err("%s: frontend initialization failed\n",
  2252. dev->name);
  2253. goto frontend_detach;
  2254. }
  2255. /* define general-purpose callback pointer */
  2256. fe0->dvb.frontend->callback = cx23885_tuner_callback;
  2257. if (fe1)
  2258. fe1->dvb.frontend->callback = cx23885_tuner_callback;
  2259. #if 0
  2260. /* Ensure all frontends negotiate bus access */
  2261. fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  2262. if (fe1)
  2263. fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  2264. #endif
  2265. /* Put the analog decoder in standby to keep it quiet */
  2266. call_all(dev, core, s_power, 0);
  2267. if (fe0->dvb.frontend->ops.analog_ops.standby)
  2268. fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
  2269. /* register everything */
  2270. ret = vb2_dvb_register_bus(&port->frontends, THIS_MODULE, port,
  2271. &dev->pci->dev, NULL,
  2272. adapter_nr, mfe_shared);
  2273. if (ret)
  2274. goto frontend_detach;
  2275. ret = dvb_register_ci_mac(port);
  2276. if (ret)
  2277. goto frontend_detach;
  2278. return 0;
  2279. frontend_detach:
  2280. /* remove I2C client for SEC */
  2281. client_sec = port->i2c_client_sec;
  2282. if (client_sec) {
  2283. module_put(client_sec->dev.driver->owner);
  2284. i2c_unregister_device(client_sec);
  2285. port->i2c_client_sec = NULL;
  2286. }
  2287. /* remove I2C client for tuner */
  2288. client_tuner = port->i2c_client_tuner;
  2289. if (client_tuner) {
  2290. module_put(client_tuner->dev.driver->owner);
  2291. i2c_unregister_device(client_tuner);
  2292. port->i2c_client_tuner = NULL;
  2293. }
  2294. /* remove I2C client for demodulator */
  2295. client_demod = port->i2c_client_demod;
  2296. if (client_demod) {
  2297. module_put(client_demod->dev.driver->owner);
  2298. i2c_unregister_device(client_demod);
  2299. port->i2c_client_demod = NULL;
  2300. }
  2301. port->gate_ctrl = NULL;
  2302. vb2_dvb_dealloc_frontends(&port->frontends);
  2303. return -EINVAL;
  2304. }
  2305. int cx23885_dvb_register(struct cx23885_tsport *port)
  2306. {
  2307. struct vb2_dvb_frontend *fe0;
  2308. struct cx23885_dev *dev = port->dev;
  2309. int err, i;
  2310. /* Here we need to allocate the correct number of frontends,
  2311. * as reflected in the cards struct. The reality is that currently
  2312. * no cx23885 boards support this - yet. But, if we don't modify this
  2313. * code then the second frontend would never be allocated (later)
  2314. * and fail with error before the attach in dvb_register().
  2315. * Without these changes we risk an OOPS later. The changes here
  2316. * are for safety, and should provide a good foundation for the
  2317. * future addition of any multi-frontend cx23885 based boards.
  2318. */
  2319. pr_info("%s() allocating %d frontend(s)\n", __func__,
  2320. port->num_frontends);
  2321. for (i = 1; i <= port->num_frontends; i++) {
  2322. struct vb2_queue *q;
  2323. if (vb2_dvb_alloc_frontend(
  2324. &port->frontends, i) == NULL) {
  2325. pr_err("%s() failed to alloc\n", __func__);
  2326. return -ENOMEM;
  2327. }
  2328. fe0 = vb2_dvb_get_frontend(&port->frontends, i);
  2329. if (!fe0)
  2330. return -EINVAL;
  2331. dprintk(1, "%s\n", __func__);
  2332. dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
  2333. dev->board,
  2334. dev->name,
  2335. dev->pci_bus,
  2336. dev->pci_slot);
  2337. err = -ENODEV;
  2338. /* dvb stuff */
  2339. /* We have to init the queue for each frontend on a port. */
  2340. pr_info("%s: cx23885 based dvb card\n", dev->name);
  2341. q = &fe0->dvb.dvbq;
  2342. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  2343. q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
  2344. q->gfp_flags = GFP_DMA32;
  2345. q->min_buffers_needed = 2;
  2346. q->drv_priv = port;
  2347. q->buf_struct_size = sizeof(struct cx23885_buffer);
  2348. q->ops = &dvb_qops;
  2349. q->mem_ops = &vb2_dma_sg_memops;
  2350. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  2351. q->lock = &dev->lock;
  2352. q->dev = &dev->pci->dev;
  2353. err = vb2_queue_init(q);
  2354. if (err < 0)
  2355. return err;
  2356. }
  2357. err = dvb_register(port);
  2358. if (err != 0)
  2359. pr_err("%s() dvb_register failed err = %d\n",
  2360. __func__, err);
  2361. return err;
  2362. }
  2363. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  2364. {
  2365. struct vb2_dvb_frontend *fe0;
  2366. struct i2c_client *client;
  2367. /* remove I2C client for CI */
  2368. client = port->i2c_client_ci;
  2369. if (client) {
  2370. module_put(client->dev.driver->owner);
  2371. i2c_unregister_device(client);
  2372. }
  2373. /* remove I2C client for SEC */
  2374. client = port->i2c_client_sec;
  2375. if (client) {
  2376. module_put(client->dev.driver->owner);
  2377. i2c_unregister_device(client);
  2378. }
  2379. /* remove I2C client for tuner */
  2380. client = port->i2c_client_tuner;
  2381. if (client) {
  2382. module_put(client->dev.driver->owner);
  2383. i2c_unregister_device(client);
  2384. }
  2385. /* remove I2C client for demodulator */
  2386. client = port->i2c_client_demod;
  2387. if (client) {
  2388. module_put(client->dev.driver->owner);
  2389. i2c_unregister_device(client);
  2390. }
  2391. fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
  2392. if (fe0 && fe0->dvb.frontend)
  2393. vb2_dvb_unregister_bus(&port->frontends);
  2394. switch (port->dev->board) {
  2395. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  2396. netup_ci_exit(port);
  2397. break;
  2398. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  2399. altera_ci_release(port->dev, port->nr);
  2400. break;
  2401. }
  2402. port->gate_ctrl = NULL;
  2403. return 0;
  2404. }