saa7134-dvb.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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. #ifdef HAVE_MT352
  35. # include "mt352.h"
  36. # include "mt352_priv.h" /* FIXME */
  37. #endif
  38. #ifdef HAVE_TDA1004X
  39. # include "tda1004x.h"
  40. #endif
  41. #ifdef HAVE_NXT200X
  42. # include "nxt200x.h"
  43. #endif
  44. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  45. MODULE_LICENSE("GPL");
  46. static unsigned int antenna_pwr = 0;
  47. module_param(antenna_pwr, int, 0444);
  48. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  49. /* ------------------------------------------------------------------ */
  50. #ifdef HAVE_MT352
  51. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  52. {
  53. u32 ok;
  54. if (!on) {
  55. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  56. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  57. return 0;
  58. }
  59. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  60. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  61. udelay(10);
  62. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  63. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  64. udelay(10);
  65. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  66. udelay(10);
  67. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  68. printk("%s: %s %s\n", dev->name, __FUNCTION__,
  69. ok ? "on" : "off");
  70. if (!ok)
  71. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  72. return ok;
  73. }
  74. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  75. {
  76. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  77. static u8 reset [] = { RESET, 0x80 };
  78. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  79. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  80. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  81. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  82. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  83. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  84. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  85. struct saa7134_dev *dev= fe->dvb->priv;
  86. printk("%s: %s called\n",dev->name,__FUNCTION__);
  87. mt352_write(fe, clock_config, sizeof(clock_config));
  88. udelay(200);
  89. mt352_write(fe, reset, sizeof(reset));
  90. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  91. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  92. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  93. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  94. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  95. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  96. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  97. return 0;
  98. }
  99. static int mt352_aver777_init(struct dvb_frontend* fe)
  100. {
  101. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  102. static u8 reset [] = { RESET, 0x80 };
  103. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  104. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  105. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  106. mt352_write(fe, clock_config, sizeof(clock_config));
  107. udelay(200);
  108. mt352_write(fe, reset, sizeof(reset));
  109. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  110. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  111. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  112. return 0;
  113. }
  114. static int mt352_pinnacle_tuner_pllbuf(struct dvb_frontend* fe,
  115. struct dvb_frontend_parameters* params,
  116. u8* pllbuf, int buf_len)
  117. {
  118. u8 off[] = { 0x00, 0xf1};
  119. u8 on[] = { 0x00, 0x71};
  120. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  121. struct saa7134_dev *dev = fe->dvb->priv;
  122. struct v4l2_frequency f;
  123. if (buf_len < 5)
  124. return -EINVAL;
  125. /* set frequency (mt2050) */
  126. f.tuner = 0;
  127. f.type = V4L2_TUNER_DIGITAL_TV;
  128. f.frequency = params->frequency / 1000 * 16 / 1000;
  129. i2c_transfer(&dev->i2c_adap, &msg, 1);
  130. saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
  131. msg.buf = on;
  132. i2c_transfer(&dev->i2c_adap, &msg, 1);
  133. pinnacle_antenna_pwr(dev, antenna_pwr);
  134. /* mt352 setup */
  135. mt352_pinnacle_init(fe);
  136. pllbuf[0] = 0x61;
  137. pllbuf[1] = 0x00;
  138. pllbuf[2] = 0x00;
  139. pllbuf[3] = 0x80;
  140. pllbuf[4] = 0x00;
  141. return 5;
  142. }
  143. static int mt352_aver777_tuner_pllbuf(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
  144. {
  145. if (buf_len < 5)
  146. return -EINVAL;
  147. pllbuf[0] = 0x61;
  148. dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
  149. params->frequency,
  150. params->u.ofdm.bandwidth);
  151. return 5;
  152. }
  153. static struct mt352_config pinnacle_300i = {
  154. .demod_address = 0x3c >> 1,
  155. .adc_clock = 20333,
  156. .if2 = 36150,
  157. .no_tuner = 1,
  158. .demod_init = mt352_pinnacle_init,
  159. };
  160. static struct mt352_config avermedia_777 = {
  161. .demod_address = 0xf,
  162. .demod_init = mt352_aver777_init,
  163. };
  164. #endif
  165. /* ------------------------------------------------------------------ */
  166. #ifdef HAVE_TDA1004X
  167. static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  168. {
  169. struct saa7134_dev *dev = fe->dvb->priv;
  170. u8 tuner_buf[4];
  171. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  172. sizeof(tuner_buf) };
  173. int tuner_frequency = 0;
  174. u8 band, cp, filter;
  175. /* determine charge pump */
  176. tuner_frequency = params->frequency + 36166000;
  177. if (tuner_frequency < 87000000)
  178. return -EINVAL;
  179. else if (tuner_frequency < 130000000)
  180. cp = 3;
  181. else if (tuner_frequency < 160000000)
  182. cp = 5;
  183. else if (tuner_frequency < 200000000)
  184. cp = 6;
  185. else if (tuner_frequency < 290000000)
  186. cp = 3;
  187. else if (tuner_frequency < 420000000)
  188. cp = 5;
  189. else if (tuner_frequency < 480000000)
  190. cp = 6;
  191. else if (tuner_frequency < 620000000)
  192. cp = 3;
  193. else if (tuner_frequency < 830000000)
  194. cp = 5;
  195. else if (tuner_frequency < 895000000)
  196. cp = 7;
  197. else
  198. return -EINVAL;
  199. /* determine band */
  200. if (params->frequency < 49000000)
  201. return -EINVAL;
  202. else if (params->frequency < 161000000)
  203. band = 1;
  204. else if (params->frequency < 444000000)
  205. band = 2;
  206. else if (params->frequency < 861000000)
  207. band = 4;
  208. else
  209. return -EINVAL;
  210. /* setup PLL filter */
  211. switch (params->u.ofdm.bandwidth) {
  212. case BANDWIDTH_6_MHZ:
  213. filter = 0;
  214. break;
  215. case BANDWIDTH_7_MHZ:
  216. filter = 0;
  217. break;
  218. case BANDWIDTH_8_MHZ:
  219. filter = 1;
  220. break;
  221. default:
  222. return -EINVAL;
  223. }
  224. /* calculate divisor
  225. * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
  226. */
  227. tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
  228. /* setup tuner buffer */
  229. tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
  230. tuner_buf[1] = tuner_frequency & 0xff;
  231. tuner_buf[2] = 0xca;
  232. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  233. if (fe->ops->i2c_gate_ctrl)
  234. fe->ops->i2c_gate_ctrl(fe, 1);
  235. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  236. return -EIO;
  237. msleep(1);
  238. return 0;
  239. }
  240. static int philips_tda6651_pll_init(u8 addr, struct dvb_frontend *fe)
  241. {
  242. struct saa7134_dev *dev = fe->dvb->priv;
  243. static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  244. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
  245. /* setup PLL configuration */
  246. if (fe->ops->i2c_gate_ctrl)
  247. fe->ops->i2c_gate_ctrl(fe, 1);
  248. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  249. return -EIO;
  250. msleep(1);
  251. return 0;
  252. }
  253. /* ------------------------------------------------------------------ */
  254. static int philips_tu1216_tuner_60_init(struct dvb_frontend *fe)
  255. {
  256. return philips_tda6651_pll_init(0x60, fe);
  257. }
  258. static int philips_tu1216_tuner_60_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  259. {
  260. return philips_tda6651_pll_set(0x60, fe, params);
  261. }
  262. static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
  263. const struct firmware **fw, char *name)
  264. {
  265. struct saa7134_dev *dev = fe->dvb->priv;
  266. return request_firmware(fw, name, &dev->pci->dev);
  267. }
  268. static struct tda1004x_config philips_tu1216_60_config = {
  269. .demod_address = 0x8,
  270. .invert = 1,
  271. .invert_oclk = 0,
  272. .xtal_freq = TDA10046_XTAL_4M,
  273. .agc_config = TDA10046_AGC_DEFAULT,
  274. .if_freq = TDA10046_FREQ_3617,
  275. .request_firmware = philips_tu1216_request_firmware,
  276. };
  277. /* ------------------------------------------------------------------ */
  278. static int philips_tu1216_tuner_61_init(struct dvb_frontend *fe)
  279. {
  280. return philips_tda6651_pll_init(0x61, fe);
  281. }
  282. static int philips_tu1216_tuner_61_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  283. {
  284. return philips_tda6651_pll_set(0x61, fe, params);
  285. }
  286. static struct tda1004x_config philips_tu1216_61_config = {
  287. .demod_address = 0x8,
  288. .invert = 1,
  289. .invert_oclk = 0,
  290. .xtal_freq = TDA10046_XTAL_4M,
  291. .agc_config = TDA10046_AGC_DEFAULT,
  292. .if_freq = TDA10046_FREQ_3617,
  293. .request_firmware = philips_tu1216_request_firmware,
  294. };
  295. /* ------------------------------------------------------------------ */
  296. static int philips_europa_tuner_init(struct dvb_frontend *fe)
  297. {
  298. struct saa7134_dev *dev = fe->dvb->priv;
  299. static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
  300. struct i2c_msg init_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
  301. /* setup PLL configuration */
  302. if (fe->ops->i2c_gate_ctrl)
  303. fe->ops->i2c_gate_ctrl(fe, 1);
  304. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  305. return -EIO;
  306. msleep(1);
  307. /* switch the board to dvb mode */
  308. init_msg.addr = 0x43;
  309. init_msg.len = 0x02;
  310. msg[0] = 0x00;
  311. msg[1] = 0x40;
  312. if (fe->ops->i2c_gate_ctrl)
  313. fe->ops->i2c_gate_ctrl(fe, 1);
  314. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  315. return -EIO;
  316. return 0;
  317. }
  318. static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  319. {
  320. return philips_tda6651_pll_set(0x61, fe, params);
  321. }
  322. static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
  323. {
  324. struct saa7134_dev *dev = fe->dvb->priv;
  325. /* this message actually turns the tuner back to analog mode */
  326. static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
  327. struct i2c_msg analog_msg = {.addr = 0x61,.flags = 0,.buf = msg,.len = sizeof(msg) };
  328. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  329. msleep(1);
  330. /* switch the board to analog mode */
  331. analog_msg.addr = 0x43;
  332. analog_msg.len = 0x02;
  333. msg[0] = 0x00;
  334. msg[1] = 0x14;
  335. if (fe->ops->i2c_gate_ctrl)
  336. fe->ops->i2c_gate_ctrl(fe, 1);
  337. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  338. return 0;
  339. }
  340. static int philips_europa_demod_sleep(struct dvb_frontend *fe)
  341. {
  342. struct saa7134_dev *dev = fe->dvb->priv;
  343. if (dev->original_demod_sleep)
  344. dev->original_demod_sleep(fe);
  345. fe->ops->i2c_gate_ctrl(fe, 1);
  346. return 0;
  347. }
  348. static struct tda1004x_config philips_europa_config = {
  349. .demod_address = 0x8,
  350. .invert = 0,
  351. .invert_oclk = 0,
  352. .xtal_freq = TDA10046_XTAL_4M,
  353. .agc_config = TDA10046_AGC_IFO_AUTO_POS,
  354. .if_freq = TDA10046_FREQ_052,
  355. .request_firmware = NULL,
  356. };
  357. /* ------------------------------------------------------------------ */
  358. static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
  359. {
  360. struct saa7134_dev *dev = fe->dvb->priv;
  361. /* this message is to set up ATC and ALC */
  362. static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
  363. struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
  364. if (fe->ops->i2c_gate_ctrl)
  365. fe->ops->i2c_gate_ctrl(fe, 1);
  366. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  367. return -EIO;
  368. msleep(1);
  369. return 0;
  370. }
  371. static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
  372. {
  373. struct saa7134_dev *dev = fe->dvb->priv;
  374. /* this message actually turns the tuner back to analog mode */
  375. static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
  376. struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
  377. if (fe->ops->i2c_gate_ctrl)
  378. fe->ops->i2c_gate_ctrl(fe, 1);
  379. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  380. msleep(1);
  381. fmd1216_init[2] = 0x86;
  382. fmd1216_init[3] = 0x54;
  383. if (fe->ops->i2c_gate_ctrl)
  384. fe->ops->i2c_gate_ctrl(fe, 1);
  385. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  386. msleep(1);
  387. return 0;
  388. }
  389. static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  390. {
  391. struct saa7134_dev *dev = fe->dvb->priv;
  392. u8 tuner_buf[4];
  393. struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
  394. sizeof(tuner_buf) };
  395. int tuner_frequency = 0;
  396. int divider = 0;
  397. u8 band, mode, cp;
  398. /* determine charge pump */
  399. tuner_frequency = params->frequency + 36130000;
  400. if (tuner_frequency < 87000000)
  401. return -EINVAL;
  402. /* low band */
  403. else if (tuner_frequency < 180000000) {
  404. band = 1;
  405. mode = 7;
  406. cp = 0;
  407. } else if (tuner_frequency < 195000000) {
  408. band = 1;
  409. mode = 6;
  410. cp = 1;
  411. /* mid band */
  412. } else if (tuner_frequency < 366000000) {
  413. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  414. band = 10;
  415. } else {
  416. band = 2;
  417. }
  418. mode = 7;
  419. cp = 0;
  420. } else if (tuner_frequency < 478000000) {
  421. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  422. band = 10;
  423. } else {
  424. band = 2;
  425. }
  426. mode = 6;
  427. cp = 1;
  428. /* high band */
  429. } else if (tuner_frequency < 662000000) {
  430. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  431. band = 12;
  432. } else {
  433. band = 4;
  434. }
  435. mode = 7;
  436. cp = 0;
  437. } else if (tuner_frequency < 840000000) {
  438. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  439. band = 12;
  440. } else {
  441. band = 4;
  442. }
  443. mode = 6;
  444. cp = 1;
  445. } else {
  446. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  447. band = 12;
  448. } else {
  449. band = 4;
  450. }
  451. mode = 7;
  452. cp = 1;
  453. }
  454. /* calculate divisor */
  455. /* ((36166000 + Finput) / 166666) rounded! */
  456. divider = (tuner_frequency + 83333) / 166667;
  457. /* setup tuner buffer */
  458. tuner_buf[0] = (divider >> 8) & 0x7f;
  459. tuner_buf[1] = divider & 0xff;
  460. tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
  461. tuner_buf[3] = 0x40 | band;
  462. if (fe->ops->i2c_gate_ctrl)
  463. fe->ops->i2c_gate_ctrl(fe, 1);
  464. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  465. return -EIO;
  466. return 0;
  467. }
  468. static struct tda1004x_config medion_cardbus = {
  469. .demod_address = 0x08,
  470. .invert = 1,
  471. .invert_oclk = 0,
  472. .xtal_freq = TDA10046_XTAL_16M,
  473. .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
  474. .if_freq = TDA10046_FREQ_3613,
  475. .request_firmware = NULL,
  476. };
  477. /* ------------------------------------------------------------------ */
  478. struct tda827x_data {
  479. u32 lomax;
  480. u8 spd;
  481. u8 bs;
  482. u8 bp;
  483. u8 cp;
  484. u8 gc3;
  485. u8 div1p5;
  486. };
  487. static struct tda827x_data tda827x_dvbt[] = {
  488. { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
  489. { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
  490. { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
  491. { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
  492. { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
  493. { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
  494. { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
  495. { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
  496. { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
  497. { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
  498. { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
  499. { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
  500. { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
  501. { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
  502. { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
  503. { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
  504. { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
  505. { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
  506. { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
  507. { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
  508. { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
  509. { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
  510. { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
  511. { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
  512. { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
  513. { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
  514. { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
  515. { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
  516. { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
  517. };
  518. static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
  519. {
  520. return 0;
  521. }
  522. static int philips_tda827x_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  523. {
  524. struct saa7134_dev *dev = fe->dvb->priv;
  525. u8 tuner_buf[14];
  526. struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
  527. .len = sizeof(tuner_buf) };
  528. int i, tuner_freq, if_freq;
  529. u32 N;
  530. switch (params->u.ofdm.bandwidth) {
  531. case BANDWIDTH_6_MHZ:
  532. if_freq = 4000000;
  533. break;
  534. case BANDWIDTH_7_MHZ:
  535. if_freq = 4500000;
  536. break;
  537. default: /* 8 MHz or Auto */
  538. if_freq = 5000000;
  539. break;
  540. }
  541. tuner_freq = params->frequency + if_freq;
  542. i = 0;
  543. while (tda827x_dvbt[i].lomax < tuner_freq) {
  544. if(tda827x_dvbt[i + 1].lomax == 0)
  545. break;
  546. i++;
  547. }
  548. N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
  549. tuner_buf[0] = 0;
  550. tuner_buf[1] = (N>>8) | 0x40;
  551. tuner_buf[2] = N & 0xff;
  552. tuner_buf[3] = 0;
  553. tuner_buf[4] = 0x52;
  554. tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
  555. (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
  556. tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
  557. tuner_buf[7] = 0xbf;
  558. tuner_buf[8] = 0x2a;
  559. tuner_buf[9] = 0x05;
  560. tuner_buf[10] = 0xff;
  561. tuner_buf[11] = 0x00;
  562. tuner_buf[12] = 0x00;
  563. tuner_buf[13] = 0x40;
  564. tuner_msg.len = 14;
  565. if (fe->ops->i2c_gate_ctrl)
  566. fe->ops->i2c_gate_ctrl(fe, 1);
  567. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  568. return -EIO;
  569. msleep(500);
  570. /* correct CP value */
  571. tuner_buf[0] = 0x30;
  572. tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
  573. tuner_msg.len = 2;
  574. if (fe->ops->i2c_gate_ctrl)
  575. fe->ops->i2c_gate_ctrl(fe, 1);
  576. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  577. return 0;
  578. }
  579. static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
  580. {
  581. struct saa7134_dev *dev = fe->dvb->priv;
  582. static u8 tda827x_sleep[] = { 0x30, 0xd0};
  583. struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
  584. .len = sizeof(tda827x_sleep) };
  585. if (fe->ops->i2c_gate_ctrl)
  586. fe->ops->i2c_gate_ctrl(fe, 1);
  587. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  588. return 0;
  589. }
  590. static struct tda1004x_config tda827x_lifeview_config = {
  591. .demod_address = 0x08,
  592. .invert = 1,
  593. .invert_oclk = 0,
  594. .xtal_freq = TDA10046_XTAL_16M,
  595. .agc_config = TDA10046_AGC_TDA827X,
  596. .if_freq = TDA10046_FREQ_045,
  597. .request_firmware = NULL,
  598. };
  599. /* ------------------------------------------------------------------ */
  600. struct tda827xa_data {
  601. u32 lomax;
  602. u8 svco;
  603. u8 spd;
  604. u8 scr;
  605. u8 sbs;
  606. u8 gc3;
  607. };
  608. static struct tda827xa_data tda827xa_dvbt[] = {
  609. { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
  610. { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
  611. { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
  612. { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
  613. { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
  614. { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
  615. { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
  616. { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
  617. { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
  618. { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
  619. { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
  620. { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
  621. { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
  622. { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
  623. { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
  624. { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
  625. { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
  626. { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
  627. { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
  628. { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
  629. { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
  630. { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
  631. { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
  632. { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
  633. { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
  634. { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
  635. { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}};
  636. static int philips_tda827xa_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  637. {
  638. struct saa7134_dev *dev = fe->dvb->priv;
  639. u8 tuner_buf[14];
  640. unsigned char reg2[2];
  641. struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = tuner_buf};
  642. int i, tuner_freq, if_freq;
  643. u32 N;
  644. switch (params->u.ofdm.bandwidth) {
  645. case BANDWIDTH_6_MHZ:
  646. if_freq = 4000000;
  647. break;
  648. case BANDWIDTH_7_MHZ:
  649. if_freq = 4500000;
  650. break;
  651. default: /* 8 MHz or Auto */
  652. if_freq = 5000000;
  653. break;
  654. }
  655. tuner_freq = params->frequency + if_freq;
  656. i = 0;
  657. while (tda827xa_dvbt[i].lomax < tuner_freq) {
  658. if(tda827xa_dvbt[i + 1].lomax == 0)
  659. break;
  660. i++;
  661. }
  662. N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
  663. tuner_buf[0] = 0; // subaddress
  664. tuner_buf[1] = N >> 8;
  665. tuner_buf[2] = N & 0xff;
  666. tuner_buf[3] = 0;
  667. tuner_buf[4] = 0x16;
  668. tuner_buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
  669. tda827xa_dvbt[i].sbs;
  670. tuner_buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
  671. tuner_buf[7] = 0x0c;
  672. tuner_buf[8] = 0x06;
  673. tuner_buf[9] = 0x24;
  674. tuner_buf[10] = 0xff;
  675. tuner_buf[11] = 0x60;
  676. tuner_buf[12] = 0x00;
  677. tuner_buf[13] = 0x39; // lpsel
  678. msg.len = 14;
  679. if (fe->ops->i2c_gate_ctrl)
  680. fe->ops->i2c_gate_ctrl(fe, 1);
  681. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
  682. return -EIO;
  683. msg.buf= reg2;
  684. msg.len = 2;
  685. reg2[0] = 0x60;
  686. reg2[1] = 0x3c;
  687. if (fe->ops->i2c_gate_ctrl)
  688. fe->ops->i2c_gate_ctrl(fe, 1);
  689. i2c_transfer(&dev->i2c_adap, &msg, 1);
  690. reg2[0] = 0xa0;
  691. reg2[1] = 0x40;
  692. if (fe->ops->i2c_gate_ctrl)
  693. fe->ops->i2c_gate_ctrl(fe, 1);
  694. i2c_transfer(&dev->i2c_adap, &msg, 1);
  695. msleep(2);
  696. /* correct CP value */
  697. reg2[0] = 0x30;
  698. reg2[1] = 0x10 + tda827xa_dvbt[i].scr;
  699. msg.len = 2;
  700. if (fe->ops->i2c_gate_ctrl)
  701. fe->ops->i2c_gate_ctrl(fe, 1);
  702. i2c_transfer(&dev->i2c_adap, &msg, 1);
  703. msleep(550);
  704. reg2[0] = 0x50;
  705. reg2[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
  706. if (fe->ops->i2c_gate_ctrl)
  707. fe->ops->i2c_gate_ctrl(fe, 1);
  708. i2c_transfer(&dev->i2c_adap, &msg, 1);
  709. return 0;
  710. }
  711. static int philips_tda827xa_tuner_sleep(u8 addr, struct dvb_frontend *fe)
  712. {
  713. struct saa7134_dev *dev = fe->dvb->priv;
  714. static u8 tda827xa_sleep[] = { 0x30, 0x90};
  715. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tda827xa_sleep,
  716. .len = sizeof(tda827xa_sleep) };
  717. if (fe->ops->i2c_gate_ctrl)
  718. fe->ops->i2c_gate_ctrl(fe, 1);
  719. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  720. return 0;
  721. }
  722. /* ------------------------------------------------------------------ */
  723. static int philips_tiger_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  724. {
  725. int ret;
  726. struct saa7134_dev *dev = fe->dvb->priv;
  727. static u8 tda8290_close[] = { 0x21, 0xc0};
  728. static u8 tda8290_open[] = { 0x21, 0x80};
  729. struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
  730. /* close tda8290 i2c bridge */
  731. tda8290_msg.buf = tda8290_close;
  732. ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
  733. if (ret != 1)
  734. return -EIO;
  735. msleep(20);
  736. ret = philips_tda827xa_pll_set(0x61, fe, params);
  737. if (ret != 0)
  738. return ret;
  739. /* open tda8290 i2c bridge */
  740. tda8290_msg.buf = tda8290_open;
  741. i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
  742. return ret;
  743. }
  744. static int philips_tiger_tuner_init(struct dvb_frontend *fe)
  745. {
  746. struct saa7134_dev *dev = fe->dvb->priv;
  747. static u8 data[] = { 0x3c, 0x33, 0x6a};
  748. struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
  749. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
  750. return -EIO;
  751. return 0;
  752. }
  753. static int philips_tiger_tuner_sleep(struct dvb_frontend *fe)
  754. {
  755. struct saa7134_dev *dev = fe->dvb->priv;
  756. static u8 data[] = { 0x3c, 0x33, 0x68};
  757. struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
  758. i2c_transfer(&dev->i2c_adap, &msg, 1);
  759. philips_tda827xa_tuner_sleep( 0x61, fe);
  760. return 0;
  761. }
  762. static struct tda1004x_config philips_tiger_config = {
  763. .demod_address = 0x08,
  764. .invert = 1,
  765. .invert_oclk = 0,
  766. .xtal_freq = TDA10046_XTAL_16M,
  767. .agc_config = TDA10046_AGC_TDA827X,
  768. .if_freq = TDA10046_FREQ_045,
  769. .request_firmware = NULL,
  770. };
  771. /* ------------------------------------------------------------------ */
  772. static int lifeview_trio_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  773. {
  774. int ret;
  775. ret = philips_tda827xa_pll_set(0x60, fe, params);
  776. return ret;
  777. }
  778. static int lifeview_trio_tuner_sleep(struct dvb_frontend *fe)
  779. {
  780. philips_tda827xa_tuner_sleep(0x60, fe);
  781. return 0;
  782. }
  783. static struct tda1004x_config lifeview_trio_config = {
  784. .demod_address = 0x09,
  785. .invert = 1,
  786. .invert_oclk = 0,
  787. .xtal_freq = TDA10046_XTAL_16M,
  788. .agc_config = TDA10046_AGC_TDA827X_GPL,
  789. .if_freq = TDA10046_FREQ_045,
  790. .request_firmware = NULL,
  791. };
  792. /* ------------------------------------------------------------------ */
  793. static int ads_duo_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  794. {
  795. int ret;
  796. ret = philips_tda827xa_pll_set(0x61, fe, params);
  797. return ret;
  798. }
  799. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  800. {
  801. struct saa7134_dev *dev = fe->dvb->priv;
  802. /* route TDA8275a AGC input to the channel decoder */
  803. saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x60);
  804. return 0;
  805. }
  806. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  807. {
  808. struct saa7134_dev *dev = fe->dvb->priv;
  809. /* route TDA8275a AGC input to the analog IF chip*/
  810. saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x20);
  811. philips_tda827xa_tuner_sleep( 0x61, fe);
  812. return 0;
  813. }
  814. static struct tda1004x_config ads_tech_duo_config = {
  815. .demod_address = 0x08,
  816. .invert = 1,
  817. .invert_oclk = 0,
  818. .xtal_freq = TDA10046_XTAL_16M,
  819. .agc_config = TDA10046_AGC_TDA827X_GPL,
  820. .if_freq = TDA10046_FREQ_045,
  821. .request_firmware = NULL,
  822. };
  823. /* ------------------------------------------------------------------ */
  824. static int tevion_dvb220rf_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  825. {
  826. int ret;
  827. ret = philips_tda827xa_pll_set(0x60, fe, params);
  828. return ret;
  829. }
  830. static int tevion_dvb220rf_tuner_sleep(struct dvb_frontend *fe)
  831. {
  832. philips_tda827xa_tuner_sleep( 0x61, fe);
  833. return 0;
  834. }
  835. static struct tda1004x_config tevion_dvbt220rf_config = {
  836. .demod_address = 0x08,
  837. .invert = 1,
  838. .invert_oclk = 0,
  839. .xtal_freq = TDA10046_XTAL_16M,
  840. .agc_config = TDA10046_AGC_TDA827X,
  841. .if_freq = TDA10046_FREQ_045,
  842. .request_firmware = NULL,
  843. };
  844. #endif
  845. /* ------------------------------------------------------------------ */
  846. #ifdef HAVE_NXT200X
  847. static struct nxt200x_config avertvhda180 = {
  848. .demod_address = 0x0a,
  849. };
  850. static int nxt200x_set_pll_input(u8 *buf, int input)
  851. {
  852. if (input)
  853. buf[3] |= 0x08;
  854. else
  855. buf[3] &= ~0x08;
  856. return 0;
  857. }
  858. static struct nxt200x_config kworldatsc110 = {
  859. .demod_address = 0x0a,
  860. .set_pll_input = nxt200x_set_pll_input,
  861. };
  862. #endif
  863. /* ------------------------------------------------------------------ */
  864. static int dvb_init(struct saa7134_dev *dev)
  865. {
  866. /* init struct videobuf_dvb */
  867. dev->ts.nr_bufs = 32;
  868. dev->ts.nr_packets = 32*4;
  869. dev->dvb.name = dev->name;
  870. videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
  871. dev->pci, &dev->slock,
  872. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  873. V4L2_FIELD_ALTERNATE,
  874. sizeof(struct saa7134_buf),
  875. dev);
  876. switch (dev->board) {
  877. #ifdef HAVE_MT352
  878. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  879. printk("%s: pinnacle 300i dvb setup\n",dev->name);
  880. dev->dvb.frontend = mt352_attach(&pinnacle_300i,
  881. &dev->i2c_adap);
  882. dev->dvb.frontend->ops->tuner_ops.pllbuf = mt352_pinnacle_tuner_pllbuf;
  883. break;
  884. case SAA7134_BOARD_AVERMEDIA_777:
  885. printk("%s: avertv 777 dvb setup\n",dev->name);
  886. dev->dvb.frontend = mt352_attach(&avermedia_777,
  887. &dev->i2c_adap);
  888. dev->dvb.frontend->ops->tuner_ops.pllbuf = mt352_aver777_tuner_pllbuf;
  889. break;
  890. #endif
  891. #ifdef HAVE_TDA1004X
  892. case SAA7134_BOARD_MD7134:
  893. dev->dvb.frontend = tda10046_attach(&medion_cardbus,
  894. &dev->i2c_adap);
  895. dev->dvb.frontend->ops->tuner_ops.init = philips_fmd1216_tuner_init;
  896. dev->dvb.frontend->ops->tuner_ops.sleep = philips_fmd1216_tuner_sleep;
  897. dev->dvb.frontend->ops->tuner_ops.set_params = philips_fmd1216_tuner_set_params;
  898. break;
  899. case SAA7134_BOARD_PHILIPS_TOUGH:
  900. dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config,
  901. &dev->i2c_adap);
  902. dev->dvb.frontend->ops->tuner_ops.init = philips_tu1216_tuner_60_init;
  903. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tu1216_tuner_60_set_params;
  904. break;
  905. case SAA7134_BOARD_FLYDVBTDUO:
  906. dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
  907. &dev->i2c_adap);
  908. dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
  909. dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
  910. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
  911. break;
  912. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  913. dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
  914. &dev->i2c_adap);
  915. dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
  916. dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
  917. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
  918. break;
  919. case SAA7134_BOARD_PHILIPS_EUROPA:
  920. dev->dvb.frontend = tda10046_attach(&philips_europa_config,
  921. &dev->i2c_adap);
  922. dev->original_demod_sleep = dev->dvb.frontend->ops->sleep;
  923. dev->dvb.frontend->ops->sleep = philips_europa_demod_sleep;
  924. dev->dvb.frontend->ops->tuner_ops.init = philips_europa_tuner_init;
  925. dev->dvb.frontend->ops->tuner_ops.sleep = philips_europa_tuner_sleep;
  926. dev->dvb.frontend->ops->tuner_ops.set_params = philips_td1316_tuner_set_params;
  927. break;
  928. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  929. dev->dvb.frontend = tda10046_attach(&philips_europa_config,
  930. &dev->i2c_adap);
  931. dev->dvb.frontend->ops->tuner_ops.init = philips_europa_tuner_init;
  932. dev->dvb.frontend->ops->tuner_ops.sleep = philips_europa_tuner_sleep;
  933. dev->dvb.frontend->ops->tuner_ops.set_params = philips_td1316_tuner_set_params;
  934. break;
  935. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  936. dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config,
  937. &dev->i2c_adap);
  938. dev->dvb.frontend->ops->tuner_ops.init = philips_tu1216_tuner_61_init;
  939. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tu1216_tuner_61_set_params;
  940. break;
  941. case SAA7134_BOARD_PHILIPS_TIGER:
  942. dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
  943. &dev->i2c_adap);
  944. dev->dvb.frontend->ops->tuner_ops.init = philips_tiger_tuner_init;
  945. dev->dvb.frontend->ops->tuner_ops.sleep = philips_tiger_tuner_sleep;
  946. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tiger_tuner_set_params;
  947. break;
  948. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  949. dev->dvb.frontend = tda10046_attach(&philips_tiger_config,
  950. &dev->i2c_adap);
  951. dev->dvb.frontend->ops->tuner_ops.init = philips_tiger_tuner_init;
  952. dev->dvb.frontend->ops->tuner_ops.sleep = philips_tiger_tuner_sleep;
  953. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tiger_tuner_set_params;
  954. break;
  955. case SAA7134_BOARD_FLYDVBT_LR301:
  956. dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
  957. &dev->i2c_adap);
  958. dev->dvb.frontend->ops->tuner_ops.init = philips_tda827x_tuner_init;
  959. dev->dvb.frontend->ops->tuner_ops.sleep = philips_tda827x_tuner_sleep;
  960. dev->dvb.frontend->ops->tuner_ops.set_params = philips_tda827x_tuner_set_params;
  961. break;
  962. case SAA7134_BOARD_FLYDVB_TRIO:
  963. dev->dvb.frontend = tda10046_attach(&lifeview_trio_config,
  964. &dev->i2c_adap);
  965. dev->dvb.frontend->ops->tuner_ops.sleep = lifeview_trio_tuner_sleep;
  966. dev->dvb.frontend->ops->tuner_ops.set_params = lifeview_trio_tuner_set_params;
  967. break;
  968. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  969. dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
  970. &dev->i2c_adap);
  971. dev->dvb.frontend->ops->tuner_ops.init = ads_duo_tuner_init;
  972. dev->dvb.frontend->ops->tuner_ops.sleep = ads_duo_tuner_sleep;
  973. dev->dvb.frontend->ops->tuner_ops.set_params = ads_duo_tuner_set_params;
  974. break;
  975. case SAA7134_BOARD_TEVION_DVBT_220RF:
  976. dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
  977. &dev->i2c_adap);
  978. dev->dvb.frontend->ops->tuner_ops.sleep = tevion_dvb220rf_tuner_sleep;
  979. dev->dvb.frontend->ops->tuner_ops.set_params = tevion_dvb220rf_tuner_set_params;
  980. break;
  981. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  982. dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
  983. &dev->i2c_adap);
  984. dev->dvb.frontend->ops->tuner_ops.init = ads_duo_tuner_init;
  985. dev->dvb.frontend->ops->tuner_ops.sleep = ads_duo_tuner_sleep;
  986. dev->dvb.frontend->ops->tuner_ops.set_params = ads_duo_tuner_set_params;
  987. break;
  988. #endif
  989. #ifdef HAVE_NXT200X
  990. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  991. dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap);
  992. if (dev->dvb.frontend) {
  993. dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tdhu2);
  994. }
  995. break;
  996. case SAA7134_BOARD_KWORLD_ATSC110:
  997. dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap);
  998. if (dev->dvb.frontend) {
  999. dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tuv1236d);
  1000. }
  1001. break;
  1002. #endif
  1003. default:
  1004. printk("%s: Huh? unknown DVB card?\n",dev->name);
  1005. break;
  1006. }
  1007. if (NULL == dev->dvb.frontend) {
  1008. printk("%s: frontend initialization failed\n",dev->name);
  1009. return -1;
  1010. }
  1011. /* register everything else */
  1012. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
  1013. }
  1014. static int dvb_fini(struct saa7134_dev *dev)
  1015. {
  1016. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1017. switch (dev->board) {
  1018. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  1019. /* otherwise we don't detect the tuner on next insmod */
  1020. saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
  1021. break;
  1022. };
  1023. videobuf_dvb_unregister(&dev->dvb);
  1024. return 0;
  1025. }
  1026. static struct saa7134_mpeg_ops dvb_ops = {
  1027. .type = SAA7134_MPEG_DVB,
  1028. .init = dvb_init,
  1029. .fini = dvb_fini,
  1030. };
  1031. static int __init dvb_register(void)
  1032. {
  1033. return saa7134_ts_register(&dvb_ops);
  1034. }
  1035. static void __exit dvb_unregister(void)
  1036. {
  1037. saa7134_ts_unregister(&dvb_ops);
  1038. }
  1039. module_init(dvb_register);
  1040. module_exit(dvb_unregister);
  1041. /* ------------------------------------------------------------------ */
  1042. /*
  1043. * Local variables:
  1044. * c-basic-offset: 8
  1045. * End:
  1046. */