1 /* 2 * media/sunxi_camera_v2.h -- Ctrl IDs definitions for sunxi-vin 3 * 4 * Copyright (C) 2014 Allwinnertech Co., Ltd. 5 * Copyright (C) 2015 Yang Feng 6 * 7 * Author: Yang Feng <yangfeng@allwinnertech.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 as published by 11 * the Free Software Foundation; version 2 of the License. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 */ 19 #ifndef _SUNXI_CAMERA_H_ 20 #define _SUNXI_CAMERA_H_ 21 22 #include <linux/types.h> 23 #include <linux/videodev2.h> 24 25 /* Flags for 'capability' and 'capturemode' fields */ 26 #define V4L2_MODE_HIGHQUALITY 0x0001 27 #define V4L2_MODE_VIDEO 0x0002 28 #define V4L2_MODE_IMAGE 0x0003 29 #define V4L2_MODE_PREVIEW 0x0004 30 31 /* for yuv420 FBC mode*/ 32 #define V4L2_PIX_FMT_FBC v4l2_fourcc('F', 'C', '2', '1') 33 #define V4L2_PIX_FMT_LBC_2_0X v4l2_fourcc('L', 'C', '2', '1') 34 #define V4L2_PIX_FMT_LBC_2_5X v4l2_fourcc('L', 'C', '2', '2') 35 #define V4L2_PIX_FMT_LBC_1_0X v4l2_fourcc('L', 'C', '2', '3') 36 37 /* 38 * USER CIDS 39 */ 40 struct v4l2_win_coordinate { 41 __s32 x1; 42 __s32 y1; 43 __s32 x2; 44 __s32 y2; 45 }; 46 47 /* 48 *enum v4l2_flash_led_mode { 49 * V4L2_FLASH_LED_MODE_NONE, 50 * V4L2_FLASH_LED_MODE_FLASH, 51 * V4L2_FLASH_LED_MODE_TORCH, 52 *}; 53 */ 54 #define V4L2_FLASH_LED_MODE_AUTO (V4L2_FLASH_LED_MODE_TORCH + 1) 55 #define V4L2_FLASH_LED_MODE_RED_EYE (V4L2_FLASH_LED_MODE_TORCH + 2) 56 57 struct v4l2_win_setting { 58 struct v4l2_win_coordinate coor; 59 }; 60 61 enum v4l2_gain_shift { 62 V4L2_GAIN_SHIFT = 0, 63 V4L2_SHARP_LEVEL_SHIFT = 8, 64 V4L2_SHARP_MIN_SHIFT = 20, 65 V4L2_NDF_SHIFT = 26, 66 }; 67 68 #define MAX_EXP_FRAMES 5 69 70 /* 71 * The base for the sunxi-vfe controls. 72 * Total of 64 controls is reserved for this driver, add by yangfeng 73 */ 74 #define V4L2_CID_USER_SUNXI_CAMERA_BASE (V4L2_CID_USER_BASE + 0x1050) 75 76 #define V4L2_CID_AUTO_FOCUS_INIT (V4L2_CID_USER_SUNXI_CAMERA_BASE + 2) 77 #define V4L2_CID_AUTO_FOCUS_RELEASE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 3) 78 #define V4L2_CID_GSENSOR_ROTATION (V4L2_CID_USER_SUNXI_CAMERA_BASE + 4) 79 #define V4L2_CID_FRAME_RATE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 5) 80 81 enum v4l2_take_picture { 82 V4L2_TAKE_PICTURE_STOP = 0, 83 V4L2_TAKE_PICTURE_NORM = 1, 84 V4L2_TAKE_PICTURE_FAST = 2, 85 V4L2_TAKE_PICTURE_FLASH = 3, 86 V4L2_TAKE_PICTURE_HDR = 4, 87 }; 88 struct isp_hdr_setting_t { 89 __s32 hdr_en; 90 __s32 hdr_mode; 91 __s32 frames_count; 92 __s32 total_frames; 93 __s32 values[MAX_EXP_FRAMES]; 94 }; 95 struct csi_sync_ctrl { 96 __s32 type; 97 __s32 prs_sync_en; 98 __s32 prs_sync_scr_sel; 99 __s32 prs_sync_bench_sel; 100 __s32 prs_sync_input_vsync_en; 101 __s32 prs_sync_singal_via_by; 102 __s32 prs_sync_singal_scr_sel; 103 __s32 prs_sync_pulse_cfg; 104 __s32 prs_sync_dist; 105 __s32 prs_sync_wait_n; 106 __s32 prs_sync_wait_m; 107 __s32 dma_clr_dist; 108 109 __s32 prs_xvs_out_en; 110 __s32 prs_xhs_out_en; 111 __s32 prs_xvs_t; 112 __s32 prs_xhs_t; 113 __s32 prs_xvs_len; 114 __s32 prs_xhs_len; 115 }; 116 117 #define HDR_CTRL_GET 0 118 #define HDR_CTRL_SET 1 119 struct isp_hdr_ctrl { 120 __s32 flag; 121 __s32 count; 122 struct isp_hdr_setting_t hdr_t; 123 }; 124 125 #define V4L2_CID_TAKE_PICTURE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 6) 126 127 typedef union { 128 unsigned int dwval; 129 struct { 130 unsigned int af_sharp:16; 131 unsigned int hdr_cnt:4; 132 unsigned int flash_ok:1; 133 unsigned int capture_ok:1; 134 unsigned int fast_capture_ok:1; 135 unsigned int res0:9; 136 } bits; 137 } IMAGE_FLAG_t; 138 139 #define V4L2_CID_HOR_VISUAL_ANGLE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 7) 140 #define V4L2_CID_VER_VISUAL_ANGLE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 8) 141 #define V4L2_CID_FOCUS_LENGTH (V4L2_CID_USER_SUNXI_CAMERA_BASE + 9) 142 #define V4L2_CID_R_GAIN (V4L2_CID_USER_SUNXI_CAMERA_BASE + 10) 143 #define V4L2_CID_GR_GAIN (V4L2_CID_USER_SUNXI_CAMERA_BASE + 11) 144 #define V4L2_CID_GB_GAIN (V4L2_CID_USER_SUNXI_CAMERA_BASE + 12) 145 #define V4L2_CID_B_GAIN (V4L2_CID_USER_SUNXI_CAMERA_BASE + 13) 146 147 enum v4l2_sensor_type { 148 V4L2_SENSOR_TYPE_YUV = 0, 149 V4L2_SENSOR_TYPE_RAW = 1, 150 }; 151 152 #define V4L2_CID_SENSOR_TYPE (V4L2_CID_USER_SUNXI_CAMERA_BASE + 14) 153 154 #define V4L2_CID_AE_WIN_X1 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 15) 155 #define V4L2_CID_AE_WIN_Y1 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 16) 156 #define V4L2_CID_AE_WIN_X2 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 17) 157 #define V4L2_CID_AE_WIN_Y2 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 18) 158 159 #define V4L2_CID_AF_WIN_X1 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 19) 160 #define V4L2_CID_AF_WIN_Y1 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 20) 161 #define V4L2_CID_AF_WIN_X2 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 21) 162 #define V4L2_CID_AF_WIN_Y2 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 22) 163 164 static const char *const flash_led_mode_v1[] = { 165 "Off", 166 "Auto", 167 "Red Eye", 168 NULL, 169 }; 170 171 enum v4l2_flash_led_mode_v1{ 172 V4L2_FLASH_MODE_NONE = 0, 173 V4L2_FLASH_MODE_AUTO, 174 V4L2_FLASH_MODE_RED_EYE, 175 }; 176 177 #define V4L2_CID_FLASH_LED_MODE_V1 (V4L2_CID_USER_SUNXI_CAMERA_BASE + 23) 178 /* 179 * PRIVATE IOCTRLS 180 */ 181 182 struct isp_stat_buf { 183 void __user *buf; 184 __u32 buf_size; 185 }; 186 struct isp_exif_attribute { 187 struct v4l2_fract exposure_time; 188 struct v4l2_fract shutter_speed; 189 __u32 fnumber; 190 __u32 focal_length; 191 __s32 exposure_bias; 192 __u32 iso_speed; 193 __u32 flash_fire; 194 __u32 brightness; 195 __s32 reserved[16]; 196 }; 197 198 struct vin_top_clk { 199 __u32 clk_rate; 200 }; 201 202 struct vin_fps_ds { 203 __u32 fps_ds; 204 }; 205 206 struct isp_debug_mode { 207 __u32 debug_en; 208 __u32 debug_sel; 209 }; 210 211 struct vin_pattern_config { 212 __u32 ptn_en; 213 void __user *ptn_addr; 214 void __user *drc_tab; 215 void __user *gamma_tab; 216 void __user *isp_reg; 217 __u32 ptn_size; 218 __u32 ptn_w; 219 __u32 ptn_h; 220 __u32 ptn_fmt; 221 __u32 ptn_type; 222 }; 223 224 struct vin_reset_time { 225 __u32 reset_time; 226 }; 227 228 struct parser_fps_ds { 229 __u32 ch0_fps_ds; 230 __u32 ch1_fps_ds; 231 __u32 ch2_fps_ds; 232 __u32 ch3_fps_ds; 233 }; 234 235 struct sensor_isp_cfg { 236 __u8 isp_wdr_mode; 237 __u8 large_image; 238 }; 239 240 #define VIDIOC_ISP_AE_STAT_REQ \ 241 _IOWR('V', BASE_VIDIOC_PRIVATE + 1, struct isp_stat_buf) 242 #define VIDIOC_ISP_HIST_STAT_REQ \ 243 _IOWR('V', BASE_VIDIOC_PRIVATE + 2, struct isp_stat_buf) 244 #define VIDIOC_ISP_AF_STAT_REQ \ 245 _IOWR('V', BASE_VIDIOC_PRIVATE + 3, struct isp_stat_buf) 246 #define VIDIOC_ISP_EXIF_REQ \ 247 _IOWR('V', BASE_VIDIOC_PRIVATE + 4, struct isp_exif_attribute) 248 #define VIDIOC_ISP_GAMMA_REQ \ 249 _IOWR('V', BASE_VIDIOC_PRIVATE + 5, struct isp_stat_buf) 250 #define VIDIOC_SET_TOP_CLK \ 251 _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct vin_top_clk) 252 #define VIDIOC_SET_FPS_DS \ 253 _IOWR('V', BASE_VIDIOC_PRIVATE + 7, struct vin_fps_ds) 254 #define VIDIOC_HDR_CTRL \ 255 _IOWR('V', BASE_VIDIOC_PRIVATE + 8, struct isp_hdr_ctrl) 256 #define VIDIOC_SYNC_CTRL \ 257 _IOWR('V', BASE_VIDIOC_PRIVATE + 9, struct csi_sync_ctrl) 258 #define VIDIOC_ISP_DEBUG \ 259 _IOWR('V', BASE_VIDIOC_PRIVATE + 10, struct isp_debug_mode) 260 #define VIDIOC_VIN_PTN_CFG \ 261 _IOWR('V', BASE_VIDIOC_PRIVATE + 11, struct vin_pattern_config) 262 #define VIDIOC_VIN_RESET_TIME \ 263 _IOWR('V', BASE_VIDIOC_PRIVATE + 12, struct vin_reset_time) 264 #define VIDIOC_SET_PARSER_FPS \ 265 _IOWR('V', BASE_VIDIOC_PRIVATE + 13, struct parser_fps_ds) 266 #define VIDIOC_SET_SENSOR_ISP_CFG \ 267 _IOWR('V', BASE_VIDIOC_PRIVATE + 14, struct sensor_isp_cfg) 268 269 /* 270 * Events 271 * 272 * V4L2_EVENT_VIN_H3A: Histogram and AWB AE AF statistics data ready 273 * V4L2_EVENT_VIN_ISP_OFF: ISP stream off 274 */ 275 276 #define V4L2_EVENT_VIN_CLASS (V4L2_EVENT_PRIVATE_START | 0x100) 277 #define V4L2_EVENT_VIN_H3A (V4L2_EVENT_VIN_CLASS | 0x1) 278 #define V4L2_EVENT_VIN_HDR (V4L2_EVENT_VIN_CLASS | 0x2) 279 #define V4L2_EVENT_VIN_ISP_OFF (V4L2_EVENT_VIN_CLASS | 0x3) 280 281 struct vin_isp_h3a_config { 282 __u32 buf_size; 283 __u32 config_counter; 284 }; 285 286 /** 287 * struct vin_isp_stat_data - Statistic data sent to or received from user 288 * @ts: Timestamp of returned framestats. 289 * @buf: Pointer to pass to user. 290 * @frame_number: Frame number of requested stats. 291 * @cur_frame: Current frame number being processed. 292 * @config_counter: Number of the configuration associated with the data. 293 */ 294 struct vin_isp_stat_data { 295 void __user *buf; 296 __u32 buf_size; 297 __u32 frame_number; 298 __u32 config_counter; 299 }; 300 301 struct vin_isp_stat_event_status { 302 __u32 frame_number; 303 __u16 config_counter; 304 __u8 buf_err; 305 }; 306 307 struct vin_isp_hdr_event_data { 308 __u32 cmd; 309 struct isp_hdr_ctrl hdr; 310 }; 311 312 struct vin_vsync_event_data { 313 __u64 frame_number; 314 }; 315 316 /* 317 * Statistics IOCTLs 318 * 319 * VIDIOC_VIN_ISP_H3A_CFG: Set AE configuration 320 * VIDIOC_VIN_ISP_STAT_REQ: Read statistics (AE/AWB/AF/histogram) data 321 * VIDIOC_VIN_ISP_STAT_EN: Enable/disable a statistics module 322 */ 323 324 #define VIDIOC_VIN_ISP_H3A_CFG \ 325 _IOWR('V', BASE_VIDIOC_PRIVATE + 31, struct vin_isp_h3a_config) 326 #define VIDIOC_VIN_ISP_STAT_REQ \ 327 _IOWR('V', BASE_VIDIOC_PRIVATE + 32, struct vin_isp_stat_data) 328 #define VIDIOC_VIN_ISP_STAT_EN \ 329 _IOWR('V', BASE_VIDIOC_PRIVATE + 33, unsigned int) 330 331 struct sensor_config { 332 int width; 333 int height; 334 unsigned int hoffset; /*receive hoffset from sensor output*/ 335 unsigned int voffset; /*receive voffset from sensor output*/ 336 unsigned int hts; /*h size of timing, unit: pclk */ 337 unsigned int vts; /*v size of timing, unit: line */ 338 unsigned int pclk; /*pixel clock in Hz */ 339 unsigned int fps_fixed; /*sensor fps */ 340 unsigned int bin_factor;/*binning factor */ 341 unsigned int intg_min; /*integration min, unit: line, Q4 */ 342 unsigned int intg_max; /*integration max, unit: line, Q4 */ 343 unsigned int gain_min; /*sensor gain min, Q4 */ 344 unsigned int gain_max; /*sensor gain max, Q4 */ 345 unsigned int mbus_code; /*media bus code */ 346 unsigned int wdr_mode; /*isp wdr mode */ 347 }; 348 349 struct sensor_exp_gain { 350 int exp_val; 351 int gain_val; 352 int r_gain; 353 int b_gain; 354 }; 355 356 struct sensor_fps { 357 int fps; 358 }; 359 struct sensor_temp { 360 int temp; 361 }; 362 363 struct isp_table_reg_map { 364 void __user *addr; 365 unsigned int size; 366 }; 367 368 struct actuator_ctrl { 369 unsigned int code; 370 }; 371 372 struct actuator_para { 373 unsigned short code_min; 374 unsigned short code_max; 375 }; 376 377 struct flash_para { 378 enum v4l2_flash_led_mode mode; 379 }; 380 381 /* 382 * Camera Sensor IOCTLs 383 */ 384 385 #define VIDIOC_VIN_SENSOR_CFG_REQ \ 386 _IOWR('V', BASE_VIDIOC_PRIVATE + 60, struct sensor_config) 387 388 #define VIDIOC_VIN_SENSOR_EXP_GAIN \ 389 _IOWR('V', BASE_VIDIOC_PRIVATE + 61, struct sensor_exp_gain) 390 #define VIDIOC_VIN_SENSOR_SET_FPS \ 391 _IOWR('V', BASE_VIDIOC_PRIVATE + 62, struct sensor_fps) 392 #define VIDIOC_VIN_SENSOR_GET_TEMP \ 393 _IOWR('V', BASE_VIDIOC_PRIVATE + 63, struct sensor_temp) 394 395 #define VIDIOC_VIN_ACT_SET_CODE \ 396 _IOWR('V', BASE_VIDIOC_PRIVATE + 64, struct actuator_ctrl) 397 #define VIDIOC_VIN_ACT_INIT \ 398 _IOWR('V', BASE_VIDIOC_PRIVATE + 65, struct actuator_para) 399 #define VIDIOC_VIN_FLASH_EN \ 400 _IOWR('V', BASE_VIDIOC_PRIVATE + 66, struct flash_para) 401 402 #define VIDIOC_VIN_ISP_LOAD_REG \ 403 _IOWR('V', BASE_VIDIOC_PRIVATE + 70, struct isp_table_reg_map) 404 405 #define VIDIOC_VIN_ISP_TABLE1_MAP \ 406 _IOWR('V', BASE_VIDIOC_PRIVATE + 71, struct isp_table_reg_map) 407 408 #define VIDIOC_VIN_ISP_TABLE2_MAP \ 409 _IOWR('V', BASE_VIDIOC_PRIVATE + 72, struct isp_table_reg_map) 410 411 #define VIDIOC_VIN_GET_SENSOR_CODE \ 412 _IOWR('V', BASE_VIDIOC_PRIVATE + 73, int) 413 414 #endif /*_SUNXI_CAMERA_H_*/ 415 416