ngene-cards.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/pci.h>
  28. #include <linux/pci_ids.h>
  29. #include "ngene.h"
  30. /* demods/tuners */
  31. #include "stv6110x.h"
  32. #include "stv090x.h"
  33. #include "lnbh24.h"
  34. #include "lgdt330x.h"
  35. #include "mt2131.h"
  36. #include "tda18271c2dd.h"
  37. #include "drxk.h"
  38. #include "drxd.h"
  39. #include "dvb-pll.h"
  40. /****************************************************************************/
  41. /* Demod/tuner attachment ***************************************************/
  42. /****************************************************************************/
  43. static int tuner_attach_stv6110(struct ngene_channel *chan)
  44. {
  45. struct i2c_adapter *i2c;
  46. struct stv090x_config *feconf = (struct stv090x_config *)
  47. chan->dev->card_info->fe_config[chan->number];
  48. struct stv6110x_config *tunerconf = (struct stv6110x_config *)
  49. chan->dev->card_info->tuner_config[chan->number];
  50. const struct stv6110x_devctl *ctl;
  51. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  52. if (chan->number < 2)
  53. i2c = &chan->dev->channel[0].i2c_adapter;
  54. else
  55. i2c = &chan->dev->channel[1].i2c_adapter;
  56. ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
  57. if (ctl == NULL) {
  58. printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
  59. return -ENODEV;
  60. }
  61. feconf->tuner_init = ctl->tuner_init;
  62. feconf->tuner_sleep = ctl->tuner_sleep;
  63. feconf->tuner_set_mode = ctl->tuner_set_mode;
  64. feconf->tuner_set_frequency = ctl->tuner_set_frequency;
  65. feconf->tuner_get_frequency = ctl->tuner_get_frequency;
  66. feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
  67. feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
  68. feconf->tuner_set_bbgain = ctl->tuner_set_bbgain;
  69. feconf->tuner_get_bbgain = ctl->tuner_get_bbgain;
  70. feconf->tuner_set_refclk = ctl->tuner_set_refclk;
  71. feconf->tuner_get_status = ctl->tuner_get_status;
  72. return 0;
  73. }
  74. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  75. {
  76. struct ngene_channel *chan = fe->sec_priv;
  77. int status;
  78. if (enable) {
  79. down(&chan->dev->pll_mutex);
  80. status = chan->gate_ctrl(fe, 1);
  81. } else {
  82. status = chan->gate_ctrl(fe, 0);
  83. up(&chan->dev->pll_mutex);
  84. }
  85. return status;
  86. }
  87. static int tuner_attach_tda18271(struct ngene_channel *chan)
  88. {
  89. struct i2c_adapter *i2c;
  90. struct dvb_frontend *fe;
  91. i2c = &chan->dev->channel[0].i2c_adapter;
  92. if (chan->fe->ops.i2c_gate_ctrl)
  93. chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
  94. fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
  95. if (chan->fe->ops.i2c_gate_ctrl)
  96. chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
  97. if (!fe) {
  98. printk(KERN_ERR "No TDA18271 found!\n");
  99. return -ENODEV;
  100. }
  101. return 0;
  102. }
  103. static int tuner_attach_probe(struct ngene_channel *chan)
  104. {
  105. if (chan->demod_type == 0)
  106. return tuner_attach_stv6110(chan);
  107. if (chan->demod_type == 1)
  108. return tuner_attach_tda18271(chan);
  109. return -EINVAL;
  110. }
  111. static int demod_attach_stv0900(struct ngene_channel *chan)
  112. {
  113. struct i2c_adapter *i2c;
  114. struct stv090x_config *feconf = (struct stv090x_config *)
  115. chan->dev->card_info->fe_config[chan->number];
  116. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  117. /* Note: Both adapters share the same i2c bus, but the demod */
  118. /* driver requires that each demod has its own i2c adapter */
  119. if (chan->number < 2)
  120. i2c = &chan->dev->channel[0].i2c_adapter;
  121. else
  122. i2c = &chan->dev->channel[1].i2c_adapter;
  123. chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
  124. (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
  125. : STV090x_DEMODULATOR_1);
  126. if (chan->fe == NULL) {
  127. printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
  128. return -ENODEV;
  129. }
  130. /* store channel info */
  131. if (feconf->tuner_i2c_lock)
  132. chan->fe->analog_demod_priv = chan;
  133. if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
  134. 0, chan->dev->card_info->lnb[chan->number])) {
  135. printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
  136. dvb_frontend_detach(chan->fe);
  137. chan->fe = NULL;
  138. return -ENODEV;
  139. }
  140. return 0;
  141. }
  142. static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
  143. {
  144. struct ngene_channel *chan = fe->analog_demod_priv;
  145. if (lock)
  146. down(&chan->dev->pll_mutex);
  147. else
  148. up(&chan->dev->pll_mutex);
  149. }
  150. static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
  151. {
  152. struct i2c_msg msgs[1] = {{.addr = adr, .flags = I2C_M_RD,
  153. .buf = val, .len = 1 } };
  154. return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
  155. }
  156. static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
  157. u16 reg, u8 *val)
  158. {
  159. u8 msg[2] = {reg>>8, reg&0xff};
  160. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  161. .buf = msg, .len = 2},
  162. {.addr = adr, .flags = I2C_M_RD,
  163. .buf = val, .len = 1} };
  164. return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
  165. }
  166. static int port_has_stv0900(struct i2c_adapter *i2c, int port)
  167. {
  168. u8 val;
  169. if (i2c_read_reg16(i2c, 0x68+port/2, 0xf100, &val) < 0)
  170. return 0;
  171. return 1;
  172. }
  173. static int port_has_drxk(struct i2c_adapter *i2c, int port)
  174. {
  175. u8 val;
  176. if (i2c_read(i2c, 0x29+port, &val) < 0)
  177. return 0;
  178. return 1;
  179. }
  180. static int demod_attach_drxk(struct ngene_channel *chan,
  181. struct i2c_adapter *i2c)
  182. {
  183. struct drxk_config config;
  184. memset(&config, 0, sizeof(config));
  185. config.microcode_name = "drxk_a3.mc";
  186. config.qam_demod_parameter_count = 4;
  187. config.adr = 0x29 + (chan->number ^ 2);
  188. chan->fe = dvb_attach(drxk_attach, &config, i2c);
  189. if (!chan->fe) {
  190. printk(KERN_ERR "No DRXK found!\n");
  191. return -ENODEV;
  192. }
  193. chan->fe->sec_priv = chan;
  194. chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
  195. chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  196. return 0;
  197. }
  198. static int cineS2_probe(struct ngene_channel *chan)
  199. {
  200. struct i2c_adapter *i2c;
  201. struct stv090x_config *fe_conf;
  202. u8 buf[3];
  203. struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
  204. int rc;
  205. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  206. if (chan->number < 2)
  207. i2c = &chan->dev->channel[0].i2c_adapter;
  208. else
  209. i2c = &chan->dev->channel[1].i2c_adapter;
  210. if (port_has_stv0900(i2c, chan->number)) {
  211. chan->demod_type = 0;
  212. fe_conf = chan->dev->card_info->fe_config[chan->number];
  213. /* demod found, attach it */
  214. rc = demod_attach_stv0900(chan);
  215. if (rc < 0 || chan->number < 2)
  216. return rc;
  217. /* demod #2: reprogram outputs DPN1 & DPN2 */
  218. i2c_msg.addr = fe_conf->address;
  219. i2c_msg.len = 3;
  220. buf[0] = 0xf1;
  221. switch (chan->number) {
  222. case 2:
  223. buf[1] = 0x5c;
  224. buf[2] = 0xc2;
  225. break;
  226. case 3:
  227. buf[1] = 0x61;
  228. buf[2] = 0xcc;
  229. break;
  230. default:
  231. return -ENODEV;
  232. }
  233. rc = i2c_transfer(i2c, &i2c_msg, 1);
  234. if (rc != 1) {
  235. printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
  236. return -EIO;
  237. }
  238. } else if (port_has_drxk(i2c, chan->number^2)) {
  239. chan->demod_type = 1;
  240. demod_attach_drxk(chan, i2c);
  241. } else {
  242. printk(KERN_ERR "No demod found on chan %d\n", chan->number);
  243. return -ENODEV;
  244. }
  245. return 0;
  246. }
  247. static struct lgdt330x_config aver_m780 = {
  248. .demod_address = 0xb2 >> 1,
  249. .demod_chip = LGDT3303,
  250. .serial_mpeg = 0x00, /* PARALLEL */
  251. .clock_polarity_flip = 1,
  252. };
  253. static struct mt2131_config m780_tunerconfig = {
  254. 0xc0 >> 1
  255. };
  256. /* A single func to attach the demo and tuner, rather than
  257. * use two sep funcs like the current design mandates.
  258. */
  259. static int demod_attach_lg330x(struct ngene_channel *chan)
  260. {
  261. chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
  262. if (chan->fe == NULL) {
  263. printk(KERN_ERR DEVICE_NAME ": No LGDT330x found!\n");
  264. return -ENODEV;
  265. }
  266. dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
  267. &m780_tunerconfig, 0);
  268. return (chan->fe) ? 0 : -ENODEV;
  269. }
  270. static int demod_attach_drxd(struct ngene_channel *chan)
  271. {
  272. struct drxd_config *feconf;
  273. feconf = chan->dev->card_info->fe_config[chan->number];
  274. chan->fe = dvb_attach(drxd_attach, feconf, chan,
  275. &chan->i2c_adapter, &chan->dev->pci_dev->dev);
  276. if (!chan->fe) {
  277. pr_err("No DRXD found!\n");
  278. return -ENODEV;
  279. }
  280. return 0;
  281. }
  282. static int tuner_attach_dtt7520x(struct ngene_channel *chan)
  283. {
  284. struct drxd_config *feconf;
  285. feconf = chan->dev->card_info->fe_config[chan->number];
  286. if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
  287. &chan->i2c_adapter,
  288. feconf->pll_type)) {
  289. pr_err("No pll(%d) found!\n", feconf->pll_type);
  290. return -ENODEV;
  291. }
  292. return 0;
  293. }
  294. /****************************************************************************/
  295. /* EEPROM TAGS **************************************************************/
  296. /****************************************************************************/
  297. #define MICNG_EE_START 0x0100
  298. #define MICNG_EE_END 0x0FF0
  299. #define MICNG_EETAG_END0 0x0000
  300. #define MICNG_EETAG_END1 0xFFFF
  301. /* 0x0001 - 0x000F reserved for housekeeping */
  302. /* 0xFFFF - 0xFFFE reserved for housekeeping */
  303. /* Micronas assigned tags
  304. EEProm tags for hardware support */
  305. #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
  306. #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
  307. #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
  308. #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
  309. /* Tag range for OEMs */
  310. #define MICNG_EETAG_OEM_FIRST 0xC000
  311. #define MICNG_EETAG_OEM_LAST 0xFFEF
  312. static int i2c_write_eeprom(struct i2c_adapter *adapter,
  313. u8 adr, u16 reg, u8 data)
  314. {
  315. u8 m[3] = {(reg >> 8), (reg & 0xff), data};
  316. struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
  317. .len = sizeof(m)};
  318. if (i2c_transfer(adapter, &msg, 1) != 1) {
  319. pr_err(DEVICE_NAME ": Error writing EEPROM!\n");
  320. return -EIO;
  321. }
  322. return 0;
  323. }
  324. static int i2c_read_eeprom(struct i2c_adapter *adapter,
  325. u8 adr, u16 reg, u8 *data, int len)
  326. {
  327. u8 msg[2] = {(reg >> 8), (reg & 0xff)};
  328. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  329. .buf = msg, .len = 2 },
  330. {.addr = adr, .flags = I2C_M_RD,
  331. .buf = data, .len = len} };
  332. if (i2c_transfer(adapter, msgs, 2) != 2) {
  333. pr_err(DEVICE_NAME ": Error reading EEPROM\n");
  334. return -EIO;
  335. }
  336. return 0;
  337. }
  338. static int ReadEEProm(struct i2c_adapter *adapter,
  339. u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
  340. {
  341. int status = 0;
  342. u16 Addr = MICNG_EE_START, Length, tag = 0;
  343. u8 EETag[3];
  344. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  345. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  346. return -1;
  347. tag = (EETag[0] << 8) | EETag[1];
  348. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  349. return -1;
  350. if (tag == Tag)
  351. break;
  352. Addr += sizeof(u16) + 1 + EETag[2];
  353. }
  354. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  355. pr_err(DEVICE_NAME
  356. ": Reached EOEE @ Tag = %04x Length = %3d\n",
  357. tag, EETag[2]);
  358. return -1;
  359. }
  360. Length = EETag[2];
  361. if (Length > MaxLen)
  362. Length = (u16) MaxLen;
  363. if (Length > 0) {
  364. Addr += sizeof(u16) + 1;
  365. status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
  366. if (!status) {
  367. *pLength = EETag[2];
  368. #if 0
  369. if (Length < EETag[2])
  370. status = STATUS_BUFFER_OVERFLOW;
  371. #endif
  372. }
  373. }
  374. return status;
  375. }
  376. static int WriteEEProm(struct i2c_adapter *adapter,
  377. u16 Tag, u32 Length, u8 *data)
  378. {
  379. int status = 0;
  380. u16 Addr = MICNG_EE_START;
  381. u8 EETag[3];
  382. u16 tag = 0;
  383. int retry, i;
  384. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  385. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  386. return -1;
  387. tag = (EETag[0] << 8) | EETag[1];
  388. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  389. return -1;
  390. if (tag == Tag)
  391. break;
  392. Addr += sizeof(u16) + 1 + EETag[2];
  393. }
  394. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  395. pr_err(DEVICE_NAME
  396. ": Reached EOEE @ Tag = %04x Length = %3d\n",
  397. tag, EETag[2]);
  398. return -1;
  399. }
  400. if (Length > EETag[2])
  401. return -EINVAL;
  402. /* Note: We write the data one byte at a time to avoid
  403. issues with page sizes. (which are different for
  404. each manufacture and eeprom size)
  405. */
  406. Addr += sizeof(u16) + 1;
  407. for (i = 0; i < Length; i++, Addr++) {
  408. status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
  409. if (status)
  410. break;
  411. /* Poll for finishing write cycle */
  412. retry = 10;
  413. while (retry) {
  414. u8 Tmp;
  415. msleep(50);
  416. status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
  417. if (status)
  418. break;
  419. if (Tmp != data[i])
  420. pr_err(DEVICE_NAME
  421. "eeprom write error\n");
  422. retry -= 1;
  423. }
  424. if (status) {
  425. pr_err(DEVICE_NAME
  426. ": Timeout polling eeprom\n");
  427. break;
  428. }
  429. }
  430. return status;
  431. }
  432. static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
  433. {
  434. int stat;
  435. u8 buf[2];
  436. u32 len = 0;
  437. stat = ReadEEProm(adapter, tag, 2, buf, &len);
  438. if (stat)
  439. return stat;
  440. if (len != 2)
  441. return -EINVAL;
  442. *data = (buf[0] << 8) | buf[1];
  443. return 0;
  444. }
  445. static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
  446. {
  447. int stat;
  448. u8 buf[2];
  449. buf[0] = data >> 8;
  450. buf[1] = data & 0xff;
  451. stat = WriteEEProm(adapter, tag, 2, buf);
  452. if (stat)
  453. return stat;
  454. return 0;
  455. }
  456. static s16 osc_deviation(void *priv, s16 deviation, int flag)
  457. {
  458. struct ngene_channel *chan = priv;
  459. struct i2c_adapter *adap = &chan->i2c_adapter;
  460. u16 data = 0;
  461. if (flag) {
  462. data = (u16) deviation;
  463. pr_info(DEVICE_NAME ": write deviation %d\n",
  464. deviation);
  465. eeprom_write_ushort(adap, 0x1000 + chan->number, data);
  466. } else {
  467. if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
  468. data = 0;
  469. pr_info(DEVICE_NAME ": read deviation %d\n",
  470. (s16) data);
  471. }
  472. return (s16) data;
  473. }
  474. /****************************************************************************/
  475. /* Switch control (I2C gates, etc.) *****************************************/
  476. /****************************************************************************/
  477. static struct stv090x_config fe_cineS2 = {
  478. .device = STV0900,
  479. .demod_mode = STV090x_DUAL,
  480. .clk_mode = STV090x_CLK_EXT,
  481. .xtal = 27000000,
  482. .address = 0x68,
  483. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  484. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  485. .repeater_level = STV090x_RPTLEVEL_16,
  486. .adc1_range = STV090x_ADC_1Vpp,
  487. .adc2_range = STV090x_ADC_1Vpp,
  488. .diseqc_envelope_mode = true,
  489. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  490. };
  491. static struct stv090x_config fe_cineS2_2 = {
  492. .device = STV0900,
  493. .demod_mode = STV090x_DUAL,
  494. .clk_mode = STV090x_CLK_EXT,
  495. .xtal = 27000000,
  496. .address = 0x69,
  497. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  498. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  499. .repeater_level = STV090x_RPTLEVEL_16,
  500. .adc1_range = STV090x_ADC_1Vpp,
  501. .adc2_range = STV090x_ADC_1Vpp,
  502. .diseqc_envelope_mode = true,
  503. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  504. };
  505. static struct stv6110x_config tuner_cineS2_0 = {
  506. .addr = 0x60,
  507. .refclk = 27000000,
  508. .clk_div = 1,
  509. };
  510. static struct stv6110x_config tuner_cineS2_1 = {
  511. .addr = 0x63,
  512. .refclk = 27000000,
  513. .clk_div = 1,
  514. };
  515. static const struct ngene_info ngene_info_cineS2 = {
  516. .type = NGENE_SIDEWINDER,
  517. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
  518. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  519. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  520. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  521. .fe_config = {&fe_cineS2, &fe_cineS2},
  522. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  523. .lnb = {0x0b, 0x08},
  524. .tsf = {3, 3},
  525. .fw_version = 18,
  526. .msi_supported = true,
  527. };
  528. static const struct ngene_info ngene_info_satixS2 = {
  529. .type = NGENE_SIDEWINDER,
  530. .name = "Mystique SaTiX-S2 Dual",
  531. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  532. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  533. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  534. .fe_config = {&fe_cineS2, &fe_cineS2},
  535. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  536. .lnb = {0x0b, 0x08},
  537. .tsf = {3, 3},
  538. .fw_version = 18,
  539. .msi_supported = true,
  540. };
  541. static const struct ngene_info ngene_info_satixS2v2 = {
  542. .type = NGENE_SIDEWINDER,
  543. .name = "Mystique SaTiX-S2 Dual (v2)",
  544. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  545. NGENE_IO_TSOUT},
  546. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  547. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  548. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  549. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  550. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  551. .tsf = {3, 3},
  552. .fw_version = 18,
  553. .msi_supported = true,
  554. };
  555. static const struct ngene_info ngene_info_cineS2v5 = {
  556. .type = NGENE_SIDEWINDER,
  557. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
  558. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  559. NGENE_IO_TSOUT},
  560. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  561. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  562. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  563. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  564. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  565. .tsf = {3, 3},
  566. .fw_version = 18,
  567. .msi_supported = true,
  568. };
  569. static const struct ngene_info ngene_info_duoFlex = {
  570. .type = NGENE_SIDEWINDER,
  571. .name = "Digital Devices DuoFlex PCIe or miniPCIe",
  572. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  573. NGENE_IO_TSOUT},
  574. .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
  575. .tuner_attach = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
  576. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  577. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  578. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  579. .tsf = {3, 3},
  580. .fw_version = 18,
  581. .msi_supported = true,
  582. };
  583. static const struct ngene_info ngene_info_m780 = {
  584. .type = NGENE_APP,
  585. .name = "Aver M780 ATSC/QAM-B",
  586. /* Channel 0 is analog, which is currently unsupported */
  587. .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
  588. .demod_attach = { NULL, demod_attach_lg330x },
  589. /* Ensure these are NULL else the frame will call them (as funcs) */
  590. .tuner_attach = { NULL, NULL, NULL, NULL },
  591. .fe_config = { NULL, &aver_m780 },
  592. .avf = { 0 },
  593. /* A custom electrical interface config for the demod to bridge */
  594. .tsf = { 4, 4 },
  595. .fw_version = 15,
  596. };
  597. static struct drxd_config fe_terratec_dvbt_0 = {
  598. .index = 0,
  599. .demod_address = 0x70,
  600. .demod_revision = 0xa2,
  601. .demoda_address = 0x00,
  602. .pll_address = 0x60,
  603. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  604. .clock = 20000,
  605. .osc_deviation = osc_deviation,
  606. };
  607. static struct drxd_config fe_terratec_dvbt_1 = {
  608. .index = 1,
  609. .demod_address = 0x71,
  610. .demod_revision = 0xa2,
  611. .demoda_address = 0x00,
  612. .pll_address = 0x60,
  613. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  614. .clock = 20000,
  615. .osc_deviation = osc_deviation,
  616. };
  617. static const struct ngene_info ngene_info_terratec = {
  618. .type = NGENE_TERRATEC,
  619. .name = "Terratec Integra/Cinergy2400i Dual DVB-T",
  620. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  621. .demod_attach = {demod_attach_drxd, demod_attach_drxd},
  622. .tuner_attach = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
  623. .fe_config = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
  624. .i2c_access = 1,
  625. };
  626. /****************************************************************************/
  627. /****************************************************************************/
  628. /* PCI Subsystem ID *********************************************************/
  629. /****************************************************************************/
  630. #define NGENE_ID(_subvend, _subdev, _driverdata) { \
  631. .vendor = NGENE_VID, .device = NGENE_PID, \
  632. .subvendor = _subvend, .subdevice = _subdev, \
  633. .driver_data = (unsigned long) &_driverdata }
  634. /****************************************************************************/
  635. static const struct pci_device_id ngene_id_tbl[] = {
  636. NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
  637. NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
  638. NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
  639. NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
  640. NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
  641. NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
  642. NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
  643. NGENE_ID(0x1461, 0x062e, ngene_info_m780),
  644. NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
  645. {0}
  646. };
  647. MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
  648. /****************************************************************************/
  649. /* Init/Exit ****************************************************************/
  650. /****************************************************************************/
  651. static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
  652. enum pci_channel_state state)
  653. {
  654. printk(KERN_ERR DEVICE_NAME ": PCI error\n");
  655. if (state == pci_channel_io_perm_failure)
  656. return PCI_ERS_RESULT_DISCONNECT;
  657. if (state == pci_channel_io_frozen)
  658. return PCI_ERS_RESULT_NEED_RESET;
  659. return PCI_ERS_RESULT_CAN_RECOVER;
  660. }
  661. static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
  662. {
  663. printk(KERN_INFO DEVICE_NAME ": slot reset\n");
  664. return 0;
  665. }
  666. static void ngene_resume(struct pci_dev *dev)
  667. {
  668. printk(KERN_INFO DEVICE_NAME ": resume\n");
  669. }
  670. static const struct pci_error_handlers ngene_errors = {
  671. .error_detected = ngene_error_detected,
  672. .slot_reset = ngene_slot_reset,
  673. .resume = ngene_resume,
  674. };
  675. static struct pci_driver ngene_pci_driver = {
  676. .name = "ngene",
  677. .id_table = ngene_id_tbl,
  678. .probe = ngene_probe,
  679. .remove = ngene_remove,
  680. .err_handler = &ngene_errors,
  681. .shutdown = ngene_shutdown,
  682. };
  683. static __init int module_init_ngene(void)
  684. {
  685. printk(KERN_INFO
  686. "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
  687. return pci_register_driver(&ngene_pci_driver);
  688. }
  689. static __exit void module_exit_ngene(void)
  690. {
  691. pci_unregister_driver(&ngene_pci_driver);
  692. }
  693. module_init(module_init_ngene);
  694. module_exit(module_exit_ngene);
  695. MODULE_DESCRIPTION("nGene");
  696. MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
  697. MODULE_LICENSE("GPL");