saa7134-dvb.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  1. /*
  2. *
  3. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  4. *
  5. * Extended 3 / 2005 by Hartmut Hackmann to support various
  6. * cards with the tda10046 DVB-T channel decoder
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/slab.h>
  27. #include <linux/delay.h>
  28. #include <linux/kthread.h>
  29. #include <linux/suspend.h>
  30. #include "saa7134-reg.h"
  31. #include "saa7134.h"
  32. #include <media/v4l2-common.h>
  33. #include "dvb-pll.h"
  34. #include <dvb_frontend.h>
  35. #include "mt352.h"
  36. #include "mt352_priv.h" /* FIXME */
  37. #include "tda1004x.h"
  38. #include "nxt200x.h"
  39. #include "tuner-xc2028.h"
  40. #include "tda10086.h"
  41. #include "tda826x.h"
  42. #include "tda827x.h"
  43. #include "isl6421.h"
  44. #include "isl6405.h"
  45. #include "lnbp21.h"
  46. #include "tuner-simple.h"
  47. #include "zl10353.h"
  48. #include "zl10036.h"
  49. #include "mt312.h"
  50. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  51. MODULE_LICENSE("GPL");
  52. static unsigned int antenna_pwr;
  53. module_param(antenna_pwr, int, 0444);
  54. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  55. static int use_frontend;
  56. module_param(use_frontend, int, 0644);
  57. MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
  58. static int debug;
  59. module_param(debug, int, 0644);
  60. MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
  61. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  62. #define dprintk(fmt, arg...) do { if (debug) \
  63. printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
  64. /* Print a warning */
  65. #define wprintk(fmt, arg...) \
  66. printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
  67. /* ------------------------------------------------------------------
  68. * mt352 based DVB-T cards
  69. */
  70. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  71. {
  72. u32 ok;
  73. if (!on) {
  74. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  75. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  76. return 0;
  77. }
  78. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  79. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  80. udelay(10);
  81. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  82. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  83. udelay(10);
  84. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  85. udelay(10);
  86. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  87. dprintk("%s %s\n", __func__, ok ? "on" : "off");
  88. if (!ok)
  89. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  90. return ok;
  91. }
  92. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  93. {
  94. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  95. static u8 reset [] = { RESET, 0x80 };
  96. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  97. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  98. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  99. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  100. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  101. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  102. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  103. struct saa7134_dev *dev= fe->dvb->priv;
  104. dprintk("%s called\n", __func__);
  105. mt352_write(fe, clock_config, sizeof(clock_config));
  106. udelay(200);
  107. mt352_write(fe, reset, sizeof(reset));
  108. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  109. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  110. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  111. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  112. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  113. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  114. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  115. return 0;
  116. }
  117. static int mt352_aver777_init(struct dvb_frontend* fe)
  118. {
  119. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  120. static u8 reset [] = { RESET, 0x80 };
  121. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  122. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  123. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  124. mt352_write(fe, clock_config, sizeof(clock_config));
  125. udelay(200);
  126. mt352_write(fe, reset, sizeof(reset));
  127. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  128. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  129. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  130. return 0;
  131. }
  132. static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
  133. {
  134. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  135. static u8 reset [] = { RESET, 0x80 };
  136. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  137. static u8 agc_cfg [] = { AGC_TARGET, 0xe };
  138. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  139. mt352_write(fe, clock_config, sizeof(clock_config));
  140. udelay(200);
  141. mt352_write(fe, reset, sizeof(reset));
  142. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  143. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  144. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  145. return 0;
  146. }
  147. static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
  148. struct dvb_frontend_parameters* params)
  149. {
  150. u8 off[] = { 0x00, 0xf1};
  151. u8 on[] = { 0x00, 0x71};
  152. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  153. struct saa7134_dev *dev = fe->dvb->priv;
  154. struct v4l2_frequency f;
  155. /* set frequency (mt2050) */
  156. f.tuner = 0;
  157. f.type = V4L2_TUNER_DIGITAL_TV;
  158. f.frequency = params->frequency / 1000 * 16 / 1000;
  159. if (fe->ops.i2c_gate_ctrl)
  160. fe->ops.i2c_gate_ctrl(fe, 1);
  161. i2c_transfer(&dev->i2c_adap, &msg, 1);
  162. saa_call_all(dev, tuner, s_frequency, &f);
  163. msg.buf = on;
  164. if (fe->ops.i2c_gate_ctrl)
  165. fe->ops.i2c_gate_ctrl(fe, 1);
  166. i2c_transfer(&dev->i2c_adap, &msg, 1);
  167. pinnacle_antenna_pwr(dev, antenna_pwr);
  168. /* mt352 setup */
  169. return mt352_pinnacle_init(fe);
  170. }
  171. static struct mt352_config pinnacle_300i = {
  172. .demod_address = 0x3c >> 1,
  173. .adc_clock = 20333,
  174. .if2 = 36150,
  175. .no_tuner = 1,
  176. .demod_init = mt352_pinnacle_init,
  177. };
  178. static struct mt352_config avermedia_777 = {
  179. .demod_address = 0xf,
  180. .demod_init = mt352_aver777_init,
  181. };
  182. static struct mt352_config avermedia_xc3028_mt352_dev = {
  183. .demod_address = (0x1e >> 1),
  184. .no_tuner = 1,
  185. .demod_init = mt352_avermedia_xc3028_init,
  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. struct videobuf_dvb_frontend *fe0;
  458. /* Get the first frontend */
  459. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  460. fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
  461. if (fe0->dvb.frontend) {
  462. if (cdec_conf->i2c_gate)
  463. fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  464. if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
  465. cdec_conf->tuner_address,
  466. &dev->i2c_adap, tuner_conf))
  467. return 0;
  468. wprintk("no tda827x tuner found at addr: %02x\n",
  469. cdec_conf->tuner_address);
  470. }
  471. return -EINVAL;
  472. }
  473. /* ------------------------------------------------------------------ */
  474. static struct tda827x_config tda827x_cfg_0 = {
  475. .init = philips_tda827x_tuner_init,
  476. .sleep = philips_tda827x_tuner_sleep,
  477. .config = 0,
  478. .switch_addr = 0
  479. };
  480. static struct tda827x_config tda827x_cfg_1 = {
  481. .init = philips_tda827x_tuner_init,
  482. .sleep = philips_tda827x_tuner_sleep,
  483. .config = 1,
  484. .switch_addr = 0x4b
  485. };
  486. static struct tda827x_config tda827x_cfg_2 = {
  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. .init = philips_tda827x_tuner_init,
  494. .sleep = philips_tda827x_tuner_sleep,
  495. .config = 2,
  496. .switch_addr = 0x42
  497. };
  498. /* ------------------------------------------------------------------ */
  499. static struct tda1004x_config tda827x_lifeview_config = {
  500. .demod_address = 0x08,
  501. .invert = 1,
  502. .invert_oclk = 0,
  503. .xtal_freq = TDA10046_XTAL_16M,
  504. .agc_config = TDA10046_AGC_TDA827X,
  505. .gpio_config = TDA10046_GP11_I,
  506. .if_freq = TDA10046_FREQ_045,
  507. .tuner_address = 0x60,
  508. .request_firmware = philips_tda1004x_request_firmware
  509. };
  510. static struct tda1004x_config philips_tiger_config = {
  511. .demod_address = 0x08,
  512. .invert = 1,
  513. .invert_oclk = 0,
  514. .xtal_freq = TDA10046_XTAL_16M,
  515. .agc_config = TDA10046_AGC_TDA827X,
  516. .gpio_config = TDA10046_GP11_I,
  517. .if_freq = TDA10046_FREQ_045,
  518. .i2c_gate = 0x4b,
  519. .tuner_address = 0x61,
  520. .antenna_switch= 1,
  521. .request_firmware = philips_tda1004x_request_firmware
  522. };
  523. static struct tda1004x_config cinergy_ht_config = {
  524. .demod_address = 0x08,
  525. .invert = 1,
  526. .invert_oclk = 0,
  527. .xtal_freq = TDA10046_XTAL_16M,
  528. .agc_config = TDA10046_AGC_TDA827X,
  529. .gpio_config = TDA10046_GP01_I,
  530. .if_freq = TDA10046_FREQ_045,
  531. .i2c_gate = 0x4b,
  532. .tuner_address = 0x61,
  533. .request_firmware = philips_tda1004x_request_firmware
  534. };
  535. static struct tda1004x_config cinergy_ht_pci_config = {
  536. .demod_address = 0x08,
  537. .invert = 1,
  538. .invert_oclk = 0,
  539. .xtal_freq = TDA10046_XTAL_16M,
  540. .agc_config = TDA10046_AGC_TDA827X,
  541. .gpio_config = TDA10046_GP01_I,
  542. .if_freq = TDA10046_FREQ_045,
  543. .i2c_gate = 0x4b,
  544. .tuner_address = 0x60,
  545. .request_firmware = philips_tda1004x_request_firmware
  546. };
  547. static struct tda1004x_config philips_tiger_s_config = {
  548. .demod_address = 0x08,
  549. .invert = 1,
  550. .invert_oclk = 0,
  551. .xtal_freq = TDA10046_XTAL_16M,
  552. .agc_config = TDA10046_AGC_TDA827X,
  553. .gpio_config = TDA10046_GP01_I,
  554. .if_freq = TDA10046_FREQ_045,
  555. .i2c_gate = 0x4b,
  556. .tuner_address = 0x61,
  557. .antenna_switch= 1,
  558. .request_firmware = philips_tda1004x_request_firmware
  559. };
  560. static struct tda1004x_config pinnacle_pctv_310i_config = {
  561. .demod_address = 0x08,
  562. .invert = 1,
  563. .invert_oclk = 0,
  564. .xtal_freq = TDA10046_XTAL_16M,
  565. .agc_config = TDA10046_AGC_TDA827X,
  566. .gpio_config = TDA10046_GP11_I,
  567. .if_freq = TDA10046_FREQ_045,
  568. .i2c_gate = 0x4b,
  569. .tuner_address = 0x61,
  570. .request_firmware = philips_tda1004x_request_firmware
  571. };
  572. static struct tda1004x_config hauppauge_hvr_1110_config = {
  573. .demod_address = 0x08,
  574. .invert = 1,
  575. .invert_oclk = 0,
  576. .xtal_freq = TDA10046_XTAL_16M,
  577. .agc_config = TDA10046_AGC_TDA827X,
  578. .gpio_config = TDA10046_GP11_I,
  579. .if_freq = TDA10046_FREQ_045,
  580. .i2c_gate = 0x4b,
  581. .tuner_address = 0x61,
  582. .request_firmware = philips_tda1004x_request_firmware
  583. };
  584. static struct tda1004x_config asus_p7131_dual_config = {
  585. .demod_address = 0x08,
  586. .invert = 1,
  587. .invert_oclk = 0,
  588. .xtal_freq = TDA10046_XTAL_16M,
  589. .agc_config = TDA10046_AGC_TDA827X,
  590. .gpio_config = TDA10046_GP11_I,
  591. .if_freq = TDA10046_FREQ_045,
  592. .i2c_gate = 0x4b,
  593. .tuner_address = 0x61,
  594. .antenna_switch= 2,
  595. .request_firmware = philips_tda1004x_request_firmware
  596. };
  597. static struct tda1004x_config lifeview_trio_config = {
  598. .demod_address = 0x09,
  599. .invert = 1,
  600. .invert_oclk = 0,
  601. .xtal_freq = TDA10046_XTAL_16M,
  602. .agc_config = TDA10046_AGC_TDA827X,
  603. .gpio_config = TDA10046_GP00_I,
  604. .if_freq = TDA10046_FREQ_045,
  605. .tuner_address = 0x60,
  606. .request_firmware = philips_tda1004x_request_firmware
  607. };
  608. static struct tda1004x_config tevion_dvbt220rf_config = {
  609. .demod_address = 0x08,
  610. .invert = 1,
  611. .invert_oclk = 0,
  612. .xtal_freq = TDA10046_XTAL_16M,
  613. .agc_config = TDA10046_AGC_TDA827X,
  614. .gpio_config = TDA10046_GP11_I,
  615. .if_freq = TDA10046_FREQ_045,
  616. .tuner_address = 0x60,
  617. .request_firmware = philips_tda1004x_request_firmware
  618. };
  619. static struct tda1004x_config md8800_dvbt_config = {
  620. .demod_address = 0x08,
  621. .invert = 1,
  622. .invert_oclk = 0,
  623. .xtal_freq = TDA10046_XTAL_16M,
  624. .agc_config = TDA10046_AGC_TDA827X,
  625. .gpio_config = TDA10046_GP01_I,
  626. .if_freq = TDA10046_FREQ_045,
  627. .i2c_gate = 0x4b,
  628. .tuner_address = 0x60,
  629. .request_firmware = philips_tda1004x_request_firmware
  630. };
  631. static struct tda1004x_config asus_p7131_4871_config = {
  632. .demod_address = 0x08,
  633. .invert = 1,
  634. .invert_oclk = 0,
  635. .xtal_freq = TDA10046_XTAL_16M,
  636. .agc_config = TDA10046_AGC_TDA827X,
  637. .gpio_config = TDA10046_GP01_I,
  638. .if_freq = TDA10046_FREQ_045,
  639. .i2c_gate = 0x4b,
  640. .tuner_address = 0x61,
  641. .antenna_switch= 2,
  642. .request_firmware = philips_tda1004x_request_firmware
  643. };
  644. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  645. .demod_address = 0x08,
  646. .invert = 1,
  647. .invert_oclk = 0,
  648. .xtal_freq = TDA10046_XTAL_16M,
  649. .agc_config = TDA10046_AGC_TDA827X,
  650. .gpio_config = TDA10046_GP11_I,
  651. .if_freq = TDA10046_FREQ_045,
  652. .i2c_gate = 0x4b,
  653. .tuner_address = 0x61,
  654. .antenna_switch= 2,
  655. .request_firmware = philips_tda1004x_request_firmware
  656. };
  657. static struct tda1004x_config kworld_dvb_t_210_config = {
  658. .demod_address = 0x08,
  659. .invert = 1,
  660. .invert_oclk = 0,
  661. .xtal_freq = TDA10046_XTAL_16M,
  662. .agc_config = TDA10046_AGC_TDA827X,
  663. .gpio_config = TDA10046_GP11_I,
  664. .if_freq = TDA10046_FREQ_045,
  665. .i2c_gate = 0x4b,
  666. .tuner_address = 0x61,
  667. .antenna_switch= 1,
  668. .request_firmware = philips_tda1004x_request_firmware
  669. };
  670. static struct tda1004x_config avermedia_super_007_config = {
  671. .demod_address = 0x08,
  672. .invert = 1,
  673. .invert_oclk = 0,
  674. .xtal_freq = TDA10046_XTAL_16M,
  675. .agc_config = TDA10046_AGC_TDA827X,
  676. .gpio_config = TDA10046_GP01_I,
  677. .if_freq = TDA10046_FREQ_045,
  678. .i2c_gate = 0x4b,
  679. .tuner_address = 0x60,
  680. .antenna_switch= 1,
  681. .request_firmware = philips_tda1004x_request_firmware
  682. };
  683. static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
  684. .demod_address = 0x08,
  685. .invert = 1,
  686. .invert_oclk = 0,
  687. .xtal_freq = TDA10046_XTAL_16M,
  688. .agc_config = TDA10046_AGC_TDA827X,
  689. .gpio_config = TDA10046_GP01_I,
  690. .if_freq = TDA10046_FREQ_045,
  691. .i2c_gate = 0x42,
  692. .tuner_address = 0x61,
  693. .antenna_switch = 1,
  694. .request_firmware = philips_tda1004x_request_firmware
  695. };
  696. static struct tda1004x_config asus_tiger_3in1_config = {
  697. .demod_address = 0x0b,
  698. .invert = 1,
  699. .invert_oclk = 0,
  700. .xtal_freq = TDA10046_XTAL_16M,
  701. .agc_config = TDA10046_AGC_TDA827X,
  702. .gpio_config = TDA10046_GP11_I,
  703. .if_freq = TDA10046_FREQ_045,
  704. .i2c_gate = 0x4b,
  705. .tuner_address = 0x61,
  706. .antenna_switch = 1,
  707. .request_firmware = philips_tda1004x_request_firmware
  708. };
  709. /* ------------------------------------------------------------------
  710. * special case: this card uses saa713x GPIO22 for the mode switch
  711. */
  712. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  713. {
  714. struct saa7134_dev *dev = fe->dvb->priv;
  715. philips_tda827x_tuner_init(fe);
  716. /* route TDA8275a AGC input to the channel decoder */
  717. saa7134_set_gpio(dev, 22, 1);
  718. return 0;
  719. }
  720. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  721. {
  722. struct saa7134_dev *dev = fe->dvb->priv;
  723. /* route TDA8275a AGC input to the analog IF chip*/
  724. saa7134_set_gpio(dev, 22, 0);
  725. philips_tda827x_tuner_sleep(fe);
  726. return 0;
  727. }
  728. static struct tda827x_config ads_duo_cfg = {
  729. .init = ads_duo_tuner_init,
  730. .sleep = ads_duo_tuner_sleep,
  731. .config = 0
  732. };
  733. static struct tda1004x_config ads_tech_duo_config = {
  734. .demod_address = 0x08,
  735. .invert = 1,
  736. .invert_oclk = 0,
  737. .xtal_freq = TDA10046_XTAL_16M,
  738. .agc_config = TDA10046_AGC_TDA827X,
  739. .gpio_config = TDA10046_GP00_I,
  740. .if_freq = TDA10046_FREQ_045,
  741. .tuner_address = 0x61,
  742. .request_firmware = philips_tda1004x_request_firmware
  743. };
  744. static struct zl10353_config behold_h6_config = {
  745. .demod_address = 0x1e>>1,
  746. .no_tuner = 1,
  747. .parallel_ts = 1,
  748. .disable_i2c_gate_ctrl = 1,
  749. };
  750. /* ==================================================================
  751. * tda10086 based DVB-S cards, helper functions
  752. */
  753. static struct tda10086_config flydvbs = {
  754. .demod_address = 0x0e,
  755. .invert = 0,
  756. .diseqc_tone = 0,
  757. .xtal_freq = TDA10086_XTAL_16M,
  758. };
  759. static struct tda10086_config sd1878_4m = {
  760. .demod_address = 0x0e,
  761. .invert = 0,
  762. .diseqc_tone = 0,
  763. .xtal_freq = TDA10086_XTAL_4M,
  764. };
  765. /* ------------------------------------------------------------------
  766. * special case: lnb supply is connected to the gated i2c
  767. */
  768. static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  769. {
  770. int res = -EIO;
  771. struct saa7134_dev *dev = fe->dvb->priv;
  772. if (fe->ops.i2c_gate_ctrl) {
  773. fe->ops.i2c_gate_ctrl(fe, 1);
  774. if (dev->original_set_voltage)
  775. res = dev->original_set_voltage(fe, voltage);
  776. fe->ops.i2c_gate_ctrl(fe, 0);
  777. }
  778. return res;
  779. };
  780. static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
  781. {
  782. int res = -EIO;
  783. struct saa7134_dev *dev = fe->dvb->priv;
  784. if (fe->ops.i2c_gate_ctrl) {
  785. fe->ops.i2c_gate_ctrl(fe, 1);
  786. if (dev->original_set_high_voltage)
  787. res = dev->original_set_high_voltage(fe, arg);
  788. fe->ops.i2c_gate_ctrl(fe, 0);
  789. }
  790. return res;
  791. };
  792. static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  793. {
  794. struct saa7134_dev *dev = fe->dvb->priv;
  795. u8 wbuf[2] = { 0x1f, 00 };
  796. u8 rbuf;
  797. struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
  798. { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
  799. if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
  800. return -EIO;
  801. /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
  802. if (voltage == SEC_VOLTAGE_18)
  803. wbuf[1] = rbuf | 0x10;
  804. else
  805. wbuf[1] = rbuf & 0xef;
  806. msg[0].len = 2;
  807. i2c_transfer(&dev->i2c_adap, msg, 1);
  808. return 0;
  809. }
  810. static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
  811. {
  812. struct saa7134_dev *dev = fe->dvb->priv;
  813. wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
  814. return -EIO;
  815. }
  816. /* ==================================================================
  817. * nxt200x based ATSC cards, helper functions
  818. */
  819. static struct nxt200x_config avertvhda180 = {
  820. .demod_address = 0x0a,
  821. };
  822. static struct nxt200x_config kworldatsc110 = {
  823. .demod_address = 0x0a,
  824. };
  825. /* ------------------------------------------------------------------ */
  826. static struct mt312_config avertv_a700_mt312 = {
  827. .demod_address = 0x0e,
  828. .voltage_inverted = 1,
  829. };
  830. static struct zl10036_config avertv_a700_tuner = {
  831. .tuner_address = 0x60,
  832. };
  833. /* ==================================================================
  834. * Core code
  835. */
  836. static int dvb_init(struct saa7134_dev *dev)
  837. {
  838. int ret;
  839. int attach_xc3028 = 0;
  840. struct videobuf_dvb_frontend *fe0;
  841. /* FIXME: add support for multi-frontend */
  842. mutex_init(&dev->frontends.lock);
  843. INIT_LIST_HEAD(&dev->frontends.felist);
  844. printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
  845. fe0 = videobuf_dvb_alloc_frontend(&dev->frontends, 1);
  846. if (!fe0) {
  847. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  848. return -ENOMEM;
  849. }
  850. /* init struct videobuf_dvb */
  851. dev->ts.nr_bufs = 32;
  852. dev->ts.nr_packets = 32*4;
  853. fe0->dvb.name = dev->name;
  854. videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
  855. &dev->pci->dev, &dev->slock,
  856. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  857. V4L2_FIELD_ALTERNATE,
  858. sizeof(struct saa7134_buf),
  859. dev);
  860. switch (dev->board) {
  861. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  862. dprintk("pinnacle 300i dvb setup\n");
  863. fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  864. &dev->i2c_adap);
  865. if (fe0->dvb.frontend) {
  866. fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  867. }
  868. break;
  869. case SAA7134_BOARD_AVERMEDIA_777:
  870. case SAA7134_BOARD_AVERMEDIA_A16AR:
  871. dprintk("avertv 777 dvb setup\n");
  872. fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  873. &dev->i2c_adap);
  874. if (fe0->dvb.frontend) {
  875. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  876. &dev->i2c_adap, 0x61,
  877. TUNER_PHILIPS_TD1316);
  878. }
  879. break;
  880. case SAA7134_BOARD_AVERMEDIA_A16D:
  881. dprintk("AverMedia A16D dvb setup\n");
  882. fe0->dvb.frontend = dvb_attach(mt352_attach,
  883. &avermedia_xc3028_mt352_dev,
  884. &dev->i2c_adap);
  885. attach_xc3028 = 1;
  886. break;
  887. case SAA7134_BOARD_MD7134:
  888. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  889. &medion_cardbus,
  890. &dev->i2c_adap);
  891. if (fe0->dvb.frontend) {
  892. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  893. &dev->i2c_adap, medion_cardbus.tuner_address,
  894. TUNER_PHILIPS_FMD1216ME_MK3);
  895. }
  896. break;
  897. case SAA7134_BOARD_PHILIPS_TOUGH:
  898. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  899. &philips_tu1216_60_config,
  900. &dev->i2c_adap);
  901. if (fe0->dvb.frontend) {
  902. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  903. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  904. }
  905. break;
  906. case SAA7134_BOARD_FLYDVBTDUO:
  907. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  908. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  909. &tda827x_cfg_0) < 0)
  910. goto dettach_frontend;
  911. break;
  912. case SAA7134_BOARD_PHILIPS_EUROPA:
  913. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  914. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  915. &philips_europa_config,
  916. &dev->i2c_adap);
  917. if (fe0->dvb.frontend) {
  918. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  919. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  920. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  921. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  922. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  923. }
  924. break;
  925. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  926. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  927. &philips_tu1216_61_config,
  928. &dev->i2c_adap);
  929. if (fe0->dvb.frontend) {
  930. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  931. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  932. }
  933. break;
  934. case SAA7134_BOARD_KWORLD_DVBT_210:
  935. if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
  936. &tda827x_cfg_2) < 0)
  937. goto dettach_frontend;
  938. break;
  939. case SAA7134_BOARD_PHILIPS_TIGER:
  940. if (configure_tda827x_fe(dev, &philips_tiger_config,
  941. &tda827x_cfg_0) < 0)
  942. goto dettach_frontend;
  943. break;
  944. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  945. if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
  946. &tda827x_cfg_1) < 0)
  947. goto dettach_frontend;
  948. break;
  949. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  950. if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
  951. &tda827x_cfg_1) < 0)
  952. goto dettach_frontend;
  953. break;
  954. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  955. if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
  956. &tda827x_cfg_0) < 0)
  957. goto dettach_frontend;
  958. break;
  959. case SAA7134_BOARD_FLYDVBT_LR301:
  960. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  961. &tda827x_cfg_0) < 0)
  962. goto dettach_frontend;
  963. break;
  964. case SAA7134_BOARD_FLYDVB_TRIO:
  965. if (!use_frontend) { /* terrestrial */
  966. if (configure_tda827x_fe(dev, &lifeview_trio_config,
  967. &tda827x_cfg_0) < 0)
  968. goto dettach_frontend;
  969. } else { /* satellite */
  970. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  971. if (fe0->dvb.frontend) {
  972. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
  973. &dev->i2c_adap, 0) == NULL) {
  974. wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
  975. goto dettach_frontend;
  976. }
  977. if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
  978. 0x08, 0, 0) == NULL) {
  979. wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
  980. goto dettach_frontend;
  981. }
  982. }
  983. }
  984. break;
  985. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  986. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  987. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  988. &ads_tech_duo_config,
  989. &dev->i2c_adap);
  990. if (fe0->dvb.frontend) {
  991. if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
  992. ads_tech_duo_config.tuner_address, &dev->i2c_adap,
  993. &ads_duo_cfg) == NULL) {
  994. wprintk("no tda827x tuner found at addr: %02x\n",
  995. ads_tech_duo_config.tuner_address);
  996. goto dettach_frontend;
  997. }
  998. } else
  999. wprintk("failed to attach tda10046\n");
  1000. break;
  1001. case SAA7134_BOARD_TEVION_DVBT_220RF:
  1002. if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
  1003. &tda827x_cfg_0) < 0)
  1004. goto dettach_frontend;
  1005. break;
  1006. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  1007. if (!use_frontend) { /* terrestrial */
  1008. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1009. &tda827x_cfg_0) < 0)
  1010. goto dettach_frontend;
  1011. } else { /* satellite */
  1012. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1013. &flydvbs, &dev->i2c_adap);
  1014. if (fe0->dvb.frontend) {
  1015. struct dvb_frontend *fe = fe0->dvb.frontend;
  1016. u8 dev_id = dev->eedata[2];
  1017. u8 data = 0xc4;
  1018. struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
  1019. if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
  1020. 0x60, &dev->i2c_adap, 0) == NULL) {
  1021. wprintk("%s: Medion Quadro, no tda826x "
  1022. "found !\n", __func__);
  1023. goto dettach_frontend;
  1024. }
  1025. if (dev_id != 0x08) {
  1026. /* we need to open the i2c gate (we know it exists) */
  1027. fe->ops.i2c_gate_ctrl(fe, 1);
  1028. if (dvb_attach(isl6405_attach, fe,
  1029. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1030. wprintk("%s: Medion Quadro, no ISL6405 "
  1031. "found !\n", __func__);
  1032. goto dettach_frontend;
  1033. }
  1034. if (dev_id == 0x07) {
  1035. /* fire up the 2nd section of the LNB supply since
  1036. we can't do this from the other section */
  1037. msg.buf = &data;
  1038. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1039. }
  1040. fe->ops.i2c_gate_ctrl(fe, 0);
  1041. dev->original_set_voltage = fe->ops.set_voltage;
  1042. fe->ops.set_voltage = md8800_set_voltage;
  1043. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1044. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1045. } else {
  1046. fe->ops.set_voltage = md8800_set_voltage2;
  1047. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
  1048. }
  1049. }
  1050. }
  1051. break;
  1052. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  1053. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  1054. &dev->i2c_adap);
  1055. if (fe0->dvb.frontend)
  1056. dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
  1057. NULL, DVB_PLL_TDHU2);
  1058. break;
  1059. case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
  1060. case SAA7134_BOARD_KWORLD_ATSC110:
  1061. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  1062. &dev->i2c_adap);
  1063. if (fe0->dvb.frontend)
  1064. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1065. &dev->i2c_adap, 0x61,
  1066. TUNER_PHILIPS_TUV1236D);
  1067. break;
  1068. case SAA7134_BOARD_FLYDVBS_LR300:
  1069. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1070. &dev->i2c_adap);
  1071. if (fe0->dvb.frontend) {
  1072. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1073. &dev->i2c_adap, 0) == NULL) {
  1074. wprintk("%s: No tda826x found!\n", __func__);
  1075. goto dettach_frontend;
  1076. }
  1077. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1078. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1079. wprintk("%s: No ISL6421 found!\n", __func__);
  1080. goto dettach_frontend;
  1081. }
  1082. }
  1083. break;
  1084. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1085. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1086. &medion_cardbus,
  1087. &dev->i2c_adap);
  1088. if (fe0->dvb.frontend) {
  1089. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1090. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1091. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1092. &dev->i2c_adap, medion_cardbus.tuner_address,
  1093. TUNER_PHILIPS_FMD1216ME_MK3);
  1094. }
  1095. break;
  1096. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1097. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1098. &philips_europa_config,
  1099. &dev->i2c_adap);
  1100. if (fe0->dvb.frontend) {
  1101. fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1102. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1103. }
  1104. break;
  1105. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1106. if (configure_tda827x_fe(dev, &cinergy_ht_config,
  1107. &tda827x_cfg_0) < 0)
  1108. goto dettach_frontend;
  1109. break;
  1110. case SAA7134_BOARD_CINERGY_HT_PCI:
  1111. if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
  1112. &tda827x_cfg_0) < 0)
  1113. goto dettach_frontend;
  1114. break;
  1115. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1116. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1117. &tda827x_cfg_2) < 0)
  1118. goto dettach_frontend;
  1119. break;
  1120. case SAA7134_BOARD_ASUS_P7131_4871:
  1121. if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
  1122. &tda827x_cfg_2) < 0)
  1123. goto dettach_frontend;
  1124. break;
  1125. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1126. if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
  1127. &tda827x_cfg_2) < 0)
  1128. goto dettach_frontend;
  1129. break;
  1130. case SAA7134_BOARD_AVERMEDIA_SUPER_007:
  1131. if (configure_tda827x_fe(dev, &avermedia_super_007_config,
  1132. &tda827x_cfg_0) < 0)
  1133. goto dettach_frontend;
  1134. break;
  1135. case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
  1136. if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
  1137. &tda827x_cfg_2_sw42) < 0)
  1138. goto dettach_frontend;
  1139. break;
  1140. case SAA7134_BOARD_PHILIPS_SNAKE:
  1141. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1142. &dev->i2c_adap);
  1143. if (fe0->dvb.frontend) {
  1144. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1145. &dev->i2c_adap, 0) == NULL) {
  1146. wprintk("%s: No tda826x found!\n", __func__);
  1147. goto dettach_frontend;
  1148. }
  1149. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1150. &dev->i2c_adap, 0, 0) == NULL) {
  1151. wprintk("%s: No lnbp21 found!\n", __func__);
  1152. goto dettach_frontend;
  1153. }
  1154. }
  1155. break;
  1156. case SAA7134_BOARD_CREATIX_CTX953:
  1157. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1158. &tda827x_cfg_0) < 0)
  1159. goto dettach_frontend;
  1160. break;
  1161. case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
  1162. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1163. &tda827x_cfg_2) < 0)
  1164. goto dettach_frontend;
  1165. break;
  1166. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  1167. dprintk("AverMedia E506R dvb setup\n");
  1168. saa7134_set_gpio(dev, 25, 0);
  1169. msleep(10);
  1170. saa7134_set_gpio(dev, 25, 1);
  1171. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1172. &avermedia_xc3028_mt352_dev,
  1173. &dev->i2c_adap);
  1174. attach_xc3028 = 1;
  1175. break;
  1176. case SAA7134_BOARD_MD7134_BRIDGE_2:
  1177. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1178. &sd1878_4m, &dev->i2c_adap);
  1179. if (fe0->dvb.frontend) {
  1180. struct dvb_frontend *fe;
  1181. if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1182. &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
  1183. wprintk("%s: MD7134 DVB-S, no SD1878 "
  1184. "found !\n", __func__);
  1185. goto dettach_frontend;
  1186. }
  1187. /* we need to open the i2c gate (we know it exists) */
  1188. fe = fe0->dvb.frontend;
  1189. fe->ops.i2c_gate_ctrl(fe, 1);
  1190. if (dvb_attach(isl6405_attach, fe,
  1191. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1192. wprintk("%s: MD7134 DVB-S, no ISL6405 "
  1193. "found !\n", __func__);
  1194. goto dettach_frontend;
  1195. }
  1196. fe->ops.i2c_gate_ctrl(fe, 0);
  1197. dev->original_set_voltage = fe->ops.set_voltage;
  1198. fe->ops.set_voltage = md8800_set_voltage;
  1199. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1200. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1201. }
  1202. break;
  1203. case SAA7134_BOARD_AVERMEDIA_M103:
  1204. saa7134_set_gpio(dev, 25, 0);
  1205. msleep(10);
  1206. saa7134_set_gpio(dev, 25, 1);
  1207. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1208. &avermedia_xc3028_mt352_dev,
  1209. &dev->i2c_adap);
  1210. attach_xc3028 = 1;
  1211. break;
  1212. case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
  1213. if (!use_frontend) { /* terrestrial */
  1214. if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
  1215. &tda827x_cfg_2) < 0)
  1216. goto dettach_frontend;
  1217. } else { /* satellite */
  1218. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1219. &flydvbs, &dev->i2c_adap);
  1220. if (fe0->dvb.frontend) {
  1221. if (dvb_attach(tda826x_attach,
  1222. fe0->dvb.frontend, 0x60,
  1223. &dev->i2c_adap, 0) == NULL) {
  1224. wprintk("%s: Asus Tiger 3in1, no "
  1225. "tda826x found!\n", __func__);
  1226. goto dettach_frontend;
  1227. }
  1228. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1229. &dev->i2c_adap, 0, 0) == NULL) {
  1230. wprintk("%s: Asus Tiger 3in1, no lnbp21"
  1231. " found!\n", __func__);
  1232. goto dettach_frontend;
  1233. }
  1234. }
  1235. }
  1236. break;
  1237. case SAA7134_BOARD_ASUSTeK_TIGER:
  1238. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1239. &tda827x_cfg_0) < 0)
  1240. goto dettach_frontend;
  1241. break;
  1242. case SAA7134_BOARD_BEHOLD_H6:
  1243. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1244. &behold_h6_config,
  1245. &dev->i2c_adap);
  1246. if (fe0->dvb.frontend) {
  1247. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1248. &dev->i2c_adap, 0x61,
  1249. TUNER_PHILIPS_FMD1216ME_MK3);
  1250. }
  1251. break;
  1252. case SAA7134_BOARD_AVERMEDIA_A700_PRO:
  1253. case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
  1254. /* Zarlink ZL10313 */
  1255. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1256. &avertv_a700_mt312, &dev->i2c_adap);
  1257. if (fe0->dvb.frontend) {
  1258. if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
  1259. &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
  1260. wprintk("%s: No zl10036 found!\n",
  1261. __func__);
  1262. }
  1263. }
  1264. break;
  1265. default:
  1266. wprintk("Huh? unknown DVB card?\n");
  1267. break;
  1268. }
  1269. if (attach_xc3028) {
  1270. struct dvb_frontend *fe;
  1271. struct xc2028_config cfg = {
  1272. .i2c_adap = &dev->i2c_adap,
  1273. .i2c_addr = 0x61,
  1274. };
  1275. if (!fe0->dvb.frontend)
  1276. goto dettach_frontend;
  1277. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  1278. if (!fe) {
  1279. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  1280. dev->name);
  1281. goto dettach_frontend;
  1282. }
  1283. }
  1284. if (NULL == fe0->dvb.frontend) {
  1285. printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
  1286. goto dettach_frontend;
  1287. }
  1288. /* define general-purpose callback pointer */
  1289. fe0->dvb.frontend->callback = saa7134_tuner_callback;
  1290. /* register everything else */
  1291. ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1292. &dev->pci->dev, adapter_nr, 0);
  1293. /* this sequence is necessary to make the tda1004x load its firmware
  1294. * and to enter analog mode of hybrid boards
  1295. */
  1296. if (!ret) {
  1297. if (fe0->dvb.frontend->ops.init)
  1298. fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
  1299. if (fe0->dvb.frontend->ops.sleep)
  1300. fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
  1301. if (fe0->dvb.frontend->ops.tuner_ops.sleep)
  1302. fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
  1303. }
  1304. return ret;
  1305. dettach_frontend:
  1306. videobuf_dvb_dealloc_frontends(&dev->frontends);
  1307. return -EINVAL;
  1308. }
  1309. static int dvb_fini(struct saa7134_dev *dev)
  1310. {
  1311. struct videobuf_dvb_frontend *fe0;
  1312. /* Get the first frontend */
  1313. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  1314. if (!fe0)
  1315. return -EINVAL;
  1316. /* FIXME: I suspect that this code is bogus, since the entry for
  1317. Pinnacle 300I DVB-T PAL already defines the proper init to allow
  1318. the detection of mt2032 (TDA9887_PORT2_INACTIVE)
  1319. */
  1320. if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
  1321. struct v4l2_priv_tun_config tda9887_cfg;
  1322. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1323. tda9887_cfg.tuner = TUNER_TDA9887;
  1324. tda9887_cfg.priv = &on;
  1325. /* otherwise we don't detect the tuner on next insmod */
  1326. saa_call_all(dev, tuner, s_config, &tda9887_cfg);
  1327. } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
  1328. if ((dev->eedata[2] == 0x07) && use_frontend) {
  1329. /* turn off the 2nd lnb supply */
  1330. u8 data = 0x80;
  1331. struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
  1332. struct dvb_frontend *fe;
  1333. fe = fe0->dvb.frontend;
  1334. if (fe->ops.i2c_gate_ctrl) {
  1335. fe->ops.i2c_gate_ctrl(fe, 1);
  1336. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1337. fe->ops.i2c_gate_ctrl(fe, 0);
  1338. }
  1339. }
  1340. }
  1341. videobuf_dvb_unregister_bus(&dev->frontends);
  1342. return 0;
  1343. }
  1344. static struct saa7134_mpeg_ops dvb_ops = {
  1345. .type = SAA7134_MPEG_DVB,
  1346. .init = dvb_init,
  1347. .fini = dvb_fini,
  1348. };
  1349. static int __init dvb_register(void)
  1350. {
  1351. return saa7134_ts_register(&dvb_ops);
  1352. }
  1353. static void __exit dvb_unregister(void)
  1354. {
  1355. saa7134_ts_unregister(&dvb_ops);
  1356. }
  1357. module_init(dvb_register);
  1358. module_exit(dvb_unregister);
  1359. /* ------------------------------------------------------------------ */
  1360. /*
  1361. * Local variables:
  1362. * c-basic-offset: 8
  1363. * End:
  1364. */