ispvideo.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 <linux/version.h>
  29. #include <media/media-entity.h>
  30. #include <media/v4l2-dev.h>
  31. #include <media/v4l2-fh.h>
  32. #include "ispqueue.h"
  33. #define ISP_VIDEO_DRIVER_NAME "ispvideo"
  34. #define ISP_VIDEO_DRIVER_VERSION KERNEL_VERSION(0, 0, 1)
  35. struct isp_device;
  36. struct isp_video;
  37. struct v4l2_mbus_framefmt;
  38. struct v4l2_pix_format;
  39. /*
  40. * struct isp_format_info - ISP media bus format information
  41. * @code: V4L2 media bus format code
  42. * @truncated: V4L2 media bus format code for the same format truncated to 10
  43. * bits. Identical to @code if the format is 10 bits wide or less.
  44. * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
  45. * format. Identical to @code if the format is not DPCM compressed.
  46. * @pixelformat: V4L2 pixel format FCC identifier
  47. * @bpp: Bits per pixel
  48. */
  49. struct isp_format_info {
  50. enum v4l2_mbus_pixelcode code;
  51. enum v4l2_mbus_pixelcode truncated;
  52. enum v4l2_mbus_pixelcode uncompressed;
  53. u32 pixelformat;
  54. unsigned int bpp;
  55. };
  56. enum isp_pipeline_stream_state {
  57. ISP_PIPELINE_STREAM_STOPPED = 0,
  58. ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  59. ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  60. };
  61. enum isp_pipeline_state {
  62. /* The stream has been started on the input video node. */
  63. ISP_PIPELINE_STREAM_INPUT = 1,
  64. /* The stream has been started on the output video node. */
  65. ISP_PIPELINE_STREAM_OUTPUT = 2,
  66. /* At least one buffer is queued on the input video node. */
  67. ISP_PIPELINE_QUEUE_INPUT = 4,
  68. /* At least one buffer is queued on the output video node. */
  69. ISP_PIPELINE_QUEUE_OUTPUT = 8,
  70. /* The input entity is idle, ready to be started. */
  71. ISP_PIPELINE_IDLE_INPUT = 16,
  72. /* The output entity is idle, ready to be started. */
  73. ISP_PIPELINE_IDLE_OUTPUT = 32,
  74. /* The pipeline is currently streaming. */
  75. ISP_PIPELINE_STREAM = 64,
  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. unsigned long l3_ick;
  85. unsigned int max_rate;
  86. atomic_t frame_number;
  87. bool do_propagation; /* of frame number */
  88. struct v4l2_fract max_timeperframe;
  89. };
  90. #define to_isp_pipeline(__e) \
  91. container_of((__e)->pipe, struct isp_pipeline, pipe)
  92. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  93. {
  94. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  95. ISP_PIPELINE_STREAM_OUTPUT |
  96. ISP_PIPELINE_QUEUE_INPUT |
  97. ISP_PIPELINE_QUEUE_OUTPUT |
  98. ISP_PIPELINE_IDLE_INPUT |
  99. ISP_PIPELINE_IDLE_OUTPUT);
  100. }
  101. /*
  102. * struct isp_buffer - ISP buffer
  103. * @buffer: ISP video buffer
  104. * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
  105. */
  106. struct isp_buffer {
  107. struct isp_video_buffer buffer;
  108. dma_addr_t isp_addr;
  109. };
  110. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
  111. enum isp_video_dmaqueue_flags {
  112. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  113. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  114. /* Set when queuing buffer to an empty DMA queue */
  115. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  116. };
  117. #define isp_video_dmaqueue_flags_clr(video) \
  118. ({ (video)->dmaqueue_flags = 0; })
  119. /*
  120. * struct isp_video_operations - ISP video operations
  121. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  122. * if there was no buffer previously queued.
  123. */
  124. struct isp_video_operations {
  125. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  126. };
  127. struct isp_video {
  128. struct video_device video;
  129. enum v4l2_buf_type type;
  130. struct media_pad pad;
  131. struct mutex mutex; /* format and crop settings */
  132. atomic_t active;
  133. struct isp_device *isp;
  134. unsigned int capture_mem;
  135. unsigned int bpl_alignment; /* alignment value */
  136. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  137. unsigned int bpl_max; /* maximum bytes per line value */
  138. unsigned int bpl_value; /* bytes per line value */
  139. unsigned int bpl_padding; /* padding at end of line */
  140. /* Entity video node streaming */
  141. unsigned int streaming:1;
  142. /* Pipeline state */
  143. struct isp_pipeline pipe;
  144. struct mutex stream_lock; /* pipeline and stream states */
  145. /* Video buffers queue */
  146. struct isp_video_queue *queue;
  147. struct list_head dmaqueue;
  148. enum isp_video_dmaqueue_flags dmaqueue_flags;
  149. const struct isp_video_operations *ops;
  150. };
  151. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  152. struct isp_video_fh {
  153. struct v4l2_fh vfh;
  154. struct isp_video *video;
  155. struct isp_video_queue queue;
  156. struct v4l2_format format;
  157. struct v4l2_fract timeperframe;
  158. };
  159. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  160. #define isp_video_queue_to_isp_video_fh(q) \
  161. container_of(q, struct isp_video_fh, queue)
  162. int omap3isp_video_init(struct isp_video *video, const char *name);
  163. int omap3isp_video_register(struct isp_video *video,
  164. struct v4l2_device *vdev);
  165. void omap3isp_video_unregister(struct isp_video *video);
  166. struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
  167. unsigned int error);
  168. void omap3isp_video_resume(struct isp_video *video, int continuous);
  169. struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
  170. const struct isp_format_info *
  171. omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
  172. #endif /* OMAP3_ISP_VIDEO_H */