ngene-cards.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. /****************************************************************************/
  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. 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 demod_attach_stv0900(struct ngene_channel *chan)
  75. {
  76. struct i2c_adapter *i2c;
  77. struct stv090x_config *feconf = (struct stv090x_config *)
  78. chan->dev->card_info->fe_config[chan->number];
  79. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  80. /* Note: Both adapters share the same i2c bus, but the demod */
  81. /* driver requires that each demod has its own i2c adapter */
  82. if (chan->number < 2)
  83. i2c = &chan->dev->channel[0].i2c_adapter;
  84. else
  85. i2c = &chan->dev->channel[1].i2c_adapter;
  86. chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
  87. (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
  88. : STV090x_DEMODULATOR_1);
  89. if (chan->fe == NULL) {
  90. printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
  91. return -ENODEV;
  92. }
  93. /* store channel info */
  94. if (feconf->tuner_i2c_lock)
  95. chan->fe->analog_demod_priv = chan;
  96. if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
  97. 0, chan->dev->card_info->lnb[chan->number])) {
  98. printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
  99. dvb_frontend_detach(chan->fe);
  100. chan->fe = NULL;
  101. return -ENODEV;
  102. }
  103. return 0;
  104. }
  105. static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
  106. {
  107. struct ngene_channel *chan = fe->analog_demod_priv;
  108. if (lock)
  109. down(&chan->dev->pll_mutex);
  110. else
  111. up(&chan->dev->pll_mutex);
  112. }
  113. static int cineS2_probe(struct ngene_channel *chan)
  114. {
  115. struct i2c_adapter *i2c;
  116. struct stv090x_config *fe_conf;
  117. u8 buf[3];
  118. struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
  119. int rc;
  120. /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
  121. if (chan->number < 2)
  122. i2c = &chan->dev->channel[0].i2c_adapter;
  123. else
  124. i2c = &chan->dev->channel[1].i2c_adapter;
  125. fe_conf = chan->dev->card_info->fe_config[chan->number];
  126. i2c_msg.addr = fe_conf->address;
  127. /* probe demod */
  128. i2c_msg.len = 2;
  129. buf[0] = 0xf1;
  130. buf[1] = 0x00;
  131. rc = i2c_transfer(i2c, &i2c_msg, 1);
  132. if (rc != 1)
  133. return -ENODEV;
  134. /* demod found, attach it */
  135. rc = demod_attach_stv0900(chan);
  136. if (rc < 0 || chan->number < 2)
  137. return rc;
  138. /* demod #2: reprogram outputs DPN1 & DPN2 */
  139. i2c_msg.len = 3;
  140. buf[0] = 0xf1;
  141. switch (chan->number) {
  142. case 2:
  143. buf[1] = 0x5c;
  144. buf[2] = 0xc2;
  145. break;
  146. case 3:
  147. buf[1] = 0x61;
  148. buf[2] = 0xcc;
  149. break;
  150. default:
  151. return -ENODEV;
  152. }
  153. rc = i2c_transfer(i2c, &i2c_msg, 1);
  154. if (rc != 1) {
  155. printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
  156. return -EIO;
  157. }
  158. return 0;
  159. }
  160. static struct lgdt330x_config aver_m780 = {
  161. .demod_address = 0xb2 >> 1,
  162. .demod_chip = LGDT3303,
  163. .serial_mpeg = 0x00, /* PARALLEL */
  164. .clock_polarity_flip = 1,
  165. };
  166. static struct mt2131_config m780_tunerconfig = {
  167. 0xc0 >> 1
  168. };
  169. /* A single func to attach the demo and tuner, rather than
  170. * use two sep funcs like the current design mandates.
  171. */
  172. static int demod_attach_lg330x(struct ngene_channel *chan)
  173. {
  174. chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
  175. if (chan->fe == NULL) {
  176. printk(KERN_ERR DEVICE_NAME ": No LGDT330x found!\n");
  177. return -ENODEV;
  178. }
  179. dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
  180. &m780_tunerconfig, 0);
  181. return (chan->fe) ? 0 : -ENODEV;
  182. }
  183. /****************************************************************************/
  184. /* Switch control (I2C gates, etc.) *****************************************/
  185. /****************************************************************************/
  186. static struct stv090x_config fe_cineS2 = {
  187. .device = STV0900,
  188. .demod_mode = STV090x_DUAL,
  189. .clk_mode = STV090x_CLK_EXT,
  190. .xtal = 27000000,
  191. .address = 0x68,
  192. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  193. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  194. .repeater_level = STV090x_RPTLEVEL_16,
  195. .adc1_range = STV090x_ADC_1Vpp,
  196. .adc2_range = STV090x_ADC_1Vpp,
  197. .diseqc_envelope_mode = true,
  198. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  199. };
  200. static struct stv090x_config fe_cineS2_2 = {
  201. .device = STV0900,
  202. .demod_mode = STV090x_DUAL,
  203. .clk_mode = STV090x_CLK_EXT,
  204. .xtal = 27000000,
  205. .address = 0x69,
  206. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  207. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  208. .repeater_level = STV090x_RPTLEVEL_16,
  209. .adc1_range = STV090x_ADC_1Vpp,
  210. .adc2_range = STV090x_ADC_1Vpp,
  211. .diseqc_envelope_mode = true,
  212. .tuner_i2c_lock = cineS2_tuner_i2c_lock,
  213. };
  214. static struct stv6110x_config tuner_cineS2_0 = {
  215. .addr = 0x60,
  216. .refclk = 27000000,
  217. .clk_div = 1,
  218. };
  219. static struct stv6110x_config tuner_cineS2_1 = {
  220. .addr = 0x63,
  221. .refclk = 27000000,
  222. .clk_div = 1,
  223. };
  224. static struct ngene_info ngene_info_cineS2 = {
  225. .type = NGENE_SIDEWINDER,
  226. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
  227. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  228. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  229. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  230. .fe_config = {&fe_cineS2, &fe_cineS2},
  231. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  232. .lnb = {0x0b, 0x08},
  233. .tsf = {3, 3},
  234. .fw_version = 18,
  235. .msi_supported = true,
  236. };
  237. static struct ngene_info ngene_info_satixS2 = {
  238. .type = NGENE_SIDEWINDER,
  239. .name = "Mystique SaTiX-S2 Dual",
  240. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  241. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  242. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  243. .fe_config = {&fe_cineS2, &fe_cineS2},
  244. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  245. .lnb = {0x0b, 0x08},
  246. .tsf = {3, 3},
  247. .fw_version = 18,
  248. .msi_supported = true,
  249. };
  250. static struct ngene_info ngene_info_satixS2v2 = {
  251. .type = NGENE_SIDEWINDER,
  252. .name = "Mystique SaTiX-S2 Dual (v2)",
  253. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  254. NGENE_IO_TSOUT},
  255. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  256. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
  257. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  258. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  259. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  260. .tsf = {3, 3},
  261. .fw_version = 18,
  262. .msi_supported = true,
  263. };
  264. static struct ngene_info ngene_info_cineS2v5 = {
  265. .type = NGENE_SIDEWINDER,
  266. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
  267. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  268. NGENE_IO_TSOUT},
  269. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
  270. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
  271. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  272. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  273. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  274. .tsf = {3, 3},
  275. .fw_version = 18,
  276. .msi_supported = true,
  277. };
  278. static struct ngene_info ngene_info_duoFlexS2 = {
  279. .type = NGENE_SIDEWINDER,
  280. .name = "Digital Devices DuoFlex S2 miniPCIe",
  281. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
  282. NGENE_IO_TSOUT},
  283. .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
  284. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
  285. .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
  286. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
  287. .lnb = {0x0a, 0x08, 0x0b, 0x09},
  288. .tsf = {3, 3},
  289. .fw_version = 18,
  290. .msi_supported = true,
  291. };
  292. static struct ngene_info ngene_info_m780 = {
  293. .type = NGENE_APP,
  294. .name = "Aver M780 ATSC/QAM-B",
  295. /* Channel 0 is analog, which is currently unsupported */
  296. .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
  297. .demod_attach = { NULL, demod_attach_lg330x },
  298. /* Ensure these are NULL else the frame will call them (as funcs) */
  299. .tuner_attach = { 0, 0, 0, 0 },
  300. .fe_config = { NULL, &aver_m780 },
  301. .avf = { 0 },
  302. /* A custom electrical interface config for the demod to bridge */
  303. .tsf = { 4, 4 },
  304. .fw_version = 15,
  305. };
  306. /****************************************************************************/
  307. /****************************************************************************/
  308. /* PCI Subsystem ID *********************************************************/
  309. /****************************************************************************/
  310. #define NGENE_ID(_subvend, _subdev, _driverdata) { \
  311. .vendor = NGENE_VID, .device = NGENE_PID, \
  312. .subvendor = _subvend, .subdevice = _subdev, \
  313. .driver_data = (unsigned long) &_driverdata }
  314. /****************************************************************************/
  315. static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
  316. NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
  317. NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
  318. NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
  319. NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
  320. NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
  321. NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlexS2),
  322. NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlexS2),
  323. NGENE_ID(0x1461, 0x062e, ngene_info_m780),
  324. {0}
  325. };
  326. MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
  327. /****************************************************************************/
  328. /* Init/Exit ****************************************************************/
  329. /****************************************************************************/
  330. static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
  331. enum pci_channel_state state)
  332. {
  333. printk(KERN_ERR DEVICE_NAME ": PCI error\n");
  334. if (state == pci_channel_io_perm_failure)
  335. return PCI_ERS_RESULT_DISCONNECT;
  336. if (state == pci_channel_io_frozen)
  337. return PCI_ERS_RESULT_NEED_RESET;
  338. return PCI_ERS_RESULT_CAN_RECOVER;
  339. }
  340. static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
  341. {
  342. printk(KERN_INFO DEVICE_NAME ": link reset\n");
  343. return 0;
  344. }
  345. static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
  346. {
  347. printk(KERN_INFO DEVICE_NAME ": slot reset\n");
  348. return 0;
  349. }
  350. static void ngene_resume(struct pci_dev *dev)
  351. {
  352. printk(KERN_INFO DEVICE_NAME ": resume\n");
  353. }
  354. static struct pci_error_handlers ngene_errors = {
  355. .error_detected = ngene_error_detected,
  356. .link_reset = ngene_link_reset,
  357. .slot_reset = ngene_slot_reset,
  358. .resume = ngene_resume,
  359. };
  360. static struct pci_driver ngene_pci_driver = {
  361. .name = "ngene",
  362. .id_table = ngene_id_tbl,
  363. .probe = ngene_probe,
  364. .remove = __devexit_p(ngene_remove),
  365. .err_handler = &ngene_errors,
  366. .shutdown = ngene_shutdown,
  367. };
  368. static __init int module_init_ngene(void)
  369. {
  370. printk(KERN_INFO
  371. "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
  372. return pci_register_driver(&ngene_pci_driver);
  373. }
  374. static __exit void module_exit_ngene(void)
  375. {
  376. pci_unregister_driver(&ngene_pci_driver);
  377. }
  378. module_init(module_init_ngene);
  379. module_exit(module_exit_ngene);
  380. MODULE_DESCRIPTION("nGene");
  381. MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
  382. MODULE_LICENSE("GPL");