]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/platform/exynos4-is/fimc-isp.h
Merge remote-tracking branch 'v4l-dvb/master'
[karo-tx-linux.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-v4l2.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-mediabus.h>
27 #include <media/exynos-fimc.h>
28
29 extern int fimc_isp_debug;
30
31 #define isp_dbg(level, dev, fmt, arg...) \
32         v4l2_dbg(level, fimc_isp_debug, dev, fmt, ## arg)
33
34 /* FIXME: revisit these constraints */
35 #define FIMC_ISP_SINK_WIDTH_MIN         (16 + 8)
36 #define FIMC_ISP_SINK_HEIGHT_MIN        (12 + 8)
37 #define FIMC_ISP_SOURCE_WIDTH_MIN       8
38 #define FIMC_ISP_SOURCE_HEIGHT_MIN      8
39 #define FIMC_ISP_CAC_MARGIN_WIDTH       16
40 #define FIMC_ISP_CAC_MARGIN_HEIGHT      12
41
42 #define FIMC_ISP_SINK_WIDTH_MAX         (4000 - 16)
43 #define FIMC_ISP_SINK_HEIGHT_MAX        (4000 + 12)
44 #define FIMC_ISP_SOURCE_WIDTH_MAX       4000
45 #define FIMC_ISP_SOURCE_HEIGHT_MAX      4000
46
47 #define FIMC_ISP_NUM_FORMATS            3
48 #define FIMC_ISP_REQ_BUFS_MIN           2
49 #define FIMC_ISP_REQ_BUFS_MAX           32
50
51 #define FIMC_ISP_SD_PAD_SINK            0
52 #define FIMC_ISP_SD_PAD_SRC_FIFO        1
53 #define FIMC_ISP_SD_PAD_SRC_DMA         2
54 #define FIMC_ISP_SD_PADS_NUM            3
55 #define FIMC_ISP_MAX_PLANES             1
56
57 /**
58  * struct fimc_isp_frame - source/target frame properties
59  * @width: full image width
60  * @height: full image height
61  * @rect: crop/composition rectangle
62  */
63 struct fimc_isp_frame {
64         u16 width;
65         u16 height;
66         struct v4l2_rect rect;
67 };
68
69 struct fimc_isp_ctrls {
70         struct v4l2_ctrl_handler handler;
71
72         /* Auto white balance */
73         struct v4l2_ctrl *auto_wb;
74         /* Auto ISO control cluster */
75         struct {
76                 struct v4l2_ctrl *auto_iso;
77                 struct v4l2_ctrl *iso;
78         };
79         /* Adjust - contrast */
80         struct v4l2_ctrl *contrast;
81         /* Adjust - saturation */
82         struct v4l2_ctrl *saturation;
83         /* Adjust - sharpness */
84         struct v4l2_ctrl *sharpness;
85         /* Adjust - brightness */
86         struct v4l2_ctrl *brightness;
87         /* Adjust - hue */
88         struct v4l2_ctrl *hue;
89
90         /* Auto/manual exposure */
91         struct v4l2_ctrl *auto_exp;
92         /* Manual exposure value */
93         struct v4l2_ctrl *exposure;
94         /* AE/AWB lock/unlock */
95         struct v4l2_ctrl *aewb_lock;
96         /* Exposure metering mode */
97         struct v4l2_ctrl *exp_metering;
98         /* AFC */
99         struct v4l2_ctrl *afc;
100         /* ISP image effect */
101         struct v4l2_ctrl *colorfx;
102 };
103
104 struct isp_video_buf {
105         struct vb2_v4l2_buffer vb;
106         dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES];
107         unsigned int index;
108 };
109
110 #define to_isp_video_buf(_b) container_of(_b, struct isp_video_buf, vb)
111
112 #define FIMC_ISP_MAX_BUFS       4
113
114 /**
115  * struct fimc_is_video - fimc-is video device structure
116  * @vdev: video_device structure
117  * @type: video device type (CAPTURE/OUTPUT)
118  * @pad: video device media (sink) pad
119  * @pending_buf_q: pending buffers queue head
120  * @active_buf_q: a queue head of buffers scheduled in hardware
121  * @vb_queue: vb2 buffer queue
122  * @active_buf_count: number of video buffers scheduled in hardware
123  * @frame_count: counter of frames dequeued to user space
124  * @reqbufs_count: number of buffers requested with REQBUFS ioctl
125  * @format: current pixel format
126  */
127 struct fimc_is_video {
128         struct exynos_video_entity ve;
129         enum v4l2_buf_type      type;
130         struct media_pad        pad;
131         struct list_head        pending_buf_q;
132         struct list_head        active_buf_q;
133         struct vb2_queue        vb_queue;
134         unsigned int            reqbufs_count;
135         unsigned int            buf_count;
136         unsigned int            buf_mask;
137         unsigned int            frame_count;
138         int                     streaming;
139         struct isp_video_buf    *buffers[FIMC_ISP_MAX_BUFS];
140         const struct fimc_fmt   *format;
141         struct v4l2_pix_format_mplane pixfmt;
142 };
143
144 /* struct fimc_isp:state bit definitions */
145 #define ST_ISP_VID_CAP_BUF_PREP         0
146 #define ST_ISP_VID_CAP_STREAMING        1
147
148 /**
149  * struct fimc_isp - FIMC-IS ISP data structure
150  * @pdev: pointer to FIMC-IS platform device
151  * @alloc_ctx: videobuf2 memory allocator context
152  * @subdev: ISP v4l2_subdev
153  * @subdev_pads: the ISP subdev media pads
154  * @test_pattern: test pattern controls
155  * @ctrls: v4l2 controls structure
156  * @video_lock: mutex serializing video device and the subdev operations
157  * @cac_margin_x: horizontal CAC margin in pixels
158  * @cac_margin_y: vertical CAC margin in pixels
159  * @state: driver state flags
160  * @video_capture: the ISP block video capture device
161  */
162 struct fimc_isp {
163         struct platform_device          *pdev;
164         struct vb2_alloc_ctx            *alloc_ctx;
165         struct v4l2_subdev              subdev;
166         struct media_pad                subdev_pads[FIMC_ISP_SD_PADS_NUM];
167         struct v4l2_mbus_framefmt       src_fmt;
168         struct v4l2_mbus_framefmt       sink_fmt;
169         struct v4l2_ctrl                *test_pattern;
170         struct fimc_isp_ctrls           ctrls;
171
172         struct mutex                    video_lock;
173         struct mutex                    subdev_lock;
174
175         unsigned int                    cac_margin_x;
176         unsigned int                    cac_margin_y;
177
178         unsigned long                   state;
179
180         struct fimc_is_video            video_capture;
181 };
182
183 #define ctrl_to_fimc_isp(_ctrl) \
184         container_of(ctrl->handler, struct fimc_isp, ctrls.handler)
185
186 struct fimc_is;
187
188 int fimc_isp_subdev_create(struct fimc_isp *isp);
189 void fimc_isp_subdev_destroy(struct fimc_isp *isp);
190 void fimc_isp_irq_handler(struct fimc_is *is);
191 int fimc_is_create_controls(struct fimc_isp *isp);
192 int fimc_is_delete_controls(struct fimc_isp *isp);
193 const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
194                                         const u32 *mbus_code, int index);
195 #endif /* FIMC_ISP_H_ */