usbtv.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Fushicai USBTV007 Audio-Video Grabber Driver
  3. *
  4. * Copyright (c) 2013 Lubomir Rintel
  5. * All rights reserved.
  6. * No physical hardware was harmed running Windows during the
  7. * reverse-engineering activity
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions, and the following disclaimer,
  14. * without modification.
  15. * 2. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * Alternatively, this software may be distributed under the terms of the
  19. * GNU General Public License ("GPL").
  20. */
  21. #include <linux/module.h>
  22. #include <linux/slab.h>
  23. #include <linux/usb.h>
  24. #include <media/v4l2-device.h>
  25. #include <media/videobuf2-v4l2.h>
  26. #include <media/videobuf2-vmalloc.h>
  27. /* Hardware. */
  28. #define USBTV_VIDEO_ENDP 0x81
  29. #define USBTV_AUDIO_ENDP 0x83
  30. #define USBTV_BASE 0xc000
  31. #define USBTV_REQUEST_REG 12
  32. /* Number of concurrent isochronous urbs submitted.
  33. * Higher numbers was seen to overly saturate the USB bus. */
  34. #define USBTV_ISOC_TRANSFERS 16
  35. #define USBTV_ISOC_PACKETS 8
  36. #define USBTV_CHUNK_SIZE 256
  37. #define USBTV_CHUNK 240
  38. #define USBTV_AUDIO_URBSIZE 20480
  39. #define USBTV_AUDIO_HDRSIZE 4
  40. #define USBTV_AUDIO_BUFFER 65536
  41. /* Chunk header. */
  42. #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
  43. == 0x88000000)
  44. #define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
  45. #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
  46. #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
  47. #define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
  48. /* parameters for supported TV norms */
  49. struct usbtv_norm_params {
  50. v4l2_std_id norm;
  51. int cap_width, cap_height;
  52. };
  53. /* A single videobuf2 frame buffer. */
  54. struct usbtv_buf {
  55. struct vb2_v4l2_buffer vb;
  56. struct list_head list;
  57. };
  58. /* Per-device structure. */
  59. struct usbtv {
  60. struct device *dev;
  61. struct usb_device *udev;
  62. /* video */
  63. struct v4l2_device v4l2_dev;
  64. struct video_device vdev;
  65. struct vb2_queue vb2q;
  66. struct mutex v4l2_lock;
  67. struct mutex vb2q_lock;
  68. /* List of videobuf2 buffers protected by a lock. */
  69. spinlock_t buflock;
  70. struct list_head bufs;
  71. /* Number of currently processed frame, useful find
  72. * out when a new one begins. */
  73. u32 frame_id;
  74. int chunks_done;
  75. enum {
  76. USBTV_COMPOSITE_INPUT,
  77. USBTV_SVIDEO_INPUT,
  78. } input;
  79. v4l2_std_id norm;
  80. int width, height;
  81. int n_chunks;
  82. int iso_size;
  83. unsigned int sequence;
  84. struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
  85. /* audio */
  86. struct snd_card *snd;
  87. struct snd_pcm_substream *snd_substream;
  88. atomic_t snd_stream;
  89. struct work_struct snd_trigger;
  90. struct urb *snd_bulk_urb;
  91. size_t snd_buffer_pos;
  92. size_t snd_period_pos;
  93. };
  94. int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size);
  95. int usbtv_video_init(struct usbtv *usbtv);
  96. void usbtv_video_free(struct usbtv *usbtv);
  97. int usbtv_audio_init(struct usbtv *usbtv);
  98. void usbtv_audio_free(struct usbtv *usbtv);
  99. void usbtv_audio_suspend(struct usbtv *usbtv);
  100. void usbtv_audio_resume(struct usbtv *usbtv);