saa7134-dvb.c 42 KB

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