cx23885-dvb.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/device.h>
  24. #include <linux/fs.h>
  25. #include <linux/kthread.h>
  26. #include <linux/file.h>
  27. #include <linux/suspend.h>
  28. #include "cx23885.h"
  29. #include <media/v4l2-common.h>
  30. #include "s5h1409.h"
  31. #include "mt2131.h"
  32. #include "lgdt330x.h"
  33. #include "xc5000.h"
  34. #include "dvb-pll.h"
  35. static unsigned int debug = 0;
  36. #define dprintk(level,fmt, arg...) if (debug >= level) \
  37. printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
  38. /* ------------------------------------------------------------------ */
  39. static int dvb_buf_setup(struct videobuf_queue *q,
  40. unsigned int *count, unsigned int *size)
  41. {
  42. struct cx23885_tsport *port = q->priv_data;
  43. port->ts_packet_size = 188 * 4;
  44. port->ts_packet_count = 32;
  45. *size = port->ts_packet_size * port->ts_packet_count;
  46. *count = 32;
  47. return 0;
  48. }
  49. static int dvb_buf_prepare(struct videobuf_queue *q,
  50. struct videobuf_buffer *vb, enum v4l2_field field)
  51. {
  52. struct cx23885_tsport *port = q->priv_data;
  53. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  54. }
  55. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  56. {
  57. struct cx23885_tsport *port = q->priv_data;
  58. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  59. }
  60. static void dvb_buf_release(struct videobuf_queue *q,
  61. struct videobuf_buffer *vb)
  62. {
  63. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  64. }
  65. static int cx23885_request_firmware(struct dvb_frontend *fe,
  66. const struct firmware **fw, char *name)
  67. {
  68. struct cx23885_tsport *port = fe->dvb->priv;
  69. struct cx23885_dev *dev = port->dev;
  70. dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name);
  71. return request_firmware(fw, name, &dev->pci->dev);
  72. }
  73. static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe)
  74. {
  75. struct cx23885_tsport *port = fe->dvb->priv;
  76. struct cx23885_dev *dev = port->dev;
  77. dprintk(1, "%s()\n", __FUNCTION__);
  78. /* Drive the tuner into reset back back */
  79. cx_clear(GP0_IO, 0x00000004);
  80. mdelay(200);
  81. cx_set(GP0_IO, 0x00000004);
  82. return 0;
  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. static struct s5h1409_config hauppauge_generic_config = {
  91. .demod_address = 0x32 >> 1,
  92. .output_mode = S5H1409_SERIAL_OUTPUT,
  93. .gpio = S5H1409_GPIO_ON,
  94. .qam_if = 44000,
  95. .inversion = S5H1409_INVERSION_OFF,
  96. .status_mode = S5H1409_DEMODLOCKING
  97. };
  98. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  99. .demod_address = 0x32 >> 1,
  100. .output_mode = S5H1409_SERIAL_OUTPUT,
  101. .gpio = S5H1409_GPIO_OFF,
  102. .qam_if = 44000,
  103. .inversion = S5H1409_INVERSION_OFF,
  104. .status_mode = S5H1409_DEMODLOCKING
  105. };
  106. static struct mt2131_config hauppauge_generic_tunerconfig = {
  107. 0x61
  108. };
  109. static struct lgdt330x_config fusionhdtv_5_express = {
  110. .demod_address = 0x0e,
  111. .demod_chip = LGDT3303,
  112. .serial_mpeg = 0x40,
  113. };
  114. static struct s5h1409_config hauppauge_hvr1500q_config = {
  115. .demod_address = 0x32 >> 1,
  116. .output_mode = S5H1409_SERIAL_OUTPUT,
  117. .gpio = S5H1409_GPIO_ON,
  118. .qam_if = 44000,
  119. .inversion = S5H1409_INVERSION_OFF,
  120. .status_mode = S5H1409_DEMODLOCKING
  121. };
  122. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  123. .i2c_address = 0x61,
  124. .if_frequency = 4570000,
  125. .request_firmware = cx23885_request_firmware,
  126. .tuner_reset = hauppauge_hvr1500q_tuner_reset
  127. };
  128. static int dvb_register(struct cx23885_tsport *port)
  129. {
  130. struct cx23885_dev *dev = port->dev;
  131. struct cx23885_i2c *i2c_bus = NULL;
  132. /* init struct videobuf_dvb */
  133. port->dvb.name = dev->name;
  134. /* init frontend */
  135. switch (dev->board) {
  136. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  137. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  138. i2c_bus = &dev->i2c_bus[0];
  139. port->dvb.frontend = dvb_attach(s5h1409_attach,
  140. &hauppauge_generic_config,
  141. &i2c_bus->i2c_adap);
  142. if (port->dvb.frontend != NULL) {
  143. dvb_attach(mt2131_attach, port->dvb.frontend,
  144. &i2c_bus->i2c_adap,
  145. &hauppauge_generic_tunerconfig, 0);
  146. }
  147. break;
  148. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  149. i2c_bus = &dev->i2c_bus[0];
  150. port->dvb.frontend = dvb_attach(s5h1409_attach,
  151. &hauppauge_hvr1800lp_config,
  152. &i2c_bus->i2c_adap);
  153. if (port->dvb.frontend != NULL) {
  154. dvb_attach(mt2131_attach, port->dvb.frontend,
  155. &i2c_bus->i2c_adap,
  156. &hauppauge_generic_tunerconfig, 0);
  157. }
  158. break;
  159. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  160. i2c_bus = &dev->i2c_bus[0];
  161. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  162. &fusionhdtv_5_express,
  163. &i2c_bus->i2c_adap);
  164. if (port->dvb.frontend != NULL) {
  165. dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
  166. &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
  167. }
  168. break;
  169. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  170. i2c_bus = &dev->i2c_bus[1];
  171. port->dvb.frontend = dvb_attach(s5h1409_attach,
  172. &hauppauge_hvr1500q_config,
  173. &dev->i2c_bus[0].i2c_adap);
  174. if (port->dvb.frontend != NULL) {
  175. dvb_attach(xc5000_attach, port->dvb.frontend,
  176. &i2c_bus->i2c_adap,
  177. &hauppauge_hvr1500q_tunerconfig);
  178. }
  179. break;
  180. default:
  181. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  182. dev->name);
  183. break;
  184. }
  185. if (NULL == port->dvb.frontend) {
  186. printk("%s: frontend initialization failed\n", dev->name);
  187. return -1;
  188. }
  189. /* Put the analog decoder in standby to keep it quiet */
  190. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  191. /* register everything */
  192. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  193. &dev->pci->dev);
  194. }
  195. int cx23885_dvb_register(struct cx23885_tsport *port)
  196. {
  197. struct cx23885_dev *dev = port->dev;
  198. int err;
  199. dprintk(1, "%s\n", __FUNCTION__);
  200. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  201. dev->board,
  202. dev->name,
  203. dev->pci_bus,
  204. dev->pci_slot);
  205. err = -ENODEV;
  206. /* dvb stuff */
  207. printk("%s: cx23885 based dvb card\n", dev->name);
  208. videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
  209. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  210. sizeof(struct cx23885_buffer), port);
  211. err = dvb_register(port);
  212. if (err != 0)
  213. printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
  214. return err;
  215. }
  216. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  217. {
  218. /* dvb */
  219. if(port->dvb.frontend)
  220. videobuf_dvb_unregister(&port->dvb);
  221. return 0;
  222. }
  223. /*
  224. * Local variables:
  225. * c-basic-offset: 8
  226. * End:
  227. * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  228. */