saa7134-dvb.c 40 KB

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