Merge branches 'acpi-tables', 'acpi-osl', 'acpi-misc' and 'acpi-tools'
[sfrench/cifs-2.6.git] / drivers / media / platform / exynos4-is / fimc-isp.h
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
13 #include <linux/io.h>
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>
19
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>
25
26 extern int fimc_isp_debug;
27
28 #define isp_dbg(level, dev, fmt, arg...) \
29         v4l2_dbg(level, fimc_isp_debug, dev, fmt, ## arg)
30
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
38
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
43
44 #define FIMC_ISP_NUM_FORMATS            3
45 #define FIMC_ISP_REQ_BUFS_MIN           2
46 #define FIMC_ISP_REQ_BUFS_MAX           32
47
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
53
54 /**
55  * struct fimc_isp_frame - source/target frame properties
56  * @width: full image width
57  * @height: full image height
58  * @rect: crop/composition rectangle
59  */
60 struct fimc_isp_frame {
61         u16 width;
62         u16 height;
63         struct v4l2_rect rect;
64 };
65
66 struct fimc_isp_ctrls {
67         struct v4l2_ctrl_handler handler;
68
69         /* Auto white balance */
70         struct v4l2_ctrl *auto_wb;
71         /* Auto ISO control cluster */
72         struct {
73                 struct v4l2_ctrl *auto_iso;
74                 struct v4l2_ctrl *iso;
75         };
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;
84         /* Adjust - hue */
85         struct v4l2_ctrl *hue;
86
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;
95         /* AFC */
96         struct v4l2_ctrl *afc;
97         /* ISP image effect */
98         struct v4l2_ctrl *colorfx;
99 };
100
101 struct isp_video_buf {
102         struct vb2_v4l2_buffer vb;
103         dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES];
104         unsigned int index;
105 };
106
107 #define to_isp_video_buf(_b) container_of(_b, struct isp_video_buf, vb)
108
109 #define FIMC_ISP_MAX_BUFS       4
110
111 /**
112  * struct fimc_is_video - fimc-is video device structure
113  * @vdev: video_device structure
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  * @active_buf_count: number of video buffers scheduled in hardware
120  * @frame_count: counter of frames dequeued to user space
121  * @reqbufs_count: number of buffers requested with REQBUFS ioctl
122  * @format: current pixel format
123  */
124 struct fimc_is_video {
125         struct exynos_video_entity ve;
126         enum v4l2_buf_type      type;
127         struct media_pad        pad;
128         struct list_head        pending_buf_q;
129         struct list_head        active_buf_q;
130         struct vb2_queue        vb_queue;
131         unsigned int            reqbufs_count;
132         unsigned int            buf_count;
133         unsigned int            buf_mask;
134         unsigned int            frame_count;
135         int                     streaming;
136         struct isp_video_buf    *buffers[FIMC_ISP_MAX_BUFS];
137         const struct fimc_fmt   *format;
138         struct v4l2_pix_format_mplane pixfmt;
139 };
140
141 /* struct fimc_isp:state bit definitions */
142 #define ST_ISP_VID_CAP_BUF_PREP         0
143 #define ST_ISP_VID_CAP_STREAMING        1
144
145 /**
146  * struct fimc_isp - FIMC-IS ISP data structure
147  * @pdev: pointer to FIMC-IS platform device
148  * @subdev: ISP v4l2_subdev
149  * @subdev_pads: the ISP subdev media pads
150  * @test_pattern: test pattern controls
151  * @ctrls: v4l2 controls structure
152  * @video_lock: mutex serializing video device and the subdev operations
153  * @cac_margin_x: horizontal CAC margin in pixels
154  * @cac_margin_y: vertical CAC margin in pixels
155  * @state: driver state flags
156  * @video_capture: the ISP block video capture device
157  */
158 struct fimc_isp {
159         struct platform_device          *pdev;
160         struct v4l2_subdev              subdev;
161         struct media_pad                subdev_pads[FIMC_ISP_SD_PADS_NUM];
162         struct v4l2_mbus_framefmt       src_fmt;
163         struct v4l2_mbus_framefmt       sink_fmt;
164         struct v4l2_ctrl                *test_pattern;
165         struct fimc_isp_ctrls           ctrls;
166
167         struct mutex                    video_lock;
168         struct mutex                    subdev_lock;
169
170         unsigned int                    cac_margin_x;
171         unsigned int                    cac_margin_y;
172
173         unsigned long                   state;
174
175         struct fimc_is_video            video_capture;
176 };
177
178 #define ctrl_to_fimc_isp(_ctrl) \
179         container_of(ctrl->handler, struct fimc_isp, ctrls.handler)
180
181 struct fimc_is;
182
183 int fimc_isp_subdev_create(struct fimc_isp *isp);
184 void fimc_isp_subdev_destroy(struct fimc_isp *isp);
185 void fimc_isp_irq_handler(struct fimc_is *is);
186 int fimc_is_create_controls(struct fimc_isp *isp);
187 int fimc_is_delete_controls(struct fimc_isp *isp);
188 const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
189                                         const u32 *mbus_code, int index);
190 #endif /* FIMC_ISP_H_ */