ngene-cards.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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");