cx23885-dvb.c 67 KB

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