saa7134-dvb.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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 "mt352.h"
  35. #include "mt352_priv.h" /* FIXME */
  36. #include "tda1004x.h"
  37. #include "nxt200x.h"
  38. #include "tda10086.h"
  39. #include "tda826x.h"
  40. #include "tda827x.h"
  41. #include "isl6421.h"
  42. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  43. MODULE_LICENSE("GPL");
  44. static unsigned int antenna_pwr = 0;
  45. module_param(antenna_pwr, int, 0444);
  46. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  47. static int use_frontend = 0;
  48. module_param(use_frontend, int, 0644);
  49. MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
  50. static int debug = 0;
  51. module_param(debug, int, 0644);
  52. MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
  53. #define dprintk(fmt, arg...) do { if (debug) \
  54. printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
  55. /* Print a warning */
  56. #define wprintk(fmt, arg...) \
  57. printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
  58. /* ------------------------------------------------------------------
  59. * mt352 based DVB-T cards
  60. */
  61. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  62. {
  63. u32 ok;
  64. if (!on) {
  65. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  66. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  67. return 0;
  68. }
  69. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  70. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  71. udelay(10);
  72. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  73. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  74. udelay(10);
  75. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  76. udelay(10);
  77. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  78. dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off");
  79. if (!ok)
  80. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  81. return ok;
  82. }
  83. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  84. {
  85. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  86. static u8 reset [] = { RESET, 0x80 };
  87. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  88. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  89. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  90. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  91. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  92. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  93. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  94. struct saa7134_dev *dev= fe->dvb->priv;
  95. dprintk("%s called\n", __FUNCTION__);
  96. mt352_write(fe, clock_config, sizeof(clock_config));
  97. udelay(200);
  98. mt352_write(fe, reset, sizeof(reset));
  99. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  100. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  101. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  102. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  103. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  104. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  105. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  106. return 0;
  107. }
  108. static int mt352_aver777_init(struct dvb_frontend* fe)
  109. {
  110. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  111. static u8 reset [] = { RESET, 0x80 };
  112. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  113. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  114. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  115. mt352_write(fe, clock_config, sizeof(clock_config));
  116. udelay(200);
  117. mt352_write(fe, reset, sizeof(reset));
  118. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  119. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  120. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  121. return 0;
  122. }
  123. static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
  124. struct dvb_frontend_parameters* params)
  125. {
  126. u8 off[] = { 0x00, 0xf1};
  127. u8 on[] = { 0x00, 0x71};
  128. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  129. struct saa7134_dev *dev = fe->dvb->priv;
  130. struct v4l2_frequency f;
  131. /* set frequency (mt2050) */
  132. f.tuner = 0;
  133. f.type = V4L2_TUNER_DIGITAL_TV;
  134. f.frequency = params->frequency / 1000 * 16 / 1000;
  135. if (fe->ops.i2c_gate_ctrl)
  136. fe->ops.i2c_gate_ctrl(fe, 1);
  137. i2c_transfer(&dev->i2c_adap, &msg, 1);
  138. saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
  139. msg.buf = on;
  140. if (fe->ops.i2c_gate_ctrl)
  141. fe->ops.i2c_gate_ctrl(fe, 1);
  142. i2c_transfer(&dev->i2c_adap, &msg, 1);
  143. pinnacle_antenna_pwr(dev, antenna_pwr);
  144. /* mt352 setup */
  145. return mt352_pinnacle_init(fe);
  146. }
  147. static int mt352_aver777_tuner_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
  148. {
  149. if (buf_len < 5)
  150. return -EINVAL;
  151. pllbuf[0] = 0x61;
  152. dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1, params);
  153. return 5;
  154. }
  155. static struct mt352_config pinnacle_300i = {
  156. .demod_address = 0x3c >> 1,
  157. .adc_clock = 20333,
  158. .if2 = 36150,
  159. .no_tuner = 1,
  160. .demod_init = mt352_pinnacle_init,
  161. };
  162. static struct mt352_config avermedia_777 = {
  163. .demod_address = 0xf,
  164. .demod_init = mt352_aver777_init,
  165. };
  166. /* ==================================================================
  167. * tda1004x based DVB-T cards, helper functions
  168. */
  169. static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
  170. const struct firmware **fw, char *name)
  171. {
  172. struct saa7134_dev *dev = fe->dvb->priv;
  173. return request_firmware(fw, name, &dev->pci->dev);
  174. }
  175. /* ------------------------------------------------------------------
  176. * these tuners are tu1216, td1316(a)
  177. */
  178. static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  179. {
  180. struct saa7134_dev *dev = fe->dvb->priv;
  181. struct tda1004x_state *state = fe->demodulator_priv;
  182. u8 addr = state->config->tuner_address;
  183. u8 tuner_buf[4];
  184. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  185. sizeof(tuner_buf) };
  186. int tuner_frequency = 0;
  187. u8 band, cp, filter;
  188. /* determine charge pump */
  189. tuner_frequency = params->frequency + 36166000;
  190. if (tuner_frequency < 87000000)
  191. return -EINVAL;
  192. else if (tuner_frequency < 130000000)
  193. cp = 3;
  194. else if (tuner_frequency < 160000000)
  195. cp = 5;
  196. else if (tuner_frequency < 200000000)
  197. cp = 6;
  198. else if (tuner_frequency < 290000000)
  199. cp = 3;
  200. else if (tuner_frequency < 420000000)
  201. cp = 5;
  202. else if (tuner_frequency < 480000000)
  203. cp = 6;
  204. else if (tuner_frequency < 620000000)
  205. cp = 3;
  206. else if (tuner_frequency < 830000000)
  207. cp = 5;
  208. else if (tuner_frequency < 895000000)
  209. cp = 7;
  210. else
  211. return -EINVAL;
  212. /* determine band */
  213. if (params->frequency < 49000000)
  214. return -EINVAL;
  215. else if (params->frequency < 161000000)
  216. band = 1;
  217. else if (params->frequency < 444000000)
  218. band = 2;
  219. else if (params->frequency < 861000000)
  220. band = 4;
  221. else
  222. return -EINVAL;
  223. /* setup PLL filter */
  224. switch (params->u.ofdm.bandwidth) {
  225. case BANDWIDTH_6_MHZ:
  226. filter = 0;
  227. break;
  228. case BANDWIDTH_7_MHZ:
  229. filter = 0;
  230. break;
  231. case BANDWIDTH_8_MHZ:
  232. filter = 1;
  233. break;
  234. default:
  235. return -EINVAL;
  236. }
  237. /* calculate divisor
  238. * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
  239. */
  240. tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
  241. /* setup tuner buffer */
  242. tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
  243. tuner_buf[1] = tuner_frequency & 0xff;
  244. tuner_buf[2] = 0xca;
  245. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  246. if (fe->ops.i2c_gate_ctrl)
  247. fe->ops.i2c_gate_ctrl(fe, 1);
  248. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
  249. wprintk("could not write to tuner at addr: 0x%02x\n",
  250. addr << 1);
  251. return -EIO;
  252. }
  253. msleep(1);
  254. return 0;
  255. }
  256. static int philips_tu1216_init(struct dvb_frontend *fe)
  257. {
  258. struct saa7134_dev *dev = fe->dvb->priv;
  259. struct tda1004x_state *state = fe->demodulator_priv;
  260. u8 addr = state->config->tuner_address;
  261. static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  262. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
  263. /* setup PLL configuration */
  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. return -EIO;
  268. msleep(1);
  269. return 0;
  270. }
  271. /* ------------------------------------------------------------------ */
  272. static struct tda1004x_config philips_tu1216_60_config = {
  273. .demod_address = 0x8,
  274. .invert = 1,
  275. .invert_oclk = 0,
  276. .xtal_freq = TDA10046_XTAL_4M,
  277. .agc_config = TDA10046_AGC_DEFAULT,
  278. .if_freq = TDA10046_FREQ_3617,
  279. .tuner_address = 0x60,
  280. .request_firmware = philips_tda1004x_request_firmware
  281. };
  282. static struct tda1004x_config philips_tu1216_61_config = {
  283. .demod_address = 0x8,
  284. .invert = 1,
  285. .invert_oclk = 0,
  286. .xtal_freq = TDA10046_XTAL_4M,
  287. .agc_config = TDA10046_AGC_DEFAULT,
  288. .if_freq = TDA10046_FREQ_3617,
  289. .tuner_address = 0x61,
  290. .request_firmware = philips_tda1004x_request_firmware
  291. };
  292. /* ------------------------------------------------------------------ */
  293. static int philips_td1316_tuner_init(struct dvb_frontend *fe)
  294. {
  295. struct saa7134_dev *dev = fe->dvb->priv;
  296. struct tda1004x_state *state = fe->demodulator_priv;
  297. u8 addr = state->config->tuner_address;
  298. static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
  299. struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  300. /* setup PLL configuration */
  301. if (fe->ops.i2c_gate_ctrl)
  302. fe->ops.i2c_gate_ctrl(fe, 1);
  303. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  304. return -EIO;
  305. return 0;
  306. }
  307. static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  308. {
  309. return philips_tda6651_pll_set(fe, params);
  310. }
  311. static int philips_td1316_tuner_sleep(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, 0xdc, 0x86, 0xa4 };
  317. struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  318. /* switch the tuner to analog mode */
  319. if (fe->ops.i2c_gate_ctrl)
  320. fe->ops.i2c_gate_ctrl(fe, 1);
  321. if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
  322. return -EIO;
  323. return 0;
  324. }
  325. /* ------------------------------------------------------------------ */
  326. static int philips_europa_tuner_init(struct dvb_frontend *fe)
  327. {
  328. struct saa7134_dev *dev = fe->dvb->priv;
  329. static u8 msg[] = { 0x00, 0x40};
  330. struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  331. if (philips_td1316_tuner_init(fe))
  332. return -EIO;
  333. msleep(1);
  334. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  335. return -EIO;
  336. return 0;
  337. }
  338. static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
  339. {
  340. struct saa7134_dev *dev = fe->dvb->priv;
  341. static u8 msg[] = { 0x00, 0x14 };
  342. struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  343. if (philips_td1316_tuner_sleep(fe))
  344. return -EIO;
  345. /* switch the board to analog mode */
  346. if (fe->ops.i2c_gate_ctrl)
  347. fe->ops.i2c_gate_ctrl(fe, 1);
  348. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  349. return 0;
  350. }
  351. static int philips_europa_demod_sleep(struct dvb_frontend *fe)
  352. {
  353. struct saa7134_dev *dev = fe->dvb->priv;
  354. if (dev->original_demod_sleep)
  355. dev->original_demod_sleep(fe);
  356. fe->ops.i2c_gate_ctrl(fe, 1);
  357. return 0;
  358. }
  359. static struct tda1004x_config philips_europa_config = {
  360. .demod_address = 0x8,
  361. .invert = 0,
  362. .invert_oclk = 0,
  363. .xtal_freq = TDA10046_XTAL_4M,
  364. .agc_config = TDA10046_AGC_IFO_AUTO_POS,
  365. .if_freq = TDA10046_FREQ_052,
  366. .tuner_address = 0x61,
  367. .request_firmware = philips_tda1004x_request_firmware
  368. };
  369. /* ------------------------------------------------------------------ */
  370. static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
  371. {
  372. struct saa7134_dev *dev = fe->dvb->priv;
  373. struct tda1004x_state *state = fe->demodulator_priv;
  374. u8 addr = state->config->tuner_address;
  375. /* this message is to set up ATC and ALC */
  376. static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
  377. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
  378. if (fe->ops.i2c_gate_ctrl)
  379. fe->ops.i2c_gate_ctrl(fe, 1);
  380. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  381. return -EIO;
  382. msleep(1);
  383. return 0;
  384. }
  385. static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
  386. {
  387. struct saa7134_dev *dev = fe->dvb->priv;
  388. struct tda1004x_state *state = fe->demodulator_priv;
  389. u8 addr = state->config->tuner_address;
  390. /* this message actually turns the tuner back to analog mode */
  391. u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
  392. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
  393. if (fe->ops.i2c_gate_ctrl)
  394. fe->ops.i2c_gate_ctrl(fe, 1);
  395. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  396. msleep(1);
  397. fmd1216_init[2] = 0x86;
  398. fmd1216_init[3] = 0x54;
  399. if (fe->ops.i2c_gate_ctrl)
  400. fe->ops.i2c_gate_ctrl(fe, 1);
  401. i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
  402. msleep(1);
  403. return 0;
  404. }
  405. static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  406. {
  407. struct saa7134_dev *dev = fe->dvb->priv;
  408. struct tda1004x_state *state = fe->demodulator_priv;
  409. u8 addr = state->config->tuner_address;
  410. u8 tuner_buf[4];
  411. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  412. sizeof(tuner_buf) };
  413. int tuner_frequency = 0;
  414. int divider = 0;
  415. u8 band, mode, cp;
  416. /* determine charge pump */
  417. tuner_frequency = params->frequency + 36130000;
  418. if (tuner_frequency < 87000000)
  419. return -EINVAL;
  420. /* low band */
  421. else if (tuner_frequency < 180000000) {
  422. band = 1;
  423. mode = 7;
  424. cp = 0;
  425. } else if (tuner_frequency < 195000000) {
  426. band = 1;
  427. mode = 6;
  428. cp = 1;
  429. /* mid band */
  430. } else if (tuner_frequency < 366000000) {
  431. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  432. band = 10;
  433. } else {
  434. band = 2;
  435. }
  436. mode = 7;
  437. cp = 0;
  438. } else if (tuner_frequency < 478000000) {
  439. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  440. band = 10;
  441. } else {
  442. band = 2;
  443. }
  444. mode = 6;
  445. cp = 1;
  446. /* high band */
  447. } else if (tuner_frequency < 662000000) {
  448. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  449. band = 12;
  450. } else {
  451. band = 4;
  452. }
  453. mode = 7;
  454. cp = 0;
  455. } else if (tuner_frequency < 840000000) {
  456. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  457. band = 12;
  458. } else {
  459. band = 4;
  460. }
  461. mode = 6;
  462. cp = 1;
  463. } else {
  464. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
  465. band = 12;
  466. } else {
  467. band = 4;
  468. }
  469. mode = 7;
  470. cp = 1;
  471. }
  472. /* calculate divisor */
  473. /* ((36166000 + Finput) / 166666) rounded! */
  474. divider = (tuner_frequency + 83333) / 166667;
  475. /* setup tuner buffer */
  476. tuner_buf[0] = (divider >> 8) & 0x7f;
  477. tuner_buf[1] = divider & 0xff;
  478. tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
  479. tuner_buf[3] = 0x40 | band;
  480. if (fe->ops.i2c_gate_ctrl)
  481. fe->ops.i2c_gate_ctrl(fe, 1);
  482. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
  483. wprintk("could not write to tuner at addr: 0x%02x\n",
  484. addr << 1);
  485. return -EIO;
  486. }
  487. return 0;
  488. }
  489. static struct tda1004x_config medion_cardbus = {
  490. .demod_address = 0x08,
  491. .invert = 1,
  492. .invert_oclk = 0,
  493. .xtal_freq = TDA10046_XTAL_16M,
  494. .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
  495. .if_freq = TDA10046_FREQ_3613,
  496. .tuner_address = 0x61,
  497. .request_firmware = philips_tda1004x_request_firmware
  498. };
  499. /* ------------------------------------------------------------------
  500. * tda 1004x based cards with philips silicon tuner
  501. */
  502. static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
  503. {
  504. struct saa7134_dev *dev = fe->dvb->priv;
  505. struct tda1004x_state *state = fe->demodulator_priv;
  506. u8 addr = state->config->i2c_gate;
  507. u8 config = state->config->tuner_config;
  508. u8 GP00_CF[] = {0x20, 0x01};
  509. u8 GP00_LEV[] = {0x22, 0x00};
  510. struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
  511. if (config) {
  512. if (high) {
  513. dprintk("setting LNA to high gain\n");
  514. } else {
  515. dprintk("setting LNA to low gain\n");
  516. }
  517. }
  518. switch (config) {
  519. case 0: /* no LNA */
  520. break;
  521. case 1: /* switch is GPIO 0 of tda8290 */
  522. case 2:
  523. /* turn Vsync off */
  524. saa7134_set_gpio(dev, 22, 0);
  525. GP00_LEV[1] = high ? 0 : 1;
  526. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
  527. wprintk("could not access tda8290 at addr: 0x%02x\n",
  528. addr << 1);
  529. return;
  530. }
  531. msg.buf = GP00_LEV;
  532. if (config == 2)
  533. GP00_LEV[1] = high ? 1 : 0;
  534. i2c_transfer(&dev->i2c_adap, &msg, 1);
  535. break;
  536. case 3: /* switch with GPIO of saa713x */
  537. saa7134_set_gpio(dev, 22, high);
  538. break;
  539. }
  540. }
  541. static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
  542. {
  543. struct tda1004x_state *state = fe->demodulator_priv;
  544. u8 addr = state->config->i2c_gate;
  545. static u8 tda8290_close[] = { 0x21, 0xc0};
  546. static u8 tda8290_open[] = { 0x21, 0x80};
  547. struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
  548. if (enable) {
  549. tda8290_msg.buf = tda8290_close;
  550. } else {
  551. tda8290_msg.buf = tda8290_open;
  552. }
  553. if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
  554. struct saa7134_dev *dev = fe->dvb->priv;
  555. wprintk("could not access tda8290 I2C gate\n");
  556. return -EIO;
  557. }
  558. msleep(20);
  559. return 0;
  560. }
  561. /* ------------------------------------------------------------------ */
  562. static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
  563. {
  564. struct saa7134_dev *dev = fe->dvb->priv;
  565. struct tda1004x_state *state = fe->demodulator_priv;
  566. switch (state->config->antenna_switch) {
  567. case 0: break;
  568. case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
  569. saa7134_set_gpio(dev, 21, 0);
  570. break;
  571. case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
  572. saa7134_set_gpio(dev, 21, 1);
  573. break;
  574. }
  575. return 0;
  576. }
  577. static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
  578. {
  579. struct saa7134_dev *dev = fe->dvb->priv;
  580. struct tda1004x_state *state = fe->demodulator_priv;
  581. switch (state->config->antenna_switch) {
  582. case 0: break;
  583. case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
  584. saa7134_set_gpio(dev, 21, 1);
  585. break;
  586. case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
  587. saa7134_set_gpio(dev, 21, 0);
  588. break;
  589. }
  590. return 0;
  591. }
  592. static struct tda827x_config tda827x_cfg = {
  593. .lna_gain = philips_tda827x_lna_gain,
  594. .init = philips_tda827x_tuner_init,
  595. .sleep = philips_tda827x_tuner_sleep
  596. };
  597. static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
  598. {
  599. dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
  600. if (dev->dvb.frontend) {
  601. if (tda_conf->i2c_gate)
  602. dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  603. if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address,
  604. &dev->i2c_adap,&tda827x_cfg) == NULL) {
  605. wprintk("no tda827x tuner found at addr: %02x\n",
  606. tda_conf->tuner_address);
  607. }
  608. }
  609. }
  610. /* ------------------------------------------------------------------ */
  611. static struct tda1004x_config tda827x_lifeview_config = {
  612. .demod_address = 0x08,
  613. .invert = 1,
  614. .invert_oclk = 0,
  615. .xtal_freq = TDA10046_XTAL_16M,
  616. .agc_config = TDA10046_AGC_TDA827X,
  617. .gpio_config = TDA10046_GP11_I,
  618. .if_freq = TDA10046_FREQ_045,
  619. .tuner_address = 0x60,
  620. .request_firmware = philips_tda1004x_request_firmware
  621. };
  622. static struct tda1004x_config philips_tiger_config = {
  623. .demod_address = 0x08,
  624. .invert = 1,
  625. .invert_oclk = 0,
  626. .xtal_freq = TDA10046_XTAL_16M,
  627. .agc_config = TDA10046_AGC_TDA827X,
  628. .gpio_config = TDA10046_GP11_I,
  629. .if_freq = TDA10046_FREQ_045,
  630. .i2c_gate = 0x4b,
  631. .tuner_address = 0x61,
  632. .tuner_config = 0,
  633. .antenna_switch= 1,
  634. .request_firmware = philips_tda1004x_request_firmware
  635. };
  636. static struct tda1004x_config cinergy_ht_config = {
  637. .demod_address = 0x08,
  638. .invert = 1,
  639. .invert_oclk = 0,
  640. .xtal_freq = TDA10046_XTAL_16M,
  641. .agc_config = TDA10046_AGC_TDA827X,
  642. .gpio_config = TDA10046_GP01_I,
  643. .if_freq = TDA10046_FREQ_045,
  644. .i2c_gate = 0x4b,
  645. .tuner_address = 0x61,
  646. .tuner_config = 0,
  647. .request_firmware = philips_tda1004x_request_firmware
  648. };
  649. static struct tda1004x_config cinergy_ht_pci_config = {
  650. .demod_address = 0x08,
  651. .invert = 1,
  652. .invert_oclk = 0,
  653. .xtal_freq = TDA10046_XTAL_16M,
  654. .agc_config = TDA10046_AGC_TDA827X,
  655. .gpio_config = TDA10046_GP01_I,
  656. .if_freq = TDA10046_FREQ_045,
  657. .i2c_gate = 0x4b,
  658. .tuner_address = 0x60,
  659. .tuner_config = 0,
  660. .request_firmware = philips_tda1004x_request_firmware
  661. };
  662. static struct tda1004x_config philips_tiger_s_config = {
  663. .demod_address = 0x08,
  664. .invert = 1,
  665. .invert_oclk = 0,
  666. .xtal_freq = TDA10046_XTAL_16M,
  667. .agc_config = TDA10046_AGC_TDA827X,
  668. .gpio_config = TDA10046_GP01_I,
  669. .if_freq = TDA10046_FREQ_045,
  670. .i2c_gate = 0x4b,
  671. .tuner_address = 0x61,
  672. .tuner_config = 2,
  673. .antenna_switch= 1,
  674. .request_firmware = philips_tda1004x_request_firmware
  675. };
  676. static struct tda1004x_config pinnacle_pctv_310i_config = {
  677. .demod_address = 0x08,
  678. .invert = 1,
  679. .invert_oclk = 0,
  680. .xtal_freq = TDA10046_XTAL_16M,
  681. .agc_config = TDA10046_AGC_TDA827X,
  682. .gpio_config = TDA10046_GP11_I,
  683. .if_freq = TDA10046_FREQ_045,
  684. .i2c_gate = 0x4b,
  685. .tuner_address = 0x61,
  686. .tuner_config = 1,
  687. .request_firmware = philips_tda1004x_request_firmware
  688. };
  689. static struct tda1004x_config hauppauge_hvr_1110_config = {
  690. .demod_address = 0x08,
  691. .invert = 1,
  692. .invert_oclk = 0,
  693. .xtal_freq = TDA10046_XTAL_16M,
  694. .agc_config = TDA10046_AGC_TDA827X,
  695. .gpio_config = TDA10046_GP11_I,
  696. .if_freq = TDA10046_FREQ_045,
  697. .i2c_gate = 0x4b,
  698. .tuner_address = 0x61,
  699. .request_firmware = philips_tda1004x_request_firmware
  700. };
  701. static struct tda1004x_config asus_p7131_dual_config = {
  702. .demod_address = 0x08,
  703. .invert = 1,
  704. .invert_oclk = 0,
  705. .xtal_freq = TDA10046_XTAL_16M,
  706. .agc_config = TDA10046_AGC_TDA827X,
  707. .gpio_config = TDA10046_GP11_I,
  708. .if_freq = TDA10046_FREQ_045,
  709. .i2c_gate = 0x4b,
  710. .tuner_address = 0x61,
  711. .tuner_config = 0,
  712. .antenna_switch= 2,
  713. .request_firmware = philips_tda1004x_request_firmware
  714. };
  715. static struct tda1004x_config lifeview_trio_config = {
  716. .demod_address = 0x09,
  717. .invert = 1,
  718. .invert_oclk = 0,
  719. .xtal_freq = TDA10046_XTAL_16M,
  720. .agc_config = TDA10046_AGC_TDA827X,
  721. .gpio_config = TDA10046_GP00_I,
  722. .if_freq = TDA10046_FREQ_045,
  723. .tuner_address = 0x60,
  724. .request_firmware = philips_tda1004x_request_firmware
  725. };
  726. static struct tda1004x_config tevion_dvbt220rf_config = {
  727. .demod_address = 0x08,
  728. .invert = 1,
  729. .invert_oclk = 0,
  730. .xtal_freq = TDA10046_XTAL_16M,
  731. .agc_config = TDA10046_AGC_TDA827X,
  732. .gpio_config = TDA10046_GP11_I,
  733. .if_freq = TDA10046_FREQ_045,
  734. .tuner_address = 0x60,
  735. .request_firmware = philips_tda1004x_request_firmware
  736. };
  737. static struct tda1004x_config md8800_dvbt_config = {
  738. .demod_address = 0x08,
  739. .invert = 1,
  740. .invert_oclk = 0,
  741. .xtal_freq = TDA10046_XTAL_16M,
  742. .agc_config = TDA10046_AGC_TDA827X,
  743. .gpio_config = TDA10046_GP01_I,
  744. .if_freq = TDA10046_FREQ_045,
  745. .i2c_gate = 0x4b,
  746. .tuner_address = 0x60,
  747. .tuner_config = 0,
  748. .request_firmware = philips_tda1004x_request_firmware
  749. };
  750. static struct tda1004x_config asus_p7131_4871_config = {
  751. .demod_address = 0x08,
  752. .invert = 1,
  753. .invert_oclk = 0,
  754. .xtal_freq = TDA10046_XTAL_16M,
  755. .agc_config = TDA10046_AGC_TDA827X,
  756. .gpio_config = TDA10046_GP01_I,
  757. .if_freq = TDA10046_FREQ_045,
  758. .i2c_gate = 0x4b,
  759. .tuner_address = 0x61,
  760. .tuner_config = 2,
  761. .antenna_switch= 2,
  762. .request_firmware = philips_tda1004x_request_firmware
  763. };
  764. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  765. .demod_address = 0x08,
  766. .invert = 1,
  767. .invert_oclk = 0,
  768. .xtal_freq = TDA10046_XTAL_16M,
  769. .agc_config = TDA10046_AGC_TDA827X,
  770. .gpio_config = TDA10046_GP11_I,
  771. .if_freq = TDA10046_FREQ_045,
  772. .i2c_gate = 0x4b,
  773. .tuner_address = 0x61,
  774. .tuner_config = 2,
  775. .antenna_switch= 2,
  776. .request_firmware = philips_tda1004x_request_firmware
  777. };
  778. static struct tda1004x_config kworld_dvb_t_210_config = {
  779. .demod_address = 0x08,
  780. .invert = 1,
  781. .invert_oclk = 0,
  782. .xtal_freq = TDA10046_XTAL_16M,
  783. .agc_config = TDA10046_AGC_TDA827X,
  784. .gpio_config = TDA10046_GP11_I,
  785. .if_freq = TDA10046_FREQ_045,
  786. .i2c_gate = 0x4b,
  787. .tuner_address = 0x61,
  788. .tuner_config = 2,
  789. .antenna_switch= 1,
  790. .request_firmware = philips_tda1004x_request_firmware
  791. };
  792. /* ------------------------------------------------------------------
  793. * special case: this card uses saa713x GPIO22 for the mode switch
  794. */
  795. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  796. {
  797. struct saa7134_dev *dev = fe->dvb->priv;
  798. philips_tda827x_tuner_init(fe);
  799. /* route TDA8275a AGC input to the channel decoder */
  800. saa7134_set_gpio(dev, 22, 1);
  801. return 0;
  802. }
  803. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  804. {
  805. struct saa7134_dev *dev = fe->dvb->priv;
  806. /* route TDA8275a AGC input to the analog IF chip*/
  807. saa7134_set_gpio(dev, 22, 0);
  808. philips_tda827x_tuner_sleep(fe);
  809. return 0;
  810. }
  811. static struct tda827x_config ads_duo_cfg = {
  812. .lna_gain = philips_tda827x_lna_gain,
  813. .init = ads_duo_tuner_init,
  814. .sleep = ads_duo_tuner_sleep
  815. };
  816. static struct tda1004x_config ads_tech_duo_config = {
  817. .demod_address = 0x08,
  818. .invert = 1,
  819. .invert_oclk = 0,
  820. .xtal_freq = TDA10046_XTAL_16M,
  821. .agc_config = TDA10046_AGC_TDA827X,
  822. .gpio_config = TDA10046_GP00_I,
  823. .if_freq = TDA10046_FREQ_045,
  824. .tuner_address = 0x61,
  825. .request_firmware = philips_tda1004x_request_firmware
  826. };
  827. /* ==================================================================
  828. * tda10086 based DVB-S cards, helper functions
  829. */
  830. static struct tda10086_config flydvbs = {
  831. .demod_address = 0x0e,
  832. .invert = 0,
  833. };
  834. /* ==================================================================
  835. * nxt200x based ATSC cards, helper functions
  836. */
  837. static struct nxt200x_config avertvhda180 = {
  838. .demod_address = 0x0a,
  839. };
  840. static struct nxt200x_config kworldatsc110 = {
  841. .demod_address = 0x0a,
  842. };
  843. /* ==================================================================
  844. * Core code
  845. */
  846. static int dvb_init(struct saa7134_dev *dev)
  847. {
  848. int ret;
  849. /* init struct videobuf_dvb */
  850. dev->ts.nr_bufs = 32;
  851. dev->ts.nr_packets = 32*4;
  852. dev->dvb.name = dev->name;
  853. videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
  854. dev->pci, &dev->slock,
  855. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  856. V4L2_FIELD_ALTERNATE,
  857. sizeof(struct saa7134_buf),
  858. dev);
  859. switch (dev->board) {
  860. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  861. dprintk("pinnacle 300i dvb setup\n");
  862. dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  863. &dev->i2c_adap);
  864. if (dev->dvb.frontend) {
  865. dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  866. }
  867. break;
  868. case SAA7134_BOARD_AVERMEDIA_777:
  869. case SAA7134_BOARD_AVERMEDIA_A16AR:
  870. dprintk("avertv 777 dvb setup\n");
  871. dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  872. &dev->i2c_adap);
  873. if (dev->dvb.frontend) {
  874. dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
  875. }
  876. break;
  877. case SAA7134_BOARD_MD7134:
  878. dev->dvb.frontend = dvb_attach(tda10046_attach,
  879. &medion_cardbus,
  880. &dev->i2c_adap);
  881. if (dev->dvb.frontend) {
  882. dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
  883. dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
  884. dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
  885. }
  886. break;
  887. case SAA7134_BOARD_PHILIPS_TOUGH:
  888. dev->dvb.frontend = dvb_attach(tda10046_attach,
  889. &philips_tu1216_60_config,
  890. &dev->i2c_adap);
  891. if (dev->dvb.frontend) {
  892. dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  893. dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  894. }
  895. break;
  896. case SAA7134_BOARD_FLYDVBTDUO:
  897. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  898. configure_tda827x_fe(dev, &tda827x_lifeview_config);
  899. break;
  900. case SAA7134_BOARD_PHILIPS_EUROPA:
  901. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  902. dev->dvb.frontend = dvb_attach(tda10046_attach,
  903. &philips_europa_config,
  904. &dev->i2c_adap);
  905. if (dev->dvb.frontend) {
  906. dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
  907. dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  908. dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  909. dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  910. dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  911. }
  912. break;
  913. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  914. dev->dvb.frontend = dvb_attach(tda10046_attach,
  915. &philips_tu1216_61_config,
  916. &dev->i2c_adap);
  917. if (dev->dvb.frontend) {
  918. dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  919. dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  920. }
  921. break;
  922. case SAA7134_BOARD_KWORLD_DVBT_210:
  923. configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
  924. break;
  925. case SAA7134_BOARD_PHILIPS_TIGER:
  926. configure_tda827x_fe(dev, &philips_tiger_config);
  927. break;
  928. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  929. configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
  930. break;
  931. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  932. configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
  933. break;
  934. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  935. configure_tda827x_fe(dev, &asus_p7131_dual_config);
  936. break;
  937. case SAA7134_BOARD_FLYDVBT_LR301:
  938. configure_tda827x_fe(dev, &tda827x_lifeview_config);
  939. break;
  940. case SAA7134_BOARD_FLYDVB_TRIO:
  941. if(! use_frontend) { //terrestrial
  942. configure_tda827x_fe(dev, &lifeview_trio_config);
  943. } else { //satellite
  944. dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  945. if (dev->dvb.frontend) {
  946. if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
  947. &dev->i2c_adap, 0) == NULL) {
  948. wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
  949. }
  950. if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
  951. 0x08, 0, 0) == NULL) {
  952. wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
  953. }
  954. }
  955. }
  956. break;
  957. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  958. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  959. dev->dvb.frontend = dvb_attach(tda10046_attach,
  960. &ads_tech_duo_config,
  961. &dev->i2c_adap);
  962. if (dev->dvb.frontend) {
  963. if (dvb_attach(tda827x_attach,dev->dvb.frontend,
  964. ads_tech_duo_config.tuner_address,
  965. &dev->i2c_adap,&ads_duo_cfg) == NULL) {
  966. wprintk("no tda827x tuner found at addr: %02x\n",
  967. ads_tech_duo_config.tuner_address);
  968. }
  969. }
  970. break;
  971. case SAA7134_BOARD_TEVION_DVBT_220RF:
  972. configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
  973. break;
  974. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  975. configure_tda827x_fe(dev, &md8800_dvbt_config);
  976. break;
  977. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  978. dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  979. &dev->i2c_adap);
  980. if (dev->dvb.frontend) {
  981. dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
  982. NULL, &dvb_pll_tdhu2);
  983. }
  984. break;
  985. case SAA7134_BOARD_KWORLD_ATSC110:
  986. dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  987. &dev->i2c_adap);
  988. if (dev->dvb.frontend) {
  989. dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
  990. NULL, &dvb_pll_tuv1236d);
  991. }
  992. break;
  993. case SAA7134_BOARD_FLYDVBS_LR300:
  994. dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  995. &dev->i2c_adap);
  996. if (dev->dvb.frontend) {
  997. if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
  998. &dev->i2c_adap, 0) == NULL) {
  999. wprintk("%s: No tda826x found!\n", __FUNCTION__);
  1000. }
  1001. if (dvb_attach(isl6421_attach, dev->dvb.frontend,
  1002. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1003. wprintk("%s: No ISL6421 found!\n", __FUNCTION__);
  1004. }
  1005. }
  1006. break;
  1007. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1008. dev->dvb.frontend = tda10046_attach(&medion_cardbus,
  1009. &dev->i2c_adap);
  1010. if (dev->dvb.frontend) {
  1011. dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
  1012. dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1013. dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
  1014. dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
  1015. dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
  1016. }
  1017. break;
  1018. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1019. dev->dvb.frontend = dvb_attach(tda10046_attach,
  1020. &philips_europa_config,
  1021. &dev->i2c_adap);
  1022. if (dev->dvb.frontend) {
  1023. dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1024. dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1025. }
  1026. break;
  1027. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1028. configure_tda827x_fe(dev, &cinergy_ht_config);
  1029. break;
  1030. case SAA7134_BOARD_CINERGY_HT_PCI:
  1031. configure_tda827x_fe(dev, &cinergy_ht_pci_config);
  1032. break;
  1033. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1034. configure_tda827x_fe(dev, &philips_tiger_s_config);
  1035. break;
  1036. case SAA7134_BOARD_ASUS_P7131_4871:
  1037. configure_tda827x_fe(dev, &asus_p7131_4871_config);
  1038. break;
  1039. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1040. configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
  1041. break;
  1042. default:
  1043. wprintk("Huh? unknown DVB card?\n");
  1044. break;
  1045. }
  1046. if (NULL == dev->dvb.frontend) {
  1047. printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
  1048. return -1;
  1049. }
  1050. /* register everything else */
  1051. ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
  1052. /* this sequence is necessary to make the tda1004x load its firmware
  1053. * and to enter analog mode of hybrid boards
  1054. */
  1055. if (!ret) {
  1056. if (dev->dvb.frontend->ops.init)
  1057. dev->dvb.frontend->ops.init(dev->dvb.frontend);
  1058. if (dev->dvb.frontend->ops.sleep)
  1059. dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
  1060. if (dev->dvb.frontend->ops.tuner_ops.sleep)
  1061. dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
  1062. }
  1063. return ret;
  1064. }
  1065. static int dvb_fini(struct saa7134_dev *dev)
  1066. {
  1067. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1068. switch (dev->board) {
  1069. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  1070. /* otherwise we don't detect the tuner on next insmod */
  1071. saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
  1072. break;
  1073. };
  1074. videobuf_dvb_unregister(&dev->dvb);
  1075. return 0;
  1076. }
  1077. static struct saa7134_mpeg_ops dvb_ops = {
  1078. .type = SAA7134_MPEG_DVB,
  1079. .init = dvb_init,
  1080. .fini = dvb_fini,
  1081. };
  1082. static int __init dvb_register(void)
  1083. {
  1084. return saa7134_ts_register(&dvb_ops);
  1085. }
  1086. static void __exit dvb_unregister(void)
  1087. {
  1088. saa7134_ts_unregister(&dvb_ops);
  1089. }
  1090. module_init(dvb_register);
  1091. module_exit(dvb_unregister);
  1092. /* ------------------------------------------------------------------ */
  1093. /*
  1094. * Local variables:
  1095. * c-basic-offset: 8
  1096. * End:
  1097. */