Re: [PATCH v4 2/2] media: video-i2c: add video-i2c driver
On Wed, Feb 28, 2018 at 8:22 PM, kbuild test robot wrote: > Hi Matt, > > I love your patch! Perhaps something to improve: > > [auto build test WARNING on linuxtv-media/master] > [also build test WARNING on v4.16-rc3 next-20180228] > [if your patch is applied to the wrong git tree, please drop us a note to > help improve the system] > > url: > https://github.com/0day-ci/linux/commits/Matt-Ranostay/media-video-i2c-add-video-i2c-driver-support/20180301-111038 > base: git://linuxtv.org/media_tree.git master > config: ia64-allmodconfig (attached as .config) > compiler: ia64-linux-gcc (GCC) 7.2.0 > reproduce: > wget > https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O > ~/bin/make.cross > chmod +x ~/bin/make.cross > # save the attached .config to linux build tree > make.cross ARCH=ia64 > > All warnings (new ones prefixed by >>): > >drivers/media//i2c/video-i2c.c: In function 'video_i2c_probe': >>> drivers/media//i2c/video-i2c.c:456:13: warning: cast from pointer to >>> integer of different size [-Wpointer-to-int-cast] > chip_id = (int) of_device_get_match_data(&client->dev); Suspect this is some Itanium weirdness nobody cares about. > ^ > > vim +456 drivers/media//i2c/video-i2c.c > >442 >443 static int video_i2c_probe(struct i2c_client *client, >444 const struct i2c_device_id *id) >445 { >446 struct video_i2c_data *data; >447 struct v4l2_device *v4l2_dev; >448 struct vb2_queue *queue; >449 int chip_id, ret; >450 >451 data = kzalloc(sizeof(*data), GFP_KERNEL); >452 if (!data) >453 return -ENOMEM; >454 >455 if (client->dev.of_node) > > 456 chip_id = (int) > of_device_get_match_data(&client->dev); >457 else >458 chip_id = id->driver_data; >459 >460 data->chip = &video_i2c_chip[chip_id]; >461 data->client = client; >462 v4l2_dev = &data->v4l2_dev; >463 strlcpy(v4l2_dev->name, VIDEO_I2C_DRIVER, > sizeof(v4l2_dev->name)); >464 >465 ret = v4l2_device_register(&client->dev, v4l2_dev); >466 if (ret < 0) >467 goto error_free_device; >468 >469 mutex_init(&data->lock); >470 mutex_init(&data->queue_lock); >471 >472 queue = &data->vb_vidq; >473 queue->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; >474 queue->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR | > VB2_READ; >475 queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; >476 queue->drv_priv = data; >477 queue->buf_struct_size = sizeof(struct video_i2c_buffer); >478 queue->min_buffers_needed = 1; >479 queue->ops = &video_i2c_video_qops; >480 queue->mem_ops = &vb2_vmalloc_memops; >481 >482 ret = vb2_queue_init(queue); >483 if (ret < 0) >484 goto error_unregister_device; >485 >486 data->vdev.queue = queue; >487 data->vdev.queue->lock = &data->queue_lock; >488 >489 snprintf(data->vdev.name, sizeof(data->vdev.name), >490 "I2C %d-%d Transport Video", >491 client->adapter->nr, client->addr); >492 >493 data->vdev.v4l2_dev = v4l2_dev; >494 data->vdev.fops = &video_i2c_fops; >495 data->vdev.lock = &data->lock; >496 data->vdev.ioctl_ops = &video_i2c_ioctl_ops; >497 data->vdev.release = video_i2c_release; >498 data->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | >499 V4L2_CAP_READWRITE | > V4L2_CAP_STREAMING; >500 >501 spin_lock_init(&data->slock); >502 INIT_LIST_HEAD(&data->vid_cap_active); >503 >504 video_set_drvdata(&data->vdev, data); >505 i2c_set_clientdata(client, data); >506 >507 ret = video_register_device(&data->vdev, VFL_TYPE_GRABBER, > -1); >508 if (ret < 0) >509 goto error_unregister_device; >510 >511 return 0; >512 >513 error_unregister_device: >514 v4l2_device_unregister(v4l2_dev); >515 >516 error_free_device: >517 kfree(data); >518 >519 return ret; >520 } >521 > > --- > 0-DAY kernel test infrastructureOpen Source Technology Center > https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v4 2/2] media: video-i2c: add video-i2c driver
Hi Matt, I love your patch! Perhaps something to improve: [auto build test WARNING on linuxtv-media/master] [also build test WARNING on v4.16-rc3 next-20180228] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Matt-Ranostay/media-video-i2c-add-video-i2c-driver-support/20180301-111038 base: git://linuxtv.org/media_tree.git master config: ia64-allmodconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=ia64 All warnings (new ones prefixed by >>): drivers/media//i2c/video-i2c.c: In function 'video_i2c_probe': >> drivers/media//i2c/video-i2c.c:456:13: warning: cast from pointer to integer >> of different size [-Wpointer-to-int-cast] chip_id = (int) of_device_get_match_data(&client->dev); ^ vim +456 drivers/media//i2c/video-i2c.c 442 443 static int video_i2c_probe(struct i2c_client *client, 444 const struct i2c_device_id *id) 445 { 446 struct video_i2c_data *data; 447 struct v4l2_device *v4l2_dev; 448 struct vb2_queue *queue; 449 int chip_id, ret; 450 451 data = kzalloc(sizeof(*data), GFP_KERNEL); 452 if (!data) 453 return -ENOMEM; 454 455 if (client->dev.of_node) > 456 chip_id = (int) of_device_get_match_data(&client->dev); 457 else 458 chip_id = id->driver_data; 459 460 data->chip = &video_i2c_chip[chip_id]; 461 data->client = client; 462 v4l2_dev = &data->v4l2_dev; 463 strlcpy(v4l2_dev->name, VIDEO_I2C_DRIVER, sizeof(v4l2_dev->name)); 464 465 ret = v4l2_device_register(&client->dev, v4l2_dev); 466 if (ret < 0) 467 goto error_free_device; 468 469 mutex_init(&data->lock); 470 mutex_init(&data->queue_lock); 471 472 queue = &data->vb_vidq; 473 queue->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 474 queue->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR | VB2_READ; 475 queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 476 queue->drv_priv = data; 477 queue->buf_struct_size = sizeof(struct video_i2c_buffer); 478 queue->min_buffers_needed = 1; 479 queue->ops = &video_i2c_video_qops; 480 queue->mem_ops = &vb2_vmalloc_memops; 481 482 ret = vb2_queue_init(queue); 483 if (ret < 0) 484 goto error_unregister_device; 485 486 data->vdev.queue = queue; 487 data->vdev.queue->lock = &data->queue_lock; 488 489 snprintf(data->vdev.name, sizeof(data->vdev.name), 490 "I2C %d-%d Transport Video", 491 client->adapter->nr, client->addr); 492 493 data->vdev.v4l2_dev = v4l2_dev; 494 data->vdev.fops = &video_i2c_fops; 495 data->vdev.lock = &data->lock; 496 data->vdev.ioctl_ops = &video_i2c_ioctl_ops; 497 data->vdev.release = video_i2c_release; 498 data->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | 499 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 500 501 spin_lock_init(&data->slock); 502 INIT_LIST_HEAD(&data->vid_cap_active); 503 504 video_set_drvdata(&data->vdev, data); 505 i2c_set_clientdata(client, data); 506 507 ret = video_register_device(&data->vdev, VFL_TYPE_GRABBER, -1); 508 if (ret < 0) 509 goto error_unregister_device; 510 511 return 0; 512 513 error_unregister_device: 514 v4l2_device_unregister(v4l2_dev); 515 516 error_free_device: 517 kfree(data); 518 519 return ret; 520 } 521 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
[PATCH v4 2/2] media: video-i2c: add video-i2c driver
There are several thermal sensors that only have a low-speed bus interface but output valid video data. This patchset enables support for the AMG88xx "Grid-Eye" sensor family. Cc: Luca Barbato Cc: Laurent Pinchart Signed-off-by: Matt Ranostay --- MAINTAINERS | 6 + drivers/media/i2c/Kconfig | 9 + drivers/media/i2c/Makefile| 1 + drivers/media/i2c/video-i2c.c | 558 ++ 4 files changed, 574 insertions(+) create mode 100644 drivers/media/i2c/video-i2c.c diff --git a/MAINTAINERS b/MAINTAINERS index 8c2320e1685c..90ae81ae0e09 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14776,6 +14776,12 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/platform/video-mux.c +VIDEO I2C POLLING DRIVER +M: Matt Ranostay +L: linux-media@vger.kernel.org +S: Maintained +F: drivers/media/i2c/video-i2c.c + VIDEOBUF2 FRAMEWORK M: Pawel Osciak M: Marek Szyprowski diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 8fdd673d449f..53aede720e0f 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -917,6 +917,15 @@ config VIDEO_M52790 To compile this driver as a module, choose M here: the module will be called m52790. + +config VIDEO_I2C + tristate "I2C transport video support" + depends on VIDEO_V4L2 && I2C + select VIDEOBUF2_VMALLOC + ---help--- + Enable the I2C transport video support which supports the + following: + * Panasonic AMG88xx Grid-Eye Sensors endmenu menu "Sensors used on soc_camera driver" diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 26b19a2e9d04..5d4c06cb3f6f 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -91,6 +91,7 @@ obj-$(CONFIG_VIDEO_LM3646)+= lm3646.o obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o obj-$(CONFIG_VIDEO_AK881X) += ak881x.o obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o +obj-$(CONFIG_VIDEO_I2C)+= video-i2c.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o obj-$(CONFIG_VIDEO_OV2659) += ov2659.o obj-$(CONFIG_VIDEO_TC358743) += tc358743.o diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c new file mode 100644 index ..cd64fa80f55d --- /dev/null +++ b/drivers/media/i2c/video-i2c.c @@ -0,0 +1,558 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * video-i2c.c - Support for I2C transport video devices + * + * Copyright (C) 2018 Matt Ranostay + * + * Supported: + * - Panasonic AMG88xx Grid-Eye Sensors + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VIDEO_I2C_DRIVER "video-i2c" +#define MAX_BUFFER_SIZE128 + +struct video_i2c_chip; + +struct video_i2c_buffer { + struct vb2_v4l2_buffer vb; + struct list_head list; +}; + +struct video_i2c_data { + struct i2c_client *client; + const struct video_i2c_chip *chip; + struct mutex lock; + spinlock_t slock; + struct mutex queue_lock; + + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct vb2_queue vb_vidq; + + struct task_struct *kthread_vid_cap; + struct list_head vid_cap_active; +}; + +static struct v4l2_fmtdesc amg88xx_format = { + .pixelformat = V4L2_PIX_FMT_Y12, +}; + +static struct v4l2_frmsize_discrete amg88xx_size = { + .width = 8, + .height = 8, +}; + +struct video_i2c_chip { + /* video dimensions */ + const struct v4l2_fmtdesc *format; + const struct v4l2_frmsize_discrete *size; + + /* max frames per second */ + unsigned int max_fps; + + /* pixel buffer size */ + unsigned int buffer_size; + + /* pixel size in bits */ + unsigned int bpp; + + /* xfer function */ + int (*xfer)(struct video_i2c_data *data, char *buf); +}; + +static int amg88xx_xfer(struct video_i2c_data *data, char *buf) +{ + struct i2c_client *client = data->client; + struct i2c_msg msg[2]; + u8 reg = 0x80; + int ret; + + msg[0].addr = client->addr; + msg[0].flags = 0; + msg[0].len = 1; + msg[0].buf = (char *) ® + + msg[1].addr = client->addr; + msg[1].flags = I2C_M_RD; + msg[1].len = data->chip->buffer_size; + msg[1].buf = (char *) buf; + + ret = i2c_transfer(client->adapter, msg, 2); + + return (ret == 2) ? 0 : -EIO; +} + +#define AMG88XX0 + +static const struct video_i2c_chip video_i2c_chip[] = { + [AMG88XX] = { + .size = &amg88xx_size, + .format = &amg88xx_format, + .max_fps= 10, + .buffer_size= 128, + .bpp= 16, + .xfer = &am