cx23885-dvb.c 5.8 KB

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