saa7134-dvb.c 40 KB

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