cx23885-dvb.c 77 KB

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