cxusb.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _DVB_USB_CXUSB_H_
  3. #define _DVB_USB_CXUSB_H_
  4. #include <linux/completion.h>
  5. #include <linux/i2c.h>
  6. #include <linux/list.h>
  7. #include <linux/mutex.h>
  8. #include <linux/usb.h>
  9. #include <linux/workqueue.h>
  10. #include <media/v4l2-common.h>
  11. #include <media/v4l2-dev.h>
  12. #include <media/v4l2-device.h>
  13. #include <media/videobuf2-core.h>
  14. #include <media/videobuf2-v4l2.h>
  15. #define DVB_USB_LOG_PREFIX "cxusb"
  16. #include "dvb-usb.h"
  17. #define CXUSB_VIDEO_URBS (5)
  18. #define CXUSB_VIDEO_URB_MAX_SIZE (512 * 1024)
  19. #define CXUSB_VIDEO_PKT_SIZE 3030
  20. #define CXUSB_VIDEO_MAX_FRAME_PKTS 346
  21. #define CXUSB_VIDEO_MAX_FRAME_SIZE (CXUSB_VIDEO_MAX_FRAME_PKTS * \
  22. CXUSB_VIDEO_PKT_SIZE)
  23. /* usb commands - some of it are guesses, don't have a reference yet */
  24. #define CMD_BLUEBIRD_GPIO_RW 0x05
  25. #define CMD_I2C_WRITE 0x08
  26. #define CMD_I2C_READ 0x09
  27. #define CMD_GPIO_READ 0x0d
  28. #define CMD_GPIO_WRITE 0x0e
  29. #define GPIO_TUNER 0x02
  30. #define CMD_POWER_OFF 0xdc
  31. #define CMD_POWER_ON 0xde
  32. #define CMD_STREAMING_ON 0x36
  33. #define CMD_STREAMING_OFF 0x37
  34. #define CMD_AVER_STREAM_ON 0x18
  35. #define CMD_AVER_STREAM_OFF 0x19
  36. #define CMD_GET_IR_CODE 0x47
  37. #define CMD_ANALOG 0x50
  38. #define CMD_DIGITAL 0x51
  39. #define CXUSB_BT656_PREAMBLE ((const u8 *)"\xff\x00\x00")
  40. #define CXUSB_BT656_FIELD_MASK BIT(6)
  41. #define CXUSB_BT656_FIELD_1 0
  42. #define CXUSB_BT656_FIELD_2 BIT(6)
  43. #define CXUSB_BT656_VBI_MASK BIT(5)
  44. #define CXUSB_BT656_VBI_ON BIT(5)
  45. #define CXUSB_BT656_VBI_OFF 0
  46. #define CXUSB_BT656_SEAV_MASK BIT(4)
  47. #define CXUSB_BT656_SEAV_EAV BIT(4)
  48. #define CXUSB_BT656_SEAV_SAV 0
  49. /* Max transfer size done by I2C transfer functions */
  50. #define MAX_XFER_SIZE 80
  51. struct cxusb_state {
  52. u8 gpio_write_state[3];
  53. bool gpio_write_refresh[3];
  54. struct i2c_client *i2c_client_demod;
  55. struct i2c_client *i2c_client_tuner;
  56. unsigned char data[MAX_XFER_SIZE];
  57. struct mutex stream_mutex;
  58. u8 last_lock;
  59. int (*fe_read_status)(struct dvb_frontend *fe,
  60. enum fe_status *status);
  61. };
  62. enum cxusb_open_type {
  63. CXUSB_OPEN_INIT,
  64. CXUSB_OPEN_NONE,
  65. CXUSB_OPEN_ANALOG,
  66. CXUSB_OPEN_DIGITAL
  67. };
  68. struct cxusb_medion_auxbuf {
  69. u8 *buf;
  70. unsigned int len;
  71. unsigned int paylen;
  72. };
  73. enum cxusb_bt656_mode {
  74. NEW_FRAME, FIRST_FIELD, SECOND_FIELD
  75. };
  76. enum cxusb_bt656_fmode {
  77. START_SEARCH, LINE_SAMPLES, VBI_SAMPLES
  78. };
  79. struct cxusb_bt656_params {
  80. enum cxusb_bt656_mode mode;
  81. enum cxusb_bt656_fmode fmode;
  82. unsigned int pos;
  83. unsigned int line;
  84. unsigned int linesamples;
  85. u8 *buf;
  86. };
  87. struct cxusb_medion_dev {
  88. /* has to be the first one */
  89. struct cxusb_state state;
  90. struct dvb_usb_device *dvbdev;
  91. enum cxusb_open_type open_type;
  92. unsigned int open_ctr;
  93. struct mutex open_lock;
  94. #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
  95. struct v4l2_device v4l2dev;
  96. struct v4l2_subdev *cx25840;
  97. struct v4l2_subdev *tuner;
  98. struct v4l2_subdev *tda9887;
  99. struct video_device *videodev, *radiodev;
  100. struct mutex dev_lock;
  101. struct vb2_queue videoqueue;
  102. u32 input;
  103. bool stop_streaming;
  104. u32 width, height;
  105. u32 field_order;
  106. struct cxusb_medion_auxbuf auxbuf;
  107. v4l2_std_id norm;
  108. struct urb *streamurbs[CXUSB_VIDEO_URBS];
  109. unsigned long urbcomplete;
  110. struct work_struct urbwork;
  111. unsigned int nexturb;
  112. struct cxusb_bt656_params bt656;
  113. struct cxusb_medion_vbuffer *vbuf;
  114. __u32 vbuf_sequence;
  115. struct list_head buflist;
  116. struct completion v4l2_release;
  117. #endif
  118. };
  119. struct cxusb_medion_vbuffer {
  120. struct vb2_v4l2_buffer vb2;
  121. struct list_head list;
  122. };
  123. /* defines for "debug" module parameter */
  124. #define CXUSB_DBG_RC BIT(0)
  125. #define CXUSB_DBG_I2C BIT(1)
  126. #define CXUSB_DBG_MISC BIT(2)
  127. #define CXUSB_DBG_BT656 BIT(3)
  128. #define CXUSB_DBG_URB BIT(4)
  129. #define CXUSB_DBG_OPS BIT(5)
  130. #define CXUSB_DBG_AUXB BIT(6)
  131. extern int dvb_usb_cxusb_debug;
  132. #define cxusb_vprintk(dvbdev, lvl, ...) do { \
  133. struct cxusb_medion_dev *_cxdev = (dvbdev)->priv; \
  134. if (dvb_usb_cxusb_debug & CXUSB_DBG_##lvl) \
  135. v4l2_printk(KERN_DEBUG, \
  136. &_cxdev->v4l2dev, __VA_ARGS__); \
  137. } while (0)
  138. int cxusb_ctrl_msg(struct dvb_usb_device *d,
  139. u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen);
  140. #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
  141. int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev);
  142. int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev);
  143. void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev);
  144. #else
  145. static inline int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev)
  146. {
  147. return -EINVAL;
  148. }
  149. static inline int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev)
  150. {
  151. return 0;
  152. }
  153. static inline void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev)
  154. {
  155. }
  156. #endif
  157. int cxusb_medion_get(struct dvb_usb_device *dvbdev,
  158. enum cxusb_open_type open_type);
  159. void cxusb_medion_put(struct dvb_usb_device *dvbdev);
  160. #endif