saa7134-dvb.c 42 KB

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