ispvideo.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  23. * 02110-1301 USA
  24. */
  25. #ifndef OMAP3_ISP_VIDEO_H
  26. #define OMAP3_ISP_VIDEO_H
  27. #include <linux/v4l2-mediabus.h>
  28. #include <media/media-entity.h>
  29. #include <media/v4l2-dev.h>
  30. #include <media/v4l2-fh.h>
  31. #include "ispqueue.h"
  32. #define ISP_VIDEO_DRIVER_NAME "ispvideo"
  33. #define ISP_VIDEO_DRIVER_VERSION "0.0.2"
  34. struct isp_device;
  35. struct isp_video;
  36. struct v4l2_mbus_framefmt;
  37. struct v4l2_pix_format;
  38. /*
  39. * struct isp_format_info - ISP media bus format information
  40. * @code: V4L2 media bus format code
  41. * @truncated: V4L2 media bus format code for the same format truncated to 10
  42. * bits. Identical to @code if the format is 10 bits wide or less.
  43. * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
  44. * format. Identical to @code if the format is not DPCM compressed.
  45. * @flavor: V4L2 media bus format code for the same pixel layout but
  46. * shifted to be 8 bits per pixel. =0 if format is not shiftable.
  47. * @pixelformat: V4L2 pixel format FCC identifier
  48. * @bpp: Bits per pixel
  49. */
  50. struct isp_format_info {
  51. enum v4l2_mbus_pixelcode code;
  52. enum v4l2_mbus_pixelcode truncated;
  53. enum v4l2_mbus_pixelcode uncompressed;
  54. enum v4l2_mbus_pixelcode flavor;
  55. u32 pixelformat;
  56. unsigned int bpp;
  57. };
  58. enum isp_pipeline_stream_state {
  59. ISP_PIPELINE_STREAM_STOPPED = 0,
  60. ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  61. ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  62. };
  63. enum isp_pipeline_state {
  64. /* The stream has been started on the input video node. */
  65. ISP_PIPELINE_STREAM_INPUT = 1,
  66. /* The stream has been started on the output video node. */
  67. ISP_PIPELINE_STREAM_OUTPUT = 2,
  68. /* At least one buffer is queued on the input video node. */
  69. ISP_PIPELINE_QUEUE_INPUT = 4,
  70. /* At least one buffer is queued on the output video node. */
  71. ISP_PIPELINE_QUEUE_OUTPUT = 8,
  72. /* The input entity is idle, ready to be started. */
  73. ISP_PIPELINE_IDLE_INPUT = 16,
  74. /* The output entity is idle, ready to be started. */
  75. ISP_PIPELINE_IDLE_OUTPUT = 32,
  76. /* The pipeline is currently streaming. */
  77. ISP_PIPELINE_STREAM = 64,
  78. };
  79. struct isp_pipeline {
  80. struct media_pipeline pipe;
  81. spinlock_t lock; /* Pipeline state and queue flags */
  82. unsigned int state;
  83. enum isp_pipeline_stream_state stream_state;
  84. struct isp_video *input;
  85. struct isp_video *output;
  86. unsigned long l3_ick;
  87. unsigned int max_rate;
  88. atomic_t frame_number;
  89. bool do_propagation; /* of frame number */
  90. struct v4l2_fract max_timeperframe;
  91. };
  92. #define to_isp_pipeline(__e) \
  93. container_of((__e)->pipe, struct isp_pipeline, pipe)
  94. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  95. {
  96. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  97. ISP_PIPELINE_STREAM_OUTPUT |
  98. ISP_PIPELINE_QUEUE_INPUT |
  99. ISP_PIPELINE_QUEUE_OUTPUT |
  100. ISP_PIPELINE_IDLE_INPUT |
  101. ISP_PIPELINE_IDLE_OUTPUT);
  102. }
  103. /*
  104. * struct isp_buffer - ISP buffer
  105. * @buffer: ISP video buffer
  106. * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
  107. */
  108. struct isp_buffer {
  109. struct isp_video_buffer buffer;
  110. dma_addr_t isp_addr;
  111. };
  112. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
  113. enum isp_video_dmaqueue_flags {
  114. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  115. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  116. /* Set when queuing buffer to an empty DMA queue */
  117. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  118. };
  119. #define isp_video_dmaqueue_flags_clr(video) \
  120. ({ (video)->dmaqueue_flags = 0; })
  121. /*
  122. * struct isp_video_operations - ISP video operations
  123. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  124. * if there was no buffer previously queued.
  125. */
  126. struct isp_video_operations {
  127. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  128. };
  129. struct isp_video {
  130. struct video_device video;
  131. enum v4l2_buf_type type;
  132. struct media_pad pad;
  133. struct mutex mutex; /* format and crop settings */
  134. atomic_t active;
  135. struct isp_device *isp;
  136. unsigned int capture_mem;
  137. unsigned int bpl_alignment; /* alignment value */
  138. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  139. unsigned int bpl_max; /* maximum bytes per line value */
  140. unsigned int bpl_value; /* bytes per line value */
  141. unsigned int bpl_padding; /* padding at end of line */
  142. /* Entity video node streaming */
  143. unsigned int streaming:1;
  144. /* Pipeline state */
  145. struct isp_pipeline pipe;
  146. struct mutex stream_lock; /* pipeline and stream states */
  147. /* Video buffers queue */
  148. struct isp_video_queue *queue;
  149. struct list_head dmaqueue;
  150. enum isp_video_dmaqueue_flags dmaqueue_flags;
  151. const struct isp_video_operations *ops;
  152. };
  153. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  154. struct isp_video_fh {
  155. struct v4l2_fh vfh;
  156. struct isp_video *video;
  157. struct isp_video_queue queue;
  158. struct v4l2_format format;
  159. struct v4l2_fract timeperframe;
  160. };
  161. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  162. #define isp_video_queue_to_isp_video_fh(q) \
  163. container_of(q, struct isp_video_fh, queue)
  164. int omap3isp_video_init(struct isp_video *video, const char *name);
  165. void omap3isp_video_cleanup(struct isp_video *video);
  166. int omap3isp_video_register(struct isp_video *video,
  167. struct v4l2_device *vdev);
  168. void omap3isp_video_unregister(struct isp_video *video);
  169. struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
  170. unsigned int error);
  171. void omap3isp_video_resume(struct isp_video *video, int continuous);
  172. struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
  173. const struct isp_format_info *
  174. omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
  175. #endif /* OMAP3_ISP_VIDEO_H */