hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 *************************************************************************
 * Rockchip driver for CIF ISP 1.0
 * (Based on Intel driver for sofiaxxx)
 *
 * Copyright (C) 2015 Intel Mobile Communications GmbH
 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *************************************************************************
 */
#ifndef _CIF_ISP10_PLATFORM_H
#define _CIF_ISP10_PLATFORM_H
#include <linux/videodev2.h>
 
#define CIF_ISP10_SOC_RK3288    "rk3288"
#define CIF_ISP10_SOC_RK3368    "rk3368"
#define CIF_ISP10_SOC_RK3399    "rk3399"
 
#define DRIVER_NAME "rkisp10"
#define ISP_VDEV_NAME DRIVER_NAME  "_ispdev"
#define SP_VDEV_NAME DRIVER_NAME   "_selfpath"
#define MP_VDEV_NAME DRIVER_NAME   "_mainpath"
#define DMA_VDEV_NAME DRIVER_NAME  "_dmapath"
 
enum pltfrm_cam_signal_polarity {
   PLTFRM_CAM_SIGNAL_HIGH_LEVEL = 0,
   PLTFRM_CAM_SIGNAL_LOW_LEVEL = 1,
};
 
enum pltfrm_cam_sample_type {
   PLTFRM_CAM_SDR_NEG_EDG = 0x10000001,
   PLTFRM_CAM_SDR_POS_EDG = 0x10000002,
   PLTFRM_CAM_DDR         = 0x20000000
};
 
enum pltfrm_cam_itf_type {
   PLTFRM_CAM_ITF_MIPI     = 0x10000000,
   PLTFRM_CAM_ITF_BT601_8  = 0x20000071,
   PLTFRM_CAM_ITF_BT656_8  = 0x20000072,
   PLTFRM_CAM_ITF_BT601_10 = 0x20000091,
   PLTFRM_CAM_ITF_BT656_10 = 0x20000092,
   PLTFRM_CAM_ITF_BT601_12 = 0x200000B1,
   PLTFRM_CAM_ITF_BT656_12 = 0x200000B2,
   PLTFRM_CAM_ITF_BT601_16 = 0x200000F1,
   PLTFRM_CAM_ITF_BT656_16 = 0x200000F2,
   PLTFRM_CAM_ITF_BT656_8I = 0x20000172
};
 
#define PLTFRM_CAM_ITF_MAIN_MASK   0xf0000000
#define PLTFRM_CAM_ITF_SUB_MASK    0x0000000f
#define PLTFRM_CAM_ITF_DVP_BW_MASK 0x000000f0
#define PLTFRM_CAM_ITF_INTERLACE_MASK    0x00000100
 
#define PLTFRM_CAM_ITF_IS_MIPI(a)    \
       (((a) & PLTFRM_CAM_ITF_MAIN_MASK) == 0x10000000)
#define PLTFRM_CAM_ITF_IS_DVP(a)    \
       (((a) & PLTFRM_CAM_ITF_MAIN_MASK) == 0x20000000)
#define PLTFRM_CAM_ITF_IS_BT656(a)    (PLTFRM_CAM_ITF_IS_DVP(a) &&\
       (((a) & PLTFRM_CAM_ITF_SUB_MASK) == 0x02))
#define PLTFRM_CAM_ITF_IS_BT601(a)    (PLTFRM_CAM_ITF_IS_DVP(a) &&\
       (((a) & PLTFRM_CAM_ITF_SUB_MASK) == 0x01))
#define PLTFRM_CAM_ITF_DVP_BW(a)    \
       ((((a) & PLTFRM_CAM_ITF_DVP_BW_MASK) >> 4) + 1)
#define PLTFRM_CAM_ITF_INTERLACE(a)   \
       (((a) & PLTFRM_CAM_ITF_INTERLACE_MASK) == 0x00000100)
 
struct pltfrm_cam_mipi_config {
   u32 dphy_index;
   u32 vc;
   u32 nb_lanes;
   u32 bit_rate;
};
 
struct pltfrm_cam_dvp_config {
   enum pltfrm_cam_signal_polarity vsync;
   enum pltfrm_cam_signal_polarity hsync;
   enum pltfrm_cam_sample_type pclk;
};
 
struct pltfrm_cam_itf {
   enum pltfrm_cam_itf_type type;
 
   union {
       struct pltfrm_cam_mipi_config mipi;
       struct pltfrm_cam_dvp_config dvp;
   } cfg;
   unsigned int mclk_hz;
};
 
#define PLTFRM_CAM_ITF_MIPI_CFG(v, nb, br, mk)\
   .itf_cfg = {\
       .type =  PLTFRM_CAM_ITF_MIPI,\
           .cfg = {\
               .mipi = {\
                   .dphy_index = 0,\
                   .vc = v,\
                   .nb_lanes = nb,\
                   .bit_rate = br,\
               } \
           },\
       .mclk_hz = mk\
   }
#define PLTFRM_CAM_ITF_DVP_CFG(ty, vs, hs, ck, mk)\
   .itf_cfg = {\
       .type =  ty,\
       .cfg = {\
           .dvp = {\
               .vsync = vs,\
               .hsync = hs,\
               .pclk = ck,\
           } \
       },\
       .mclk_hz = mk\
   }
 
#define PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE    0x00
#define PLTFRM_CIFCAM_G_ITF_CFG    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 1)
#define PLTFRM_CIFCAM_G_DEFRECT    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 2)
#define PLTFRM_CIFCAM_ATTACH    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 3)
#define PLTFRM_CIFCAM_SET_VCM_POS    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 4)
#define PLTFRM_CIFCAM_GET_VCM_POS    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 5)
#define PLTFRM_CIFCAM_GET_VCM_MOVE_RES    \
               (PLTFRM_CIFCAM_IOCTL_INTERNAL_BASE + 6)
 
struct pltfrm_cam_vcm_tim {
   struct timeval vcm_start_t;
   struct timeval vcm_end_t;
};
 
struct pltfrm_cam_defrect {
   unsigned int width;
   unsigned int height;
   struct v4l2_rect defrect;
};
 
enum pltfrm_soc_cfg_cmd {
   PLTFRM_MCLK_CFG = 0,
   PLTFRM_MIPI_DPHY_CFG,
 
   PLTFRM_CLKEN,
   PLTFRM_CLKDIS,
   PLTFRM_CLKRST,
 
   PLTFRM_SOC_INIT
};
 
enum pltfrm_soc_io_voltage {
   PLTFRM_IO_1V8 = 0,
   PLTFRM_IO_3V3 = 1
};
 
enum pltfrm_soc_drv_strength {
   PLTFRM_DRV_STRENGTH_0 = 0,
   PLTFRM_DRV_STRENGTH_1 = 1,
   PLTFRM_DRV_STRENGTH_2 = 2,
   PLTFRM_DRV_STRENGTH_3 = 3
 
};
 
struct pltfrm_soc_init_para {
   struct platform_device *pdev;
   void __iomem *isp_base;
};
 
struct pltfrm_soc_mclk_para {
   enum pltfrm_soc_io_voltage io_voltage;
   enum pltfrm_soc_drv_strength drv_strength;
};
 
struct pltfrm_soc_cfg_para {
   enum pltfrm_soc_cfg_cmd cmd;
   void **isp_config;
   void *cfg_para;
};
 
struct pltfrm_soc_cfg {
   char name[32];
   void *isp_config;
   int (*soc_cfg)(struct pltfrm_soc_cfg_para *cfg);
};
 
int pltfrm_rk3288_cfg(struct pltfrm_soc_cfg_para *cfg);
int pltfrm_rk3399_cfg(struct pltfrm_soc_cfg_para *cfg);
 
 
#endif