camera: rockchip: porting ov8858&ov4689&ov2710 driver
[firefly-linux-kernel-4.4.55.git] / drivers / media / i2c / soc_camera / rockchip / aptina_camera_module.h
1 /*
2  * aptina_camera_module.h
3  *
4  * Generic galaxycore sensor driver
5  *
6  * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
7  *
8  * Copyright (C) 2012-2014 Intel Mobile Communications GmbH
9  *
10  * Copyright (C) 2008 Texas Instruments.
11  *
12  * This file is licensed under the terms of the GNU General Public License
13  * version 2. This program is licensed "as is" without any warranty of any
14  * kind, whether express or implied.
15  *
16  */
17
18 #ifndef APTINA_CAMERA_MODULE_H
19 #define APTINA_CAMERA_MODULE_H
20 #include <linux/workqueue.h>
21 #include <linux/platform_data/rk_isp10_platform_camera_module.h>
22 #include <linux/platform_data/rk_isp10_platform.h>
23 /*
24  * TODO: references to v4l2 should be reomved from here and go into a
25  * platform dependent wrapper
26  */
27
28 #define APTINA_CAMERA_MODULE_REG_TYPE_DATA \
29                                 PLTFRM_CAMERA_MODULE_REG_TYPE_DATA
30 #define APTINA_CAMERA_MODULE_REG_TYPE_TIMEOUT \
31                                 PLTFRM_CAMERA_MODULE_REG_TYPE_TIMEOUT
32 #define aptina_camera_module_csi_config
33 #define aptina_camera_module_reg pltfrm_camera_module_reg
34 #define APTINA_FLIP_BIT_MASK 0x2
35 #define APTINA_MIRROR_BIT_MASK 0x1
36
37 #define APTINA_CAMERA_MODULE_CTRL_UPDT_GAIN 0x01
38 #define APTINA_CAMERA_MODULE_CTRL_UPDT_EXP_TIME 0x02
39 #define APTINA_CAMERA_MODULE_CTRL_UPDT_WB_TEMPERATURE 0x04
40 #define APTINA_CAMERA_MODULE_CTRL_UPDT_AUTO_WB 0x08
41 #define APTINA_CAMERA_MODULE_CTRL_UPDT_AUTO_GAIN 0x10
42 #define APTINA_CAMERA_MODULE_CTRL_UPDT_AUTO_EXP 0x20
43 #define APTINA_CAMERA_MODULE_CTRL_UPDT_FOCUS_ABSOLUTE 0x40
44 #define APTINA_CAMERA_MODULE_CTRL_UPDT_PRESET_WB 0x80
45
46 enum aptina_camera_module_state {
47         APTINA_CAMERA_MODULE_POWER_OFF = 0,
48         APTINA_CAMERA_MODULE_HW_STANDBY = 1,
49         APTINA_CAMERA_MODULE_SW_STANDBY = 2,
50         APTINA_CAMERA_MODULE_STREAMING = 3
51 };
52
53 struct aptina_camera_module;
54
55 struct aptina_camera_module_timings {
56         /* public */
57         u32 coarse_integration_time_min;
58         u32 coarse_integration_time_max_margin;
59         u32 fine_integration_time_min;
60         u32 fine_integration_time_max_margin;
61         u32 frame_length_lines;
62         u32 line_length_pck;
63         u32 vt_pix_clk_freq_hz;
64         u32 sensor_output_width;
65         u32 sensor_output_height;
66         u32 crop_horizontal_start; /* Sensor crop start cord. (x0,y0) */
67         u32 crop_vertical_start;
68         u32 crop_horizontal_end; /* Sensor crop end cord. (x1,y1) */
69         u32 crop_vertical_end;
70         u8 binning_factor_x;
71         u8 binning_factor_y;
72 };
73
74 struct aptina_camera_module_config {
75         const char *name;
76         struct v4l2_mbus_framefmt frm_fmt;
77         struct v4l2_subdev_frame_interval frm_intrvl;
78         bool auto_exp_enabled;
79         bool auto_gain_enabled;
80         bool auto_wb_enabled;
81         struct aptina_camera_module_reg *reg_table;
82         u32 reg_table_num_entries;
83         u32 bayer_order_alter_enble;
84         u32 v_blanking_time_us;
85         u32 line_length_pck;
86         u32 frame_length_lines;
87         struct aptina_camera_module_timings timings;
88         bool soft_reset;
89         bool ignore_measurement_check;
90         struct pltfrm_cam_itf itf_cfg;
91 };
92
93 struct aptina_camera_module_exp_config {
94         u32 exp_time;
95         bool auto_exp;
96         u16 gain;
97         u16 gain_percent;
98         bool auto_gain;
99         enum v4l2_flash_led_mode flash_mode;
100 };
101
102 struct aptina_camera_module_wb_config {
103         u32 temperature;
104         u32 preset_id;
105         bool auto_wb;
106 };
107
108 struct aptina_camera_module_af_config {
109         u32 abs_pos;
110         u32 rel_pos;
111 };
112
113 struct aptina_camera_module_ext_ctrl {
114         /* public */
115         u32 id;
116         u32 value;
117         __u32 reserved2[1];
118 };
119
120 struct aptina_camera_module_ext_ctrls {
121         /* public */
122         u32 count;
123         struct aptina_camera_module_ext_ctrl *ctrls;
124 };
125
126 /*
127  * start_streaming: (mandatory) will be called when sensor should be
128  * put into streaming mode right after the base config has been
129  * written to the sensor. After a successful call of this function
130  * the sensor should start delivering frame data.
131  *
132  * stop_streaming: (mandatory) will be called when sensor should stop
133  * delivering data. After a successful call of this function the
134  * sensor should not deliver any more frame data.
135  *
136  * check_camera_id: (optional) will be called when the sensor is
137  * powered on. If provided should check the sensor ID/version
138  * required by the custom driver. Register access should be
139  * possible when this function is invoked.
140  *
141  * s_ctrl: (mandatory) will be called at the successful end of
142  * aptina_camera_module_s_ctrl with the ctrl_id as argument.
143  *
144  * priv: (optional) for private data used by the custom driver.
145  */
146 struct aptina_camera_module_custom_config {
147         int (*start_streaming)(struct aptina_camera_module *cam_mod);
148         int (*stop_streaming)(struct aptina_camera_module *cam_mod);
149         int (*check_camera_id)(struct aptina_camera_module *cam_mod);
150         int (*s_ctrl)(struct aptina_camera_module *cam_mod, u32 ctrl_id);
151         int (*g_ctrl)(struct aptina_camera_module *cam_mod, u32 ctrl_id);
152         int (*g_timings)(struct aptina_camera_module *cam_mod,
153                 struct aptina_camera_module_timings *timings);
154         int (*s_ext_ctrls)(struct aptina_camera_module *cam_mod,
155                 struct aptina_camera_module_ext_ctrls *ctrls);
156         int (*set_flip)(struct aptina_camera_module *cam_mod);
157         struct aptina_camera_module_config *configs;
158         int (*init_common)(struct aptina_camera_module *cam_mod);
159         int (*g_exposure_valid_frame)(struct aptina_camera_module *cam_mod);
160         u32 num_configs;
161         u32 power_up_delays_ms[3];
162         void *priv;
163         struct aptina_camera_module_timings timings;
164 };
165
166 struct aptina_camera_module {
167         /* public */
168         struct v4l2_subdev sd;
169         struct v4l2_mbus_framefmt frm_fmt;
170         struct v4l2_subdev_frame_interval frm_intrvl;
171         struct aptina_camera_module_exp_config exp_config;
172         struct aptina_camera_module_wb_config wb_config;
173         struct aptina_camera_module_af_config af_config;
174         struct aptina_camera_module_custom_config custom;
175         enum aptina_camera_module_state state;
176         enum aptina_camera_module_state state_before_suspend;
177         struct aptina_camera_module_config *active_config;
178         u32 ctrl_updt;
179         u32 vts_min;
180         bool auto_adjust_fps;
181         bool update_config;
182         bool frm_fmt_valid;
183         bool frm_intrvl_valid;
184         bool hflip;
185         bool vflip;
186         u32 rotation;
187         void *pltfm_data;
188         bool inited;
189 };
190
191 #define aptina_camera_module_pr_info(cam_mod, fmt, arg...) \
192         pltfrm_camera_module_pr_info(&cam_mod->sd, fmt, ## arg)
193 #define aptina_camera_module_pr_debug(cam_mod, fmt, arg...) \
194                 pltfrm_camera_module_pr_debug(&cam_mod->sd, fmt, ## arg)
195 #define aptina_camera_module_pr_warn(cam_mod, fmt, arg...) \
196                 pltfrm_camera_module_pr_warn(&cam_mod->sd, fmt, ## arg)
197 #define aptina_camera_module_pr_err(cam_mod, fmt, arg...) \
198                 pltfrm_camera_module_pr_err(&cam_mod->sd, fmt, ## arg)
199
200 int aptina_camera_module_write_reglist(
201         struct aptina_camera_module *cam_mod,
202         const struct aptina_camera_module_reg reglist[],
203         int len);
204
205 int aptina_camera_module_write_reg(
206         struct aptina_camera_module *cam_mod,
207         u16 reg,
208         u16 val);
209
210 int aptina_camera_module_read_reg(
211         struct aptina_camera_module *cam_mod,
212         u16 data_length,
213         u16 reg,
214         u32 *val);
215
216 int aptina_camera_module_read_reg_table(
217         struct aptina_camera_module *cam_mod,
218         u16 reg,
219         u32 *val);
220
221 int aptina_camera_module_try_fmt(
222         struct v4l2_subdev *sd,
223         struct v4l2_mbus_framefmt *fmt);
224
225 int aptina_camera_module_s_fmt(
226         struct v4l2_subdev *sd,
227         struct v4l2_subdev_pad_config *cfg,
228         struct v4l2_subdev_format *format);
229
230 int aptina_camera_module_g_fmt(
231         struct v4l2_subdev *sd,
232         struct v4l2_subdev_pad_config *cfg,
233         struct v4l2_subdev_format *format);
234
235 int aptina_camera_module_s_frame_interval(
236         struct v4l2_subdev *sd,
237         struct v4l2_subdev_frame_interval *interval);
238
239 int aptina_camera_module_s_stream(
240         struct v4l2_subdev *sd,
241         int enable);
242
243 int aptina_camera_module_s_power(
244         struct v4l2_subdev *sd,
245         int on);
246
247 int aptina_camera_module_g_ctrl(
248         struct v4l2_subdev *sd,
249         struct v4l2_control *ctrl);
250
251 int aptina_camera_module_s_ctrl(
252         struct v4l2_subdev *sd,
253         struct v4l2_control *ctrl);
254
255 int aptina_camera_module_s_ext_ctrls(
256         struct v4l2_subdev *sd,
257         struct v4l2_ext_controls *ctrls);
258
259 int aptina_camera_module_enum_frameintervals(
260         struct v4l2_subdev *sd,
261         struct v4l2_subdev_pad_config *cfg,
262         struct v4l2_subdev_frame_interval_enum *file);
263
264 int aptina_camera_module_init(
265         struct aptina_camera_module *cam_mod,
266         struct aptina_camera_module_custom_config *custom);
267
268 void aptina_camera_module_release(
269         struct aptina_camera_module *cam_mod);
270
271 long aptina_camera_module_ioctl(struct v4l2_subdev *sd,
272         unsigned int cmd,
273         void *arg);
274
275 int aptina_camera_module_get_flip_mirror(
276         struct aptina_camera_module *cam_mod);
277 #endif
278