saa7134-dvb.c 45 KB

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