saa7134-dvb.c 56 KB

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