2 * aptina_camera_module.h
4 * Generic galaxycore sensor driver
6 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
8 * Copyright (C) 2012-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2008 Texas Instruments.
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.
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>
24 * TODO: references to v4l2 should be reomved from here and go into a
25 * platform dependent wrapper
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
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
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
53 struct aptina_camera_module;
55 struct aptina_camera_module_timings {
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;
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;
74 struct aptina_camera_module_config {
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;
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;
86 u32 frame_length_lines;
87 struct aptina_camera_module_timings timings;
89 bool ignore_measurement_check;
90 struct pltfrm_cam_itf itf_cfg;
93 struct aptina_camera_module_exp_config {
99 enum v4l2_flash_led_mode flash_mode;
102 struct aptina_camera_module_wb_config {
108 struct aptina_camera_module_af_config {
113 struct aptina_camera_module_ext_ctrl {
120 struct aptina_camera_module_ext_ctrls {
123 struct aptina_camera_module_ext_ctrl *ctrls;
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.
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.
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.
141 * s_ctrl: (mandatory) will be called at the successful end of
142 * aptina_camera_module_s_ctrl with the ctrl_id as argument.
144 * priv: (optional) for private data used by the custom driver.
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);
161 u32 power_up_delays_ms[3];
163 struct aptina_camera_module_timings timings;
166 struct aptina_camera_module {
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;
180 bool auto_adjust_fps;
183 bool frm_intrvl_valid;
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)
200 int aptina_camera_module_write_reglist(
201 struct aptina_camera_module *cam_mod,
202 const struct aptina_camera_module_reg reglist[],
205 int aptina_camera_module_write_reg(
206 struct aptina_camera_module *cam_mod,
210 int aptina_camera_module_read_reg(
211 struct aptina_camera_module *cam_mod,
216 int aptina_camera_module_read_reg_table(
217 struct aptina_camera_module *cam_mod,
221 int aptina_camera_module_try_fmt(
222 struct v4l2_subdev *sd,
223 struct v4l2_mbus_framefmt *fmt);
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);
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);
235 int aptina_camera_module_s_frame_interval(
236 struct v4l2_subdev *sd,
237 struct v4l2_subdev_frame_interval *interval);
239 int aptina_camera_module_s_stream(
240 struct v4l2_subdev *sd,
243 int aptina_camera_module_s_power(
244 struct v4l2_subdev *sd,
247 int aptina_camera_module_g_ctrl(
248 struct v4l2_subdev *sd,
249 struct v4l2_control *ctrl);
251 int aptina_camera_module_s_ctrl(
252 struct v4l2_subdev *sd,
253 struct v4l2_control *ctrl);
255 int aptina_camera_module_s_ext_ctrls(
256 struct v4l2_subdev *sd,
257 struct v4l2_ext_controls *ctrls);
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);
264 int aptina_camera_module_init(
265 struct aptina_camera_module *cam_mod,
266 struct aptina_camera_module_custom_config *custom);
268 void aptina_camera_module_release(
269 struct aptina_camera_module *cam_mod);
271 long aptina_camera_module_ioctl(struct v4l2_subdev *sd,
275 int aptina_camera_module_get_flip_mirror(
276 struct aptina_camera_module *cam_mod);