saa7134-dvb.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  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. #include "saa7134.h"
  19. #include "saa7134-reg.h"
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/delay.h>
  25. #include <linux/kthread.h>
  26. #include <linux/suspend.h>
  27. #include <media/v4l2-common.h>
  28. #include "dvb-pll.h"
  29. #include <dvb_frontend.h>
  30. #include "mt352.h"
  31. #include "mt352_priv.h" /* FIXME */
  32. #include "tda1004x.h"
  33. #include "nxt200x.h"
  34. #include "tuner-xc2028.h"
  35. #include "xc5000.h"
  36. #include "tda10086.h"
  37. #include "tda826x.h"
  38. #include "tda827x.h"
  39. #include "isl6421.h"
  40. #include "isl6405.h"
  41. #include "lnbp21.h"
  42. #include "tuner-simple.h"
  43. #include "tda10048.h"
  44. #include "tda18271.h"
  45. #include "lgdt3305.h"
  46. #include "tda8290.h"
  47. #include "mb86a20s.h"
  48. #include "lgs8gxx.h"
  49. #include "zl10353.h"
  50. #include "qt1010.h"
  51. #include "zl10036.h"
  52. #include "zl10039.h"
  53. #include "mt312.h"
  54. #include "s5h1411.h"
  55. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  56. MODULE_LICENSE("GPL");
  57. static unsigned int antenna_pwr;
  58. module_param(antenna_pwr, int, 0444);
  59. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  60. static int use_frontend;
  61. module_param(use_frontend, int, 0644);
  62. MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
  63. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  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. pr_debug("%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. pr_debug("%s called\n", __func__);
  101. mt352_write(fe, clock_config, sizeof(clock_config));
  102. udelay(200);
  103. mt352_write(fe, reset, sizeof(reset));
  104. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  105. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  106. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  107. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  108. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  109. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  110. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  111. return 0;
  112. }
  113. static int mt352_aver777_init(struct dvb_frontend* fe)
  114. {
  115. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  116. static u8 reset [] = { RESET, 0x80 };
  117. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  118. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  119. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  120. mt352_write(fe, clock_config, sizeof(clock_config));
  121. udelay(200);
  122. mt352_write(fe, reset, sizeof(reset));
  123. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  124. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  125. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  126. return 0;
  127. }
  128. static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
  129. {
  130. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
  131. static u8 reset [] = { RESET, 0x80 };
  132. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  133. static u8 agc_cfg [] = { AGC_TARGET, 0xe };
  134. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
  135. mt352_write(fe, clock_config, sizeof(clock_config));
  136. udelay(200);
  137. mt352_write(fe, reset, sizeof(reset));
  138. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  139. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  140. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  141. return 0;
  142. }
  143. static int mt352_pinnacle_tuner_set_params(struct dvb_frontend *fe)
  144. {
  145. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  146. u8 off[] = { 0x00, 0xf1};
  147. u8 on[] = { 0x00, 0x71};
  148. struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
  149. struct saa7134_dev *dev = fe->dvb->priv;
  150. struct v4l2_frequency f;
  151. /* set frequency (mt2050) */
  152. f.tuner = 0;
  153. f.type = V4L2_TUNER_DIGITAL_TV;
  154. f.frequency = c->frequency / 1000 * 16 / 1000;
  155. if (fe->ops.i2c_gate_ctrl)
  156. fe->ops.i2c_gate_ctrl(fe, 1);
  157. i2c_transfer(&dev->i2c_adap, &msg, 1);
  158. saa_call_all(dev, tuner, s_frequency, &f);
  159. msg.buf = on;
  160. if (fe->ops.i2c_gate_ctrl)
  161. fe->ops.i2c_gate_ctrl(fe, 1);
  162. i2c_transfer(&dev->i2c_adap, &msg, 1);
  163. pinnacle_antenna_pwr(dev, antenna_pwr);
  164. /* mt352 setup */
  165. return mt352_pinnacle_init(fe);
  166. }
  167. static struct mt352_config pinnacle_300i = {
  168. .demod_address = 0x3c >> 1,
  169. .adc_clock = 20333,
  170. .if2 = 36150,
  171. .no_tuner = 1,
  172. .demod_init = mt352_pinnacle_init,
  173. };
  174. static struct mt352_config avermedia_777 = {
  175. .demod_address = 0xf,
  176. .demod_init = mt352_aver777_init,
  177. };
  178. static struct mt352_config avermedia_xc3028_mt352_dev = {
  179. .demod_address = (0x1e >> 1),
  180. .no_tuner = 1,
  181. .demod_init = mt352_avermedia_xc3028_init,
  182. };
  183. static struct tda18271_std_map mb86a20s_tda18271_std_map = {
  184. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  185. .if_lvl = 7, .rfagc_top = 0x37, },
  186. };
  187. static struct tda18271_config kworld_tda18271_config = {
  188. .std_map = &mb86a20s_tda18271_std_map,
  189. .gate = TDA18271_GATE_DIGITAL,
  190. .config = 3, /* Use tuner callback for AGC */
  191. };
  192. static const struct mb86a20s_config kworld_mb86a20s_config = {
  193. .demod_address = 0x10,
  194. };
  195. static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
  196. {
  197. struct saa7134_dev *dev = fe->dvb->priv;
  198. unsigned char initmsg[] = {0x45, 0x97};
  199. unsigned char msg_enable[] = {0x45, 0xc1};
  200. unsigned char msg_disable[] = {0x45, 0x81};
  201. struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
  202. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
  203. pr_warn("could not access the I2C gate\n");
  204. return -EIO;
  205. }
  206. if (enable)
  207. msg.buf = msg_enable;
  208. else
  209. msg.buf = msg_disable;
  210. if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
  211. pr_warn("could not access the I2C gate\n");
  212. return -EIO;
  213. }
  214. msleep(20);
  215. return 0;
  216. }
  217. /* ==================================================================
  218. * tda1004x based DVB-T cards, helper functions
  219. */
  220. static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
  221. const struct firmware **fw, char *name)
  222. {
  223. struct saa7134_dev *dev = fe->dvb->priv;
  224. return request_firmware(fw, name, &dev->pci->dev);
  225. }
  226. /* ------------------------------------------------------------------
  227. * these tuners are tu1216, td1316(a)
  228. */
  229. static int philips_tda6651_pll_set(struct dvb_frontend *fe)
  230. {
  231. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  232. struct saa7134_dev *dev = fe->dvb->priv;
  233. struct tda1004x_state *state = fe->demodulator_priv;
  234. u8 addr = state->config->tuner_address;
  235. u8 tuner_buf[4];
  236. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
  237. sizeof(tuner_buf) };
  238. int tuner_frequency = 0;
  239. u8 band, cp, filter;
  240. /* determine charge pump */
  241. tuner_frequency = c->frequency + 36166000;
  242. if (tuner_frequency < 87000000)
  243. return -EINVAL;
  244. else if (tuner_frequency < 130000000)
  245. cp = 3;
  246. else if (tuner_frequency < 160000000)
  247. cp = 5;
  248. else if (tuner_frequency < 200000000)
  249. cp = 6;
  250. else if (tuner_frequency < 290000000)
  251. cp = 3;
  252. else if (tuner_frequency < 420000000)
  253. cp = 5;
  254. else if (tuner_frequency < 480000000)
  255. cp = 6;
  256. else if (tuner_frequency < 620000000)
  257. cp = 3;
  258. else if (tuner_frequency < 830000000)
  259. cp = 5;
  260. else if (tuner_frequency < 895000000)
  261. cp = 7;
  262. else
  263. return -EINVAL;
  264. /* determine band */
  265. if (c->frequency < 49000000)
  266. return -EINVAL;
  267. else if (c->frequency < 161000000)
  268. band = 1;
  269. else if (c->frequency < 444000000)
  270. band = 2;
  271. else if (c->frequency < 861000000)
  272. band = 4;
  273. else
  274. return -EINVAL;
  275. /* setup PLL filter */
  276. switch (c->bandwidth_hz) {
  277. case 6000000:
  278. filter = 0;
  279. break;
  280. case 7000000:
  281. filter = 0;
  282. break;
  283. case 8000000:
  284. filter = 1;
  285. break;
  286. default:
  287. return -EINVAL;
  288. }
  289. /* calculate divisor
  290. * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
  291. */
  292. tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;
  293. /* setup tuner buffer */
  294. tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
  295. tuner_buf[1] = tuner_frequency & 0xff;
  296. tuner_buf[2] = 0xca;
  297. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  298. if (fe->ops.i2c_gate_ctrl)
  299. fe->ops.i2c_gate_ctrl(fe, 1);
  300. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
  301. pr_warn("could not write to tuner at addr: 0x%02x\n",
  302. addr << 1);
  303. return -EIO;
  304. }
  305. msleep(1);
  306. return 0;
  307. }
  308. static int philips_tu1216_init(struct dvb_frontend *fe)
  309. {
  310. struct saa7134_dev *dev = fe->dvb->priv;
  311. struct tda1004x_state *state = fe->demodulator_priv;
  312. u8 addr = state->config->tuner_address;
  313. static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  314. struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
  315. /* setup PLL configuration */
  316. if (fe->ops.i2c_gate_ctrl)
  317. fe->ops.i2c_gate_ctrl(fe, 1);
  318. if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
  319. return -EIO;
  320. msleep(1);
  321. return 0;
  322. }
  323. /* ------------------------------------------------------------------ */
  324. static struct tda1004x_config philips_tu1216_60_config = {
  325. .demod_address = 0x8,
  326. .invert = 1,
  327. .invert_oclk = 0,
  328. .xtal_freq = TDA10046_XTAL_4M,
  329. .agc_config = TDA10046_AGC_DEFAULT,
  330. .if_freq = TDA10046_FREQ_3617,
  331. .tuner_address = 0x60,
  332. .request_firmware = philips_tda1004x_request_firmware
  333. };
  334. static struct tda1004x_config philips_tu1216_61_config = {
  335. .demod_address = 0x8,
  336. .invert = 1,
  337. .invert_oclk = 0,
  338. .xtal_freq = TDA10046_XTAL_4M,
  339. .agc_config = TDA10046_AGC_DEFAULT,
  340. .if_freq = TDA10046_FREQ_3617,
  341. .tuner_address = 0x61,
  342. .request_firmware = philips_tda1004x_request_firmware
  343. };
  344. /* ------------------------------------------------------------------ */
  345. static int philips_td1316_tuner_init(struct dvb_frontend *fe)
  346. {
  347. struct saa7134_dev *dev = fe->dvb->priv;
  348. struct tda1004x_state *state = fe->demodulator_priv;
  349. u8 addr = state->config->tuner_address;
  350. static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
  351. struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  352. /* setup PLL configuration */
  353. if (fe->ops.i2c_gate_ctrl)
  354. fe->ops.i2c_gate_ctrl(fe, 1);
  355. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  356. return -EIO;
  357. return 0;
  358. }
  359. static int philips_td1316_tuner_set_params(struct dvb_frontend *fe)
  360. {
  361. return philips_tda6651_pll_set(fe);
  362. }
  363. static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
  364. {
  365. struct saa7134_dev *dev = fe->dvb->priv;
  366. struct tda1004x_state *state = fe->demodulator_priv;
  367. u8 addr = state->config->tuner_address;
  368. static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
  369. struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
  370. /* switch the tuner to analog mode */
  371. if (fe->ops.i2c_gate_ctrl)
  372. fe->ops.i2c_gate_ctrl(fe, 1);
  373. if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
  374. return -EIO;
  375. return 0;
  376. }
  377. /* ------------------------------------------------------------------ */
  378. static int philips_europa_tuner_init(struct dvb_frontend *fe)
  379. {
  380. struct saa7134_dev *dev = fe->dvb->priv;
  381. static u8 msg[] = { 0x00, 0x40};
  382. struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  383. if (philips_td1316_tuner_init(fe))
  384. return -EIO;
  385. msleep(1);
  386. if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
  387. return -EIO;
  388. return 0;
  389. }
  390. static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
  391. {
  392. struct saa7134_dev *dev = fe->dvb->priv;
  393. static u8 msg[] = { 0x00, 0x14 };
  394. struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
  395. if (philips_td1316_tuner_sleep(fe))
  396. return -EIO;
  397. /* switch the board to analog mode */
  398. if (fe->ops.i2c_gate_ctrl)
  399. fe->ops.i2c_gate_ctrl(fe, 1);
  400. i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
  401. return 0;
  402. }
  403. static int philips_europa_demod_sleep(struct dvb_frontend *fe)
  404. {
  405. struct saa7134_dev *dev = fe->dvb->priv;
  406. if (dev->original_demod_sleep)
  407. dev->original_demod_sleep(fe);
  408. fe->ops.i2c_gate_ctrl(fe, 1);
  409. return 0;
  410. }
  411. static struct tda1004x_config philips_europa_config = {
  412. .demod_address = 0x8,
  413. .invert = 0,
  414. .invert_oclk = 0,
  415. .xtal_freq = TDA10046_XTAL_4M,
  416. .agc_config = TDA10046_AGC_IFO_AUTO_POS,
  417. .if_freq = TDA10046_FREQ_052,
  418. .tuner_address = 0x61,
  419. .request_firmware = philips_tda1004x_request_firmware
  420. };
  421. static struct tda1004x_config medion_cardbus = {
  422. .demod_address = 0x08,
  423. .invert = 1,
  424. .invert_oclk = 0,
  425. .xtal_freq = TDA10046_XTAL_16M,
  426. .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
  427. .if_freq = TDA10046_FREQ_3613,
  428. .tuner_address = 0x61,
  429. .request_firmware = philips_tda1004x_request_firmware
  430. };
  431. static struct tda1004x_config technotrend_budget_t3000_config = {
  432. .demod_address = 0x8,
  433. .invert = 1,
  434. .invert_oclk = 0,
  435. .xtal_freq = TDA10046_XTAL_4M,
  436. .agc_config = TDA10046_AGC_DEFAULT,
  437. .if_freq = TDA10046_FREQ_3617,
  438. .tuner_address = 0x63,
  439. .request_firmware = philips_tda1004x_request_firmware
  440. };
  441. /* ------------------------------------------------------------------
  442. * tda 1004x based cards with philips silicon tuner
  443. */
  444. static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
  445. {
  446. struct tda1004x_state *state = fe->demodulator_priv;
  447. u8 addr = state->config->i2c_gate;
  448. static u8 tda8290_close[] = { 0x21, 0xc0};
  449. static u8 tda8290_open[] = { 0x21, 0x80};
  450. struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
  451. if (enable) {
  452. tda8290_msg.buf = tda8290_close;
  453. } else {
  454. tda8290_msg.buf = tda8290_open;
  455. }
  456. if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
  457. pr_warn("could not access tda8290 I2C gate\n");
  458. return -EIO;
  459. }
  460. msleep(20);
  461. return 0;
  462. }
  463. static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
  464. {
  465. struct saa7134_dev *dev = fe->dvb->priv;
  466. struct tda1004x_state *state = fe->demodulator_priv;
  467. switch (state->config->antenna_switch) {
  468. case 0:
  469. break;
  470. case 1:
  471. pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
  472. saa7134_set_gpio(dev, 21, 0);
  473. break;
  474. case 2:
  475. pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
  476. saa7134_set_gpio(dev, 21, 1);
  477. break;
  478. }
  479. return 0;
  480. }
  481. static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
  482. {
  483. struct saa7134_dev *dev = fe->dvb->priv;
  484. struct tda1004x_state *state = fe->demodulator_priv;
  485. switch (state->config->antenna_switch) {
  486. case 0:
  487. break;
  488. case 1:
  489. pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
  490. saa7134_set_gpio(dev, 21, 1);
  491. break;
  492. case 2:
  493. pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
  494. saa7134_set_gpio(dev, 21, 0);
  495. break;
  496. }
  497. return 0;
  498. }
  499. static int configure_tda827x_fe(struct saa7134_dev *dev,
  500. struct tda1004x_config *cdec_conf,
  501. struct tda827x_config *tuner_conf)
  502. {
  503. struct vb2_dvb_frontend *fe0;
  504. /* Get the first frontend */
  505. fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
  506. if (!fe0)
  507. return -EINVAL;
  508. fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
  509. if (fe0->dvb.frontend) {
  510. if (cdec_conf->i2c_gate)
  511. fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
  512. if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
  513. cdec_conf->tuner_address,
  514. &dev->i2c_adap, tuner_conf))
  515. return 0;
  516. pr_warn("no tda827x tuner found at addr: %02x\n",
  517. cdec_conf->tuner_address);
  518. }
  519. return -EINVAL;
  520. }
  521. /* ------------------------------------------------------------------ */
  522. static struct tda827x_config tda827x_cfg_0 = {
  523. .init = philips_tda827x_tuner_init,
  524. .sleep = philips_tda827x_tuner_sleep,
  525. .config = 0,
  526. .switch_addr = 0
  527. };
  528. static struct tda827x_config tda827x_cfg_1 = {
  529. .init = philips_tda827x_tuner_init,
  530. .sleep = philips_tda827x_tuner_sleep,
  531. .config = 1,
  532. .switch_addr = 0x4b
  533. };
  534. static struct tda827x_config tda827x_cfg_2 = {
  535. .init = philips_tda827x_tuner_init,
  536. .sleep = philips_tda827x_tuner_sleep,
  537. .config = 2,
  538. .switch_addr = 0x4b
  539. };
  540. static struct tda827x_config tda827x_cfg_2_sw42 = {
  541. .init = philips_tda827x_tuner_init,
  542. .sleep = philips_tda827x_tuner_sleep,
  543. .config = 2,
  544. .switch_addr = 0x42
  545. };
  546. /* ------------------------------------------------------------------ */
  547. static struct tda1004x_config tda827x_lifeview_config = {
  548. .demod_address = 0x08,
  549. .invert = 1,
  550. .invert_oclk = 0,
  551. .xtal_freq = TDA10046_XTAL_16M,
  552. .agc_config = TDA10046_AGC_TDA827X,
  553. .gpio_config = TDA10046_GP11_I,
  554. .if_freq = TDA10046_FREQ_045,
  555. .tuner_address = 0x60,
  556. .request_firmware = philips_tda1004x_request_firmware
  557. };
  558. static struct tda1004x_config philips_tiger_config = {
  559. .demod_address = 0x08,
  560. .invert = 1,
  561. .invert_oclk = 0,
  562. .xtal_freq = TDA10046_XTAL_16M,
  563. .agc_config = TDA10046_AGC_TDA827X,
  564. .gpio_config = TDA10046_GP11_I,
  565. .if_freq = TDA10046_FREQ_045,
  566. .i2c_gate = 0x4b,
  567. .tuner_address = 0x61,
  568. .antenna_switch= 1,
  569. .request_firmware = philips_tda1004x_request_firmware
  570. };
  571. static struct tda1004x_config cinergy_ht_config = {
  572. .demod_address = 0x08,
  573. .invert = 1,
  574. .invert_oclk = 0,
  575. .xtal_freq = TDA10046_XTAL_16M,
  576. .agc_config = TDA10046_AGC_TDA827X,
  577. .gpio_config = TDA10046_GP01_I,
  578. .if_freq = TDA10046_FREQ_045,
  579. .i2c_gate = 0x4b,
  580. .tuner_address = 0x61,
  581. .request_firmware = philips_tda1004x_request_firmware
  582. };
  583. static struct tda1004x_config cinergy_ht_pci_config = {
  584. .demod_address = 0x08,
  585. .invert = 1,
  586. .invert_oclk = 0,
  587. .xtal_freq = TDA10046_XTAL_16M,
  588. .agc_config = TDA10046_AGC_TDA827X,
  589. .gpio_config = TDA10046_GP01_I,
  590. .if_freq = TDA10046_FREQ_045,
  591. .i2c_gate = 0x4b,
  592. .tuner_address = 0x60,
  593. .request_firmware = philips_tda1004x_request_firmware
  594. };
  595. static struct tda1004x_config philips_tiger_s_config = {
  596. .demod_address = 0x08,
  597. .invert = 1,
  598. .invert_oclk = 0,
  599. .xtal_freq = TDA10046_XTAL_16M,
  600. .agc_config = TDA10046_AGC_TDA827X,
  601. .gpio_config = TDA10046_GP01_I,
  602. .if_freq = TDA10046_FREQ_045,
  603. .i2c_gate = 0x4b,
  604. .tuner_address = 0x61,
  605. .antenna_switch= 1,
  606. .request_firmware = philips_tda1004x_request_firmware
  607. };
  608. static struct tda1004x_config pinnacle_pctv_310i_config = {
  609. .demod_address = 0x08,
  610. .invert = 1,
  611. .invert_oclk = 0,
  612. .xtal_freq = TDA10046_XTAL_16M,
  613. .agc_config = TDA10046_AGC_TDA827X,
  614. .gpio_config = TDA10046_GP11_I,
  615. .if_freq = TDA10046_FREQ_045,
  616. .i2c_gate = 0x4b,
  617. .tuner_address = 0x61,
  618. .request_firmware = philips_tda1004x_request_firmware
  619. };
  620. static struct tda1004x_config hauppauge_hvr_1110_config = {
  621. .demod_address = 0x08,
  622. .invert = 1,
  623. .invert_oclk = 0,
  624. .xtal_freq = TDA10046_XTAL_16M,
  625. .agc_config = TDA10046_AGC_TDA827X,
  626. .gpio_config = TDA10046_GP11_I,
  627. .if_freq = TDA10046_FREQ_045,
  628. .i2c_gate = 0x4b,
  629. .tuner_address = 0x61,
  630. .request_firmware = philips_tda1004x_request_firmware
  631. };
  632. static struct tda1004x_config asus_p7131_dual_config = {
  633. .demod_address = 0x08,
  634. .invert = 1,
  635. .invert_oclk = 0,
  636. .xtal_freq = TDA10046_XTAL_16M,
  637. .agc_config = TDA10046_AGC_TDA827X,
  638. .gpio_config = TDA10046_GP11_I,
  639. .if_freq = TDA10046_FREQ_045,
  640. .i2c_gate = 0x4b,
  641. .tuner_address = 0x61,
  642. .antenna_switch= 2,
  643. .request_firmware = philips_tda1004x_request_firmware
  644. };
  645. static struct tda1004x_config lifeview_trio_config = {
  646. .demod_address = 0x09,
  647. .invert = 1,
  648. .invert_oclk = 0,
  649. .xtal_freq = TDA10046_XTAL_16M,
  650. .agc_config = TDA10046_AGC_TDA827X,
  651. .gpio_config = TDA10046_GP00_I,
  652. .if_freq = TDA10046_FREQ_045,
  653. .tuner_address = 0x60,
  654. .request_firmware = philips_tda1004x_request_firmware
  655. };
  656. static struct tda1004x_config tevion_dvbt220rf_config = {
  657. .demod_address = 0x08,
  658. .invert = 1,
  659. .invert_oclk = 0,
  660. .xtal_freq = TDA10046_XTAL_16M,
  661. .agc_config = TDA10046_AGC_TDA827X,
  662. .gpio_config = TDA10046_GP11_I,
  663. .if_freq = TDA10046_FREQ_045,
  664. .tuner_address = 0x60,
  665. .request_firmware = philips_tda1004x_request_firmware
  666. };
  667. static struct tda1004x_config md8800_dvbt_config = {
  668. .demod_address = 0x08,
  669. .invert = 1,
  670. .invert_oclk = 0,
  671. .xtal_freq = TDA10046_XTAL_16M,
  672. .agc_config = TDA10046_AGC_TDA827X,
  673. .gpio_config = TDA10046_GP01_I,
  674. .if_freq = TDA10046_FREQ_045,
  675. .i2c_gate = 0x4b,
  676. .tuner_address = 0x60,
  677. .request_firmware = philips_tda1004x_request_firmware
  678. };
  679. static struct tda1004x_config asus_p7131_4871_config = {
  680. .demod_address = 0x08,
  681. .invert = 1,
  682. .invert_oclk = 0,
  683. .xtal_freq = TDA10046_XTAL_16M,
  684. .agc_config = TDA10046_AGC_TDA827X,
  685. .gpio_config = TDA10046_GP01_I,
  686. .if_freq = TDA10046_FREQ_045,
  687. .i2c_gate = 0x4b,
  688. .tuner_address = 0x61,
  689. .antenna_switch= 2,
  690. .request_firmware = philips_tda1004x_request_firmware
  691. };
  692. static struct tda1004x_config asus_p7131_hybrid_lna_config = {
  693. .demod_address = 0x08,
  694. .invert = 1,
  695. .invert_oclk = 0,
  696. .xtal_freq = TDA10046_XTAL_16M,
  697. .agc_config = TDA10046_AGC_TDA827X,
  698. .gpio_config = TDA10046_GP11_I,
  699. .if_freq = TDA10046_FREQ_045,
  700. .i2c_gate = 0x4b,
  701. .tuner_address = 0x61,
  702. .antenna_switch= 2,
  703. .request_firmware = philips_tda1004x_request_firmware
  704. };
  705. static struct tda1004x_config kworld_dvb_t_210_config = {
  706. .demod_address = 0x08,
  707. .invert = 1,
  708. .invert_oclk = 0,
  709. .xtal_freq = TDA10046_XTAL_16M,
  710. .agc_config = TDA10046_AGC_TDA827X,
  711. .gpio_config = TDA10046_GP11_I,
  712. .if_freq = TDA10046_FREQ_045,
  713. .i2c_gate = 0x4b,
  714. .tuner_address = 0x61,
  715. .antenna_switch= 1,
  716. .request_firmware = philips_tda1004x_request_firmware
  717. };
  718. static struct tda1004x_config avermedia_super_007_config = {
  719. .demod_address = 0x08,
  720. .invert = 1,
  721. .invert_oclk = 0,
  722. .xtal_freq = TDA10046_XTAL_16M,
  723. .agc_config = TDA10046_AGC_TDA827X,
  724. .gpio_config = TDA10046_GP01_I,
  725. .if_freq = TDA10046_FREQ_045,
  726. .i2c_gate = 0x4b,
  727. .tuner_address = 0x60,
  728. .antenna_switch= 1,
  729. .request_firmware = philips_tda1004x_request_firmware
  730. };
  731. static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
  732. .demod_address = 0x08,
  733. .invert = 1,
  734. .invert_oclk = 0,
  735. .xtal_freq = TDA10046_XTAL_16M,
  736. .agc_config = TDA10046_AGC_TDA827X,
  737. .gpio_config = TDA10046_GP01_I,
  738. .if_freq = TDA10046_FREQ_045,
  739. .i2c_gate = 0x42,
  740. .tuner_address = 0x61,
  741. .antenna_switch = 1,
  742. .request_firmware = philips_tda1004x_request_firmware
  743. };
  744. static struct tda1004x_config asus_tiger_3in1_config = {
  745. .demod_address = 0x0b,
  746. .invert = 1,
  747. .invert_oclk = 0,
  748. .xtal_freq = TDA10046_XTAL_16M,
  749. .agc_config = TDA10046_AGC_TDA827X,
  750. .gpio_config = TDA10046_GP11_I,
  751. .if_freq = TDA10046_FREQ_045,
  752. .i2c_gate = 0x4b,
  753. .tuner_address = 0x61,
  754. .antenna_switch = 1,
  755. .request_firmware = philips_tda1004x_request_firmware
  756. };
  757. static struct tda1004x_config asus_ps3_100_config = {
  758. .demod_address = 0x0b,
  759. .invert = 1,
  760. .invert_oclk = 0,
  761. .xtal_freq = TDA10046_XTAL_16M,
  762. .agc_config = TDA10046_AGC_TDA827X,
  763. .gpio_config = TDA10046_GP11_I,
  764. .if_freq = TDA10046_FREQ_045,
  765. .i2c_gate = 0x4b,
  766. .tuner_address = 0x61,
  767. .antenna_switch = 1,
  768. .request_firmware = philips_tda1004x_request_firmware
  769. };
  770. /* ------------------------------------------------------------------
  771. * special case: this card uses saa713x GPIO22 for the mode switch
  772. */
  773. static int ads_duo_tuner_init(struct dvb_frontend *fe)
  774. {
  775. struct saa7134_dev *dev = fe->dvb->priv;
  776. philips_tda827x_tuner_init(fe);
  777. /* route TDA8275a AGC input to the channel decoder */
  778. saa7134_set_gpio(dev, 22, 1);
  779. return 0;
  780. }
  781. static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
  782. {
  783. struct saa7134_dev *dev = fe->dvb->priv;
  784. /* route TDA8275a AGC input to the analog IF chip*/
  785. saa7134_set_gpio(dev, 22, 0);
  786. philips_tda827x_tuner_sleep(fe);
  787. return 0;
  788. }
  789. static struct tda827x_config ads_duo_cfg = {
  790. .init = ads_duo_tuner_init,
  791. .sleep = ads_duo_tuner_sleep,
  792. .config = 0
  793. };
  794. static struct tda1004x_config ads_tech_duo_config = {
  795. .demod_address = 0x08,
  796. .invert = 1,
  797. .invert_oclk = 0,
  798. .xtal_freq = TDA10046_XTAL_16M,
  799. .agc_config = TDA10046_AGC_TDA827X,
  800. .gpio_config = TDA10046_GP00_I,
  801. .if_freq = TDA10046_FREQ_045,
  802. .tuner_address = 0x61,
  803. .request_firmware = philips_tda1004x_request_firmware
  804. };
  805. static struct zl10353_config behold_h6_config = {
  806. .demod_address = 0x1e>>1,
  807. .no_tuner = 1,
  808. .parallel_ts = 1,
  809. .disable_i2c_gate_ctrl = 1,
  810. };
  811. static struct xc5000_config behold_x7_tunerconfig = {
  812. .i2c_address = 0xc2>>1,
  813. .if_khz = 4560,
  814. .radio_input = XC5000_RADIO_FM1,
  815. };
  816. static struct zl10353_config behold_x7_config = {
  817. .demod_address = 0x1e>>1,
  818. .if2 = 45600,
  819. .no_tuner = 1,
  820. .parallel_ts = 1,
  821. .disable_i2c_gate_ctrl = 1,
  822. };
  823. static struct zl10353_config videomate_t750_zl10353_config = {
  824. .demod_address = 0x0f,
  825. .no_tuner = 1,
  826. .parallel_ts = 1,
  827. .disable_i2c_gate_ctrl = 1,
  828. };
  829. static struct qt1010_config videomate_t750_qt1010_config = {
  830. .i2c_address = 0x62
  831. };
  832. /* ==================================================================
  833. * tda10086 based DVB-S cards, helper functions
  834. */
  835. static struct tda10086_config flydvbs = {
  836. .demod_address = 0x0e,
  837. .invert = 0,
  838. .diseqc_tone = 0,
  839. .xtal_freq = TDA10086_XTAL_16M,
  840. };
  841. static struct tda10086_config sd1878_4m = {
  842. .demod_address = 0x0e,
  843. .invert = 0,
  844. .diseqc_tone = 0,
  845. .xtal_freq = TDA10086_XTAL_4M,
  846. };
  847. /* ------------------------------------------------------------------
  848. * special case: lnb supply is connected to the gated i2c
  849. */
  850. static int md8800_set_voltage(struct dvb_frontend *fe,
  851. enum fe_sec_voltage voltage)
  852. {
  853. int res = -EIO;
  854. struct saa7134_dev *dev = fe->dvb->priv;
  855. if (fe->ops.i2c_gate_ctrl) {
  856. fe->ops.i2c_gate_ctrl(fe, 1);
  857. if (dev->original_set_voltage)
  858. res = dev->original_set_voltage(fe, voltage);
  859. fe->ops.i2c_gate_ctrl(fe, 0);
  860. }
  861. return res;
  862. };
  863. static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
  864. {
  865. int res = -EIO;
  866. struct saa7134_dev *dev = fe->dvb->priv;
  867. if (fe->ops.i2c_gate_ctrl) {
  868. fe->ops.i2c_gate_ctrl(fe, 1);
  869. if (dev->original_set_high_voltage)
  870. res = dev->original_set_high_voltage(fe, arg);
  871. fe->ops.i2c_gate_ctrl(fe, 0);
  872. }
  873. return res;
  874. };
  875. static int md8800_set_voltage2(struct dvb_frontend *fe,
  876. enum fe_sec_voltage voltage)
  877. {
  878. struct saa7134_dev *dev = fe->dvb->priv;
  879. u8 wbuf[2] = { 0x1f, 00 };
  880. u8 rbuf;
  881. struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
  882. { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
  883. if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
  884. return -EIO;
  885. /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
  886. if (voltage == SEC_VOLTAGE_18)
  887. wbuf[1] = rbuf | 0x10;
  888. else
  889. wbuf[1] = rbuf & 0xef;
  890. msg[0].len = 2;
  891. i2c_transfer(&dev->i2c_adap, msg, 1);
  892. return 0;
  893. }
  894. static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
  895. {
  896. pr_warn("%s: sorry can't set high LNB supply voltage from here\n",
  897. __func__);
  898. return -EIO;
  899. }
  900. /* ==================================================================
  901. * nxt200x based ATSC cards, helper functions
  902. */
  903. static struct nxt200x_config avertvhda180 = {
  904. .demod_address = 0x0a,
  905. };
  906. static struct nxt200x_config kworldatsc110 = {
  907. .demod_address = 0x0a,
  908. };
  909. /* ------------------------------------------------------------------ */
  910. static struct mt312_config avertv_a700_mt312 = {
  911. .demod_address = 0x0e,
  912. .voltage_inverted = 1,
  913. };
  914. static struct zl10036_config avertv_a700_tuner = {
  915. .tuner_address = 0x60,
  916. };
  917. static struct mt312_config zl10313_compro_s350_config = {
  918. .demod_address = 0x0e,
  919. };
  920. static struct mt312_config zl10313_avermedia_a706_config = {
  921. .demod_address = 0x0e,
  922. };
  923. static struct lgdt3305_config hcw_lgdt3305_config = {
  924. .i2c_addr = 0x0e,
  925. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  926. .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
  927. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  928. .deny_i2c_rptr = 1,
  929. .spectral_inversion = 1,
  930. .qam_if_khz = 4000,
  931. .vsb_if_khz = 3250,
  932. };
  933. static struct tda10048_config hcw_tda10048_config = {
  934. .demod_address = 0x10 >> 1,
  935. .output_mode = TDA10048_SERIAL_OUTPUT,
  936. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  937. .inversion = TDA10048_INVERSION_ON,
  938. .dtv6_if_freq_khz = TDA10048_IF_3300,
  939. .dtv7_if_freq_khz = TDA10048_IF_3500,
  940. .dtv8_if_freq_khz = TDA10048_IF_4000,
  941. .clk_freq_khz = TDA10048_CLK_16000,
  942. .disable_gate_access = 1,
  943. };
  944. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  945. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
  946. .if_lvl = 1, .rfagc_top = 0x58, },
  947. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  948. .if_lvl = 1, .rfagc_top = 0x58, },
  949. };
  950. static struct tda18271_config hcw_tda18271_config = {
  951. .std_map = &hauppauge_tda18271_std_map,
  952. .gate = TDA18271_GATE_ANALOG,
  953. .config = 3,
  954. .output_opt = TDA18271_OUTPUT_LT_OFF,
  955. };
  956. static struct tda829x_config tda829x_no_probe = {
  957. .probe_tuner = TDA829X_DONT_PROBE,
  958. };
  959. static struct tda10048_config zolid_tda10048_config = {
  960. .demod_address = 0x10 >> 1,
  961. .output_mode = TDA10048_PARALLEL_OUTPUT,
  962. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  963. .inversion = TDA10048_INVERSION_ON,
  964. .dtv6_if_freq_khz = TDA10048_IF_3300,
  965. .dtv7_if_freq_khz = TDA10048_IF_3500,
  966. .dtv8_if_freq_khz = TDA10048_IF_4000,
  967. .clk_freq_khz = TDA10048_CLK_16000,
  968. .disable_gate_access = 1,
  969. };
  970. static struct tda18271_config zolid_tda18271_config = {
  971. .gate = TDA18271_GATE_ANALOG,
  972. };
  973. static struct tda10048_config dtv1000s_tda10048_config = {
  974. .demod_address = 0x10 >> 1,
  975. .output_mode = TDA10048_PARALLEL_OUTPUT,
  976. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  977. .inversion = TDA10048_INVERSION_ON,
  978. .dtv6_if_freq_khz = TDA10048_IF_3300,
  979. .dtv7_if_freq_khz = TDA10048_IF_3800,
  980. .dtv8_if_freq_khz = TDA10048_IF_4300,
  981. .clk_freq_khz = TDA10048_CLK_16000,
  982. .disable_gate_access = 1,
  983. };
  984. static struct tda18271_std_map dtv1000s_tda18271_std_map = {
  985. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  986. .if_lvl = 1, .rfagc_top = 0x37, },
  987. .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
  988. .if_lvl = 1, .rfagc_top = 0x37, },
  989. .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
  990. .if_lvl = 1, .rfagc_top = 0x37, },
  991. };
  992. static struct tda18271_config dtv1000s_tda18271_config = {
  993. .std_map = &dtv1000s_tda18271_std_map,
  994. .gate = TDA18271_GATE_ANALOG,
  995. };
  996. static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = {
  997. .prod = LGS8GXX_PROD_LGS8G75,
  998. .demod_address = 0x1d,
  999. .serial_ts = 0,
  1000. .ts_clk_pol = 1,
  1001. .ts_clk_gated = 0,
  1002. .if_clk_freq = 30400, /* 30.4 MHz */
  1003. .if_freq = 4000, /* 4.00 MHz */
  1004. .if_neg_center = 0,
  1005. .ext_adc = 0,
  1006. .adc_signed = 1,
  1007. .adc_vpp = 3, /* 2.0 Vpp */
  1008. .if_neg_edge = 1,
  1009. };
  1010. static struct tda18271_config prohdtv_pro2_tda18271_config = {
  1011. .gate = TDA18271_GATE_ANALOG,
  1012. .output_opt = TDA18271_OUTPUT_LT_OFF,
  1013. };
  1014. static struct tda18271_std_map kworld_tda18271_std_map = {
  1015. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3,
  1016. .if_lvl = 6, .rfagc_top = 0x37 },
  1017. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  1018. .if_lvl = 6, .rfagc_top = 0x37 },
  1019. };
  1020. static struct tda18271_config kworld_pc150u_tda18271_config = {
  1021. .std_map = &kworld_tda18271_std_map,
  1022. .gate = TDA18271_GATE_ANALOG,
  1023. .output_opt = TDA18271_OUTPUT_LT_OFF,
  1024. .config = 3, /* Use tuner callback for AGC */
  1025. .rf_cal_on_startup = 1
  1026. };
  1027. static struct s5h1411_config kworld_s5h1411_config = {
  1028. .output_mode = S5H1411_PARALLEL_OUTPUT,
  1029. .gpio = S5H1411_GPIO_OFF,
  1030. .qam_if = S5H1411_IF_4000,
  1031. .vsb_if = S5H1411_IF_3250,
  1032. .inversion = S5H1411_INVERSION_ON,
  1033. .status_mode = S5H1411_DEMODLOCKING,
  1034. .mpeg_timing =
  1035. S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  1036. };
  1037. /* ==================================================================
  1038. * Core code
  1039. */
  1040. static int dvb_init(struct saa7134_dev *dev)
  1041. {
  1042. int ret;
  1043. int attach_xc3028 = 0;
  1044. struct vb2_dvb_frontend *fe0;
  1045. struct vb2_queue *q;
  1046. /* FIXME: add support for multi-frontend */
  1047. mutex_init(&dev->frontends.lock);
  1048. INIT_LIST_HEAD(&dev->frontends.felist);
  1049. pr_info("%s() allocating 1 frontend\n", __func__);
  1050. fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);
  1051. if (!fe0) {
  1052. pr_err("%s() failed to alloc\n", __func__);
  1053. return -ENOMEM;
  1054. }
  1055. /* init struct vb2_dvb */
  1056. dev->ts.nr_bufs = 32;
  1057. dev->ts.nr_packets = 32*4;
  1058. fe0->dvb.name = dev->name;
  1059. q = &fe0->dvb.dvbq;
  1060. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1061. q->io_modes = VB2_MMAP | VB2_READ;
  1062. q->drv_priv = &dev->ts_q;
  1063. q->ops = &saa7134_ts_qops;
  1064. q->mem_ops = &vb2_dma_sg_memops;
  1065. q->buf_struct_size = sizeof(struct saa7134_buf);
  1066. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  1067. q->lock = &dev->lock;
  1068. q->dev = &dev->pci->dev;
  1069. ret = vb2_queue_init(q);
  1070. if (ret) {
  1071. vb2_dvb_dealloc_frontends(&dev->frontends);
  1072. return ret;
  1073. }
  1074. switch (dev->board) {
  1075. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  1076. pr_debug("pinnacle 300i dvb setup\n");
  1077. fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
  1078. &dev->i2c_adap);
  1079. if (fe0->dvb.frontend) {
  1080. fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
  1081. }
  1082. break;
  1083. case SAA7134_BOARD_AVERMEDIA_777:
  1084. case SAA7134_BOARD_AVERMEDIA_A16AR:
  1085. pr_debug("avertv 777 dvb setup\n");
  1086. fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
  1087. &dev->i2c_adap);
  1088. if (fe0->dvb.frontend) {
  1089. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1090. &dev->i2c_adap, 0x61,
  1091. TUNER_PHILIPS_TD1316);
  1092. }
  1093. break;
  1094. case SAA7134_BOARD_AVERMEDIA_A16D:
  1095. pr_debug("AverMedia A16D dvb setup\n");
  1096. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1097. &avermedia_xc3028_mt352_dev,
  1098. &dev->i2c_adap);
  1099. attach_xc3028 = 1;
  1100. break;
  1101. case SAA7134_BOARD_MD7134:
  1102. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1103. &medion_cardbus,
  1104. &dev->i2c_adap);
  1105. if (fe0->dvb.frontend) {
  1106. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1107. &dev->i2c_adap, medion_cardbus.tuner_address,
  1108. TUNER_PHILIPS_FMD1216ME_MK3);
  1109. }
  1110. break;
  1111. case SAA7134_BOARD_PHILIPS_TOUGH:
  1112. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1113. &philips_tu1216_60_config,
  1114. &dev->i2c_adap);
  1115. if (fe0->dvb.frontend) {
  1116. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  1117. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  1118. }
  1119. break;
  1120. case SAA7134_BOARD_FLYDVBTDUO:
  1121. case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
  1122. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  1123. &tda827x_cfg_0) < 0)
  1124. goto detach_frontend;
  1125. break;
  1126. case SAA7134_BOARD_PHILIPS_EUROPA:
  1127. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  1128. case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
  1129. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1130. &philips_europa_config,
  1131. &dev->i2c_adap);
  1132. if (fe0->dvb.frontend) {
  1133. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1134. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1135. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  1136. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  1137. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1138. }
  1139. break;
  1140. case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
  1141. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1142. &technotrend_budget_t3000_config,
  1143. &dev->i2c_adap);
  1144. if (fe0->dvb.frontend) {
  1145. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1146. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1147. fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
  1148. fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
  1149. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1150. }
  1151. break;
  1152. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  1153. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1154. &philips_tu1216_61_config,
  1155. &dev->i2c_adap);
  1156. if (fe0->dvb.frontend) {
  1157. fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
  1158. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
  1159. }
  1160. break;
  1161. case SAA7134_BOARD_KWORLD_DVBT_210:
  1162. if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
  1163. &tda827x_cfg_2) < 0)
  1164. goto detach_frontend;
  1165. break;
  1166. case SAA7134_BOARD_HAUPPAUGE_HVR1120:
  1167. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1168. &hcw_tda10048_config,
  1169. &dev->i2c_adap);
  1170. if (fe0->dvb.frontend != NULL) {
  1171. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1172. &dev->i2c_adap, 0x4b,
  1173. &tda829x_no_probe);
  1174. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1175. 0x60, &dev->i2c_adap,
  1176. &hcw_tda18271_config);
  1177. }
  1178. break;
  1179. case SAA7134_BOARD_PHILIPS_TIGER:
  1180. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1181. &tda827x_cfg_0) < 0)
  1182. goto detach_frontend;
  1183. break;
  1184. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  1185. if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
  1186. &tda827x_cfg_1) < 0)
  1187. goto detach_frontend;
  1188. break;
  1189. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  1190. if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
  1191. &tda827x_cfg_1) < 0)
  1192. goto detach_frontend;
  1193. break;
  1194. case SAA7134_BOARD_HAUPPAUGE_HVR1150:
  1195. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  1196. &hcw_lgdt3305_config,
  1197. &dev->i2c_adap);
  1198. if (fe0->dvb.frontend) {
  1199. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1200. &dev->i2c_adap, 0x4b,
  1201. &tda829x_no_probe);
  1202. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1203. 0x60, &dev->i2c_adap,
  1204. &hcw_tda18271_config);
  1205. }
  1206. break;
  1207. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  1208. if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
  1209. &tda827x_cfg_0) < 0)
  1210. goto detach_frontend;
  1211. break;
  1212. case SAA7134_BOARD_FLYDVBT_LR301:
  1213. if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
  1214. &tda827x_cfg_0) < 0)
  1215. goto detach_frontend;
  1216. break;
  1217. case SAA7134_BOARD_FLYDVB_TRIO:
  1218. if (!use_frontend) { /* terrestrial */
  1219. if (configure_tda827x_fe(dev, &lifeview_trio_config,
  1220. &tda827x_cfg_0) < 0)
  1221. goto detach_frontend;
  1222. } else { /* satellite */
  1223. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
  1224. if (fe0->dvb.frontend) {
  1225. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
  1226. &dev->i2c_adap, 0) == NULL) {
  1227. pr_warn("%s: Lifeview Trio, No tda826x found!\n",
  1228. __func__);
  1229. goto detach_frontend;
  1230. }
  1231. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1232. &dev->i2c_adap,
  1233. 0x08, 0, 0, false) == NULL) {
  1234. pr_warn("%s: Lifeview Trio, No ISL6421 found!\n",
  1235. __func__);
  1236. goto detach_frontend;
  1237. }
  1238. }
  1239. }
  1240. break;
  1241. case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
  1242. case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
  1243. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1244. &ads_tech_duo_config,
  1245. &dev->i2c_adap);
  1246. if (fe0->dvb.frontend) {
  1247. if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
  1248. ads_tech_duo_config.tuner_address, &dev->i2c_adap,
  1249. &ads_duo_cfg) == NULL) {
  1250. pr_warn("no tda827x tuner found at addr: %02x\n",
  1251. ads_tech_duo_config.tuner_address);
  1252. goto detach_frontend;
  1253. }
  1254. } else
  1255. pr_warn("failed to attach tda10046\n");
  1256. break;
  1257. case SAA7134_BOARD_TEVION_DVBT_220RF:
  1258. if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
  1259. &tda827x_cfg_0) < 0)
  1260. goto detach_frontend;
  1261. break;
  1262. case SAA7134_BOARD_MEDION_MD8800_QUADRO:
  1263. if (!use_frontend) { /* terrestrial */
  1264. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1265. &tda827x_cfg_0) < 0)
  1266. goto detach_frontend;
  1267. } else { /* satellite */
  1268. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1269. &flydvbs, &dev->i2c_adap);
  1270. if (fe0->dvb.frontend) {
  1271. struct dvb_frontend *fe = fe0->dvb.frontend;
  1272. u8 dev_id = dev->eedata[2];
  1273. u8 data = 0xc4;
  1274. struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
  1275. if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
  1276. 0x60, &dev->i2c_adap, 0) == NULL) {
  1277. pr_warn("%s: Medion Quadro, no tda826x found !\n",
  1278. __func__);
  1279. goto detach_frontend;
  1280. }
  1281. if (dev_id != 0x08) {
  1282. /* we need to open the i2c gate (we know it exists) */
  1283. fe->ops.i2c_gate_ctrl(fe, 1);
  1284. if (dvb_attach(isl6405_attach, fe,
  1285. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1286. pr_warn("%s: Medion Quadro, no ISL6405 found !\n",
  1287. __func__);
  1288. goto detach_frontend;
  1289. }
  1290. if (dev_id == 0x07) {
  1291. /* fire up the 2nd section of the LNB supply since
  1292. we can't do this from the other section */
  1293. msg.buf = &data;
  1294. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1295. }
  1296. fe->ops.i2c_gate_ctrl(fe, 0);
  1297. dev->original_set_voltage = fe->ops.set_voltage;
  1298. fe->ops.set_voltage = md8800_set_voltage;
  1299. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1300. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1301. } else {
  1302. fe->ops.set_voltage = md8800_set_voltage2;
  1303. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
  1304. }
  1305. }
  1306. }
  1307. break;
  1308. case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
  1309. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
  1310. &dev->i2c_adap);
  1311. if (fe0->dvb.frontend)
  1312. dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
  1313. NULL, DVB_PLL_TDHU2);
  1314. break;
  1315. case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
  1316. case SAA7134_BOARD_KWORLD_ATSC110:
  1317. fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
  1318. &dev->i2c_adap);
  1319. if (fe0->dvb.frontend)
  1320. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1321. &dev->i2c_adap, 0x61,
  1322. TUNER_PHILIPS_TUV1236D);
  1323. break;
  1324. case SAA7134_BOARD_KWORLD_PC150U:
  1325. saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */
  1326. saa7134_tuner_callback(dev, 0,
  1327. TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
  1328. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1329. &kworld_s5h1411_config,
  1330. &dev->i2c_adap);
  1331. if (fe0->dvb.frontend != NULL) {
  1332. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1333. &dev->i2c_adap, 0x4b,
  1334. &tda829x_no_probe);
  1335. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1336. 0x60, &dev->i2c_adap,
  1337. &kworld_pc150u_tda18271_config);
  1338. }
  1339. break;
  1340. case SAA7134_BOARD_FLYDVBS_LR300:
  1341. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1342. &dev->i2c_adap);
  1343. if (fe0->dvb.frontend) {
  1344. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1345. &dev->i2c_adap, 0) == NULL) {
  1346. pr_warn("%s: No tda826x found!\n", __func__);
  1347. goto detach_frontend;
  1348. }
  1349. if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1350. &dev->i2c_adap,
  1351. 0x08, 0, 0, false) == NULL) {
  1352. pr_warn("%s: No ISL6421 found!\n", __func__);
  1353. goto detach_frontend;
  1354. }
  1355. }
  1356. break;
  1357. case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
  1358. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1359. &medion_cardbus,
  1360. &dev->i2c_adap);
  1361. if (fe0->dvb.frontend) {
  1362. dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
  1363. fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
  1364. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1365. &dev->i2c_adap, medion_cardbus.tuner_address,
  1366. TUNER_PHILIPS_FMD1216ME_MK3);
  1367. }
  1368. break;
  1369. case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
  1370. fe0->dvb.frontend = dvb_attach(tda10046_attach,
  1371. &philips_europa_config,
  1372. &dev->i2c_adap);
  1373. if (fe0->dvb.frontend) {
  1374. fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
  1375. fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
  1376. }
  1377. break;
  1378. case SAA7134_BOARD_CINERGY_HT_PCMCIA:
  1379. if (configure_tda827x_fe(dev, &cinergy_ht_config,
  1380. &tda827x_cfg_0) < 0)
  1381. goto detach_frontend;
  1382. break;
  1383. case SAA7134_BOARD_CINERGY_HT_PCI:
  1384. if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
  1385. &tda827x_cfg_0) < 0)
  1386. goto detach_frontend;
  1387. break;
  1388. case SAA7134_BOARD_PHILIPS_TIGER_S:
  1389. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1390. &tda827x_cfg_2) < 0)
  1391. goto detach_frontend;
  1392. break;
  1393. case SAA7134_BOARD_ASUS_P7131_4871:
  1394. if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
  1395. &tda827x_cfg_2) < 0)
  1396. goto detach_frontend;
  1397. break;
  1398. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  1399. if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
  1400. &tda827x_cfg_2) < 0)
  1401. goto detach_frontend;
  1402. break;
  1403. case SAA7134_BOARD_AVERMEDIA_SUPER_007:
  1404. if (configure_tda827x_fe(dev, &avermedia_super_007_config,
  1405. &tda827x_cfg_0) < 0)
  1406. goto detach_frontend;
  1407. break;
  1408. case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
  1409. if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
  1410. &tda827x_cfg_2_sw42) < 0)
  1411. goto detach_frontend;
  1412. break;
  1413. case SAA7134_BOARD_PHILIPS_SNAKE:
  1414. fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
  1415. &dev->i2c_adap);
  1416. if (fe0->dvb.frontend) {
  1417. if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
  1418. &dev->i2c_adap, 0) == NULL) {
  1419. pr_warn("%s: No tda826x found!\n", __func__);
  1420. goto detach_frontend;
  1421. }
  1422. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1423. &dev->i2c_adap, 0, 0) == NULL) {
  1424. pr_warn("%s: No lnbp21 found!\n", __func__);
  1425. goto detach_frontend;
  1426. }
  1427. }
  1428. break;
  1429. case SAA7134_BOARD_CREATIX_CTX953:
  1430. if (configure_tda827x_fe(dev, &md8800_dvbt_config,
  1431. &tda827x_cfg_0) < 0)
  1432. goto detach_frontend;
  1433. break;
  1434. case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
  1435. if (configure_tda827x_fe(dev, &philips_tiger_s_config,
  1436. &tda827x_cfg_2) < 0)
  1437. goto detach_frontend;
  1438. break;
  1439. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  1440. pr_debug("AverMedia E506R dvb setup\n");
  1441. saa7134_set_gpio(dev, 25, 0);
  1442. msleep(10);
  1443. saa7134_set_gpio(dev, 25, 1);
  1444. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1445. &avermedia_xc3028_mt352_dev,
  1446. &dev->i2c_adap);
  1447. attach_xc3028 = 1;
  1448. break;
  1449. case SAA7134_BOARD_MD7134_BRIDGE_2:
  1450. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1451. &sd1878_4m, &dev->i2c_adap);
  1452. if (fe0->dvb.frontend) {
  1453. struct dvb_frontend *fe;
  1454. if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1455. &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
  1456. pr_warn("%s: MD7134 DVB-S, no SD1878 found !\n",
  1457. __func__);
  1458. goto detach_frontend;
  1459. }
  1460. /* we need to open the i2c gate (we know it exists) */
  1461. fe = fe0->dvb.frontend;
  1462. fe->ops.i2c_gate_ctrl(fe, 1);
  1463. if (dvb_attach(isl6405_attach, fe,
  1464. &dev->i2c_adap, 0x08, 0, 0) == NULL) {
  1465. pr_warn("%s: MD7134 DVB-S, no ISL6405 found !\n",
  1466. __func__);
  1467. goto detach_frontend;
  1468. }
  1469. fe->ops.i2c_gate_ctrl(fe, 0);
  1470. dev->original_set_voltage = fe->ops.set_voltage;
  1471. fe->ops.set_voltage = md8800_set_voltage;
  1472. dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
  1473. fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
  1474. }
  1475. break;
  1476. case SAA7134_BOARD_AVERMEDIA_M103:
  1477. saa7134_set_gpio(dev, 25, 0);
  1478. msleep(10);
  1479. saa7134_set_gpio(dev, 25, 1);
  1480. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1481. &avermedia_xc3028_mt352_dev,
  1482. &dev->i2c_adap);
  1483. attach_xc3028 = 1;
  1484. break;
  1485. case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
  1486. if (!use_frontend) { /* terrestrial */
  1487. if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
  1488. &tda827x_cfg_2) < 0)
  1489. goto detach_frontend;
  1490. } else { /* satellite */
  1491. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1492. &flydvbs, &dev->i2c_adap);
  1493. if (fe0->dvb.frontend) {
  1494. if (dvb_attach(tda826x_attach,
  1495. fe0->dvb.frontend, 0x60,
  1496. &dev->i2c_adap, 0) == NULL) {
  1497. pr_warn("%s: Asus Tiger 3in1, no tda826x found!\n",
  1498. __func__);
  1499. goto detach_frontend;
  1500. }
  1501. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1502. &dev->i2c_adap, 0, 0) == NULL) {
  1503. pr_warn("%s: Asus Tiger 3in1, no lnbp21 found!\n",
  1504. __func__);
  1505. goto detach_frontend;
  1506. }
  1507. }
  1508. }
  1509. break;
  1510. case SAA7134_BOARD_ASUSTeK_PS3_100:
  1511. if (!use_frontend) { /* terrestrial */
  1512. if (configure_tda827x_fe(dev, &asus_ps3_100_config,
  1513. &tda827x_cfg_2) < 0)
  1514. goto detach_frontend;
  1515. } else { /* satellite */
  1516. fe0->dvb.frontend = dvb_attach(tda10086_attach,
  1517. &flydvbs, &dev->i2c_adap);
  1518. if (fe0->dvb.frontend) {
  1519. if (dvb_attach(tda826x_attach,
  1520. fe0->dvb.frontend, 0x60,
  1521. &dev->i2c_adap, 0) == NULL) {
  1522. pr_warn("%s: Asus My Cinema PS3-100, no tda826x found!\n",
  1523. __func__);
  1524. goto detach_frontend;
  1525. }
  1526. if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
  1527. &dev->i2c_adap, 0, 0) == NULL) {
  1528. pr_warn("%s: Asus My Cinema PS3-100, no lnbp21 found!\n",
  1529. __func__);
  1530. goto detach_frontend;
  1531. }
  1532. }
  1533. }
  1534. break;
  1535. case SAA7134_BOARD_ASUSTeK_TIGER:
  1536. if (configure_tda827x_fe(dev, &philips_tiger_config,
  1537. &tda827x_cfg_0) < 0)
  1538. goto detach_frontend;
  1539. break;
  1540. case SAA7134_BOARD_BEHOLD_H6:
  1541. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1542. &behold_h6_config,
  1543. &dev->i2c_adap);
  1544. if (fe0->dvb.frontend) {
  1545. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1546. &dev->i2c_adap, 0x61,
  1547. TUNER_PHILIPS_FMD1216MEX_MK3);
  1548. }
  1549. break;
  1550. case SAA7134_BOARD_BEHOLD_X7:
  1551. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1552. &behold_x7_config,
  1553. &dev->i2c_adap);
  1554. if (fe0->dvb.frontend) {
  1555. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1556. &dev->i2c_adap, &behold_x7_tunerconfig);
  1557. }
  1558. break;
  1559. case SAA7134_BOARD_BEHOLD_H7:
  1560. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1561. &behold_x7_config,
  1562. &dev->i2c_adap);
  1563. if (fe0->dvb.frontend) {
  1564. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1565. &dev->i2c_adap, &behold_x7_tunerconfig);
  1566. }
  1567. break;
  1568. case SAA7134_BOARD_AVERMEDIA_A700_PRO:
  1569. case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
  1570. /* Zarlink ZL10313 */
  1571. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1572. &avertv_a700_mt312, &dev->i2c_adap);
  1573. if (fe0->dvb.frontend) {
  1574. if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
  1575. &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
  1576. pr_warn("%s: No zl10036 found!\n",
  1577. __func__);
  1578. }
  1579. }
  1580. break;
  1581. case SAA7134_BOARD_VIDEOMATE_S350:
  1582. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1583. &zl10313_compro_s350_config, &dev->i2c_adap);
  1584. if (fe0->dvb.frontend)
  1585. if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
  1586. 0x60, &dev->i2c_adap) == NULL)
  1587. pr_warn("%s: No zl10039 found!\n",
  1588. __func__);
  1589. break;
  1590. case SAA7134_BOARD_VIDEOMATE_T750:
  1591. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1592. &videomate_t750_zl10353_config,
  1593. &dev->i2c_adap);
  1594. if (fe0->dvb.frontend != NULL) {
  1595. if (dvb_attach(qt1010_attach,
  1596. fe0->dvb.frontend,
  1597. &dev->i2c_adap,
  1598. &videomate_t750_qt1010_config) == NULL)
  1599. pr_warn("error attaching QT1010\n");
  1600. }
  1601. break;
  1602. case SAA7134_BOARD_ZOLID_HYBRID_PCI:
  1603. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1604. &zolid_tda10048_config,
  1605. &dev->i2c_adap);
  1606. if (fe0->dvb.frontend != NULL) {
  1607. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1608. &dev->i2c_adap, 0x4b,
  1609. &tda829x_no_probe);
  1610. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1611. 0x60, &dev->i2c_adap,
  1612. &zolid_tda18271_config);
  1613. }
  1614. break;
  1615. case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
  1616. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  1617. &dtv1000s_tda10048_config,
  1618. &dev->i2c_adap);
  1619. if (fe0->dvb.frontend != NULL) {
  1620. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1621. &dev->i2c_adap, 0x4b,
  1622. &tda829x_no_probe);
  1623. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1624. 0x60, &dev->i2c_adap,
  1625. &dtv1000s_tda18271_config);
  1626. }
  1627. break;
  1628. case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
  1629. /* Switch to digital mode */
  1630. saa7134_tuner_callback(dev, 0,
  1631. TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);
  1632. fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
  1633. &kworld_mb86a20s_config,
  1634. &dev->i2c_adap);
  1635. if (fe0->dvb.frontend != NULL) {
  1636. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1637. &dev->i2c_adap, 0x4b,
  1638. &tda829x_no_probe);
  1639. fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl;
  1640. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1641. 0x60, &dev->i2c_adap,
  1642. &kworld_tda18271_config);
  1643. }
  1644. /* mb86a20s need to use the I2C gateway */
  1645. break;
  1646. case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2:
  1647. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  1648. &prohdtv_pro2_lgs8g75_config,
  1649. &dev->i2c_adap);
  1650. if (fe0->dvb.frontend != NULL) {
  1651. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  1652. &dev->i2c_adap, 0x4b,
  1653. &tda829x_no_probe);
  1654. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  1655. 0x60, &dev->i2c_adap,
  1656. &prohdtv_pro2_tda18271_config);
  1657. }
  1658. break;
  1659. case SAA7134_BOARD_AVERMEDIA_A706:
  1660. /* Enable all DVB-S devices now */
  1661. /* CE5039 DVB-S tuner SLEEP pin low */
  1662. saa7134_set_gpio(dev, 23, 0);
  1663. /* CE6313 DVB-S demod SLEEP pin low */
  1664. saa7134_set_gpio(dev, 9, 0);
  1665. /* CE6313 DVB-S demod RESET# pin high */
  1666. saa7134_set_gpio(dev, 25, 1);
  1667. msleep(1);
  1668. fe0->dvb.frontend = dvb_attach(mt312_attach,
  1669. &zl10313_avermedia_a706_config, &dev->i2c_adap);
  1670. if (fe0->dvb.frontend) {
  1671. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1672. if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
  1673. 0x60, &dev->i2c_adap) == NULL)
  1674. pr_warn("%s: No zl10039 found!\n",
  1675. __func__);
  1676. }
  1677. break;
  1678. default:
  1679. pr_warn("Huh? unknown DVB card?\n");
  1680. break;
  1681. }
  1682. if (attach_xc3028) {
  1683. struct dvb_frontend *fe;
  1684. struct xc2028_config cfg = {
  1685. .i2c_adap = &dev->i2c_adap,
  1686. .i2c_addr = 0x61,
  1687. };
  1688. if (!fe0->dvb.frontend)
  1689. goto detach_frontend;
  1690. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  1691. if (!fe) {
  1692. pr_err("%s/2: xc3028 attach failed\n",
  1693. dev->name);
  1694. goto detach_frontend;
  1695. }
  1696. }
  1697. if (NULL == fe0->dvb.frontend) {
  1698. pr_err("%s/dvb: frontend initialization failed\n", dev->name);
  1699. goto detach_frontend;
  1700. }
  1701. /* define general-purpose callback pointer */
  1702. fe0->dvb.frontend->callback = saa7134_tuner_callback;
  1703. /* register everything else */
  1704. #ifndef CONFIG_MEDIA_CONTROLLER_DVB
  1705. ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1706. &dev->pci->dev, NULL,
  1707. adapter_nr, 0);
  1708. #else
  1709. ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1710. &dev->pci->dev, dev->media_dev,
  1711. adapter_nr, 0);
  1712. #endif
  1713. /* this sequence is necessary to make the tda1004x load its firmware
  1714. * and to enter analog mode of hybrid boards
  1715. */
  1716. if (!ret) {
  1717. if (fe0->dvb.frontend->ops.init)
  1718. fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
  1719. if (fe0->dvb.frontend->ops.sleep)
  1720. fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
  1721. if (fe0->dvb.frontend->ops.tuner_ops.sleep)
  1722. fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
  1723. }
  1724. return ret;
  1725. detach_frontend:
  1726. vb2_dvb_dealloc_frontends(&dev->frontends);
  1727. vb2_queue_release(&fe0->dvb.dvbq);
  1728. return -EINVAL;
  1729. }
  1730. static int dvb_fini(struct saa7134_dev *dev)
  1731. {
  1732. struct vb2_dvb_frontend *fe0;
  1733. /* Get the first frontend */
  1734. fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);
  1735. if (!fe0)
  1736. return -EINVAL;
  1737. /* FIXME: I suspect that this code is bogus, since the entry for
  1738. Pinnacle 300I DVB-T PAL already defines the proper init to allow
  1739. the detection of mt2032 (TDA9887_PORT2_INACTIVE)
  1740. */
  1741. if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
  1742. struct v4l2_priv_tun_config tda9887_cfg;
  1743. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  1744. tda9887_cfg.tuner = TUNER_TDA9887;
  1745. tda9887_cfg.priv = &on;
  1746. /* otherwise we don't detect the tuner on next insmod */
  1747. saa_call_all(dev, tuner, s_config, &tda9887_cfg);
  1748. } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
  1749. if ((dev->eedata[2] == 0x07) && use_frontend) {
  1750. /* turn off the 2nd lnb supply */
  1751. u8 data = 0x80;
  1752. struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
  1753. struct dvb_frontend *fe;
  1754. fe = fe0->dvb.frontend;
  1755. if (fe->ops.i2c_gate_ctrl) {
  1756. fe->ops.i2c_gate_ctrl(fe, 1);
  1757. i2c_transfer(&dev->i2c_adap, &msg, 1);
  1758. fe->ops.i2c_gate_ctrl(fe, 0);
  1759. }
  1760. }
  1761. }
  1762. vb2_dvb_unregister_bus(&dev->frontends);
  1763. vb2_queue_release(&fe0->dvb.dvbq);
  1764. return 0;
  1765. }
  1766. static struct saa7134_mpeg_ops dvb_ops = {
  1767. .type = SAA7134_MPEG_DVB,
  1768. .init = dvb_init,
  1769. .fini = dvb_fini,
  1770. };
  1771. static int __init dvb_register(void)
  1772. {
  1773. return saa7134_ts_register(&dvb_ops);
  1774. }
  1775. static void __exit dvb_unregister(void)
  1776. {
  1777. saa7134_ts_unregister(&dvb_ops);
  1778. }
  1779. module_init(dvb_register);
  1780. module_exit(dvb_unregister);