saa7134-dvb.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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. struct videobuf_dvb_frontend *fe0;
  455. /* Get the first frontend */
  456. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  457. fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
  458. if (fe0->dvb.frontend) {
  459. if (cdec_conf->i2c_gate)
  460. fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  461. if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
  462. cdec_conf->tuner_address,
  463. &dev->i2c_adap, tuner_conf))
  464. return 0;
  465. wprintk("no tda827x tuner found at addr: %02x\n",
  466. cdec_conf->tuner_address);
  467. }
  468. return -EINVAL;
  469. }
  470. /* ------------------------------------------------------------------ */
  471. static struct tda827x_config tda827x_cfg_0 = {
  472. .init = philips_tda827x_tuner_init,
  473. .sleep = philips_tda827x_tuner_sleep,
  474. .config = 0,
  475. .switch_addr = 0
  476. };
  477. static struct tda827x_config tda827x_cfg_1 = {
  478. .init = philips_tda827x_tuner_init,
  479. .sleep = philips_tda827x_tuner_sleep,
  480. .config = 1,
  481. .switch_addr = 0x4b
  482. };
  483. static struct tda827x_config tda827x_cfg_2 = {
  484. .init = philips_tda827x_tuner_init,
  485. .sleep = philips_tda827x_tuner_sleep,
  486. .config = 2,
  487. .switch_addr = 0x4b
  488. };
  489. static struct tda827x_config tda827x_cfg_2_sw42 = {
  490. .init = philips_tda827x_tuner_init,
  491. .sleep = philips_tda827x_tuner_sleep,
  492. .config = 2,
  493. .switch_addr = 0x42
  494. };
  495. /* ------------------------------------------------------------------ */
  496. static struct tda1004x_config tda827x_lifeview_config = {
  497. .demod_address = 0x08,
  498. .invert = 1,
  499. .invert_oclk = 0,
  500. .xtal_freq = TDA10046_XTAL_16M,
  501. .agc_config = TDA10046_AGC_TDA827X,
  502. .gpio_config = TDA10046_GP11_I,
  503. .if_freq = TDA10046_FREQ_045,
  504. .tuner_address = 0x60,
  505. .request_firmware = philips_tda1004x_request_firmware
  506. };
  507. static struct tda1004x_config philips_tiger_config = {
  508. .demod_address = 0x08,
  509. .invert = 1,
  510. .invert_oclk = 0,
  511. .xtal_freq = TDA10046_XTAL_16M,
  512. .agc_config = TDA10046_AGC_TDA827X,
  513. .gpio_config = TDA10046_GP11_I,
  514. .if_freq = TDA10046_FREQ_045,
  515. .i2c_gate = 0x4b,
  516. .tuner_address = 0x61,
  517. .antenna_switch= 1,
  518. .request_firmware = philips_tda1004x_request_firmware
  519. };
  520. static struct tda1004x_config cinergy_ht_config = {
  521. .demod_address = 0x08,
  522. .invert = 1,
  523. .invert_oclk = 0,
  524. .xtal_freq = TDA10046_XTAL_16M,
  525. .agc_config = TDA10046_AGC_TDA827X,
  526. .gpio_config = TDA10046_GP01_I,
  527. .if_freq = TDA10046_FREQ_045,
  528. .i2c_gate = 0x4b,
  529. .tuner_address = 0x61,
  530. .request_firmware = philips_tda1004x_request_firmware
  531. };
  532. static struct tda1004x_config cinergy_ht_pci_config = {
  533. .demod_address = 0x08,
  534. .invert = 1,
  535. .invert_oclk = 0,
  536. .xtal_freq = TDA10046_XTAL_16M,
  537. .agc_config = TDA10046_AGC_TDA827X,
  538. .gpio_config = TDA10046_GP01_I,
  539. .if_freq = TDA10046_FREQ_045,
  540. .i2c_gate = 0x4b,
  541. .tuner_address = 0x60,
  542. .request_firmware = philips_tda1004x_request_firmware
  543. };
  544. static struct tda1004x_config philips_tiger_s_config = {
  545. .demod_address = 0x08,
  546. .invert = 1,
  547. .invert_oclk = 0,
  548. .xtal_freq = TDA10046_XTAL_16M,
  549. .agc_config = TDA10046_AGC_TDA827X,
  550. .gpio_config = TDA10046_GP01_I,
  551. .if_freq = TDA10046_FREQ_045,
  552. .i2c_gate = 0x4b,
  553. .tuner_address = 0x61,
  554. .antenna_switch= 1,
  555. .request_firmware = philips_tda1004x_request_firmware
  556. };
  557. static struct tda1004x_config pinnacle_pctv_310i_config = {
  558. .demod_address = 0x08,
  559. .invert = 1,
  560. .invert_oclk = 0,
  561. .xtal_freq = TDA10046_XTAL_16M,
  562. .agc_config = TDA10046_AGC_TDA827X,
  563. .gpio_config = TDA10046_GP11_I,
  564. .if_freq = TDA10046_FREQ_045,
  565. .i2c_gate = 0x4b,
  566. .tuner_address = 0x61,
  567. .request_firmware = philips_tda1004x_request_firmware
  568. };
  569. static struct tda1004x_config hauppauge_hvr_1110_config = {
  570. .demod_address = 0x08,
  571. .invert = 1,
  572. .invert_oclk = 0,
  573. .xtal_freq = TDA10046_XTAL_16M,
  574. .agc_config = TDA10046_AGC_TDA827X,
  575. .gpio_config = TDA10046_GP11_I,
  576. .if_freq = TDA10046_FREQ_045,
  577. .i2c_gate = 0x4b,
  578. .tuner_address = 0x61,
  579. .request_firmware = philips_tda1004x_request_firmware
  580. };
  581. static struct tda1004x_config asus_p7131_dual_config = {
  582. .demod_address = 0x08,
  583. .invert = 1,
  584. .invert_oclk = 0,
  585. .xtal_freq = TDA10046_XTAL_16M,
  586. .agc_config = TDA10046_AGC_TDA827X,
  587. .gpio_config = TDA10046_GP11_I,
  588. .if_freq = TDA10046_FREQ_045,
  589. .i2c_gate = 0x4b,
  590. .tuner_address = 0x61,
  591. .antenna_switch= 2,
  592. .request_firmware = philips_tda1004x_request_firmware
  593. };
  594. static struct tda1004x_config lifeview_trio_config = {
  595. .demod_address = 0x09,
  596. .invert = 1,
  597. .invert_oclk = 0,
  598. .xtal_freq = TDA10046_XTAL_16M,
  599. .agc_config = TDA10046_AGC_TDA827X,
  600. .gpio_config = TDA10046_GP00_I,
  601. .if_freq = TDA10046_FREQ_045,
  602. .tuner_address = 0x60,
  603. .request_firmware = philips_tda1004x_request_firmware
  604. };
  605. static struct tda1004x_config tevion_dvbt220rf_config = {
  606. .demod_address = 0x08,
  607. .invert = 1,
  608. .invert_oclk = 0,
  609. .xtal_freq = TDA10046_XTAL_16M,
  610. .agc_config = TDA10046_AGC_TDA827X,
  611. .gpio_config = TDA10046_GP11_I,
  612. .if_freq = TDA10046_FREQ_045,
  613. .tuner_address = 0x60,
  614. .request_firmware = philips_tda1004x_request_firmware
  615. };
  616. static struct tda1004x_config md8800_dvbt_config = {
  617. .demod_address = 0x08,
  618. .invert = 1,
  619. .invert_oclk = 0,
  620. .xtal_freq = TDA10046_XTAL_16M,
  621. .agc_config = TDA10046_AGC_TDA827X,
  622. .gpio_config = TDA10046_GP01_I,
  623. .if_freq = TDA10046_FREQ_045,
  624. .i2c_gate = 0x4b,
  625. .tuner_address = 0x60,
  626. .request_firmware = philips_tda1004x_request_firmware
  627. };
  628. static struct tda1004x_config asus_p7131_4871_config = {
  629. .demod_address = 0x08,
  630. .invert = 1,
  631. .invert_oclk = 0,
  632. .xtal_freq = TDA10046_XTAL_16M,
  633. .agc_config = TDA10046_AGC_TDA827X,
  634. .gpio_config = TDA10046_GP01_I,
  635. .if_freq = TDA10046_FREQ_045,
  636. .i2c_gate = 0x4b,
  637. .tuner_address = 0x61,
  638. .antenna_switch= 2,
  639. .request_firmware = philips_tda1004x_request_firmware
  640. };
  641. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  642. .demod_address = 0x08,
  643. .invert = 1,
  644. .invert_oclk = 0,
  645. .xtal_freq = TDA10046_XTAL_16M,
  646. .agc_config = TDA10046_AGC_TDA827X,
  647. .gpio_config = TDA10046_GP11_I,
  648. .if_freq = TDA10046_FREQ_045,
  649. .i2c_gate = 0x4b,
  650. .tuner_address = 0x61,
  651. .antenna_switch= 2,
  652. .request_firmware = philips_tda1004x_request_firmware
  653. };
  654. static struct tda1004x_config kworld_dvb_t_210_config = {
  655. .demod_address = 0x08,
  656. .invert = 1,
  657. .invert_oclk = 0,
  658. .xtal_freq = TDA10046_XTAL_16M,
  659. .agc_config = TDA10046_AGC_TDA827X,
  660. .gpio_config = TDA10046_GP11_I,
  661. .if_freq = TDA10046_FREQ_045,
  662. .i2c_gate = 0x4b,
  663. .tuner_address = 0x61,
  664. .antenna_switch= 1,
  665. .request_firmware = philips_tda1004x_request_firmware
  666. };
  667. static struct tda1004x_config avermedia_super_007_config = {
  668. .demod_address = 0x08,
  669. .invert = 1,
  670. .invert_oclk = 0,
  671. .xtal_freq = TDA10046_XTAL_16M,
  672. .agc_config = TDA10046_AGC_TDA827X,
  673. .gpio_config = TDA10046_GP01_I,
  674. .if_freq = TDA10046_FREQ_045,
  675. .i2c_gate = 0x4b,
  676. .tuner_address = 0x60,
  677. .antenna_switch= 1,
  678. .request_firmware = philips_tda1004x_request_firmware
  679. };
  680. static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
  681. .demod_address = 0x08,
  682. .invert = 1,
  683. .invert_oclk = 0,
  684. .xtal_freq = TDA10046_XTAL_16M,
  685. .agc_config = TDA10046_AGC_TDA827X,
  686. .gpio_config = TDA10046_GP01_I,
  687. .if_freq = TDA10046_FREQ_045,
  688. .i2c_gate = 0x42,
  689. .tuner_address = 0x61,
  690. .antenna_switch = 1,
  691. .request_firmware = philips_tda1004x_request_firmware
  692. };
  693. static struct tda1004x_config asus_tiger_3in1_config = {
  694. .demod_address = 0x0b,
  695. .invert = 1,
  696. .invert_oclk = 0,
  697. .xtal_freq = TDA10046_XTAL_16M,
  698. .agc_config = TDA10046_AGC_TDA827X,
  699. .gpio_config = TDA10046_GP11_I,
  700. .if_freq = TDA10046_FREQ_045,
  701. .i2c_gate = 0x4b,
  702. .tuner_address = 0x61,
  703. .antenna_switch = 1,
  704. .request_firmware = philips_tda1004x_request_firmware
  705. };
  706. /* ------------------------------------------------------------------
  707. * special case: this card uses saa713x GPIO22 for the mode switch
  708. */
  709. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  710. {
  711. struct saa7134_dev *dev = fe->dvb->priv;
  712. philips_tda827x_tuner_init(fe);
  713. /* route TDA8275a AGC input to the channel decoder */
  714. saa7134_set_gpio(dev, 22, 1);
  715. return 0;
  716. }
  717. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  718. {
  719. struct saa7134_dev *dev = fe->dvb->priv;
  720. /* route TDA8275a AGC input to the analog IF chip*/
  721. saa7134_set_gpio(dev, 22, 0);
  722. philips_tda827x_tuner_sleep(fe);
  723. return 0;
  724. }
  725. static struct tda827x_config ads_duo_cfg = {
  726. .init = ads_duo_tuner_init,
  727. .sleep = ads_duo_tuner_sleep,
  728. .config = 0
  729. };
  730. static struct tda1004x_config ads_tech_duo_config = {
  731. .demod_address = 0x08,
  732. .invert = 1,
  733. .invert_oclk = 0,
  734. .xtal_freq = TDA10046_XTAL_16M,
  735. .agc_config = TDA10046_AGC_TDA827X,
  736. .gpio_config = TDA10046_GP00_I,
  737. .if_freq = TDA10046_FREQ_045,
  738. .tuner_address = 0x61,
  739. .request_firmware = philips_tda1004x_request_firmware
  740. };
  741. /* ==================================================================
  742. * tda10086 based DVB-S cards, helper functions
  743. */
  744. static struct tda10086_config flydvbs = {
  745. .demod_address = 0x0e,
  746. .invert = 0,
  747. .diseqc_tone = 0,
  748. .xtal_freq = TDA10086_XTAL_16M,
  749. };
  750. static struct tda10086_config sd1878_4m = {
  751. .demod_address = 0x0e,
  752. .invert = 0,
  753. .diseqc_tone = 0,
  754. .xtal_freq = TDA10086_XTAL_4M,
  755. };
  756. /* ------------------------------------------------------------------
  757. * special case: lnb supply is connected to the gated i2c
  758. */
  759. static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  760. {
  761. int res = -EIO;
  762. struct saa7134_dev *dev = fe->dvb->priv;
  763. if (fe->ops.i2c_gate_ctrl) {
  764. fe->ops.i2c_gate_ctrl(fe, 1);
  765. if (dev->original_set_voltage)
  766. res = dev->original_set_voltage(fe, voltage);
  767. fe->ops.i2c_gate_ctrl(fe, 0);
  768. }
  769. return res;
  770. };
  771. static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
  772. {
  773. int res = -EIO;
  774. struct saa7134_dev *dev = fe->dvb->priv;
  775. if (fe->ops.i2c_gate_ctrl) {
  776. fe->ops.i2c_gate_ctrl(fe, 1);
  777. if (dev->original_set_high_voltage)
  778. res = dev->original_set_high_voltage(fe, arg);
  779. fe->ops.i2c_gate_ctrl(fe, 0);
  780. }
  781. return res;
  782. };
  783. static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  784. {
  785. struct saa7134_dev *dev = fe->dvb->priv;
  786. u8 wbuf[2] = { 0x1f, 00 };
  787. u8 rbuf;
  788. struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
  789. { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
  790. if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
  791. return -EIO;
  792. /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
  793. if (voltage == SEC_VOLTAGE_18)
  794. wbuf[1] = rbuf | 0x10;
  795. else
  796. wbuf[1] = rbuf & 0xef;
  797. msg[0].len = 2;
  798. i2c_transfer(&dev->i2c_adap, msg, 1);
  799. return 0;
  800. }
  801. static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
  802. {
  803. struct saa7134_dev *dev = fe->dvb->priv;
  804. wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
  805. return -EIO;
  806. }
  807. /* ==================================================================
  808. * nxt200x based ATSC cards, helper functions
  809. */
  810. static struct nxt200x_config avertvhda180 = {
  811. .demod_address = 0x0a,
  812. };
  813. static struct nxt200x_config kworldatsc110 = {
  814. .demod_address = 0x0a,
  815. };
  816. /* ==================================================================
  817. * Core code
  818. */
  819. static int dvb_init(struct saa7134_dev *dev)
  820. {
  821. int ret;
  822. int attach_xc3028 = 0;
  823. struct videobuf_dvb_frontend *fe0;
  824. /* FIXME: add support for multi-frontend */
  825. mutex_init(&dev->frontends.lock);
  826. INIT_LIST_HEAD(&dev->frontends.frontend.felist);
  827. dev->frontends.active_fe_id = 0;
  828. printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
  829. if (videobuf_dvb_alloc_frontend(dev, &dev->frontends, 1) == NULL) {
  830. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  831. return -ENOMEM;
  832. }
  833. /* Get the first frontend */
  834. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  835. if (!fe0)
  836. return -EINVAL;
  837. /* init struct videobuf_dvb */
  838. dev->ts.nr_bufs = 32;
  839. dev->ts.nr_packets = 32*4;
  840. fe0->dvb.name = dev->name;
  841. videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
  842. &dev->pci->dev, &dev->slock,
  843. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  844. V4L2_FIELD_ALTERNATE,
  845. sizeof(struct saa7134_buf),
  846. dev);
  847. switch (dev->board) {
  848. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  849. dprintk("pinnacle 300i dvb setup\n");
  850. fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  851. &dev->i2c_adap);
  852. if (fe0->dvb.frontend) {
  853. fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  854. }
  855. break;
  856. case SAA7134_BOARD_AVERMEDIA_777:
  857. case SAA7134_BOARD_AVERMEDIA_A16AR:
  858. dprintk("avertv 777 dvb setup\n");
  859. fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  860. &dev->i2c_adap);
  861. if (fe0->dvb.frontend) {
  862. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  863. &dev->i2c_adap, 0x61,
  864. TUNER_PHILIPS_TD1316);
  865. }
  866. break;
  867. case SAA7134_BOARD_AVERMEDIA_A16D:
  868. dprintk("AverMedia A16D dvb setup\n");
  869. fe0->dvb.frontend = dvb_attach(mt352_attach,
  870. &avermedia_xc3028_mt352_dev,
  871. &dev->i2c_adap);
  872. attach_xc3028 = 1;
  873. break;
  874. case SAA7134_BOARD_MD7134:
  875. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  876. &medion_cardbus,
  877. &dev->i2c_adap);
  878. if (fe0->dvb.frontend) {
  879. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  880. &dev->i2c_adap, medion_cardbus.tuner_address,
  881. TUNER_PHILIPS_FMD1216ME_MK3);
  882. }
  883. break;
  884. case SAA7134_BOARD_PHILIPS_TOUGH:
  885. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  886. &philips_tu1216_60_config,
  887. &dev->i2c_adap);
  888. if (fe0->dvb.frontend) {
  889. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  890. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  891. }
  892. break;
  893. case SAA7134_BOARD_FLYDVBTDUO:
  894. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  895. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  896. &tda827x_cfg_0) < 0)
  897. goto dettach_frontend;
  898. break;
  899. case SAA7134_BOARD_PHILIPS_EUROPA:
  900. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  901. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  902. &philips_europa_config,
  903. &dev->i2c_adap);
  904. if (fe0->dvb.frontend) {
  905. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  906. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  907. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  908. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  909. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  910. }
  911. break;
  912. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  913. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  914. &philips_tu1216_61_config,
  915. &dev->i2c_adap);
  916. if (fe0->dvb.frontend) {
  917. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  918. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  919. }
  920. break;
  921. case SAA7134_BOARD_KWORLD_DVBT_210:
  922. if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
  923. &tda827x_cfg_2) < 0)
  924. goto dettach_frontend;
  925. break;
  926. case SAA7134_BOARD_PHILIPS_TIGER:
  927. if (configure_tda827x_fe(dev, &philips_tiger_config,
  928. &tda827x_cfg_0) < 0)
  929. goto dettach_frontend;
  930. break;
  931. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  932. if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
  933. &tda827x_cfg_1) < 0)
  934. goto dettach_frontend;
  935. break;
  936. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  937. if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
  938. &tda827x_cfg_1) < 0)
  939. goto dettach_frontend;
  940. break;
  941. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  942. if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
  943. &tda827x_cfg_0) < 0)
  944. goto dettach_frontend;
  945. break;
  946. case SAA7134_BOARD_FLYDVBT_LR301:
  947. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  948. &tda827x_cfg_0) < 0)
  949. goto dettach_frontend;
  950. break;
  951. case SAA7134_BOARD_FLYDVB_TRIO:
  952. if (!use_frontend) { /* terrestrial */
  953. if (configure_tda827x_fe(dev, &lifeview_trio_config,
  954. &tda827x_cfg_0) < 0)
  955. goto dettach_frontend;
  956. } else { /* satellite */
  957. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  958. if (fe0->dvb.frontend) {
  959. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
  960. &dev->i2c_adap, 0) == NULL) {
  961. wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
  962. goto dettach_frontend;
  963. }
  964. if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
  965. 0x08, 0, 0) == NULL) {
  966. wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
  967. goto dettach_frontend;
  968. }
  969. }
  970. }
  971. break;
  972. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  973. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  974. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  975. &ads_tech_duo_config,
  976. &dev->i2c_adap);
  977. if (fe0->dvb.frontend) {
  978. if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
  979. ads_tech_duo_config.tuner_address, &dev->i2c_adap,
  980. &ads_duo_cfg) == NULL) {
  981. wprintk("no tda827x tuner found at addr: %02x\n",
  982. ads_tech_duo_config.tuner_address);
  983. goto dettach_frontend;
  984. }
  985. } else
  986. wprintk("failed to attach tda10046\n");
  987. break;
  988. case SAA7134_BOARD_TEVION_DVBT_220RF:
  989. if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
  990. &tda827x_cfg_0) < 0)
  991. goto dettach_frontend;
  992. break;
  993. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  994. if (!use_frontend) { /* terrestrial */
  995. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  996. &tda827x_cfg_0) < 0)
  997. goto dettach_frontend;
  998. } else { /* satellite */
  999. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1000. &flydvbs, &dev->i2c_adap);
  1001. if (fe0->dvb.frontend) {
  1002. struct dvb_frontend *fe = fe0->dvb.frontend;
  1003. u8 dev_id = dev->eedata[2];
  1004. u8 data = 0xc4;
  1005. struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
  1006. if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
  1007. 0x60, &dev->i2c_adap, 0) == NULL) {
  1008. wprintk("%s: Medion Quadro, no tda826x "
  1009. "found !\n", __func__);
  1010. goto dettach_frontend;
  1011. }
  1012. if (dev_id != 0x08) {
  1013. /* we need to open the i2c gate (we know it exists) */
  1014. fe->ops.i2c_gate_ctrl(fe, 1);
  1015. if (dvb_attach(isl6405_attach, fe,
  1016. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1017. wprintk("%s: Medion Quadro, no ISL6405 "
  1018. "found !\n", __func__);
  1019. goto dettach_frontend;
  1020. }
  1021. if (dev_id == 0x07) {
  1022. /* fire up the 2nd section of the LNB supply since
  1023. we can't do this from the other section */
  1024. msg.buf = &data;
  1025. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1026. }
  1027. fe->ops.i2c_gate_ctrl(fe, 0);
  1028. dev->original_set_voltage = fe->ops.set_voltage;
  1029. fe->ops.set_voltage = md8800_set_voltage;
  1030. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1031. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1032. } else {
  1033. fe->ops.set_voltage = md8800_set_voltage2;
  1034. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
  1035. }
  1036. }
  1037. }
  1038. break;
  1039. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  1040. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  1041. &dev->i2c_adap);
  1042. if (fe0->dvb.frontend)
  1043. dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
  1044. NULL, DVB_PLL_TDHU2);
  1045. break;
  1046. case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
  1047. case SAA7134_BOARD_KWORLD_ATSC110:
  1048. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  1049. &dev->i2c_adap);
  1050. if (fe0->dvb.frontend)
  1051. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1052. &dev->i2c_adap, 0x61,
  1053. TUNER_PHILIPS_TUV1236D);
  1054. break;
  1055. case SAA7134_BOARD_FLYDVBS_LR300:
  1056. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1057. &dev->i2c_adap);
  1058. if (fe0->dvb.frontend) {
  1059. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1060. &dev->i2c_adap, 0) == NULL) {
  1061. wprintk("%s: No tda826x found!\n", __func__);
  1062. goto dettach_frontend;
  1063. }
  1064. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1065. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1066. wprintk("%s: No ISL6421 found!\n", __func__);
  1067. goto dettach_frontend;
  1068. }
  1069. }
  1070. break;
  1071. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1072. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1073. &medion_cardbus,
  1074. &dev->i2c_adap);
  1075. if (fe0->dvb.frontend) {
  1076. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1077. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1078. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1079. &dev->i2c_adap, medion_cardbus.tuner_address,
  1080. TUNER_PHILIPS_FMD1216ME_MK3);
  1081. }
  1082. break;
  1083. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1084. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1085. &philips_europa_config,
  1086. &dev->i2c_adap);
  1087. if (fe0->dvb.frontend) {
  1088. fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1089. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1090. }
  1091. break;
  1092. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1093. if (configure_tda827x_fe(dev, &cinergy_ht_config,
  1094. &tda827x_cfg_0) < 0)
  1095. goto dettach_frontend;
  1096. break;
  1097. case SAA7134_BOARD_CINERGY_HT_PCI:
  1098. if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
  1099. &tda827x_cfg_0) < 0)
  1100. goto dettach_frontend;
  1101. break;
  1102. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1103. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1104. &tda827x_cfg_2) < 0)
  1105. goto dettach_frontend;
  1106. break;
  1107. case SAA7134_BOARD_ASUS_P7131_4871:
  1108. if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
  1109. &tda827x_cfg_2) < 0)
  1110. goto dettach_frontend;
  1111. break;
  1112. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1113. if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
  1114. &tda827x_cfg_2) < 0)
  1115. goto dettach_frontend;
  1116. break;
  1117. case SAA7134_BOARD_AVERMEDIA_SUPER_007:
  1118. if (configure_tda827x_fe(dev, &avermedia_super_007_config,
  1119. &tda827x_cfg_0) < 0)
  1120. goto dettach_frontend;
  1121. break;
  1122. case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
  1123. if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
  1124. &tda827x_cfg_2_sw42) < 0)
  1125. goto dettach_frontend;
  1126. break;
  1127. case SAA7134_BOARD_PHILIPS_SNAKE:
  1128. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1129. &dev->i2c_adap);
  1130. if (fe0->dvb.frontend) {
  1131. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1132. &dev->i2c_adap, 0) == NULL) {
  1133. wprintk("%s: No tda826x found!\n", __func__);
  1134. goto dettach_frontend;
  1135. }
  1136. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1137. &dev->i2c_adap, 0, 0) == NULL) {
  1138. wprintk("%s: No lnbp21 found!\n", __func__);
  1139. goto dettach_frontend;
  1140. }
  1141. }
  1142. break;
  1143. case SAA7134_BOARD_CREATIX_CTX953:
  1144. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1145. &tda827x_cfg_0) < 0)
  1146. goto dettach_frontend;
  1147. break;
  1148. case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
  1149. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1150. &tda827x_cfg_2) < 0)
  1151. goto dettach_frontend;
  1152. break;
  1153. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  1154. dprintk("AverMedia E506R dvb setup\n");
  1155. saa7134_set_gpio(dev, 25, 0);
  1156. msleep(10);
  1157. saa7134_set_gpio(dev, 25, 1);
  1158. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1159. &avermedia_xc3028_mt352_dev,
  1160. &dev->i2c_adap);
  1161. attach_xc3028 = 1;
  1162. break;
  1163. case SAA7134_BOARD_MD7134_BRIDGE_2:
  1164. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1165. &sd1878_4m, &dev->i2c_adap);
  1166. if (fe0->dvb.frontend) {
  1167. struct dvb_frontend *fe;
  1168. if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1169. &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
  1170. wprintk("%s: MD7134 DVB-S, no SD1878 "
  1171. "found !\n", __func__);
  1172. goto dettach_frontend;
  1173. }
  1174. /* we need to open the i2c gate (we know it exists) */
  1175. fe = fe0->dvb.frontend;
  1176. fe->ops.i2c_gate_ctrl(fe, 1);
  1177. if (dvb_attach(isl6405_attach, fe,
  1178. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1179. wprintk("%s: MD7134 DVB-S, no ISL6405 "
  1180. "found !\n", __func__);
  1181. goto dettach_frontend;
  1182. }
  1183. fe->ops.i2c_gate_ctrl(fe, 0);
  1184. dev->original_set_voltage = fe->ops.set_voltage;
  1185. fe->ops.set_voltage = md8800_set_voltage;
  1186. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1187. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1188. }
  1189. break;
  1190. case SAA7134_BOARD_AVERMEDIA_M103:
  1191. saa7134_set_gpio(dev, 25, 0);
  1192. msleep(10);
  1193. saa7134_set_gpio(dev, 25, 1);
  1194. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1195. &avermedia_xc3028_mt352_dev,
  1196. &dev->i2c_adap);
  1197. attach_xc3028 = 1;
  1198. break;
  1199. case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
  1200. if (!use_frontend) { /* terrestrial */
  1201. if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
  1202. &tda827x_cfg_2) < 0)
  1203. goto dettach_frontend;
  1204. } else { /* satellite */
  1205. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1206. &flydvbs, &dev->i2c_adap);
  1207. if (fe0->dvb.frontend) {
  1208. if (dvb_attach(tda826x_attach,
  1209. fe0->dvb.frontend, 0x60,
  1210. &dev->i2c_adap, 0) == NULL) {
  1211. wprintk("%s: Asus Tiger 3in1, no "
  1212. "tda826x found!\n", __func__);
  1213. goto dettach_frontend;
  1214. }
  1215. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1216. &dev->i2c_adap, 0, 0) == NULL) {
  1217. wprintk("%s: Asus Tiger 3in1, no lnbp21"
  1218. " found!\n", __func__);
  1219. goto dettach_frontend;
  1220. }
  1221. }
  1222. }
  1223. break;
  1224. case SAA7134_BOARD_ASUSTeK_TIGER:
  1225. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1226. &tda827x_cfg_0) < 0)
  1227. goto dettach_frontend;
  1228. break;
  1229. default:
  1230. wprintk("Huh? unknown DVB card?\n");
  1231. break;
  1232. }
  1233. if (attach_xc3028) {
  1234. struct dvb_frontend *fe;
  1235. struct xc2028_config cfg = {
  1236. .i2c_adap = &dev->i2c_adap,
  1237. .i2c_addr = 0x61,
  1238. };
  1239. if (!fe0->dvb.frontend)
  1240. return -1;
  1241. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  1242. if (!fe) {
  1243. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  1244. dev->name);
  1245. goto dettach_frontend;
  1246. }
  1247. }
  1248. if (NULL == fe0->dvb.frontend) {
  1249. printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
  1250. return -1;
  1251. }
  1252. /* define general-purpose callback pointer */
  1253. fe0->dvb.frontend->callback = saa7134_tuner_callback;
  1254. /* register everything else */
  1255. ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1256. &dev->pci->dev, adapter_nr, 0);
  1257. /* this sequence is necessary to make the tda1004x load its firmware
  1258. * and to enter analog mode of hybrid boards
  1259. */
  1260. if (!ret) {
  1261. if (fe0->dvb.frontend->ops.init)
  1262. fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
  1263. if (fe0->dvb.frontend->ops.sleep)
  1264. fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
  1265. if (fe0->dvb.frontend->ops.tuner_ops.sleep)
  1266. fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
  1267. }
  1268. return ret;
  1269. dettach_frontend:
  1270. if (fe0->dvb.frontend)
  1271. dvb_frontend_detach(fe0->dvb.frontend);
  1272. fe0->dvb.frontend = NULL;
  1273. return -1;
  1274. }
  1275. static int dvb_fini(struct saa7134_dev *dev)
  1276. {
  1277. struct videobuf_dvb_frontend *fe0;
  1278. /* Get the first frontend */
  1279. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  1280. if (!fe0)
  1281. return -EINVAL;
  1282. /* FIXME: I suspect that this code is bogus, since the entry for
  1283. Pinnacle 300I DVB-T PAL already defines the proper init to allow
  1284. the detection of mt2032 (TDA9887_PORT2_INACTIVE)
  1285. */
  1286. if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
  1287. struct v4l2_priv_tun_config tda9887_cfg;
  1288. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1289. tda9887_cfg.tuner = TUNER_TDA9887;
  1290. tda9887_cfg.priv = &on;
  1291. /* otherwise we don't detect the tuner on next insmod */
  1292. saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
  1293. } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
  1294. if ((dev->eedata[2] == 0x07) && use_frontend) {
  1295. /* turn off the 2nd lnb supply */
  1296. u8 data = 0x80;
  1297. struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
  1298. struct dvb_frontend *fe;
  1299. fe = fe0->dvb.frontend;
  1300. if (fe->ops.i2c_gate_ctrl) {
  1301. fe->ops.i2c_gate_ctrl(fe, 1);
  1302. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1303. fe->ops.i2c_gate_ctrl(fe, 0);
  1304. }
  1305. }
  1306. }
  1307. if (fe0->dvb.frontend)
  1308. videobuf_dvb_unregister_bus(&dev->frontends);
  1309. return 0;
  1310. }
  1311. static struct saa7134_mpeg_ops dvb_ops = {
  1312. .type = SAA7134_MPEG_DVB,
  1313. .init = dvb_init,
  1314. .fini = dvb_fini,
  1315. };
  1316. static int __init dvb_register(void)
  1317. {
  1318. return saa7134_ts_register(&dvb_ops);
  1319. }
  1320. static void __exit dvb_unregister(void)
  1321. {
  1322. saa7134_ts_unregister(&dvb_ops);
  1323. }
  1324. module_init(dvb_register);
  1325. module_exit(dvb_unregister);
  1326. /* ------------------------------------------------------------------ */
  1327. /*
  1328. * Local variables:
  1329. * c-basic-offset: 8
  1330. * End:
  1331. */