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 <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. * @flavor: V4L2 media bus format code for the same pixel layout but
  47. * shifted to be 8 bits per pixel. =0 if format is not shiftable.
  48. * @pixelformat: V4L2 pixel format FCC identifier
  49. * @bpp: Bits per pixel
  50. */
  51. struct isp_format_info {
  52. enum v4l2_mbus_pixelcode code;
  53. enum v4l2_mbus_pixelcode truncated;
  54. enum v4l2_mbus_pixelcode uncompressed;
  55. enum v4l2_mbus_pixelcode flavor;
  56. u32 pixelformat;
  57. unsigned int bpp;
  58. };
  59. enum isp_pipeline_stream_state {
  60. ISP_PIPELINE_STREAM_STOPPED = 0,
  61. ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  62. ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  63. };
  64. enum isp_pipeline_state {
  65. /* The stream has been started on the input video node. */
  66. ISP_PIPELINE_STREAM_INPUT = 1,
  67. /* The stream has been started on the output video node. */
  68. ISP_PIPELINE_STREAM_OUTPUT = 2,
  69. /* At least one buffer is queued on the input video node. */
  70. ISP_PIPELINE_QUEUE_INPUT = 4,
  71. /* At least one buffer is queued on the output video node. */
  72. ISP_PIPELINE_QUEUE_OUTPUT = 8,
  73. /* The input entity is idle, ready to be started. */
  74. ISP_PIPELINE_IDLE_INPUT = 16,
  75. /* The output entity is idle, ready to be started. */
  76. ISP_PIPELINE_IDLE_OUTPUT = 32,
  77. /* The pipeline is currently streaming. */
  78. ISP_PIPELINE_STREAM = 64,
  79. };
  80. struct isp_pipeline {
  81. struct media_pipeline pipe;
  82. spinlock_t lock; /* Pipeline state and queue flags */
  83. unsigned int state;
  84. enum isp_pipeline_stream_state stream_state;
  85. struct isp_video *input;
  86. struct isp_video *output;
  87. unsigned long l3_ick;
  88. unsigned int max_rate;
  89. atomic_t frame_number;
  90. bool do_propagation; /* of frame number */
  91. struct v4l2_fract max_timeperframe;
  92. };
  93. #define to_isp_pipeline(__e) \
  94. container_of((__e)->pipe, struct isp_pipeline, pipe)
  95. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  96. {
  97. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  98. ISP_PIPELINE_STREAM_OUTPUT |
  99. ISP_PIPELINE_QUEUE_INPUT |
  100. ISP_PIPELINE_QUEUE_OUTPUT |
  101. ISP_PIPELINE_IDLE_INPUT |
  102. ISP_PIPELINE_IDLE_OUTPUT);
  103. }
  104. /*
  105. * struct isp_buffer - ISP buffer
  106. * @buffer: ISP video buffer
  107. * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
  108. */
  109. struct isp_buffer {
  110. struct isp_video_buffer buffer;
  111. dma_addr_t isp_addr;
  112. };
  113. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
  114. enum isp_video_dmaqueue_flags {
  115. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  116. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  117. /* Set when queuing buffer to an empty DMA queue */
  118. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  119. };
  120. #define isp_video_dmaqueue_flags_clr(video) \
  121. ({ (video)->dmaqueue_flags = 0; })
  122. /*
  123. * struct isp_video_operations - ISP video operations
  124. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  125. * if there was no buffer previously queued.
  126. */
  127. struct isp_video_operations {
  128. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  129. };
  130. struct isp_video {
  131. struct video_device video;
  132. enum v4l2_buf_type type;
  133. struct media_pad pad;
  134. struct mutex mutex; /* format and crop settings */
  135. atomic_t active;
  136. struct isp_device *isp;
  137. unsigned int capture_mem;
  138. unsigned int bpl_alignment; /* alignment value */
  139. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  140. unsigned int bpl_max; /* maximum bytes per line value */
  141. unsigned int bpl_value; /* bytes per line value */
  142. unsigned int bpl_padding; /* padding at end of line */
  143. /* Entity video node streaming */
  144. unsigned int streaming:1;
  145. /* Pipeline state */
  146. struct isp_pipeline pipe;
  147. struct mutex stream_lock; /* pipeline and stream states */
  148. /* Video buffers queue */
  149. struct isp_video_queue *queue;
  150. struct list_head dmaqueue;
  151. enum isp_video_dmaqueue_flags dmaqueue_flags;
  152. const struct isp_video_operations *ops;
  153. };
  154. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  155. struct isp_video_fh {
  156. struct v4l2_fh vfh;
  157. struct isp_video *video;
  158. struct isp_video_queue queue;
  159. struct v4l2_format format;
  160. struct v4l2_fract timeperframe;
  161. };
  162. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  163. #define isp_video_queue_to_isp_video_fh(q) \
  164. container_of(q, struct isp_video_fh, queue)
  165. int omap3isp_video_init(struct isp_video *video, const char *name);
  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 */