1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR MIT) */ 2 /* 3 * Rockchip module information 4 * Copyright (C) 2018-2019 Rockchip Electronics Co., Ltd. 5 */ 6 7 #ifndef _UAPI_RKMODULE_CAMERA_H 8 #define _UAPI_RKMODULE_CAMERA_H 9 10 #include <linux/types.h> 11 #include <linux/rk-video-format.h> 12 13 #define RKMODULE_API_VERSION KERNEL_VERSION(0, 1, 0x2) 14 15 /* using for rk3588 dual isp unite */ 16 #define RKMOUDLE_UNITE_EXTEND_PIXEL 128 17 /* using for rv1109 and rv1126 */ 18 #define RKMODULE_EXTEND_LINE 24 19 20 #define RKMODULE_NAME_LEN 32 21 #define RKMODULE_LSCDATA_LEN 289 22 23 #define RKMODULE_MAX_VC_CH 4 24 25 #define RKMODULE_PADF_GAINMAP_LEN 1024 26 #define RKMODULE_PDAF_DCCMAP_LEN 256 27 #define RKMODULE_AF_OTP_MAX_LEN 3 28 29 #define RKMODULE_CAMERA_MODULE_INDEX "rockchip,camera-module-index" 30 #define RKMODULE_CAMERA_MODULE_FACING "rockchip,camera-module-facing" 31 #define RKMODULE_CAMERA_MODULE_NAME "rockchip,camera-module-name" 32 #define RKMODULE_CAMERA_LENS_NAME "rockchip,camera-module-lens-name" 33 34 #define RKMODULE_CAMERA_SYNC_MODE "rockchip,camera-module-sync-mode" 35 #define RKMODULE_INTERNAL_MASTER_MODE "internal_master" 36 #define RKMODULE_EXTERNAL_MASTER_MODE "external_master" 37 #define RKMODULE_SLAVE_MODE "slave" 38 39 /* BT.656 & BT.1120 multi channel 40 * On which channels it can send video data 41 * related with struct rkmodule_bt656_mbus_info 42 */ 43 #define RKMODULE_CAMERA_BT656_ID_EN_BITS_1 (0x1) 44 #define RKMODULE_CAMERA_BT656_ID_EN_BITS_2 (0x3) 45 #define RKMODULE_CAMERA_BT656_ID_EN_BITS_3 (0x7) 46 #define RKMODULE_CAMERA_BT656_ID_EN_BITS_4 (0xf) 47 #define RKMODULE_CAMERA_BT656_PARSE_ID_LSB BIT(0) 48 #define RKMODULE_CAMERA_BT656_PARSE_ID_MSB BIT(1) 49 #define RKMODULE_CAMERA_BT656_CHANNEL_0 BIT(2) 50 #define RKMODULE_CAMERA_BT656_CHANNEL_1 BIT(3) 51 #define RKMODULE_CAMERA_BT656_CHANNEL_2 BIT(4) 52 #define RKMODULE_CAMERA_BT656_CHANNEL_3 BIT(5) 53 #define RKMODULE_CAMERA_BT656_CHANNELS (RKMODULE_CAMERA_BT656_CHANNEL_0 | \ 54 RKMODULE_CAMERA_BT656_CHANNEL_1 | \ 55 RKMODULE_CAMERA_BT656_CHANNEL_2 | \ 56 RKMODULE_CAMERA_BT656_CHANNEL_3) 57 58 #define RKMODULE_GET_MODULE_INFO \ 59 _IOR('V', BASE_VIDIOC_PRIVATE + 0, struct rkmodule_inf) 60 61 #define RKMODULE_AWB_CFG \ 62 _IOW('V', BASE_VIDIOC_PRIVATE + 1, struct rkmodule_awb_cfg) 63 64 #define RKMODULE_AF_CFG \ 65 _IOW('V', BASE_VIDIOC_PRIVATE + 2, struct rkmodule_af_cfg) 66 67 #define RKMODULE_LSC_CFG \ 68 _IOW('V', BASE_VIDIOC_PRIVATE + 3, struct rkmodule_lsc_cfg) 69 70 #define RKMODULE_GET_HDR_CFG \ 71 _IOR('V', BASE_VIDIOC_PRIVATE + 4, struct rkmodule_hdr_cfg) 72 73 #define RKMODULE_SET_HDR_CFG \ 74 _IOW('V', BASE_VIDIOC_PRIVATE + 5, struct rkmodule_hdr_cfg) 75 76 #define RKMODULE_SET_CONVERSION_GAIN \ 77 _IOW('V', BASE_VIDIOC_PRIVATE + 6, __u32) 78 79 #define RKMODULE_GET_LVDS_CFG \ 80 _IOR('V', BASE_VIDIOC_PRIVATE + 7, struct rkmodule_lvds_cfg) 81 82 #define RKMODULE_SET_DPCC_CFG \ 83 _IOW('V', BASE_VIDIOC_PRIVATE + 8, struct rkmodule_dpcc_cfg) 84 85 #define RKMODULE_GET_NR_SWITCH_THRESHOLD \ 86 _IOR('V', BASE_VIDIOC_PRIVATE + 9, struct rkmodule_nr_switch_threshold) 87 88 #define RKMODULE_SET_QUICK_STREAM \ 89 _IOW('V', BASE_VIDIOC_PRIVATE + 10, __u32) 90 91 #define RKMODULE_GET_BT656_INTF_TYPE \ 92 _IOR('V', BASE_VIDIOC_PRIVATE + 11, __u32) 93 94 #define RKMODULE_GET_VC_FMT_INFO \ 95 _IOR('V', BASE_VIDIOC_PRIVATE + 12, struct rkmodule_vc_fmt_info) 96 97 #define RKMODULE_GET_VC_HOTPLUG_INFO \ 98 _IOR('V', BASE_VIDIOC_PRIVATE + 13, struct rkmodule_vc_hotplug_info) 99 100 #define RKMODULE_GET_START_STREAM_SEQ \ 101 _IOR('V', BASE_VIDIOC_PRIVATE + 14, __u32) 102 103 #define RKMODULE_GET_VICAP_RST_INFO \ 104 _IOR('V', BASE_VIDIOC_PRIVATE + 15, struct rkmodule_vicap_reset_info) 105 106 #define RKMODULE_SET_VICAP_RST_INFO \ 107 _IOW('V', BASE_VIDIOC_PRIVATE + 16, struct rkmodule_vicap_reset_info) 108 109 #define RKMODULE_GET_BT656_MBUS_INFO \ 110 _IOR('V', BASE_VIDIOC_PRIVATE + 17, struct rkmodule_bt656_mbus_info) 111 112 #define RKMODULE_GET_DCG_RATIO \ 113 _IOR('V', BASE_VIDIOC_PRIVATE + 18, struct rkmodule_dcg_ratio) 114 115 #define RKMODULE_GET_SONY_BRL \ 116 _IOR('V', BASE_VIDIOC_PRIVATE + 19, __u32) 117 118 #define RKMODULE_GET_CHANNEL_INFO \ 119 _IOWR('V', BASE_VIDIOC_PRIVATE + 20, struct rkmodule_channel_info) 120 121 #define RKMODULE_GET_SYNC_MODE \ 122 _IOR('V', BASE_VIDIOC_PRIVATE + 21, __u32) 123 124 #define RKMODULE_SET_SYNC_MODE \ 125 _IOW('V', BASE_VIDIOC_PRIVATE + 22, __u32) 126 127 /** 128 * struct rkmodule_base_inf - module base information 129 * 130 */ 131 struct rkmodule_base_inf { 132 char sensor[RKMODULE_NAME_LEN]; 133 char module[RKMODULE_NAME_LEN]; 134 char lens[RKMODULE_NAME_LEN]; 135 } __attribute__ ((packed)); 136 137 /** 138 * struct rkmodule_fac_inf - module factory information 139 * 140 */ 141 struct rkmodule_fac_inf { 142 __u32 flag; 143 144 char module[RKMODULE_NAME_LEN]; 145 char lens[RKMODULE_NAME_LEN]; 146 __u32 year; 147 __u32 month; 148 __u32 day; 149 } __attribute__ ((packed)); 150 151 /** 152 * struct rkmodule_awb_inf - module awb information 153 * 154 */ 155 struct rkmodule_awb_inf { 156 __u32 flag; 157 158 __u32 r_value; 159 __u32 b_value; 160 __u32 gr_value; 161 __u32 gb_value; 162 163 __u32 golden_r_value; 164 __u32 golden_b_value; 165 __u32 golden_gr_value; 166 __u32 golden_gb_value; 167 } __attribute__ ((packed)); 168 169 /** 170 * struct rkmodule_lsc_inf - module lsc information 171 * 172 */ 173 struct rkmodule_lsc_inf { 174 __u32 flag; 175 176 __u16 lsc_w; 177 __u16 lsc_h; 178 __u16 decimal_bits; 179 180 __u16 lsc_r[RKMODULE_LSCDATA_LEN]; 181 __u16 lsc_b[RKMODULE_LSCDATA_LEN]; 182 __u16 lsc_gr[RKMODULE_LSCDATA_LEN]; 183 __u16 lsc_gb[RKMODULE_LSCDATA_LEN]; 184 185 __u16 width; 186 __u16 height; 187 __u16 table_size; 188 } __attribute__ ((packed)); 189 190 /** 191 * enum rkmodule_af_dir - enum of module af otp direction 192 */ 193 enum rkmodele_af_otp_dir { 194 AF_OTP_DIR_HORIZONTAL = 0, 195 AF_OTP_DIR_UP = 1, 196 AF_OTP_DIR_DOWN = 2, 197 }; 198 199 /** 200 * struct rkmodule_af_otp - module af otp in one direction 201 */ 202 struct rkmodule_af_otp { 203 __u32 vcm_start; 204 __u32 vcm_end; 205 __u32 vcm_dir; 206 }; 207 208 /** 209 * struct rkmodule_af_inf - module af information 210 * 211 */ 212 struct rkmodule_af_inf { 213 __u32 flag; 214 __u32 dir_cnt; 215 struct rkmodule_af_otp af_otp[RKMODULE_AF_OTP_MAX_LEN]; 216 } __attribute__ ((packed)); 217 218 /** 219 * struct rkmodule_pdaf_inf - module pdaf information 220 * 221 */ 222 struct rkmodule_pdaf_inf { 223 __u32 flag; 224 225 __u32 gainmap_width; 226 __u32 gainmap_height; 227 __u32 dccmap_width; 228 __u32 dccmap_height; 229 __u32 dcc_mode; 230 __u32 dcc_dir; 231 __u16 gainmap[RKMODULE_PADF_GAINMAP_LEN]; 232 __u16 dccmap[RKMODULE_PDAF_DCCMAP_LEN]; 233 } __attribute__ ((packed)); 234 235 /** 236 * struct rkmodule_otp_module_inf - otp module info 237 * 238 */ 239 struct rkmodule_otp_module_inf { 240 __u32 flag; 241 __u8 vendor[8]; 242 __u32 module_id; 243 __u16 version; 244 __u16 full_width; 245 __u16 full_height; 246 __u8 supplier_id; 247 __u8 year; 248 __u8 mouth; 249 __u8 day; 250 __u8 sensor_id; 251 __u8 lens_id; 252 __u8 vcm_id; 253 __u8 drv_id; 254 __u8 flip; 255 } __attribute__ ((packed)); 256 257 /** 258 * struct rkmodule_inf - module information 259 * 260 */ 261 struct rkmodule_inf { 262 struct rkmodule_base_inf base; 263 struct rkmodule_fac_inf fac; 264 struct rkmodule_awb_inf awb; 265 struct rkmodule_lsc_inf lsc; 266 struct rkmodule_af_inf af; 267 struct rkmodule_pdaf_inf pdaf; 268 struct rkmodule_otp_module_inf module_inf; 269 } __attribute__ ((packed)); 270 271 /** 272 * struct rkmodule_awb_inf - module awb information 273 * 274 */ 275 struct rkmodule_awb_cfg { 276 __u32 enable; 277 __u32 golden_r_value; 278 __u32 golden_b_value; 279 __u32 golden_gr_value; 280 __u32 golden_gb_value; 281 } __attribute__ ((packed)); 282 283 /** 284 * struct rkmodule_af_cfg 285 * 286 */ 287 struct rkmodule_af_cfg { 288 __u32 enable; 289 __u32 vcm_start; 290 __u32 vcm_end; 291 __u32 vcm_dir; 292 } __attribute__ ((packed)); 293 294 /** 295 * struct rkmodule_lsc_cfg 296 * 297 */ 298 struct rkmodule_lsc_cfg { 299 __u32 enable; 300 } __attribute__ ((packed)); 301 302 /** 303 * NO_HDR: linear mode 304 * HDR_X2: hdr two frame or line mode 305 * HDR_X3: hdr three or line mode 306 */ 307 enum rkmodule_hdr_mode { 308 NO_HDR = 0, 309 HDR_X2 = 5, 310 HDR_X3 = 6, 311 }; 312 313 /** 314 * HDR_NORMAL_VC: hdr frame with diff virtual channels 315 * HDR_LINE_CNT: hdr frame with line counter 316 * HDR_ID_CODE: hdr frame with identification code 317 */ 318 enum hdr_esp_mode { 319 HDR_NORMAL_VC = 0, 320 HDR_LINE_CNT, 321 HDR_ID_CODE, 322 }; 323 324 /** 325 * lcnt: line counter 326 * padnum: the pixels of padding row 327 * padpix: the payload of padding 328 * idcd: identification code 329 * efpix: identification code of Effective line 330 * obpix: identification code of OB line 331 */ 332 struct rkmodule_hdr_esp { 333 enum hdr_esp_mode mode; 334 union { 335 struct { 336 __u32 padnum; 337 __u32 padpix; 338 } lcnt; 339 struct { 340 __u32 efpix; 341 __u32 obpix; 342 } idcd; 343 } val; 344 }; 345 346 struct rkmodule_hdr_cfg { 347 __u32 hdr_mode; 348 struct rkmodule_hdr_esp esp; 349 } __attribute__ ((packed)); 350 351 /* sensor lvds sync code 352 * sav: start of active video codes 353 * eav: end of active video codes 354 */ 355 struct rkmodule_sync_code { 356 __u16 sav; 357 __u16 eav; 358 }; 359 360 /* sensor lvds difference sync code mode 361 * LS_FIRST: valid line ls-le or sav-eav 362 * invalid line fs-fe or sav-eav 363 * FS_FIRST: valid line fs-le 364 * invalid line ls-fe 365 * ls: line start 366 * le: line end 367 * fs: frame start 368 * fe: frame end 369 * SONY_DOL_HDR_1: sony dol hdr pattern 1 370 * SONY_DOL_HDR_2: sony dol hdr pattern 2 371 */ 372 enum rkmodule_lvds_mode { 373 LS_FIRST = 0, 374 FS_FIRST, 375 SONY_DOL_HDR_1, 376 SONY_DOL_HDR_2 377 }; 378 379 /* sync code of different frame type (hdr or linear) for lvds 380 * act: valid line sync code 381 * blk: invalid line sync code 382 */ 383 struct rkmodule_lvds_frm_sync_code { 384 struct rkmodule_sync_code act; 385 struct rkmodule_sync_code blk; 386 }; 387 388 /* sync code for lvds of sensor 389 * odd_sync_code: sync code of odd frame id for lvds of sony sensor 390 * even_sync_code: sync code of even frame id for lvds of sony sensor 391 */ 392 struct rkmodule_lvds_frame_sync_code { 393 struct rkmodule_lvds_frm_sync_code odd_sync_code; 394 struct rkmodule_lvds_frm_sync_code even_sync_code; 395 }; 396 397 /* lvds sync code category of sensor for different operation */ 398 enum rkmodule_lvds_sync_code_group { 399 LVDS_CODE_GRP_LINEAR = 0x0, 400 LVDS_CODE_GRP_LONG, 401 LVDS_CODE_GRP_MEDIUM, 402 LVDS_CODE_GRP_SHORT, 403 LVDS_CODE_GRP_MAX 404 }; 405 406 /* struct rkmodule_lvds_cfg 407 * frm_sync_code[index]: 408 * index == LVDS_CODE_GRP_LONG: 409 * sync code for frame of linear mode or for long frame of hdr mode 410 * index == LVDS_CODE_GRP_MEDIUM: 411 * sync code for medium long frame of hdr mode 412 * index == LVDS_CODE_GRP_SHOR: 413 * sync code for short long frame of hdr mode 414 */ 415 struct rkmodule_lvds_cfg { 416 enum rkmodule_lvds_mode mode; 417 struct rkmodule_lvds_frame_sync_code frm_sync_code[LVDS_CODE_GRP_MAX]; 418 } __attribute__ ((packed)); 419 420 /** 421 * struct rkmodule_dpcc_cfg 422 * enable: 0 -> disable dpcc, 1 -> enable multiple, 423 * 2 -> enable single, 3 -> enable all; 424 * cur_single_dpcc: the strength of single dpcc; 425 * cur_multiple_dpcc: the strength of multiple dpcc; 426 * total_dpcc: the max strength; 427 */ 428 struct rkmodule_dpcc_cfg { 429 __u32 enable; 430 __u32 cur_single_dpcc; 431 __u32 cur_multiple_dpcc; 432 __u32 total_dpcc; 433 } __attribute__ ((packed)); 434 435 /** 436 * nr switch by gain 437 * direct: 0 -> up_thres LSNR to HSNR, 1 -> up_thres HSNR to LSNR 438 * up_thres: threshold of nr change from low gain to high gain 439 * down_thres: threshold of nr change from high gain to low gain; 440 * div_coeff: Coefficients converted from float to int 441 */ 442 struct rkmodule_nr_switch_threshold { 443 __u32 direct; 444 __u32 up_thres; 445 __u32 down_thres; 446 __u32 div_coeff; 447 } __attribute__ ((packed)); 448 449 /** 450 * enum rkmodule_bt656_intf_type 451 * to support sony bt656 raw 452 */ 453 enum rkmodule_bt656_intf_type { 454 BT656_STD_RAW = 0, 455 BT656_SONY_RAW, 456 }; 457 458 /** 459 * struct rkmodule_vc_fmt_info - virtual channels fmt info 460 * 461 */ 462 struct rkmodule_vc_fmt_info { 463 __u32 width[RKMODULE_MAX_VC_CH]; 464 __u32 height[RKMODULE_MAX_VC_CH]; 465 __u32 fps[RKMODULE_MAX_VC_CH]; 466 } __attribute__ ((packed)); 467 468 /** 469 * struct rkmodule_vc_hotplug_info - virtual channels hotplug status info 470 * detect_status: hotplug status 471 * bit 0~3 means channels id, value : 0 -> plug out, 1 -> plug in. 472 */ 473 struct rkmodule_vc_hotplug_info { 474 __u8 detect_status; 475 } __attribute__ ((packed)); 476 477 478 /* sensor start stream sequence 479 * RKMODULE_START_STREAM_DEFAULT: by default 480 * RKMODULE_START_STREAM_BEHIND : sensor start stream should be behind the controller 481 * RKMODULE_START_STREAM_FRONT : sensor start stream should be in front of the controller 482 */ 483 enum rkmodule_start_stream_seq { 484 RKMODULE_START_STREAM_DEFAULT = 0, 485 RKMODULE_START_STREAM_BEHIND, 486 RKMODULE_START_STREAM_FRONT, 487 }; 488 489 /* 490 * the causation to do cif reset work 491 */ 492 enum rkmodule_reset_src { 493 RKCIF_RESET_SRC_NON = 0x0, 494 RKCIF_RESET_SRC_ERR_CSI2, 495 RKCIF_RESET_SRC_ERR_LVDS, 496 RKICF_RESET_SRC_ERR_CUTOFF, 497 RKCIF_RESET_SRC_ERR_HOTPLUG, 498 RKCIF_RESET_SRC_ERR_APP, 499 }; 500 501 struct rkmodule_vicap_reset_info { 502 __u32 is_reset; 503 enum rkmodule_reset_src src; 504 } __attribute__ ((packed)); 505 506 struct rkmodule_bt656_mbus_info { 507 __u32 flags; 508 __u32 id_en_bits; 509 } __attribute__ ((packed)); 510 511 /* DCG ratio (float) = integer + decimal / div_coeff */ 512 struct rkmodule_dcg_ratio { 513 __u32 integer; 514 __u32 decimal; 515 __u32 div_coeff; 516 }; 517 518 struct rkmodule_channel_info { 519 __u32 index; 520 __u32 vc; 521 __u32 width; 522 __u32 height; 523 __u32 bus_fmt; 524 __u32 data_type; 525 __u32 data_bit; 526 } __attribute__ ((packed)); 527 528 /* 529 * link to vicap 530 * linear mode: pad0~pad3 for id0~id3; 531 * 532 * HDR_X2: id0 fiexd to vc0 for long frame 533 * id1 fixed to vc1 for short frame; 534 * id2~id3 reserved, can config by PAD2~PAD3 535 * 536 * HDR_X3: id0 fiexd to vc0 for long frame 537 * id1 fixed to vc1 for middle frame 538 * id2 fixed to vc2 for short frame; 539 * id3 reserved, can config by PAD3 540 * 541 * link to isp, the connection relationship is as follows 542 */ 543 enum rkmodule_max_pad { 544 PAD0, /* link to isp */ 545 PAD1, /* link to csi wr0 | hdr x2:L x3:M */ 546 PAD2, /* link to csi wr1 | hdr x3:L */ 547 PAD3, /* link to csi wr2 | hdr x2:M x3:S */ 548 PAD_MAX, 549 }; 550 551 /* 552 * sensor exposure sync mode 553 */ 554 enum rkmodule_sync_mode { 555 NO_SYNC_MODE = 0, 556 EXTERNAL_MASTER_MODE, 557 INTERNAL_MASTER_MODE, 558 SLAVE_MODE, 559 }; 560 #endif /* _UAPI_RKMODULE_CAMERA_H */ 561