cx23885-dvb.c 75 KB

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