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