1 #ifndef __MSMB_ISP__ 2 #define __MSMB_ISP__ 3 4 #include <linux/videodev2.h> 5 6 #define MAX_PLANES_PER_STREAM 3 7 #define MAX_NUM_STREAM 7 8 9 #define ISP_VERSION_40 40 10 #define ISP_VERSION_32 32 11 #define ISP_NATIVE_BUF_BIT (0x10000 << 0) 12 #define ISP0_BIT (0x10000 << 1) 13 #define ISP1_BIT (0x10000 << 2) 14 #define ISP_META_CHANNEL_BIT (0x10000 << 3) 15 #define ISP_SCRATCH_BUF_BIT (0x10000 << 4) 16 #define ISP_STATS_STREAM_BIT 0x80000000 17 18 #define ISP_REG_CFG_NUM_CFG_MAX (10) 19 #define ISP_REG_CFG_CMD_LEN_MAX (3 * 1024) 20 21 enum ISP_START_PIXEL_PATTERN { 22 ISP_BAYER_RGRGRG, 23 ISP_BAYER_GRGRGR, 24 ISP_BAYER_BGBGBG, 25 ISP_BAYER_GBGBGB, 26 ISP_YUV_YCbYCr, 27 ISP_YUV_YCrYCb, 28 ISP_YUV_CbYCrY, 29 ISP_YUV_CrYCbY, 30 ISP_PIX_PATTERN_MAX 31 }; 32 33 enum msm_vfe_plane_fmt { 34 Y_PLANE, 35 CB_PLANE, 36 CR_PLANE, 37 CRCB_PLANE, 38 CBCR_PLANE, 39 VFE_PLANE_FMT_MAX 40 }; 41 42 enum msm_vfe_input_src { 43 VFE_PIX_0, 44 VFE_RAW_0, 45 VFE_RAW_1, 46 VFE_RAW_2, 47 VFE_SRC_MAX, 48 }; 49 50 enum msm_vfe_axi_stream_src { 51 PIX_ENCODER, 52 PIX_VIEWFINDER, 53 CAMIF_RAW, 54 IDEAL_RAW, 55 RDI_INTF_0, 56 RDI_INTF_1, 57 RDI_INTF_2, 58 VFE_AXI_SRC_MAX 59 }; 60 61 enum msm_vfe_frame_skip_pattern { 62 NO_SKIP, 63 EVERY_2FRAME, 64 EVERY_3FRAME, 65 EVERY_4FRAME, 66 EVERY_5FRAME, 67 EVERY_6FRAME, 68 EVERY_7FRAME, 69 EVERY_8FRAME, 70 EVERY_16FRAME, 71 EVERY_32FRAME, 72 SKIP_ALL, 73 MAX_SKIP, 74 }; 75 76 enum msm_vfe_camif_input { 77 CAMIF_DISABLED, 78 CAMIF_PAD_REG_INPUT, 79 CAMIF_MIDDI_INPUT, 80 CAMIF_MIPI_INPUT, 81 }; 82 83 struct msm_vfe_camif_cfg { 84 uint32_t lines_per_frame; 85 uint32_t pixels_per_line; 86 uint32_t first_pixel; 87 uint32_t last_pixel; 88 uint32_t first_line; 89 uint32_t last_line; 90 uint32_t epoch_line0; 91 uint32_t epoch_line1; 92 enum msm_vfe_camif_input camif_input; 93 }; 94 95 enum msm_vfe_inputmux { 96 CAMIF, 97 TESTGEN, 98 EXTERNAL_READ, 99 }; 100 101 struct msm_vfe_pix_cfg { 102 struct msm_vfe_camif_cfg camif_cfg; 103 enum msm_vfe_inputmux input_mux; 104 enum ISP_START_PIXEL_PATTERN pixel_pattern; 105 }; 106 107 struct msm_vfe_rdi_cfg { 108 uint8_t cid; 109 uint8_t frame_based; 110 }; 111 112 struct msm_vfe_input_cfg { 113 union { 114 struct msm_vfe_pix_cfg pix_cfg; 115 struct msm_vfe_rdi_cfg rdi_cfg; 116 } d; 117 enum msm_vfe_input_src input_src; 118 uint32_t input_pix_clk; 119 }; 120 121 struct msm_vfe_axi_plane_cfg { 122 uint32_t output_width; /*Include padding*/ 123 uint32_t output_height; 124 uint32_t output_stride; 125 uint32_t output_scan_lines; 126 uint32_t output_plane_format; /*Y/Cb/Cr/CbCr*/ 127 uint32_t plane_addr_offset; 128 uint8_t csid_src; /*RDI 0-2*/ 129 uint8_t rdi_cid;/*CID 1-16*/ 130 }; 131 132 struct msm_vfe_axi_stream_request_cmd { 133 uint32_t session_id; 134 uint32_t stream_id; 135 uint32_t output_format;/*Planar/RAW/Misc*/ 136 enum msm_vfe_axi_stream_src stream_src; /*CAMIF/IDEAL/RDIs*/ 137 struct msm_vfe_axi_plane_cfg plane_cfg[MAX_PLANES_PER_STREAM]; 138 139 uint32_t burst_count; 140 uint32_t hfr_mode; 141 uint8_t frame_base; 142 143 uint32_t init_frame_drop; /*MAX 31 Frames*/ 144 enum msm_vfe_frame_skip_pattern frame_skip_pattern; 145 uint8_t buf_divert; /* if TRUE no vb2 buf done. */ 146 /*Return values*/ 147 uint32_t axi_stream_handle; 148 }; 149 150 struct msm_vfe_axi_stream_release_cmd { 151 uint32_t stream_handle; 152 }; 153 154 enum msm_vfe_axi_stream_cmd { 155 STOP_STREAM, 156 START_STREAM, 157 STOP_IMMEDIATELY, 158 }; 159 160 struct msm_vfe_axi_stream_cfg_cmd { 161 uint8_t num_streams; 162 uint32_t stream_handle[MAX_NUM_STREAM]; 163 enum msm_vfe_axi_stream_cmd cmd; 164 }; 165 166 enum msm_vfe_axi_stream_update_type { 167 ENABLE_STREAM_BUF_DIVERT, 168 DISABLE_STREAM_BUF_DIVERT, 169 UPDATE_STREAM_FRAMEDROP_PATTERN, 170 UPDATE_STREAM_REQUEST_FRAMES, 171 }; 172 173 struct msm_vfe_axi_stream_update_cmd { 174 uint32_t stream_handle; 175 enum msm_vfe_axi_stream_update_type update_type; 176 enum msm_vfe_frame_skip_pattern skip_pattern; 177 uint32_t request_frm_num; 178 }; 179 180 enum msm_isp_stats_type { 181 MSM_ISP_STATS_AEC, /* legacy based AEC */ 182 MSM_ISP_STATS_AF, /* legacy based AF */ 183 MSM_ISP_STATS_AWB, /* legacy based AWB */ 184 MSM_ISP_STATS_RS, /* legacy based RS */ 185 MSM_ISP_STATS_CS, /* legacy based CS */ 186 MSM_ISP_STATS_IHIST, /* legacy based HIST */ 187 MSM_ISP_STATS_SKIN, /* legacy based SKIN */ 188 MSM_ISP_STATS_BG, /* Bayer Grids */ 189 MSM_ISP_STATS_BF, /* Bayer Focus */ 190 MSM_ISP_STATS_BE, /* Bayer Exposure*/ 191 MSM_ISP_STATS_BHIST, /* Bayer Hist */ 192 MSM_ISP_STATS_MAX /* MAX */ 193 }; 194 195 struct msm_vfe_stats_stream_request_cmd { 196 uint32_t session_id; 197 uint32_t stream_id; 198 enum msm_isp_stats_type stats_type; 199 uint32_t composite_flag; 200 uint32_t framedrop_pattern; 201 uint32_t irq_subsample_pattern; 202 uint32_t buffer_offset; 203 uint32_t stream_handle; 204 }; 205 206 struct msm_vfe_stats_stream_release_cmd { 207 uint32_t stream_handle; 208 }; 209 struct msm_vfe_stats_stream_cfg_cmd { 210 uint8_t num_streams; 211 uint32_t stream_handle[MSM_ISP_STATS_MAX]; 212 uint8_t enable; 213 }; 214 215 enum msm_vfe_reg_cfg_type { 216 VFE_WRITE, 217 VFE_WRITE_MB, 218 VFE_READ, 219 VFE_CFG_MASK, 220 VFE_WRITE_DMI_16BIT, 221 VFE_WRITE_DMI_32BIT, 222 VFE_WRITE_DMI_64BIT, 223 VFE_READ_DMI_16BIT, 224 VFE_READ_DMI_32BIT, 225 VFE_READ_DMI_64BIT, 226 }; 227 228 struct msm_vfe_cfg_cmd2 { 229 uint16_t num_cfg; 230 uint16_t cmd_len; 231 void __user *cfg_data; 232 void __user *cfg_cmd; 233 }; 234 235 struct msm_vfe_reg_rw_info { 236 uint32_t reg_offset; 237 uint32_t cmd_data_offset; 238 uint32_t len; 239 }; 240 241 struct msm_vfe_reg_mask_info { 242 uint32_t reg_offset; 243 uint32_t mask; 244 uint32_t val; 245 }; 246 247 struct msm_vfe_reg_dmi_info { 248 uint32_t hi_tbl_offset; /*Optional*/ 249 uint32_t lo_tbl_offset; /*Required*/ 250 uint32_t len; 251 }; 252 253 struct msm_vfe_reg_cfg_cmd { 254 union { 255 struct msm_vfe_reg_rw_info rw_info; 256 struct msm_vfe_reg_mask_info mask_info; 257 struct msm_vfe_reg_dmi_info dmi_info; 258 } u; 259 260 enum msm_vfe_reg_cfg_type cmd_type; 261 }; 262 263 enum msm_isp_buf_type { 264 ISP_PRIVATE_BUF, 265 ISP_SHARE_BUF, 266 MAX_ISP_BUF_TYPE, 267 }; 268 269 struct msm_isp_buf_request { 270 uint32_t session_id; 271 uint32_t stream_id; 272 uint8_t num_buf; 273 uint32_t handle; 274 enum msm_isp_buf_type buf_type; 275 }; 276 277 struct msm_isp_qbuf_info { 278 uint32_t handle; 279 int buf_idx; 280 /*Only used for prepare buffer*/ 281 struct v4l2_buffer buffer; 282 /*Only used for diverted buffer*/ 283 uint32_t dirty_buf; 284 }; 285 286 struct msm_vfe_axi_src_state { 287 enum msm_vfe_input_src input_src; 288 uint32_t src_active; 289 }; 290 291 enum msm_isp_event_idx { 292 ISP_REG_UPDATE = 0, 293 ISP_START_ACK = 1, 294 ISP_STOP_ACK = 2, 295 ISP_IRQ_VIOLATION = 3, 296 ISP_WM_BUS_OVERFLOW = 4, 297 ISP_STATS_OVERFLOW = 5, 298 ISP_CAMIF_ERROR = 6, 299 ISP_SOF = 7, 300 ISP_EOF = 8, 301 ISP_FRAME_DROP = 9, 302 ISP_EVENT_MAX = 10 303 }; 304 305 #define ISP_EVENT_OFFSET 8 306 #define ISP_EVENT_BASE (V4L2_EVENT_PRIVATE_START) 307 #define ISP_BUF_EVENT_BASE (ISP_EVENT_BASE + (1 << ISP_EVENT_OFFSET)) 308 #define ISP_STATS_EVENT_BASE (ISP_EVENT_BASE + (2 << ISP_EVENT_OFFSET)) 309 #define ISP_EVENT_REG_UPDATE (ISP_EVENT_BASE + ISP_REG_UPDATE) 310 #define ISP_EVENT_START_ACK (ISP_EVENT_BASE + ISP_START_ACK) 311 #define ISP_EVENT_STOP_ACK (ISP_EVENT_BASE + ISP_STOP_ACK) 312 #define ISP_EVENT_IRQ_VIOLATION (ISP_EVENT_BASE + ISP_IRQ_VIOLATION) 313 #define ISP_EVENT_WM_BUS_OVERFLOW (ISP_EVENT_BASE + ISP_WM_BUS_OVERFLOW) 314 #define ISP_EVENT_STATS_OVERFLOW (ISP_EVENT_BASE + ISP_STATS_OVERFLOW) 315 #define ISP_EVENT_CAMIF_ERROR (ISP_EVENT_BASE + ISP_CAMIF_ERROR) 316 #define ISP_EVENT_SOF (ISP_EVENT_BASE + ISP_SOF) 317 #define ISP_EVENT_EOF (ISP_EVENT_BASE + ISP_EOF) 318 #define ISP_EVENT_FRAME_DROP (ISP_EVENT_BASE + ISP_FRAME_DROP) 319 #define ISP_EVENT_BUF_DIVERT (ISP_BUF_EVENT_BASE) 320 #define ISP_EVENT_STATS_NOTIFY (ISP_STATS_EVENT_BASE) 321 #define ISP_EVENT_COMP_STATS_NOTIFY (ISP_EVENT_STATS_NOTIFY + MSM_ISP_STATS_MAX) 322 /* The msm_v4l2_event_data structure should match the 323 * v4l2_event.u.data field. 324 * should not exceed 64 bytes */ 325 326 struct msm_isp_buf_event { 327 uint32_t session_id; 328 uint32_t stream_id; 329 uint32_t handle; 330 int8_t buf_idx; 331 }; 332 struct msm_isp_stats_event { 333 uint32_t stats_mask; /* 4 bytes */ 334 uint8_t stats_buf_idxs[MSM_ISP_STATS_MAX]; /* 11 bytes */ 335 }; 336 337 struct msm_isp_stream_ack { 338 uint32_t session_id; 339 uint32_t stream_id; 340 uint32_t handle; 341 }; 342 343 struct msm_isp_event_data { 344 /*Wall clock except for buffer divert events 345 *which use monotonic clock 346 */ 347 struct timeval timestamp; 348 /* Monotonic timestamp since bootup */ 349 struct timeval mono_timestamp; 350 /* if pix is a src frame_id is from camif */ 351 uint32_t frame_id; 352 union { 353 /* START_ACK, STOP_ACK */ 354 struct msm_isp_stream_ack stream_ack; 355 /* REG_UPDATE_TRIGGER, bus over flow */ 356 enum msm_vfe_input_src input_src; 357 /* stats notify */ 358 struct msm_isp_stats_event stats; 359 /* IRQ_VIOLATION, STATS_OVER_FLOW, WM_OVER_FLOW */ 360 uint32_t irq_status_mask; 361 struct msm_isp_buf_event buf_done; 362 } u; /* union can have max 52 bytes */ 363 }; 364 365 #define V4L2_PIX_FMT_QBGGR8 v4l2_fourcc('Q', 'B', 'G', '8') 366 #define V4L2_PIX_FMT_QGBRG8 v4l2_fourcc('Q', 'G', 'B', '8') 367 #define V4L2_PIX_FMT_QGRBG8 v4l2_fourcc('Q', 'G', 'R', '8') 368 #define V4L2_PIX_FMT_QRGGB8 v4l2_fourcc('Q', 'R', 'G', '8') 369 #define V4L2_PIX_FMT_QBGGR10 v4l2_fourcc('Q', 'B', 'G', '0') 370 #define V4L2_PIX_FMT_QGBRG10 v4l2_fourcc('Q', 'G', 'B', '0') 371 #define V4L2_PIX_FMT_QGRBG10 v4l2_fourcc('Q', 'G', 'R', '0') 372 #define V4L2_PIX_FMT_QRGGB10 v4l2_fourcc('Q', 'R', 'G', '0') 373 #define V4L2_PIX_FMT_QBGGR12 v4l2_fourcc('Q', 'B', 'G', '2') 374 #define V4L2_PIX_FMT_QGBRG12 v4l2_fourcc('Q', 'G', 'B', '2') 375 #define V4L2_PIX_FMT_QGRBG12 v4l2_fourcc('Q', 'G', 'R', '2') 376 #define V4L2_PIX_FMT_QRGGB12 v4l2_fourcc('Q', 'R', 'G', '2') 377 378 #define VIDIOC_MSM_VFE_REG_CFG \ 379 _IOWR('V', BASE_VIDIOC_PRIVATE, struct msm_vfe_cfg_cmd2) 380 381 #define VIDIOC_MSM_ISP_REQUEST_BUF \ 382 _IOWR('V', BASE_VIDIOC_PRIVATE+1, struct msm_isp_buf_request) 383 384 #define VIDIOC_MSM_ISP_ENQUEUE_BUF \ 385 _IOWR('V', BASE_VIDIOC_PRIVATE+2, struct msm_isp_qbuf_info) 386 387 #define VIDIOC_MSM_ISP_RELEASE_BUF \ 388 _IOWR('V', BASE_VIDIOC_PRIVATE+3, struct msm_isp_buf_request) 389 390 #define VIDIOC_MSM_ISP_REQUEST_STREAM \ 391 _IOWR('V', BASE_VIDIOC_PRIVATE+4, struct msm_vfe_axi_stream_request_cmd) 392 393 #define VIDIOC_MSM_ISP_CFG_STREAM \ 394 _IOWR('V', BASE_VIDIOC_PRIVATE+5, struct msm_vfe_axi_stream_cfg_cmd) 395 396 #define VIDIOC_MSM_ISP_RELEASE_STREAM \ 397 _IOWR('V', BASE_VIDIOC_PRIVATE+6, struct msm_vfe_axi_stream_release_cmd) 398 399 #define VIDIOC_MSM_ISP_INPUT_CFG \ 400 _IOWR('V', BASE_VIDIOC_PRIVATE+7, struct msm_vfe_input_cfg) 401 402 #define VIDIOC_MSM_ISP_SET_SRC_STATE \ 403 _IOWR('V', BASE_VIDIOC_PRIVATE+8, struct msm_vfe_axi_src_state) 404 405 #define VIDIOC_MSM_ISP_REQUEST_STATS_STREAM \ 406 _IOWR('V', BASE_VIDIOC_PRIVATE+9, \ 407 struct msm_vfe_stats_stream_request_cmd) 408 409 #define VIDIOC_MSM_ISP_CFG_STATS_STREAM \ 410 _IOWR('V', BASE_VIDIOC_PRIVATE+10, struct msm_vfe_stats_stream_cfg_cmd) 411 412 #define VIDIOC_MSM_ISP_RELEASE_STATS_STREAM \ 413 _IOWR('V', BASE_VIDIOC_PRIVATE+11, \ 414 struct msm_vfe_stats_stream_release_cmd) 415 416 #define VIDIOC_MSM_ISP_UPDATE_STREAM \ 417 _IOWR('V', BASE_VIDIOC_PRIVATE+13, struct msm_vfe_axi_stream_update_cmd) 418 419 #define VIDIOC_MSM_ISP_CONFIG_DONE \ 420 _IOWR('V', BASE_VIDIOC_PRIVATE+14, int) 421 422 423 #endif /* __MSMB_ISP__ */ 424