cx23885-dvb.c 77 KB

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