Re: [PATCH v8 10/10] Input: sur40 - use new V4L2 touch input type

2016-08-12 Thread Nick Dyer
Signed-off-by: Nick Dyer 

On 12 August 2016 10:41:08 BST, Hans Verkuil  wrote:
>Hi Nick,
>
>On 07/18/2016 11:10 PM, Nick Dyer wrote:
>> Support both V4L2_TCH_FMT_TU08 and V4L2_PIX_FMT_GREY for backwards
>> compatibility.
>> 
>> Note: I have not tested these changes (I have no access to the
>hardware)
>> so not signing off.
>
>I can't merge this without your Signed-off. The Signed-off has nothing
>to do with
>whether or not you have tested the code. I'm leaving this out of the
>pull request
>for now.
>
>Regards,
>
>   Hans
>
>> ---
>>  drivers/input/touchscreen/sur40.c |  122
>+++--
>>  1 file changed, 89 insertions(+), 33 deletions(-)
>> 
>> diff --git a/drivers/input/touchscreen/sur40.c
>b/drivers/input/touchscreen/sur40.c
>> index 4ea4757..fc275cb 100644
>> --- a/drivers/input/touchscreen/sur40.c
>> +++ b/drivers/input/touchscreen/sur40.c
>> @@ -139,6 +139,27 @@ struct sur40_image_header {
>>  #define SUR40_GET_STATE   0xc5 /*  4 bytes state (?) */
>>  #define SUR40_GET_SENSORS 0xb1 /*  8 bytes sensors   */
>>  
>> +static const struct v4l2_pix_format sur40_pix_format[] = {
>> +{
>> +.pixelformat = V4L2_TCH_FMT_TU08,
>> +.width  = SENSOR_RES_X / 2,
>> +.height = SENSOR_RES_Y / 2,
>> +.field = V4L2_FIELD_NONE,
>> +.colorspace = V4L2_COLORSPACE_SRGB,
>> +.bytesperline = SENSOR_RES_X / 2,
>> +.sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
>> +},
>> +{
>> +.pixelformat = V4L2_PIX_FMT_GREY,
>> +.width  = SENSOR_RES_X / 2,
>> +.height = SENSOR_RES_Y / 2,
>> +.field = V4L2_FIELD_NONE,
>> +.colorspace = V4L2_COLORSPACE_SRGB,
>> +.bytesperline = SENSOR_RES_X / 2,
>> +.sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
>> +}
>> +};
>> +
>>  /* master device state */
>>  struct sur40_state {
>>  
>> @@ -149,6 +170,7 @@ struct sur40_state {
>>  struct v4l2_device v4l2;
>>  struct video_device vdev;
>>  struct mutex lock;
>> +struct v4l2_pix_format pix_fmt;
>>  
>>  struct vb2_queue queue;
>>  struct list_head buf_list;
>> @@ -169,7 +191,6 @@ struct sur40_buffer {
>>  
>>  /* forward declarations */
>>  static const struct video_device sur40_video_device;
>> -static const struct v4l2_pix_format sur40_video_format;
>>  static const struct vb2_queue sur40_queue;
>>  static void sur40_process_video(struct sur40_state *sur40);
>>  
>> @@ -420,7 +441,7 @@ static void sur40_process_video(struct
>sur40_state *sur40)
>>  goto err_poll;
>>  }
>>  
>> -if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) {
>> +if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) {
>>  dev_err(sur40->dev, "image size mismatch\n");
>>  goto err_poll;
>>  }
>> @@ -431,7 +452,7 @@ static void sur40_process_video(struct
>sur40_state *sur40)
>>  
>>  result = usb_sg_init(, sur40->usbdev,
>>  usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
>> -sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0);
>> +sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0);
>>  if (result < 0) {
>>  dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
>>  goto err_poll;
>> @@ -586,13 +607,14 @@ static int sur40_probe(struct usb_interface
>*interface,
>>  if (error)
>>  goto err_unreg_v4l2;
>>  
>> +sur40->pix_fmt = sur40_pix_format[0];
>>  sur40->vdev = sur40_video_device;
>>  sur40->vdev.v4l2_dev = >v4l2;
>>  sur40->vdev.lock = >lock;
>>  sur40->vdev.queue = >queue;
>>  video_set_drvdata(>vdev, sur40);
>>  
>> -error = video_register_device(>vdev, VFL_TYPE_GRABBER, -1);
>> +error = video_register_device(>vdev, VFL_TYPE_TOUCH, -1);
>>  if (error) {
>>  dev_err(>dev,
>>  "Unable to register video subdevice.");
>> @@ -651,10 +673,10 @@ static int sur40_queue_setup(struct vb2_queue
>*q,
>>  *nbuffers = 3 - q->num_buffers;
>>  
>>  if (*nplanes)
>> -return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0;
>> +return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
>>  
>>  *nplanes = 1;
>> -sizes[0] = sur40_video_format.sizeimage;
>> +sizes[0] = sur40->pix_fmt.sizeimage;
>>  
>>  return 0;
>>  }
>> @@ -666,7 +688,7 @@ static int sur40_queue_setup(struct vb2_queue *q,
>>  static int sur40_buffer_prepare(struct vb2_buffer *vb)
>>  {
>>  struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
>> -unsigned long size = sur40_video_format.sizeimage;
>> +unsigned long size = sur40->pix_fmt.sizeimage;
>>  
>>  if (vb2_plane_size(vb, 0) < size) {
>>  dev_err(>usbdev->dev, "buffer too small (%lu < %lu)\n",
>> @@ -741,7 +763,7 @@ static int sur40_vidioc_querycap(struct file
>*file, void 

Re: [PATCH v8 10/10] Input: sur40 - use new V4L2 touch input type

2016-08-12 Thread Hans Verkuil
Hi Nick,

On 07/18/2016 11:10 PM, Nick Dyer wrote:
> Support both V4L2_TCH_FMT_TU08 and V4L2_PIX_FMT_GREY for backwards
> compatibility.
> 
> Note: I have not tested these changes (I have no access to the hardware)
> so not signing off.

I can't merge this without your Signed-off. The Signed-off has nothing to do 
with
whether or not you have tested the code. I'm leaving this out of the pull 
request
for now.

Regards,

Hans

> ---
>  drivers/input/touchscreen/sur40.c |  122 
> +++--
>  1 file changed, 89 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/sur40.c 
> b/drivers/input/touchscreen/sur40.c
> index 4ea4757..fc275cb 100644
> --- a/drivers/input/touchscreen/sur40.c
> +++ b/drivers/input/touchscreen/sur40.c
> @@ -139,6 +139,27 @@ struct sur40_image_header {
>  #define SUR40_GET_STATE   0xc5 /*  4 bytes state (?) */
>  #define SUR40_GET_SENSORS 0xb1 /*  8 bytes sensors   */
>  
> +static const struct v4l2_pix_format sur40_pix_format[] = {
> + {
> + .pixelformat = V4L2_TCH_FMT_TU08,
> + .width  = SENSOR_RES_X / 2,
> + .height = SENSOR_RES_Y / 2,
> + .field = V4L2_FIELD_NONE,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .bytesperline = SENSOR_RES_X / 2,
> + .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
> + },
> + {
> + .pixelformat = V4L2_PIX_FMT_GREY,
> + .width  = SENSOR_RES_X / 2,
> + .height = SENSOR_RES_Y / 2,
> + .field = V4L2_FIELD_NONE,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .bytesperline = SENSOR_RES_X / 2,
> + .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
> + }
> +};
> +
>  /* master device state */
>  struct sur40_state {
>  
> @@ -149,6 +170,7 @@ struct sur40_state {
>   struct v4l2_device v4l2;
>   struct video_device vdev;
>   struct mutex lock;
> + struct v4l2_pix_format pix_fmt;
>  
>   struct vb2_queue queue;
>   struct list_head buf_list;
> @@ -169,7 +191,6 @@ struct sur40_buffer {
>  
>  /* forward declarations */
>  static const struct video_device sur40_video_device;
> -static const struct v4l2_pix_format sur40_video_format;
>  static const struct vb2_queue sur40_queue;
>  static void sur40_process_video(struct sur40_state *sur40);
>  
> @@ -420,7 +441,7 @@ static void sur40_process_video(struct sur40_state *sur40)
>   goto err_poll;
>   }
>  
> - if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) {
> + if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) {
>   dev_err(sur40->dev, "image size mismatch\n");
>   goto err_poll;
>   }
> @@ -431,7 +452,7 @@ static void sur40_process_video(struct sur40_state *sur40)
>  
>   result = usb_sg_init(, sur40->usbdev,
>   usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
> - sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0);
> + sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0);
>   if (result < 0) {
>   dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
>   goto err_poll;
> @@ -586,13 +607,14 @@ static int sur40_probe(struct usb_interface *interface,
>   if (error)
>   goto err_unreg_v4l2;
>  
> + sur40->pix_fmt = sur40_pix_format[0];
>   sur40->vdev = sur40_video_device;
>   sur40->vdev.v4l2_dev = >v4l2;
>   sur40->vdev.lock = >lock;
>   sur40->vdev.queue = >queue;
>   video_set_drvdata(>vdev, sur40);
>  
> - error = video_register_device(>vdev, VFL_TYPE_GRABBER, -1);
> + error = video_register_device(>vdev, VFL_TYPE_TOUCH, -1);
>   if (error) {
>   dev_err(>dev,
>   "Unable to register video subdevice.");
> @@ -651,10 +673,10 @@ static int sur40_queue_setup(struct vb2_queue *q,
>   *nbuffers = 3 - q->num_buffers;
>  
>   if (*nplanes)
> - return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0;
> + return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
>  
>   *nplanes = 1;
> - sizes[0] = sur40_video_format.sizeimage;
> + sizes[0] = sur40->pix_fmt.sizeimage;
>  
>   return 0;
>  }
> @@ -666,7 +688,7 @@ static int sur40_queue_setup(struct vb2_queue *q,
>  static int sur40_buffer_prepare(struct vb2_buffer *vb)
>  {
>   struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
> - unsigned long size = sur40_video_format.sizeimage;
> + unsigned long size = sur40->pix_fmt.sizeimage;
>  
>   if (vb2_plane_size(vb, 0) < size) {
>   dev_err(>usbdev->dev, "buffer too small (%lu < %lu)\n",
> @@ -741,7 +763,7 @@ static int sur40_vidioc_querycap(struct file *file, void 
> *priv,
>   strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
>   strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card));
>   usb_make_path(sur40->usbdev, cap->bus_info, 

[PATCH v8 10/10] Input: sur40 - use new V4L2 touch input type

2016-07-18 Thread Nick Dyer
Support both V4L2_TCH_FMT_TU08 and V4L2_PIX_FMT_GREY for backwards
compatibility.

Note: I have not tested these changes (I have no access to the hardware)
so not signing off.
---
 drivers/input/touchscreen/sur40.c |  122 +++--
 1 file changed, 89 insertions(+), 33 deletions(-)

diff --git a/drivers/input/touchscreen/sur40.c 
b/drivers/input/touchscreen/sur40.c
index 4ea4757..fc275cb 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -139,6 +139,27 @@ struct sur40_image_header {
 #define SUR40_GET_STATE   0xc5 /*  4 bytes state (?) */
 #define SUR40_GET_SENSORS 0xb1 /*  8 bytes sensors   */
 
+static const struct v4l2_pix_format sur40_pix_format[] = {
+   {
+   .pixelformat = V4L2_TCH_FMT_TU08,
+   .width  = SENSOR_RES_X / 2,
+   .height = SENSOR_RES_Y / 2,
+   .field = V4L2_FIELD_NONE,
+   .colorspace = V4L2_COLORSPACE_SRGB,
+   .bytesperline = SENSOR_RES_X / 2,
+   .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
+   },
+   {
+   .pixelformat = V4L2_PIX_FMT_GREY,
+   .width  = SENSOR_RES_X / 2,
+   .height = SENSOR_RES_Y / 2,
+   .field = V4L2_FIELD_NONE,
+   .colorspace = V4L2_COLORSPACE_SRGB,
+   .bytesperline = SENSOR_RES_X / 2,
+   .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
+   }
+};
+
 /* master device state */
 struct sur40_state {
 
@@ -149,6 +170,7 @@ struct sur40_state {
struct v4l2_device v4l2;
struct video_device vdev;
struct mutex lock;
+   struct v4l2_pix_format pix_fmt;
 
struct vb2_queue queue;
struct list_head buf_list;
@@ -169,7 +191,6 @@ struct sur40_buffer {
 
 /* forward declarations */
 static const struct video_device sur40_video_device;
-static const struct v4l2_pix_format sur40_video_format;
 static const struct vb2_queue sur40_queue;
 static void sur40_process_video(struct sur40_state *sur40);
 
@@ -420,7 +441,7 @@ static void sur40_process_video(struct sur40_state *sur40)
goto err_poll;
}
 
-   if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) {
+   if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) {
dev_err(sur40->dev, "image size mismatch\n");
goto err_poll;
}
@@ -431,7 +452,7 @@ static void sur40_process_video(struct sur40_state *sur40)
 
result = usb_sg_init(, sur40->usbdev,
usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
-   sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0);
+   sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0);
if (result < 0) {
dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
goto err_poll;
@@ -586,13 +607,14 @@ static int sur40_probe(struct usb_interface *interface,
if (error)
goto err_unreg_v4l2;
 
+   sur40->pix_fmt = sur40_pix_format[0];
sur40->vdev = sur40_video_device;
sur40->vdev.v4l2_dev = >v4l2;
sur40->vdev.lock = >lock;
sur40->vdev.queue = >queue;
video_set_drvdata(>vdev, sur40);
 
-   error = video_register_device(>vdev, VFL_TYPE_GRABBER, -1);
+   error = video_register_device(>vdev, VFL_TYPE_TOUCH, -1);
if (error) {
dev_err(>dev,
"Unable to register video subdevice.");
@@ -651,10 +673,10 @@ static int sur40_queue_setup(struct vb2_queue *q,
*nbuffers = 3 - q->num_buffers;
 
if (*nplanes)
-   return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0;
+   return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
 
*nplanes = 1;
-   sizes[0] = sur40_video_format.sizeimage;
+   sizes[0] = sur40->pix_fmt.sizeimage;
 
return 0;
 }
@@ -666,7 +688,7 @@ static int sur40_queue_setup(struct vb2_queue *q,
 static int sur40_buffer_prepare(struct vb2_buffer *vb)
 {
struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
-   unsigned long size = sur40_video_format.sizeimage;
+   unsigned long size = sur40->pix_fmt.sizeimage;
 
if (vb2_plane_size(vb, 0) < size) {
dev_err(>usbdev->dev, "buffer too small (%lu < %lu)\n",
@@ -741,7 +763,7 @@ static int sur40_vidioc_querycap(struct file *file, void 
*priv,
strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card));
usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info));
-   cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
+   cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING;
cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -753,7 +775,7 @@ static int sur40_vidioc_enum_input(struct file *file,