ispvideo.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /*
  80. * struct isp_pipeline - An ISP hardware pipeline
  81. * @error: A hardware error occurred during capture
  82. */
  83. struct isp_pipeline {
  84. struct media_pipeline pipe;
  85. spinlock_t lock; /* Pipeline state and queue flags */
  86. unsigned int state;
  87. enum isp_pipeline_stream_state stream_state;
  88. struct isp_video *input;
  89. struct isp_video *output;
  90. unsigned long l3_ick;
  91. unsigned int max_rate;
  92. atomic_t frame_number;
  93. bool do_propagation; /* of frame number */
  94. bool error;
  95. struct v4l2_fract max_timeperframe;
  96. };
  97. #define to_isp_pipeline(__e) \
  98. container_of((__e)->pipe, struct isp_pipeline, pipe)
  99. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  100. {
  101. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  102. ISP_PIPELINE_STREAM_OUTPUT |
  103. ISP_PIPELINE_QUEUE_INPUT |
  104. ISP_PIPELINE_QUEUE_OUTPUT |
  105. ISP_PIPELINE_IDLE_INPUT |
  106. ISP_PIPELINE_IDLE_OUTPUT);
  107. }
  108. /*
  109. * struct isp_buffer - ISP buffer
  110. * @buffer: ISP video buffer
  111. * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
  112. */
  113. struct isp_buffer {
  114. struct isp_video_buffer buffer;
  115. dma_addr_t isp_addr;
  116. };
  117. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
  118. enum isp_video_dmaqueue_flags {
  119. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  120. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  121. /* Set when queuing buffer to an empty DMA queue */
  122. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  123. };
  124. #define isp_video_dmaqueue_flags_clr(video) \
  125. ({ (video)->dmaqueue_flags = 0; })
  126. /*
  127. * struct isp_video_operations - ISP video operations
  128. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  129. * if there was no buffer previously queued.
  130. */
  131. struct isp_video_operations {
  132. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  133. };
  134. struct isp_video {
  135. struct video_device video;
  136. enum v4l2_buf_type type;
  137. struct media_pad pad;
  138. struct mutex mutex; /* format and crop settings */
  139. atomic_t active;
  140. struct isp_device *isp;
  141. unsigned int capture_mem;
  142. unsigned int bpl_alignment; /* alignment value */
  143. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  144. unsigned int bpl_max; /* maximum bytes per line value */
  145. unsigned int bpl_value; /* bytes per line value */
  146. unsigned int bpl_padding; /* padding at end of line */
  147. /* Entity video node streaming */
  148. unsigned int streaming:1;
  149. /* Pipeline state */
  150. struct isp_pipeline pipe;
  151. struct mutex stream_lock; /* pipeline and stream states */
  152. /* Video buffers queue */
  153. struct isp_video_queue *queue;
  154. struct list_head dmaqueue;
  155. enum isp_video_dmaqueue_flags dmaqueue_flags;
  156. const struct isp_video_operations *ops;
  157. };
  158. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  159. struct isp_video_fh {
  160. struct v4l2_fh vfh;
  161. struct isp_video *video;
  162. struct isp_video_queue queue;
  163. struct v4l2_format format;
  164. struct v4l2_fract timeperframe;
  165. };
  166. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  167. #define isp_video_queue_to_isp_video_fh(q) \
  168. container_of(q, struct isp_video_fh, queue)
  169. int omap3isp_video_init(struct isp_video *video, const char *name);
  170. void omap3isp_video_cleanup(struct isp_video *video);
  171. int omap3isp_video_register(struct isp_video *video,
  172. struct v4l2_device *vdev);
  173. void omap3isp_video_unregister(struct isp_video *video);
  174. struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
  175. void omap3isp_video_resume(struct isp_video *video, int continuous);
  176. struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
  177. const struct isp_format_info *
  178. omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
  179. #endif /* OMAP3_ISP_VIDEO_H */