Cannot unload OV5640 in iMX8 MQ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cannot unload OV5640 in iMX8 MQ?

1,799 Views
kaartic_sn
Contributor III

Hi,

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");
    }
    else
    {
        pr_info("before unregister subdev\n");
        v4l2_async_unregister_subdev(&csi2dev->sd);
        pr_info("after unregister subdev\n");

        pr_info("before notifier unregister\n");
        v4l2_async_notifier_unregister(&csi2dev->subdev_notifier);
        pr_info("after notifier unregister\n");

        pr_info("before v4l2 device unregister\n");
        v4l2_device_unregister(&csi2dev->v4l2_dev);
        pr_info("after v4l2 device unregister\n");
    }

    mipi_csi2_clk_disable(csi2dev);
    pm_runtime_disable(&pdev->dev);

    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.

0 Kudos
5 Replies

1,294 Views
rstabile
Contributor I

"We made the OV5640 and the related modules into loadable ones." 

I am trying to do the same thing.  What changes did you make to make the modules loadable?  Did you end up getting it to work?

0 Kudos

1,294 Views
jimmychan
NXP TechSupport
NXP TechSupport

Which BSP are you using?

0 Kudos

1,294 Views
kaartic_sn
Contributor III

We are using the latest BSP for the iMX 8M Quad EVK which is based on the kernel 4.14.78. It is identified as L4.14.78_1.0.0_MX8MQ in the website.

0 Kudos

1,294 Views
jimmychan
NXP TechSupport
NXP TechSupport

could you try to unregister the notifier

v4l2_async_notifier_unregister(&csi2dev->subdev_notifier);

before

v4l2_async_unregister_subdev(&csi2dev->sd);

Please let me know if it is work or not.

0 Kudos

1,294 Views
kaartic_sn
Contributor III

Hi jimmychan‌,

I've tried the order that you've suggested i.e., calling v4l2_async_notifier_unregister before v4l2_async_unregister_subdev. I do not face any crash now when unloading the mx6s_capture driver but I'm still unable to unload the camera driver as the usage count in the camera driver hasn't decreased yet. It still stays at 1.

0 Kudos