5757#define CSI2RX_LANES_MAX 4
5858#define CSI2RX_STREAMS_MAX 4
5959
60+ #define CSI2RX_ERROR_IRQS_REG 0x28
61+ #define CSI2RX_ERROR_IRQS_MASK_REG 0x2C
62+
63+ #define CSI2RX_STREAM3_FIFO_OVERFLOW_IRQ BIT(19)
64+ #define CSI2RX_STREAM2_FIFO_OVERFLOW_IRQ BIT(18)
65+ #define CSI2RX_STREAM1_FIFO_OVERFLOW_IRQ BIT(17)
66+ #define CSI2RX_STREAM0_FIFO_OVERFLOW_IRQ BIT(16)
67+ #define CSI2RX_FRONT_TRUNC_HDR_IRQ BIT(12)
68+ #define CSI2RX_PROT_TRUNCATED_PACKET_IRQ BIT(11)
69+ #define CSI2RX_FRONT_LP_NO_PAYLOAD_IRQ BIT(10)
70+ #define CSI2RX_SP_INVALID_RCVD_IRQ BIT(9)
71+ #define CSI2RX_DATA_ID_IRQ BIT(7)
72+ #define CSI2RX_HEADER_CORRECTED_ECC_IRQ BIT(6)
73+ #define CSI2RX_HEADER_ECC_IRQ BIT(5)
74+ #define CSI2RX_PAYLOAD_CRC_IRQ BIT(4)
75+
76+ #define CSI2RX_ECC_ERRORS GENMASK(7, 4)
77+ #define CSI2RX_PACKET_ERRORS GENMASK(12, 9)
78+
6079enum csi2rx_pads {
6180 CSI2RX_PAD_SINK ,
6281 CSI2RX_PAD_SOURCE_STREAM0 ,
@@ -71,9 +90,32 @@ struct csi2rx_fmt {
7190 u8 bpp ;
7291};
7392
93+ struct csi2rx_event {
94+ u32 mask ;
95+ const char * name ;
96+ };
97+
98+ static const struct csi2rx_event csi2rx_events [] = {
99+ { CSI2RX_STREAM3_FIFO_OVERFLOW_IRQ , "Overflow of the Stream 3 FIFO detected" },
100+ { CSI2RX_STREAM2_FIFO_OVERFLOW_IRQ , "Overflow of the Stream 2 FIFO detected" },
101+ { CSI2RX_STREAM1_FIFO_OVERFLOW_IRQ , "Overflow of the Stream 1 FIFO detected" },
102+ { CSI2RX_STREAM0_FIFO_OVERFLOW_IRQ , "Overflow of the Stream 0 FIFO detected" },
103+ { CSI2RX_FRONT_TRUNC_HDR_IRQ , "A truncated header [short or long] has been received" },
104+ { CSI2RX_PROT_TRUNCATED_PACKET_IRQ , "A truncated long packet has been received" },
105+ { CSI2RX_FRONT_LP_NO_PAYLOAD_IRQ , "A truncated long packet has been received. No payload" },
106+ { CSI2RX_SP_INVALID_RCVD_IRQ , "A reserved or invalid short packet has been received" },
107+ { CSI2RX_DATA_ID_IRQ , "Data ID error in the header packet" },
108+ { CSI2RX_HEADER_CORRECTED_ECC_IRQ , "ECC error detected and corrected" },
109+ { CSI2RX_HEADER_ECC_IRQ , "Unrecoverable ECC error" },
110+ { CSI2RX_PAYLOAD_CRC_IRQ , "CRC error" },
111+ };
112+
113+ #define CSI2RX_NUM_EVENTS ARRAY_SIZE(csi2rx_events)
114+
74115struct csi2rx_priv {
75116 struct device * dev ;
76117 unsigned int count ;
118+ int error_irq ;
77119
78120 /*
79121 * Used to prevent race conditions between multiple,
@@ -95,6 +137,7 @@ struct csi2rx_priv {
95137 u8 max_lanes ;
96138 u8 max_streams ;
97139 bool has_internal_dphy ;
140+ u32 events [CSI2RX_NUM_EVENTS ];
98141
99142 struct v4l2_subdev subdev ;
100143 struct v4l2_async_notifier notifier ;
@@ -124,6 +167,54 @@ static const struct csi2rx_fmt formats[] = {
124167 { .code = MEDIA_BUS_FMT_BGR888_1X24 , .bpp = 24 , },
125168};
126169
170+ static void csi2rx_configure_error_irq_mask (void __iomem * base ,
171+ struct csi2rx_priv * csi2rx )
172+ {
173+ u32 error_irq_mask = 0 ;
174+
175+ error_irq_mask |= CSI2RX_ECC_ERRORS ;
176+ error_irq_mask |= CSI2RX_PACKET_ERRORS ;
177+
178+ /*
179+ * Iterate through all source pads and check if they are linked
180+ * to an active remote pad. If an active remote pad is found,
181+ * calculate the corresponding bit position and set it in
182+ * mask, enabling the stream overflow error in the mask.
183+ */
184+ for (int i = CSI2RX_PAD_SOURCE_STREAM0 ; i < CSI2RX_PAD_MAX ; i ++ ) {
185+ struct media_pad * remote_pad ;
186+
187+ remote_pad = media_pad_remote_pad_first (& csi2rx -> pads [i ]);
188+ if (remote_pad ) {
189+ int pad = i - CSI2RX_PAD_SOURCE_STREAM0 ;
190+ u32 bit_mask = CSI2RX_STREAM0_FIFO_OVERFLOW_IRQ << pad ;
191+
192+ error_irq_mask |= bit_mask ;
193+ }
194+ }
195+
196+ writel (error_irq_mask , base + CSI2RX_ERROR_IRQS_MASK_REG );
197+ }
198+
199+ static irqreturn_t csi2rx_irq_handler (int irq , void * dev_id )
200+ {
201+ struct csi2rx_priv * csi2rx = dev_id ;
202+ int i ;
203+ u32 error_status , error_mask ;
204+
205+ error_status = readl (csi2rx -> base + CSI2RX_ERROR_IRQS_REG );
206+ error_mask = readl (csi2rx -> base + CSI2RX_ERROR_IRQS_MASK_REG );
207+
208+ for (i = 0 ; i < CSI2RX_NUM_EVENTS ; i ++ )
209+ if ((error_status & csi2rx_events [i ].mask ) &&
210+ (error_mask & csi2rx_events [i ].mask ))
211+ csi2rx -> events [i ]++ ;
212+
213+ writel (error_status , csi2rx -> base + CSI2RX_ERROR_IRQS_REG );
214+
215+ return IRQ_HANDLED ;
216+ }
217+
127218static const struct csi2rx_fmt * csi2rx_get_fmt_by_code (u32 code )
128219{
129220 unsigned int i ;
@@ -220,6 +311,9 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
220311 reset_control_deassert (csi2rx -> p_rst );
221312 csi2rx_reset (csi2rx );
222313
314+ if (csi2rx -> error_irq >= 0 )
315+ csi2rx_configure_error_irq_mask (csi2rx -> base , csi2rx );
316+
223317 reg = csi2rx -> num_lanes << 8 ;
224318 for (i = 0 ; i < csi2rx -> num_lanes ; i ++ ) {
225319 reg |= CSI2RX_STATIC_CFG_DLANE_MAP (i , csi2rx -> lanes [i ]);
@@ -332,6 +426,8 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)
332426 reset_control_assert (csi2rx -> sys_rst );
333427 clk_disable_unprepare (csi2rx -> sys_clk );
334428
429+ writel (0 , csi2rx -> base + CSI2RX_ERROR_IRQS_MASK_REG );
430+
335431 for (i = 0 ; i < csi2rx -> max_streams ; i ++ ) {
336432 writel (CSI2RX_STREAM_CTRL_STOP ,
337433 csi2rx -> base + CSI2RX_STREAM_CTRL_REG (i ));
@@ -363,6 +459,21 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)
363459 }
364460}
365461
462+ static int csi2rx_log_status (struct v4l2_subdev * sd )
463+ {
464+ struct csi2rx_priv * csi2rx = v4l2_subdev_to_csi2rx (sd );
465+ unsigned int i ;
466+
467+ for (i = 0 ; i < CSI2RX_NUM_EVENTS ; i ++ ) {
468+ if (csi2rx -> events [i ])
469+ dev_info (csi2rx -> dev , "%s events: %d\n" ,
470+ csi2rx_events [i ].name ,
471+ csi2rx -> events [i ]);
472+ }
473+
474+ return 0 ;
475+ }
476+
366477static int csi2rx_s_stream (struct v4l2_subdev * subdev , int enable )
367478{
368479 struct csi2rx_priv * csi2rx = v4l2_subdev_to_csi2rx (subdev );
@@ -468,7 +579,12 @@ static const struct v4l2_subdev_video_ops csi2rx_video_ops = {
468579 .s_stream = csi2rx_s_stream ,
469580};
470581
582+ static const struct v4l2_subdev_core_ops csi2rx_core_ops = {
583+ .log_status = csi2rx_log_status ,
584+ };
585+
471586static const struct v4l2_subdev_ops csi2rx_subdev_ops = {
587+ .core = & csi2rx_core_ops ,
472588 .video = & csi2rx_video_ops ,
473589 .pad = & csi2rx_pad_ops ,
474590};
@@ -705,6 +821,21 @@ static int csi2rx_probe(struct platform_device *pdev)
705821 if (ret )
706822 goto err_cleanup ;
707823
824+ csi2rx -> error_irq = platform_get_irq_byname_optional (pdev , "error_irq" );
825+
826+ if (csi2rx -> error_irq < 0 ) {
827+ dev_dbg (csi2rx -> dev , "Optional interrupt not defined, proceeding without it\n" );
828+ } else {
829+ ret = devm_request_irq (csi2rx -> dev , csi2rx -> error_irq ,
830+ csi2rx_irq_handler , 0 ,
831+ dev_name (& pdev -> dev ), csi2rx );
832+ if (ret ) {
833+ dev_err (csi2rx -> dev ,
834+ "Unable to request interrupt: %d\n" , ret );
835+ goto err_cleanup ;
836+ }
837+ }
838+
708839 ret = v4l2_subdev_init_finalize (& csi2rx -> subdev );
709840 if (ret )
710841 goto err_cleanup ;
0 commit comments