Merge tag 'for-linus' of git://github.com/realmz/blackfin-linux
[firefly-linux-kernel-4.4.55.git] / drivers / media / platform / exynos4-is / fimc-isp.h
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
16 #include <linux/io.h>
17 #include <linux/platform_device.h>
18 #include <linux/sched.h>
19 #include <linux/spinlock.h>
20 #include <linux/types.h>
21 #include <linux/videodev2.h>
22
23 #include <media/media-entity.h>
24 #include <media/videobuf2-core.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-mediabus.h>
27 #include <media/s5p_fimc.h>
28
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_SOURC_HEIGHT_MIN       8
34 #define FIMC_ISP_CAC_MARGIN_WIDTH       16
35 #define FIMC_ISP_CAC_MARGIN_HEIGHT      12
36
37 #define FIMC_ISP_SINK_WIDTH_MAX         (4000 - 16)
38 #define FIMC_ISP_SINK_HEIGHT_MAX        (4000 + 12)
39 #define FIMC_ISP_SOURCE_WIDTH_MAX       4000
40 #define FIMC_ISP_SOURC_HEIGHT_MAX       4000
41
42 #define FIMC_ISP_NUM_FORMATS            3
43 #define FIMC_ISP_REQ_BUFS_MIN           2
44
45 #define FIMC_ISP_SD_PAD_SINK            0
46 #define FIMC_ISP_SD_PAD_SRC_FIFO        1
47 #define FIMC_ISP_SD_PAD_SRC_DMA         2
48 #define FIMC_ISP_SD_PADS_NUM            3
49 #define FIMC_ISP_MAX_PLANES             1
50
51 /**
52  * struct fimc_isp_frame - source/target frame properties
53  * @width: full image width
54  * @height: full image height
55  * @rect: crop/composition rectangle
56  */
57 struct fimc_isp_frame {
58         u16 width;
59         u16 height;
60         struct v4l2_rect rect;
61 };
62
63 struct fimc_isp_ctrls {
64         struct v4l2_ctrl_handler handler;
65
66         /* Auto white balance */
67         struct v4l2_ctrl *auto_wb;
68         /* Auto ISO control cluster */
69         struct {
70                 struct v4l2_ctrl *auto_iso;
71                 struct v4l2_ctrl *iso;
72         };
73         /* Adjust - contrast */
74         struct v4l2_ctrl *contrast;
75         /* Adjust - saturation */
76         struct v4l2_ctrl *saturation;
77         /* Adjust - sharpness */
78         struct v4l2_ctrl *sharpness;
79         /* Adjust - brightness */
80         struct v4l2_ctrl *brightness;
81         /* Adjust - hue */
82         struct v4l2_ctrl *hue;
83
84         /* Auto/manual exposure */
85         struct v4l2_ctrl *auto_exp;
86         /* Manual exposure value */
87         struct v4l2_ctrl *exposure;
88         /* AE/AWB lock/unlock */
89         struct v4l2_ctrl *aewb_lock;
90         /* Exposure metering mode */
91         struct v4l2_ctrl *exp_metering;
92         /* AFC */
93         struct v4l2_ctrl *afc;
94         /* ISP image effect */
95         struct v4l2_ctrl *colorfx;
96 };
97
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 video_device     vdev;
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            frame_count;
119         unsigned int            reqbufs_count;
120         int                     streaming;
121         unsigned long           payload[FIMC_ISP_MAX_PLANES];
122         const struct fimc_fmt   *format;
123 };
124
125 /**
126  * struct fimc_isp - FIMC-IS ISP data structure
127  * @pdev: pointer to FIMC-IS platform device
128  * @alloc_ctx: videobuf2 memory allocator context
129  * @subdev: ISP v4l2_subdev
130  * @subdev_pads: the ISP subdev media pads
131  * @ctrl_handler: v4l2 controls handler
132  * @test_pattern: test pattern controls
133  * @pipeline: video capture pipeline data structure
134  * @video_lock: mutex serializing video device and the subdev operations
135  * @fmt: pointer to color format description structure
136  * @payload: image size in bytes (w x h x bpp)
137  * @inp_frame: camera input frame structure
138  * @out_frame: DMA output frame structure
139  * @source_subdev_grp_id: group id of remote source subdev
140  * @cac_margin_x: horizontal CAC margin in pixels
141  * @cac_margin_y: vertical CAC margin in pixels
142  * @state: driver state flags
143  * @video_capture: the ISP block video capture device
144  */
145 struct fimc_isp {
146         struct platform_device          *pdev;
147         struct vb2_alloc_ctx            *alloc_ctx;
148         struct v4l2_subdev              subdev;
149         struct media_pad                subdev_pads[FIMC_ISP_SD_PADS_NUM];
150         struct v4l2_mbus_framefmt       subdev_fmt;
151         struct v4l2_ctrl                *test_pattern;
152         struct fimc_isp_ctrls           ctrls;
153
154         struct mutex                    video_lock;
155         struct mutex                    subdev_lock;
156
157         struct fimc_isp_frame           inp_frame;
158         struct fimc_isp_frame           out_frame;
159         unsigned int                    source_subdev_grp_id;
160
161         unsigned int                    cac_margin_x;
162         unsigned int                    cac_margin_y;
163
164         unsigned long                   state;
165
166         struct fimc_is_video            video_capture;
167 };
168
169 #define ctrl_to_fimc_isp(_ctrl) \
170         container_of(ctrl->handler, struct fimc_isp, ctrls.handler)
171
172 struct fimc_is;
173
174 int fimc_isp_subdev_create(struct fimc_isp *isp);
175 void fimc_isp_subdev_destroy(struct fimc_isp *isp);
176 void fimc_isp_irq_handler(struct fimc_is *is);
177 int fimc_is_create_controls(struct fimc_isp *isp);
178 int fimc_is_delete_controls(struct fimc_isp *isp);
179 const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
180                                         const u32 *mbus_code, int index);
181 #endif /* FIMC_ISP_H_ */