fimc-isp.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. *
  6. * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
  7. * Younghwan Joo <yhwan.joo@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #ifndef FIMC_ISP_H_
  14. #define FIMC_ISP_H_
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/sched.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/types.h>
  20. #include <linux/videodev2.h>
  21. #include <media/media-entity.h>
  22. #include <media/videobuf2-v4l2.h>
  23. #include <media/v4l2-device.h>
  24. #include <media/v4l2-mediabus.h>
  25. #include <media/exynos-fimc.h>
  26. extern int fimc_isp_debug;
  27. #define isp_dbg(level, dev, fmt, arg...) \
  28. v4l2_dbg(level, fimc_isp_debug, dev, fmt, ## arg)
  29. /* FIXME: revisit these constraints */
  30. #define FIMC_ISP_SINK_WIDTH_MIN (16 + 8)
  31. #define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8)
  32. #define FIMC_ISP_SOURCE_WIDTH_MIN 8
  33. #define FIMC_ISP_SOURCE_HEIGHT_MIN 8
  34. #define FIMC_ISP_CAC_MARGIN_WIDTH 16
  35. #define FIMC_ISP_CAC_MARGIN_HEIGHT 12
  36. #define FIMC_ISP_SINK_WIDTH_MAX (4000 - 16)
  37. #define FIMC_ISP_SINK_HEIGHT_MAX (4000 + 12)
  38. #define FIMC_ISP_SOURCE_WIDTH_MAX 4000
  39. #define FIMC_ISP_SOURCE_HEIGHT_MAX 4000
  40. #define FIMC_ISP_NUM_FORMATS 3
  41. #define FIMC_ISP_REQ_BUFS_MIN 2
  42. #define FIMC_ISP_REQ_BUFS_MAX 32
  43. #define FIMC_ISP_SD_PAD_SINK 0
  44. #define FIMC_ISP_SD_PAD_SRC_FIFO 1
  45. #define FIMC_ISP_SD_PAD_SRC_DMA 2
  46. #define FIMC_ISP_SD_PADS_NUM 3
  47. #define FIMC_ISP_MAX_PLANES 1
  48. /**
  49. * struct fimc_isp_frame - source/target frame properties
  50. * @width: full image width
  51. * @height: full image height
  52. * @rect: crop/composition rectangle
  53. */
  54. struct fimc_isp_frame {
  55. u16 width;
  56. u16 height;
  57. struct v4l2_rect rect;
  58. };
  59. struct fimc_isp_ctrls {
  60. struct v4l2_ctrl_handler handler;
  61. /* Auto white balance */
  62. struct v4l2_ctrl *auto_wb;
  63. /* Auto ISO control cluster */
  64. struct {
  65. struct v4l2_ctrl *auto_iso;
  66. struct v4l2_ctrl *iso;
  67. };
  68. /* Adjust - contrast */
  69. struct v4l2_ctrl *contrast;
  70. /* Adjust - saturation */
  71. struct v4l2_ctrl *saturation;
  72. /* Adjust - sharpness */
  73. struct v4l2_ctrl *sharpness;
  74. /* Adjust - brightness */
  75. struct v4l2_ctrl *brightness;
  76. /* Adjust - hue */
  77. struct v4l2_ctrl *hue;
  78. /* Auto/manual exposure */
  79. struct v4l2_ctrl *auto_exp;
  80. /* Manual exposure value */
  81. struct v4l2_ctrl *exposure;
  82. /* AE/AWB lock/unlock */
  83. struct v4l2_ctrl *aewb_lock;
  84. /* Exposure metering mode */
  85. struct v4l2_ctrl *exp_metering;
  86. /* AFC */
  87. struct v4l2_ctrl *afc;
  88. /* ISP image effect */
  89. struct v4l2_ctrl *colorfx;
  90. };
  91. struct isp_video_buf {
  92. struct vb2_v4l2_buffer vb;
  93. dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES];
  94. unsigned int index;
  95. };
  96. #define to_isp_video_buf(_b) container_of(_b, struct isp_video_buf, vb)
  97. #define FIMC_ISP_MAX_BUFS 4
  98. /**
  99. * struct fimc_is_video - fimc-is video device structure
  100. * @vdev: video_device structure
  101. * @type: video device type (CAPTURE/OUTPUT)
  102. * @pad: video device media (sink) pad
  103. * @pending_buf_q: pending buffers queue head
  104. * @active_buf_q: a queue head of buffers scheduled in hardware
  105. * @vb_queue: vb2 buffer queue
  106. * @active_buf_count: number of video buffers scheduled in hardware
  107. * @frame_count: counter of frames dequeued to user space
  108. * @reqbufs_count: number of buffers requested with REQBUFS ioctl
  109. * @format: current pixel format
  110. */
  111. struct fimc_is_video {
  112. struct exynos_video_entity ve;
  113. enum v4l2_buf_type type;
  114. struct media_pad pad;
  115. struct list_head pending_buf_q;
  116. struct list_head active_buf_q;
  117. struct vb2_queue vb_queue;
  118. unsigned int reqbufs_count;
  119. unsigned int buf_count;
  120. unsigned int buf_mask;
  121. unsigned int frame_count;
  122. int streaming;
  123. struct isp_video_buf *buffers[FIMC_ISP_MAX_BUFS];
  124. const struct fimc_fmt *format;
  125. struct v4l2_pix_format_mplane pixfmt;
  126. };
  127. /* struct fimc_isp:state bit definitions */
  128. #define ST_ISP_VID_CAP_BUF_PREP 0
  129. #define ST_ISP_VID_CAP_STREAMING 1
  130. /**
  131. * struct fimc_isp - FIMC-IS ISP data structure
  132. * @pdev: pointer to FIMC-IS platform device
  133. * @alloc_ctx: videobuf2 memory allocator context
  134. * @subdev: ISP v4l2_subdev
  135. * @subdev_pads: the ISP subdev media pads
  136. * @test_pattern: test pattern controls
  137. * @ctrls: v4l2 controls structure
  138. * @video_lock: mutex serializing video device and the subdev operations
  139. * @cac_margin_x: horizontal CAC margin in pixels
  140. * @cac_margin_y: vertical CAC margin in pixels
  141. * @state: driver state flags
  142. * @video_capture: the ISP block video capture device
  143. */
  144. struct fimc_isp {
  145. struct platform_device *pdev;
  146. struct vb2_alloc_ctx *alloc_ctx;
  147. struct v4l2_subdev subdev;
  148. struct media_pad subdev_pads[FIMC_ISP_SD_PADS_NUM];
  149. struct v4l2_mbus_framefmt src_fmt;
  150. struct v4l2_mbus_framefmt sink_fmt;
  151. struct v4l2_ctrl *test_pattern;
  152. struct fimc_isp_ctrls ctrls;
  153. struct mutex video_lock;
  154. struct mutex subdev_lock;
  155. unsigned int cac_margin_x;
  156. unsigned int cac_margin_y;
  157. unsigned long state;
  158. struct fimc_is_video video_capture;
  159. };
  160. #define ctrl_to_fimc_isp(_ctrl) \
  161. container_of(ctrl->handler, struct fimc_isp, ctrls.handler)
  162. struct fimc_is;
  163. int fimc_isp_subdev_create(struct fimc_isp *isp);
  164. void fimc_isp_subdev_destroy(struct fimc_isp *isp);
  165. void fimc_isp_irq_handler(struct fimc_is *is);
  166. int fimc_is_create_controls(struct fimc_isp *isp);
  167. int fimc_is_delete_controls(struct fimc_isp *isp);
  168. const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
  169. const u32 *mbus_code, int index);
  170. #endif /* FIMC_ISP_H_ */