ngene-cards.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 stv090x_config *feconf = (struct stv090x_config *)
  46. chan->dev->card_info->fe_config[chan->number];
  47. struct stv6110x_config *tunerconf = (struct stv6110x_config *)
  48. chan->dev->card_info->tuner_config[chan->number];
  49. struct stv6110x_devctl *ctl;
  50. ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf,
  51. &chan->i2c_adapter);
  52. if (ctl == NULL) {
  53. printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
  54. return -ENODEV;
  55. }
  56. feconf->tuner_init = ctl->tuner_init;
  57. feconf->tuner_set_mode = ctl->tuner_set_mode;
  58. feconf->tuner_set_frequency = ctl->tuner_set_frequency;
  59. feconf->tuner_get_frequency = ctl->tuner_get_frequency;
  60. feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
  61. feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
  62. feconf->tuner_set_bbgain = ctl->tuner_set_bbgain;
  63. feconf->tuner_get_bbgain = ctl->tuner_get_bbgain;
  64. feconf->tuner_set_refclk = ctl->tuner_set_refclk;
  65. feconf->tuner_get_status = ctl->tuner_get_status;
  66. return 0;
  67. }
  68. static int demod_attach_stv0900(struct ngene_channel *chan)
  69. {
  70. struct stv090x_config *feconf = (struct stv090x_config *)
  71. chan->dev->card_info->fe_config[chan->number];
  72. chan->fe = dvb_attach(stv090x_attach,
  73. feconf,
  74. &chan->i2c_adapter,
  75. chan->number == 0 ? STV090x_DEMODULATOR_0 :
  76. STV090x_DEMODULATOR_1);
  77. if (chan->fe == NULL) {
  78. printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
  79. return -ENODEV;
  80. }
  81. if (!dvb_attach(lnbh24_attach, chan->fe, &chan->i2c_adapter, 0,
  82. 0, chan->dev->card_info->lnb[chan->number])) {
  83. printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
  84. dvb_frontend_detach(chan->fe);
  85. return -ENODEV;
  86. }
  87. return 0;
  88. }
  89. static struct lgdt330x_config aver_m780 = {
  90. .demod_address = 0xb2 >> 1,
  91. .demod_chip = LGDT3303,
  92. .serial_mpeg = 0x00, /* PARALLEL */
  93. .clock_polarity_flip = 1,
  94. };
  95. static struct mt2131_config m780_tunerconfig = {
  96. 0xc0 >> 1
  97. };
  98. /* A single func to attach the demo and tuner, rather than
  99. * use two sep funcs like the current design mandates.
  100. */
  101. static int demod_attach_lg330x(struct ngene_channel *chan)
  102. {
  103. chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
  104. if (chan->fe == NULL) {
  105. printk(KERN_ERR DEVICE_NAME ": No LGDT330x found!\n");
  106. return -ENODEV;
  107. }
  108. dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
  109. &m780_tunerconfig, 0);
  110. return (chan->fe) ? 0 : -ENODEV;
  111. }
  112. /****************************************************************************/
  113. /* Switch control (I2C gates, etc.) *****************************************/
  114. /****************************************************************************/
  115. static struct stv090x_config fe_cineS2 = {
  116. .device = STV0900,
  117. .demod_mode = STV090x_DUAL,
  118. .clk_mode = STV090x_CLK_EXT,
  119. .xtal = 27000000,
  120. .address = 0x68,
  121. .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  122. .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
  123. .repeater_level = STV090x_RPTLEVEL_16,
  124. .adc1_range = STV090x_ADC_1Vpp,
  125. .adc2_range = STV090x_ADC_1Vpp,
  126. .diseqc_envelope_mode = true,
  127. };
  128. static struct stv6110x_config tuner_cineS2_0 = {
  129. .addr = 0x60,
  130. .refclk = 27000000,
  131. .clk_div = 1,
  132. };
  133. static struct stv6110x_config tuner_cineS2_1 = {
  134. .addr = 0x63,
  135. .refclk = 27000000,
  136. .clk_div = 1,
  137. };
  138. static struct ngene_info ngene_info_cineS2 = {
  139. .type = NGENE_SIDEWINDER,
  140. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
  141. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  142. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  143. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  144. .fe_config = {&fe_cineS2, &fe_cineS2},
  145. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  146. .lnb = {0x0b, 0x08},
  147. .tsf = {3, 3},
  148. .fw_version = 15,
  149. };
  150. static struct ngene_info ngene_info_satixS2 = {
  151. .type = NGENE_SIDEWINDER,
  152. .name = "Mystique SaTiX-S2 Dual",
  153. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  154. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  155. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  156. .fe_config = {&fe_cineS2, &fe_cineS2},
  157. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  158. .lnb = {0x0b, 0x08},
  159. .tsf = {3, 3},
  160. .fw_version = 15,
  161. };
  162. static struct ngene_info ngene_info_satixS2v2 = {
  163. .type = NGENE_SIDEWINDER,
  164. .name = "Mystique SaTiX-S2 Dual (v2)",
  165. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  166. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  167. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  168. .fe_config = {&fe_cineS2, &fe_cineS2},
  169. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  170. .lnb = {0x0a, 0x08},
  171. .tsf = {3, 3},
  172. .fw_version = 15,
  173. };
  174. static struct ngene_info ngene_info_cineS2v5 = {
  175. .type = NGENE_SIDEWINDER,
  176. .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
  177. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  178. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  179. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  180. .fe_config = {&fe_cineS2, &fe_cineS2},
  181. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  182. .lnb = {0x0a, 0x08},
  183. .tsf = {3, 3},
  184. .fw_version = 15,
  185. };
  186. static struct ngene_info ngene_info_duoFlexS2 = {
  187. .type = NGENE_SIDEWINDER,
  188. .name = "Digital Devices DuoFlex S2 miniPCIe",
  189. .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
  190. .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
  191. .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
  192. .fe_config = {&fe_cineS2, &fe_cineS2},
  193. .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
  194. .lnb = {0x0a, 0x08},
  195. .tsf = {3, 3},
  196. .fw_version = 15,
  197. };
  198. static struct ngene_info ngene_info_m780 = {
  199. .type = NGENE_APP,
  200. .name = "Aver M780 ATSC/QAM-B",
  201. /* Channel 0 is analog, which is currently unsupported */
  202. .io_type = { NGENE_IO_NONE, NGENE_IO_TSIN },
  203. .demod_attach = { NULL, demod_attach_lg330x },
  204. /* Ensure these are NULL else the frame will call them (as funcs) */
  205. .tuner_attach = { 0, 0, 0, 0 },
  206. .fe_config = { NULL, &aver_m780 },
  207. .avf = { 0 },
  208. /* A custom electrical interface config for the demod to bridge */
  209. .tsf = { 4, 4 },
  210. .fw_version = 15,
  211. };
  212. /****************************************************************************/
  213. /****************************************************************************/
  214. /* PCI Subsystem ID *********************************************************/
  215. /****************************************************************************/
  216. #define NGENE_ID(_subvend, _subdev, _driverdata) { \
  217. .vendor = NGENE_VID, .device = NGENE_PID, \
  218. .subvendor = _subvend, .subdevice = _subdev, \
  219. .driver_data = (unsigned long) &_driverdata }
  220. /****************************************************************************/
  221. static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
  222. NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
  223. NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
  224. NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
  225. NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
  226. NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
  227. NGENE_ID(0x18c3, 0xdd10, ngene_info_duoFlexS2),
  228. NGENE_ID(0x18c3, 0xdd20, ngene_info_duoFlexS2),
  229. NGENE_ID(0x1461, 0x062e, ngene_info_m780),
  230. {0}
  231. };
  232. MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
  233. /****************************************************************************/
  234. /* Init/Exit ****************************************************************/
  235. /****************************************************************************/
  236. static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
  237. enum pci_channel_state state)
  238. {
  239. printk(KERN_ERR DEVICE_NAME ": PCI error\n");
  240. if (state == pci_channel_io_perm_failure)
  241. return PCI_ERS_RESULT_DISCONNECT;
  242. if (state == pci_channel_io_frozen)
  243. return PCI_ERS_RESULT_NEED_RESET;
  244. return PCI_ERS_RESULT_CAN_RECOVER;
  245. }
  246. static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
  247. {
  248. printk(KERN_INFO DEVICE_NAME ": link reset\n");
  249. return 0;
  250. }
  251. static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
  252. {
  253. printk(KERN_INFO DEVICE_NAME ": slot reset\n");
  254. return 0;
  255. }
  256. static void ngene_resume(struct pci_dev *dev)
  257. {
  258. printk(KERN_INFO DEVICE_NAME ": resume\n");
  259. }
  260. static struct pci_error_handlers ngene_errors = {
  261. .error_detected = ngene_error_detected,
  262. .link_reset = ngene_link_reset,
  263. .slot_reset = ngene_slot_reset,
  264. .resume = ngene_resume,
  265. };
  266. static struct pci_driver ngene_pci_driver = {
  267. .name = "ngene",
  268. .id_table = ngene_id_tbl,
  269. .probe = ngene_probe,
  270. .remove = __devexit_p(ngene_remove),
  271. .err_handler = &ngene_errors,
  272. };
  273. static __init int module_init_ngene(void)
  274. {
  275. printk(KERN_INFO
  276. "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
  277. return pci_register_driver(&ngene_pci_driver);
  278. }
  279. static __exit void module_exit_ngene(void)
  280. {
  281. pci_unregister_driver(&ngene_pci_driver);
  282. }
  283. module_init(module_init_ngene);
  284. module_exit(module_exit_ngene);
  285. MODULE_DESCRIPTION("nGene");
  286. MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
  287. MODULE_LICENSE("GPL");