Imx6 as UVC wbcam camera

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

Imx6 as UVC wbcam camera

Jump to solution
1,828 Views
Kanstantsin1
Contributor III

Hi there. 

I have found the article : 

https://developer.ridgerun.com/wiki/index.php/How_to_use_the_UVC_gadget_driver_in_Linux

And tried the second way to send video to PC through function uvc and the software: https://gitlab.freedesktop.org/camera/uvc-gadget

So device is detected as camera. But it doesn't send picture. At kernel log I see:

[ 78.763930] configfs-gadget gadget: uvc: Failed to queue request (-22).
[ 79.259922] ci_hdrc ci_hdrc.0: not page aligned sg buffer
[ 79.265343] configfs-gadget gadget: uvc: Failed to queue request (-22).
[ 79.776011] ci_hdrc ci_hdrc.0: not page aligned sg buffer
[ 79.781435] configfs-gadget gadget: uvc: Failed to queue request (-22).
[ 80.277839] ci_hdrc ci_hdrc.0: not page aligned sg buffer

Does anyone can help me?

0 Kudos
Reply
1 Solution
1,744 Views
marcomadrigal
Contributor III

Hi @Kanstantsin1 

 

Thanks for the additional information. I just noticed you are using a  quite new kernel, so there is something we can try out at least for testing purposes and find out what is going on

The kernel version you are using has added the scatter-gather (SG) support to UVC, this is quite a new addition to the UVC driver. However, SG is quite picky with the memory alignment and memory type you pass to the driver and it can easily complain about it. So let's first give it a try to the legacy memory transfer support (slower than SG) to check everything is working. There might be better ways to do it but since we are just testing, we can disable the SG support with the following patch in uvc_queue.c:

 

@@ -135,12 +135,7 @@ int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2
 	queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
 	queue->queue.ops = &uvc_queue_qops;
 	queue->queue.lock = lock;
-	if (cdev->gadget->sg_supported) {
-		queue->queue.mem_ops = &vb2_dma_sg_memops;
-		queue->use_sg = 1;
-	} else {
-		queue->queue.mem_ops = &vb2_vmalloc_memops;
-	}
+	queue->queue.mem_ops = &vb2_vmalloc_memops;
 
 	queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY
 				     | V4L2_BUF_FLAG_TSTAMP_SRC_EOF;

 

Best Regards,

Marco

www.ridgerun.com

View solution in original post

6 Replies
1,774 Views
Kanstantsin1
Contributor III

Hi, @marcomadrigal
Thank you for your reply.  Unfortunately, it seems to me problem lays at another way. 
But let's me describe what I know now.

1.  Yeah. https://github.com/wlhe/uvc-gadget. This application is simpler, but produces the same dmesg log (as I listed at topic).

2.  echo 0xffff > /sys/module/usb_f_uvc/parameters/trace - doesn't  show any interesting. (BTW: I have usb_f_uvc, but not uvcvideo. Can the problem lay here?).

So I was digging around the problem and found that it is stumbled at the line:

https://elixir.bootlin.com/linux/v5.15.32/source/drivers/usb/chipidea/udc.c#L518
It is checking for memory alignment. So memory can be mmaped but not  aligned....  It is strange.  I haven't found such checking(on aligment) at dw3

So I have quesetion.

It is something wrong with chipidea driver or may be my configuration spoiled so the request is not aligned? 

0 Kudos
Reply
1,745 Views
marcomadrigal
Contributor III

Hi @Kanstantsin1 

 

Thanks for the additional information. I just noticed you are using a  quite new kernel, so there is something we can try out at least for testing purposes and find out what is going on

The kernel version you are using has added the scatter-gather (SG) support to UVC, this is quite a new addition to the UVC driver. However, SG is quite picky with the memory alignment and memory type you pass to the driver and it can easily complain about it. So let's first give it a try to the legacy memory transfer support (slower than SG) to check everything is working. There might be better ways to do it but since we are just testing, we can disable the SG support with the following patch in uvc_queue.c:

 

@@ -135,12 +135,7 @@ int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2
 	queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
 	queue->queue.ops = &uvc_queue_qops;
 	queue->queue.lock = lock;
-	if (cdev->gadget->sg_supported) {
-		queue->queue.mem_ops = &vb2_dma_sg_memops;
-		queue->use_sg = 1;
-	} else {
-		queue->queue.mem_ops = &vb2_vmalloc_memops;
-	}
+	queue->queue.mem_ops = &vb2_vmalloc_memops;
 
 	queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY
 				     | V4L2_BUF_FLAG_TSTAMP_SRC_EOF;

 

Best Regards,

Marco

www.ridgerun.com

1,722 Views
Kanstantsin1
Contributor III

Thank you a lot, @marcomadrigal 
It works. 

0 Kudos
Reply
1,811 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

I think someone at @RidgeRun

Regards

0 Kudos
Reply
1,825 Views
Kanstantsin1
Contributor III

@marcomadrigal Hi. Have you seen such problem?

 

0 Kudos
Reply
1,813 Views
marcomadrigal
Contributor III

Hi,

Unfortunately I  haven't seen that error, however, we have not used that library either. I would recommend to first give it a try to this project: 

 

https://github.com/wlhe/uvc-gadget

 

You will notice it is much less complex, and yet it is functional. Since it is less complex it will be less error prone and you might have better chances to test functionality before moving to a more complex solution.

I am not yet suggesting any solution, but a way to get a better sense of what is going on.

Another hint would be to enable the host-side debug and check if you get any hints of what is going on:

 

sudo echo 0xffff > /sys/module/uvcvideo/parameters/trace

 

Also, make sure the format and resolutions you are trying to capture match with the ones registered by the device, you can check the device's reported formats with

lsusb -v -d <PID>:<VID>

 

Best Regards,

Marco

www.ridgerun.com

0 Kudos
Reply