saa7134-dvb.c 43 KB

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