cx23885-dvb.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_generic_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 mt2131_config hauppauge_generic_tunerconfig = {
  77. 0x61
  78. };
  79. static int dvb_register(struct cx23885_tsport *port)
  80. {
  81. struct cx23885_dev *dev = port->dev;
  82. /* init struct videobuf_dvb */
  83. port->dvb.name = dev->name;
  84. /* init frontend */
  85. switch (dev->board) {
  86. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  87. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  88. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  89. port->dvb.frontend = dvb_attach(s5h1409_attach,
  90. &hauppauge_generic_config,
  91. &dev->i2c_bus[0].i2c_adap);
  92. if (port->dvb.frontend != NULL) {
  93. dvb_attach(mt2131_attach, port->dvb.frontend,
  94. &dev->i2c_bus[0].i2c_adap,
  95. &hauppauge_generic_tunerconfig, 0);
  96. }
  97. break;
  98. default:
  99. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  100. dev->name);
  101. break;
  102. }
  103. if (NULL == port->dvb.frontend) {
  104. printk("%s: frontend initialization failed\n", dev->name);
  105. return -1;
  106. }
  107. /* Put the analog decoder in standby to keep it quiet */
  108. cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
  109. /* register everything */
  110. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  111. &dev->pci->dev);
  112. }
  113. int cx23885_dvb_register(struct cx23885_tsport *port)
  114. {
  115. struct cx23885_dev *dev = port->dev;
  116. int err;
  117. dprintk(1, "%s\n", __FUNCTION__);
  118. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  119. dev->board,
  120. dev->name,
  121. dev->pci_bus,
  122. dev->pci_slot);
  123. err = -ENODEV;
  124. if (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB))
  125. goto fail_core;
  126. /* dvb stuff */
  127. printk("%s: cx23885 based dvb card\n", dev->name);
  128. videobuf_queue_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
  129. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  130. sizeof(struct cx23885_buffer), port);
  131. err = dvb_register(port);
  132. if (err != 0)
  133. printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
  134. fail_core:
  135. return err;
  136. }
  137. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  138. {
  139. /* dvb */
  140. if(port->dvb.frontend)
  141. videobuf_dvb_unregister(&port->dvb);
  142. return 0;
  143. }
  144. /*
  145. * Local variables:
  146. * c-basic-offset: 8
  147. * End:
  148. * 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
  149. */