AnsweredAssumed Answered

Cannot unload OV5640 in iMX8 MQ?

Question asked by Kaartic Sivaraam Sankaranarayan on Mar 20, 2019
Latest reply on Mar 20, 2020 by Rod Stabile



We are using the OV5640 camera in the iMX 8MQ board. We made the OV5640 and the related modules into loadable ones. So, out lsmod output is:


root@imx8mqevk:~# lsmod
Module Size Used by
crc32_ce 16384 4
crct10dif_ce 16384 0
ov5640_camera_mipi_v2 28672 1
mx6s_capture 36864 0
mxc_mipi_csi2_yav 20480 2


To unload the OV5640 we did the following to correctly remove the dependent modules before removing it but we still get an error stating module is in use.


root@imx8mqevk:~# rmmod mx6s_capture
[  238.408492] mxc-mipi-csi2_yav 30b60000.mipi_csi2: mipi_csi2_probe
[  238.414950] mxc-mipi-csi2_yav 30b60000.mipi_csi: Remote device at /mipi_csi2@30b60000/port/endpoint1 XXX found
[  238.425212] mxc-mipi-csi2_yav 30b60000.mipi_csi2: lanes: 2, name: mxc-mipi-csi2.1
[  238.434838] mxc-mipi-csi2_yav 30a70000.mipi_csi1: mipi_csi2_probe
[  238.441288] mxc-mipi-csi2_yav 30a70000.mipi_csi: Remote device at /mipi_csi1@30a70000/port/endpoint1 XXX found
[  238.451419] mxc-mipi-csi2_yav 30a70000.mipi_csi1: lanes: 2, name: mxc-mipi-csi2.0
root@imx8mqevk:~# rmmod mxc_mipi_csi2_yav
root@imx8mqevk:~# rmmod ov5640_camera_mipi_v2
rmmod: ERROR: Module ov5640_camera_mipi_v2 is in use


On exploration we came to know that the platform driver mxc_mipi_csi2_yav did not unregister the subdev which it registered in it's probe. So, we changed the mxc_mipi_csi2_yav in mxc-mipi-csi2_yav.c as follows to correctly unregister the subdev:


static int mipi_csi2_remove(struct platform_device *pdev)
    struct v4l2_subdev *sd = platform_get_drvdata(pdev);
    struct mxc_mipi_csi2_dev *csi2dev = sd_to_mxc_mipi_csi2_dev(sd);

    if (csi2dev == NULL)
        pr_err("csi2dev is NULL\n");
        pr_info("before unregister subdev\n");
        pr_info("after unregister subdev\n");

        pr_info("before notifier unregister\n");
        pr_info("after notifier unregister\n");

        pr_info("before v4l2 device unregister\n");
        pr_info("after v4l2 device unregister\n");


    return 0;


After that we get a crash when unloading the mx6s_capture module. I have attached the crash log for reference. We would like to know why we couldn't correctly unregister the subdev? What should we do to make the OV5640 module unloadable? What are we missing?


Any help would be useful! Thanks in advance.