Kernel hang on CSI OV5640 camera when cable unplugged during capture

Setup:

Apalis TK1 with r21.7 drivers
OV5640 CSI camera
Kernel 3.10

Problem:

After gstreamer capture command,

gst-launch-1.0 v4l2src device=/dev/video0 ! ‘video/x-raw,format={UYVY},width=640,height=480’ ! xvimagesink

kernel hangs if the the camera is unplugged during capture. The following error is displayed after vi2 driver enters the v2_capture_wait function, similar to https://devtalk.nvidia.com/default/topic/976606/jetson-tk1/kernel-hang-with-tc358840-hdmi-to-csi-2-bridge-on-tk1-when-data-stops/post/5023233/#5023233 .

[64.371464] vi vi.0: CSI_A syncpt timeout, syncpt = 576, err = -11
[   64.384395] TEGRA_CSI_CSI_CIL_A_STATUS 0x00000013
[   64.395241] TEGRA_CSI_CSI_CILA_STATUS 0x00070070
[   64.405176] TEGRA_CSI_CSI_CIL_B_STATUS 0x00000000
[   64.414045] TEGRA_CSI_CSI_CIL_C_STATUS 0x00000000
[   64.420547] TEGRA_CSI_CSI_CIL_D_STATUS 0x00000000
[   64.425401] TEGRA_CSI_CSI_CIL_E_STATUS 0x00000000
[   64.430663] TEGRA_CSI_CSI_PIXEL_PARSER_A_STATUS 0x00004000
[   64.436564] TEGRA_CSI_CSI_PIXEL_PARSER_B_STATUS 0x00000000
[   64.442303] TEGRA_VI_CSI_0_ERROR_STATUS 0x00000000
[   64.447296] TEGRA_VI_CSI_1_ERROR_STATUS 0x00000000
[   64.655574] vi vi.0: CSI_A syncpt timeout, syncpt = 578, err = -11
[   64.672086] TEGRA_CSI_CSI_CIL_A_STATUS 0x00000013
[   64.680539] TEGRA_CSI_CSI_CILA_STATUS 0x00070070
[   64.687340] TEGRA_CSI_CSI_CIL_B_STATUS 0x00000000
[   64.692352] TEGRA_CSI_CSI_CIL_C_STATUS 0x00000000
[   64.697798] TEGRA_CSI_CSI_CIL_D_STATUS 0x00000000
[   64.702613] TEGRA_CSI_CSI_CIL_E_STATUS 0x00000000
[   64.707714] TEGRA_CSI_CSI_PIXEL_PARSER_A_STATUS 0x00004080
[   64.713450] TEGRA_CSI_CSI_PIXEL_PARSER_B_STATUS 0x00000000
[   64.719011] TEGRA_VI_CSI_0_ERROR_STATUS 0x00000004
[   64.723916] TEGRA_VI_CSI_1_ERROR_STATUS 0x00000000
[   64.932991] vi vi.0: CSI_A syncpt timeout, syncpt = 580, err = -11

The problem seems to come from the access to TEGRA_CSI_CSI_CIL_A_STATUS register during vi2_capture_error_status function (https://devtalk.nvidia.com/default/topic/1015105/jetson-tk1/jetson-tk1-read-csi-status-registry-value-causes-kernel-freeze/) but don’t fully understand what the workaround is (modifying the tegra_camera_deactivate fundtion in common.c to skip all the deactivation proceedure?)

hello gmask,

may I know what’s your interface to connect a CSI camera to Tegra, is it through HDMI-CSI bridge?
thanks

Hello,

No, it is a direct MIPI/CSI-2 D-PHY interface (see https://developer.toradex.com/products/csi-camera-module-5mp-ov5640)

hello gmask,

this seems not a hot-plug device,
may I have more details about why you need to unplugged the camera device during system running?
thanks

Hello

Well, it certainly is not a hot plug device, but unplugging for any reason should not drive a system hang. Anyway, I fixed it now: http://git.toradex.com/cgit/linux-toradex.git/commit/?h=toradex_tk1_l4t_r21.7-next&id=6c533d394e9f65d1f2b1075a5169c8c33d623c9a