saa7134-dvb.c 41 KB

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