usbtv.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2013 Lubomir Rintel
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions, and the following disclaimer,
  10. * without modification.
  11. * 2. The name of the author may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * Alternatively, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL").
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*
  30. * Fushicai USBTV007 Audio-Video Grabber Driver
  31. *
  32. * No physical hardware was harmed running Windows during the
  33. * reverse-engineering activity
  34. */
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/usb.h>
  38. #include <media/v4l2-device.h>
  39. #include <media/videobuf2-v4l2.h>
  40. #include <media/videobuf2-vmalloc.h>
  41. /* Hardware. */
  42. #define USBTV_VIDEO_ENDP 0x81
  43. #define USBTV_AUDIO_ENDP 0x83
  44. #define USBTV_BASE 0xc000
  45. #define USBTV_REQUEST_REG 12
  46. /* Number of concurrent isochronous urbs submitted.
  47. * Higher numbers was seen to overly saturate the USB bus. */
  48. #define USBTV_ISOC_TRANSFERS 16
  49. #define USBTV_ISOC_PACKETS 8
  50. #define USBTV_CHUNK_SIZE 256
  51. #define USBTV_CHUNK 240
  52. #define USBTV_AUDIO_URBSIZE 20480
  53. #define USBTV_AUDIO_HDRSIZE 4
  54. #define USBTV_AUDIO_BUFFER 65536
  55. /* Chunk header. */
  56. #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
  57. == 0x88000000)
  58. #define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
  59. #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
  60. #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
  61. #define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
  62. /* parameters for supported TV norms */
  63. struct usbtv_norm_params {
  64. v4l2_std_id norm;
  65. int cap_width, cap_height;
  66. };
  67. /* A single videobuf2 frame buffer. */
  68. struct usbtv_buf {
  69. struct vb2_v4l2_buffer vb;
  70. struct list_head list;
  71. };
  72. /* Per-device structure. */
  73. struct usbtv {
  74. struct device *dev;
  75. struct usb_device *udev;
  76. /* video */
  77. struct v4l2_device v4l2_dev;
  78. struct video_device vdev;
  79. struct vb2_queue vb2q;
  80. struct mutex v4l2_lock;
  81. struct mutex vb2q_lock;
  82. /* List of videobuf2 buffers protected by a lock. */
  83. spinlock_t buflock;
  84. struct list_head bufs;
  85. /* Number of currently processed frame, useful find
  86. * out when a new one begins. */
  87. u32 frame_id;
  88. int chunks_done;
  89. enum {
  90. USBTV_COMPOSITE_INPUT,
  91. USBTV_SVIDEO_INPUT,
  92. } input;
  93. v4l2_std_id norm;
  94. int width, height;
  95. int n_chunks;
  96. int iso_size;
  97. int last_odd;
  98. unsigned int sequence;
  99. struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
  100. /* audio */
  101. struct snd_card *snd;
  102. struct snd_pcm_substream *snd_substream;
  103. atomic_t snd_stream;
  104. struct work_struct snd_trigger;
  105. struct urb *snd_bulk_urb;
  106. size_t snd_buffer_pos;
  107. size_t snd_period_pos;
  108. };
  109. int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size);
  110. int usbtv_video_init(struct usbtv *usbtv);
  111. void usbtv_video_free(struct usbtv *usbtv);
  112. int usbtv_audio_init(struct usbtv *usbtv);
  113. void usbtv_audio_free(struct usbtv *usbtv);
  114. void usbtv_audio_suspend(struct usbtv *usbtv);
  115. void usbtv_audio_resume(struct usbtv *usbtv);