cx88-dvb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*
  2. * $Id: cx88-dvb.c,v 1.37 2005/06/28 23:41:47 mkrufky Exp $
  3. *
  4. * device driver for Conexant 2388x based TV cards
  5. * MPEG Transport Stream (DVB) routines
  6. *
  7. * (c) 2004 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  8. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/device.h>
  27. #include <linux/fs.h>
  28. #include <linux/kthread.h>
  29. #include <linux/file.h>
  30. #include <linux/suspend.h>
  31. /* these three frontends need merging via linuxtv cvs ... */
  32. #define HAVE_CX22702 1
  33. #define HAVE_OR51132 1
  34. #define HAVE_LGDT3302 1
  35. #include "cx88.h"
  36. #include "dvb-pll.h"
  37. #include "mt352.h"
  38. #include "mt352_priv.h"
  39. #if HAVE_CX22702
  40. # include "cx22702.h"
  41. #endif
  42. #if HAVE_OR51132
  43. # include "or51132.h"
  44. #endif
  45. #if HAVE_LGDT3302
  46. # include "lgdt3302.h"
  47. #endif
  48. MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
  49. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  50. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  51. MODULE_LICENSE("GPL");
  52. static unsigned int debug = 0;
  53. module_param(debug, int, 0644);
  54. MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
  55. #define dprintk(level,fmt, arg...) if (debug >= level) \
  56. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
  57. /* ------------------------------------------------------------------ */
  58. static int dvb_buf_setup(struct videobuf_queue *q,
  59. unsigned int *count, unsigned int *size)
  60. {
  61. struct cx8802_dev *dev = q->priv_data;
  62. dev->ts_packet_size = 188 * 4;
  63. dev->ts_packet_count = 32;
  64. *size = dev->ts_packet_size * dev->ts_packet_count;
  65. *count = 32;
  66. return 0;
  67. }
  68. static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  69. enum v4l2_field field)
  70. {
  71. struct cx8802_dev *dev = q->priv_data;
  72. return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb);
  73. }
  74. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  75. {
  76. struct cx8802_dev *dev = q->priv_data;
  77. cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
  78. }
  79. static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  80. {
  81. struct cx8802_dev *dev = q->priv_data;
  82. cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
  83. }
  84. static struct videobuf_queue_ops dvb_qops = {
  85. .buf_setup = dvb_buf_setup,
  86. .buf_prepare = dvb_buf_prepare,
  87. .buf_queue = dvb_buf_queue,
  88. .buf_release = dvb_buf_release,
  89. };
  90. /* ------------------------------------------------------------------ */
  91. static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
  92. {
  93. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
  94. static u8 reset [] = { RESET, 0x80 };
  95. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  96. static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
  97. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  98. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  99. mt352_write(fe, clock_config, sizeof(clock_config));
  100. udelay(200);
  101. mt352_write(fe, reset, sizeof(reset));
  102. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  103. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  104. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  105. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  106. return 0;
  107. }
  108. static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
  109. {
  110. static u8 clock_config [] = { 0x89, 0x38, 0x39 };
  111. static u8 reset [] = { 0x50, 0x80 };
  112. static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  113. static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
  114. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  115. static u8 dntv_extra[] = { 0xB5, 0x7A };
  116. static u8 capt_range_cfg[] = { 0x75, 0x32 };
  117. mt352_write(fe, clock_config, sizeof(clock_config));
  118. udelay(2000);
  119. mt352_write(fe, reset, sizeof(reset));
  120. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  121. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  122. udelay(2000);
  123. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  124. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  125. return 0;
  126. }
  127. static int mt352_pll_set(struct dvb_frontend* fe,
  128. struct dvb_frontend_parameters* params,
  129. u8* pllbuf)
  130. {
  131. struct cx8802_dev *dev= fe->dvb->priv;
  132. pllbuf[0] = dev->core->pll_addr << 1;
  133. dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
  134. params->frequency,
  135. params->u.ofdm.bandwidth);
  136. return 0;
  137. }
  138. static struct mt352_config dvico_fusionhdtv = {
  139. .demod_address = 0x0F,
  140. .demod_init = dvico_fusionhdtv_demod_init,
  141. .pll_set = mt352_pll_set,
  142. };
  143. static struct mt352_config dntv_live_dvbt_config = {
  144. .demod_address = 0x0f,
  145. .demod_init = dntv_live_dvbt_demod_init,
  146. .pll_set = mt352_pll_set,
  147. };
  148. #if HAVE_CX22702
  149. static struct cx22702_config connexant_refboard_config = {
  150. .demod_address = 0x43,
  151. .pll_address = 0x60,
  152. .pll_desc = &dvb_pll_thomson_dtt7579,
  153. };
  154. static struct cx22702_config hauppauge_novat_config = {
  155. .demod_address = 0x43,
  156. .pll_address = 0x61,
  157. .pll_desc = &dvb_pll_thomson_dtt759x,
  158. };
  159. #endif
  160. #if HAVE_OR51132
  161. static int or51132_set_ts_param(struct dvb_frontend* fe,
  162. int is_punctured)
  163. {
  164. struct cx8802_dev *dev= fe->dvb->priv;
  165. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  166. return 0;
  167. }
  168. static struct or51132_config pchdtv_hd3000 = {
  169. .demod_address = 0x15,
  170. .pll_address = 0x61,
  171. .pll_desc = &dvb_pll_thomson_dtt7610,
  172. .set_ts_params = or51132_set_ts_param,
  173. };
  174. #endif
  175. #if HAVE_LGDT3302
  176. static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  177. {
  178. struct cx8802_dev *dev= fe->dvb->priv;
  179. if (is_punctured)
  180. dev->ts_gen_cntrl |= 0x04;
  181. else
  182. dev->ts_gen_cntrl &= ~0x04;
  183. return 0;
  184. }
  185. static struct lgdt3302_config fusionhdtv_3_gold_q = {
  186. .demod_address = 0x0e,
  187. .pll_address = 0x61,
  188. .pll_desc = &dvb_pll_microtune_4042,
  189. .set_ts_params = lgdt3302_set_ts_param,
  190. };
  191. #endif
  192. static int dvb_register(struct cx8802_dev *dev)
  193. {
  194. /* init struct videobuf_dvb */
  195. dev->dvb.name = dev->core->name;
  196. dev->ts_gen_cntrl = 0x0c;
  197. /* init frontend */
  198. switch (dev->core->board) {
  199. #if HAVE_CX22702
  200. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  201. dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
  202. &dev->core->i2c_adap);
  203. break;
  204. case CX88_BOARD_CONEXANT_DVB_T1:
  205. dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
  206. &dev->core->i2c_adap);
  207. break;
  208. #endif
  209. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
  210. dev->core->pll_addr = 0x61;
  211. dev->core->pll_desc = &dvb_pll_lg_z201;
  212. dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
  213. &dev->core->i2c_adap);
  214. break;
  215. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
  216. dev->core->pll_addr = 0x60;
  217. dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
  218. dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
  219. &dev->core->i2c_adap);
  220. break;
  221. case CX88_BOARD_KWORLD_DVB_T:
  222. case CX88_BOARD_DNTV_LIVE_DVB_T:
  223. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  224. dev->core->pll_addr = 0x61;
  225. dev->core->pll_desc = &dvb_pll_unknown_1;
  226. dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
  227. &dev->core->i2c_adap);
  228. break;
  229. #if HAVE_OR51132
  230. case CX88_BOARD_PCHDTV_HD3000:
  231. dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
  232. &dev->core->i2c_adap);
  233. break;
  234. #endif
  235. #if HAVE_LGDT3302
  236. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
  237. dev->ts_gen_cntrl = 0x08;
  238. {
  239. /* Do a hardware reset of chip before using it. */
  240. struct cx88_core *core = dev->core;
  241. cx_clear(MO_GP0_IO, 1);
  242. mdelay(100);
  243. cx_set(MO_GP0_IO, 9); // ANT connector too FIXME
  244. mdelay(200);
  245. dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q,
  246. &dev->core->i2c_adap);
  247. }
  248. break;
  249. #endif
  250. default:
  251. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  252. dev->core->name);
  253. break;
  254. }
  255. if (NULL == dev->dvb.frontend) {
  256. printk("%s: frontend initialization failed\n",dev->core->name);
  257. return -1;
  258. }
  259. if (dev->core->pll_desc) {
  260. dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
  261. dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
  262. }
  263. /* Copy the board name into the DVB structure */
  264. strlcpy(dev->dvb.frontend->ops->info.name,
  265. cx88_boards[dev->core->board].name,
  266. sizeof(dev->dvb.frontend->ops->info.name));
  267. /* register everything */
  268. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
  269. }
  270. /* ----------------------------------------------------------- */
  271. static int __devinit dvb_probe(struct pci_dev *pci_dev,
  272. const struct pci_device_id *pci_id)
  273. {
  274. struct cx8802_dev *dev;
  275. struct cx88_core *core;
  276. int err;
  277. /* general setup */
  278. core = cx88_core_get(pci_dev);
  279. if (NULL == core)
  280. return -EINVAL;
  281. err = -ENODEV;
  282. if (!cx88_boards[core->board].dvb)
  283. goto fail_core;
  284. err = -ENOMEM;
  285. dev = kmalloc(sizeof(*dev),GFP_KERNEL);
  286. if (NULL == dev)
  287. goto fail_core;
  288. memset(dev,0,sizeof(*dev));
  289. dev->pci = pci_dev;
  290. dev->core = core;
  291. err = cx8802_init_common(dev);
  292. if (0 != err)
  293. goto fail_free;
  294. /* dvb stuff */
  295. printk("%s/2: cx2388x based dvb card\n", core->name);
  296. videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
  297. dev->pci, &dev->slock,
  298. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  299. V4L2_FIELD_TOP,
  300. sizeof(struct cx88_buffer),
  301. dev);
  302. err = dvb_register(dev);
  303. if (0 != err)
  304. goto fail_fini;
  305. return 0;
  306. fail_fini:
  307. cx8802_fini_common(dev);
  308. fail_free:
  309. kfree(dev);
  310. fail_core:
  311. cx88_core_put(core,pci_dev);
  312. return err;
  313. }
  314. static void __devexit dvb_remove(struct pci_dev *pci_dev)
  315. {
  316. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  317. /* dvb */
  318. videobuf_dvb_unregister(&dev->dvb);
  319. /* common */
  320. cx8802_fini_common(dev);
  321. cx88_core_put(dev->core,dev->pci);
  322. kfree(dev);
  323. }
  324. static struct pci_device_id cx8802_pci_tbl[] = {
  325. {
  326. .vendor = 0x14f1,
  327. .device = 0x8802,
  328. .subvendor = PCI_ANY_ID,
  329. .subdevice = PCI_ANY_ID,
  330. },{
  331. /* --- end of list --- */
  332. }
  333. };
  334. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  335. static struct pci_driver dvb_pci_driver = {
  336. .name = "cx88-dvb",
  337. .id_table = cx8802_pci_tbl,
  338. .probe = dvb_probe,
  339. .remove = __devexit_p(dvb_remove),
  340. .suspend = cx8802_suspend_common,
  341. .resume = cx8802_resume_common,
  342. };
  343. static int dvb_init(void)
  344. {
  345. printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
  346. (CX88_VERSION_CODE >> 16) & 0xff,
  347. (CX88_VERSION_CODE >> 8) & 0xff,
  348. CX88_VERSION_CODE & 0xff);
  349. #ifdef SNAPSHOT
  350. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  351. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  352. #endif
  353. return pci_register_driver(&dvb_pci_driver);
  354. }
  355. static void dvb_fini(void)
  356. {
  357. pci_unregister_driver(&dvb_pci_driver);
  358. }
  359. module_init(dvb_init);
  360. module_exit(dvb_fini);
  361. /*
  362. * Local variables:
  363. * c-basic-offset: 8
  364. * compile-command: "make DVB=1"
  365. * End:
  366. */