saa7134-dvb.c 57 KB

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