ngene-cards.c 22 KB

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