fimc-isp.h 5.2 KB

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