ispvideo.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * ispvideo.h
  3. *
  4. * TI OMAP3 ISP - Generic video node
  5. *
  6. * Copyright (C) 2009-2010 Nokia Corporation
  7. *
  8. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  9. * Sakari Ailus <sakari.ailus@iki.fi>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #ifndef OMAP3_ISP_VIDEO_H
  16. #define OMAP3_ISP_VIDEO_H
  17. #include <linux/v4l2-mediabus.h>
  18. #include <media/media-entity.h>
  19. #include <media/v4l2-dev.h>
  20. #include <media/v4l2-fh.h>
  21. #include <media/videobuf2-v4l2.h>
  22. #define ISP_VIDEO_DRIVER_NAME "ispvideo"
  23. #define ISP_VIDEO_DRIVER_VERSION "0.0.2"
  24. struct isp_device;
  25. struct isp_video;
  26. struct v4l2_mbus_framefmt;
  27. struct v4l2_pix_format;
  28. /*
  29. * struct isp_format_info - ISP media bus format information
  30. * @code: V4L2 media bus format code
  31. * @truncated: V4L2 media bus format code for the same format truncated to 10
  32. * bits. Identical to @code if the format is 10 bits wide or less.
  33. * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
  34. * format. Identical to @code if the format is not DPCM compressed.
  35. * @flavor: V4L2 media bus format code for the same pixel layout but
  36. * shifted to be 8 bits per pixel. =0 if format is not shiftable.
  37. * @pixelformat: V4L2 pixel format FCC identifier
  38. * @width: Bits per pixel (when transferred over a bus)
  39. * @bpp: Bytes per pixel (when stored in memory)
  40. */
  41. struct isp_format_info {
  42. u32 code;
  43. u32 truncated;
  44. u32 uncompressed;
  45. u32 flavor;
  46. u32 pixelformat;
  47. unsigned int width;
  48. unsigned int bpp;
  49. };
  50. enum isp_pipeline_stream_state {
  51. ISP_PIPELINE_STREAM_STOPPED = 0,
  52. ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  53. ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  54. };
  55. enum isp_pipeline_state {
  56. /* The stream has been started on the input video node. */
  57. ISP_PIPELINE_STREAM_INPUT = 1,
  58. /* The stream has been started on the output video node. */
  59. ISP_PIPELINE_STREAM_OUTPUT = 2,
  60. /* At least one buffer is queued on the input video node. */
  61. ISP_PIPELINE_QUEUE_INPUT = 4,
  62. /* At least one buffer is queued on the output video node. */
  63. ISP_PIPELINE_QUEUE_OUTPUT = 8,
  64. /* The input entity is idle, ready to be started. */
  65. ISP_PIPELINE_IDLE_INPUT = 16,
  66. /* The output entity is idle, ready to be started. */
  67. ISP_PIPELINE_IDLE_OUTPUT = 32,
  68. /* The pipeline is currently streaming. */
  69. ISP_PIPELINE_STREAM = 64,
  70. };
  71. /*
  72. * struct isp_pipeline - An ISP hardware pipeline
  73. * @field: The field being processed by the pipeline
  74. * @error: A hardware error occurred during capture
  75. * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
  76. */
  77. struct isp_pipeline {
  78. struct media_pipeline pipe;
  79. spinlock_t lock; /* Pipeline state and queue flags */
  80. unsigned int state;
  81. enum isp_pipeline_stream_state stream_state;
  82. struct isp_video *input;
  83. struct isp_video *output;
  84. u32 entities;
  85. unsigned long l3_ick;
  86. unsigned int max_rate;
  87. enum v4l2_field field;
  88. atomic_t frame_number;
  89. bool do_propagation; /* of frame number */
  90. bool error;
  91. struct v4l2_fract max_timeperframe;
  92. struct v4l2_subdev *external;
  93. unsigned int external_rate;
  94. unsigned int external_width;
  95. };
  96. #define to_isp_pipeline(__e) \
  97. container_of((__e)->pipe, struct isp_pipeline, pipe)
  98. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  99. {
  100. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  101. ISP_PIPELINE_STREAM_OUTPUT |
  102. ISP_PIPELINE_QUEUE_INPUT |
  103. ISP_PIPELINE_QUEUE_OUTPUT |
  104. ISP_PIPELINE_IDLE_INPUT |
  105. ISP_PIPELINE_IDLE_OUTPUT);
  106. }
  107. /**
  108. * struct isp_buffer - ISP video buffer
  109. * @vb: videobuf2 buffer
  110. * @irqlist: List head for insertion into IRQ queue
  111. * @dma: DMA address
  112. */
  113. struct isp_buffer {
  114. struct vb2_v4l2_buffer vb;
  115. struct list_head irqlist;
  116. dma_addr_t dma;
  117. };
  118. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, vb)
  119. enum isp_video_dmaqueue_flags {
  120. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  121. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  122. /* Set when queuing buffer to an empty DMA queue */
  123. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  124. };
  125. #define isp_video_dmaqueue_flags_clr(video) \
  126. ({ (video)->dmaqueue_flags = 0; })
  127. /*
  128. * struct isp_video_operations - ISP video operations
  129. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  130. * if there was no buffer previously queued.
  131. */
  132. struct isp_video_operations {
  133. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  134. };
  135. struct isp_video {
  136. struct video_device video;
  137. enum v4l2_buf_type type;
  138. struct media_pad pad;
  139. struct mutex mutex; /* format and crop settings */
  140. atomic_t active;
  141. struct isp_device *isp;
  142. unsigned int capture_mem;
  143. unsigned int bpl_alignment; /* alignment value */
  144. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  145. unsigned int bpl_max; /* maximum bytes per line value */
  146. unsigned int bpl_value; /* bytes per line value */
  147. unsigned int bpl_padding; /* padding at end of line */
  148. /* Pipeline state */
  149. struct isp_pipeline pipe;
  150. struct mutex stream_lock; /* pipeline and stream states */
  151. bool error;
  152. /* Video buffers queue */
  153. void *alloc_ctx;
  154. struct vb2_queue *queue;
  155. struct mutex queue_lock; /* protects the queue */
  156. spinlock_t irqlock; /* protects dmaqueue */
  157. struct list_head dmaqueue;
  158. enum isp_video_dmaqueue_flags dmaqueue_flags;
  159. const struct isp_video_operations *ops;
  160. };
  161. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  162. struct isp_video_fh {
  163. struct v4l2_fh vfh;
  164. struct isp_video *video;
  165. struct vb2_queue queue;
  166. struct v4l2_format format;
  167. struct v4l2_fract timeperframe;
  168. };
  169. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  170. #define isp_video_queue_to_isp_video_fh(q) \
  171. container_of(q, struct isp_video_fh, queue)
  172. int omap3isp_video_init(struct isp_video *video, const char *name);
  173. void omap3isp_video_cleanup(struct isp_video *video);
  174. int omap3isp_video_register(struct isp_video *video,
  175. struct v4l2_device *vdev);
  176. void omap3isp_video_unregister(struct isp_video *video);
  177. struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
  178. void omap3isp_video_cancel_stream(struct isp_video *video);
  179. void omap3isp_video_resume(struct isp_video *video, int continuous);
  180. struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
  181. const struct isp_format_info *
  182. omap3isp_video_format_info(u32 code);
  183. #endif /* OMAP3_ISP_VIDEO_H */