cx23885-dvb.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. static unsigned int debug = 0;
  33. #define dprintk(level,fmt, arg...) if (debug >= level) \
  34. printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
  35. /* ------------------------------------------------------------------ */
  36. static int dvb_buf_setup(struct videobuf_queue *q,
  37. unsigned int *count, unsigned int *size)
  38. {
  39. struct cx23885_tsport *port = q->priv_data;
  40. port->ts_packet_size = 188 * 4;
  41. port->ts_packet_count = 32;
  42. *size = port->ts_packet_size * port->ts_packet_count;
  43. *count = 32;
  44. return 0;
  45. }
  46. static int dvb_buf_prepare(struct videobuf_queue *q,
  47. struct videobuf_buffer *vb, enum v4l2_field field)
  48. {
  49. struct cx23885_tsport *port = q->priv_data;
  50. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  51. }
  52. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  53. {
  54. struct cx23885_tsport *port = q->priv_data;
  55. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  56. }
  57. static void dvb_buf_release(struct videobuf_queue *q,
  58. struct videobuf_buffer *vb)
  59. {
  60. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  61. }
  62. static struct videobuf_queue_ops dvb_qops = {
  63. .buf_setup = dvb_buf_setup,
  64. .buf_prepare = dvb_buf_prepare,
  65. .buf_queue = dvb_buf_queue,
  66. .buf_release = dvb_buf_release,
  67. };
  68. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  69. .demod_address = 0x32 >> 1,
  70. .output_mode = S5H1409_SERIAL_OUTPUT,
  71. .gpio = S5H1409_GPIO_OFF,
  72. .if_freq = 44000,
  73. .inversion = S5H1409_INVERSION_OFF,
  74. .status_mode = S5H1409_DEMODLOCKING
  75. };
  76. static struct s5h1409_config hauppauge_hvr1800_config = {
  77. .demod_address = 0x32 >> 1,
  78. .output_mode = S5H1409_SERIAL_OUTPUT,
  79. .gpio = S5H1409_GPIO_ON,
  80. .if_freq = 44000,
  81. .inversion = S5H1409_INVERSION_OFF,
  82. .status_mode = S5H1409_DEMODLOCKING
  83. };
  84. static struct s5h1409_config hauppauge_hvr1250_config = {
  85. .demod_address = 0x32 >> 1,
  86. .output_mode = S5H1409_SERIAL_OUTPUT,
  87. .gpio = S5H1409_GPIO_ON,
  88. .if_freq = 44000,
  89. .inversion = S5H1409_INVERSION_OFF,
  90. .status_mode = S5H1409_DEMODLOCKING
  91. };
  92. static struct mt2131_config hauppauge_hvr1800lp_rev2_tunerconfig = {
  93. 0x61
  94. };
  95. static struct mt2131_config hauppauge_hvr1800_tunerconfig = {
  96. 0x61
  97. };
  98. static struct mt2131_config hauppauge_hvr1250_tunerconfig = {
  99. 0x61
  100. };
  101. static int dvb_register(struct cx23885_tsport *port)
  102. {
  103. struct cx23885_dev *dev = port->dev;
  104. /* init struct videobuf_dvb */
  105. port->dvb.name = dev->name;
  106. /* init frontend */
  107. switch (dev->board) {
  108. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  109. port->dvb.frontend = dvb_attach(s5h1409_attach,
  110. &hauppauge_hvr1250_config,
  111. &dev->i2c_bus[0].i2c_adap);
  112. if (port->dvb.frontend != NULL) {
  113. dvb_attach(mt2131_attach, port->dvb.frontend,
  114. &dev->i2c_bus[0].i2c_adap,
  115. &hauppauge_hvr1250_tunerconfig, 0);
  116. }
  117. break;
  118. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  119. port->dvb.frontend = dvb_attach(s5h1409_attach,
  120. &hauppauge_hvr1800lp_config,
  121. &dev->i2c_bus[0].i2c_adap);
  122. if (port->dvb.frontend != NULL) {
  123. dvb_attach(mt2131_attach, port->dvb.frontend,
  124. &dev->i2c_bus[0].i2c_adap,
  125. &hauppauge_hvr1800lp_rev2_tunerconfig, 0);
  126. }
  127. break;
  128. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  129. port->dvb.frontend = dvb_attach(s5h1409_attach,
  130. &hauppauge_hvr1800_config,
  131. &dev->i2c_bus[0].i2c_adap);
  132. if (port->dvb.frontend != NULL) {
  133. dvb_attach(mt2131_attach, port->dvb.frontend,
  134. &dev->i2c_bus[0].i2c_adap,
  135. &hauppauge_hvr1800_tunerconfig, 0);
  136. }
  137. break;
  138. default:
  139. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  140. dev->name);
  141. break;
  142. }
  143. if (NULL == port->dvb.frontend) {
  144. printk("%s: frontend initialization failed\n", dev->name);
  145. return -1;
  146. }
  147. /* Put the analog decoder in standby to keep it quiet */
  148. cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
  149. /* register everything */
  150. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  151. &dev->pci->dev);
  152. }
  153. int cx23885_dvb_register(struct cx23885_tsport *port)
  154. {
  155. struct cx23885_dev *dev = port->dev;
  156. int err;
  157. dprintk(1, "%s\n", __FUNCTION__);
  158. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  159. dev->board,
  160. dev->name,
  161. dev->pci_bus,
  162. dev->pci_slot);
  163. err = -ENODEV;
  164. if (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB))
  165. goto fail_core;
  166. /* dvb stuff */
  167. printk("%s: cx23885 based dvb card\n", dev->name);
  168. videobuf_queue_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
  169. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  170. sizeof(struct cx23885_buffer), port);
  171. err = dvb_register(port);
  172. if (err != 0)
  173. printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
  174. fail_core:
  175. return err;
  176. }
  177. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  178. {
  179. /* dvb */
  180. if(port->dvb.frontend)
  181. videobuf_dvb_unregister(&port->dvb);
  182. return 0;
  183. }
  184. /*
  185. * Local variables:
  186. * c-basic-offset: 8
  187. * End:
  188. * 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
  189. */