How to create v4l2 subdevice

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

How to create v4l2 subdevice

Jump to solution
8,376 Views
nikhil3karale
Contributor I

Hello all,

I working on interfacing own camera chip with iMX8M processor using linux kernel 4.14.78.

I have written the camera driver for chip and it probes successfully as a video subdevice.

In order to program the chip from the user application, i need to define some custom controls in my v4l2 sub-device driver As per the following link 1.7. V4L2 sub-devices — Linux Media Subsystem Documentation documentation  , subdevice must get created in /dev/ directory but in my case i am not able to generate the subdevice nodes

Does iMX platforms support v4l2 subdevice creation for the video device...?

Can anoyne help me to create v4l2 subdevice entry for my camera driver...?

Labels (1)
Tags (1)
0 Kudos
1 Solution
7,099 Views
krisztianbakos8
Contributor III

In the meantime I figured out that it does work with my 4.14 (and saw you are using the same kernel), so here is what needs to be done:

You initialize your subdevice with your subdev_ops pointer:

    v4l2_i2c_subdev_init(&sensor->subdev, client, &ar0330_subdev_ops);

Then you can fill up the _HAS_DEVNODE flag, which tells V4L2 that your device wishes to expose the /dev/v4l-subdevX:

    sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
    sensor->subdev.grp_id = 678;

And only then, you actually register your subdevice (so the _HAS_DEVNODE can take effect):

ret = v4l2_async_register_subdev(&sensor->subdev);

After this, if you are using the driver from NXP for MIPI (mxc-mipi-csi2_yav.c), then only after the first streaming command your device will register in the /dev/ folder, because in that driver, they don't have a callback to when the subdevice actually registers, so they have just put it in the s_stream callback (see v4l2_device_register_subdev_nodes()):

static int mipi_csi2_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct mxc_mipi_csi2_dev *csi2dev = sd_to_mxc_mipi_csi2_dev(sd);
    struct device *dev = &csi2dev->pdev->dev;
    struct v4l2_subdev *sensor_sd = csi2dev->sensor_sd;
    int ret = 0;

    
    dev_dbg(&csi2dev->pdev->dev, "%s: %d, csi2dev: 0x%x\n",
        __func__, enable, csi2dev->flags);

    if(csi2dev->registered == false)
    {
        csi2dev->registered = true;
        v4l2_info(&csi2dev->v4l2_dev, "Registering subdevice nodes");
        ret = v4l2_device_register_subdev_nodes(&csi2dev->v4l2_dev);
        if(ret < 0 ){
            v4l2_info(&csi2dev->v4l2_dev, "Error registering subdevice nodes");
            return -EINVAL;
        }
    }

Hope that helps.

View solution in original post

0 Kudos
8 Replies
7,099 Views
krisztianbakos8
Contributor III

Hello,

Are you still struggling with this? I noticed that with Kernel 4.9 I was able to create a subdevice, but when upgrading to 4.14, my driver stopped creating it for whatever reason.

Let me know which Kernel you are running, and I can post some snippets here from the working one on 4.9 and I will try to resolve the problem with the 4.14 today, hopefully I will be able to help you.

(as this forum is not entirely helpful at all times :smileyhappy: )

0 Kudos
7,100 Views
krisztianbakos8
Contributor III

In the meantime I figured out that it does work with my 4.14 (and saw you are using the same kernel), so here is what needs to be done:

You initialize your subdevice with your subdev_ops pointer:

    v4l2_i2c_subdev_init(&sensor->subdev, client, &ar0330_subdev_ops);

Then you can fill up the _HAS_DEVNODE flag, which tells V4L2 that your device wishes to expose the /dev/v4l-subdevX:

    sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
    sensor->subdev.grp_id = 678;

And only then, you actually register your subdevice (so the _HAS_DEVNODE can take effect):

ret = v4l2_async_register_subdev(&sensor->subdev);

After this, if you are using the driver from NXP for MIPI (mxc-mipi-csi2_yav.c), then only after the first streaming command your device will register in the /dev/ folder, because in that driver, they don't have a callback to when the subdevice actually registers, so they have just put it in the s_stream callback (see v4l2_device_register_subdev_nodes()):

static int mipi_csi2_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct mxc_mipi_csi2_dev *csi2dev = sd_to_mxc_mipi_csi2_dev(sd);
    struct device *dev = &csi2dev->pdev->dev;
    struct v4l2_subdev *sensor_sd = csi2dev->sensor_sd;
    int ret = 0;

    
    dev_dbg(&csi2dev->pdev->dev, "%s: %d, csi2dev: 0x%x\n",
        __func__, enable, csi2dev->flags);

    if(csi2dev->registered == false)
    {
        csi2dev->registered = true;
        v4l2_info(&csi2dev->v4l2_dev, "Registering subdevice nodes");
        ret = v4l2_device_register_subdev_nodes(&csi2dev->v4l2_dev);
        if(ret < 0 ){
            v4l2_info(&csi2dev->v4l2_dev, "Error registering subdevice nodes");
            return -EINVAL;
        }
    }

Hope that helps.

0 Kudos
5,175 Views
avijitnsec
Contributor III

I am trying to do the same. But having problem creating the device node. I am using the kernel 5.4.

I have integrated custom camera sensor, and trying to add ioctl calls and access it from user-space.

Got this in dmesg

CSI: Registered sensor subdevice: mxc_mipi-csi.0

Seems like the camera sensor sub-device is registered. I have added a ioctl, can you please tell me which device node I should access to call those IOCTLs? I see /dev/v4l-subdev0 is not being created.

0 Kudos
7,099 Views
igorpadykov
NXP Employee
NXP Employee

Hi Nikhil

yes sudev supported, for general steps for creating it for new sensor one can check

MIPI RAW12 Configuration for AR0330 on i.mx8mq 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
7,099 Views
nikhil3karale
Contributor I

Hello, i am not able to access the link.

pastedImage_1.png

0 Kudos
7,101 Views
igorpadykov
NXP Employee
NXP Employee

sorry correct link

iMX8M MIPI-CSI 4-lane configuration 

Best regards
igor

0 Kudos
7,101 Views
nikhil3karale
Contributor I

Thanks for the reply.

I went through the above link but i have not found information about creating v4l2 subdevices.

0 Kudos
7,101 Views
igorpadykov
NXP Employee
NXP Employee

unfortunately such documentation for creating v4l2 subdevices is not available.

If you have difficulities, NXP has special service for software porting

NXP Professional Services | NXP 

Best regards
igor

0 Kudos