saa7134-dvb.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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 <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/slab.h>
  27. #include <linux/delay.h>
  28. #include <linux/kthread.h>
  29. #include <linux/suspend.h>
  30. #include "saa7134-reg.h"
  31. #include "saa7134.h"
  32. #include <media/v4l2-common.h>
  33. #include "dvb-pll.h"
  34. #include <dvb_frontend.h>
  35. #include "mt352.h"
  36. #include "mt352_priv.h" /* FIXME */
  37. #include "tda1004x.h"
  38. #include "nxt200x.h"
  39. #include "tuner-xc2028.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 "zl10353.h"
  48. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  49. MODULE_LICENSE("GPL");
  50. static unsigned int antenna_pwr;
  51. module_param(antenna_pwr, int, 0444);
  52. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  53. static int use_frontend;
  54. module_param(use_frontend, int, 0644);
  55. MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
  56. static int debug;
  57. module_param(debug, int, 0644);
  58. MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
  59. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  60. #define dprintk(fmt, arg...) do { if (debug) \
  61. printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
  62. /* Print a warning */
  63. #define wprintk(fmt, arg...) \
  64. printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
  65. /* ------------------------------------------------------------------
  66. * mt352 based DVB-T cards
  67. */
  68. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  69. {
  70. u32 ok;
  71. if (!on) {
  72. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  73. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  74. return 0;
  75. }
  76. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  77. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  78. udelay(10);
  79. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  80. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  81. udelay(10);
  82. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  83. udelay(10);
  84. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  85. dprintk("%s %s\n", __func__, ok ? "on" : "off");
  86. if (!ok)
  87. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  88. return ok;
  89. }
  90. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  91. {
  92. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  93. static u8 reset [] = { RESET, 0x80 };
  94. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  95. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  96. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  97. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  98. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  99. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  100. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  101. struct saa7134_dev *dev= fe->dvb->priv;
  102. dprintk("%s called\n", __func__);
  103. mt352_write(fe, clock_config, sizeof(clock_config));
  104. udelay(200);
  105. mt352_write(fe, reset, sizeof(reset));
  106. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  107. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  108. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  109. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  110. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  111. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  112. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  113. return 0;
  114. }
  115. static int mt352_aver777_init(struct dvb_frontend* fe)
  116. {
  117. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  118. static u8 reset [] = { RESET, 0x80 };
  119. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  120. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  121. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  122. mt352_write(fe, clock_config, sizeof(clock_config));
  123. udelay(200);
  124. mt352_write(fe, reset, sizeof(reset));
  125. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  126. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  127. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  128. return 0;
  129. }
  130. static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
  131. {
  132. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  133. static u8 reset [] = { RESET, 0x80 };
  134. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  135. static u8 agc_cfg [] = { AGC_TARGET, 0xe };
  136. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  137. mt352_write(fe, clock_config, sizeof(clock_config));
  138. udelay(200);
  139. mt352_write(fe, reset, sizeof(reset));
  140. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  141. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  142. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  143. return 0;
  144. }
  145. static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
  146. struct dvb_frontend_parameters* params)
  147. {
  148. u8 off[] = { 0x00, 0xf1};
  149. u8 on[] = { 0x00, 0x71};
  150. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  151. struct saa7134_dev *dev = fe->dvb->priv;
  152. struct v4l2_frequency f;
  153. /* set frequency (mt2050) */
  154. f.tuner = 0;
  155. f.type = V4L2_TUNER_DIGITAL_TV;
  156. f.frequency = params->frequency / 1000 * 16 / 1000;
  157. if (fe->ops.i2c_gate_ctrl)
  158. fe->ops.i2c_gate_ctrl(fe, 1);
  159. i2c_transfer(&dev->i2c_adap, &msg, 1);
  160. saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
  161. msg.buf = on;
  162. if (fe->ops.i2c_gate_ctrl)
  163. fe->ops.i2c_gate_ctrl(fe, 1);
  164. i2c_transfer(&dev->i2c_adap, &msg, 1);
  165. pinnacle_antenna_pwr(dev, antenna_pwr);
  166. /* mt352 setup */
  167. return mt352_pinnacle_init(fe);
  168. }
  169. static struct mt352_config pinnacle_300i = {
  170. .demod_address = 0x3c >> 1,
  171. .adc_clock = 20333,
  172. .if2 = 36150,
  173. .no_tuner = 1,
  174. .demod_init = mt352_pinnacle_init,
  175. };
  176. static struct mt352_config avermedia_777 = {
  177. .demod_address = 0xf,
  178. .demod_init = mt352_aver777_init,
  179. };
  180. static struct mt352_config avermedia_xc3028_mt352_dev = {
  181. .demod_address = (0x1e >> 1),
  182. .no_tuner = 1,
  183. .demod_init = mt352_avermedia_xc3028_init,
  184. };
  185. /* ==================================================================
  186. * tda1004x based DVB-T cards, helper functions
  187. */
  188. static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
  189. const struct firmware **fw, char *name)
  190. {
  191. struct saa7134_dev *dev = fe->dvb->priv;
  192. return request_firmware(fw, name, &dev->pci->dev);
  193. }
  194. /* ------------------------------------------------------------------
  195. * these tuners are tu1216, td1316(a)
  196. */
  197. static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  198. {
  199. struct saa7134_dev *dev = fe->dvb->priv;
  200. struct tda1004x_state *state = fe->demodulator_priv;
  201. u8 addr = state->config->tuner_address;
  202. u8 tuner_buf[4];
  203. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  204. sizeof(tuner_buf) };
  205. int tuner_frequency = 0;
  206. u8 band, cp, filter;
  207. /* determine charge pump */
  208. tuner_frequency = params->frequency + 36166000;
  209. if (tuner_frequency < 87000000)
  210. return -EINVAL;
  211. else if (tuner_frequency < 130000000)
  212. cp = 3;
  213. else if (tuner_frequency < 160000000)
  214. cp = 5;
  215. else if (tuner_frequency < 200000000)
  216. cp = 6;
  217. else if (tuner_frequency < 290000000)
  218. cp = 3;
  219. else if (tuner_frequency < 420000000)
  220. cp = 5;
  221. else if (tuner_frequency < 480000000)
  222. cp = 6;
  223. else if (tuner_frequency < 620000000)
  224. cp = 3;
  225. else if (tuner_frequency < 830000000)
  226. cp = 5;
  227. else if (tuner_frequency < 895000000)
  228. cp = 7;
  229. else
  230. return -EINVAL;
  231. /* determine band */
  232. if (params->frequency < 49000000)
  233. return -EINVAL;
  234. else if (params->frequency < 161000000)
  235. band = 1;
  236. else if (params->frequency < 444000000)
  237. band = 2;
  238. else if (params->frequency < 861000000)
  239. band = 4;
  240. else
  241. return -EINVAL;
  242. /* setup PLL filter */
  243. switch (params->u.ofdm.bandwidth) {
  244. case BANDWIDTH_6_MHZ:
  245. filter = 0;
  246. break;
  247. case BANDWIDTH_7_MHZ:
  248. filter = 0;
  249. break;
  250. case BANDWIDTH_8_MHZ:
  251. filter = 1;
  252. break;
  253. default:
  254. return -EINVAL;
  255. }
  256. /* calculate divisor
  257. * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
  258. */
  259. tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
  260. /* setup tuner buffer */
  261. tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
  262. tuner_buf[1] = tuner_frequency & 0xff;
  263. tuner_buf[2] = 0xca;
  264. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  265. if (fe->ops.i2c_gate_ctrl)
  266. fe->ops.i2c_gate_ctrl(fe, 1);
  267. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
  268. wprintk("could not write to tuner at addr: 0x%02x\n",
  269. addr << 1);
  270. return -EIO;
  271. }
  272. msleep(1);
  273. return 0;
  274. }
  275. static int philips_tu1216_init(struct dvb_frontend *fe)
  276. {
  277. struct saa7134_dev *dev = fe->dvb->priv;
  278. struct tda1004x_state *state = fe->demodulator_priv;
  279. u8 addr = state->config->tuner_address;
  280. static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  281. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
  282. /* setup PLL configuration */
  283. if (fe->ops.i2c_gate_ctrl)
  284. fe->ops.i2c_gate_ctrl(fe, 1);
  285. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  286. return -EIO;
  287. msleep(1);
  288. return 0;
  289. }
  290. /* ------------------------------------------------------------------ */
  291. static struct tda1004x_config philips_tu1216_60_config = {
  292. .demod_address = 0x8,
  293. .invert = 1,
  294. .invert_oclk = 0,
  295. .xtal_freq = TDA10046_XTAL_4M,
  296. .agc_config = TDA10046_AGC_DEFAULT,
  297. .if_freq = TDA10046_FREQ_3617,
  298. .tuner_address = 0x60,
  299. .request_firmware = philips_tda1004x_request_firmware
  300. };
  301. static struct tda1004x_config philips_tu1216_61_config = {
  302. .demod_address = 0x8,
  303. .invert = 1,
  304. .invert_oclk = 0,
  305. .xtal_freq = TDA10046_XTAL_4M,
  306. .agc_config = TDA10046_AGC_DEFAULT,
  307. .if_freq = TDA10046_FREQ_3617,
  308. .tuner_address = 0x61,
  309. .request_firmware = philips_tda1004x_request_firmware
  310. };
  311. /* ------------------------------------------------------------------ */
  312. static int philips_td1316_tuner_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 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
  318. struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  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, &init_msg, 1) != 1)
  323. return -EIO;
  324. return 0;
  325. }
  326. static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  327. {
  328. return philips_tda6651_pll_set(fe, params);
  329. }
  330. static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
  331. {
  332. struct saa7134_dev *dev = fe->dvb->priv;
  333. struct tda1004x_state *state = fe->demodulator_priv;
  334. u8 addr = state->config->tuner_address;
  335. static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
  336. struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  337. /* switch the tuner to analog mode */
  338. if (fe->ops.i2c_gate_ctrl)
  339. fe->ops.i2c_gate_ctrl(fe, 1);
  340. if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
  341. return -EIO;
  342. return 0;
  343. }
  344. /* ------------------------------------------------------------------ */
  345. static int philips_europa_tuner_init(struct dvb_frontend *fe)
  346. {
  347. struct saa7134_dev *dev = fe->dvb->priv;
  348. static u8 msg[] = { 0x00, 0x40};
  349. struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  350. if (philips_td1316_tuner_init(fe))
  351. return -EIO;
  352. msleep(1);
  353. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  354. return -EIO;
  355. return 0;
  356. }
  357. static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
  358. {
  359. struct saa7134_dev *dev = fe->dvb->priv;
  360. static u8 msg[] = { 0x00, 0x14 };
  361. struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  362. if (philips_td1316_tuner_sleep(fe))
  363. return -EIO;
  364. /* switch the board to analog mode */
  365. if (fe->ops.i2c_gate_ctrl)
  366. fe->ops.i2c_gate_ctrl(fe, 1);
  367. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  368. return 0;
  369. }
  370. static int philips_europa_demod_sleep(struct dvb_frontend *fe)
  371. {
  372. struct saa7134_dev *dev = fe->dvb->priv;
  373. if (dev->original_demod_sleep)
  374. dev->original_demod_sleep(fe);
  375. fe->ops.i2c_gate_ctrl(fe, 1);
  376. return 0;
  377. }
  378. static struct tda1004x_config philips_europa_config = {
  379. .demod_address = 0x8,
  380. .invert = 0,
  381. .invert_oclk = 0,
  382. .xtal_freq = TDA10046_XTAL_4M,
  383. .agc_config = TDA10046_AGC_IFO_AUTO_POS,
  384. .if_freq = TDA10046_FREQ_052,
  385. .tuner_address = 0x61,
  386. .request_firmware = philips_tda1004x_request_firmware
  387. };
  388. static struct tda1004x_config medion_cardbus = {
  389. .demod_address = 0x08,
  390. .invert = 1,
  391. .invert_oclk = 0,
  392. .xtal_freq = TDA10046_XTAL_16M,
  393. .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
  394. .if_freq = TDA10046_FREQ_3613,
  395. .tuner_address = 0x61,
  396. .request_firmware = philips_tda1004x_request_firmware
  397. };
  398. /* ------------------------------------------------------------------
  399. * tda 1004x based cards with philips silicon tuner
  400. */
  401. static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
  402. {
  403. struct tda1004x_state *state = fe->demodulator_priv;
  404. u8 addr = state->config->i2c_gate;
  405. static u8 tda8290_close[] = { 0x21, 0xc0};
  406. static u8 tda8290_open[] = { 0x21, 0x80};
  407. struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
  408. if (enable) {
  409. tda8290_msg.buf = tda8290_close;
  410. } else {
  411. tda8290_msg.buf = tda8290_open;
  412. }
  413. if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
  414. struct saa7134_dev *dev = fe->dvb->priv;
  415. wprintk("could not access tda8290 I2C gate\n");
  416. return -EIO;
  417. }
  418. msleep(20);
  419. return 0;
  420. }
  421. static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
  422. {
  423. struct saa7134_dev *dev = fe->dvb->priv;
  424. struct tda1004x_state *state = fe->demodulator_priv;
  425. switch (state->config->antenna_switch) {
  426. case 0: break;
  427. case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
  428. saa7134_set_gpio(dev, 21, 0);
  429. break;
  430. case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
  431. saa7134_set_gpio(dev, 21, 1);
  432. break;
  433. }
  434. return 0;
  435. }
  436. static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
  437. {
  438. struct saa7134_dev *dev = fe->dvb->priv;
  439. struct tda1004x_state *state = fe->demodulator_priv;
  440. switch (state->config->antenna_switch) {
  441. case 0: break;
  442. case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
  443. saa7134_set_gpio(dev, 21, 1);
  444. break;
  445. case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
  446. saa7134_set_gpio(dev, 21, 0);
  447. break;
  448. }
  449. return 0;
  450. }
  451. static int configure_tda827x_fe(struct saa7134_dev *dev,
  452. struct tda1004x_config *cdec_conf,
  453. struct tda827x_config *tuner_conf)
  454. {
  455. struct videobuf_dvb_frontend *fe0;
  456. /* Get the first frontend */
  457. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  458. fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
  459. if (fe0->dvb.frontend) {
  460. if (cdec_conf->i2c_gate)
  461. fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  462. if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
  463. cdec_conf->tuner_address,
  464. &dev->i2c_adap, tuner_conf))
  465. return 0;
  466. wprintk("no tda827x tuner found at addr: %02x\n",
  467. cdec_conf->tuner_address);
  468. }
  469. return -EINVAL;
  470. }
  471. /* ------------------------------------------------------------------ */
  472. static struct tda827x_config tda827x_cfg_0 = {
  473. .init = philips_tda827x_tuner_init,
  474. .sleep = philips_tda827x_tuner_sleep,
  475. .config = 0,
  476. .switch_addr = 0
  477. };
  478. static struct tda827x_config tda827x_cfg_1 = {
  479. .init = philips_tda827x_tuner_init,
  480. .sleep = philips_tda827x_tuner_sleep,
  481. .config = 1,
  482. .switch_addr = 0x4b
  483. };
  484. static struct tda827x_config tda827x_cfg_2 = {
  485. .init = philips_tda827x_tuner_init,
  486. .sleep = philips_tda827x_tuner_sleep,
  487. .config = 2,
  488. .switch_addr = 0x4b
  489. };
  490. static struct tda827x_config tda827x_cfg_2_sw42 = {
  491. .init = philips_tda827x_tuner_init,
  492. .sleep = philips_tda827x_tuner_sleep,
  493. .config = 2,
  494. .switch_addr = 0x42
  495. };
  496. /* ------------------------------------------------------------------ */
  497. static struct tda1004x_config tda827x_lifeview_config = {
  498. .demod_address = 0x08,
  499. .invert = 1,
  500. .invert_oclk = 0,
  501. .xtal_freq = TDA10046_XTAL_16M,
  502. .agc_config = TDA10046_AGC_TDA827X,
  503. .gpio_config = TDA10046_GP11_I,
  504. .if_freq = TDA10046_FREQ_045,
  505. .tuner_address = 0x60,
  506. .request_firmware = philips_tda1004x_request_firmware
  507. };
  508. static struct tda1004x_config philips_tiger_config = {
  509. .demod_address = 0x08,
  510. .invert = 1,
  511. .invert_oclk = 0,
  512. .xtal_freq = TDA10046_XTAL_16M,
  513. .agc_config = TDA10046_AGC_TDA827X,
  514. .gpio_config = TDA10046_GP11_I,
  515. .if_freq = TDA10046_FREQ_045,
  516. .i2c_gate = 0x4b,
  517. .tuner_address = 0x61,
  518. .antenna_switch= 1,
  519. .request_firmware = philips_tda1004x_request_firmware
  520. };
  521. static struct tda1004x_config cinergy_ht_config = {
  522. .demod_address = 0x08,
  523. .invert = 1,
  524. .invert_oclk = 0,
  525. .xtal_freq = TDA10046_XTAL_16M,
  526. .agc_config = TDA10046_AGC_TDA827X,
  527. .gpio_config = TDA10046_GP01_I,
  528. .if_freq = TDA10046_FREQ_045,
  529. .i2c_gate = 0x4b,
  530. .tuner_address = 0x61,
  531. .request_firmware = philips_tda1004x_request_firmware
  532. };
  533. static struct tda1004x_config cinergy_ht_pci_config = {
  534. .demod_address = 0x08,
  535. .invert = 1,
  536. .invert_oclk = 0,
  537. .xtal_freq = TDA10046_XTAL_16M,
  538. .agc_config = TDA10046_AGC_TDA827X,
  539. .gpio_config = TDA10046_GP01_I,
  540. .if_freq = TDA10046_FREQ_045,
  541. .i2c_gate = 0x4b,
  542. .tuner_address = 0x60,
  543. .request_firmware = philips_tda1004x_request_firmware
  544. };
  545. static struct tda1004x_config philips_tiger_s_config = {
  546. .demod_address = 0x08,
  547. .invert = 1,
  548. .invert_oclk = 0,
  549. .xtal_freq = TDA10046_XTAL_16M,
  550. .agc_config = TDA10046_AGC_TDA827X,
  551. .gpio_config = TDA10046_GP01_I,
  552. .if_freq = TDA10046_FREQ_045,
  553. .i2c_gate = 0x4b,
  554. .tuner_address = 0x61,
  555. .antenna_switch= 1,
  556. .request_firmware = philips_tda1004x_request_firmware
  557. };
  558. static struct tda1004x_config pinnacle_pctv_310i_config = {
  559. .demod_address = 0x08,
  560. .invert = 1,
  561. .invert_oclk = 0,
  562. .xtal_freq = TDA10046_XTAL_16M,
  563. .agc_config = TDA10046_AGC_TDA827X,
  564. .gpio_config = TDA10046_GP11_I,
  565. .if_freq = TDA10046_FREQ_045,
  566. .i2c_gate = 0x4b,
  567. .tuner_address = 0x61,
  568. .request_firmware = philips_tda1004x_request_firmware
  569. };
  570. static struct tda1004x_config hauppauge_hvr_1110_config = {
  571. .demod_address = 0x08,
  572. .invert = 1,
  573. .invert_oclk = 0,
  574. .xtal_freq = TDA10046_XTAL_16M,
  575. .agc_config = TDA10046_AGC_TDA827X,
  576. .gpio_config = TDA10046_GP11_I,
  577. .if_freq = TDA10046_FREQ_045,
  578. .i2c_gate = 0x4b,
  579. .tuner_address = 0x61,
  580. .request_firmware = philips_tda1004x_request_firmware
  581. };
  582. static struct tda1004x_config asus_p7131_dual_config = {
  583. .demod_address = 0x08,
  584. .invert = 1,
  585. .invert_oclk = 0,
  586. .xtal_freq = TDA10046_XTAL_16M,
  587. .agc_config = TDA10046_AGC_TDA827X,
  588. .gpio_config = TDA10046_GP11_I,
  589. .if_freq = TDA10046_FREQ_045,
  590. .i2c_gate = 0x4b,
  591. .tuner_address = 0x61,
  592. .antenna_switch= 2,
  593. .request_firmware = philips_tda1004x_request_firmware
  594. };
  595. static struct tda1004x_config lifeview_trio_config = {
  596. .demod_address = 0x09,
  597. .invert = 1,
  598. .invert_oclk = 0,
  599. .xtal_freq = TDA10046_XTAL_16M,
  600. .agc_config = TDA10046_AGC_TDA827X,
  601. .gpio_config = TDA10046_GP00_I,
  602. .if_freq = TDA10046_FREQ_045,
  603. .tuner_address = 0x60,
  604. .request_firmware = philips_tda1004x_request_firmware
  605. };
  606. static struct tda1004x_config tevion_dvbt220rf_config = {
  607. .demod_address = 0x08,
  608. .invert = 1,
  609. .invert_oclk = 0,
  610. .xtal_freq = TDA10046_XTAL_16M,
  611. .agc_config = TDA10046_AGC_TDA827X,
  612. .gpio_config = TDA10046_GP11_I,
  613. .if_freq = TDA10046_FREQ_045,
  614. .tuner_address = 0x60,
  615. .request_firmware = philips_tda1004x_request_firmware
  616. };
  617. static struct tda1004x_config md8800_dvbt_config = {
  618. .demod_address = 0x08,
  619. .invert = 1,
  620. .invert_oclk = 0,
  621. .xtal_freq = TDA10046_XTAL_16M,
  622. .agc_config = TDA10046_AGC_TDA827X,
  623. .gpio_config = TDA10046_GP01_I,
  624. .if_freq = TDA10046_FREQ_045,
  625. .i2c_gate = 0x4b,
  626. .tuner_address = 0x60,
  627. .request_firmware = philips_tda1004x_request_firmware
  628. };
  629. static struct tda1004x_config asus_p7131_4871_config = {
  630. .demod_address = 0x08,
  631. .invert = 1,
  632. .invert_oclk = 0,
  633. .xtal_freq = TDA10046_XTAL_16M,
  634. .agc_config = TDA10046_AGC_TDA827X,
  635. .gpio_config = TDA10046_GP01_I,
  636. .if_freq = TDA10046_FREQ_045,
  637. .i2c_gate = 0x4b,
  638. .tuner_address = 0x61,
  639. .antenna_switch= 2,
  640. .request_firmware = philips_tda1004x_request_firmware
  641. };
  642. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  643. .demod_address = 0x08,
  644. .invert = 1,
  645. .invert_oclk = 0,
  646. .xtal_freq = TDA10046_XTAL_16M,
  647. .agc_config = TDA10046_AGC_TDA827X,
  648. .gpio_config = TDA10046_GP11_I,
  649. .if_freq = TDA10046_FREQ_045,
  650. .i2c_gate = 0x4b,
  651. .tuner_address = 0x61,
  652. .antenna_switch= 2,
  653. .request_firmware = philips_tda1004x_request_firmware
  654. };
  655. static struct tda1004x_config kworld_dvb_t_210_config = {
  656. .demod_address = 0x08,
  657. .invert = 1,
  658. .invert_oclk = 0,
  659. .xtal_freq = TDA10046_XTAL_16M,
  660. .agc_config = TDA10046_AGC_TDA827X,
  661. .gpio_config = TDA10046_GP11_I,
  662. .if_freq = TDA10046_FREQ_045,
  663. .i2c_gate = 0x4b,
  664. .tuner_address = 0x61,
  665. .antenna_switch= 1,
  666. .request_firmware = philips_tda1004x_request_firmware
  667. };
  668. static struct tda1004x_config avermedia_super_007_config = {
  669. .demod_address = 0x08,
  670. .invert = 1,
  671. .invert_oclk = 0,
  672. .xtal_freq = TDA10046_XTAL_16M,
  673. .agc_config = TDA10046_AGC_TDA827X,
  674. .gpio_config = TDA10046_GP01_I,
  675. .if_freq = TDA10046_FREQ_045,
  676. .i2c_gate = 0x4b,
  677. .tuner_address = 0x60,
  678. .antenna_switch= 1,
  679. .request_firmware = philips_tda1004x_request_firmware
  680. };
  681. static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
  682. .demod_address = 0x08,
  683. .invert = 1,
  684. .invert_oclk = 0,
  685. .xtal_freq = TDA10046_XTAL_16M,
  686. .agc_config = TDA10046_AGC_TDA827X,
  687. .gpio_config = TDA10046_GP01_I,
  688. .if_freq = TDA10046_FREQ_045,
  689. .i2c_gate = 0x42,
  690. .tuner_address = 0x61,
  691. .antenna_switch = 1,
  692. .request_firmware = philips_tda1004x_request_firmware
  693. };
  694. static struct tda1004x_config asus_tiger_3in1_config = {
  695. .demod_address = 0x0b,
  696. .invert = 1,
  697. .invert_oclk = 0,
  698. .xtal_freq = TDA10046_XTAL_16M,
  699. .agc_config = TDA10046_AGC_TDA827X,
  700. .gpio_config = TDA10046_GP11_I,
  701. .if_freq = TDA10046_FREQ_045,
  702. .i2c_gate = 0x4b,
  703. .tuner_address = 0x61,
  704. .antenna_switch = 1,
  705. .request_firmware = philips_tda1004x_request_firmware
  706. };
  707. /* ------------------------------------------------------------------
  708. * special case: this card uses saa713x GPIO22 for the mode switch
  709. */
  710. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  711. {
  712. struct saa7134_dev *dev = fe->dvb->priv;
  713. philips_tda827x_tuner_init(fe);
  714. /* route TDA8275a AGC input to the channel decoder */
  715. saa7134_set_gpio(dev, 22, 1);
  716. return 0;
  717. }
  718. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  719. {
  720. struct saa7134_dev *dev = fe->dvb->priv;
  721. /* route TDA8275a AGC input to the analog IF chip*/
  722. saa7134_set_gpio(dev, 22, 0);
  723. philips_tda827x_tuner_sleep(fe);
  724. return 0;
  725. }
  726. static struct tda827x_config ads_duo_cfg = {
  727. .init = ads_duo_tuner_init,
  728. .sleep = ads_duo_tuner_sleep,
  729. .config = 0
  730. };
  731. static struct tda1004x_config ads_tech_duo_config = {
  732. .demod_address = 0x08,
  733. .invert = 1,
  734. .invert_oclk = 0,
  735. .xtal_freq = TDA10046_XTAL_16M,
  736. .agc_config = TDA10046_AGC_TDA827X,
  737. .gpio_config = TDA10046_GP00_I,
  738. .if_freq = TDA10046_FREQ_045,
  739. .tuner_address = 0x61,
  740. .request_firmware = philips_tda1004x_request_firmware
  741. };
  742. static struct zl10353_config behold_h6_config = {
  743. .demod_address = 0x1e>>1,
  744. .no_tuner = 1,
  745. .parallel_ts = 1,
  746. };
  747. /* ==================================================================
  748. * tda10086 based DVB-S cards, helper functions
  749. */
  750. static struct tda10086_config flydvbs = {
  751. .demod_address = 0x0e,
  752. .invert = 0,
  753. .diseqc_tone = 0,
  754. .xtal_freq = TDA10086_XTAL_16M,
  755. };
  756. static struct tda10086_config sd1878_4m = {
  757. .demod_address = 0x0e,
  758. .invert = 0,
  759. .diseqc_tone = 0,
  760. .xtal_freq = TDA10086_XTAL_4M,
  761. };
  762. /* ------------------------------------------------------------------
  763. * special case: lnb supply is connected to the gated i2c
  764. */
  765. static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  766. {
  767. int res = -EIO;
  768. struct saa7134_dev *dev = fe->dvb->priv;
  769. if (fe->ops.i2c_gate_ctrl) {
  770. fe->ops.i2c_gate_ctrl(fe, 1);
  771. if (dev->original_set_voltage)
  772. res = dev->original_set_voltage(fe, voltage);
  773. fe->ops.i2c_gate_ctrl(fe, 0);
  774. }
  775. return res;
  776. };
  777. static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
  778. {
  779. int res = -EIO;
  780. struct saa7134_dev *dev = fe->dvb->priv;
  781. if (fe->ops.i2c_gate_ctrl) {
  782. fe->ops.i2c_gate_ctrl(fe, 1);
  783. if (dev->original_set_high_voltage)
  784. res = dev->original_set_high_voltage(fe, arg);
  785. fe->ops.i2c_gate_ctrl(fe, 0);
  786. }
  787. return res;
  788. };
  789. static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  790. {
  791. struct saa7134_dev *dev = fe->dvb->priv;
  792. u8 wbuf[2] = { 0x1f, 00 };
  793. u8 rbuf;
  794. struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
  795. { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
  796. if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
  797. return -EIO;
  798. /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
  799. if (voltage == SEC_VOLTAGE_18)
  800. wbuf[1] = rbuf | 0x10;
  801. else
  802. wbuf[1] = rbuf & 0xef;
  803. msg[0].len = 2;
  804. i2c_transfer(&dev->i2c_adap, msg, 1);
  805. return 0;
  806. }
  807. static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
  808. {
  809. struct saa7134_dev *dev = fe->dvb->priv;
  810. wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
  811. return -EIO;
  812. }
  813. /* ==================================================================
  814. * nxt200x based ATSC cards, helper functions
  815. */
  816. static struct nxt200x_config avertvhda180 = {
  817. .demod_address = 0x0a,
  818. };
  819. static struct nxt200x_config kworldatsc110 = {
  820. .demod_address = 0x0a,
  821. };
  822. /* ==================================================================
  823. * Core code
  824. */
  825. static int dvb_init(struct saa7134_dev *dev)
  826. {
  827. int ret;
  828. int attach_xc3028 = 0;
  829. struct videobuf_dvb_frontend *fe0;
  830. /* FIXME: add support for multi-frontend */
  831. mutex_init(&dev->frontends.lock);
  832. INIT_LIST_HEAD(&dev->frontends.felist);
  833. printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
  834. fe0 = videobuf_dvb_alloc_frontend(&dev->frontends, 1);
  835. if (!fe0) {
  836. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  837. return -ENOMEM;
  838. }
  839. /* init struct videobuf_dvb */
  840. dev->ts.nr_bufs = 32;
  841. dev->ts.nr_packets = 32*4;
  842. fe0->dvb.name = dev->name;
  843. videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
  844. &dev->pci->dev, &dev->slock,
  845. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  846. V4L2_FIELD_ALTERNATE,
  847. sizeof(struct saa7134_buf),
  848. dev);
  849. switch (dev->board) {
  850. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  851. dprintk("pinnacle 300i dvb setup\n");
  852. fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  853. &dev->i2c_adap);
  854. if (fe0->dvb.frontend) {
  855. fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  856. }
  857. break;
  858. case SAA7134_BOARD_AVERMEDIA_777:
  859. case SAA7134_BOARD_AVERMEDIA_A16AR:
  860. dprintk("avertv 777 dvb setup\n");
  861. fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  862. &dev->i2c_adap);
  863. if (fe0->dvb.frontend) {
  864. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  865. &dev->i2c_adap, 0x61,
  866. TUNER_PHILIPS_TD1316);
  867. }
  868. break;
  869. case SAA7134_BOARD_AVERMEDIA_A16D:
  870. dprintk("AverMedia A16D dvb setup\n");
  871. fe0->dvb.frontend = dvb_attach(mt352_attach,
  872. &avermedia_xc3028_mt352_dev,
  873. &dev->i2c_adap);
  874. attach_xc3028 = 1;
  875. break;
  876. case SAA7134_BOARD_MD7134:
  877. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  878. &medion_cardbus,
  879. &dev->i2c_adap);
  880. if (fe0->dvb.frontend) {
  881. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  882. &dev->i2c_adap, medion_cardbus.tuner_address,
  883. TUNER_PHILIPS_FMD1216ME_MK3);
  884. }
  885. break;
  886. case SAA7134_BOARD_PHILIPS_TOUGH:
  887. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  888. &philips_tu1216_60_config,
  889. &dev->i2c_adap);
  890. if (fe0->dvb.frontend) {
  891. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  892. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  893. }
  894. break;
  895. case SAA7134_BOARD_FLYDVBTDUO:
  896. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  897. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  898. &tda827x_cfg_0) < 0)
  899. goto dettach_frontend;
  900. break;
  901. case SAA7134_BOARD_PHILIPS_EUROPA:
  902. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  903. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  904. &philips_europa_config,
  905. &dev->i2c_adap);
  906. if (fe0->dvb.frontend) {
  907. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  908. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  909. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  910. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  911. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  912. }
  913. break;
  914. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  915. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  916. &philips_tu1216_61_config,
  917. &dev->i2c_adap);
  918. if (fe0->dvb.frontend) {
  919. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  920. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  921. }
  922. break;
  923. case SAA7134_BOARD_KWORLD_DVBT_210:
  924. if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
  925. &tda827x_cfg_2) < 0)
  926. goto dettach_frontend;
  927. break;
  928. case SAA7134_BOARD_PHILIPS_TIGER:
  929. if (configure_tda827x_fe(dev, &philips_tiger_config,
  930. &tda827x_cfg_0) < 0)
  931. goto dettach_frontend;
  932. break;
  933. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  934. if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
  935. &tda827x_cfg_1) < 0)
  936. goto dettach_frontend;
  937. break;
  938. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  939. if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
  940. &tda827x_cfg_1) < 0)
  941. goto dettach_frontend;
  942. break;
  943. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  944. if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
  945. &tda827x_cfg_0) < 0)
  946. goto dettach_frontend;
  947. break;
  948. case SAA7134_BOARD_FLYDVBT_LR301:
  949. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  950. &tda827x_cfg_0) < 0)
  951. goto dettach_frontend;
  952. break;
  953. case SAA7134_BOARD_FLYDVB_TRIO:
  954. if (!use_frontend) { /* terrestrial */
  955. if (configure_tda827x_fe(dev, &lifeview_trio_config,
  956. &tda827x_cfg_0) < 0)
  957. goto dettach_frontend;
  958. } else { /* satellite */
  959. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  960. if (fe0->dvb.frontend) {
  961. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
  962. &dev->i2c_adap, 0) == NULL) {
  963. wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
  964. goto dettach_frontend;
  965. }
  966. if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
  967. 0x08, 0, 0) == NULL) {
  968. wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
  969. goto dettach_frontend;
  970. }
  971. }
  972. }
  973. break;
  974. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  975. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  976. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  977. &ads_tech_duo_config,
  978. &dev->i2c_adap);
  979. if (fe0->dvb.frontend) {
  980. if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
  981. ads_tech_duo_config.tuner_address, &dev->i2c_adap,
  982. &ads_duo_cfg) == NULL) {
  983. wprintk("no tda827x tuner found at addr: %02x\n",
  984. ads_tech_duo_config.tuner_address);
  985. goto dettach_frontend;
  986. }
  987. } else
  988. wprintk("failed to attach tda10046\n");
  989. break;
  990. case SAA7134_BOARD_TEVION_DVBT_220RF:
  991. if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
  992. &tda827x_cfg_0) < 0)
  993. goto dettach_frontend;
  994. break;
  995. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  996. if (!use_frontend) { /* terrestrial */
  997. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  998. &tda827x_cfg_0) < 0)
  999. goto dettach_frontend;
  1000. } else { /* satellite */
  1001. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1002. &flydvbs, &dev->i2c_adap);
  1003. if (fe0->dvb.frontend) {
  1004. struct dvb_frontend *fe = fe0->dvb.frontend;
  1005. u8 dev_id = dev->eedata[2];
  1006. u8 data = 0xc4;
  1007. struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
  1008. if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
  1009. 0x60, &dev->i2c_adap, 0) == NULL) {
  1010. wprintk("%s: Medion Quadro, no tda826x "
  1011. "found !\n", __func__);
  1012. goto dettach_frontend;
  1013. }
  1014. if (dev_id != 0x08) {
  1015. /* we need to open the i2c gate (we know it exists) */
  1016. fe->ops.i2c_gate_ctrl(fe, 1);
  1017. if (dvb_attach(isl6405_attach, fe,
  1018. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1019. wprintk("%s: Medion Quadro, no ISL6405 "
  1020. "found !\n", __func__);
  1021. goto dettach_frontend;
  1022. }
  1023. if (dev_id == 0x07) {
  1024. /* fire up the 2nd section of the LNB supply since
  1025. we can't do this from the other section */
  1026. msg.buf = &data;
  1027. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1028. }
  1029. fe->ops.i2c_gate_ctrl(fe, 0);
  1030. dev->original_set_voltage = fe->ops.set_voltage;
  1031. fe->ops.set_voltage = md8800_set_voltage;
  1032. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1033. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1034. } else {
  1035. fe->ops.set_voltage = md8800_set_voltage2;
  1036. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
  1037. }
  1038. }
  1039. }
  1040. break;
  1041. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  1042. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  1043. &dev->i2c_adap);
  1044. if (fe0->dvb.frontend)
  1045. dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
  1046. NULL, DVB_PLL_TDHU2);
  1047. break;
  1048. case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
  1049. case SAA7134_BOARD_KWORLD_ATSC110:
  1050. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  1051. &dev->i2c_adap);
  1052. if (fe0->dvb.frontend)
  1053. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1054. &dev->i2c_adap, 0x61,
  1055. TUNER_PHILIPS_TUV1236D);
  1056. break;
  1057. case SAA7134_BOARD_FLYDVBS_LR300:
  1058. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1059. &dev->i2c_adap);
  1060. if (fe0->dvb.frontend) {
  1061. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1062. &dev->i2c_adap, 0) == NULL) {
  1063. wprintk("%s: No tda826x found!\n", __func__);
  1064. goto dettach_frontend;
  1065. }
  1066. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1067. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1068. wprintk("%s: No ISL6421 found!\n", __func__);
  1069. goto dettach_frontend;
  1070. }
  1071. }
  1072. break;
  1073. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1074. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1075. &medion_cardbus,
  1076. &dev->i2c_adap);
  1077. if (fe0->dvb.frontend) {
  1078. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1079. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1080. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1081. &dev->i2c_adap, medion_cardbus.tuner_address,
  1082. TUNER_PHILIPS_FMD1216ME_MK3);
  1083. }
  1084. break;
  1085. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1086. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1087. &philips_europa_config,
  1088. &dev->i2c_adap);
  1089. if (fe0->dvb.frontend) {
  1090. fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1091. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1092. }
  1093. break;
  1094. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1095. if (configure_tda827x_fe(dev, &cinergy_ht_config,
  1096. &tda827x_cfg_0) < 0)
  1097. goto dettach_frontend;
  1098. break;
  1099. case SAA7134_BOARD_CINERGY_HT_PCI:
  1100. if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
  1101. &tda827x_cfg_0) < 0)
  1102. goto dettach_frontend;
  1103. break;
  1104. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1105. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1106. &tda827x_cfg_2) < 0)
  1107. goto dettach_frontend;
  1108. break;
  1109. case SAA7134_BOARD_ASUS_P7131_4871:
  1110. if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
  1111. &tda827x_cfg_2) < 0)
  1112. goto dettach_frontend;
  1113. break;
  1114. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1115. if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
  1116. &tda827x_cfg_2) < 0)
  1117. goto dettach_frontend;
  1118. break;
  1119. case SAA7134_BOARD_AVERMEDIA_SUPER_007:
  1120. if (configure_tda827x_fe(dev, &avermedia_super_007_config,
  1121. &tda827x_cfg_0) < 0)
  1122. goto dettach_frontend;
  1123. break;
  1124. case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
  1125. if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
  1126. &tda827x_cfg_2_sw42) < 0)
  1127. goto dettach_frontend;
  1128. break;
  1129. case SAA7134_BOARD_PHILIPS_SNAKE:
  1130. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1131. &dev->i2c_adap);
  1132. if (fe0->dvb.frontend) {
  1133. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1134. &dev->i2c_adap, 0) == NULL) {
  1135. wprintk("%s: No tda826x found!\n", __func__);
  1136. goto dettach_frontend;
  1137. }
  1138. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1139. &dev->i2c_adap, 0, 0) == NULL) {
  1140. wprintk("%s: No lnbp21 found!\n", __func__);
  1141. goto dettach_frontend;
  1142. }
  1143. }
  1144. break;
  1145. case SAA7134_BOARD_CREATIX_CTX953:
  1146. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1147. &tda827x_cfg_0) < 0)
  1148. goto dettach_frontend;
  1149. break;
  1150. case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
  1151. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1152. &tda827x_cfg_2) < 0)
  1153. goto dettach_frontend;
  1154. break;
  1155. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  1156. dprintk("AverMedia E506R dvb setup\n");
  1157. saa7134_set_gpio(dev, 25, 0);
  1158. msleep(10);
  1159. saa7134_set_gpio(dev, 25, 1);
  1160. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1161. &avermedia_xc3028_mt352_dev,
  1162. &dev->i2c_adap);
  1163. attach_xc3028 = 1;
  1164. break;
  1165. case SAA7134_BOARD_MD7134_BRIDGE_2:
  1166. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1167. &sd1878_4m, &dev->i2c_adap);
  1168. if (fe0->dvb.frontend) {
  1169. struct dvb_frontend *fe;
  1170. if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1171. &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
  1172. wprintk("%s: MD7134 DVB-S, no SD1878 "
  1173. "found !\n", __func__);
  1174. goto dettach_frontend;
  1175. }
  1176. /* we need to open the i2c gate (we know it exists) */
  1177. fe = fe0->dvb.frontend;
  1178. fe->ops.i2c_gate_ctrl(fe, 1);
  1179. if (dvb_attach(isl6405_attach, fe,
  1180. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1181. wprintk("%s: MD7134 DVB-S, no ISL6405 "
  1182. "found !\n", __func__);
  1183. goto dettach_frontend;
  1184. }
  1185. fe->ops.i2c_gate_ctrl(fe, 0);
  1186. dev->original_set_voltage = fe->ops.set_voltage;
  1187. fe->ops.set_voltage = md8800_set_voltage;
  1188. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1189. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1190. }
  1191. break;
  1192. case SAA7134_BOARD_AVERMEDIA_M103:
  1193. saa7134_set_gpio(dev, 25, 0);
  1194. msleep(10);
  1195. saa7134_set_gpio(dev, 25, 1);
  1196. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1197. &avermedia_xc3028_mt352_dev,
  1198. &dev->i2c_adap);
  1199. attach_xc3028 = 1;
  1200. break;
  1201. case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
  1202. if (!use_frontend) { /* terrestrial */
  1203. if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
  1204. &tda827x_cfg_2) < 0)
  1205. goto dettach_frontend;
  1206. } else { /* satellite */
  1207. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1208. &flydvbs, &dev->i2c_adap);
  1209. if (fe0->dvb.frontend) {
  1210. if (dvb_attach(tda826x_attach,
  1211. fe0->dvb.frontend, 0x60,
  1212. &dev->i2c_adap, 0) == NULL) {
  1213. wprintk("%s: Asus Tiger 3in1, no "
  1214. "tda826x found!\n", __func__);
  1215. goto dettach_frontend;
  1216. }
  1217. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1218. &dev->i2c_adap, 0, 0) == NULL) {
  1219. wprintk("%s: Asus Tiger 3in1, no lnbp21"
  1220. " found!\n", __func__);
  1221. goto dettach_frontend;
  1222. }
  1223. }
  1224. }
  1225. break;
  1226. case SAA7134_BOARD_ASUSTeK_TIGER:
  1227. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1228. &tda827x_cfg_0) < 0)
  1229. goto dettach_frontend;
  1230. break;
  1231. case SAA7134_BOARD_BEHOLD_H6:
  1232. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1233. &behold_h6_config,
  1234. &dev->i2c_adap);
  1235. if (fe0->dvb.frontend) {
  1236. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1237. &dev->i2c_adap, 0x61,
  1238. TUNER_PHILIPS_FMD1216ME_MK3);
  1239. }
  1240. break;
  1241. default:
  1242. wprintk("Huh? unknown DVB card?\n");
  1243. break;
  1244. }
  1245. if (attach_xc3028) {
  1246. struct dvb_frontend *fe;
  1247. struct xc2028_config cfg = {
  1248. .i2c_adap = &dev->i2c_adap,
  1249. .i2c_addr = 0x61,
  1250. };
  1251. if (!fe0->dvb.frontend)
  1252. goto dettach_frontend;
  1253. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  1254. if (!fe) {
  1255. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  1256. dev->name);
  1257. goto dettach_frontend;
  1258. }
  1259. }
  1260. if (NULL == fe0->dvb.frontend) {
  1261. printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
  1262. goto dettach_frontend;
  1263. }
  1264. /* define general-purpose callback pointer */
  1265. fe0->dvb.frontend->callback = saa7134_tuner_callback;
  1266. /* register everything else */
  1267. ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1268. &dev->pci->dev, adapter_nr, 0);
  1269. /* this sequence is necessary to make the tda1004x load its firmware
  1270. * and to enter analog mode of hybrid boards
  1271. */
  1272. if (!ret) {
  1273. if (fe0->dvb.frontend->ops.init)
  1274. fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
  1275. if (fe0->dvb.frontend->ops.sleep)
  1276. fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
  1277. if (fe0->dvb.frontend->ops.tuner_ops.sleep)
  1278. fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
  1279. }
  1280. return ret;
  1281. dettach_frontend:
  1282. videobuf_dvb_dealloc_frontends(&dev->frontends);
  1283. return -EINVAL;
  1284. }
  1285. static int dvb_fini(struct saa7134_dev *dev)
  1286. {
  1287. struct videobuf_dvb_frontend *fe0;
  1288. /* Get the first frontend */
  1289. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  1290. if (!fe0)
  1291. return -EINVAL;
  1292. /* FIXME: I suspect that this code is bogus, since the entry for
  1293. Pinnacle 300I DVB-T PAL already defines the proper init to allow
  1294. the detection of mt2032 (TDA9887_PORT2_INACTIVE)
  1295. */
  1296. if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
  1297. struct v4l2_priv_tun_config tda9887_cfg;
  1298. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1299. tda9887_cfg.tuner = TUNER_TDA9887;
  1300. tda9887_cfg.priv = &on;
  1301. /* otherwise we don't detect the tuner on next insmod */
  1302. saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
  1303. } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
  1304. if ((dev->eedata[2] == 0x07) && use_frontend) {
  1305. /* turn off the 2nd lnb supply */
  1306. u8 data = 0x80;
  1307. struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
  1308. struct dvb_frontend *fe;
  1309. fe = fe0->dvb.frontend;
  1310. if (fe->ops.i2c_gate_ctrl) {
  1311. fe->ops.i2c_gate_ctrl(fe, 1);
  1312. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1313. fe->ops.i2c_gate_ctrl(fe, 0);
  1314. }
  1315. }
  1316. }
  1317. videobuf_dvb_unregister_bus(&dev->frontends);
  1318. return 0;
  1319. }
  1320. static struct saa7134_mpeg_ops dvb_ops = {
  1321. .type = SAA7134_MPEG_DVB,
  1322. .init = dvb_init,
  1323. .fini = dvb_fini,
  1324. };
  1325. static int __init dvb_register(void)
  1326. {
  1327. return saa7134_ts_register(&dvb_ops);
  1328. }
  1329. static void __exit dvb_unregister(void)
  1330. {
  1331. saa7134_ts_unregister(&dvb_ops);
  1332. }
  1333. module_init(dvb_register);
  1334. module_exit(dvb_unregister);
  1335. /* ------------------------------------------------------------------ */
  1336. /*
  1337. * Local variables:
  1338. * c-basic-offset: 8
  1339. * End:
  1340. */