10
10
11
11
#include <linux/iopoll.h>
12
12
#include <linux/pm_runtime.h>
13
+ #include <linux/regmap.h>
13
14
#include <linux/videodev2.h>
14
15
#include <linux/vmalloc.h>
15
16
53
54
* +---------------------------------------------------------+
54
55
*/
55
56
57
+ /* -----------------------------------------------------------------------------
58
+ * Media block control (i.MX8MP only)
59
+ */
60
+
61
+ #define ISP_DEWARP_CONTROL 0x0138
62
+
63
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_HS_POLARITY BIT(22)
64
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_RISING (0 << 20)
65
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_NEGATIVE (1 << 20)
66
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_POSITIVE (2 << 20)
67
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_FALLING (3 << 20)
68
+ #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_MASK GENMASK(21, 20)
69
+ #define ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE BIT(19)
70
+ #define ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE (dt ) ((dt) << 13)
71
+ #define ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK GENMASK(18, 13)
72
+
73
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_HS_POLARITY BIT(12)
74
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_RISING (0 << 10)
75
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_NEGATIVE (1 << 10)
76
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_POSITIVE (2 << 10)
77
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_FALLING (3 << 10)
78
+ #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_MASK GENMASK(11, 10)
79
+ #define ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE BIT(9)
80
+ #define ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE (dt ) ((dt) << 3)
81
+ #define ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK GENMASK(8, 3)
82
+
83
+ #define ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE BIT(1)
84
+ #define ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE BIT(0)
85
+
86
+ static int rkisp1_gasket_enable (struct rkisp1_device * rkisp1 ,
87
+ struct media_pad * source )
88
+ {
89
+ struct v4l2_subdev * source_sd ;
90
+ struct v4l2_mbus_frame_desc fd ;
91
+ unsigned int dt ;
92
+ u32 mask ;
93
+ u32 val ;
94
+ int ret ;
95
+
96
+ /*
97
+ * Configure and enable the gasket with the CSI-2 data type. Set the
98
+ * vsync polarity as active high, as that is what the ISP is configured
99
+ * to expect in ISP_ACQ_PROP. Enable left justification, as the i.MX8MP
100
+ * ISP has a 16-bit wide input and expects data to be left-aligned.
101
+ */
102
+
103
+ source_sd = media_entity_to_v4l2_subdev (source -> entity );
104
+ ret = v4l2_subdev_call (source_sd , pad , get_frame_desc ,
105
+ source -> index , & fd );
106
+ if (ret ) {
107
+ dev_err (rkisp1 -> dev ,
108
+ "failed to get frame descriptor from '%s':%u: %d\n" ,
109
+ source_sd -> name , 0 , ret );
110
+ return ret ;
111
+ }
112
+
113
+ if (fd .num_entries != 1 ) {
114
+ dev_err (rkisp1 -> dev , "invalid frame descriptor for '%s':%u\n" ,
115
+ source_sd -> name , 0 );
116
+ return - EINVAL ;
117
+ }
118
+
119
+ dt = fd .entry [0 ].bus .csi2 .dt ;
120
+
121
+ if (rkisp1 -> gasket_id == 0 ) {
122
+ mask = ISP_DEWARP_CONTROL_MIPI_CSI1_HS_POLARITY
123
+ | ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_MASK
124
+ | ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE
125
+ | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK
126
+ | ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE ;
127
+ val = ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_POSITIVE
128
+ | ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE
129
+ | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE (dt );
130
+ } else {
131
+ mask = ISP_DEWARP_CONTROL_MIPI_CSI2_HS_POLARITY
132
+ | ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_MASK
133
+ | ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE
134
+ | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK
135
+ | ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE ;
136
+ val = ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_POSITIVE
137
+ | ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE
138
+ | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE (dt );
139
+ }
140
+
141
+ regmap_update_bits (rkisp1 -> gasket , ISP_DEWARP_CONTROL , mask , val );
142
+
143
+ return 0 ;
144
+ }
145
+
146
+ static void rkisp1_gasket_disable (struct rkisp1_device * rkisp1 )
147
+ {
148
+ u32 mask ;
149
+ u32 val ;
150
+
151
+ if (rkisp1 -> gasket_id == 1 ) {
152
+ mask = ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE
153
+ | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK
154
+ | ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE ;
155
+ val = ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE ;
156
+ } else {
157
+ mask = ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE
158
+ | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK
159
+ | ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE ;
160
+ val = ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE ;
161
+ }
162
+
163
+ regmap_update_bits (rkisp1 -> gasket , ISP_DEWARP_CONTROL , mask , val );
164
+ }
165
+
56
166
/* ----------------------------------------------------------------------------
57
167
* Camera Interface registers configurations
58
168
*/
@@ -291,6 +401,9 @@ static void rkisp1_isp_stop(struct rkisp1_isp *isp)
291
401
RKISP1_CIF_VI_IRCL_MIPI_SW_RST |
292
402
RKISP1_CIF_VI_IRCL_ISP_SW_RST );
293
403
rkisp1_write (rkisp1 , RKISP1_CIF_VI_IRCL , 0x0 );
404
+
405
+ if (rkisp1 -> info -> isp_ver == RKISP1_V_IMX8MP )
406
+ rkisp1_gasket_disable (rkisp1 );
294
407
}
295
408
296
409
static void rkisp1_config_clk (struct rkisp1_isp * isp )
@@ -315,16 +428,24 @@ static void rkisp1_config_clk(struct rkisp1_isp *isp)
315
428
}
316
429
}
317
430
318
- static void rkisp1_isp_start (struct rkisp1_isp * isp ,
319
- struct v4l2_subdev_state * sd_state )
431
+ static int rkisp1_isp_start (struct rkisp1_isp * isp ,
432
+ struct v4l2_subdev_state * sd_state ,
433
+ struct media_pad * source )
320
434
{
321
435
struct rkisp1_device * rkisp1 = isp -> rkisp1 ;
322
436
const struct v4l2_mbus_framefmt * src_fmt ;
323
437
const struct rkisp1_mbus_info * src_info ;
324
438
u32 val ;
439
+ int ret ;
325
440
326
441
rkisp1_config_clk (isp );
327
442
443
+ if (rkisp1 -> info -> isp_ver == RKISP1_V_IMX8MP ) {
444
+ ret = rkisp1_gasket_enable (rkisp1 , source );
445
+ if (ret )
446
+ return ret ;
447
+ }
448
+
328
449
/* Activate ISP */
329
450
val = rkisp1_read (rkisp1 , RKISP1_CIF_ISP_CTRL );
330
451
val |= RKISP1_CIF_ISP_CTRL_ISP_CFG_UPD |
@@ -338,6 +459,8 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
338
459
339
460
if (src_info -> pixel_enc != V4L2_PIXEL_ENC_BAYER )
340
461
rkisp1_params_post_configure (& rkisp1 -> params );
462
+
463
+ return 0 ;
341
464
}
342
465
343
466
/* ----------------------------------------------------------------------------
@@ -848,7 +971,9 @@ static int rkisp1_isp_s_stream(struct v4l2_subdev *sd, int enable)
848
971
if (ret )
849
972
goto out_unlock ;
850
973
851
- rkisp1_isp_start (isp , sd_state );
974
+ ret = rkisp1_isp_start (isp , sd_state , source_pad );
975
+ if (ret )
976
+ goto out_unlock ;
852
977
853
978
ret = v4l2_subdev_call (rkisp1 -> source , video , s_stream , true);
854
979
if (ret ) {
0 commit comments