ngene-cards.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /*
  2. * ngene-cards.c: nGene PCIe bridge driver - card specific info
  3. *
  4. * Copyright (C) 2005-2007 Micronas
  5. *
  6. * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
  7. * Modifications for new nGene firmware,
  8. * support for EEPROM-copying,
  9. * support for new dual DVB-S2 card prototype
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * version 2 only, as published by the Free Software Foundation.
  15. *
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * To obtain the license, point your browser to
  23. * http://www.gnu.org/copyleft/gpl.html
  24. */
  25. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/pci_ids.h>
  30. #include "ngene.h"
  31. /* demods/tuners */
  32. #include "stv6110x.h"
  33. #include "stv090x.h"
  34. #include "lnbh24.h"
  35. #include "lgdt330x.h"
  36. #include "mt2131.h"
  37. #include "tda18271c2dd.h"
  38. #include "drxk.h"
  39. #include "drxd.h"
  40. #include "dvb-pll.h"
  41. #include "stv0367.h"
  42. #include "stv0367_priv.h"
  43. #include "tda18212.h"
  44. #include "cxd2841er.h"
  45. #include "stv0910.h"
  46. #include "stv6111.h"
  47. #include "lnbh25.h"
  48. /****************************************************************************/
  49. /* I2C transfer functions used for demod/tuner probing***********************/
  50. /****************************************************************************/
  51. static int i2c_io(struct i2c_adapter *adapter, u8 adr,
  52. u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
  53. {
  54. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  55. .buf = wbuf, .len = wlen },
  56. {.addr = adr, .flags = I2C_M_RD,
  57. .buf = rbuf, .len = rlen } };
  58. return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
  59. }
  60. static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
  61. {
  62. struct i2c_msg msg = {.addr = adr, .flags = 0,
  63. .buf = data, .len = len};
  64. return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
  65. }
  66. static int i2c_write_reg(struct i2c_adapter *adap, u8 adr,
  67. u8 reg, u8 val)
  68. {
  69. u8 msg[2] = {reg, val};
  70. return i2c_write(adap, adr, msg, 2);
  71. }
  72. static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
  73. {
  74. struct i2c_msg msgs[1] = {{.addr = adr, .flags = I2C_M_RD,
  75. .buf = val, .len = 1 } };
  76. return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
  77. }
  78. static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
  79. u16 reg, u8 *val)
  80. {
  81. u8 msg[2] = {reg >> 8, reg & 0xff};
  82. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  83. .buf = msg, .len = 2},
  84. {.addr = adr, .flags = I2C_M_RD,
  85. .buf = val, .len = 1} };
  86. return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
  87. }
  88. static int i2c_read_regs(struct i2c_adapter *adapter,
  89. u8 adr, u8 reg, u8 *val, u8 len)
  90. {
  91. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  92. .buf = &reg, .len = 1},
  93. {.addr = adr, .flags = I2C_M_RD,
  94. .buf = val, .len = len} };
  95. return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
  96. }
  97. static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val)
  98. {
  99. return i2c_read_regs(adapter, adr, reg, val, 1);
  100. }
  101. /****************************************************************************/
  102. /* Demod/tuner attachment ***************************************************/
  103. /****************************************************************************/
  104. static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan)
  105. {
  106. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  107. if (chan->number < 2)
  108. return &chan->dev->channel[0].i2c_adapter;
  109. return &chan->dev->channel[1].i2c_adapter;
  110. }
  111. static int tuner_attach_stv6110(struct ngene_channel *chan)
  112. {
  113. struct device *pdev = &chan->dev->pci_dev->dev;
  114. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  115. struct stv090x_config *feconf = (struct stv090x_config *)
  116. chan->dev->card_info->fe_config[chan->number];
  117. struct stv6110x_config *tunerconf = (struct stv6110x_config *)
  118. chan->dev->card_info->tuner_config[chan->number];
  119. const struct stv6110x_devctl *ctl;
  120. ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
  121. if (ctl == NULL) {
  122. dev_err(pdev, "No STV6110X found!\n");
  123. return -ENODEV;
  124. }
  125. feconf->tuner_init = ctl->tuner_init;
  126. feconf->tuner_sleep = ctl->tuner_sleep;
  127. feconf->tuner_set_mode = ctl->tuner_set_mode;
  128. feconf->tuner_set_frequency = ctl->tuner_set_frequency;
  129. feconf->tuner_get_frequency = ctl->tuner_get_frequency;
  130. feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
  131. feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
  132. feconf->tuner_set_bbgain = ctl->tuner_set_bbgain;
  133. feconf->tuner_get_bbgain = ctl->tuner_get_bbgain;
  134. feconf->tuner_set_refclk = ctl->tuner_set_refclk;
  135. feconf->tuner_get_status = ctl->tuner_get_status;
  136. return 0;
  137. }
  138. static int tuner_attach_stv6111(struct ngene_channel *chan)
  139. {
  140. struct device *pdev = &chan->dev->pci_dev->dev;
  141. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  142. struct dvb_frontend *fe;
  143. u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60);
  144. fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
  145. if (!fe) {
  146. fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
  147. if (!fe) {
  148. dev_err(pdev, "stv6111_attach() failed!\n");
  149. return -ENODEV;
  150. }
  151. }
  152. return 0;
  153. }
  154. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  155. {
  156. struct ngene_channel *chan = fe->sec_priv;
  157. int status;
  158. if (enable) {
  159. down(&chan->dev->pll_mutex);
  160. status = chan->gate_ctrl(fe, 1);
  161. } else {
  162. status = chan->gate_ctrl(fe, 0);
  163. up(&chan->dev->pll_mutex);
  164. }
  165. return status;
  166. }
  167. static int tuner_attach_tda18271(struct ngene_channel *chan)
  168. {
  169. struct device *pdev = &chan->dev->pci_dev->dev;
  170. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  171. struct dvb_frontend *fe;
  172. if (chan->fe->ops.i2c_gate_ctrl)
  173. chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
  174. fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
  175. if (chan->fe->ops.i2c_gate_ctrl)
  176. chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
  177. if (!fe) {
  178. dev_err(pdev, "No TDA18271 found!\n");
  179. return -ENODEV;
  180. }
  181. return 0;
  182. }
  183. static int tuner_tda18212_ping(struct ngene_channel *chan,
  184. struct i2c_adapter *i2c,
  185. unsigned short adr)
  186. {
  187. struct device *pdev = &chan->dev->pci_dev->dev;
  188. u8 tda_id[2];
  189. u8 subaddr = 0x00;
  190. dev_dbg(pdev, "stv0367-tda18212 tuner ping\n");
  191. if (chan->fe->ops.i2c_gate_ctrl)
  192. chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
  193. if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
  194. dev_dbg(pdev, "tda18212 ping 1 fail\n");
  195. if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
  196. dev_warn(pdev, "tda18212 ping failed, expect problems\n");
  197. if (chan->fe->ops.i2c_gate_ctrl)
  198. chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
  199. return 0;
  200. }
  201. static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
  202. {
  203. struct device *pdev = &chan->dev->pci_dev->dev;
  204. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  205. struct i2c_client *client;
  206. struct tda18212_config config = {
  207. .fe = chan->fe,
  208. .if_dvbt_6 = 3550,
  209. .if_dvbt_7 = 3700,
  210. .if_dvbt_8 = 4150,
  211. .if_dvbt2_6 = 3250,
  212. .if_dvbt2_7 = 4000,
  213. .if_dvbt2_8 = 4000,
  214. .if_dvbc = 5000,
  215. };
  216. u8 addr = (chan->number & 1) ? 0x63 : 0x60;
  217. /*
  218. * due to a hardware quirk with the I2C gate on the stv0367+tda18212
  219. * combo, the tda18212 must be probed by reading it's id _twice_ when
  220. * cold started, or it very likely will fail.
  221. */
  222. if (dmdtype == DEMOD_TYPE_STV0367)
  223. tuner_tda18212_ping(chan, i2c, addr);
  224. /* perform tuner probe/init/attach */
  225. client = dvb_module_probe("tda18212", NULL, i2c, addr, &config);
  226. if (!client)
  227. goto err;
  228. chan->i2c_client[0] = client;
  229. chan->i2c_client_fe = 1;
  230. return 0;
  231. err:
  232. dev_err(pdev, "TDA18212 tuner not found. Device is not fully operational.\n");
  233. return -ENODEV;
  234. }
  235. static int tuner_attach_probe(struct ngene_channel *chan)
  236. {
  237. switch (chan->demod_type) {
  238. case DEMOD_TYPE_STV090X:
  239. return tuner_attach_stv6110(chan);
  240. case DEMOD_TYPE_DRXK:
  241. return tuner_attach_tda18271(chan);
  242. case DEMOD_TYPE_STV0367:
  243. case DEMOD_TYPE_SONY_CT2:
  244. case DEMOD_TYPE_SONY_ISDBT:
  245. case DEMOD_TYPE_SONY_C2T2:
  246. case DEMOD_TYPE_SONY_C2T2I:
  247. return tuner_attach_tda18212(chan, chan->demod_type);
  248. case DEMOD_TYPE_STV0910:
  249. return tuner_attach_stv6111(chan);
  250. }
  251. return -EINVAL;
  252. }
  253. static int demod_attach_stv0900(struct ngene_channel *chan)
  254. {
  255. struct device *pdev = &chan->dev->pci_dev->dev;
  256. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  257. struct stv090x_config *feconf = (struct stv090x_config *)
  258. chan->dev->card_info->fe_config[chan->number];
  259. chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
  260. (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
  261. : STV090x_DEMODULATOR_1);
  262. if (chan->fe == NULL) {
  263. dev_err(pdev, "No STV0900 found!\n");
  264. return -ENODEV;
  265. }
  266. /* store channel info */
  267. if (feconf->tuner_i2c_lock)
  268. chan->fe->analog_demod_priv = chan;
  269. if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
  270. 0, chan->dev->card_info->lnb[chan->number])) {
  271. dev_err(pdev, "No LNBH24 found!\n");
  272. dvb_frontend_detach(chan->fe);
  273. chan->fe = NULL;
  274. return -ENODEV;
  275. }
  276. return 0;
  277. }
  278. static struct stv0910_cfg stv0910_p = {
  279. .adr = 0x68,
  280. .parallel = 1,
  281. .rptlvl = 4,
  282. .clk = 30000000,
  283. .tsspeed = 0x28,
  284. };
  285. static struct lnbh25_config lnbh25_cfg = {
  286. .i2c_address = 0x0c << 1,
  287. .data2_config = LNBH25_TEN
  288. };
  289. static int demod_attach_stv0910(struct ngene_channel *chan,
  290. struct i2c_adapter *i2c)
  291. {
  292. struct device *pdev = &chan->dev->pci_dev->dev;
  293. struct stv0910_cfg cfg = stv0910_p;
  294. struct lnbh25_config lnbcfg = lnbh25_cfg;
  295. chan->fe = dvb_attach(stv0910_attach, i2c, &cfg, (chan->number & 1));
  296. if (!chan->fe) {
  297. cfg.adr = 0x6c;
  298. chan->fe = dvb_attach(stv0910_attach, i2c,
  299. &cfg, (chan->number & 1));
  300. }
  301. if (!chan->fe) {
  302. dev_err(pdev, "stv0910_attach() failed!\n");
  303. return -ENODEV;
  304. }
  305. /*
  306. * attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
  307. * i2c addresses
  308. */
  309. lnbcfg.i2c_address = (((chan->number & 1) ? 0x0d : 0x0c) << 1);
  310. if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
  311. lnbcfg.i2c_address = (((chan->number & 1) ? 0x09 : 0x08) << 1);
  312. if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
  313. dev_err(pdev, "lnbh25_attach() failed!\n");
  314. dvb_frontend_detach(chan->fe);
  315. chan->fe = NULL;
  316. return -ENODEV;
  317. }
  318. }
  319. return 0;
  320. }
  321. static struct stv0367_config ddb_stv0367_config[] = {
  322. {
  323. .demod_address = 0x1f,
  324. .xtal = 27000000,
  325. .if_khz = 0,
  326. .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
  327. .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
  328. .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
  329. }, {
  330. .demod_address = 0x1e,
  331. .xtal = 27000000,
  332. .if_khz = 0,
  333. .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
  334. .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
  335. .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
  336. },
  337. };
  338. static int demod_attach_stv0367(struct ngene_channel *chan,
  339. struct i2c_adapter *i2c)
  340. {
  341. struct device *pdev = &chan->dev->pci_dev->dev;
  342. chan->fe = dvb_attach(stv0367ddb_attach,
  343. &ddb_stv0367_config[(chan->number & 1)], i2c);
  344. if (!chan->fe) {
  345. dev_err(pdev, "stv0367ddb_attach() failed!\n");
  346. return -ENODEV;
  347. }
  348. chan->fe->sec_priv = chan;
  349. chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
  350. chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  351. return 0;
  352. }
  353. static int demod_attach_cxd28xx(struct ngene_channel *chan,
  354. struct i2c_adapter *i2c, int osc24)
  355. {
  356. struct device *pdev = &chan->dev->pci_dev->dev;
  357. struct cxd2841er_config cfg;
  358. /* the cxd2841er driver expects 8bit/shifted I2C addresses */
  359. cfg.i2c_addr = ((chan->number & 1) ? 0x6d : 0x6c) << 1;
  360. cfg.xtal = osc24 ? SONY_XTAL_24000 : SONY_XTAL_20500;
  361. cfg.flags = CXD2841ER_AUTO_IFHZ | CXD2841ER_EARLY_TUNE |
  362. CXD2841ER_NO_WAIT_LOCK | CXD2841ER_NO_AGCNEG |
  363. CXD2841ER_TSBITS | CXD2841ER_TS_SERIAL;
  364. /* attach frontend */
  365. chan->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
  366. if (!chan->fe) {
  367. dev_err(pdev, "CXD28XX attach failed!\n");
  368. return -ENODEV;
  369. }
  370. chan->fe->sec_priv = chan;
  371. chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
  372. chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  373. return 0;
  374. }
  375. static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
  376. {
  377. struct ngene_channel *chan = fe->analog_demod_priv;
  378. if (lock)
  379. down(&chan->dev->pll_mutex);
  380. else
  381. up(&chan->dev->pll_mutex);
  382. }
  383. static int port_has_stv0900(struct i2c_adapter *i2c, int port)
  384. {
  385. u8 val;
  386. if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
  387. return 0;
  388. return 1;
  389. }
  390. static int port_has_drxk(struct i2c_adapter *i2c, int port)
  391. {
  392. u8 val;
  393. if (i2c_read(i2c, 0x29+port, &val) < 0)
  394. return 0;
  395. return 1;
  396. }
  397. static int port_has_stv0367(struct i2c_adapter *i2c)
  398. {
  399. u8 val;
  400. if (i2c_read_reg16(i2c, 0x1e, 0xf000, &val) < 0)
  401. return 0;
  402. if (val != 0x60)
  403. return 0;
  404. if (i2c_read_reg16(i2c, 0x1f, 0xf000, &val) < 0)
  405. return 0;
  406. if (val != 0x60)
  407. return 0;
  408. return 1;
  409. }
  410. int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type)
  411. {
  412. u8 val;
  413. u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4];
  414. struct i2c_msg msgs[2] = {{ .addr = 0x40, .flags = 0,
  415. .buf = probe, .len = 4 },
  416. { .addr = 0x40, .flags = I2C_M_RD,
  417. .buf = data, .len = 4 } };
  418. val = i2c_transfer(i2c, msgs, 2);
  419. if (val != 2)
  420. return 0;
  421. if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43)
  422. *type = 2;
  423. else
  424. *type = 1;
  425. return 1;
  426. }
  427. static int demod_attach_drxk(struct ngene_channel *chan,
  428. struct i2c_adapter *i2c)
  429. {
  430. struct device *pdev = &chan->dev->pci_dev->dev;
  431. struct drxk_config config;
  432. memset(&config, 0, sizeof(config));
  433. config.microcode_name = "drxk_a3.mc";
  434. config.qam_demod_parameter_count = 4;
  435. config.adr = 0x29 + (chan->number ^ 2);
  436. chan->fe = dvb_attach(drxk_attach, &config, i2c);
  437. if (!chan->fe) {
  438. dev_err(pdev, "No DRXK found!\n");
  439. return -ENODEV;
  440. }
  441. chan->fe->sec_priv = chan;
  442. chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
  443. chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  444. return 0;
  445. }
  446. /****************************************************************************/
  447. /* XO2 related lists and functions ******************************************/
  448. /****************************************************************************/
  449. static char *xo2names[] = {
  450. "DUAL DVB-S2",
  451. "DUAL DVB-C/T/T2",
  452. "DUAL DVB-ISDBT",
  453. "DUAL DVB-C/C2/T/T2",
  454. "DUAL ATSC",
  455. "DUAL DVB-C/C2/T/T2/I",
  456. };
  457. static int init_xo2(struct ngene_channel *chan, struct i2c_adapter *i2c)
  458. {
  459. struct device *pdev = &chan->dev->pci_dev->dev;
  460. u8 addr = 0x10;
  461. u8 val, data[2];
  462. int res;
  463. res = i2c_read_regs(i2c, addr, 0x04, data, 2);
  464. if (res < 0)
  465. return res;
  466. if (data[0] != 0x01) {
  467. dev_info(pdev, "Invalid XO2 on channel %d\n", chan->number);
  468. return -1;
  469. }
  470. i2c_read_reg(i2c, addr, 0x08, &val);
  471. if (val != 0) {
  472. i2c_write_reg(i2c, addr, 0x08, 0x00);
  473. msleep(100);
  474. }
  475. /* Enable tuner power, disable pll, reset demods */
  476. i2c_write_reg(i2c, addr, 0x08, 0x04);
  477. usleep_range(2000, 3000);
  478. /* Release demod resets */
  479. i2c_write_reg(i2c, addr, 0x08, 0x07);
  480. /*
  481. * speed: 0=55,1=75,2=90,3=104 MBit/s
  482. * Note: The ngene hardware must be run at 75 MBit/s compared
  483. * to more modern ddbridge hardware which runs at 90 MBit/s,
  484. * else there will be issues with the data transport and non-
  485. * working secondary/slave demods/tuners.
  486. */
  487. i2c_write_reg(i2c, addr, 0x09, 1);
  488. i2c_write_reg(i2c, addr, 0x0a, 0x01);
  489. i2c_write_reg(i2c, addr, 0x0b, 0x01);
  490. usleep_range(2000, 3000);
  491. /* Start XO2 PLL */
  492. i2c_write_reg(i2c, addr, 0x08, 0x87);
  493. return 0;
  494. }
  495. static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id)
  496. {
  497. u8 probe[1] = { 0x00 }, data[4];
  498. u8 addr = 0x10;
  499. *type = NGENE_XO2_TYPE_NONE;
  500. if (i2c_io(i2c, addr, probe, 1, data, 4))
  501. return 0;
  502. if (data[0] == 'D' && data[1] == 'F') {
  503. *id = data[2];
  504. *type = NGENE_XO2_TYPE_DUOFLEX;
  505. return 1;
  506. }
  507. if (data[0] == 'C' && data[1] == 'I') {
  508. *id = data[2];
  509. *type = NGENE_XO2_TYPE_CI;
  510. return 1;
  511. }
  512. return 0;
  513. }
  514. /****************************************************************************/
  515. /* Probing and port/channel handling ****************************************/
  516. /****************************************************************************/
  517. static int cineS2_probe(struct ngene_channel *chan)
  518. {
  519. struct device *pdev = &chan->dev->pci_dev->dev;
  520. struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
  521. struct stv090x_config *fe_conf;
  522. u8 buf[3];
  523. u8 xo2_type, xo2_id, xo2_demodtype;
  524. u8 sony_osc24 = 0;
  525. struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
  526. int rc;
  527. if (port_has_xo2(i2c, &xo2_type, &xo2_id)) {
  528. xo2_id >>= 2;
  529. dev_dbg(pdev, "XO2 on channel %d (type %d, id %d)\n",
  530. chan->number, xo2_type, xo2_id);
  531. switch (xo2_type) {
  532. case NGENE_XO2_TYPE_DUOFLEX:
  533. if (chan->number & 1)
  534. dev_dbg(pdev,
  535. "skipping XO2 init on odd channel %d",
  536. chan->number);
  537. else
  538. init_xo2(chan, i2c);
  539. xo2_demodtype = DEMOD_TYPE_XO2 + xo2_id;
  540. switch (xo2_demodtype) {
  541. case DEMOD_TYPE_SONY_CT2:
  542. case DEMOD_TYPE_SONY_ISDBT:
  543. case DEMOD_TYPE_SONY_C2T2:
  544. case DEMOD_TYPE_SONY_C2T2I:
  545. dev_info(pdev, "%s (XO2) on channel %d\n",
  546. xo2names[xo2_id], chan->number);
  547. chan->demod_type = xo2_demodtype;
  548. if (xo2_demodtype == DEMOD_TYPE_SONY_C2T2I)
  549. sony_osc24 = 1;
  550. demod_attach_cxd28xx(chan, i2c, sony_osc24);
  551. break;
  552. case DEMOD_TYPE_STV0910:
  553. dev_info(pdev, "%s (XO2) on channel %d\n",
  554. xo2names[xo2_id], chan->number);
  555. chan->demod_type = xo2_demodtype;
  556. demod_attach_stv0910(chan, i2c);
  557. break;
  558. default:
  559. dev_warn(pdev,
  560. "Unsupported XO2 module on channel %d\n",
  561. chan->number);
  562. return -ENODEV;
  563. }
  564. break;
  565. case NGENE_XO2_TYPE_CI:
  566. dev_info(pdev, "DuoFlex CI modules not supported\n");
  567. return -ENODEV;
  568. default:
  569. dev_info(pdev, "Unsupported XO2 module type\n");
  570. return -ENODEV;
  571. }
  572. } else if (port_has_stv0900(i2c, chan->number)) {
  573. chan->demod_type = DEMOD_TYPE_STV090X;
  574. fe_conf = chan->dev->card_info->fe_config[chan->number];
  575. /* demod found, attach it */
  576. rc = demod_attach_stv0900(chan);
  577. if (rc < 0 || chan->number < 2)
  578. return rc;
  579. /* demod #2: reprogram outputs DPN1 & DPN2 */
  580. i2c_msg.addr = fe_conf->address;
  581. i2c_msg.len = 3;
  582. buf[0] = 0xf1;
  583. switch (chan->number) {
  584. case 2:
  585. buf[1] = 0x5c;
  586. buf[2] = 0xc2;
  587. break;
  588. case 3:
  589. buf[1] = 0x61;
  590. buf[2] = 0xcc;
  591. break;
  592. default:
  593. return -ENODEV;
  594. }
  595. rc = i2c_transfer(i2c, &i2c_msg, 1);
  596. if (rc != 1) {
  597. dev_err(pdev, "Could not setup DPNx\n");
  598. return -EIO;
  599. }
  600. } else if (port_has_drxk(i2c, chan->number^2)) {
  601. chan->demod_type = DEMOD_TYPE_DRXK;
  602. demod_attach_drxk(chan, i2c);
  603. } else if (port_has_stv0367(i2c)) {
  604. chan->demod_type = DEMOD_TYPE_STV0367;
  605. dev_info(pdev, "STV0367 on channel %d\n", chan->number);
  606. demod_attach_stv0367(chan, i2c);
  607. } else {
  608. dev_info(pdev, "No demod found on chan %d\n", chan->number);
  609. return -ENODEV;
  610. }
  611. return 0;
  612. }
  613. static struct lgdt330x_config aver_m780 = {
  614. .demod_chip = LGDT3303,
  615. .serial_mpeg = 0x00, /* PARALLEL */
  616. .clock_polarity_flip = 1,
  617. };
  618. static struct mt2131_config m780_tunerconfig = {
  619. 0xc0 >> 1
  620. };
  621. /* A single func to attach the demo and tuner, rather than
  622. * use two sep funcs like the current design mandates.
  623. */
  624. static int demod_attach_lg330x(struct ngene_channel *chan)
  625. {
  626. struct device *pdev = &chan->dev->pci_dev->dev;
  627. chan->fe = dvb_attach(lgdt330x_attach, &aver_m780,
  628. 0xb2 >> 1, &chan->i2c_adapter);
  629. if (chan->fe == NULL) {
  630. dev_err(pdev, "No LGDT330x found!\n");
  631. return -ENODEV;
  632. }
  633. dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
  634. &m780_tunerconfig, 0);
  635. return (chan->fe) ? 0 : -ENODEV;
  636. }
  637. static int demod_attach_drxd(struct ngene_channel *chan)
  638. {
  639. struct device *pdev = &chan->dev->pci_dev->dev;
  640. struct drxd_config *feconf;
  641. feconf = chan->dev->card_info->fe_config[chan->number];
  642. chan->fe = dvb_attach(drxd_attach, feconf, chan,
  643. &chan->i2c_adapter, &chan->dev->pci_dev->dev);
  644. if (!chan->fe) {
  645. dev_err(pdev, "No DRXD found!\n");
  646. return -ENODEV;
  647. }
  648. return 0;
  649. }
  650. static int tuner_attach_dtt7520x(struct ngene_channel *chan)
  651. {
  652. struct device *pdev = &chan->dev->pci_dev->dev;
  653. struct drxd_config *feconf;
  654. feconf = chan->dev->card_info->fe_config[chan->number];
  655. if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
  656. &chan->i2c_adapter,
  657. feconf->pll_type)) {
  658. dev_err(pdev, "No pll(%d) found!\n", feconf->pll_type);
  659. return -ENODEV;
  660. }
  661. return 0;
  662. }
  663. /****************************************************************************/
  664. /* EEPROM TAGS **************************************************************/
  665. /****************************************************************************/
  666. #define MICNG_EE_START 0x0100
  667. #define MICNG_EE_END 0x0FF0
  668. #define MICNG_EETAG_END0 0x0000
  669. #define MICNG_EETAG_END1 0xFFFF
  670. /* 0x0001 - 0x000F reserved for housekeeping */
  671. /* 0xFFFF - 0xFFFE reserved for housekeeping */
  672. /* Micronas assigned tags
  673. EEProm tags for hardware support */
  674. #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
  675. #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
  676. #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
  677. #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
  678. /* Tag range for OEMs */
  679. #define MICNG_EETAG_OEM_FIRST 0xC000
  680. #define MICNG_EETAG_OEM_LAST 0xFFEF
  681. static int i2c_write_eeprom(struct i2c_adapter *adapter,
  682. u8 adr, u16 reg, u8 data)
  683. {
  684. struct device *pdev = adapter->dev.parent;
  685. u8 m[3] = {(reg >> 8), (reg & 0xff), data};
  686. struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
  687. .len = sizeof(m)};
  688. if (i2c_transfer(adapter, &msg, 1) != 1) {
  689. dev_err(pdev, "Error writing EEPROM!\n");
  690. return -EIO;
  691. }
  692. return 0;
  693. }
  694. static int i2c_read_eeprom(struct i2c_adapter *adapter,
  695. u8 adr, u16 reg, u8 *data, int len)
  696. {
  697. struct device *pdev = adapter->dev.parent;
  698. u8 msg[2] = {(reg >> 8), (reg & 0xff)};
  699. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  700. .buf = msg, .len = 2 },
  701. {.addr = adr, .flags = I2C_M_RD,
  702. .buf = data, .len = len} };
  703. if (i2c_transfer(adapter, msgs, 2) != 2) {
  704. dev_err(pdev, "Error reading EEPROM\n");
  705. return -EIO;
  706. }
  707. return 0;
  708. }
  709. static int ReadEEProm(struct i2c_adapter *adapter,
  710. u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
  711. {
  712. struct device *pdev = adapter->dev.parent;
  713. int status = 0;
  714. u16 Addr = MICNG_EE_START, Length, tag = 0;
  715. u8 EETag[3];
  716. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  717. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  718. return -1;
  719. tag = (EETag[0] << 8) | EETag[1];
  720. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  721. return -1;
  722. if (tag == Tag)
  723. break;
  724. Addr += sizeof(u16) + 1 + EETag[2];
  725. }
  726. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  727. dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
  728. tag, EETag[2]);
  729. return -1;
  730. }
  731. Length = EETag[2];
  732. if (Length > MaxLen)
  733. Length = (u16) MaxLen;
  734. if (Length > 0) {
  735. Addr += sizeof(u16) + 1;
  736. status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
  737. if (!status) {
  738. *pLength = EETag[2];
  739. #if 0
  740. if (Length < EETag[2])
  741. status = STATUS_BUFFER_OVERFLOW;
  742. #endif
  743. }
  744. }
  745. return status;
  746. }
  747. static int WriteEEProm(struct i2c_adapter *adapter,
  748. u16 Tag, u32 Length, u8 *data)
  749. {
  750. struct device *pdev = adapter->dev.parent;
  751. int status = 0;
  752. u16 Addr = MICNG_EE_START;
  753. u8 EETag[3];
  754. u16 tag = 0;
  755. int retry, i;
  756. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  757. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  758. return -1;
  759. tag = (EETag[0] << 8) | EETag[1];
  760. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  761. return -1;
  762. if (tag == Tag)
  763. break;
  764. Addr += sizeof(u16) + 1 + EETag[2];
  765. }
  766. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  767. dev_err(pdev, "Reached EOEE @ Tag = %04x Length = %3d\n",
  768. tag, EETag[2]);
  769. return -1;
  770. }
  771. if (Length > EETag[2])
  772. return -EINVAL;
  773. /* Note: We write the data one byte at a time to avoid
  774. issues with page sizes. (which are different for
  775. each manufacture and eeprom size)
  776. */
  777. Addr += sizeof(u16) + 1;
  778. for (i = 0; i < Length; i++, Addr++) {
  779. status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
  780. if (status)
  781. break;
  782. /* Poll for finishing write cycle */
  783. retry = 10;
  784. while (retry) {
  785. u8 Tmp;
  786. msleep(50);
  787. status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
  788. if (status)
  789. break;
  790. if (Tmp != data[i])
  791. dev_err(pdev, "eeprom write error\n");
  792. retry -= 1;
  793. }
  794. if (status) {
  795. dev_err(pdev, "Timeout polling eeprom\n");
  796. break;
  797. }
  798. }
  799. return status;
  800. }
  801. static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
  802. {
  803. int stat;
  804. u8 buf[2];
  805. u32 len = 0;
  806. stat = ReadEEProm(adapter, tag, 2, buf, &len);
  807. if (stat)
  808. return stat;
  809. if (len != 2)
  810. return -EINVAL;
  811. *data = (buf[0] << 8) | buf[1];
  812. return 0;
  813. }
  814. static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
  815. {
  816. int stat;
  817. u8 buf[2];
  818. buf[0] = data >> 8;
  819. buf[1] = data & 0xff;
  820. stat = WriteEEProm(adapter, tag, 2, buf);
  821. if (stat)
  822. return stat;
  823. return 0;
  824. }
  825. static s16 osc_deviation(void *priv, s16 deviation, int flag)
  826. {
  827. struct ngene_channel *chan = priv;
  828. struct device *pdev = &chan->dev->pci_dev->dev;
  829. struct i2c_adapter *adap = &chan->i2c_adapter;
  830. u16 data = 0;
  831. if (flag) {
  832. data = (u16) deviation;
  833. dev_info(pdev, "write deviation %d\n",
  834. deviation);
  835. eeprom_write_ushort(adap, 0x1000 + chan->number, data);
  836. } else {
  837. if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
  838. data = 0;
  839. dev_info(pdev, "read deviation %d\n",
  840. (s16)data);
  841. }
  842. return (s16) data;
  843. }
  844. /****************************************************************************/
  845. /* Switch control (I2C gates, etc.) *****************************************/
  846. /****************************************************************************/
  847. static struct stv090x_config fe_cineS2 = {
  848. .device = STV0900,
  849. .demod_mode = STV090x_DUAL,
  850. .clk_mode = STV090x_CLK_EXT,
  851. .xtal = 27000000,
  852. .address = 0x68,
  853. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  854. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  855. .repeater_level = STV090x_RPTLEVEL_16,
  856. .adc1_range = STV090x_ADC_1Vpp,
  857. .adc2_range = STV090x_ADC_1Vpp,
  858. .diseqc_envelope_mode = true,
  859. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  860. };
  861. static struct stv090x_config fe_cineS2_2 = {
  862. .device = STV0900,
  863. .demod_mode = STV090x_DUAL,
  864. .clk_mode = STV090x_CLK_EXT,
  865. .xtal = 27000000,
  866. .address = 0x69,
  867. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  868. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  869. .repeater_level = STV090x_RPTLEVEL_16,
  870. .adc1_range = STV090x_ADC_1Vpp,
  871. .adc2_range = STV090x_ADC_1Vpp,
  872. .diseqc_envelope_mode = true,
  873. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  874. };
  875. static struct stv6110x_config tuner_cineS2_0 = {
  876. .addr = 0x60,
  877. .refclk = 27000000,
  878. .clk_div = 1,
  879. };
  880. static struct stv6110x_config tuner_cineS2_1 = {
  881. .addr = 0x63,
  882. .refclk = 27000000,
  883. .clk_div = 1,
  884. };
  885. static const struct ngene_info ngene_info_cineS2 = {
  886. .type = NGENE_SIDEWINDER,
  887. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
  888. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  889. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  890. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  891. .fe_config = {&fe_cineS2, &fe_cineS2},
  892. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  893. .lnb = {0x0b, 0x08},
  894. .tsf = {3, 3},
  895. .fw_version = 18,
  896. .msi_supported = true,
  897. };
  898. static const struct ngene_info ngene_info_satixS2 = {
  899. .type = NGENE_SIDEWINDER,
  900. .name = "Mystique SaTiX-S2 Dual",
  901. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  902. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  903. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  904. .fe_config = {&fe_cineS2, &fe_cineS2},
  905. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  906. .lnb = {0x0b, 0x08},
  907. .tsf = {3, 3},
  908. .fw_version = 18,
  909. .msi_supported = true,
  910. };
  911. static const struct ngene_info ngene_info_satixS2v2 = {
  912. .type = NGENE_SIDEWINDER,
  913. .name = "Mystique SaTiX-S2 Dual (v2)",
  914. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  915. NGENE_IO_TSOUT},
  916. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  917. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  918. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  919. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  920. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  921. .tsf = {3, 3},
  922. .fw_version = 18,
  923. .msi_supported = true,
  924. };
  925. static const struct ngene_info ngene_info_cineS2v5 = {
  926. .type = NGENE_SIDEWINDER,
  927. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
  928. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  929. NGENE_IO_TSOUT},
  930. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  931. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  932. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  933. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  934. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  935. .tsf = {3, 3},
  936. .fw_version = 18,
  937. .msi_supported = true,
  938. };
  939. static const struct ngene_info ngene_info_duoFlex = {
  940. .type = NGENE_SIDEWINDER,
  941. .name = "Digital Devices DuoFlex PCIe or miniPCIe",
  942. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  943. NGENE_IO_TSOUT},
  944. .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
  945. .tuner_attach = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
  946. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  947. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  948. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  949. .tsf = {3, 3},
  950. .fw_version = 18,
  951. .msi_supported = true,
  952. };
  953. static const struct ngene_info ngene_info_m780 = {
  954. .type = NGENE_APP,
  955. .name = "Aver M780 ATSC/QAM-B",
  956. /* Channel 0 is analog, which is currently unsupported */
  957. .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
  958. .demod_attach = { NULL, demod_attach_lg330x },
  959. /* Ensure these are NULL else the frame will call them (as funcs) */
  960. .tuner_attach = { NULL, NULL, NULL, NULL },
  961. .fe_config = { NULL, &aver_m780 },
  962. .avf = { 0 },
  963. /* A custom electrical interface config for the demod to bridge */
  964. .tsf = { 4, 4 },
  965. .fw_version = 15,
  966. };
  967. static struct drxd_config fe_terratec_dvbt_0 = {
  968. .index = 0,
  969. .demod_address = 0x70,
  970. .demod_revision = 0xa2,
  971. .demoda_address = 0x00,
  972. .pll_address = 0x60,
  973. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  974. .clock = 20000,
  975. .osc_deviation = osc_deviation,
  976. };
  977. static struct drxd_config fe_terratec_dvbt_1 = {
  978. .index = 1,
  979. .demod_address = 0x71,
  980. .demod_revision = 0xa2,
  981. .demoda_address = 0x00,
  982. .pll_address = 0x60,
  983. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  984. .clock = 20000,
  985. .osc_deviation = osc_deviation,
  986. };
  987. static const struct ngene_info ngene_info_terratec = {
  988. .type = NGENE_TERRATEC,
  989. .name = "Terratec Integra/Cinergy2400i Dual DVB-T",
  990. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  991. .demod_attach = {demod_attach_drxd, demod_attach_drxd},
  992. .tuner_attach = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
  993. .fe_config = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
  994. .i2c_access = 1,
  995. };
  996. /****************************************************************************/
  997. /****************************************************************************/
  998. /* PCI Subsystem ID *********************************************************/
  999. /****************************************************************************/
  1000. #define NGENE_ID(_subvend, _subdev, _driverdata) { \
  1001. .vendor = NGENE_VID, .device = NGENE_PID, \
  1002. .subvendor = _subvend, .subdevice = _subdev, \
  1003. .driver_data = (unsigned long) &_driverdata }
  1004. /****************************************************************************/
  1005. static const struct pci_device_id ngene_id_tbl[] = {
  1006. NGENE_ID(0x18c3, 0xab04, ngene_info_cineS2),
  1007. NGENE_ID(0x18c3, 0xab05, ngene_info_cineS2v5),
  1008. NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
  1009. NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
  1010. NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
  1011. NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
  1012. NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
  1013. NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
  1014. NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
  1015. NGENE_ID(0x1461, 0x062e, ngene_info_m780),
  1016. NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
  1017. {0}
  1018. };
  1019. MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
  1020. /****************************************************************************/
  1021. /* Init/Exit ****************************************************************/
  1022. /****************************************************************************/
  1023. static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
  1024. enum pci_channel_state state)
  1025. {
  1026. dev_err(&dev->dev, "PCI error\n");
  1027. if (state == pci_channel_io_perm_failure)
  1028. return PCI_ERS_RESULT_DISCONNECT;
  1029. if (state == pci_channel_io_frozen)
  1030. return PCI_ERS_RESULT_NEED_RESET;
  1031. return PCI_ERS_RESULT_CAN_RECOVER;
  1032. }
  1033. static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
  1034. {
  1035. dev_info(&dev->dev, "slot reset\n");
  1036. return 0;
  1037. }
  1038. static void ngene_resume(struct pci_dev *dev)
  1039. {
  1040. dev_info(&dev->dev, "resume\n");
  1041. }
  1042. static const struct pci_error_handlers ngene_errors = {
  1043. .error_detected = ngene_error_detected,
  1044. .slot_reset = ngene_slot_reset,
  1045. .resume = ngene_resume,
  1046. };
  1047. static struct pci_driver ngene_pci_driver = {
  1048. .name = "ngene",
  1049. .id_table = ngene_id_tbl,
  1050. .probe = ngene_probe,
  1051. .remove = ngene_remove,
  1052. .err_handler = &ngene_errors,
  1053. .shutdown = ngene_shutdown,
  1054. };
  1055. static __init int module_init_ngene(void)
  1056. {
  1057. /* pr_*() since we don't have a device to use with dev_*() yet */
  1058. pr_info("nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
  1059. return pci_register_driver(&ngene_pci_driver);
  1060. }
  1061. static __exit void module_exit_ngene(void)
  1062. {
  1063. pci_unregister_driver(&ngene_pci_driver);
  1064. }
  1065. module_init(module_init_ngene);
  1066. module_exit(module_exit_ngene);
  1067. MODULE_DESCRIPTION("nGene");
  1068. MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
  1069. MODULE_LICENSE("GPL");