saa7134-dvb.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * (c) 2004 Gerd Knorr <[email protected]> [SuSE Labs]
  5. *
  6. * Extended 3 / 2005 by Hartmut Hackmann to support various
  7. * cards with the tda10046 DVB-T channel decoder
  8. */
  9. #include "saa7134.h"
  10. #include "saa7134-reg.h"
  11. #include <linux/init.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/delay.h>
  16. #include <linux/kthread.h>
  17. #include <linux/suspend.h>
  18. #include <media/v4l2-common.h>
  19. #include "dvb-pll.h"
  20. #include <media/dvb_frontend.h>
  21. #include "mt352.h"
  22. #include "mt352_priv.h" /* FIXME */
  23. #include "tda1004x.h"
  24. #include "nxt200x.h"
  25. #include "xc2028.h"
  26. #include "xc5000.h"
  27. #include "tda10086.h"
  28. #include "tda826x.h"
  29. #include "tda827x.h"
  30. #include "isl6421.h"
  31. #include "isl6405.h"
  32. #include "lnbp21.h"
  33. #include "tuner-simple.h"
  34. #include "tda10048.h"
  35. #include "tda18271.h"
  36. #include "lgdt3305.h"
  37. #include "tda8290.h"
  38. #include "mb86a20s.h"
  39. #include "lgs8gxx.h"
  40. #include "zl10353.h"
  41. #include "qt1010.h"
  42. #include "zl10036.h"
  43. #include "zl10039.h"
  44. #include "mt312.h"
  45. #include "s5h1411.h"
  46. MODULE_AUTHOR("Gerd Knorr <[email protected]> [SuSE Labs]");
  47. MODULE_LICENSE("GPL");
  48. static unsigned int antenna_pwr;
  49. module_param(antenna_pwr, int, 0444);
  50. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  51. static int use_frontend;
  52. module_param(use_frontend, int, 0644);
  53. MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
  54. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  55. /* ------------------------------------------------------------------
  56. * mt352 based DVB-T cards
  57. */
  58. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  59. {
  60. u32 ok;
  61. if (!on) {
  62. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  63. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  64. return 0;
  65. }
  66. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  67. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  68. udelay(10);
  69. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  70. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  71. udelay(10);
  72. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  73. udelay(10);
  74. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  75. pr_debug("%s %s\n", __func__, ok ? "on" : "off");
  76. if (!ok)
  77. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  78. return ok;
  79. }
  80. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  81. {
  82. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  83. static u8 reset [] = { RESET, 0x80 };
  84. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  85. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  86. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  87. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  88. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  89. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  90. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  91. pr_debug("%s called\n", __func__);
  92. mt352_write(fe, clock_config, sizeof(clock_config));
  93. udelay(200);
  94. mt352_write(fe, reset, sizeof(reset));
  95. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  96. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  97. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  98. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  99. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  100. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  101. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  102. return 0;
  103. }
  104. static int mt352_aver777_init(struct dvb_frontend* fe)
  105. {
  106. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  107. static u8 reset [] = { RESET, 0x80 };
  108. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  109. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  110. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  111. mt352_write(fe, clock_config, sizeof(clock_config));
  112. udelay(200);
  113. mt352_write(fe, reset, sizeof(reset));
  114. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  115. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  116. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  117. return 0;
  118. }
  119. static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
  120. {
  121. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  122. static u8 reset [] = { RESET, 0x80 };
  123. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  124. static u8 agc_cfg [] = { AGC_TARGET, 0xe };
  125. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  126. mt352_write(fe, clock_config, sizeof(clock_config));
  127. udelay(200);
  128. mt352_write(fe, reset, sizeof(reset));
  129. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  130. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  131. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  132. return 0;
  133. }
  134. static int mt352_pinnacle_tuner_set_params(struct dvb_frontend *fe)
  135. {
  136. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  137. u8 off[] = { 0x00, 0xf1};
  138. u8 on[] = { 0x00, 0x71};
  139. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  140. struct saa7134_dev *dev = fe->dvb->priv;
  141. struct v4l2_frequency f;
  142. /* set frequency (mt2050) */
  143. f.tuner = 0;
  144. f.type = V4L2_TUNER_DIGITAL_TV;
  145. f.frequency = c->frequency / 1000 * 16 / 1000;
  146. if (fe->ops.i2c_gate_ctrl)
  147. fe->ops.i2c_gate_ctrl(fe, 1);
  148. i2c_transfer(&dev->i2c_adap, &msg, 1);
  149. saa_call_all(dev, tuner, s_frequency, &f);
  150. msg.buf = on;
  151. if (fe->ops.i2c_gate_ctrl)
  152. fe->ops.i2c_gate_ctrl(fe, 1);
  153. i2c_transfer(&dev->i2c_adap, &msg, 1);
  154. pinnacle_antenna_pwr(dev, antenna_pwr);
  155. /* mt352 setup */
  156. return mt352_pinnacle_init(fe);
  157. }
  158. static struct mt352_config pinnacle_300i = {
  159. .demod_address = 0x3c >> 1,
  160. .adc_clock = 20333,
  161. .if2 = 36150,
  162. .no_tuner = 1,
  163. .demod_init = mt352_pinnacle_init,
  164. };
  165. static struct mt352_config avermedia_777 = {
  166. .demod_address = 0xf,
  167. .demod_init = mt352_aver777_init,
  168. };
  169. static struct mt352_config avermedia_xc3028_mt352_dev = {
  170. .demod_address = (0x1e >> 1),
  171. .no_tuner = 1,
  172. .demod_init = mt352_avermedia_xc3028_init,
  173. };
  174. static struct tda18271_std_map mb86a20s_tda18271_std_map = {
  175. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  176. .if_lvl = 7, .rfagc_top = 0x37, },
  177. };
  178. static struct tda18271_config kworld_tda18271_config = {
  179. .std_map = &mb86a20s_tda18271_std_map,
  180. .gate = TDA18271_GATE_DIGITAL,
  181. .config = 3, /* Use tuner callback for AGC */
  182. };
  183. static const struct mb86a20s_config kworld_mb86a20s_config = {
  184. .demod_address = 0x10,
  185. };
  186. static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
  187. {
  188. struct saa7134_dev *dev = fe->dvb->priv;
  189. unsigned char initmsg[] = {0x45, 0x97};
  190. unsigned char msg_enable[] = {0x45, 0xc1};
  191. unsigned char msg_disable[] = {0x45, 0x81};
  192. struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
  193. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
  194. pr_warn("could not access the I2C gate\n");
  195. return -EIO;
  196. }
  197. if (enable)
  198. msg.buf = msg_enable;
  199. else
  200. msg.buf = msg_disable;
  201. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
  202. pr_warn("could not access the I2C gate\n");
  203. return -EIO;
  204. }
  205. msleep(20);
  206. return 0;
  207. }
  208. /* ==================================================================
  209. * tda1004x based DVB-T cards, helper functions
  210. */
  211. static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
  212. const struct firmware **fw, char *name)
  213. {
  214. struct saa7134_dev *dev = fe->dvb->priv;
  215. return request_firmware(fw, name, &dev->pci->dev);
  216. }
  217. /* ------------------------------------------------------------------
  218. * these tuners are tu1216, td1316(a)
  219. */
  220. static int philips_tda6651_pll_set(struct dvb_frontend *fe)
  221. {
  222. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  223. struct saa7134_dev *dev = fe->dvb->priv;
  224. struct tda1004x_state *state = fe->demodulator_priv;
  225. u8 addr = state->config->tuner_address;
  226. u8 tuner_buf[4];
  227. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  228. sizeof(tuner_buf) };
  229. int tuner_frequency = 0;
  230. u8 band, cp, filter;
  231. /* determine charge pump */
  232. tuner_frequency = c->frequency + 36166000;
  233. if (tuner_frequency < 87000000)
  234. return -EINVAL;
  235. else if (tuner_frequency < 130000000)
  236. cp = 3;
  237. else if (tuner_frequency < 160000000)
  238. cp = 5;
  239. else if (tuner_frequency < 200000000)
  240. cp = 6;
  241. else if (tuner_frequency < 290000000)
  242. cp = 3;
  243. else if (tuner_frequency < 420000000)
  244. cp = 5;
  245. else if (tuner_frequency < 480000000)
  246. cp = 6;
  247. else if (tuner_frequency < 620000000)
  248. cp = 3;
  249. else if (tuner_frequency < 830000000)
  250. cp = 5;
  251. else if (tuner_frequency < 895000000)
  252. cp = 7;
  253. else
  254. return -EINVAL;
  255. /* determine band */
  256. if (c->frequency < 49000000)
  257. return -EINVAL;
  258. else if (c->frequency < 161000000)
  259. band = 1;
  260. else if (c->frequency < 444000000)
  261. band = 2;
  262. else if (c->frequency < 861000000)
  263. band = 4;
  264. else
  265. return -EINVAL;
  266. /* setup PLL filter */
  267. switch (c->bandwidth_hz) {
  268. case 6000000:
  269. filter = 0;
  270. break;
  271. case 7000000:
  272. filter = 0;
  273. break;
  274. case 8000000:
  275. filter = 1;
  276. break;
  277. default:
  278. return -EINVAL;
  279. }
  280. /* calculate divisor
  281. * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
  282. */
  283. tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;
  284. /* setup tuner buffer */
  285. tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
  286. tuner_buf[1] = tuner_frequency & 0xff;
  287. tuner_buf[2] = 0xca;
  288. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  289. if (fe->ops.i2c_gate_ctrl)
  290. fe->ops.i2c_gate_ctrl(fe, 1);
  291. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
  292. pr_warn("could not write to tuner at addr: 0x%02x\n",
  293. addr << 1);
  294. return -EIO;
  295. }
  296. msleep(1);
  297. return 0;
  298. }
  299. static int philips_tu1216_init(struct dvb_frontend *fe)
  300. {
  301. struct saa7134_dev *dev = fe->dvb->priv;
  302. struct tda1004x_state *state = fe->demodulator_priv;
  303. u8 addr = state->config->tuner_address;
  304. static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  305. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
  306. /* setup PLL configuration */
  307. if (fe->ops.i2c_gate_ctrl)
  308. fe->ops.i2c_gate_ctrl(fe, 1);
  309. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  310. return -EIO;
  311. msleep(1);
  312. return 0;
  313. }
  314. /* ------------------------------------------------------------------ */
  315. static struct tda1004x_config philips_tu1216_60_config = {
  316. .demod_address = 0x8,
  317. .invert = 1,
  318. .invert_oclk = 0,
  319. .xtal_freq = TDA10046_XTAL_4M,
  320. .agc_config = TDA10046_AGC_DEFAULT,
  321. .if_freq = TDA10046_FREQ_3617,
  322. .tuner_address = 0x60,
  323. .request_firmware = philips_tda1004x_request_firmware
  324. };
  325. static struct tda1004x_config philips_tu1216_61_config = {
  326. .demod_address = 0x8,
  327. .invert = 1,
  328. .invert_oclk = 0,
  329. .xtal_freq = TDA10046_XTAL_4M,
  330. .agc_config = TDA10046_AGC_DEFAULT,
  331. .if_freq = TDA10046_FREQ_3617,
  332. .tuner_address = 0x61,
  333. .request_firmware = philips_tda1004x_request_firmware
  334. };
  335. /* ------------------------------------------------------------------ */
  336. static int philips_td1316_tuner_init(struct dvb_frontend *fe)
  337. {
  338. struct saa7134_dev *dev = fe->dvb->priv;
  339. struct tda1004x_state *state = fe->demodulator_priv;
  340. u8 addr = state->config->tuner_address;
  341. static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
  342. struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  343. /* setup PLL configuration */
  344. if (fe->ops.i2c_gate_ctrl)
  345. fe->ops.i2c_gate_ctrl(fe, 1);
  346. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  347. return -EIO;
  348. return 0;
  349. }
  350. static int philips_td1316_tuner_set_params(struct dvb_frontend *fe)
  351. {
  352. return philips_tda6651_pll_set(fe);
  353. }
  354. static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
  355. {
  356. struct saa7134_dev *dev = fe->dvb->priv;
  357. struct tda1004x_state *state = fe->demodulator_priv;
  358. u8 addr = state->config->tuner_address;
  359. static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
  360. struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  361. /* switch the tuner to analog mode */
  362. if (fe->ops.i2c_gate_ctrl)
  363. fe->ops.i2c_gate_ctrl(fe, 1);
  364. if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
  365. return -EIO;
  366. return 0;
  367. }
  368. /* ------------------------------------------------------------------ */
  369. static int philips_europa_tuner_init(struct dvb_frontend *fe)
  370. {
  371. struct saa7134_dev *dev = fe->dvb->priv;
  372. static u8 msg[] = { 0x00, 0x40};
  373. struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  374. if (philips_td1316_tuner_init(fe))
  375. return -EIO;
  376. msleep(1);
  377. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  378. return -EIO;
  379. return 0;
  380. }
  381. static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
  382. {
  383. struct saa7134_dev *dev = fe->dvb->priv;
  384. static u8 msg[] = { 0x00, 0x14 };
  385. struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  386. if (philips_td1316_tuner_sleep(fe))
  387. return -EIO;
  388. /* switch the board to analog mode */
  389. if (fe->ops.i2c_gate_ctrl)
  390. fe->ops.i2c_gate_ctrl(fe, 1);
  391. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  392. return 0;
  393. }
  394. static int philips_europa_demod_sleep(struct dvb_frontend *fe)
  395. {
  396. struct saa7134_dev *dev = fe->dvb->priv;
  397. if (dev->original_demod_sleep)
  398. dev->original_demod_sleep(fe);
  399. fe->ops.i2c_gate_ctrl(fe, 1);
  400. return 0;
  401. }
  402. static struct tda1004x_config philips_europa_config = {
  403. .demod_address = 0x8,
  404. .invert = 0,
  405. .invert_oclk = 0,
  406. .xtal_freq = TDA10046_XTAL_4M,
  407. .agc_config = TDA10046_AGC_IFO_AUTO_POS,
  408. .if_freq = TDA10046_FREQ_052,
  409. .tuner_address = 0x61,
  410. .request_firmware = philips_tda1004x_request_firmware
  411. };
  412. static struct tda1004x_config medion_cardbus = {
  413. .demod_address = 0x08,
  414. .invert = 1,
  415. .invert_oclk = 0,
  416. .xtal_freq = TDA10046_XTAL_16M,
  417. .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
  418. .if_freq = TDA10046_FREQ_3613,
  419. .tuner_address = 0x61,
  420. .request_firmware = philips_tda1004x_request_firmware
  421. };
  422. static struct tda1004x_config technotrend_budget_t3000_config = {
  423. .demod_address = 0x8,
  424. .invert = 1,
  425. .invert_oclk = 0,
  426. .xtal_freq = TDA10046_XTAL_4M,
  427. .agc_config = TDA10046_AGC_DEFAULT,
  428. .if_freq = TDA10046_FREQ_3617,
  429. .tuner_address = 0x63,
  430. .request_firmware = philips_tda1004x_request_firmware
  431. };
  432. /* ------------------------------------------------------------------
  433. * tda 1004x based cards with philips silicon tuner
  434. */
  435. static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
  436. {
  437. struct tda1004x_state *state = fe->demodulator_priv;
  438. u8 addr = state->config->i2c_gate;
  439. static u8 tda8290_close[] = { 0x21, 0xc0};
  440. static u8 tda8290_open[] = { 0x21, 0x80};
  441. struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
  442. if (enable) {
  443. tda8290_msg.buf = tda8290_close;
  444. } else {
  445. tda8290_msg.buf = tda8290_open;
  446. }
  447. if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
  448. pr_warn("could not access tda8290 I2C gate\n");
  449. return -EIO;
  450. }
  451. msleep(20);
  452. return 0;
  453. }
  454. static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
  455. {
  456. struct saa7134_dev *dev = fe->dvb->priv;
  457. struct tda1004x_state *state = fe->demodulator_priv;
  458. switch (state->config->antenna_switch) {
  459. case 0:
  460. break;
  461. case 1:
  462. pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
  463. saa7134_set_gpio(dev, 21, 0);
  464. break;
  465. case 2:
  466. pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
  467. saa7134_set_gpio(dev, 21, 1);
  468. break;
  469. }
  470. return 0;
  471. }
  472. static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
  473. {
  474. struct saa7134_dev *dev = fe->dvb->priv;
  475. struct tda1004x_state *state = fe->demodulator_priv;
  476. switch (state->config->antenna_switch) {
  477. case 0:
  478. break;
  479. case 1:
  480. pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
  481. saa7134_set_gpio(dev, 21, 1);
  482. break;
  483. case 2:
  484. pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
  485. saa7134_set_gpio(dev, 21, 0);
  486. break;
  487. }
  488. return 0;
  489. }
  490. static int configure_tda827x_fe(struct saa7134_dev *dev,
  491. struct tda1004x_config *cdec_conf,
  492. struct tda827x_config *tuner_conf)
  493. {
  494. struct vb2_dvb_frontend *fe0;
  495. /* Get the first frontend */
  496. fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
  497. if (!fe0)
  498. return -EINVAL;
  499. fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
  500. if (fe0->dvb.frontend) {
  501. if (cdec_conf->i2c_gate)
  502. fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  503. if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
  504. cdec_conf->tuner_address,
  505. &dev->i2c_adap, tuner_conf))
  506. return 0;
  507. pr_warn("no tda827x tuner found at addr: %02x\n",
  508. cdec_conf->tuner_address);
  509. }
  510. return -EINVAL;
  511. }
  512. /* ------------------------------------------------------------------ */
  513. static struct tda827x_config tda827x_cfg_0 = {
  514. .init = philips_tda827x_tuner_init,
  515. .sleep = philips_tda827x_tuner_sleep,
  516. .config = 0,
  517. .switch_addr = 0
  518. };
  519. static struct tda827x_config tda827x_cfg_1 = {
  520. .init = philips_tda827x_tuner_init,
  521. .sleep = philips_tda827x_tuner_sleep,
  522. .config = 1,
  523. .switch_addr = 0x4b
  524. };
  525. static struct tda827x_config tda827x_cfg_2 = {
  526. .init = philips_tda827x_tuner_init,
  527. .sleep = philips_tda827x_tuner_sleep,
  528. .config = 2,
  529. .switch_addr = 0x4b
  530. };
  531. static struct tda827x_config tda827x_cfg_2_sw42 = {
  532. .init = philips_tda827x_tuner_init,
  533. .sleep = philips_tda827x_tuner_sleep,
  534. .config = 2,
  535. .switch_addr = 0x42
  536. };
  537. /* ------------------------------------------------------------------ */
  538. static struct tda1004x_config tda827x_lifeview_config = {
  539. .demod_address = 0x08,
  540. .invert = 1,
  541. .invert_oclk = 0,
  542. .xtal_freq = TDA10046_XTAL_16M,
  543. .agc_config = TDA10046_AGC_TDA827X,
  544. .gpio_config = TDA10046_GP11_I,
  545. .if_freq = TDA10046_FREQ_045,
  546. .tuner_address = 0x60,
  547. .request_firmware = philips_tda1004x_request_firmware
  548. };
  549. static struct tda1004x_config philips_tiger_config = {
  550. .demod_address = 0x08,
  551. .invert = 1,
  552. .invert_oclk = 0,
  553. .xtal_freq = TDA10046_XTAL_16M,
  554. .agc_config = TDA10046_AGC_TDA827X,
  555. .gpio_config = TDA10046_GP11_I,
  556. .if_freq = TDA10046_FREQ_045,
  557. .i2c_gate = 0x4b,
  558. .tuner_address = 0x61,
  559. .antenna_switch= 1,
  560. .request_firmware = philips_tda1004x_request_firmware
  561. };
  562. static struct tda1004x_config cinergy_ht_config = {
  563. .demod_address = 0x08,
  564. .invert = 1,
  565. .invert_oclk = 0,
  566. .xtal_freq = TDA10046_XTAL_16M,
  567. .agc_config = TDA10046_AGC_TDA827X,
  568. .gpio_config = TDA10046_GP01_I,
  569. .if_freq = TDA10046_FREQ_045,
  570. .i2c_gate = 0x4b,
  571. .tuner_address = 0x61,
  572. .request_firmware = philips_tda1004x_request_firmware
  573. };
  574. static struct tda1004x_config cinergy_ht_pci_config = {
  575. .demod_address = 0x08,
  576. .invert = 1,
  577. .invert_oclk = 0,
  578. .xtal_freq = TDA10046_XTAL_16M,
  579. .agc_config = TDA10046_AGC_TDA827X,
  580. .gpio_config = TDA10046_GP01_I,
  581. .if_freq = TDA10046_FREQ_045,
  582. .i2c_gate = 0x4b,
  583. .tuner_address = 0x60,
  584. .request_firmware = philips_tda1004x_request_firmware
  585. };
  586. static struct tda1004x_config philips_tiger_s_config = {
  587. .demod_address = 0x08,
  588. .invert = 1,
  589. .invert_oclk = 0,
  590. .xtal_freq = TDA10046_XTAL_16M,
  591. .agc_config = TDA10046_AGC_TDA827X,
  592. .gpio_config = TDA10046_GP01_I,
  593. .if_freq = TDA10046_FREQ_045,
  594. .i2c_gate = 0x4b,
  595. .tuner_address = 0x61,
  596. .antenna_switch= 1,
  597. .request_firmware = philips_tda1004x_request_firmware
  598. };
  599. static struct tda1004x_config pinnacle_pctv_310i_config = {
  600. .demod_address = 0x08,
  601. .invert = 1,
  602. .invert_oclk = 0,
  603. .xtal_freq = TDA10046_XTAL_16M,
  604. .agc_config = TDA10046_AGC_TDA827X,
  605. .gpio_config = TDA10046_GP11_I,
  606. .if_freq = TDA10046_FREQ_045,
  607. .i2c_gate = 0x4b,
  608. .tuner_address = 0x61,
  609. .request_firmware = philips_tda1004x_request_firmware
  610. };
  611. static struct tda1004x_config hauppauge_hvr_1110_config = {
  612. .demod_address = 0x08,
  613. .invert = 1,
  614. .invert_oclk = 0,
  615. .xtal_freq = TDA10046_XTAL_16M,
  616. .agc_config = TDA10046_AGC_TDA827X,
  617. .gpio_config = TDA10046_GP11_I,
  618. .if_freq = TDA10046_FREQ_045,
  619. .i2c_gate = 0x4b,
  620. .tuner_address = 0x61,
  621. .request_firmware = philips_tda1004x_request_firmware
  622. };
  623. static struct tda1004x_config asus_p7131_dual_config = {
  624. .demod_address = 0x08,
  625. .invert = 1,
  626. .invert_oclk = 0,
  627. .xtal_freq = TDA10046_XTAL_16M,
  628. .agc_config = TDA10046_AGC_TDA827X,
  629. .gpio_config = TDA10046_GP11_I,
  630. .if_freq = TDA10046_FREQ_045,
  631. .i2c_gate = 0x4b,
  632. .tuner_address = 0x61,
  633. .antenna_switch= 2,
  634. .request_firmware = philips_tda1004x_request_firmware
  635. };
  636. static struct tda1004x_config lifeview_trio_config = {
  637. .demod_address = 0x09,
  638. .invert = 1,
  639. .invert_oclk = 0,
  640. .xtal_freq = TDA10046_XTAL_16M,
  641. .agc_config = TDA10046_AGC_TDA827X,
  642. .gpio_config = TDA10046_GP00_I,
  643. .if_freq = TDA10046_FREQ_045,
  644. .tuner_address = 0x60,
  645. .request_firmware = philips_tda1004x_request_firmware
  646. };
  647. static struct tda1004x_config tevion_dvbt220rf_config = {
  648. .demod_address = 0x08,
  649. .invert = 1,
  650. .invert_oclk = 0,
  651. .xtal_freq = TDA10046_XTAL_16M,
  652. .agc_config = TDA10046_AGC_TDA827X,
  653. .gpio_config = TDA10046_GP11_I,
  654. .if_freq = TDA10046_FREQ_045,
  655. .tuner_address = 0x60,
  656. .request_firmware = philips_tda1004x_request_firmware
  657. };
  658. static struct tda1004x_config md8800_dvbt_config = {
  659. .demod_address = 0x08,
  660. .invert = 1,
  661. .invert_oclk = 0,
  662. .xtal_freq = TDA10046_XTAL_16M,
  663. .agc_config = TDA10046_AGC_TDA827X,
  664. .gpio_config = TDA10046_GP01_I,
  665. .if_freq = TDA10046_FREQ_045,
  666. .i2c_gate = 0x4b,
  667. .tuner_address = 0x60,
  668. .request_firmware = philips_tda1004x_request_firmware
  669. };
  670. static struct tda1004x_config asus_p7131_4871_config = {
  671. .demod_address = 0x08,
  672. .invert = 1,
  673. .invert_oclk = 0,
  674. .xtal_freq = TDA10046_XTAL_16M,
  675. .agc_config = TDA10046_AGC_TDA827X,
  676. .gpio_config = TDA10046_GP01_I,
  677. .if_freq = TDA10046_FREQ_045,
  678. .i2c_gate = 0x4b,
  679. .tuner_address = 0x61,
  680. .antenna_switch= 2,
  681. .request_firmware = philips_tda1004x_request_firmware
  682. };
  683. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  684. .demod_address = 0x08,
  685. .invert = 1,
  686. .invert_oclk = 0,
  687. .xtal_freq = TDA10046_XTAL_16M,
  688. .agc_config = TDA10046_AGC_TDA827X,
  689. .gpio_config = TDA10046_GP11_I,
  690. .if_freq = TDA10046_FREQ_045,
  691. .i2c_gate = 0x4b,
  692. .tuner_address = 0x61,
  693. .antenna_switch= 2,
  694. .request_firmware = philips_tda1004x_request_firmware
  695. };
  696. static struct tda1004x_config kworld_dvb_t_210_config = {
  697. .demod_address = 0x08,
  698. .invert = 1,
  699. .invert_oclk = 0,
  700. .xtal_freq = TDA10046_XTAL_16M,
  701. .agc_config = TDA10046_AGC_TDA827X,
  702. .gpio_config = TDA10046_GP11_I,
  703. .if_freq = TDA10046_FREQ_045,
  704. .i2c_gate = 0x4b,
  705. .tuner_address = 0x61,
  706. .antenna_switch= 1,
  707. .request_firmware = philips_tda1004x_request_firmware
  708. };
  709. static struct tda1004x_config avermedia_super_007_config = {
  710. .demod_address = 0x08,
  711. .invert = 1,
  712. .invert_oclk = 0,
  713. .xtal_freq = TDA10046_XTAL_16M,
  714. .agc_config = TDA10046_AGC_TDA827X,
  715. .gpio_config = TDA10046_GP01_I,
  716. .if_freq = TDA10046_FREQ_045,
  717. .i2c_gate = 0x4b,
  718. .tuner_address = 0x60,
  719. .antenna_switch= 1,
  720. .request_firmware = philips_tda1004x_request_firmware
  721. };
  722. static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
  723. .demod_address = 0x08,
  724. .invert = 1,
  725. .invert_oclk = 0,
  726. .xtal_freq = TDA10046_XTAL_16M,
  727. .agc_config = TDA10046_AGC_TDA827X,
  728. .gpio_config = TDA10046_GP01_I,
  729. .if_freq = TDA10046_FREQ_045,
  730. .i2c_gate = 0x42,
  731. .tuner_address = 0x61,
  732. .antenna_switch = 1,
  733. .request_firmware = philips_tda1004x_request_firmware
  734. };
  735. static struct tda1004x_config asus_tiger_3in1_config = {
  736. .demod_address = 0x0b,
  737. .invert = 1,
  738. .invert_oclk = 0,
  739. .xtal_freq = TDA10046_XTAL_16M,
  740. .agc_config = TDA10046_AGC_TDA827X,
  741. .gpio_config = TDA10046_GP11_I,
  742. .if_freq = TDA10046_FREQ_045,
  743. .i2c_gate = 0x4b,
  744. .tuner_address = 0x61,
  745. .antenna_switch = 1,
  746. .request_firmware = philips_tda1004x_request_firmware
  747. };
  748. static struct tda1004x_config asus_ps3_100_config = {
  749. .demod_address = 0x0b,
  750. .invert = 1,
  751. .invert_oclk = 0,
  752. .xtal_freq = TDA10046_XTAL_16M,
  753. .agc_config = TDA10046_AGC_TDA827X,
  754. .gpio_config = TDA10046_GP11_I,
  755. .if_freq = TDA10046_FREQ_045,
  756. .i2c_gate = 0x4b,
  757. .tuner_address = 0x61,
  758. .antenna_switch = 1,
  759. .request_firmware = philips_tda1004x_request_firmware
  760. };
  761. /* ------------------------------------------------------------------
  762. * special case: this card uses saa713x GPIO22 for the mode switch
  763. */
  764. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  765. {
  766. struct saa7134_dev *dev = fe->dvb->priv;
  767. philips_tda827x_tuner_init(fe);
  768. /* route TDA8275a AGC input to the channel decoder */
  769. saa7134_set_gpio(dev, 22, 1);
  770. return 0;
  771. }
  772. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  773. {
  774. struct saa7134_dev *dev = fe->dvb->priv;
  775. /* route TDA8275a AGC input to the analog IF chip*/
  776. saa7134_set_gpio(dev, 22, 0);
  777. philips_tda827x_tuner_sleep(fe);
  778. return 0;
  779. }
  780. static struct tda827x_config ads_duo_cfg = {
  781. .init = ads_duo_tuner_init,
  782. .sleep = ads_duo_tuner_sleep,
  783. .config = 0
  784. };
  785. static struct tda1004x_config ads_tech_duo_config = {
  786. .demod_address = 0x08,
  787. .invert = 1,
  788. .invert_oclk = 0,
  789. .xtal_freq = TDA10046_XTAL_16M,
  790. .agc_config = TDA10046_AGC_TDA827X,
  791. .gpio_config = TDA10046_GP00_I,
  792. .if_freq = TDA10046_FREQ_045,
  793. .tuner_address = 0x61,
  794. .request_firmware = philips_tda1004x_request_firmware
  795. };
  796. static struct zl10353_config behold_h6_config = {
  797. .demod_address = 0x1e>>1,
  798. .no_tuner = 1,
  799. .parallel_ts = 1,
  800. .disable_i2c_gate_ctrl = 1,
  801. };
  802. static struct xc5000_config behold_x7_tunerconfig = {
  803. .i2c_address = 0xc2>>1,
  804. .if_khz = 4560,
  805. .radio_input = XC5000_RADIO_FM1,
  806. };
  807. static struct zl10353_config behold_x7_config = {
  808. .demod_address = 0x1e>>1,
  809. .if2 = 45600,
  810. .no_tuner = 1,
  811. .parallel_ts = 1,
  812. .disable_i2c_gate_ctrl = 1,
  813. };
  814. static struct zl10353_config videomate_t750_zl10353_config = {
  815. .demod_address = 0x0f,
  816. .no_tuner = 1,
  817. .parallel_ts = 1,
  818. .disable_i2c_gate_ctrl = 1,
  819. };
  820. static struct qt1010_config videomate_t750_qt1010_config = {
  821. .i2c_address = 0x62
  822. };
  823. /* ==================================================================
  824. * tda10086 based DVB-S cards, helper functions
  825. */
  826. static struct tda10086_config flydvbs = {
  827. .demod_address = 0x0e,
  828. .invert = 0,
  829. .diseqc_tone = 0,
  830. .xtal_freq = TDA10086_XTAL_16M,
  831. };
  832. static struct tda10086_config sd1878_4m = {
  833. .demod_address = 0x0e,
  834. .invert = 0,
  835. .diseqc_tone = 0,
  836. .xtal_freq = TDA10086_XTAL_4M,
  837. };
  838. /* ------------------------------------------------------------------
  839. * special case: lnb supply is connected to the gated i2c
  840. */
  841. static int md8800_set_voltage(struct dvb_frontend *fe,
  842. enum fe_sec_voltage voltage)
  843. {
  844. int res = -EIO;
  845. struct saa7134_dev *dev = fe->dvb->priv;
  846. if (fe->ops.i2c_gate_ctrl) {
  847. fe->ops.i2c_gate_ctrl(fe, 1);
  848. if (dev->original_set_voltage)
  849. res = dev->original_set_voltage(fe, voltage);
  850. fe->ops.i2c_gate_ctrl(fe, 0);
  851. }
  852. return res;
  853. };
  854. static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
  855. {
  856. int res = -EIO;
  857. struct saa7134_dev *dev = fe->dvb->priv;
  858. if (fe->ops.i2c_gate_ctrl) {
  859. fe->ops.i2c_gate_ctrl(fe, 1);
  860. if (dev->original_set_high_voltage)
  861. res = dev->original_set_high_voltage(fe, arg);
  862. fe->ops.i2c_gate_ctrl(fe, 0);
  863. }
  864. return res;
  865. };
  866. static int md8800_set_voltage2(struct dvb_frontend *fe,
  867. enum fe_sec_voltage voltage)
  868. {
  869. struct saa7134_dev *dev = fe->dvb->priv;
  870. u8 wbuf[2] = { 0x1f, 00 };
  871. u8 rbuf;
  872. struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
  873. { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
  874. if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
  875. return -EIO;
  876. /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
  877. if (voltage == SEC_VOLTAGE_18)
  878. wbuf[1] = rbuf | 0x10;
  879. else
  880. wbuf[1] = rbuf & 0xef;
  881. msg[0].len = 2;
  882. i2c_transfer(&dev->i2c_adap, msg, 1);
  883. return 0;
  884. }
  885. static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
  886. {
  887. pr_warn("%s: sorry can't set high LNB supply voltage from here\n",
  888. __func__);
  889. return -EIO;
  890. }
  891. /* ==================================================================
  892. * nxt200x based ATSC cards, helper functions
  893. */
  894. static const struct nxt200x_config avertvhda180 = {
  895. .demod_address = 0x0a,
  896. };
  897. static const struct nxt200x_config kworldatsc110 = {
  898. .demod_address = 0x0a,
  899. };
  900. /* ------------------------------------------------------------------ */
  901. static struct mt312_config avertv_a700_mt312 = {
  902. .demod_address = 0x0e,
  903. .voltage_inverted = 1,
  904. };
  905. static struct zl10036_config avertv_a700_tuner = {
  906. .tuner_address = 0x60,
  907. };
  908. static struct mt312_config zl10313_compro_s350_config = {
  909. .demod_address = 0x0e,
  910. };
  911. static struct mt312_config zl10313_avermedia_a706_config = {
  912. .demod_address = 0x0e,
  913. };
  914. static struct lgdt3305_config hcw_lgdt3305_config = {
  915. .i2c_addr = 0x0e,
  916. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  917. .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
  918. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  919. .deny_i2c_rptr = 1,
  920. .spectral_inversion = 1,
  921. .qam_if_khz = 4000,
  922. .vsb_if_khz = 3250,
  923. };
  924. static struct tda10048_config hcw_tda10048_config = {
  925. .demod_address = 0x10 >> 1,
  926. .output_mode = TDA10048_SERIAL_OUTPUT,
  927. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  928. .inversion = TDA10048_INVERSION_ON,
  929. .dtv6_if_freq_khz = TDA10048_IF_3300,
  930. .dtv7_if_freq_khz = TDA10048_IF_3500,
  931. .dtv8_if_freq_khz = TDA10048_IF_4000,
  932. .clk_freq_khz = TDA10048_CLK_16000,
  933. .disable_gate_access = 1,
  934. };
  935. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  936. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
  937. .if_lvl = 1, .rfagc_top = 0x58, },
  938. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  939. .if_lvl = 1, .rfagc_top = 0x58, },
  940. };
  941. static struct tda18271_config hcw_tda18271_config = {
  942. .std_map = &hauppauge_tda18271_std_map,
  943. .gate = TDA18271_GATE_ANALOG,
  944. .config = 3,
  945. .output_opt = TDA18271_OUTPUT_LT_OFF,
  946. };
  947. static struct tda829x_config tda829x_no_probe = {
  948. .probe_tuner = TDA829X_DONT_PROBE,
  949. };
  950. static struct tda10048_config zolid_tda10048_config = {
  951. .demod_address = 0x10 >> 1,
  952. .output_mode = TDA10048_PARALLEL_OUTPUT,
  953. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  954. .inversion = TDA10048_INVERSION_ON,
  955. .dtv6_if_freq_khz = TDA10048_IF_3300,
  956. .dtv7_if_freq_khz = TDA10048_IF_3500,
  957. .dtv8_if_freq_khz = TDA10048_IF_4000,
  958. .clk_freq_khz = TDA10048_CLK_16000,
  959. .disable_gate_access = 1,
  960. };
  961. static struct tda18271_config zolid_tda18271_config = {
  962. .gate = TDA18271_GATE_ANALOG,
  963. };
  964. static struct tda10048_config dtv1000s_tda10048_config = {
  965. .demod_address = 0x10 >> 1,
  966. .output_mode = TDA10048_PARALLEL_OUTPUT,
  967. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  968. .inversion = TDA10048_INVERSION_ON,
  969. .dtv6_if_freq_khz = TDA10048_IF_3300,
  970. .dtv7_if_freq_khz = TDA10048_IF_3800,
  971. .dtv8_if_freq_khz = TDA10048_IF_4300,
  972. .clk_freq_khz = TDA10048_CLK_16000,
  973. .disable_gate_access = 1,
  974. };
  975. static struct tda18271_std_map dtv1000s_tda18271_std_map = {
  976. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  977. .if_lvl = 1, .rfagc_top = 0x37, },
  978. .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
  979. .if_lvl = 1, .rfagc_top = 0x37, },
  980. .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
  981. .if_lvl = 1, .rfagc_top = 0x37, },
  982. };
  983. static struct tda18271_config dtv1000s_tda18271_config = {
  984. .std_map = &dtv1000s_tda18271_std_map,
  985. .gate = TDA18271_GATE_ANALOG,
  986. };
  987. static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = {
  988. .prod = LGS8GXX_PROD_LGS8G75,
  989. .demod_address = 0x1d,
  990. .serial_ts = 0,
  991. .ts_clk_pol = 1,
  992. .ts_clk_gated = 0,
  993. .if_clk_freq = 30400, /* 30.4 MHz */
  994. .if_freq = 4000, /* 4.00 MHz */
  995. .if_neg_center = 0,
  996. .ext_adc = 0,
  997. .adc_signed = 1,
  998. .adc_vpp = 3, /* 2.0 Vpp */
  999. .if_neg_edge = 1,
  1000. };
  1001. static struct tda18271_config prohdtv_pro2_tda18271_config = {
  1002. .gate = TDA18271_GATE_ANALOG,
  1003. .output_opt = TDA18271_OUTPUT_LT_OFF,
  1004. };
  1005. static struct tda18271_std_map kworld_tda18271_std_map = {
  1006. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3,
  1007. .if_lvl = 6, .rfagc_top = 0x37 },
  1008. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  1009. .if_lvl = 6, .rfagc_top = 0x37 },
  1010. };
  1011. static struct tda18271_config kworld_pc150u_tda18271_config = {
  1012. .std_map = &kworld_tda18271_std_map,
  1013. .gate = TDA18271_GATE_ANALOG,
  1014. .output_opt = TDA18271_OUTPUT_LT_OFF,
  1015. .config = 3, /* Use tuner callback for AGC */
  1016. .rf_cal_on_startup = 1
  1017. };
  1018. static struct s5h1411_config kworld_s5h1411_config = {
  1019. .output_mode = S5H1411_PARALLEL_OUTPUT,
  1020. .gpio = S5H1411_GPIO_OFF,
  1021. .qam_if = S5H1411_IF_4000,
  1022. .vsb_if = S5H1411_IF_3250,
  1023. .inversion = S5H1411_INVERSION_ON,
  1024. .status_mode = S5H1411_DEMODLOCKING,
  1025. .mpeg_timing =
  1026. S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
  1027. };
  1028. static struct tda18271_config hdtv200h_tda18271_config = {
  1029. .gate = TDA18271_GATE_ANALOG,
  1030. .config = 3 /* Use tuner callback for AGC */
  1031. };
  1032. static struct s5h1411_config hdtv200h_s5h1411_config = {
  1033. .output_mode = S5H1411_PARALLEL_OUTPUT,
  1034. .gpio = S5H1411_GPIO_OFF,
  1035. .qam_if = S5H1411_IF_4000,
  1036. .vsb_if = S5H1411_IF_3250,
  1037. .inversion = S5H1411_INVERSION_ON,
  1038. .status_mode = S5H1411_DEMODLOCKING,
  1039. .mpeg_timing =
  1040. S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
  1041. };
  1042. /* ==================================================================
  1043. * Core code
  1044. */
  1045. static int dvb_init(struct saa7134_dev *dev)
  1046. {
  1047. int ret;
  1048. int attach_xc3028 = 0;
  1049. struct vb2_dvb_frontend *fe0;
  1050. struct vb2_queue *q;
  1051. /* FIXME: add support for multi-frontend */
  1052. mutex_init(&dev->frontends.lock);
  1053. INIT_LIST_HEAD(&dev->frontends.felist);
  1054. pr_info("%s() allocating 1 frontend\n", __func__);
  1055. fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);
  1056. if (!fe0) {
  1057. pr_err("%s() failed to alloc\n", __func__);
  1058. return -ENOMEM;
  1059. }
  1060. /* init struct vb2_dvb */
  1061. dev->ts.nr_bufs = 32;
  1062. dev->ts.nr_packets = 32*4;
  1063. fe0->dvb.name = dev->name;
  1064. q = &fe0->dvb.dvbq;
  1065. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1066. q->io_modes = VB2_MMAP | VB2_READ;
  1067. q->drv_priv = &dev->ts_q;
  1068. q->ops = &saa7134_ts_qops;
  1069. q->mem_ops = &vb2_dma_sg_memops;
  1070. q->buf_struct_size = sizeof(struct saa7134_buf);
  1071. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  1072. q->lock = &dev->lock;
  1073. q->dev = &dev->pci->dev;
  1074. ret = vb2_queue_init(q);
  1075. if (ret) {
  1076. vb2_dvb_dealloc_frontends(&dev->frontends);
  1077. return ret;
  1078. }
  1079. switch (dev->board) {
  1080. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  1081. pr_debug("pinnacle 300i dvb setup\n");
  1082. fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  1083. &dev->i2c_adap);
  1084. if (fe0->dvb.frontend) {
  1085. fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  1086. }
  1087. break;
  1088. case SAA7134_BOARD_AVERMEDIA_777:
  1089. case SAA7134_BOARD_AVERMEDIA_A16AR:
  1090. pr_debug("avertv 777 dvb setup\n");
  1091. fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  1092. &dev->i2c_adap);
  1093. if (fe0->dvb.frontend) {
  1094. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1095. &dev->i2c_adap, 0x61,
  1096. TUNER_PHILIPS_TD1316);
  1097. }
  1098. break;
  1099. case SAA7134_BOARD_AVERMEDIA_A16D:
  1100. pr_debug("AverMedia A16D dvb setup\n");
  1101. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1102. &avermedia_xc3028_mt352_dev,
  1103. &dev->i2c_adap);
  1104. attach_xc3028 = 1;
  1105. break;
  1106. case SAA7134_BOARD_MD7134:
  1107. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1108. &medion_cardbus,
  1109. &dev->i2c_adap);
  1110. if (fe0->dvb.frontend) {
  1111. /*
  1112. * The TV tuner on this board is actually NOT
  1113. * behind the demod i2c gate.
  1114. * However, the demod EEPROM is indeed there and it
  1115. * conflicts with the SAA7134 chip config EEPROM
  1116. * if the i2c gate is open (since they have same
  1117. * bus addresses) resulting in card PCI SVID / SSID
  1118. * being garbage after a reboot from time to time.
  1119. *
  1120. * Let's just leave the gate permanently closed -
  1121. * saa7134_i2c_eeprom_md7134_gate() will close it for
  1122. * us at probe time if it was open for some reason.
  1123. */
  1124. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1125. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1126. &dev->i2c_adap, medion_cardbus.tuner_address,
  1127. TUNER_PHILIPS_FMD1216ME_MK3);
  1128. }
  1129. break;
  1130. case SAA7134_BOARD_PHILIPS_TOUGH:
  1131. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1132. &philips_tu1216_60_config,
  1133. &dev->i2c_adap);
  1134. if (fe0->dvb.frontend) {
  1135. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  1136. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  1137. }
  1138. break;
  1139. case SAA7134_BOARD_FLYDVBTDUO:
  1140. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  1141. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  1142. &tda827x_cfg_0) < 0)
  1143. goto detach_frontend;
  1144. break;
  1145. case SAA7134_BOARD_PHILIPS_EUROPA:
  1146. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  1147. case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
  1148. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1149. &philips_europa_config,
  1150. &dev->i2c_adap);
  1151. if (fe0->dvb.frontend) {
  1152. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1153. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1154. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  1155. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  1156. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1157. }
  1158. break;
  1159. case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
  1160. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1161. &technotrend_budget_t3000_config,
  1162. &dev->i2c_adap);
  1163. if (fe0->dvb.frontend) {
  1164. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1165. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1166. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  1167. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  1168. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1169. }
  1170. break;
  1171. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  1172. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1173. &philips_tu1216_61_config,
  1174. &dev->i2c_adap);
  1175. if (fe0->dvb.frontend) {
  1176. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  1177. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  1178. }
  1179. break;
  1180. case SAA7134_BOARD_KWORLD_DVBT_210:
  1181. if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
  1182. &tda827x_cfg_2) < 0)
  1183. goto detach_frontend;
  1184. break;
  1185. case SAA7134_BOARD_HAUPPAUGE_HVR1120:
  1186. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1187. &hcw_tda10048_config,
  1188. &dev->i2c_adap);
  1189. if (fe0->dvb.frontend != NULL) {
  1190. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1191. &dev->i2c_adap, 0x4b,
  1192. &tda829x_no_probe);
  1193. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1194. 0x60, &dev->i2c_adap,
  1195. &hcw_tda18271_config);
  1196. }
  1197. break;
  1198. case SAA7134_BOARD_PHILIPS_TIGER:
  1199. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1200. &tda827x_cfg_0) < 0)
  1201. goto detach_frontend;
  1202. break;
  1203. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  1204. if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
  1205. &tda827x_cfg_1) < 0)
  1206. goto detach_frontend;
  1207. break;
  1208. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  1209. if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
  1210. &tda827x_cfg_1) < 0)
  1211. goto detach_frontend;
  1212. break;
  1213. case SAA7134_BOARD_HAUPPAUGE_HVR1150:
  1214. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  1215. &hcw_lgdt3305_config,
  1216. &dev->i2c_adap);
  1217. if (fe0->dvb.frontend) {
  1218. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1219. &dev->i2c_adap, 0x4b,
  1220. &tda829x_no_probe);
  1221. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1222. 0x60, &dev->i2c_adap,
  1223. &hcw_tda18271_config);
  1224. }
  1225. break;
  1226. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  1227. if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
  1228. &tda827x_cfg_0) < 0)
  1229. goto detach_frontend;
  1230. break;
  1231. case SAA7134_BOARD_FLYDVBT_LR301:
  1232. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  1233. &tda827x_cfg_0) < 0)
  1234. goto detach_frontend;
  1235. break;
  1236. case SAA7134_BOARD_FLYDVB_TRIO:
  1237. if (!use_frontend) { /* terrestrial */
  1238. if (configure_tda827x_fe(dev, &lifeview_trio_config,
  1239. &tda827x_cfg_0) < 0)
  1240. goto detach_frontend;
  1241. } else { /* satellite */
  1242. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  1243. if (fe0->dvb.frontend) {
  1244. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
  1245. &dev->i2c_adap, 0) == NULL) {
  1246. pr_warn("%s: Lifeview Trio, No tda826x found!\n",
  1247. __func__);
  1248. goto detach_frontend;
  1249. }
  1250. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1251. &dev->i2c_adap,
  1252. 0x08, 0, 0, false) == NULL) {
  1253. pr_warn("%s: Lifeview Trio, No ISL6421 found!\n",
  1254. __func__);
  1255. goto detach_frontend;
  1256. }
  1257. }
  1258. }
  1259. break;
  1260. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  1261. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  1262. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1263. &ads_tech_duo_config,
  1264. &dev->i2c_adap);
  1265. if (fe0->dvb.frontend) {
  1266. if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
  1267. ads_tech_duo_config.tuner_address, &dev->i2c_adap,
  1268. &ads_duo_cfg) == NULL) {
  1269. pr_warn("no tda827x tuner found at addr: %02x\n",
  1270. ads_tech_duo_config.tuner_address);
  1271. goto detach_frontend;
  1272. }
  1273. } else
  1274. pr_warn("failed to attach tda10046\n");
  1275. break;
  1276. case SAA7134_BOARD_TEVION_DVBT_220RF:
  1277. if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
  1278. &tda827x_cfg_0) < 0)
  1279. goto detach_frontend;
  1280. break;
  1281. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  1282. if (!use_frontend) { /* terrestrial */
  1283. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1284. &tda827x_cfg_0) < 0)
  1285. goto detach_frontend;
  1286. } else { /* satellite */
  1287. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1288. &flydvbs, &dev->i2c_adap);
  1289. if (fe0->dvb.frontend) {
  1290. struct dvb_frontend *fe = fe0->dvb.frontend;
  1291. u8 dev_id = dev->eedata[2];
  1292. u8 data = 0xc4;
  1293. struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
  1294. if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
  1295. 0x60, &dev->i2c_adap, 0) == NULL) {
  1296. pr_warn("%s: Medion Quadro, no tda826x found !\n",
  1297. __func__);
  1298. goto detach_frontend;
  1299. }
  1300. if (dev_id != 0x08) {
  1301. /* we need to open the i2c gate (we know it exists) */
  1302. fe->ops.i2c_gate_ctrl(fe, 1);
  1303. if (dvb_attach(isl6405_attach, fe,
  1304. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1305. pr_warn("%s: Medion Quadro, no ISL6405 found !\n",
  1306. __func__);
  1307. goto detach_frontend;
  1308. }
  1309. if (dev_id == 0x07) {
  1310. /* fire up the 2nd section of the LNB supply since
  1311. we can't do this from the other section */
  1312. msg.buf = &data;
  1313. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1314. }
  1315. fe->ops.i2c_gate_ctrl(fe, 0);
  1316. dev->original_set_voltage = fe->ops.set_voltage;
  1317. fe->ops.set_voltage = md8800_set_voltage;
  1318. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1319. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1320. } else {
  1321. fe->ops.set_voltage = md8800_set_voltage2;
  1322. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
  1323. }
  1324. }
  1325. }
  1326. break;
  1327. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  1328. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  1329. &dev->i2c_adap);
  1330. if (fe0->dvb.frontend)
  1331. dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
  1332. NULL, DVB_PLL_TDHU2);
  1333. break;
  1334. case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
  1335. case SAA7134_BOARD_KWORLD_ATSC110:
  1336. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  1337. &dev->i2c_adap);
  1338. if (fe0->dvb.frontend)
  1339. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1340. &dev->i2c_adap, 0x61,
  1341. TUNER_PHILIPS_TUV1236D);
  1342. break;
  1343. case SAA7134_BOARD_KWORLD_PC150U:
  1344. saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */
  1345. saa7134_tuner_callback(dev, 0,
  1346. TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
  1347. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1348. &kworld_s5h1411_config,
  1349. &dev->i2c_adap);
  1350. if (fe0->dvb.frontend != NULL) {
  1351. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1352. &dev->i2c_adap, 0x4b,
  1353. &tda829x_no_probe);
  1354. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1355. 0x60, &dev->i2c_adap,
  1356. &kworld_pc150u_tda18271_config);
  1357. }
  1358. break;
  1359. case SAA7134_BOARD_FLYDVBS_LR300:
  1360. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1361. &dev->i2c_adap);
  1362. if (fe0->dvb.frontend) {
  1363. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1364. &dev->i2c_adap, 0) == NULL) {
  1365. pr_warn("%s: No tda826x found!\n", __func__);
  1366. goto detach_frontend;
  1367. }
  1368. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1369. &dev->i2c_adap,
  1370. 0x08, 0, 0, false) == NULL) {
  1371. pr_warn("%s: No ISL6421 found!\n", __func__);
  1372. goto detach_frontend;
  1373. }
  1374. }
  1375. break;
  1376. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1377. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1378. &medion_cardbus,
  1379. &dev->i2c_adap);
  1380. if (fe0->dvb.frontend) {
  1381. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1382. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1383. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1384. &dev->i2c_adap, medion_cardbus.tuner_address,
  1385. TUNER_PHILIPS_FMD1216ME_MK3);
  1386. }
  1387. break;
  1388. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1389. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1390. &philips_europa_config,
  1391. &dev->i2c_adap);
  1392. if (fe0->dvb.frontend) {
  1393. fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1394. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1395. }
  1396. break;
  1397. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1398. if (configure_tda827x_fe(dev, &cinergy_ht_config,
  1399. &tda827x_cfg_0) < 0)
  1400. goto detach_frontend;
  1401. break;
  1402. case SAA7134_BOARD_CINERGY_HT_PCI:
  1403. if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
  1404. &tda827x_cfg_0) < 0)
  1405. goto detach_frontend;
  1406. break;
  1407. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1408. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1409. &tda827x_cfg_2) < 0)
  1410. goto detach_frontend;
  1411. break;
  1412. case SAA7134_BOARD_ASUS_P7131_4871:
  1413. if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
  1414. &tda827x_cfg_2) < 0)
  1415. goto detach_frontend;
  1416. break;
  1417. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1418. if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
  1419. &tda827x_cfg_2) < 0)
  1420. goto detach_frontend;
  1421. break;
  1422. case SAA7134_BOARD_AVERMEDIA_SUPER_007:
  1423. if (configure_tda827x_fe(dev, &avermedia_super_007_config,
  1424. &tda827x_cfg_0) < 0)
  1425. goto detach_frontend;
  1426. break;
  1427. case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
  1428. if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
  1429. &tda827x_cfg_2_sw42) < 0)
  1430. goto detach_frontend;
  1431. break;
  1432. case SAA7134_BOARD_PHILIPS_SNAKE:
  1433. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1434. &dev->i2c_adap);
  1435. if (fe0->dvb.frontend) {
  1436. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1437. &dev->i2c_adap, 0) == NULL) {
  1438. pr_warn("%s: No tda826x found!\n", __func__);
  1439. goto detach_frontend;
  1440. }
  1441. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1442. &dev->i2c_adap, 0, 0) == NULL) {
  1443. pr_warn("%s: No lnbp21 found!\n", __func__);
  1444. goto detach_frontend;
  1445. }
  1446. }
  1447. break;
  1448. case SAA7134_BOARD_CREATIX_CTX953:
  1449. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1450. &tda827x_cfg_0) < 0)
  1451. goto detach_frontend;
  1452. break;
  1453. case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
  1454. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1455. &tda827x_cfg_2) < 0)
  1456. goto detach_frontend;
  1457. break;
  1458. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  1459. pr_debug("AverMedia E506R dvb setup\n");
  1460. saa7134_set_gpio(dev, 25, 0);
  1461. msleep(10);
  1462. saa7134_set_gpio(dev, 25, 1);
  1463. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1464. &avermedia_xc3028_mt352_dev,
  1465. &dev->i2c_adap);
  1466. attach_xc3028 = 1;
  1467. break;
  1468. case SAA7134_BOARD_MD7134_BRIDGE_2:
  1469. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1470. &sd1878_4m, &dev->i2c_adap);
  1471. if (fe0->dvb.frontend) {
  1472. struct dvb_frontend *fe;
  1473. if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1474. &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
  1475. pr_warn("%s: MD7134 DVB-S, no SD1878 found !\n",
  1476. __func__);
  1477. goto detach_frontend;
  1478. }
  1479. /* we need to open the i2c gate (we know it exists) */
  1480. fe = fe0->dvb.frontend;
  1481. fe->ops.i2c_gate_ctrl(fe, 1);
  1482. if (dvb_attach(isl6405_attach, fe,
  1483. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1484. pr_warn("%s: MD7134 DVB-S, no ISL6405 found !\n",
  1485. __func__);
  1486. goto detach_frontend;
  1487. }
  1488. fe->ops.i2c_gate_ctrl(fe, 0);
  1489. dev->original_set_voltage = fe->ops.set_voltage;
  1490. fe->ops.set_voltage = md8800_set_voltage;
  1491. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1492. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1493. }
  1494. break;
  1495. case SAA7134_BOARD_AVERMEDIA_M103:
  1496. saa7134_set_gpio(dev, 25, 0);
  1497. msleep(10);
  1498. saa7134_set_gpio(dev, 25, 1);
  1499. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1500. &avermedia_xc3028_mt352_dev,
  1501. &dev->i2c_adap);
  1502. attach_xc3028 = 1;
  1503. break;
  1504. case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
  1505. if (!use_frontend) { /* terrestrial */
  1506. if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
  1507. &tda827x_cfg_2) < 0)
  1508. goto detach_frontend;
  1509. } else { /* satellite */
  1510. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1511. &flydvbs, &dev->i2c_adap);
  1512. if (fe0->dvb.frontend) {
  1513. if (dvb_attach(tda826x_attach,
  1514. fe0->dvb.frontend, 0x60,
  1515. &dev->i2c_adap, 0) == NULL) {
  1516. pr_warn("%s: Asus Tiger 3in1, no tda826x found!\n",
  1517. __func__);
  1518. goto detach_frontend;
  1519. }
  1520. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1521. &dev->i2c_adap, 0, 0) == NULL) {
  1522. pr_warn("%s: Asus Tiger 3in1, no lnbp21 found!\n",
  1523. __func__);
  1524. goto detach_frontend;
  1525. }
  1526. }
  1527. }
  1528. break;
  1529. case SAA7134_BOARD_ASUSTeK_PS3_100:
  1530. if (!use_frontend) { /* terrestrial */
  1531. if (configure_tda827x_fe(dev, &asus_ps3_100_config,
  1532. &tda827x_cfg_2) < 0)
  1533. goto detach_frontend;
  1534. } else { /* satellite */
  1535. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1536. &flydvbs, &dev->i2c_adap);
  1537. if (fe0->dvb.frontend) {
  1538. if (dvb_attach(tda826x_attach,
  1539. fe0->dvb.frontend, 0x60,
  1540. &dev->i2c_adap, 0) == NULL) {
  1541. pr_warn("%s: Asus My Cinema PS3-100, no tda826x found!\n",
  1542. __func__);
  1543. goto detach_frontend;
  1544. }
  1545. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1546. &dev->i2c_adap, 0, 0) == NULL) {
  1547. pr_warn("%s: Asus My Cinema PS3-100, no lnbp21 found!\n",
  1548. __func__);
  1549. goto detach_frontend;
  1550. }
  1551. }
  1552. }
  1553. break;
  1554. case SAA7134_BOARD_ASUSTeK_TIGER:
  1555. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1556. &tda827x_cfg_0) < 0)
  1557. goto detach_frontend;
  1558. break;
  1559. case SAA7134_BOARD_BEHOLD_H6:
  1560. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1561. &behold_h6_config,
  1562. &dev->i2c_adap);
  1563. if (fe0->dvb.frontend) {
  1564. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1565. &dev->i2c_adap, 0x61,
  1566. TUNER_PHILIPS_FMD1216MEX_MK3);
  1567. }
  1568. break;
  1569. case SAA7134_BOARD_BEHOLD_X7:
  1570. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1571. &behold_x7_config,
  1572. &dev->i2c_adap);
  1573. if (fe0->dvb.frontend) {
  1574. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1575. &dev->i2c_adap, &behold_x7_tunerconfig);
  1576. }
  1577. break;
  1578. case SAA7134_BOARD_BEHOLD_H7:
  1579. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1580. &behold_x7_config,
  1581. &dev->i2c_adap);
  1582. if (fe0->dvb.frontend) {
  1583. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1584. &dev->i2c_adap, &behold_x7_tunerconfig);
  1585. }
  1586. break;
  1587. case SAA7134_BOARD_AVERMEDIA_A700_PRO:
  1588. case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
  1589. /* Zarlink ZL10313 */
  1590. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1591. &avertv_a700_mt312, &dev->i2c_adap);
  1592. if (fe0->dvb.frontend) {
  1593. if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
  1594. &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
  1595. pr_warn("%s: No zl10036 found!\n",
  1596. __func__);
  1597. }
  1598. }
  1599. break;
  1600. case SAA7134_BOARD_VIDEOMATE_S350:
  1601. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1602. &zl10313_compro_s350_config, &dev->i2c_adap);
  1603. if (fe0->dvb.frontend)
  1604. if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
  1605. 0x60, &dev->i2c_adap) == NULL)
  1606. pr_warn("%s: No zl10039 found!\n",
  1607. __func__);
  1608. break;
  1609. case SAA7134_BOARD_VIDEOMATE_T750:
  1610. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1611. &videomate_t750_zl10353_config,
  1612. &dev->i2c_adap);
  1613. if (fe0->dvb.frontend != NULL) {
  1614. if (dvb_attach(qt1010_attach,
  1615. fe0->dvb.frontend,
  1616. &dev->i2c_adap,
  1617. &videomate_t750_qt1010_config) == NULL)
  1618. pr_warn("error attaching QT1010\n");
  1619. }
  1620. break;
  1621. case SAA7134_BOARD_ZOLID_HYBRID_PCI:
  1622. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1623. &zolid_tda10048_config,
  1624. &dev->i2c_adap);
  1625. if (fe0->dvb.frontend != NULL) {
  1626. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1627. &dev->i2c_adap, 0x4b,
  1628. &tda829x_no_probe);
  1629. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1630. 0x60, &dev->i2c_adap,
  1631. &zolid_tda18271_config);
  1632. }
  1633. break;
  1634. case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
  1635. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1636. &dtv1000s_tda10048_config,
  1637. &dev->i2c_adap);
  1638. if (fe0->dvb.frontend != NULL) {
  1639. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1640. &dev->i2c_adap, 0x4b,
  1641. &tda829x_no_probe);
  1642. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1643. 0x60, &dev->i2c_adap,
  1644. &dtv1000s_tda18271_config);
  1645. }
  1646. break;
  1647. case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
  1648. /* Switch to digital mode */
  1649. saa7134_tuner_callback(dev, 0,
  1650. TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
  1651. fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
  1652. &kworld_mb86a20s_config,
  1653. &dev->i2c_adap);
  1654. if (fe0->dvb.frontend != NULL) {
  1655. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1656. &dev->i2c_adap, 0x4b,
  1657. &tda829x_no_probe);
  1658. fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl;
  1659. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1660. 0x60, &dev->i2c_adap,
  1661. &kworld_tda18271_config);
  1662. }
  1663. /* mb86a20s need to use the I2C gateway */
  1664. break;
  1665. case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2:
  1666. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1667. &prohdtv_pro2_lgs8g75_config,
  1668. &dev->i2c_adap);
  1669. if (fe0->dvb.frontend != NULL) {
  1670. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1671. &dev->i2c_adap, 0x4b,
  1672. &tda829x_no_probe);
  1673. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1674. 0x60, &dev->i2c_adap,
  1675. &prohdtv_pro2_tda18271_config);
  1676. }
  1677. break;
  1678. case SAA7134_BOARD_AVERMEDIA_A706:
  1679. /* Enable all DVB-S devices now */
  1680. /* CE5039 DVB-S tuner SLEEP pin low */
  1681. saa7134_set_gpio(dev, 23, 0);
  1682. /* CE6313 DVB-S demod SLEEP pin low */
  1683. saa7134_set_gpio(dev, 9, 0);
  1684. /* CE6313 DVB-S demod RESET# pin high */
  1685. saa7134_set_gpio(dev, 25, 1);
  1686. msleep(1);
  1687. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1688. &zl10313_avermedia_a706_config, &dev->i2c_adap);
  1689. if (fe0->dvb.frontend) {
  1690. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1691. if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
  1692. 0x60, &dev->i2c_adap) == NULL)
  1693. pr_warn("%s: No zl10039 found!\n",
  1694. __func__);
  1695. }
  1696. break;
  1697. case SAA7134_BOARD_LEADTEK_WINFAST_HDTV200_H:
  1698. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1699. &hdtv200h_s5h1411_config,
  1700. &dev->i2c_adap);
  1701. if (fe0->dvb.frontend) {
  1702. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1703. &dev->i2c_adap, 0x4b,
  1704. &tda829x_no_probe);
  1705. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1706. 0x60, &dev->i2c_adap,
  1707. &hdtv200h_tda18271_config);
  1708. }
  1709. break;
  1710. default:
  1711. pr_warn("Huh? unknown DVB card?\n");
  1712. break;
  1713. }
  1714. if (attach_xc3028) {
  1715. struct dvb_frontend *fe;
  1716. struct xc2028_config cfg = {
  1717. .i2c_adap = &dev->i2c_adap,
  1718. .i2c_addr = 0x61,
  1719. };
  1720. if (!fe0->dvb.frontend)
  1721. goto detach_frontend;
  1722. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  1723. if (!fe) {
  1724. pr_err("%s/2: xc3028 attach failed\n",
  1725. dev->name);
  1726. goto detach_frontend;
  1727. }
  1728. }
  1729. if (NULL == fe0->dvb.frontend) {
  1730. pr_err("%s/dvb: frontend initialization failed\n", dev->name);
  1731. goto detach_frontend;
  1732. }
  1733. /* define general-purpose callback pointer */
  1734. fe0->dvb.frontend->callback = saa7134_tuner_callback;
  1735. /* register everything else */
  1736. #ifndef CONFIG_MEDIA_CONTROLLER_DVB
  1737. ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1738. &dev->pci->dev, NULL,
  1739. adapter_nr, 0);
  1740. #else
  1741. ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1742. &dev->pci->dev, dev->media_dev,
  1743. adapter_nr, 0);
  1744. #endif
  1745. /* this sequence is necessary to make the tda1004x load its firmware
  1746. * and to enter analog mode of hybrid boards
  1747. */
  1748. if (!ret) {
  1749. if (fe0->dvb.frontend->ops.init)
  1750. fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
  1751. if (fe0->dvb.frontend->ops.sleep)
  1752. fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
  1753. if (fe0->dvb.frontend->ops.tuner_ops.sleep)
  1754. fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
  1755. }
  1756. return ret;
  1757. detach_frontend:
  1758. vb2_dvb_dealloc_frontends(&dev->frontends);
  1759. vb2_queue_release(&fe0->dvb.dvbq);
  1760. return -EINVAL;
  1761. }
  1762. static int dvb_fini(struct saa7134_dev *dev)
  1763. {
  1764. struct vb2_dvb_frontend *fe0;
  1765. /* Get the first frontend */
  1766. fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
  1767. if (!fe0)
  1768. return -EINVAL;
  1769. /* FIXME: I suspect that this code is bogus, since the entry for
  1770. Pinnacle 300I DVB-T PAL already defines the proper init to allow
  1771. the detection of mt2032 (TDA9887_PORT2_INACTIVE)
  1772. */
  1773. if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
  1774. struct v4l2_priv_tun_config tda9887_cfg;
  1775. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1776. tda9887_cfg.tuner = TUNER_TDA9887;
  1777. tda9887_cfg.priv = &on;
  1778. /* otherwise we don't detect the tuner on next insmod */
  1779. saa_call_all(dev, tuner, s_config, &tda9887_cfg);
  1780. } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
  1781. if ((dev->eedata[2] == 0x07) && use_frontend) {
  1782. /* turn off the 2nd lnb supply */
  1783. u8 data = 0x80;
  1784. struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
  1785. struct dvb_frontend *fe;
  1786. fe = fe0->dvb.frontend;
  1787. if (fe->ops.i2c_gate_ctrl) {
  1788. fe->ops.i2c_gate_ctrl(fe, 1);
  1789. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1790. fe->ops.i2c_gate_ctrl(fe, 0);
  1791. }
  1792. }
  1793. }
  1794. vb2_dvb_unregister_bus(&dev->frontends);
  1795. vb2_queue_release(&fe0->dvb.dvbq);
  1796. return 0;
  1797. }
  1798. static struct saa7134_mpeg_ops dvb_ops = {
  1799. .type = SAA7134_MPEG_DVB,
  1800. .init = dvb_init,
  1801. .fini = dvb_fini,
  1802. };
  1803. static int __init dvb_register(void)
  1804. {
  1805. return saa7134_ts_register(&dvb_ops);
  1806. }
  1807. static void __exit dvb_unregister(void)
  1808. {
  1809. saa7134_ts_unregister(&dvb_ops);
  1810. }
  1811. module_init(dvb_register);
  1812. module_exit(dvb_unregister);