ngene-cards.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. const 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. return 0;
  285. }
  286. static int tuner_attach_dtt7520x(struct ngene_channel *chan)
  287. {
  288. struct drxd_config *feconf;
  289. feconf = chan->dev->card_info->fe_config[chan->number];
  290. if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
  291. &chan->i2c_adapter,
  292. feconf->pll_type)) {
  293. pr_err("No pll(%d) found!\n", feconf->pll_type);
  294. return -ENODEV;
  295. }
  296. return 0;
  297. }
  298. /****************************************************************************/
  299. /* EEPROM TAGS **************************************************************/
  300. /****************************************************************************/
  301. #define MICNG_EE_START 0x0100
  302. #define MICNG_EE_END 0x0FF0
  303. #define MICNG_EETAG_END0 0x0000
  304. #define MICNG_EETAG_END1 0xFFFF
  305. /* 0x0001 - 0x000F reserved for housekeeping */
  306. /* 0xFFFF - 0xFFFE reserved for housekeeping */
  307. /* Micronas assigned tags
  308. EEProm tags for hardware support */
  309. #define MICNG_EETAG_DRXD1_OSCDEVIATION 0x1000 /* 2 Bytes data */
  310. #define MICNG_EETAG_DRXD2_OSCDEVIATION 0x1001 /* 2 Bytes data */
  311. #define MICNG_EETAG_MT2060_1_1STIF 0x1100 /* 2 Bytes data */
  312. #define MICNG_EETAG_MT2060_2_1STIF 0x1101 /* 2 Bytes data */
  313. /* Tag range for OEMs */
  314. #define MICNG_EETAG_OEM_FIRST 0xC000
  315. #define MICNG_EETAG_OEM_LAST 0xFFEF
  316. static int i2c_write_eeprom(struct i2c_adapter *adapter,
  317. u8 adr, u16 reg, u8 data)
  318. {
  319. u8 m[3] = {(reg >> 8), (reg & 0xff), data};
  320. struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m,
  321. .len = sizeof(m)};
  322. if (i2c_transfer(adapter, &msg, 1) != 1) {
  323. pr_err(DEVICE_NAME ": Error writing EEPROM!\n");
  324. return -EIO;
  325. }
  326. return 0;
  327. }
  328. static int i2c_read_eeprom(struct i2c_adapter *adapter,
  329. u8 adr, u16 reg, u8 *data, int len)
  330. {
  331. u8 msg[2] = {(reg >> 8), (reg & 0xff)};
  332. struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
  333. .buf = msg, .len = 2 },
  334. {.addr = adr, .flags = I2C_M_RD,
  335. .buf = data, .len = len} };
  336. if (i2c_transfer(adapter, msgs, 2) != 2) {
  337. pr_err(DEVICE_NAME ": Error reading EEPROM\n");
  338. return -EIO;
  339. }
  340. return 0;
  341. }
  342. static int ReadEEProm(struct i2c_adapter *adapter,
  343. u16 Tag, u32 MaxLen, u8 *data, u32 *pLength)
  344. {
  345. int status = 0;
  346. u16 Addr = MICNG_EE_START, Length, tag = 0;
  347. u8 EETag[3];
  348. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  349. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  350. return -1;
  351. tag = (EETag[0] << 8) | EETag[1];
  352. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  353. return -1;
  354. if (tag == Tag)
  355. break;
  356. Addr += sizeof(u16) + 1 + EETag[2];
  357. }
  358. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  359. pr_err(DEVICE_NAME
  360. ": Reached EOEE @ Tag = %04x Length = %3d\n",
  361. tag, EETag[2]);
  362. return -1;
  363. }
  364. Length = EETag[2];
  365. if (Length > MaxLen)
  366. Length = (u16) MaxLen;
  367. if (Length > 0) {
  368. Addr += sizeof(u16) + 1;
  369. status = i2c_read_eeprom(adapter, 0x50, Addr, data, Length);
  370. if (!status) {
  371. *pLength = EETag[2];
  372. #if 0
  373. if (Length < EETag[2])
  374. status = STATUS_BUFFER_OVERFLOW;
  375. #endif
  376. }
  377. }
  378. return status;
  379. }
  380. static int WriteEEProm(struct i2c_adapter *adapter,
  381. u16 Tag, u32 Length, u8 *data)
  382. {
  383. int status = 0;
  384. u16 Addr = MICNG_EE_START;
  385. u8 EETag[3];
  386. u16 tag = 0;
  387. int retry, i;
  388. while (Addr + sizeof(u16) + 1 < MICNG_EE_END) {
  389. if (i2c_read_eeprom(adapter, 0x50, Addr, EETag, sizeof(EETag)))
  390. return -1;
  391. tag = (EETag[0] << 8) | EETag[1];
  392. if (tag == MICNG_EETAG_END0 || tag == MICNG_EETAG_END1)
  393. return -1;
  394. if (tag == Tag)
  395. break;
  396. Addr += sizeof(u16) + 1 + EETag[2];
  397. }
  398. if (Addr + sizeof(u16) + 1 + EETag[2] > MICNG_EE_END) {
  399. pr_err(DEVICE_NAME
  400. ": Reached EOEE @ Tag = %04x Length = %3d\n",
  401. tag, EETag[2]);
  402. return -1;
  403. }
  404. if (Length > EETag[2])
  405. return -EINVAL;
  406. /* Note: We write the data one byte at a time to avoid
  407. issues with page sizes. (which are different for
  408. each manufacture and eeprom size)
  409. */
  410. Addr += sizeof(u16) + 1;
  411. for (i = 0; i < Length; i++, Addr++) {
  412. status = i2c_write_eeprom(adapter, 0x50, Addr, data[i]);
  413. if (status)
  414. break;
  415. /* Poll for finishing write cycle */
  416. retry = 10;
  417. while (retry) {
  418. u8 Tmp;
  419. msleep(50);
  420. status = i2c_read_eeprom(adapter, 0x50, Addr, &Tmp, 1);
  421. if (status)
  422. break;
  423. if (Tmp != data[i])
  424. pr_err(DEVICE_NAME
  425. "eeprom write error\n");
  426. retry -= 1;
  427. }
  428. if (status) {
  429. pr_err(DEVICE_NAME
  430. ": Timeout polling eeprom\n");
  431. break;
  432. }
  433. }
  434. return status;
  435. }
  436. static int eeprom_read_ushort(struct i2c_adapter *adapter, u16 tag, u16 *data)
  437. {
  438. int stat;
  439. u8 buf[2];
  440. u32 len = 0;
  441. stat = ReadEEProm(adapter, tag, 2, buf, &len);
  442. if (stat)
  443. return stat;
  444. if (len != 2)
  445. return -EINVAL;
  446. *data = (buf[0] << 8) | buf[1];
  447. return 0;
  448. }
  449. static int eeprom_write_ushort(struct i2c_adapter *adapter, u16 tag, u16 data)
  450. {
  451. int stat;
  452. u8 buf[2];
  453. buf[0] = data >> 8;
  454. buf[1] = data & 0xff;
  455. stat = WriteEEProm(adapter, tag, 2, buf);
  456. if (stat)
  457. return stat;
  458. return 0;
  459. }
  460. static s16 osc_deviation(void *priv, s16 deviation, int flag)
  461. {
  462. struct ngene_channel *chan = priv;
  463. struct i2c_adapter *adap = &chan->i2c_adapter;
  464. u16 data = 0;
  465. if (flag) {
  466. data = (u16) deviation;
  467. pr_info(DEVICE_NAME ": write deviation %d\n",
  468. deviation);
  469. eeprom_write_ushort(adap, 0x1000 + chan->number, data);
  470. } else {
  471. if (eeprom_read_ushort(adap, 0x1000 + chan->number, &data))
  472. data = 0;
  473. pr_info(DEVICE_NAME ": read deviation %d\n",
  474. (s16) data);
  475. }
  476. return (s16) data;
  477. }
  478. /****************************************************************************/
  479. /* Switch control (I2C gates, etc.) *****************************************/
  480. /****************************************************************************/
  481. static struct stv090x_config fe_cineS2 = {
  482. .device = STV0900,
  483. .demod_mode = STV090x_DUAL,
  484. .clk_mode = STV090x_CLK_EXT,
  485. .xtal = 27000000,
  486. .address = 0x68,
  487. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  488. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  489. .repeater_level = STV090x_RPTLEVEL_16,
  490. .adc1_range = STV090x_ADC_1Vpp,
  491. .adc2_range = STV090x_ADC_1Vpp,
  492. .diseqc_envelope_mode = true,
  493. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  494. };
  495. static struct stv090x_config fe_cineS2_2 = {
  496. .device = STV0900,
  497. .demod_mode = STV090x_DUAL,
  498. .clk_mode = STV090x_CLK_EXT,
  499. .xtal = 27000000,
  500. .address = 0x69,
  501. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  502. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  503. .repeater_level = STV090x_RPTLEVEL_16,
  504. .adc1_range = STV090x_ADC_1Vpp,
  505. .adc2_range = STV090x_ADC_1Vpp,
  506. .diseqc_envelope_mode = true,
  507. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  508. };
  509. static struct stv6110x_config tuner_cineS2_0 = {
  510. .addr = 0x60,
  511. .refclk = 27000000,
  512. .clk_div = 1,
  513. };
  514. static struct stv6110x_config tuner_cineS2_1 = {
  515. .addr = 0x63,
  516. .refclk = 27000000,
  517. .clk_div = 1,
  518. };
  519. static const struct ngene_info ngene_info_cineS2 = {
  520. .type = NGENE_SIDEWINDER,
  521. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
  522. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  523. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  524. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  525. .fe_config = {&fe_cineS2, &fe_cineS2},
  526. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  527. .lnb = {0x0b, 0x08},
  528. .tsf = {3, 3},
  529. .fw_version = 18,
  530. .msi_supported = true,
  531. };
  532. static const struct ngene_info ngene_info_satixS2 = {
  533. .type = NGENE_SIDEWINDER,
  534. .name = "Mystique SaTiX-S2 Dual",
  535. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  536. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  537. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  538. .fe_config = {&fe_cineS2, &fe_cineS2},
  539. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  540. .lnb = {0x0b, 0x08},
  541. .tsf = {3, 3},
  542. .fw_version = 18,
  543. .msi_supported = true,
  544. };
  545. static const struct ngene_info ngene_info_satixS2v2 = {
  546. .type = NGENE_SIDEWINDER,
  547. .name = "Mystique SaTiX-S2 Dual (v2)",
  548. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  549. NGENE_IO_TSOUT},
  550. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  551. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  552. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  553. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  554. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  555. .tsf = {3, 3},
  556. .fw_version = 18,
  557. .msi_supported = true,
  558. };
  559. static const struct ngene_info ngene_info_cineS2v5 = {
  560. .type = NGENE_SIDEWINDER,
  561. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
  562. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  563. NGENE_IO_TSOUT},
  564. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  565. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_probe, tuner_attach_probe},
  566. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  567. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  568. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  569. .tsf = {3, 3},
  570. .fw_version = 18,
  571. .msi_supported = true,
  572. };
  573. static const struct ngene_info ngene_info_duoFlex = {
  574. .type = NGENE_SIDEWINDER,
  575. .name = "Digital Devices DuoFlex PCIe or miniPCIe",
  576. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  577. NGENE_IO_TSOUT},
  578. .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
  579. .tuner_attach = {tuner_attach_probe, tuner_attach_probe, tuner_attach_probe, tuner_attach_probe},
  580. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  581. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  582. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  583. .tsf = {3, 3},
  584. .fw_version = 18,
  585. .msi_supported = true,
  586. };
  587. static const struct ngene_info ngene_info_m780 = {
  588. .type = NGENE_APP,
  589. .name = "Aver M780 ATSC/QAM-B",
  590. /* Channel 0 is analog, which is currently unsupported */
  591. .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
  592. .demod_attach = { NULL, demod_attach_lg330x },
  593. /* Ensure these are NULL else the frame will call them (as funcs) */
  594. .tuner_attach = { NULL, NULL, NULL, NULL },
  595. .fe_config = { NULL, &aver_m780 },
  596. .avf = { 0 },
  597. /* A custom electrical interface config for the demod to bridge */
  598. .tsf = { 4, 4 },
  599. .fw_version = 15,
  600. };
  601. static struct drxd_config fe_terratec_dvbt_0 = {
  602. .index = 0,
  603. .demod_address = 0x70,
  604. .demod_revision = 0xa2,
  605. .demoda_address = 0x00,
  606. .pll_address = 0x60,
  607. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  608. .clock = 20000,
  609. .osc_deviation = osc_deviation,
  610. };
  611. static struct drxd_config fe_terratec_dvbt_1 = {
  612. .index = 1,
  613. .demod_address = 0x71,
  614. .demod_revision = 0xa2,
  615. .demoda_address = 0x00,
  616. .pll_address = 0x60,
  617. .pll_type = DVB_PLL_THOMSON_DTT7520X,
  618. .clock = 20000,
  619. .osc_deviation = osc_deviation,
  620. };
  621. static const struct ngene_info ngene_info_terratec = {
  622. .type = NGENE_TERRATEC,
  623. .name = "Terratec Integra/Cinergy2400i Dual DVB-T",
  624. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  625. .demod_attach = {demod_attach_drxd, demod_attach_drxd},
  626. .tuner_attach = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
  627. .fe_config = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
  628. .i2c_access = 1,
  629. };
  630. /****************************************************************************/
  631. /****************************************************************************/
  632. /* PCI Subsystem ID *********************************************************/
  633. /****************************************************************************/
  634. #define NGENE_ID(_subvend, _subdev, _driverdata) { \
  635. .vendor = NGENE_VID, .device = NGENE_PID, \
  636. .subvendor = _subvend, .subdevice = _subdev, \
  637. .driver_data = (unsigned long) &_driverdata }
  638. /****************************************************************************/
  639. static const struct pci_device_id ngene_id_tbl[] = {
  640. NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
  641. NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
  642. NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
  643. NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
  644. NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
  645. NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlex),
  646. NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlex),
  647. NGENE_ID(0x1461, 0x062e, ngene_info_m780),
  648. NGENE_ID(0x153b, 0x1167, ngene_info_terratec),
  649. {0}
  650. };
  651. MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
  652. /****************************************************************************/
  653. /* Init/Exit ****************************************************************/
  654. /****************************************************************************/
  655. static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
  656. enum pci_channel_state state)
  657. {
  658. printk(KERN_ERR DEVICE_NAME ": PCI error\n");
  659. if (state == pci_channel_io_perm_failure)
  660. return PCI_ERS_RESULT_DISCONNECT;
  661. if (state == pci_channel_io_frozen)
  662. return PCI_ERS_RESULT_NEED_RESET;
  663. return PCI_ERS_RESULT_CAN_RECOVER;
  664. }
  665. static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
  666. {
  667. printk(KERN_INFO DEVICE_NAME ": link reset\n");
  668. return 0;
  669. }
  670. static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
  671. {
  672. printk(KERN_INFO DEVICE_NAME ": slot reset\n");
  673. return 0;
  674. }
  675. static void ngene_resume(struct pci_dev *dev)
  676. {
  677. printk(KERN_INFO DEVICE_NAME ": resume\n");
  678. }
  679. static const struct pci_error_handlers ngene_errors = {
  680. .error_detected = ngene_error_detected,
  681. .link_reset = ngene_link_reset,
  682. .slot_reset = ngene_slot_reset,
  683. .resume = ngene_resume,
  684. };
  685. static struct pci_driver ngene_pci_driver = {
  686. .name = "ngene",
  687. .id_table = ngene_id_tbl,
  688. .probe = ngene_probe,
  689. .remove = ngene_remove,
  690. .err_handler = &ngene_errors,
  691. .shutdown = ngene_shutdown,
  692. };
  693. static __init int module_init_ngene(void)
  694. {
  695. printk(KERN_INFO
  696. "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
  697. return pci_register_driver(&ngene_pci_driver);
  698. }
  699. static __exit void module_exit_ngene(void)
  700. {
  701. pci_unregister_driver(&ngene_pci_driver);
  702. }
  703. module_init(module_init_ngene);
  704. module_exit(module_exit_ngene);
  705. MODULE_DESCRIPTION("nGene");
  706. MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
  707. MODULE_LICENSE("GPL");