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