ispvideo.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * @width: Bits per pixel (when transferred over a bus)
  49. * @bpp: Bytes per pixel (when stored in memory)
  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 width;
  58. unsigned int bpp;
  59. };
  60. enum isp_pipeline_stream_state {
  61. ISP_PIPELINE_STREAM_STOPPED = 0,
  62. ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  63. ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  64. };
  65. enum isp_pipeline_state {
  66. /* The stream has been started on the input video node. */
  67. ISP_PIPELINE_STREAM_INPUT = 1,
  68. /* The stream has been started on the output video node. */
  69. ISP_PIPELINE_STREAM_OUTPUT = 2,
  70. /* At least one buffer is queued on the input video node. */
  71. ISP_PIPELINE_QUEUE_INPUT = 4,
  72. /* At least one buffer is queued on the output video node. */
  73. ISP_PIPELINE_QUEUE_OUTPUT = 8,
  74. /* The input entity is idle, ready to be started. */
  75. ISP_PIPELINE_IDLE_INPUT = 16,
  76. /* The output entity is idle, ready to be started. */
  77. ISP_PIPELINE_IDLE_OUTPUT = 32,
  78. /* The pipeline is currently streaming. */
  79. ISP_PIPELINE_STREAM = 64,
  80. };
  81. /*
  82. * struct isp_pipeline - An ISP hardware pipeline
  83. * @error: A hardware error occurred during capture
  84. * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
  85. */
  86. struct isp_pipeline {
  87. struct media_pipeline pipe;
  88. spinlock_t lock; /* Pipeline state and queue flags */
  89. unsigned int state;
  90. enum isp_pipeline_stream_state stream_state;
  91. struct isp_video *input;
  92. struct isp_video *output;
  93. u32 entities;
  94. unsigned long l3_ick;
  95. unsigned int max_rate;
  96. atomic_t frame_number;
  97. bool do_propagation; /* of frame number */
  98. bool error;
  99. struct v4l2_fract max_timeperframe;
  100. struct v4l2_subdev *external;
  101. unsigned int external_rate;
  102. unsigned int external_width;
  103. };
  104. #define to_isp_pipeline(__e) \
  105. container_of((__e)->pipe, struct isp_pipeline, pipe)
  106. static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  107. {
  108. return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
  109. ISP_PIPELINE_STREAM_OUTPUT |
  110. ISP_PIPELINE_QUEUE_INPUT |
  111. ISP_PIPELINE_QUEUE_OUTPUT |
  112. ISP_PIPELINE_IDLE_INPUT |
  113. ISP_PIPELINE_IDLE_OUTPUT);
  114. }
  115. /*
  116. * struct isp_buffer - ISP buffer
  117. * @buffer: ISP video buffer
  118. * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
  119. */
  120. struct isp_buffer {
  121. struct isp_video_buffer buffer;
  122. dma_addr_t isp_addr;
  123. };
  124. #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
  125. enum isp_video_dmaqueue_flags {
  126. /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
  127. ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
  128. /* Set when queuing buffer to an empty DMA queue */
  129. ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
  130. };
  131. #define isp_video_dmaqueue_flags_clr(video) \
  132. ({ (video)->dmaqueue_flags = 0; })
  133. /*
  134. * struct isp_video_operations - ISP video operations
  135. * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
  136. * if there was no buffer previously queued.
  137. */
  138. struct isp_video_operations {
  139. int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
  140. };
  141. struct isp_video {
  142. struct video_device video;
  143. enum v4l2_buf_type type;
  144. struct media_pad pad;
  145. struct mutex mutex; /* format and crop settings */
  146. atomic_t active;
  147. struct isp_device *isp;
  148. unsigned int capture_mem;
  149. unsigned int bpl_alignment; /* alignment value */
  150. unsigned int bpl_zero_padding; /* whether the alignment is optional */
  151. unsigned int bpl_max; /* maximum bytes per line value */
  152. unsigned int bpl_value; /* bytes per line value */
  153. unsigned int bpl_padding; /* padding at end of line */
  154. /* Entity video node streaming */
  155. unsigned int streaming:1;
  156. /* Pipeline state */
  157. struct isp_pipeline pipe;
  158. struct mutex stream_lock; /* pipeline and stream states */
  159. /* Video buffers queue */
  160. struct isp_video_queue *queue;
  161. struct list_head dmaqueue;
  162. enum isp_video_dmaqueue_flags dmaqueue_flags;
  163. const struct isp_video_operations *ops;
  164. };
  165. #define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
  166. struct isp_video_fh {
  167. struct v4l2_fh vfh;
  168. struct isp_video *video;
  169. struct isp_video_queue queue;
  170. struct v4l2_format format;
  171. struct v4l2_fract timeperframe;
  172. };
  173. #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
  174. #define isp_video_queue_to_isp_video_fh(q) \
  175. container_of(q, struct isp_video_fh, queue)
  176. int omap3isp_video_init(struct isp_video *video, const char *name);
  177. void omap3isp_video_cleanup(struct isp_video *video);
  178. int omap3isp_video_register(struct isp_video *video,
  179. struct v4l2_device *vdev);
  180. void omap3isp_video_unregister(struct isp_video *video);
  181. struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
  182. void omap3isp_video_resume(struct isp_video *video, int continuous);
  183. struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
  184. const struct isp_format_info *
  185. omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
  186. #endif /* OMAP3_ISP_VIDEO_H */