Re: [PATCH v3] media: video-i2c: check if chip struct has set_power function

2018-11-26 Thread Matt Ranostay
On Mon, Nov 26, 2018 at 2:50 PM Hans Verkuil  wrote:
>
> On 11/25/2018 05:55 PM, Sakari Ailus wrote:
> > Hi Matt,
> >
> > On Sat, Nov 24, 2018 at 02:03:23PM -0800, Matt Ranostay wrote:
> >> Not all future supported video chips will always have power management
> >> support, and so it is important to check before calling set_power() is
> >> defined.
> >>
> >> Cc: Sakari Ailus 
> >> Cc: Hans Verkuil 
> >> Cc: Mauro Carvalho Chehab 
> >> Cc: Akinobu Mita 
> >> Signed-off-by: Matt Ranostay 
> >> ---
> >>
> >> Changes from v2:
> >> - split out from mlx90640 patch series
> >> - added to Cc list
> >>
> >> Changes from v1:
> >> - none
> >>
> >>  drivers/media/i2c/video-i2c.c | 22 +-
> >>  1 file changed, 17 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> >> index b6ebb8d53e90..01dcf179f203 100644
> >> --- a/drivers/media/i2c/video-i2c.c
> >> +++ b/drivers/media/i2c/video-i2c.c
> >> @@ -736,9 +736,11 @@ static int video_i2c_probe(struct i2c_client *client,
> >>  video_set_drvdata(>vdev, data);
> >>  i2c_set_clientdata(client, data);
> >>
> >> -ret = data->chip->set_power(data, true);
> >> -if (ret)
> >> -goto error_unregister_device;
> >> +if (data->chip->set_power) {
> >> +ret = data->chip->set_power(data, true);
> >> +if (ret)
> >> +goto error_unregister_device;
> >> +}
> >
> > How about adding a macro to call the op if it's set? It could be used to
> > call other ops when they're set, and ignore them when they're not. Just an
> > idea. See e.g. v4l2_subdev_call() in include/media/v4l2-subdev.h .
>
> Matt, is this something you want to do? If so, then I'll wait for a v4.
>

Probably wouldn't get around to doing it for a bit (on travel for the
next few weeks). If you could review/accept v3 for now that would be
great.

- Matt

> Regards,
>
> Hans
>
> >
> >>
> >>  pm_runtime_get_noresume(>dev);
> >>  pm_runtime_set_active(>dev);
> >> @@ -767,7 +769,9 @@ static int video_i2c_probe(struct i2c_client *client,
> >>  pm_runtime_disable(>dev);
> >>  pm_runtime_set_suspended(>dev);
> >>  pm_runtime_put_noidle(>dev);
> >> -data->chip->set_power(data, false);
> >> +
> >> +if (data->chip->set_power)
> >> +data->chip->set_power(data, false);
> >>
> >>  error_unregister_device:
> >>  v4l2_device_unregister(v4l2_dev);
> >> @@ -791,7 +795,9 @@ static int video_i2c_remove(struct i2c_client *client)
> >>  pm_runtime_disable(>dev);
> >>  pm_runtime_set_suspended(>dev);
> >>  pm_runtime_put_noidle(>dev);
> >> -data->chip->set_power(data, false);
> >> +
> >> +if (data->chip->set_power)
> >> +data->chip->set_power(data, false);
> >>
> >>  video_unregister_device(>vdev);
> >>
> >> @@ -804,6 +810,9 @@ static int video_i2c_pm_runtime_suspend(struct device 
> >> *dev)
> >>  {
> >>  struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
> >>
> >> +if (!data->chip->set_power)
> >> +return 0;
> >> +
> >>  return data->chip->set_power(data, false);
> >>  }
> >>
> >> @@ -811,6 +820,9 @@ static int video_i2c_pm_runtime_resume(struct device 
> >> *dev)
> >>  {
> >>  struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
> >>
> >> +if (!data->chip->set_power)
> >> +return 0;
> >> +
> >>  return data->chip->set_power(data, true);
> >>  }
> >>
> >> --
> >> 2.17.1
> >>
> >
>


[PATCH v3] media: video-i2c: check if chip struct has set_power function

2018-11-24 Thread Matt Ranostay
Not all future supported video chips will always have power management
support, and so it is important to check before calling set_power() is
defined.

Cc: Sakari Ailus 
Cc: Hans Verkuil 
Cc: Mauro Carvalho Chehab 
Cc: Akinobu Mita 
Signed-off-by: Matt Ranostay 
---

Changes from v2:
- split out from mlx90640 patch series
- added to Cc list

Changes from v1:
- none

 drivers/media/i2c/video-i2c.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index b6ebb8d53e90..01dcf179f203 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -736,9 +736,11 @@ static int video_i2c_probe(struct i2c_client *client,
video_set_drvdata(>vdev, data);
i2c_set_clientdata(client, data);
 
-   ret = data->chip->set_power(data, true);
-   if (ret)
-   goto error_unregister_device;
+   if (data->chip->set_power) {
+   ret = data->chip->set_power(data, true);
+   if (ret)
+   goto error_unregister_device;
+   }
 
pm_runtime_get_noresume(>dev);
pm_runtime_set_active(>dev);
@@ -767,7 +769,9 @@ static int video_i2c_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
 error_unregister_device:
v4l2_device_unregister(v4l2_dev);
@@ -791,7 +795,9 @@ static int video_i2c_remove(struct i2c_client *client)
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
video_unregister_device(>vdev);
 
@@ -804,6 +810,9 @@ static int video_i2c_pm_runtime_suspend(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, false);
 }
 
@@ -811,6 +820,9 @@ static int video_i2c_pm_runtime_resume(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, true);
 }
 
-- 
2.17.1



Re: [PATCH v2 2/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-22 Thread Matt Ranostay
On Thu, Nov 22, 2018 at 12:57 AM Hans Verkuil  wrote:
>
> On 11/22/2018 04:52 AM, Matt Ranostay wrote:
> > Add initial support for MLX90640 thermal cameras which output an 32x24
> > greyscale pixel image along with 2 rows of coefficent data.
> >
> > Because of this the data outputed is really 32x26 and needs the two rows
> > removed after using the coefficent information to generate processed
> > images in userspace.
> >
> > Cc: devicet...@vger.kernel.org
> > Signed-off-by: Matt Ranostay 
> > ---
> >  .../bindings/media/i2c/melexis,mlx90640.txt   |  20 
> >  drivers/media/i2c/Kconfig |   1 +
> >  drivers/media/i2c/video-i2c.c | 110 +-
> >  3 files changed, 130 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
> >
> > diff --git 
> > a/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt 
> > b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
> > new file mode 100644
> > index ..060d2b7a5893
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
> > @@ -0,0 +1,20 @@
> > +* Melexis MLX90640 FIR Sensor
> > +
> > +Melexis MLX90640 FIR sensor support which allows recording of thermal data
> > +with 32x24 resolution excluding 2 lines of coefficient data that is used by
> > +userspace to render processed frames.
>
> So this means that the image doesn't conform to V4L2_PIX_FMT_Y12!
>

The data for this sensor is V4L2_PIX_FMT_Y16BE not Y12

> I missed that the first time around.
>
> You have three options here:
>
> 1) Create a new V4L2_PIX_FMT define + documentation describing the format that
>this device produces.
>
> 2) Split off the image from the meta data and create a new META_CAPTURE device
>node. For the META device node you would again have to document the format
>
> 3) Split off the image from the meta data and store the meta data in a V4L2
>control, which again has to be documented.
>
> I'm leaning towards 1 since that's easiest to implement. But the key is that
> you should document those two lines. The datasheet is publicly available,
> so you can refer to it for details.
>

1 is mostly what I have now, excluding the documentation and new pixel format.

Although I have to say the META_CAPTURE options seems a bit more
clean, but doesn't seem
to be documented well.  So would it basically mux the pixel data, and
metadata with the same
timestamp?  Originally I looked at the VBI/closed caption to show the
metadata/frame-only data but that
was a way too low of a bandwidth (43-bytes a second IIRC).

> Those extra two lines return addresses 0x700-0x73f, right? Is it even 
> sufficient
> to calculate the relevant data from just those lines?

Yep that is the last 2 lines so 32x26 of reported data, but only 32x24
is pixel data.

> Looking at 11.2.2 there
> is a whole calculation that should be done that is also dependent on the 
> eeprom
> values, which are not exported.
>

You must have missed the nvmem part of the patchset.. :) The
respective eeprom values are exported to userspace using that.

> I wonder if it isn't the job of the driver to do all the calculations. It has
> all the information it needs and looking at the datasheet it seems all the
> calculations are integer based, so it shouldn't be too difficult. This would
> be a fourth option.

Well it isn't really all integer based.. sure the value from the frame
and eeprom are integers but the
coefficients you generate ( frame value divided by eeprom value )
usually produces a floating point value.

>
> BTW, did we document somewhere what the panasonic device returns? It returns
> Y12 data, but what does that data mean? In order to use this in userspace you
> need to be able to convert it to temperatures, so how is that done?

It is a signed 12-bit value with 0.25C resolution per LSB but doesn't
need any processing.

>
> Regards,
>
> Hans
>
> > +
> > +Required Properties:
> > + - compatible : Must be "melexis,mlx90640"
> > + - reg : i2c address of the device
> > +
> > +Example:
> > +
> > + i2c0@1c22000 {
> > + ...
> > + mlx90640@33 {
> > + compatible = "melexis,mlx90640";
> > + reg = <0x33>;
> > + };
> > + ...
> > + };


[PATCH v2 1/2] media: video-i2c: check if chip struct has set_power function

2018-11-21 Thread Matt Ranostay
Not all future supported video chips will always have power management
support, and so it is important to check before calling set_power() is
defined.

Signed-off-by: Matt Ranostay 
---
 drivers/media/i2c/video-i2c.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 981166010c9b..a64e1a725a20 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -736,9 +736,11 @@ static int video_i2c_probe(struct i2c_client *client,
video_set_drvdata(>vdev, data);
i2c_set_clientdata(client, data);
 
-   ret = data->chip->set_power(data, true);
-   if (ret)
-   goto error_unregister_device;
+   if (data->chip->set_power) {
+   ret = data->chip->set_power(data, true);
+   if (ret)
+   goto error_unregister_device;
+   }
 
pm_runtime_get_noresume(>dev);
pm_runtime_set_active(>dev);
@@ -767,7 +769,8 @@ static int video_i2c_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
 error_unregister_device:
v4l2_device_unregister(v4l2_dev);
@@ -791,7 +794,9 @@ static int video_i2c_remove(struct i2c_client *client)
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
video_unregister_device(>vdev);
 
@@ -804,6 +809,9 @@ static int video_i2c_pm_runtime_suspend(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, false);
 }
 
@@ -811,6 +819,9 @@ static int video_i2c_pm_runtime_resume(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, true);
 }
 
-- 
2.17.1



[PATCH v2 0/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-21 Thread Matt Ranostay
Add initial support for Melexis line of thermal cameras. This is the first part 
of
processing pipeline in which the real processing is done in userspace using the
V4L2 camera data.

Dependency patchset series: https://patchwork.kernel.org/cover/10650541/

Changes from v1:

* add melexis,mlx90640.txt documentation

Matt Ranostay (2):
  media: video-i2c: check if chip struct has set_power function
  media: video-i2c: add Melexis MLX90640 thermal camera support

 .../bindings/media/i2c/melexis,mlx90640.txt   |  20 +++
 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 131 +-
 3 files changed, 146 insertions(+), 6 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt

-- 
2.17.1



[PATCH v2 2/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-21 Thread Matt Ranostay
Add initial support for MLX90640 thermal cameras which output an 32x24
greyscale pixel image along with 2 rows of coefficent data.

Because of this the data outputed is really 32x26 and needs the two rows
removed after using the coefficent information to generate processed
images in userspace.

Cc: devicet...@vger.kernel.org
Signed-off-by: Matt Ranostay 
---
 .../bindings/media/i2c/melexis,mlx90640.txt   |  20 
 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 110 +-
 3 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt 
b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
new file mode 100644
index ..060d2b7a5893
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
@@ -0,0 +1,20 @@
+* Melexis MLX90640 FIR Sensor
+
+Melexis MLX90640 FIR sensor support which allows recording of thermal data
+with 32x24 resolution excluding 2 lines of coefficient data that is used by
+userspace to render processed frames.
+
+Required Properties:
+ - compatible : Must be "melexis,mlx90640"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   mlx90640@33 {
+   compatible = "melexis,mlx90640";
+   reg = <0x33>;
+   };
+   ...
+   };
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 66bbbec487ec..24342f283f2a 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -1097,6 +1097,7 @@ config VIDEO_I2C
  Enable the I2C transport video support which supports the
  following:
   * Panasonic AMG88xx Grid-Eye Sensors
+  * Melexis MLX90640 Thermal Cameras
 
  To compile this driver as a module, choose M here: the
  module will be called video-i2c
diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index a64e1a725a20..d58f40334e8b 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -6,6 +6,7 @@
  *
  * Supported:
  * - Panasonic AMG88xx Grid-Eye Sensors
+ * - Melexis MLX90640 Thermal Cameras
  */
 
 #include 
@@ -18,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,12 +68,26 @@ static const struct v4l2_frmsize_discrete amg88xx_size = {
.height = 8,
 };
 
+static const struct v4l2_fmtdesc mlx90640_format = {
+   .pixelformat = V4L2_PIX_FMT_Y16_BE,
+};
+
+static const struct v4l2_frmsize_discrete mlx90640_size = {
+   .width = 32,
+   .height = 26, /* 24 lines of pixel data + 2 lines of processing data */
+};
+
 static const struct regmap_config amg88xx_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff
 };
 
+static const struct regmap_config mlx90640_regmap_config = {
+   .reg_bits = 16,
+   .val_bits = 16,
+};
+
 struct video_i2c_chip {
/* video dimensions */
const struct v4l2_fmtdesc *format;
@@ -88,6 +104,7 @@ struct video_i2c_chip {
unsigned int bpp;
 
const struct regmap_config *regmap_config;
+   struct nvmem_config *nvmem_config;
 
/* setup function */
int (*setup)(struct video_i2c_data *data);
@@ -102,6 +119,22 @@ struct video_i2c_chip {
int (*hwmon_init)(struct video_i2c_data *data);
 };
 
+static int mlx90640_nvram_read(void *priv, unsigned int offset, void *val,
+size_t bytes)
+{
+   struct video_i2c_data *data = priv;
+
+   return regmap_bulk_read(data->regmap, 0x2400 + offset, val, bytes);
+}
+
+static struct nvmem_config mlx90640_nvram_config = {
+   .name = "mlx90640_nvram",
+   .word_size = 2,
+   .stride = 1,
+   .size = 1664,
+   .reg_read = mlx90640_nvram_read,
+};
+
 /* Power control register */
 #define AMG88XX_REG_PCTL   0x00
 #define AMG88XX_PCTL_NORMAL0x00
@@ -122,12 +155,23 @@ struct video_i2c_chip {
 /* Temperature register */
 #define AMG88XX_REG_T01L   0x80
 
+/* Control register */
+#define MLX90640_REG_CTL1  0x800d
+#define MLX90640_REG_CTL1_MASK 0x0380
+#define MLX90640_REG_CTL1_MASK_SHIFT   7
+
 static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
 {
return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
data->chip->buffer_size);
 }
 
+static int mlx90640_xfer(struct video_i2c_data *data, char *buf)
+{
+   return regmap_bulk_read(data->regmap, 0x400, buf,
+   data->chip->buffer_size);
+}
+
 static int amg88xx_setup(struct video_i2c_data *data)
 {
unsigned int mask = AMG88XX_FPSC_1FPS;
@@ -141,6 +185,27 @@ static int amg88xx_setup(struc

Re: [PATCH 2/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-19 Thread Matt Ranostay
On Mon, Nov 19, 2018 at 6:26 AM Hans Verkuil  wrote:
>
> On 11/01/2018 05:15 AM, Matt Ranostay wrote:
> > Add initial support for MLX90640 thermal cameras which output an 32x24
> > greyscale pixel image along with 2 rows of coefficent data.
> >
> > Because of this the data outputed is really 32x26 and needs the two rows
> > removed after using the coefficent information to generate processed
> > images in userspace.
> >
> > Signed-off-by: Matt Ranostay 
> > ---
> >  drivers/media/i2c/Kconfig |   1 +
> >  drivers/media/i2c/video-i2c.c | 110 +-
> >  2 files changed, 110 insertions(+), 1 deletion(-)
>
>
>
> >
> > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> > index 704af210e270..4bfb2c66d192 100644
> > --- a/drivers/media/i2c/Kconfig
> > +++ b/drivers/media/i2c/Kconfig
> > @@ -1085,6 +1085,7 @@ config VIDEO_I2C
> > Enable the I2C transport video support which supports the
> > following:
> >  * Panasonic AMG88xx Grid-Eye Sensors
> > +* Melexis MLX90640 Thermal Cameras
> >
> > To compile this driver as a module, choose M here: the
> > module will be called video-i2c
> > diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> > index 6d3b6df0b634..38ade8cb7656 100644
> > --- a/drivers/media/i2c/video-i2c.c
> > +++ b/drivers/media/i2c/video-i2c.c
> > @@ -6,6 +6,7 @@
> >   *
> >   * Supported:
> >   * - Panasonic AMG88xx Grid-Eye Sensors
> > + * - Melexis MLX90640 Thermal Cameras
> >   */
> >
> >  #include 
> > @@ -18,6 +19,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -66,12 +68,26 @@ static const struct v4l2_frmsize_discrete amg88xx_size 
> > = {
> >   .height = 8,
> >  };
> >
> > +static const struct v4l2_fmtdesc mlx90640_format = {
> > + .pixelformat = V4L2_PIX_FMT_Y16_BE,
> > +};
> > +
> > +static const struct v4l2_frmsize_discrete mlx90640_size = {
> > + .width = 32,
> > + .height = 26, /* 24 lines of pixel data + 2 lines of processing data 
> > */
> > +};
> > +
> >  static const struct regmap_config amg88xx_regmap_config = {
> >   .reg_bits = 8,
> >   .val_bits = 8,
> >   .max_register = 0xff
> >  };
> >
> > +static const struct regmap_config mlx90640_regmap_config = {
> > + .reg_bits = 16,
> > + .val_bits = 16,
> > +};
> > +
> >  struct video_i2c_chip {
> >   /* video dimensions */
> >   const struct v4l2_fmtdesc *format;
> > @@ -88,6 +104,7 @@ struct video_i2c_chip {
> >   unsigned int bpp;
> >
> >   const struct regmap_config *regmap_config;
> > + struct nvmem_config *nvmem_config;
> >
> >   /* setup function */
> >   int (*setup)(struct video_i2c_data *data);
> > @@ -102,6 +119,22 @@ struct video_i2c_chip {
> >   int (*hwmon_init)(struct video_i2c_data *data);
> >  };
> >
> > +static int mlx90640_nvram_read(void *priv, unsigned int offset, void *val,
> > +  size_t bytes)
> > +{
> > + struct video_i2c_data *data = priv;
> > +
> > + return regmap_bulk_read(data->regmap, 0x2400 + offset, val, bytes);
> > +}
> > +
> > +static struct nvmem_config mlx90640_nvram_config = {
> > + .name = "mlx90640_nvram",
> > + .word_size = 2,
> > + .stride = 1,
> > + .size = 1664,
> > + .reg_read = mlx90640_nvram_read,
> > +};
> > +
> >  /* Power control register */
> >  #define AMG88XX_REG_PCTL 0x00
> >  #define AMG88XX_PCTL_NORMAL  0x00
> > @@ -122,12 +155,23 @@ struct video_i2c_chip {
> >  /* Temperature register */
> >  #define AMG88XX_REG_T01L 0x80
> >
> > +/* Control register */
> > +#define MLX90640_REG_CTL10x800d
> > +#define MLX90640_REG_CTL1_MASK   0x0380
> > +#define MLX90640_REG_CTL1_MASK_SHIFT 7
> > +
> >  static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
> >  {
> >   return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
> >   data->chip->buffer_size);
> >  }
> >
> > +static int mlx90640_xfer(struct video_i2c_data *data, char *buf)
> > +{
> > + return regmap_bulk_read(data->regmap, 0x400, buf,
> > + data-&g

[PATCH 0/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-10-31 Thread Matt Ranostay
Add initial support for Melexis line of thermal cameras. This is the first part 
of
processing pipeline in which the real processing is done in userspace using the
V4L2 camera data.

Dependency patchset series: https://patchwork.kernel.org/cover/10650541/

Matt Ranostay (2):
  media: video-i2c: check if chip struct has set_power function
  media: video-i2c: add Melexis MLX90640 thermal camera support

 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 131 --
 2 files changed, 126 insertions(+), 6 deletions(-)

-- 
2.17.1



[PATCH 1/2] media: video-i2c: check if chip struct has set_power function

2018-10-31 Thread Matt Ranostay
Not all future supported video chips will always have power management
support, and so it is important to check before calling set_power() is
defined.

Signed-off-by: Matt Ranostay 
---
 drivers/media/i2c/video-i2c.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index cb5db5bdab12..6d3b6df0b634 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -736,9 +736,11 @@ static int video_i2c_probe(struct i2c_client *client,
video_set_drvdata(>vdev, data);
i2c_set_clientdata(client, data);
 
-   ret = data->chip->set_power(data, true);
-   if (ret)
-   goto error_unregister_device;
+   if (data->chip->set_power) {
+   ret = data->chip->set_power(data, true);
+   if (ret)
+   goto error_unregister_device;
+   }
 
pm_runtime_get_noresume(>dev);
pm_runtime_set_active(>dev);
@@ -767,7 +769,8 @@ static int video_i2c_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
 error_unregister_device:
v4l2_device_unregister(v4l2_dev);
@@ -791,7 +794,9 @@ static int video_i2c_remove(struct i2c_client *client)
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
video_unregister_device(>vdev);
 
@@ -804,6 +809,9 @@ static int video_i2c_pm_runtime_suspend(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, false);
 }
 
@@ -811,6 +819,9 @@ static int video_i2c_pm_runtime_resume(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, true);
 }
 
-- 
2.17.1



[PATCH 2/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-10-31 Thread Matt Ranostay
Add initial support for MLX90640 thermal cameras which output an 32x24
greyscale pixel image along with 2 rows of coefficent data.

Because of this the data outputed is really 32x26 and needs the two rows
removed after using the coefficent information to generate processed
images in userspace.

Signed-off-by: Matt Ranostay 
---
 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 110 +-
 2 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 704af210e270..4bfb2c66d192 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -1085,6 +1085,7 @@ config VIDEO_I2C
  Enable the I2C transport video support which supports the
  following:
   * Panasonic AMG88xx Grid-Eye Sensors
+  * Melexis MLX90640 Thermal Cameras
 
  To compile this driver as a module, choose M here: the
  module will be called video-i2c
diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 6d3b6df0b634..38ade8cb7656 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -6,6 +6,7 @@
  *
  * Supported:
  * - Panasonic AMG88xx Grid-Eye Sensors
+ * - Melexis MLX90640 Thermal Cameras
  */
 
 #include 
@@ -18,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,12 +68,26 @@ static const struct v4l2_frmsize_discrete amg88xx_size = {
.height = 8,
 };
 
+static const struct v4l2_fmtdesc mlx90640_format = {
+   .pixelformat = V4L2_PIX_FMT_Y16_BE,
+};
+
+static const struct v4l2_frmsize_discrete mlx90640_size = {
+   .width = 32,
+   .height = 26, /* 24 lines of pixel data + 2 lines of processing data */
+};
+
 static const struct regmap_config amg88xx_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff
 };
 
+static const struct regmap_config mlx90640_regmap_config = {
+   .reg_bits = 16,
+   .val_bits = 16,
+};
+
 struct video_i2c_chip {
/* video dimensions */
const struct v4l2_fmtdesc *format;
@@ -88,6 +104,7 @@ struct video_i2c_chip {
unsigned int bpp;
 
const struct regmap_config *regmap_config;
+   struct nvmem_config *nvmem_config;
 
/* setup function */
int (*setup)(struct video_i2c_data *data);
@@ -102,6 +119,22 @@ struct video_i2c_chip {
int (*hwmon_init)(struct video_i2c_data *data);
 };
 
+static int mlx90640_nvram_read(void *priv, unsigned int offset, void *val,
+size_t bytes)
+{
+   struct video_i2c_data *data = priv;
+
+   return regmap_bulk_read(data->regmap, 0x2400 + offset, val, bytes);
+}
+
+static struct nvmem_config mlx90640_nvram_config = {
+   .name = "mlx90640_nvram",
+   .word_size = 2,
+   .stride = 1,
+   .size = 1664,
+   .reg_read = mlx90640_nvram_read,
+};
+
 /* Power control register */
 #define AMG88XX_REG_PCTL   0x00
 #define AMG88XX_PCTL_NORMAL0x00
@@ -122,12 +155,23 @@ struct video_i2c_chip {
 /* Temperature register */
 #define AMG88XX_REG_T01L   0x80
 
+/* Control register */
+#define MLX90640_REG_CTL1  0x800d
+#define MLX90640_REG_CTL1_MASK 0x0380
+#define MLX90640_REG_CTL1_MASK_SHIFT   7
+
 static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
 {
return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
data->chip->buffer_size);
 }
 
+static int mlx90640_xfer(struct video_i2c_data *data, char *buf)
+{
+   return regmap_bulk_read(data->regmap, 0x400, buf,
+   data->chip->buffer_size);
+}
+
 static int amg88xx_setup(struct video_i2c_data *data)
 {
unsigned int mask = AMG88XX_FPSC_1FPS;
@@ -141,6 +185,27 @@ static int amg88xx_setup(struct video_i2c_data *data)
return regmap_update_bits(data->regmap, AMG88XX_REG_FPSC, mask, val);
 }
 
+static int mlx90640_setup(struct video_i2c_data *data)
+{
+   unsigned int n, idx;
+
+   for (n = 0; n < data->chip->num_frame_intervals - 1; n++) {
+   if (data->frame_interval.numerator
+   != data->chip->frame_intervals[n].numerator)
+   continue;
+
+   if (data->frame_interval.denominator
+   == data->chip->frame_intervals[n].denominator)
+   break;
+   }
+
+   idx = data->chip->num_frame_intervals - n - 1;
+
+   return regmap_update_bits(data->regmap, MLX90640_REG_CTL1,
+ MLX90640_REG_CTL1_MASK,
+ idx << MLX90640_REG_CTL1_MASK_SHIFT);
+}
+
 static int amg88xx_set_power_on(struct video_i2c_data *data)
 {
int ret;
@@ -274,13 +339,27 @@ static int amg88xx_hwmon_init(struct video_i2c_data *data)
 #define

Re: [PATCH v4 3/6] media: v4l2-common: add V4L2_FRACT_COMPARE

2018-10-28 Thread Matt Ranostay
On Sun, Oct 28, 2018 at 9:25 AM Akinobu Mita  wrote:
>
> 2018年10月28日(日) 12:49 Matt Ranostay :
> >
> > On Sat, Oct 20, 2018 at 7:26 AM Akinobu Mita  wrote:
> > >
> > > Add macro to compare two v4l2_fract values in v4l2 common internal API.
> > > The same macro FRACT_CMP() is used by vivid and bcm2835-camera.  This just
> > > renames it to V4L2_FRACT_COMPARE in order to avoid namespace collision.
> > >
> > > Cc: Matt Ranostay 
> > > Cc: Sakari Ailus 
> > > Cc: Hans Verkuil 
> > > Cc: Mauro Carvalho Chehab 
> > > Acked-by: Sakari Ailus 
> > > Signed-off-by: Akinobu Mita 
> > > ---
> > > * v4
> > > - No changes from v3
> > >
> > >  include/media/v4l2-common.h | 5 +
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> > > index cdc87ec..eafb8a3 100644
> > > --- a/include/media/v4l2-common.h
> > > +++ b/include/media/v4l2-common.h
> > > @@ -384,4 +384,9 @@ int v4l2_g_parm_cap(struct video_device *vdev,
> > >  int v4l2_s_parm_cap(struct video_device *vdev,
> > > struct v4l2_subdev *sd, struct v4l2_streamparm *a);
> > >
> > > +/* Compare two v4l2_fract structs */
> > > +#define V4L2_FRACT_COMPARE(a, OP, b)   \
> > > +   ((u64)(a).numerator * (b).denominator OP\
> > > +   (u64)(b).numerator * (a).denominator)
> > > +
> >
> > Noticed a few issues today when testing another thermal camera that
> > can do 0.5 fps to 64 fps with this macro..
>
> I expect your new thermal camera's frame_intervals will be something
> like below.
>
> static const struct v4l2_fract frame_intervals[] = {
> { 1, 64 },  /* 64 fps */
> { 1, 4 },   /* 4 fps */
> { 1, 2 },   /* 2 fps */
> { 2, 1 },   /* 0.5 fps */
> };
>
> > 1) This can have collision easily when numerator and denominators
> > multiplied have the same product, example is 0.5hz and 2hz have the
> > same output as 2
>
> I think V4L2_FRACT_COMPARE() can correctly compare with 0.5hz and 2hz.
>
> V4L2_FRACT_COMPARE({ 1, 2 }, <=, { 2, 1 }); // -->  true
> V4L2_FRACT_COMPARE({ 2, 1 }, <=, { 1, 2 }); //-->  false
>
> > 2) Also this doesn't reduce fractions so I am seeing 400 compared
> > with 4 for instance with a 4hz frame interval.
>
> I think this works fine, too.
>
> V4L2_FRACT_COMPARE({ 1, 400 }, <=, { 1, 4 }); //-->  true
> V4L2_FRACT_COMPARE({ 1, 4 }, <=, { 1, 400 }); //-->  false
>
> Or, do I misunderstand your problem?

Probably not! I didn't think of them having to be sorted in a certain
way, but will test and probably will work.

Couldn't hurt to have that noted in a comment some where as well.

- Matt


Re: [PATCH v4 3/6] media: v4l2-common: add V4L2_FRACT_COMPARE

2018-10-27 Thread Matt Ranostay
On Sat, Oct 20, 2018 at 7:26 AM Akinobu Mita  wrote:
>
> Add macro to compare two v4l2_fract values in v4l2 common internal API.
> The same macro FRACT_CMP() is used by vivid and bcm2835-camera.  This just
> renames it to V4L2_FRACT_COMPARE in order to avoid namespace collision.
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Acked-by: Sakari Ailus 
> Signed-off-by: Akinobu Mita 
> ---
> * v4
> - No changes from v3
>
>  include/media/v4l2-common.h | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> index cdc87ec..eafb8a3 100644
> --- a/include/media/v4l2-common.h
> +++ b/include/media/v4l2-common.h
> @@ -384,4 +384,9 @@ int v4l2_g_parm_cap(struct video_device *vdev,
>  int v4l2_s_parm_cap(struct video_device *vdev,
> struct v4l2_subdev *sd, struct v4l2_streamparm *a);
>
> +/* Compare two v4l2_fract structs */
> +#define V4L2_FRACT_COMPARE(a, OP, b)   \
> +   ((u64)(a).numerator * (b).denominator OP\
> +   (u64)(b).numerator * (a).denominator)
> +

Noticed a few issues today when testing another thermal camera that
can do 0.5 fps to 64 fps with this macro..

1) This can have collision easily when numerator and denominators
multiplied have the same product, example is 0.5hz and 2hz have the
same output as 2

2) Also this doesn't reduce fractions so I am seeing 400 compared
with 4 for instance with a 4hz frame interval.

- Matt



>  #endif /* V4L2_COMMON_H_ */
> --
> 2.7.4
>


Re: [PATCH v4 5/6] media: video-i2c: support changing frame interval

2018-10-27 Thread Matt Ranostay
On Sat, Oct 20, 2018 at 7:26 AM Akinobu Mita  wrote:
>
> AMG88xx has a register for setting frame rate 1 or 10 FPS.
> This adds support changing frame interval.
>
> Reference specifications:
> https://docid81hrs3j1.cloudfront.net/medialibrary/2017/11/PANA-S-A0002141979-1.pdf
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Acked-by: Matt Ranostay 
> Acked-by: Sakari Ailus 
> Signed-off-by: Akinobu Mita 
> ---
> * v4
> - No changes from v3
>
>  drivers/media/i2c/video-i2c.c | 78 
> ---
>  1 file changed, 66 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index f23cb91..3334fc2 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -52,6 +52,8 @@ struct video_i2c_data {
>
> struct task_struct *kthread_vid_cap;
> struct list_head vid_cap_active;
> +
> +   struct v4l2_fract frame_interval;
>  };
>
>  static const struct v4l2_fmtdesc amg88xx_format = {
> @@ -74,8 +76,9 @@ struct video_i2c_chip {
> const struct v4l2_fmtdesc *format;
> const struct v4l2_frmsize_discrete *size;
>
> -   /* max frames per second */
> -   unsigned int max_fps;
> +   /* available frame intervals */
> +   const struct v4l2_fract *frame_intervals;
> +   unsigned int num_frame_intervals;
>
> /* pixel buffer size */
> unsigned int buffer_size;
> @@ -85,6 +88,9 @@ struct video_i2c_chip {
>
> const struct regmap_config *regmap_config;
>
> +   /* setup function */
> +   int (*setup)(struct video_i2c_data *data);
> +
> /* xfer function */
> int (*xfer)(struct video_i2c_data *data, char *buf);
>
> @@ -92,6 +98,10 @@ struct video_i2c_chip {
> int (*hwmon_init)(struct video_i2c_data *data);
>  };
>
> +/* Frame rate register */
> +#define AMG88XX_REG_FPSC   0x02
> +#define AMG88XX_FPSC_1FPS  BIT(0)
> +
>  /* Thermistor register */
>  #define AMG88XX_REG_TTHL   0x0e
>
> @@ -104,6 +114,19 @@ static int amg88xx_xfer(struct video_i2c_data *data, 
> char *buf)
> data->chip->buffer_size);
>  }
>
> +static int amg88xx_setup(struct video_i2c_data *data)
> +{
> +   unsigned int mask = AMG88XX_FPSC_1FPS;
> +   unsigned int val;
> +
> +   if (data->frame_interval.numerator == 
> data->frame_interval.denominator)
> +   val = mask;
> +   else
> +   val = 0;
> +
> +   return regmap_update_bits(data->regmap, AMG88XX_REG_FPSC, mask, val);
> +}
> +
>  #if IS_ENABLED(CONFIG_HWMON)
>
>  static const u32 amg88xx_temp_config[] = {
> @@ -178,14 +201,21 @@ static int amg88xx_hwmon_init(struct video_i2c_data 
> *data)
>
>  #define AMG88XX0
>
> +static const struct v4l2_fract amg88xx_frame_intervals[] = {
> +   { 1, 10 },
> +   { 1, 1 },
> +};
> +
>  static const struct video_i2c_chip video_i2c_chip[] = {
> [AMG88XX] = {
> .size   = _size,
> .format = _format,
> -   .max_fps= 10,
> +   .frame_intervals= amg88xx_frame_intervals,
> +   .num_frame_intervals= ARRAY_SIZE(amg88xx_frame_intervals),
> .buffer_size= 128,
> .bpp= 16,
> .regmap_config  = _regmap_config,
> +   .setup  = _setup,
> .xfer   = _xfer,
> .hwmon_init = amg88xx_hwmon_init,
> },
> @@ -250,7 +280,8 @@ static void buffer_queue(struct vb2_buffer *vb)
>  static int video_i2c_thread_vid_cap(void *priv)
>  {
> struct video_i2c_data *data = priv;
> -   unsigned int delay = msecs_to_jiffies(1000 / data->chip->max_fps);
> +   unsigned int delay = mult_frac(HZ, data->frame_interval.numerator,
> +  data->frame_interval.denominator);
>
> set_freezable();
>
> @@ -312,19 +343,26 @@ static void video_i2c_del_list(struct vb2_queue *vq, 
> enum vb2_buffer_state state
>  static int start_streaming(struct vb2_queue *vq, unsigned int count)
>  {
> struct video_i2c_data *data = vb2_get_drv_priv(vq);
> +   int ret;
>
> if (data->kthread_vid_cap)
> return 0;
>
> +   ret = data->chip->setup(data);
> +   if (ret)
> +   goto error_del_list;
> +
> data->sequence = 0;
> data->kthread_vid_cap = kth

Re: [PATCH v3 1/6] media: video-i2c: avoid accessing released memory area when removing driver

2018-10-13 Thread Matt Ranostay
On Sat, Oct 13, 2018 at 11:02 AM Akinobu Mita  wrote:
>
> The video device release() callback for video-i2c driver frees the whole
> struct video_i2c_data.  If there is no user left for the video device
> when video_unregister_device() is called, the release callback is executed.
>
> However, in video_i2c_remove() some fields (v4l2_dev, lock, and queue_lock)
> in struct video_i2c_data are still accessed after video_unregister_device()
> is called.
>
> This fixes the use after free by moving the code from video_i2c_remove()
> to the release() callback.
>
> Fixes: 5cebaac60974 ("media: video-i2c: add video-i2c driver")
> Cc: Matt Ranostay 

Reviewed-by: Matt Ranostay 

> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 
> ---
> * v3
> - Move the code causing use-after-free from video_i2c_remove() to the
>   video device release() callback.
> - Remove Acked-by line as there are enough changes from previous version
>
>  drivers/media/i2c/video-i2c.c | 11 ++-
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index 06d29d8..f27d294 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -510,7 +510,12 @@ static const struct v4l2_ioctl_ops video_i2c_ioctl_ops = 
> {
>
>  static void video_i2c_release(struct video_device *vdev)
>  {
> -   kfree(video_get_drvdata(vdev));
> +   struct video_i2c_data *data = video_get_drvdata(vdev);
> +
> +   v4l2_device_unregister(>v4l2_dev);
> +   mutex_destroy(>lock);
> +   mutex_destroy(>queue_lock);
> +   kfree(data);
>  }
>
>  static int video_i2c_probe(struct i2c_client *client,
> @@ -608,10 +613,6 @@ static int video_i2c_remove(struct i2c_client *client)
> struct video_i2c_data *data = i2c_get_clientdata(client);
>
> video_unregister_device(>vdev);
> -   v4l2_device_unregister(>v4l2_dev);
> -
> -   mutex_destroy(>lock);
> -   mutex_destroy(>queue_lock);
>
> return 0;
>  }
> --
> 2.7.4
>


Re: [PATCH v2 2/6] media: video-i2c: use i2c regmap

2018-09-23 Thread Matt Ranostay
On Mon, Sep 24, 2018 at 12:35 AM Akinobu Mita  wrote:
>
> Use regmap for i2c register access.  This simplifies register accesses and
> chooses suitable access commands based on the functionality that the
> adapter supports.
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 

Acked-by: Matt Ranostay 

> ---
> * v2
> - Add thermistor and termperature register address definisions
>
>  drivers/media/i2c/video-i2c.c | 60 
> ---
>  1 file changed, 34 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index b7a2af9..fb8509e 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -17,6 +17,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -38,7 +39,7 @@ struct video_i2c_buffer {
>  };
>
>  struct video_i2c_data {
> -   struct i2c_client *client;
> +   struct regmap *regmap;
> const struct video_i2c_chip *chip;
> struct mutex lock;
> spinlock_t slock;
> @@ -62,6 +63,12 @@ static const struct v4l2_frmsize_discrete amg88xx_size = {
> .height = 8,
>  };
>
> +static const struct regmap_config amg88xx_regmap_config = {
> +   .reg_bits = 8,
> +   .val_bits = 8,
> +   .max_register = 0xff
> +};
> +
>  struct video_i2c_chip {
> /* video dimensions */
> const struct v4l2_fmtdesc *format;
> @@ -76,6 +83,8 @@ struct video_i2c_chip {
> /* pixel size in bits */
> unsigned int bpp;
>
> +   const struct regmap_config *regmap_config;
> +
> /* xfer function */
> int (*xfer)(struct video_i2c_data *data, char *buf);
>
> @@ -83,26 +92,16 @@ struct video_i2c_chip {
> int (*hwmon_init)(struct video_i2c_data *data);
>  };
>
> -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;
> +/* Thermistor register */
> +#define AMG88XX_REG_TTHL   0x0e
>
> -   ret = i2c_transfer(client->adapter, msg, 2);
> +/* Temperature register */
> +#define AMG88XX_REG_T01L   0x80
>
> -   return (ret == 2) ? 0 : -EIO;
> +static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
> +{
> +   return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
> +   data->chip->buffer_size);
>  }
>
>  #if IS_ENABLED(CONFIG_HWMON)
> @@ -133,12 +132,15 @@ static int amg88xx_read(struct device *dev, enum 
> hwmon_sensor_types type,
> u32 attr, int channel, long *val)
>  {
> struct video_i2c_data *data = dev_get_drvdata(dev);
> -   struct i2c_client *client = data->client;
> -   int tmp = i2c_smbus_read_word_data(client, 0x0e);
> +   __le16 buf;
> +   int tmp;
>
> -   if (tmp < 0)
> +   tmp = regmap_bulk_read(data->regmap, AMG88XX_REG_TTHL, , 2);
> +   if (tmp)
> return tmp;
>
> +   tmp = le16_to_cpu(buf);
> +
> /*
>  * Check for sign bit, this isn't a two's complement value but an
>  * absolute temperature that needs to be inverted in the case of being
> @@ -164,8 +166,9 @@ static const struct hwmon_chip_info amg88xx_chip_info = {
>
>  static int amg88xx_hwmon_init(struct video_i2c_data *data)
>  {
> -   void *hwmon = devm_hwmon_device_register_with_info(>client->dev,
> -   "amg88xx", data, _chip_info, NULL);
> +   struct device *dev = regmap_get_device(data->regmap);
> +   void *hwmon = devm_hwmon_device_register_with_info(dev, "amg88xx", 
> data,
> +   _chip_info, NULL);
>
> return PTR_ERR_OR_ZERO(hwmon);
>  }
> @@ -182,6 +185,7 @@ static const struct video_i2c_chip video_i2c_chip[] = {
> .max_fps= 10,
> .buffer_size= 128,
> .bpp= 16,
> +   .regmap_config  = _regmap_config,
> .xfer   = _xfer,
> .hwmon_init = amg88xx_hwmon_init,
> 

Re: [PATCH 4/5] media: video-i2c: support changing frame interval

2018-09-18 Thread Matt Ranostay
On Mon, Sep 17, 2018 at 6:03 PM Akinobu Mita  wrote:
>
> AMG88xx has a register for setting frame rate 1 or 10 FPS.
> This adds support changing frame interval.
>
> Reference specifications:
> https://docid81hrs3j1.cloudfront.net/medialibrary/2017/11/PANA-S-A0002141979-1.pdf
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 

Acked-by: Matt Ranostay 

> ---
>  drivers/media/i2c/video-i2c.c | 76 
> ---
>  1 file changed, 64 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index 90d389b..916f36e 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -52,6 +52,8 @@ struct video_i2c_data {
>
> struct task_struct *kthread_vid_cap;
> struct list_head vid_cap_active;
> +
> +   struct v4l2_fract frame_interval;
>  };
>
>  static const struct v4l2_fmtdesc amg88xx_format = {
> @@ -74,8 +76,9 @@ struct video_i2c_chip {
> const struct v4l2_fmtdesc *format;
> const struct v4l2_frmsize_discrete *size;
>
> -   /* max frames per second */
> -   unsigned int max_fps;
> +   /* available frame intervals */
> +   const struct v4l2_fract *frame_intervals;
> +   unsigned int num_frame_intervals;
>
> /* pixel buffer size */
> unsigned int buffer_size;
> @@ -85,6 +88,9 @@ struct video_i2c_chip {
>
> const struct regmap_config *regmap_config;
>
> +   /* setup function */
> +   int (*setup)(struct video_i2c_data *data);
> +
> /* xfer function */
> int (*xfer)(struct video_i2c_data *data, char *buf);
>
> @@ -98,6 +104,22 @@ static int amg88xx_xfer(struct video_i2c_data *data, char 
> *buf)
> data->chip->buffer_size);
>  }
>
> +#define AMG88XX_REG_FPSC   0x02
> +#define AMG88XX_FPSC_1FPS  BIT(0)
> +
> +static int amg88xx_setup(struct video_i2c_data *data)
> +{
> +   unsigned int mask = AMG88XX_FPSC_1FPS;
> +   unsigned int val;
> +
> +   if (data->frame_interval.numerator == 
> data->frame_interval.denominator)
> +   val = mask;
> +   else
> +   val = 0;
> +
> +   return regmap_update_bits(data->regmap, AMG88XX_REG_FPSC, mask, val);
> +}
> +
>  #if IS_ENABLED(CONFIG_HWMON)
>
>  static const u32 amg88xx_temp_config[] = {
> @@ -172,14 +194,21 @@ static int amg88xx_hwmon_init(struct video_i2c_data 
> *data)
>
>  #define AMG88XX0
>
> +static const struct v4l2_fract amg88xx_frame_intervals[] = {
> +   { 1, 10 },
> +   { 1, 1 },
> +};
> +
>  static const struct video_i2c_chip video_i2c_chip[] = {
> [AMG88XX] = {
> .size   = _size,
> .format = _format,
> -   .max_fps= 10,
> +   .frame_intervals= amg88xx_frame_intervals,
> +   .num_frame_intervals= ARRAY_SIZE(amg88xx_frame_intervals),
> .buffer_size= 128,
> .bpp= 16,
> .regmap_config  = _regmap_config,
> +   .setup  = _setup,
> .xfer   = _xfer,
> .hwmon_init = amg88xx_hwmon_init,
> },
> @@ -244,7 +273,8 @@ static void buffer_queue(struct vb2_buffer *vb)
>  static int video_i2c_thread_vid_cap(void *priv)
>  {
> struct video_i2c_data *data = priv;
> -   unsigned int delay = msecs_to_jiffies(1000 / data->chip->max_fps);
> +   unsigned int delay = mult_frac(HZ, data->frame_interval.numerator,
> +  data->frame_interval.denominator);
>
> set_freezable();
>
> @@ -306,19 +336,26 @@ static void video_i2c_del_list(struct vb2_queue *vq, 
> enum vb2_buffer_state state
>  static int start_streaming(struct vb2_queue *vq, unsigned int count)
>  {
> struct video_i2c_data *data = vb2_get_drv_priv(vq);
> +   int ret;
>
> if (data->kthread_vid_cap)
> return 0;
>
> +   ret = data->chip->setup(data);
> +   if (ret)
> +   goto error_del_list;
> +
> data->sequence = 0;
> data->kthread_vid_cap = kthread_run(video_i2c_thread_vid_cap, data,
> "%s-vid-cap", 
> data->v4l2_dev.name);
> -   if (!IS_ERR(data->kthread_vid_cap))
> +   ret = PTR_ERR_OR_ZERO(data->kthread_vid_cap);
> +   if (!ret)
>   

Re: [PATCH 5/5] media: video-i2c: support runtime PM

2018-09-18 Thread Matt Ranostay
On Mon, Sep 17, 2018 at 6:03 PM Akinobu Mita  wrote:
>
> AMG88xx has a register for setting operating mode.  This adds support
> runtime PM by changing the operating mode.
>
> The instruction for changing sleep mode to normal mode is from the
> reference specifications.
>
> https://docid81hrs3j1.cloudfront.net/medialibrary/2017/11/PANA-S-A0002141979-1.pdf
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 
> ---
>  drivers/media/i2c/video-i2c.c | 140 
> +-
>  1 file changed, 138 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index 916f36e..93822f4 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -17,6 +17,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -94,6 +95,9 @@ struct video_i2c_chip {
> /* xfer function */
> int (*xfer)(struct video_i2c_data *data, char *buf);
>
> +   /* power control function */
> +   int (*set_power)(struct video_i2c_data *data, bool on);
> +
> /* hwmon init function */
> int (*hwmon_init)(struct video_i2c_data *data);
>  };
> @@ -104,6 +108,14 @@ static int amg88xx_xfer(struct video_i2c_data *data, 
> char *buf)
> data->chip->buffer_size);
>  }
>
> +#define AMG88XX_REG_PCTL   0x00
> +#define AMG88XX_PCTL_NORMAL0x00
> +#define AMG88XX_PCTL_SLEEP 0x10
> +
> +#define AMG88XX_REG_RST0x01
> +#define AMG88XX_RST_FLAG   0x30
> +#define AMG88XX_RST_INIT   0x3f
> +
>  #define AMG88XX_REG_FPSC   0x02
>  #define AMG88XX_FPSC_1FPS  BIT(0)
>
> @@ -120,6 +132,59 @@ static int amg88xx_setup(struct video_i2c_data *data)
> return regmap_update_bits(data->regmap, AMG88XX_REG_FPSC, mask, val);
>  }
>
> +static int amg88xx_set_power_on(struct video_i2c_data *data)
> +{
> +   int ret;
> +
> +   ret = regmap_write(data->regmap, AMG88XX_REG_PCTL, 
> AMG88XX_PCTL_NORMAL);
> +   if (ret)
> +   return ret;
> +
> +   msleep(50);
> +
> +   ret = regmap_write(data->regmap, AMG88XX_REG_RST, AMG88XX_RST_INIT);
> +   if (ret)
> +   return ret;
> +
> +   msleep(2);
> +
> +   ret = regmap_write(data->regmap, AMG88XX_REG_RST, AMG88XX_RST_FLAG);
> +   if (ret)
> +   return ret;
> +
> +   /*
> +* Wait two frames before reading thermistor and temperature registers
> +*/
> +   msleep(200);
> +
> +   return 0;
> +}
> +
> +static int amg88xx_set_power_off(struct video_i2c_data *data)
> +{
> +   int ret;
> +
> +   ret = regmap_write(data->regmap, AMG88XX_REG_PCTL, 
> AMG88XX_PCTL_SLEEP);
> +   if (ret)
> +   return ret;
> +   /*
> +* Wait for a while to avoid resuming normal mode immediately after
> +* entering sleep mode, otherwise the device occasionally goes wrong
> +* (thermistor and temperature registers are not updated at all)
> +*/
> +   msleep(100);
> +
> +   return 0;
> +}
> +
> +static int amg88xx_set_power(struct video_i2c_data *data, bool on)
> +{
> +   if (on)
> +   return amg88xx_set_power_on(data);
> +
> +   return amg88xx_set_power_off(data);
> +}
> +
>  #if IS_ENABLED(CONFIG_HWMON)
>
>  static const u32 amg88xx_temp_config[] = {
> @@ -151,7 +216,15 @@ static int amg88xx_read(struct device *dev, enum 
> hwmon_sensor_types type,
> __le16 buf;
> int tmp;
>
> +   tmp = pm_runtime_get_sync(regmap_get_device(data->regmap));
> +   if (tmp < 0) {
> +   pm_runtime_put_noidle(regmap_get_device(data->regmap));
> +   return tmp;
> +   }
> +
> tmp = regmap_bulk_read(data->regmap, 0x0e, , 2);
> +   pm_runtime_mark_last_busy(regmap_get_device(data->regmap));
> +   pm_runtime_put_autosuspend(regmap_get_device(data->regmap));
> if (tmp)
> return tmp;
>
> @@ -210,6 +283,7 @@ static const struct video_i2c_chip video_i2c_chip[] = {
> .regmap_config  = _regmap_config,
> .setup  = _setup,
> .xfer   = _xfer,
> +   .set_power  = amg88xx_set_power,
> .hwmon_init = amg88xx_hwmon_init,
> },
>  };
> @@ -336,14 +410,21 @@ static void

Re: [PATCH 2/5] media: video-i2c: use i2c regmap

2018-09-17 Thread Matt Ranostay
On Mon, Sep 17, 2018 at 9:03 AM Akinobu Mita  wrote:
>
> Use regmap for i2c register access.  This simplifies register accesses and
> chooses suitable access commands based on the functionality that the
> adapter supports.
>
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 
> ---
>  drivers/media/i2c/video-i2c.c | 54 
> ++-
>  1 file changed, 28 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index b7a2af9..90d389b 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -17,6 +17,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -38,7 +39,7 @@ struct video_i2c_buffer {
>  };
>
>  struct video_i2c_data {
> -   struct i2c_client *client;
> +   struct regmap *regmap;
> const struct video_i2c_chip *chip;
> struct mutex lock;
> spinlock_t slock;
> @@ -62,6 +63,12 @@ static const struct v4l2_frmsize_discrete amg88xx_size = {
> .height = 8,
>  };
>
> +static const struct regmap_config amg88xx_regmap_config = {
> +   .reg_bits = 8,
> +   .val_bits = 8,
> +   .max_register = 0xff
> +};
> +
>  struct video_i2c_chip {
> /* video dimensions */
> const struct v4l2_fmtdesc *format;
> @@ -76,6 +83,8 @@ struct video_i2c_chip {
> /* pixel size in bits */
> unsigned int bpp;
>
> +   const struct regmap_config *regmap_config;
> +
> /* xfer function */
> int (*xfer)(struct video_i2c_data *data, char *buf);
>
> @@ -85,24 +94,8 @@ struct video_i2c_chip {
>
>  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;
> +   return regmap_bulk_read(data->regmap, 0x80, buf,
> +   data->chip->buffer_size);

May as well make 0x80 into a AMG88XX_REG_* define as in the later
patch in this series

>  }
>
>  #if IS_ENABLED(CONFIG_HWMON)
> @@ -133,12 +126,15 @@ static int amg88xx_read(struct device *dev, enum 
> hwmon_sensor_types type,
> u32 attr, int channel, long *val)
>  {
> struct video_i2c_data *data = dev_get_drvdata(dev);
> -   struct i2c_client *client = data->client;
> -   int tmp = i2c_smbus_read_word_data(client, 0x0e);
> +   __le16 buf;
> +   int tmp;
>
> -   if (tmp < 0)
> +   tmp = regmap_bulk_read(data->regmap, 0x0e, , 2);

Same with 0x0e

- Matt

> +   if (tmp)
> return tmp;
>
> +   tmp = le16_to_cpu(buf);
> +
> /*
>  * Check for sign bit, this isn't a two's complement value but an
>  * absolute temperature that needs to be inverted in the case of being
> @@ -164,8 +160,9 @@ static const struct hwmon_chip_info amg88xx_chip_info = {
>
>  static int amg88xx_hwmon_init(struct video_i2c_data *data)
>  {
> -   void *hwmon = devm_hwmon_device_register_with_info(>client->dev,
> -   "amg88xx", data, _chip_info, NULL);
> +   struct device *dev = regmap_get_device(data->regmap);
> +   void *hwmon = devm_hwmon_device_register_with_info(dev, "amg88xx", 
> data,
> +   _chip_info, NULL);
>
> return PTR_ERR_OR_ZERO(hwmon);
>  }
> @@ -182,6 +179,7 @@ static const struct video_i2c_chip video_i2c_chip[] = {
> .max_fps= 10,
> .buffer_size= 128,
> .bpp= 16,
> +   .regmap_config  = _regmap_config,
> .xfer   = _xfer,
> .hwmon_init = amg88xx_hwmon_init,
> },
> @@ -350,7 +348,8 @@ static int video_i2c_querycap(struct file *file, void  
> *priv,
> struct v4l2_capability *vcap)
>  {
> struct video_i2c_data *data = video_drvdata(file);
> -   struct i2c_client *client = data->client;
> +   struct device *dev 

Re: [PATCH 1/5] media: video-i2c: avoid accessing released memory area when removing driver

2018-09-17 Thread Matt Ranostay
On Mon, Sep 17, 2018 at 9:03 AM Akinobu Mita  wrote:
>
> The struct video_i2c_data is released when video_unregister_device() is
> called, but it will still be accessed after calling
> video_unregister_device().
>
> Use devm_kzalloc() and let the memory be automatically released on driver
> detach.
>
> Fixes: 5cebaac60974 ("media: video-i2c: add video-i2c driver")
> Cc: Matt Ranostay 
> Cc: Sakari Ailus 
> Cc: Hans Verkuil 
> Cc: Mauro Carvalho Chehab 
> Signed-off-by: Akinobu Mita 

Acked-by: Matt Ranostay 

> ---
>  drivers/media/i2c/video-i2c.c | 18 +-
>  1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
> index 06d29d8..b7a2af9 100644
> --- a/drivers/media/i2c/video-i2c.c
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -508,20 +508,15 @@ static const struct v4l2_ioctl_ops video_i2c_ioctl_ops 
> = {
> .vidioc_streamoff   = vb2_ioctl_streamoff,
>  };
>
> -static void video_i2c_release(struct video_device *vdev)
> -{
> -   kfree(video_get_drvdata(vdev));
> -}
> -
>  static int video_i2c_probe(struct i2c_client *client,
>  const struct i2c_device_id *id)
>  {
> struct video_i2c_data *data;
> struct v4l2_device *v4l2_dev;
> struct vb2_queue *queue;
> -   int ret = -ENODEV;
> +   int ret;
>
> -   data = kzalloc(sizeof(*data), GFP_KERNEL);
> +   data = devm_kzalloc(>dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> @@ -530,7 +525,7 @@ static int video_i2c_probe(struct i2c_client *client,
> else if (id)
> data->chip = _i2c_chip[id->driver_data];
> else
> -   goto error_free_device;
> +   return -ENODEV;
>
> data->client = client;
> v4l2_dev = >v4l2_dev;
> @@ -538,7 +533,7 @@ static int video_i2c_probe(struct i2c_client *client,
>
> ret = v4l2_device_register(>dev, v4l2_dev);
> if (ret < 0)
> -   goto error_free_device;
> +   return ret;
>
> mutex_init(>lock);
> mutex_init(>queue_lock);
> @@ -568,7 +563,7 @@ static int video_i2c_probe(struct i2c_client *client,
> data->vdev.fops = _i2c_fops;
> data->vdev.lock = >lock;
> data->vdev.ioctl_ops = _i2c_ioctl_ops;
> -   data->vdev.release = video_i2c_release;
> +   data->vdev.release = video_device_release_empty;
> data->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE |
>  V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
>
> @@ -597,9 +592,6 @@ static int video_i2c_probe(struct i2c_client *client,
> mutex_destroy(>lock);
> mutex_destroy(>queue_lock);
>
> -error_free_device:
> -   kfree(data);
> -
> return ret;
>  }
>
> --
> 2.7.4
>


[PATCH] media: video-i2c: hwmon: fix return value from amg88xx_hwmon_init()

2018-07-26 Thread Matt Ranostay
PTR_ERR was making any pointer passed an error pointer, and should be
replaced with PTR_ERR_OR_ZERO which checks if is an actual error condition.

Signed-off-by: Matt Ranostay 
---
 drivers/media/i2c/video-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 7dc9338502e5..06d29d8f6be8 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -167,7 +167,7 @@ static int amg88xx_hwmon_init(struct video_i2c_data *data)
void *hwmon = devm_hwmon_device_register_with_info(>client->dev,
"amg88xx", data, _chip_info, NULL);
 
-   return PTR_ERR(hwmon);
+   return PTR_ERR_OR_ZERO(hwmon);
 }
 #else
 #defineamg88xx_hwmon_init  NULL
-- 
2.17.1



Re: [RFC] media: thermal I2C cameras metadata

2018-07-25 Thread Matt Ranostay
On Wed, Jul 25, 2018 at 2:09 AM, Sakari Ailus  wrote:
> On Tue, Jul 24, 2018 at 11:05:47PM -0700, Matt Ranostay wrote:
>> On Mon, Jul 23, 2018 at 4:35 AM, Sakari Ailus  wrote:
>> > Hi Matt,
>> >
>> > On Sun, Jul 15, 2018 at 11:05:42PM -0700, Matt Ranostay wrote:
>> >> Hello et all,
>> >>
>> >> So currently working with some thermal sensors that have coefficients
>> >> that needs to be passed back to userspace that aren't related to the
>> >> pixel data but are required to normalize to remove scan patterns and
>> >> temp gradients. Was wondering the best way to do this, and hope it
>> >> isn't some is kludge of the close captioning, or just passing raw data
>> >> as another column line.
>> >
>> > Are you referring to the EEPROM content or something else?
>> >
>> > For EEPROM, I could think of just exposing the EEPROM to the user space
>> > as-is using the NVMEM API. This information is very, very device specific
>> > and therefore using a generic interface to access individual values there
>> > isn't really useful.
>> >
>>
>> Actually that is okay for the EEPROM data that is per sensor, and
>> nvram does seem like it would work.
>> But there is per video frame data that is required along with the
>> static EEPROM data to calculate the actual end result.
>
> Could you point out what that might be on the datasheet?

Datasheet: 
https://www.melexis.com/-/media/files/documents/datasheets/mlx90640-datasheet-melexis.pdf

On page 18 it documents that 0x700-0x73f  are required for the various
userspace calculations along with the other static EEPROM data.

>
> --
> Sakari Ailus
> e-mail: sakari.ai...@iki.fi


Re: [RFC] media: thermal I2C cameras metadata

2018-07-25 Thread Matt Ranostay
On Mon, Jul 23, 2018 at 4:35 AM, Sakari Ailus  wrote:
> Hi Matt,
>
> On Sun, Jul 15, 2018 at 11:05:42PM -0700, Matt Ranostay wrote:
>> Hello et all,
>>
>> So currently working with some thermal sensors that have coefficients
>> that needs to be passed back to userspace that aren't related to the
>> pixel data but are required to normalize to remove scan patterns and
>> temp gradients. Was wondering the best way to do this, and hope it
>> isn't some is kludge of the close captioning, or just passing raw data
>> as another column line.
>
> Are you referring to the EEPROM content or something else?
>
> For EEPROM, I could think of just exposing the EEPROM to the user space
> as-is using the NVMEM API. This information is very, very device specific
> and therefore using a generic interface to access individual values there
> isn't really useful.
>

Actually that is okay for the EEPROM data that is per sensor, and
nvram does seem like it would work.
But there is per video frame data that is required along with the
static EEPROM data to calculate the actual end result.

- Matt

> --
> Sakari Ailus
> e-mail: sakari.ai...@iki.fi


[RFC] media: thermal I2C cameras metadata

2018-07-16 Thread Matt Ranostay
Hello et all,

So currently working with some thermal sensors that have coefficients
that needs to be passed back to userspace that aren't related to the
pixel data but are required to normalize to remove scan patterns and
temp gradients. Was wondering the best way to do this, and hope it
isn't some is kludge of the close captioning, or just passing raw data
as another column line.

Datasheet: 
https://www.melexis.com/en/product/MLX90640/Far-Infrared-Thermal-Sensor-Array

Thanks,

Matt


Re: [PATCH v8 2/2] media: video-i2c: add video-i2c driver

2018-04-18 Thread Matt Ranostay
On Wed, Apr 18, 2018 at 1:03 AM, Sakari Ailus <sakari.ai...@iki.fi> wrote:
> Hi Matt,
>
> Thanks for the update.
>
> On Fri, Apr 06, 2018 at 03:52:31PM -0700, Matt Ranostay wrote:
>> 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.
>>
>> Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
>> ---
>>  MAINTAINERS   |   6 +
>>  drivers/media/i2c/Kconfig |  13 +
>>  drivers/media/i2c/Makefile|   1 +
>>  drivers/media/i2c/video-i2c.c | 563 
>> ++
>>  4 files changed, 583 insertions(+)
>>  create mode 100644 drivers/media/i2c/video-i2c.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index dc153da22e8a..928b6a862626 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -14880,6 +14880,12 @@ L:   linux-media@vger.kernel.org
>>  S:   Maintained
>>  F:   drivers/media/platform/video-mux.c
>>
>> +VIDEO I2C POLLING DRIVER
>> +M:   Matt Ranostay <matt.ranos...@konsulko.com>
>> +L:   linux-media@vger.kernel.org
>> +S:   Maintained
>> +F:   drivers/media/i2c/video-i2c.c
>> +
>>  VIDEOBUF2 FRAMEWORK
>>  M:   Pawel Osciak <pa...@osciak.com>
>>  M:   Marek Szyprowski <m.szyprow...@samsung.com>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 541f0d28afd8..faaaceb94832 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -974,6 +974,19 @@ 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
>> +
>> +   To compile this driver as a module, choose M here: the
>> +   module will be called video-i2c
>> +
>>  endmenu
>>
>>  menu "Sensors used on soc_camera driver"
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index ea34aee1a85a..84cc472238ef 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -96,6 +96,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 ..ec8a597597bf
>> --- /dev/null
>> +++ b/drivers/media/i2c/video-i2c.c
>> @@ -0,0 +1,563 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * video-i2c.c - Support for I2C transport video devices
>> + *
>> + * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
>> + *
>> + * 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"
>> +
>> +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;
>> + unsigned int sequence;
>> + 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;
>> +};
>> +
>> +const stati

Re: [PATCH v8 2/2] media: video-i2c: add video-i2c driver

2018-04-18 Thread Matt Ranostay
Slight poke on this since the merge window craziness should be over
also I stupidly forgot to CC people who had comments in the last
revision. *grin*

- Matt

On Fri, Apr 6, 2018 at 3:52 PM, Matt Ranostay
<matt.ranos...@konsulko.com> wrote:
> 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.
>
> Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
> ---
>  MAINTAINERS   |   6 +
>  drivers/media/i2c/Kconfig |  13 +
>  drivers/media/i2c/Makefile|   1 +
>  drivers/media/i2c/video-i2c.c | 563 
> ++
>  4 files changed, 583 insertions(+)
>  create mode 100644 drivers/media/i2c/video-i2c.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index dc153da22e8a..928b6a862626 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -14880,6 +14880,12 @@ L: linux-media@vger.kernel.org
>  S: Maintained
>  F: drivers/media/platform/video-mux.c
>
> +VIDEO I2C POLLING DRIVER
> +M: Matt Ranostay <matt.ranos...@konsulko.com>
> +L: linux-media@vger.kernel.org
> +S: Maintained
> +F: drivers/media/i2c/video-i2c.c
> +
>  VIDEOBUF2 FRAMEWORK
>  M: Pawel Osciak <pa...@osciak.com>
>  M: Marek Szyprowski <m.szyprow...@samsung.com>
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index 541f0d28afd8..faaaceb94832 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -974,6 +974,19 @@ 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
> +
> + To compile this driver as a module, choose M here: the
> + module will be called video-i2c
> +
>  endmenu
>
>  menu "Sensors used on soc_camera driver"
> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
> index ea34aee1a85a..84cc472238ef 100644
> --- a/drivers/media/i2c/Makefile
> +++ b/drivers/media/i2c/Makefile
> @@ -96,6 +96,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 ..ec8a597597bf
> --- /dev/null
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -0,0 +1,563 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * video-i2c.c - Support for I2C transport video devices
> + *
> + * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
> + *
> + * 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"
> +
> +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;
> +   unsigned int sequence;
> +   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;
> +};
> +
> +const static struct v4l2_fmtdesc amg88xx_format = {
> +   .pixelformat = V4L2_PIX_FMT_Y12,
> +};
> +
> +const 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

[PATCH v8 0/2] media: video-i2c: add video-i2c driver support

2018-04-06 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Changes from v4:
* convert pointer from of_device_get_match_data() to long instead of int to 
avoid compiler warning

Changes from v5:
* fix various issues with v4l2-compliance tool run

Changes from v6:
* fixed minor coding issues on spacing
* changed device tree table pointers to chip struct data
* add more verbose Kconfig documentation
* destroy mutexes on error path and module removal
* fixed MODULE_LICENSE from GPL to GPLv2
* changes some calls to list_last_entry() to avoid touching next pointer
* moved common code to a function from start/stop_streaming()

Changes from v7:
* add const to several structs
* corrected a few over 80 column lines 
* change DT check to generic dev_fwnode() call

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |  13 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 563 +
 5 files changed, 602 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



[PATCH v8 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-04-06 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: devicet...@vger.kernel.org
Reviewed-by: Rob Herring <r...@kernel.org>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



[PATCH v8 2/2] media: video-i2c: add video-i2c driver

2018-04-06 Thread Matt Ranostay
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.

Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 MAINTAINERS   |   6 +
 drivers/media/i2c/Kconfig |  13 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 563 ++
 4 files changed, 583 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dc153da22e8a..928b6a862626 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14880,6 +14880,12 @@ L: linux-media@vger.kernel.org
 S: Maintained
 F: drivers/media/platform/video-mux.c
 
+VIDEO I2C POLLING DRIVER
+M:     Matt Ranostay <matt.ranos...@konsulko.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak <pa...@osciak.com>
 M: Marek Szyprowski <m.szyprow...@samsung.com>
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28afd8..faaaceb94832 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -974,6 +974,19 @@ 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
+
+ To compile this driver as a module, choose M here: the
+ module will be called video-i2c
+
 endmenu
 
 menu "Sensors used on soc_camera driver"
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ea34aee1a85a..84cc472238ef 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -96,6 +96,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 ..ec8a597597bf
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,563 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * 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"
+
+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;
+   unsigned int sequence;
+   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;
+};
+
+const static struct v4l2_fmtdesc amg88xx_format = {
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+const 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 v

[PATCH v7 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-04-05 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: devicet...@vger.kernel.org
Reviewed-by: Rob Herring <r...@kernel.org>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



[PATCH v7 2/2] media: video-i2c: add video-i2c driver

2018-04-05 Thread Matt Ranostay
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.

Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 MAINTAINERS   |   6 +
 drivers/media/i2c/Kconfig |  13 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 560 ++
 4 files changed, 580 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dc153da22e8a..928b6a862626 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14880,6 +14880,12 @@ L: linux-media@vger.kernel.org
 S: Maintained
 F: drivers/media/platform/video-mux.c
 
+VIDEO I2C POLLING DRIVER
+M:     Matt Ranostay <matt.ranos...@konsulko.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak <pa...@osciak.com>
 M: Marek Szyprowski <m.szyprow...@samsung.com>
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28afd8..faaaceb94832 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -974,6 +974,19 @@ 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
+
+ To compile this driver as a module, choose M here: the
+ module will be called video-i2c
+
 endmenu
 
 menu "Sensors used on soc_camera driver"
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ea34aee1a85a..84cc472238ef 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -96,6 +96,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 ..42427a724c00
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,560 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * 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"
+
+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;
+   unsigned int sequence;
+   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_c

[PATCH v7 0/2] media: video-i2c: add video-i2c driver support

2018-04-05 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Changes from v4:
* convert pointer from of_device_get_match_data() to long instead of int to 
avoid compiler warning

Changes from v5:
* fix various issues with v4l2-compliance tool run

Changes from v6:
* fixed minor coding issues on spacing
* changed device tree table pointers to chip struct data
* add more verbose Kconfig documentation
* destroy mutexes on error path and module removal
* fixed MODULE_LICENSE from GPL to GPLv2
* changes some calls to list_last_entry() to avoid touching next pointer
* moved common code to a function from start/stop_streaming()

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |  13 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 560 +
 5 files changed, 599 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



Re: [PATCH v6 2/2] media: video-i2c: add video-i2c driver

2018-04-05 Thread Matt Ranostay
On Thu, Apr 5, 2018 at 12:39 AM, Sakari Ailus <sakari.ai...@iki.fi> wrote:
> Hi Matt,
>
> Thanks for the patch. It's a very nicely written, small driver. :-)
>
> Please see more comments below.
>
> On Sat, Mar 31, 2018 at 05:59:26PM -0700, Matt Ranostay wrote:
>> 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.
>>
>> Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
>
> Are there plans to implement support for more of these chips?
>

Nothing on my end. But there are other low resolution thermal cameras
that output i2c that could easily be added.

>> ---
>>  MAINTAINERS   |   6 +
>>  drivers/media/i2c/Kconfig |   9 +
>>  drivers/media/i2c/Makefile|   1 +
>>  drivers/media/i2c/video-i2c.c | 562 
>> ++
>>  4 files changed, 578 insertions(+)
>>  create mode 100644 drivers/media/i2c/video-i2c.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 49236216a871..f0262b751d5b 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -14863,6 +14863,12 @@ L:   linux-media@vger.kernel.org
>>  S:   Maintained
>>  F:   drivers/media/platform/video-mux.c
>>
>> +VIDEO I2C POLLING DRIVER
>> +M:   Matt Ranostay <matt.ranos...@konsulko.com>
>> +L:   linux-media@vger.kernel.org
>> +S:   Maintained
>> +F:   drivers/media/i2c/video-i2c.c
>> +
>>  VIDEOBUF2 FRAMEWORK
>>  M:   Pawel Osciak <pa...@osciak.com>
>>  M:   Marek Szyprowski <m.szyprow...@samsung.com>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 541f0d28afd8..122e5047a01e 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -974,6 +974,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
>
> You could add the name of the module here if it's compiled as a module.
>

Ok

>>  endmenu
>>
>>  menu "Sensors used on soc_camera driver"
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index ea34aee1a85a..84cc472238ef 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -96,6 +96,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 ..9fba8a2767c5
>> --- /dev/null
>> +++ b/drivers/media/i2c/video-i2c.c
>> @@ -0,0 +1,562 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * video-i2c.c - Support for I2C transport video devices
>> + *
>> + * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
>> + *
>> + * 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"
>> +
>> +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;
>> + unsigned int sequence;
>> + struct mutex queue_lock;
>> +
>> + struct v4l2_device v4l2_dev;
>> + 

Re: [PATCH v6 2/2] media: video-i2c: add video-i2c driver

2018-03-31 Thread Matt Ranostay
On Sat, Mar 31, 2018 at 5:59 PM, Matt Ranostay
<matt.ranos...@konsulko.com> wrote:
> 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.
>
> Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
> ---


v4l2-compliance SHA   : 3dc9af2b54eddb531823b99e77f3f212bdcc9cca

Compliance test for device /dev/video0:

Driver Info:
Driver name  : video-i2c
Card type: I2C 1-105 Transport Video
Bus info : I2C:1-105
Driver version   : 4.14.31
Capabilities : 0x8521
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x0521
Video Capture
Read/Write
Streaming
Extended Pix Format

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK
test MMAP: OK
test USERPTR: OK
test DMABUF: Cannot test, specify --expbuf-device

Stream using all formats:
test MMAP for Format Y12 , Frame Size 8x8@10.00 Hz:
Stride 16, Field None: OK
Total: 47, Succeeded: 47, Failed: 0, Warnings: 0



>  MAINTAINERS   |   6 +
>  drivers/media/i2c/Kconfig |   9 +
>  drivers/media/i2c/Makefile|   1 +
>  drivers/media/i2c/video-i2c.c | 562 
> ++
>  4 files changed, 578 insertions(+)
>  create mode 100644 drivers/media/i2c/video-i2c.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 49236216a871..f0262b751d5b 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -14863,6 +14863,12 @@ L: linux-media@vger.kernel.org
>  S: Maintained
>  F: drivers/media/platform/video-mux.c
>
> +VIDEO I2C POLLING DRIVER
> +M: Matt Ranostay <matt.ranos...@konsulko.com>
> +L: linux-media@vger.kernel.org
> +S: Maintained
> +F: drivers/media/i2c/video-i2c.c
> +
>  VIDEOBUF2 FRAMEWORK
>  M: Pawel Osciak <pa...@osciak.com>
>  M: Marek Szyprowski <m.szyprow...@samsung.com>
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index 541f0d28afd8..122e5047a01e 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -974,6 +974,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/drive

[PATCH v6 0/2] media: video-i2c: add video-i2c driver support

2018-03-31 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Changes from v4:
* convert pointer from of_device_get_match_data() to long instead of int to 
avoid compiler warning

Changes from v5:
* fix various issues with v4l2-compliance tool run

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |   9 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 562 +
 5 files changed, 597 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



[PATCH v6 2/2] media: video-i2c: add video-i2c driver

2018-03-31 Thread Matt Ranostay
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.

Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 MAINTAINERS   |   6 +
 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 562 ++
 4 files changed, 578 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 49236216a871..f0262b751d5b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14863,6 +14863,12 @@ L: linux-media@vger.kernel.org
 S: Maintained
 F: drivers/media/platform/video-mux.c
 
+VIDEO I2C POLLING DRIVER
+M:     Matt Ranostay <matt.ranos...@konsulko.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak <pa...@osciak.com>
 M: Marek Szyprowski <m.szyprow...@samsung.com>
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28afd8..122e5047a01e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -974,6 +974,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 ea34aee1a85a..84cc472238ef 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -96,6 +96,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 ..9fba8a2767c5
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,562 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * 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"
+
+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;
+   unsigned int sequence;
+   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   = _size,
+   .forma

[PATCH v6 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-03-31 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: devicet...@vger.kernel.org
Reviewed-by: Rob Herring <r...@kernel.org>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



Re: [PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-22 Thread Matt Ranostay
On Thu, Mar 22, 2018 at 3:28 PM, Hans Verkuil <hverk...@xs4all.nl> wrote:
> On 03/22/2018 06:46 AM, Matt Ranostay wrote:
>> On Mon, Mar 19, 2018 at 5:31 PM, Hans Verkuil <hverk...@xs4all.nl> wrote:
>>> On 03/16/2018 03:47 AM, Matt Ranostay wrote:
>>>> On Fri, Mar 9, 2018 at 10:26 AM, Matt Ranostay
>>>> <matt.ranos...@konsulko.com> wrote:
>>>>> On Fri, Mar 9, 2018 at 4:45 AM, Hans Verkuil <hverk...@xs4all.nl> wrote:
>>>>>> Hi Matt,
>>>>>>
>>>>>> This is looking good. One request before I merge: please run the
>>>>>> 'v4l2-compliance -s -f' utility and post the result here.
>>>>>>
>>>>>> I don't think I've asked you to do that before (or if I did, I couldn't
>>>>>> find it in my mail archive).
>>>>>>
>>>>>> It should run without failures.
>>>>>>
>>>>>> Use the latest version from the git repo: 
>>>>>> https://git.linuxtv.org/v4l-utils.git/
>>>>>>
>>>>>> ./bootstrap.sh; ./configure; make; sudo make install
>>>>>
>>>>> Heh so not exactly no failures. Suspect a lot of these are due to the
>>>>> weird small 8x8 pixel input, and the fact it doesn't
>>>>> support modes a typical video capture device would.
>>>>>
>>>>> v4l2-compliance SHA   : 14ce03c18ef67aa7a3d5781f015be855fd43839c
>>>>>
>>>>> Compliance test for device /dev/video0:
>>>>>
>>>>> Driver Info:
>>>>> Driver name  : video-i2c
>>>>> Card type: I2C 2-105 Transport Video
>>>>> Bus info : I2C:2-105
>>>>> Driver version   : 4.14.11
>>>>> Capabilities : 0x8521
>>>>> Video Capture
>>>>> Read/Write
>>>>> Streaming
>>>>> Extended Pix Format
>>>>> Device Capabilities
>>>>> Device Caps  : 0x0521
>>>>> Video Capture
>>>>> Read/Write
>>>>> Streaming
>>>>> Extended Pix Format
>>>>>
>>>>> Required ioctls:
>>>>> test VIDIOC_QUERYCAP: OK
>>>>>
>>>>> Allow for multiple opens:
>>>>> test second /dev/video0 open: OK
>>>>> test VIDIOC_QUERYCAP: OK
>>>>> test VIDIOC_G/S_PRIORITY: OK
>>>>> test for unlimited opens: OK
>>>>>
>>>>> Debug ioctls:
>>>>> test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
>>>>> test VIDIOC_LOG_STATUS: OK (Not Supported)
>>>>>
>>>>> Input ioctls:
>>>>> test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
>>>>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>>>>> test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
>>>>> test VIDIOC_ENUMAUDIO: OK (Not Supported)
>>>>> test VIDIOC_G/S/ENUMINPUT: OK
>>>>> test VIDIOC_G/S_AUDIO: OK (Not Supported)
>>>>> Inputs: 1 Audio Inputs: 0 Tuners: 0
>>>>>
>>>>> Output ioctls:
>>>>> test VIDIOC_G/S_MODULATOR: OK (Not Supported)
>>>>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>>>>> test VIDIOC_ENUMAUDOUT: OK (Not Supported)
>>>>> test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
>>>>> test VIDIOC_G/S_AUDOUT: OK (Not Supported)
>>>>> Outputs: 0 Audio Outputs: 0 Modulators: 0
>>>>>
>>>>> Input/Output configuration ioctls:
>>>>> test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
>>>>> test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
>>>>> test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
>>>>> test VIDIOC_G/S_EDID: OK (Not Supported)
>>>>>
>>>>> Control ioctls (Input 0):
>>>>> test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
>>>>> test VIDIOC_QUERYCTRL: OK (Not Supported)
>>>>> test VIDIOC_G/S_CTRL: OK (Not Supported)
>>>>> test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
>>>>> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
>>>>> test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
>>>>> Standard Controls: 0 Private Controls: 0
>>>>>
>>>>> Format ioctls (Input 0):
>>>>> test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
>>>>> test VIDIOC_G/S_

Re: [PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-21 Thread Matt Ranostay
On Mon, Mar 19, 2018 at 5:31 PM, Hans Verkuil <hverk...@xs4all.nl> wrote:
> On 03/16/2018 03:47 AM, Matt Ranostay wrote:
>> On Fri, Mar 9, 2018 at 10:26 AM, Matt Ranostay
>> <matt.ranos...@konsulko.com> wrote:
>>> On Fri, Mar 9, 2018 at 4:45 AM, Hans Verkuil <hverk...@xs4all.nl> wrote:
>>>> Hi Matt,
>>>>
>>>> This is looking good. One request before I merge: please run the
>>>> 'v4l2-compliance -s -f' utility and post the result here.
>>>>
>>>> I don't think I've asked you to do that before (or if I did, I couldn't
>>>> find it in my mail archive).
>>>>
>>>> It should run without failures.
>>>>
>>>> Use the latest version from the git repo: 
>>>> https://git.linuxtv.org/v4l-utils.git/
>>>>
>>>> ./bootstrap.sh; ./configure; make; sudo make install
>>>
>>> Heh so not exactly no failures. Suspect a lot of these are due to the
>>> weird small 8x8 pixel input, and the fact it doesn't
>>> support modes a typical video capture device would.
>>>
>>> v4l2-compliance SHA   : 14ce03c18ef67aa7a3d5781f015be855fd43839c
>>>
>>> Compliance test for device /dev/video0:
>>>
>>> Driver Info:
>>> Driver name  : video-i2c
>>> Card type: I2C 2-105 Transport Video
>>> Bus info : I2C:2-105
>>> Driver version   : 4.14.11
>>> Capabilities : 0x8521
>>> Video Capture
>>> Read/Write
>>> Streaming
>>> Extended Pix Format
>>> Device Capabilities
>>> Device Caps  : 0x0521
>>> Video Capture
>>> Read/Write
>>> Streaming
>>> Extended Pix Format
>>>
>>> Required ioctls:
>>> test VIDIOC_QUERYCAP: OK
>>>
>>> Allow for multiple opens:
>>> test second /dev/video0 open: OK
>>> test VIDIOC_QUERYCAP: OK
>>> test VIDIOC_G/S_PRIORITY: OK
>>> test for unlimited opens: OK
>>>
>>> Debug ioctls:
>>> test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
>>> test VIDIOC_LOG_STATUS: OK (Not Supported)
>>>
>>> Input ioctls:
>>> test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
>>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>>> test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
>>> test VIDIOC_ENUMAUDIO: OK (Not Supported)
>>> test VIDIOC_G/S/ENUMINPUT: OK
>>> test VIDIOC_G/S_AUDIO: OK (Not Supported)
>>> Inputs: 1 Audio Inputs: 0 Tuners: 0
>>>
>>> Output ioctls:
>>> test VIDIOC_G/S_MODULATOR: OK (Not Supported)
>>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>>> test VIDIOC_ENUMAUDOUT: OK (Not Supported)
>>> test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
>>> test VIDIOC_G/S_AUDOUT: OK (Not Supported)
>>> Outputs: 0 Audio Outputs: 0 Modulators: 0
>>>
>>> Input/Output configuration ioctls:
>>> test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
>>> test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
>>> test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
>>> test VIDIOC_G/S_EDID: OK (Not Supported)
>>>
>>> Control ioctls (Input 0):
>>> test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
>>> test VIDIOC_QUERYCTRL: OK (Not Supported)
>>> test VIDIOC_G/S_CTRL: OK (Not Supported)
>>> test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
>>> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
>>> test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
>>> Standard Controls: 0 Private Controls: 0
>>>
>>> Format ioctls (Input 0):
>>> test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
>>> test VIDIOC_G/S_PARM: OK
>>> test VIDIOC_G_FBUF: OK (Not Supported)
>>> test VIDIOC_G_FMT: OK
>>> test VIDIOC_TRY_FMT: OK
>>> test VIDIOC_S_FMT: OK
>>> test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
>>> test Cropping: OK (Not Supported)
>>> test Composing: OK (Not Supported)
>>> test Scaling: OK (Not Supported)
>>>
>>> Codec ioctls (Input 0):
>>> test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
>>> test VIDIOC_G_ENC_INDEX: OK (Not Supported)
>>> test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
>>>
>>> Buffer ioctls (Input 0):
>>> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
>>> test VIDIOC_EXPBUF: OK (Not Supported)
>>>
>>> Test input 0:
>>>
>>> Streaming ioctls:
>>> test read/write: OK

Re: [PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-15 Thread Matt Ranostay
On Fri, Mar 9, 2018 at 10:26 AM, Matt Ranostay
<matt.ranos...@konsulko.com> wrote:
> On Fri, Mar 9, 2018 at 4:45 AM, Hans Verkuil <hverk...@xs4all.nl> wrote:
>> Hi Matt,
>>
>> This is looking good. One request before I merge: please run the
>> 'v4l2-compliance -s -f' utility and post the result here.
>>
>> I don't think I've asked you to do that before (or if I did, I couldn't
>> find it in my mail archive).
>>
>> It should run without failures.
>>
>> Use the latest version from the git repo: 
>> https://git.linuxtv.org/v4l-utils.git/
>>
>> ./bootstrap.sh; ./configure; make; sudo make install
>
> Heh so not exactly no failures. Suspect a lot of these are due to the
> weird small 8x8 pixel input, and the fact it doesn't
> support modes a typical video capture device would.
>
> v4l2-compliance SHA   : 14ce03c18ef67aa7a3d5781f015be855fd43839c
>
> Compliance test for device /dev/video0:
>
> Driver Info:
> Driver name  : video-i2c
> Card type: I2C 2-105 Transport Video
> Bus info : I2C:2-105
> Driver version   : 4.14.11
> Capabilities : 0x8521
> Video Capture
> Read/Write
> Streaming
> Extended Pix Format
> Device Capabilities
> Device Caps  : 0x0521
> Video Capture
> Read/Write
> Streaming
> Extended Pix Format
>
> Required ioctls:
> test VIDIOC_QUERYCAP: OK
>
> Allow for multiple opens:
> test second /dev/video0 open: OK
> test VIDIOC_QUERYCAP: OK
> test VIDIOC_G/S_PRIORITY: OK
> test for unlimited opens: OK
>
> Debug ioctls:
> test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
> test VIDIOC_LOG_STATUS: OK (Not Supported)
>
> Input ioctls:
> test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
> test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
> test VIDIOC_ENUMAUDIO: OK (Not Supported)
> test VIDIOC_G/S/ENUMINPUT: OK
> test VIDIOC_G/S_AUDIO: OK (Not Supported)
> Inputs: 1 Audio Inputs: 0 Tuners: 0
>
> Output ioctls:
> test VIDIOC_G/S_MODULATOR: OK (Not Supported)
> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
> test VIDIOC_ENUMAUDOUT: OK (Not Supported)
> test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
> test VIDIOC_G/S_AUDOUT: OK (Not Supported)
> Outputs: 0 Audio Outputs: 0 Modulators: 0
>
> Input/Output configuration ioctls:
> test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
> test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
> test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
> test VIDIOC_G/S_EDID: OK (Not Supported)
>
> Control ioctls (Input 0):
> test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
> test VIDIOC_QUERYCTRL: OK (Not Supported)
> test VIDIOC_G/S_CTRL: OK (Not Supported)
> test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
> test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
> Standard Controls: 0 Private Controls: 0
>
> Format ioctls (Input 0):
> test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
> test VIDIOC_G/S_PARM: OK
> test VIDIOC_G_FBUF: OK (Not Supported)
> test VIDIOC_G_FMT: OK
> test VIDIOC_TRY_FMT: OK
> test VIDIOC_S_FMT: OK
> test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
> test Cropping: OK (Not Supported)
> test Composing: OK (Not Supported)
> test Scaling: OK (Not Supported)
>
> Codec ioctls (Input 0):
> test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
> test VIDIOC_G_ENC_INDEX: OK (Not Supported)
> test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
>
> Buffer ioctls (Input 0):
> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
> test VIDIOC_EXPBUF: OK (Not Supported)
>
> Test input 0:
>
> Streaming ioctls:
> test read/write: OK
> fail: v4l2-test-buffers.cpp(248): g_field() == V4L2_FIELD_ANY

Noticed this seems to be the most worrying of the failures.  Any
suggestions where could be requested and still be 0 == V4L2_FIELD_ANY?

> fail: v4l2-test-buffers.cpp(658): buf.check(q, last_seq)
> fail: v4l2-test-buffers.cpp(928): captureBufs(node, q, m2m_q,
> frame_count, false)
> test MMAP: FAIL
> fail: v4l2-test-buffers.cpp(1028): can_stream && ret != EINVAL
> test USERPTR: FAIL
> test DMABUF: Cannot test, specify --expbuf-device
>
> Stream using all formats:
> test MMAP for Format Y12 , Frame Size 8x8@10.00 Hz:
> fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
> Stride 0, Field None: FAIL
> fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() <= size
> fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
> Stride 80, Field None: FAIL
> fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
> Stride 0, Field Top: FAIL
> fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() 

Re: [PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-09 Thread Matt Ranostay
Stride 0, Field Sequential Bottom-Top: FAIL
fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() <= size
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 80, Field None: FAIL
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 0, Field Alternating: FAIL
fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() <= size
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 80, Field None: FAIL
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 0, Field Interlaced Top-Bottom: FAIL
fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() <= size
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 80, Field None: FAIL
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 0, Field Interlaced Bottom-Top: FAIL
fail: v4l2-test-buffers.cpp(1472): fmt.g_sizeimage() <= size
fail: v4l2-test-buffers.cpp(1268): q.reqbufs(node, 3)
Stride 80, Field None: FAIL
Total: 64, Succeeded: 44, Failed: 20, Warnings: 0


>
> Thanks!
>
> Hans
>
> On 08/03/18 19:21, Matt Ranostay wrote:
>> Add support for video-i2c polling driver
>>
>> Changes from v1:
>> * Switch to SPDX tags versus GPLv2 license text
>> * Remove unneeded zeroing of data structures
>> * Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function
>>
>> Changes from v2:
>> * Add missing linux/kthread.h include that broke x86_64 build
>>
>> Changes from v3:
>> * Add devicetree binding documents
>> * snprintf check added
>> * switched to per chip support based on devicetree or i2c client id
>> * add VB2_DMABUF to io_modes
>> * added entry to MAINTAINERS file switched to per chip support based on 
>> devicetree or i2c client id
>>
>> Changes from v4:
>> * convert pointer from of_device_get_match_data() to long instead of int to 
>> avoid compiler warning
>>
>> Matt Ranostay (2):
>>   media: dt-bindings: Add bindings for panasonic,amg88xx
>>   media: video-i2c: add video-i2c driver
>>
>>  .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
>>  MAINTAINERS|   6 +
>>  drivers/media/i2c/Kconfig  |   9 +
>>  drivers/media/i2c/Makefile |   1 +
>>  drivers/media/i2c/video-i2c.c  | 558 
>> +
>>  5 files changed, 593 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
>>  create mode 100644 drivers/media/i2c/video-i2c.c
>>
>


[PATCH v5 2/2] media: video-i2c: add video-i2c driver

2018-03-08 Thread Matt Ranostay
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.

Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 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 e03a130902cd..4d794e78a5ce 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14876,6 +14876,12 @@ L: linux-media@vger.kernel.org
 S: Maintained
 F: drivers/media/platform/video-mux.c
 
+VIDEO I2C POLLING DRIVER
+M:     Matt Ranostay <matt.ranos...@konsulko.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak <pa...@osciak.com>
 M: Marek Szyprowski <m.szyprow...@samsung.com>
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index d7bba0e3f30e..22f7c1e40c4e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -963,6 +963,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 cc30178e3347..6cc5f0f7e4fc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -95,6 +95,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 ..a30f758f506b
--- /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 <matt.ranos...@konsulko.com>
+ *
+ * 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   = _size,
+   .forma

[PATCH v5 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-03-08 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: devicet...@vger.kernel.org
Reviewed-by: Rob Herring <r...@kernel.org>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



[PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-08 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Changes from v4:
* convert pointer from of_device_get_match_data() to long instead of int to 
avoid compiler warning

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |   9 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 558 +
 5 files changed, 593 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



Re: [PATCH v4 2/2] media: video-i2c: add video-i2c driver

2018-03-04 Thread Matt Ranostay
On Wed, Feb 28, 2018 at 8:22 PM, kbuild test robot <l...@intel.com> 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(>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(>dev);
>457  else
>458  chip_id = id->driver_data;
>459
>460  data->chip = _i2c_chip[chip_id];
>461  data->client = client;
>462  v4l2_dev = >v4l2_dev;
>463  strlcpy(v4l2_dev->name, VIDEO_I2C_DRIVER, 
> sizeof(v4l2_dev->name));
>464
>465  ret = v4l2_device_register(>dev, v4l2_dev);
>466  if (ret < 0)
>467  goto error_free_device;
>468
>469  mutex_init(>lock);
>470  mutex_init(>queue_lock);
>471
>472  queue = >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 = _i2c_video_qops;
>480  queue->mem_ops = _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 = >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 = _i2c_fops;
>495  data->vdev.lock = >lock;
>496  data->vdev.ioctl_ops = _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(>slock);
>502  INIT_LIST_HEAD(>vid_cap_active);
>503
>504  video_set_drvdata(>vdev, data);
>505  i2c_set_clientdata(client, data);
>506
>507  ret = video_register_device(>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


[PATCH v4 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-02-26 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: Rob Herring <r...@kernel.org>
Cc: devicet...@vger.kernel.org
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



[PATCH v4 2/2] media: video-i2c: add video-i2c driver

2018-02-26 Thread Matt Ranostay
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 <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 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 <matt.ranos...@konsulko.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak <pa...@osciak.com>
 M: Marek Szyprowski <m.szyprow...@samsung.com>
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 <matt.ranos...@konsulko.com>
+ *
+ * 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

[PATCH v4 0/2] media: video-i2c: add video-i2c driver support

2018-02-26 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |   9 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 558 +
 5 files changed, 593 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



[PATCH v3] media: video-i2c: add video-i2c driver

2018-02-24 Thread Matt Ranostay
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 <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 547 ++
 3 files changed, 557 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

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 ..ea8ab2fcd580
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,547 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#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;
+}
+
+static const struct video_i2c_chip video_i2c_chip = {
+   .size   = _size,
+   .format = _format,
+   .max_fps= 10,
+   .buffer_size= 128,
+   .bpp= 16,
+   .xfer   = _xfer,
+};
+
+static const struct v4l2_file_operations video_i2c_fops = {
+   .owner  = THIS_MODULE,
+   .open   = v4l2_fh_open,
+ 

[PATCH v2] media: video-i2c: add video-i2c driver

2018-02-15 Thread Matt Ranostay
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 <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 546 ++
 3 files changed, 556 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 9f18cd296841..549f1e9fc01e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -908,6 +908,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 c0f94cd8d56d..5ca4c98a4bea 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -90,6 +90,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 ..936baaae2c7f
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,546 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#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;
+}
+
+static const struct video_i2c_chip video_i2c_chip = {
+   .size   = _size,
+   .format = _format,
+   .max_fps= 10,
+   .buffer_size= 128,
+   .bpp= 16,
+   .xfer   = _xfer,
+};
+
+static const struct v4l2_file_operations video_i2c_fops = {
+   .owner  = THIS_MODULE,
+   .open   = v4l2_fh_open,
+   .release= vb2_fop_release,
+   .poll   = vb2_fop_poll,
+   .read

Re: [PATCH RESEND] media: video-i2c: add video-i2c driver

2018-02-15 Thread Matt Ranostay
On Thu, Feb 15, 2018 at 7:49 AM, Hans Verkuil <hverk...@xs4all.nl> wrote:
> Hi Matt,
>
> Here is a quick review. Apologies for the delay, it has been very busy for
> the last few weeks.
>
> On 13/01/18 04:57, Matt Ranostay wrote:
>> 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 <lu_z...@gentoo.org>
>> Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>> Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
>> ---
>>  drivers/media/i2c/Kconfig |   9 +
>>  drivers/media/i2c/Makefile|   1 +
>>  drivers/media/i2c/video-i2c.c | 556 
>> ++
>>  3 files changed, 566 insertions(+)
>>  create mode 100644 drivers/media/i2c/video-i2c.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 9f18cd296841..549f1e9fc01e 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -908,6 +908,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 c0f94cd8d56d..5ca4c98a4bea 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -90,6 +90,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 ..9df9b5ebd156
>> --- /dev/null
>> +++ b/drivers/media/i2c/video-i2c.c
>> @@ -0,0 +1,556 @@
>> +/*
>> + * video-i2c.c - Support for I2C transport video devices
>> + *
>> + * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>
> Please use the SPDX tags instead of this license text. See
> https://git.linuxtv.org/media_tree.git/tree/Documentation/process/license-rules.rst
>
>> + *
>> + * Supported:
>> + * - Panasonic AMG88xx Grid-Eye Sensors
>> + */
>> +
>> +#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_SIZE  128
>> +
>> +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 struc

[PATCH RESEND] media: video-i2c: add video-i2c driver

2018-01-12 Thread Matt Ranostay
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 <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt.ranos...@konsulko.com>
---
 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 556 ++
 3 files changed, 566 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 9f18cd296841..549f1e9fc01e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -908,6 +908,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 c0f94cd8d56d..5ca4c98a4bea 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -90,6 +90,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 ..9df9b5ebd156
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,556 @@
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay <matt.ranos...@konsulko.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#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;
+}
+
+static const struct video_i2c_chip video_i2c_chip = {
+   .size   = _size,
+   .format = _format,
+   .max_fps= 10,
+   .buffer_size= 128,

Re: [PATCH v5] media: video-i2c: add video-i2c driver

2017-01-13 Thread Matt Ranostay
On Fri, Jan 13, 2017 at 3:47 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Matt,
>
> Thank you for the patch.
>
> On Friday 23 Dec 2016 19:04:26 Matt Ranostay wrote:
>> 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: Attila Kinali <att...@kinali.ch>
>> Cc: Marek Vasut <ma...@denx.de>
>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * correct i2c_polling_remove() operations
>> * fixed delay calcuation in buffer_queue()
>> * add include linux/slab.h
>>
>> Changes from v2:
>> * fix build error due to typo in include of slab.h
>>
>> Changes from v3:
>> * switch data transport to a kthread to avoid to .buf_queue that can't sleep
>> * change naming from i2c-polling to video-i2c
>> * make the driver for single chipset under another uses the driver
>>
>> Changes from v4:
>> * fix wraparound issue with jiffies and schedule_timeout_interruptible()
>>
>>  drivers/media/i2c/Kconfig |   9 +
>>  drivers/media/i2c/Makefile|   1 +
>>  drivers/media/i2c/video-i2c.c | 569 ++
>>  3 files changed, 579 insertions(+)
>>  create mode 100644 drivers/media/i2c/video-i2c.c
>
> [snip]
>
>> diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
>> new file mode 100644
>> index ..9390560bd117
>> --- /dev/null
>> +++ b/drivers/media/i2c/video-i2c.c
>
> [snip]
>
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>
> Alphabetical order please.
>
>> +#include 
>> +#include 
>
> [snip]
>
>> +static struct v4l2_fmtdesc amg88xx_format = {
>> + .description = "12-bit Greyscale",
>
> If I'm not mistaken the V4L2 core fills that for you nowadays, you don't have
> to set it.
>
>> + .pixelformat = V4L2_PIX_FMT_Y12,
>> +};
>> +
>> +static struct v4l2_frmsize_discrete amg88xx_size = {
>> + .width = 8,
>> + .height = 8,
>> +};
>> +
>> +struct video_i2c_chip {
>> + /* video dimensions */
>> + struct v4l2_fmtdesc *format;
>> + struct v4l2_frmsize_discrete *size;
>
> You can make those two pointers (and the variables they point to) const.
>
>> +
>> + /* 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);
>> +};
>
> [snip]
>
>> +static int video_i2c_thread_vid_cap(void *priv)
>> +{
>> + struct video_i2c_data *data = priv;
>> + struct video_i2c_buffer *vid_cap_buf = NULL;
>> +
>> + set_freezable();
>> +
>> + do {
>> + unsigned int start_jiffies = jiffies;
>
> jiffies is an unsigned long.

Noted.
>
>> + unsigned int delay = msecs_to_jiffies(1000 / data->chip-
>>max_fps);
>> + int schedule_delay;
>> +
>> + try_to_freeze();
>> +
>> + mutex_lock(>lock);
>
> Why do you need the mutex here ?

Probably don't need the nested mutex and spinlock

>
>> + spin_lock(>slock);
>> +
>> + if (!list_empty(>vid_cap_active)) {
>> + vid_cap_buf = list_entry(data->vid_cap_active.next,
>> +  struct video_i2c_buffer,
> list);
>> + list_del(_cap_buf->list);
>> + }
>> +
>> + if (vid_cap_buf) {
>
> vid_cap_buf will only be non-NULL in all but the first iteration of the loop,
> even if the list is empty. You should declare the variable inside the loop,
> not at the function level.
>

Noted

>> + struct vb2_buffer *vb2_buf = _cap_buf->vb.vb2_buf;
>> + void *vbuf = vb2_plane_vaddr(vb2_buf, 0);
>> + int ret =

Re: [PATCH v5] media: video-i2c: add video-i2c driver

2017-01-13 Thread Matt Ranostay
On Fri, Jan 13, 2017 at 2:22 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Matt,
>
> On Thursday 12 Jan 2017 20:45:21 Matt Ranostay wrote:
>> On Sun, Jan 8, 2017 at 9:33 PM, Marek Vasut <ma...@denx.de> wrote:
>> > On 01/09/2017 06:17 AM, Matt Ranostay wrote:
>> >> Gentle ping on this! :)
>> >
>> > Just some high-level feedback ... You should use regmap instead. Also,
>> > calling a driver which is specific to a particular sensor (amg88x) by
>> > generic name (video_i2c) is probably not a good idea.
>>
>> There are likely going to variants, and other vendors that will have
>> parts as well. One example to note is the FLIR Lepton, and that may be
>> a good reason to use regmap in the future.   Also Laurent suggested
>> the generic naming :)
>
> I actually suggested video-i2c instead of i2c-polling to make the name *less*
> generic :-)

Ah misremembered, oops :).   Although I think having it somewhat
generic is ideal there are few of these sensors from various
semiconductor companies which are pretty much basically the same.

>
>> >>> On Dec 23, 2016, at 19:04, Matt Ranostay <matt@ranostay.consulting>
>> >>> wrote:
>> >>>
>> >>> 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: Attila Kinali <att...@kinali.ch>
>> >>> Cc: Marek Vasut <ma...@denx.de>
>> >>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> >>> Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>> >>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> >>> ---
>> >>> Changes from v1:
>> >>> * correct i2c_polling_remove() operations
>> >>> * fixed delay calcuation in buffer_queue()
>> >>> * add include linux/slab.h
>> >>>
>> >>> Changes from v2:
>> >>> * fix build error due to typo in include of slab.h
>> >>>
>> >>> Changes from v3:
>> >>> * switch data transport to a kthread to avoid to .buf_queue that can't
>> >>> sleep * change naming from i2c-polling to video-i2c
>> >>> * make the driver for single chipset under another uses the driver
>> >>>
>> >>> Changes from v4:
>> >>> * fix wraparound issue with jiffies and schedule_timeout_interruptible()
>> >>>
>> >>> drivers/media/i2c/Kconfig |   9 +
>> >>> drivers/media/i2c/Makefile|   1 +
>> >>> drivers/media/i2c/video-i2c.c | 569 
>> >>> 3 files changed, 579 insertions(+)
>> >>> create mode 100644 drivers/media/i2c/video-i2c.c
>
> --
> Regards,
>
> Laurent Pinchart
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5] media: video-i2c: add video-i2c driver

2017-01-12 Thread Matt Ranostay
On Sun, Jan 8, 2017 at 9:33 PM, Marek Vasut <ma...@denx.de> wrote:
> On 01/09/2017 06:17 AM, Matt Ranostay wrote:
>> Gentle ping on this! :)
>
> Just some high-level feedback ... You should use regmap instead. Also,
> calling a driver which is specific to a particular sensor (amg88x) by
> generic name (video_i2c) is probably not a good idea.

There are likely going to variants, and other vendors that will have
parts as well. One example to note is the FLIR Lepton, and that may be
a good reason to use regmap in the future.   Also Laurent suggested
the generic naming :)

>
>> Thanks,
>>
>> Matt
>>
>>> On Dec 23, 2016, at 19:04, Matt Ranostay <matt@ranostay.consulting> wrote:
>>>
>>> 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: Attila Kinali <att...@kinali.ch>
>>> Cc: Marek Vasut <ma...@denx.de>
>>> Cc: Luca Barbato <lu_z...@gentoo.org>
>>> Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>>> ---
>>> Changes from v1:
>>> * correct i2c_polling_remove() operations
>>> * fixed delay calcuation in buffer_queue()
>>> * add include linux/slab.h
>>>
>>> Changes from v2:
>>> * fix build error due to typo in include of slab.h
>>>
>>> Changes from v3:
>>> * switch data transport to a kthread to avoid to .buf_queue that can't sleep
>>> * change naming from i2c-polling to video-i2c
>>> * make the driver for single chipset under another uses the driver
>>>
>>> Changes from v4:
>>> * fix wraparound issue with jiffies and schedule_timeout_interruptible()
>>>
>>> drivers/media/i2c/Kconfig |   9 +
>>> drivers/media/i2c/Makefile|   1 +
>>> drivers/media/i2c/video-i2c.c | 569 
>>> ++
>>> 3 files changed, 579 insertions(+)
>>> create mode 100644 drivers/media/i2c/video-i2c.c
>>>
>>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>>> index b31fa6fae009..ef84715293a9 100644
>>> --- a/drivers/media/i2c/Kconfig
>>> +++ b/drivers/media/i2c/Kconfig
>>> @@ -768,6 +768,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 92773b2e6225..7c8eeb213c3b 100644
>>> --- a/drivers/media/i2c/Makefile
>>> +++ b/drivers/media/i2c/Makefile
>>> @@ -79,6 +79,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 ..9390560bd117
>>> --- /dev/null
>>> +++ b/drivers/media/i2c/video-i2c.c
>>> @@ -0,0 +1,569 @@
>>> +/*
>>> + * video-i2c.c - Support for I2C transport video devices
>>> + *
>>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License as published by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANT

Re: [PATCH v5] media: video-i2c: add video-i2c driver

2017-01-08 Thread Matt Ranostay
Gentle ping on this! :)

Thanks,

Matt

> On Dec 23, 2016, at 19:04, Matt Ranostay <matt@ranostay.consulting> wrote:
> 
> 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: Attila Kinali <att...@kinali.ch>
> Cc: Marek Vasut <ma...@denx.de>
> Cc: Luca Barbato <lu_z...@gentoo.org>
> Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
> Changes from v1:
> * correct i2c_polling_remove() operations
> * fixed delay calcuation in buffer_queue()
> * add include linux/slab.h
> 
> Changes from v2:
> * fix build error due to typo in include of slab.h
> 
> Changes from v3:
> * switch data transport to a kthread to avoid to .buf_queue that can't sleep
> * change naming from i2c-polling to video-i2c
> * make the driver for single chipset under another uses the driver
> 
> Changes from v4:
> * fix wraparound issue with jiffies and schedule_timeout_interruptible() 
> 
> drivers/media/i2c/Kconfig |   9 +
> drivers/media/i2c/Makefile|   1 +
> drivers/media/i2c/video-i2c.c | 569 ++
> 3 files changed, 579 insertions(+)
> create mode 100644 drivers/media/i2c/video-i2c.c
> 
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index b31fa6fae009..ef84715293a9 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -768,6 +768,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 92773b2e6225..7c8eeb213c3b 100644
> --- a/drivers/media/i2c/Makefile
> +++ b/drivers/media/i2c/Makefile
> @@ -79,6 +79,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 ..9390560bd117
> --- /dev/null
> +++ b/drivers/media/i2c/video-i2c.c
> @@ -0,0 +1,569 @@
> +/*
> + * video-i2c.c - Support for I2C transport video devices
> + *
> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * Supported:
> + * - Panasonic AMG88xx Grid-Eye Sensors
> + */
> +
> +#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 = {
> +.description = "12-bit Greyscale",
> +.pixelformat = V4L2_PIX_FMT_Y

[PATCH v5] media: video-i2c: add video-i2c driver

2016-12-23 Thread Matt Ranostay
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: Attila Kinali <att...@kinali.ch>
Cc: Marek Vasut <ma...@denx.de>
Cc: Luca Barbato <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
Changes from v1:
* correct i2c_polling_remove() operations
* fixed delay calcuation in buffer_queue()
* add include linux/slab.h

Changes from v2:
* fix build error due to typo in include of slab.h

Changes from v3:
* switch data transport to a kthread to avoid to .buf_queue that can't sleep
* change naming from i2c-polling to video-i2c
* make the driver for single chipset under another uses the driver

Changes from v4:
* fix wraparound issue with jiffies and schedule_timeout_interruptible() 

 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 569 ++
 3 files changed, 579 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index b31fa6fae009..ef84715293a9 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -768,6 +768,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 92773b2e6225..7c8eeb213c3b 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -79,6 +79,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 ..9390560bd117
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,569 @@
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#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 = {
+   .description = "12-bit Greyscale",
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct video_i2c_chip {
+   /* video dimensions */
+   struct v4l2_fmtdesc *format;
+   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];
+

[PATCH v4] media: video-i2c: add video-i2c driver

2016-11-25 Thread Matt Ranostay
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: Attila Kinali <att...@kinali.ch>
Cc: Marek Vasut <ma...@denx.de>
Cc: Luca Barbato <lu_z...@gentoo.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
Changes from v1:
* correct i2c_polling_remove() operations
* fixed delay calcuation in buffer_queue()
* add include linux/slab.h

Changes from v2:
* fix build error due to typo in include of slab.h

Changes form v3:
* switch data transport to a kthread to avoid to .buf_queue that can't sleep
* change naming from i2c-polling to video-i2c
* make the driver for single chipset under another uses the driver

 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 553 ++
 3 files changed, 563 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index b31fa6fae009..ef84715293a9 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -768,6 +768,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 92773b2e6225..7c8eeb213c3b 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -79,6 +79,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 ..59b6f68daed6
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,553 @@
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#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 = {
+   .description = "12-bit Greyscale",
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct video_i2c_chip {
+   /* video dimensions */
+   struct v4l2_fmtdesc *format;
+   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].fla

Re: [PATCH v3] media: i2c-polling: add i2c-polling driver

2016-11-24 Thread Matt Ranostay
On Wed, Nov 23, 2016 at 10:31 PM, Matt Ranostay
<matt@ranostay.consulting> wrote:
> On Wed, Nov 23, 2016 at 8:30 AM, Laurent Pinchart
> <laurent.pinch...@ideasonboard.com> wrote:
>> Hi Matt,
>>
>> Thank you for the patch.
>>
>> On Tuesday 22 Nov 2016 17:18:40 Matt Ranostay wrote:
>>> 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: Attila Kinali <att...@kinali.ch>
>>> Cc: Marek Vasut <ma...@denx.de>
>>> Cc: Luca Barbato <lu_z...@gentoo.org>
>>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>>> ---
>>> Changes from v1:
>>> * correct i2c_polling_remove() operations
>>> * fixed delay calcuation in buffer_queue()
>>> * add include linux/slab.h
>>>
>>> Changes from v2:
>>> * fix build error due to typo in include of slab.h
>>>
>>>  drivers/media/i2c/Kconfig   |   8 +
>>>  drivers/media/i2c/Makefile  |   1 +
>>>  drivers/media/i2c/i2c-polling.c | 469 +
>>
>> Just looking at the driver name I believe a rename is needed. i2c-polling is 
>> a
>> very generic name and would mislead many people into thinking about an I2C
>> subsystem core feature instead of a video driver. "video-i2c" is one option,
>> I'm open to other ideas.
>>
>>>  3 files changed, 478 insertions(+)
>>>  create mode 100644 drivers/media/i2c/i2c-polling.c
>>>
>>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>>> index b31fa6fae009..d840e7be0036 100644
>>> --- a/drivers/media/i2c/Kconfig
>>> +++ b/drivers/media/i2c/Kconfig
>>> @@ -768,6 +768,14 @@ config VIDEO_M52790
>>>
>>>To compile this driver as a module, choose M here: the
>>>module will be called m52790.
>>> +
>>> +config VIDEO_I2C_POLLING
>>> + tristate "I2C polling video support"
>>> + depends on VIDEO_V4L2 && I2C
>>> + select VIDEOBUF2_VMALLOC
>>> + ---help---
>>> +   Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
>>> --- a/drivers/media/i2c/Makefile
>>> +++ b/drivers/media/i2c/Makefile
>>> @@ -79,6 +79,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_POLLING)  += i2c-polling.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/i2c-polling.c
>>> b/drivers/media/i2c/i2c-polling.c new file mode 100644
>>> index ..46a4eecde2d2
>>> --- /dev/null
>>> +++ b/drivers/media/i2c/i2c-polling.c
>>> @@ -0,0 +1,469 @@
>>> +/*
>>> + * i2c_polling.c - Support for polling I2C video devices
>>> + *
>>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>>> + *
>>> + * Based on the orginal work drivers/media/parport/bw-qcam.c
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License as published by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + * Supported:
>>> + * - Panasonic AMG88xx Grid-Eye Sensors
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>
>> I don't think you implement device tree support, is linux/of.h needed ? Or
>> maybe you could implement device tree support ;-)
>>
>>> +#include

Re: [PATCH v3] media: i2c-polling: add i2c-polling driver

2016-11-23 Thread Matt Ranostay
On Wed, Nov 23, 2016 at 8:30 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Matt,
>
> Thank you for the patch.
>
> On Tuesday 22 Nov 2016 17:18:40 Matt Ranostay wrote:
>> 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: Attila Kinali <att...@kinali.ch>
>> Cc: Marek Vasut <ma...@denx.de>
>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * correct i2c_polling_remove() operations
>> * fixed delay calcuation in buffer_queue()
>> * add include linux/slab.h
>>
>> Changes from v2:
>> * fix build error due to typo in include of slab.h
>>
>>  drivers/media/i2c/Kconfig   |   8 +
>>  drivers/media/i2c/Makefile  |   1 +
>>  drivers/media/i2c/i2c-polling.c | 469 +
>
> Just looking at the driver name I believe a rename is needed. i2c-polling is a
> very generic name and would mislead many people into thinking about an I2C
> subsystem core feature instead of a video driver. "video-i2c" is one option,
> I'm open to other ideas.
>
>>  3 files changed, 478 insertions(+)
>>  create mode 100644 drivers/media/i2c/i2c-polling.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index b31fa6fae009..d840e7be0036 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -768,6 +768,14 @@ config VIDEO_M52790
>>
>>To compile this driver as a module, choose M here: the
>>module will be called m52790.
>> +
>> +config VIDEO_I2C_POLLING
>> + tristate "I2C polling video support"
>> + depends on VIDEO_V4L2 && I2C
>> + select VIDEOBUF2_VMALLOC
>> + ---help---
>> +   Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -79,6 +79,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_POLLING)  += i2c-polling.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/i2c-polling.c
>> b/drivers/media/i2c/i2c-polling.c new file mode 100644
>> index ..46a4eecde2d2
>> --- /dev/null
>> +++ b/drivers/media/i2c/i2c-polling.c
>> @@ -0,0 +1,469 @@
>> +/*
>> + * i2c_polling.c - Support for polling I2C video devices
>> + *
>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>> + *
>> + * Based on the orginal work drivers/media/parport/bw-qcam.c
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * Supported:
>> + * - Panasonic AMG88xx Grid-Eye Sensors
>> + */
>> +
>> +#include 
>> +#include 
>
> I don't think you implement device tree support, is linux/of.h needed ? Or
> maybe you could implement device tree support ;-)
>
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>
> You don't implement any control, you can drop support for control events as
> well.
>
>> +#include 
>
> Please sort includes alphabetically, it makes it easier to locate duplicates.
>
>> +#define I2C_POLLING_DRIVER   "i2c-polling"
>> +
&

Re: [PATCH v3] media: i2c-polling: add i2c-polling driver

2016-11-23 Thread Matt Ranostay
On Wed, Nov 23, 2016 at 8:30 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Matt,
>
> Thank you for the patch.
>
> On Tuesday 22 Nov 2016 17:18:40 Matt Ranostay wrote:
>> 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: Attila Kinali <att...@kinali.ch>
>> Cc: Marek Vasut <ma...@denx.de>
>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * correct i2c_polling_remove() operations
>> * fixed delay calcuation in buffer_queue()
>> * add include linux/slab.h
>>
>> Changes from v2:
>> * fix build error due to typo in include of slab.h
>>
>>  drivers/media/i2c/Kconfig   |   8 +
>>  drivers/media/i2c/Makefile  |   1 +
>>  drivers/media/i2c/i2c-polling.c | 469 +
>
> Just looking at the driver name I believe a rename is needed. i2c-polling is a
> very generic name and would mislead many people into thinking about an I2C
> subsystem core feature instead of a video driver. "video-i2c" is one option,
> I'm open to other ideas.
>
>>  3 files changed, 478 insertions(+)
>>  create mode 100644 drivers/media/i2c/i2c-polling.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index b31fa6fae009..d840e7be0036 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -768,6 +768,14 @@ config VIDEO_M52790
>>
>>To compile this driver as a module, choose M here: the
>>module will be called m52790.
>> +
>> +config VIDEO_I2C_POLLING
>> + tristate "I2C polling video support"
>> + depends on VIDEO_V4L2 && I2C
>> + select VIDEOBUF2_VMALLOC
>> + ---help---
>> +   Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -79,6 +79,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_POLLING)  += i2c-polling.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/i2c-polling.c
>> b/drivers/media/i2c/i2c-polling.c new file mode 100644
>> index ..46a4eecde2d2
>> --- /dev/null
>> +++ b/drivers/media/i2c/i2c-polling.c
>> @@ -0,0 +1,469 @@
>> +/*
>> + * i2c_polling.c - Support for polling I2C video devices
>> + *
>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>> + *
>> + * Based on the orginal work drivers/media/parport/bw-qcam.c
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * Supported:
>> + * - Panasonic AMG88xx Grid-Eye Sensors
>> + */
>> +
>> +#include 
>> +#include 
>
> I don't think you implement device tree support, is linux/of.h needed ? Or
> maybe you could implement device tree support ;-)
>
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>
> You don't implement any control, you can drop support for control events as
> well.
>
>> +#include 
>
> Please sort includes alphabetically, it makes it easier to locate duplicates.
>
>> +#define I2C_POLLING_DRIVER   "i2c-polling"
>> +
&

Re: [PATCH v3] media: i2c-polling: add i2c-polling driver

2016-11-23 Thread Matt Ranostay
On Wed, Nov 23, 2016 at 8:30 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Matt,
>
> Thank you for the patch.
>
> On Tuesday 22 Nov 2016 17:18:40 Matt Ranostay wrote:
>> 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: Attila Kinali <att...@kinali.ch>
>> Cc: Marek Vasut <ma...@denx.de>
>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * correct i2c_polling_remove() operations
>> * fixed delay calcuation in buffer_queue()
>> * add include linux/slab.h
>>
>> Changes from v2:
>> * fix build error due to typo in include of slab.h
>>
>>  drivers/media/i2c/Kconfig   |   8 +
>>  drivers/media/i2c/Makefile  |   1 +
>>  drivers/media/i2c/i2c-polling.c | 469 +
>
> Just looking at the driver name I believe a rename is needed. i2c-polling is a
> very generic name and would mislead many people into thinking about an I2C
> subsystem core feature instead of a video driver. "video-i2c" is one option,
> I'm open to other ideas.
>
>>  3 files changed, 478 insertions(+)
>>  create mode 100644 drivers/media/i2c/i2c-polling.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index b31fa6fae009..d840e7be0036 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -768,6 +768,14 @@ config VIDEO_M52790
>>
>>To compile this driver as a module, choose M here: the
>>module will be called m52790.
>> +
>> +config VIDEO_I2C_POLLING
>> + tristate "I2C polling video support"
>> + depends on VIDEO_V4L2 && I2C
>> + select VIDEOBUF2_VMALLOC
>> + ---help---
>> +   Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -79,6 +79,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_POLLING)  += i2c-polling.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/i2c-polling.c
>> b/drivers/media/i2c/i2c-polling.c new file mode 100644
>> index ..46a4eecde2d2
>> --- /dev/null
>> +++ b/drivers/media/i2c/i2c-polling.c
>> @@ -0,0 +1,469 @@
>> +/*
>> + * i2c_polling.c - Support for polling I2C video devices
>> + *
>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>> + *
>> + * Based on the orginal work drivers/media/parport/bw-qcam.c
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * Supported:
>> + * - Panasonic AMG88xx Grid-Eye Sensors
>> + */
>> +
>> +#include 
>> +#include 
>
> I don't think you implement device tree support, is linux/of.h needed ? Or
> maybe you could implement device tree support ;-)
>
Indeed.

>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>
> You don't implement any control, you can drop support for control events as
> well.
>
>> +#include 
>
> Please sort includes alphabetically, it makes it easier to locate duplicates.
>
>> +#define I2C_POLLING_DRIVER   "i2c-polling"
>> +
&

[PATCH v3] media: i2c-polling: add i2c-polling driver

2016-11-22 Thread Matt Ranostay
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: Attila Kinali <att...@kinali.ch>
Cc: Marek Vasut <ma...@denx.de>
Cc: Luca Barbato <lu_z...@gentoo.org>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
Changes from v1:
* correct i2c_polling_remove() operations
* fixed delay calcuation in buffer_queue()
* add include linux/slab.h

Changes from v2:
* fix build error due to typo in include of slab.h

 drivers/media/i2c/Kconfig   |   8 +
 drivers/media/i2c/Makefile  |   1 +
 drivers/media/i2c/i2c-polling.c | 469 
 3 files changed, 478 insertions(+)
 create mode 100644 drivers/media/i2c/i2c-polling.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index b31fa6fae009..d840e7be0036 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -768,6 +768,14 @@ config VIDEO_M52790
 
 To compile this driver as a module, choose M here: the
 module will be called m52790.
+
+config VIDEO_I2C_POLLING
+   tristate "I2C polling video support"
+   depends on VIDEO_V4L2 && I2C
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -79,6 +79,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_POLLING)+= i2c-polling.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/i2c-polling.c b/drivers/media/i2c/i2c-polling.c
new file mode 100644
index ..46a4eecde2d2
--- /dev/null
+++ b/drivers/media/i2c/i2c-polling.c
@@ -0,0 +1,469 @@
+/*
+ * i2c_polling.c - Support for polling I2C video devices
+ *
+ * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
+ *
+ * Based on the orginal work drivers/media/parport/bw-qcam.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define I2C_POLLING_DRIVER "i2c-polling"
+
+struct i2c_polling_chip;
+
+struct i2c_polling_data {
+   struct i2c_client *client;
+   const struct i2c_polling_chip *chip;
+   struct mutex lock;
+   struct mutex queue_lock;
+   unsigned int last_update;
+
+   struct v4l2_device v4l2_dev;
+   struct video_device vdev;
+   struct vb2_queue vb_vidq;
+};
+
+static struct v4l2_fmtdesc amg88xx_format = {
+   .description = "12-bit Greyscale",
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct i2c_polling_chip {
+   /* video dimensions */
+   struct v4l2_fmtdesc *format;
+   struct v4l2_frmsize_discrete *size;
+
+   /* max frames per second */
+   unsigned int max_fps;
+
+   /* pixel buffer size */
+   unsigned int buffer_size;
+
+   /* xfer function */
+   int (*xfer)(struct i2c_polling_data *data, char *buf);
+};
+
+enum {
+   AMG88XX = 0,
+   I2C_POLLING_CHIP_CNT,
+};
+
+static int amg88xx_xfer(struct i2c_polling_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;
+}
+
+static const struct i2c_polling_chip i2c_polling_chips[I2C_POLLING_CHIP_CNT] = 

Re: [PATCH v2] media: i2c-polling: add i2c-polling driver

2016-11-08 Thread Matt Ranostay
On Mon, Nov 7, 2016 at 11:03 PM, Ozgur <okara...@member.fsf.org> wrote:
> Dear Matt;
>
> I think the "inux/slab.h" line is incorrect and I fixed to "linux/slab.h", I
> tested. Success now.
>
> Regards,
>
> ~ Ozgur
>
>>> -#include 
>>> +#include 

Gah wondering how it built for me. will fix in v3


>
>
> 2016-11-08 9:00 GMT+03:00 Matt Ranostay <matt@ranostay.consulting>:
>>
>> 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: Attila Kinali <att...@kinali.ch>
>> Cc: Marek Vasut <ma...@denx.de>
>> Cc: Luca Barbato <lu_z...@gentoo.org>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * correct i2c_polling_remove() operations
>> * fixed delay calcuation in buffer_queue()
>> * add include linux/slab.h
>>
>>  drivers/media/i2c/Kconfig   |   8 +
>>  drivers/media/i2c/Makefile  |   1 +
>>  drivers/media/i2c/i2c-polling.c | 469
>> 
>>  3 files changed, 478 insertions(+)
>>  create mode 100644 drivers/media/i2c/i2c-polling.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 2669b4bad910..6346eeecfaae 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -768,6 +768,14 @@ config VIDEO_M52790
>>
>>  To compile this driver as a module, choose M here: the
>>  module will be called m52790.
>> +
>> +config VIDEO_I2C_POLLING
>> +   tristate "I2C polling video support"
>> +   depends on VIDEO_V4L2 && I2C
>> +   select VIDEOBUF2_VMALLOC
>> +   ---help---
>> + Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -79,6 +79,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_POLLING)+= i2c-polling.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/i2c-polling.c
>> b/drivers/media/i2c/i2c-polling.c
>> new file mode 100644
>> index ..807f3aa84245
>> --- /dev/null
>> +++ b/drivers/media/i2c/i2c-polling.c
>> @@ -0,0 +1,469 @@
>> +/*
>> + * i2c_polling.c - Support for polling I2C video devices
>> + *
>> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
>> + *
>> + * Based on the orginal work drivers/media/parport/bw-qcam.c
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * Supported:
>> + * - Panasonic AMG88xx Grid-Eye Sensors
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define I2C_POLLING_DRIVER "i2c-polling"
>> +
>> +struct i2c_polling_chip;
>> +
>> +struct i2c_polling_data {
>> +   struct i2c_client *client;
>> +   const struct i2c_polling_chip *chip;
>> +   struct mutex lock;
>> +   struct mutex queue_lock;
>> +   unsigned int last_update;
>> +
>> +   struct v4l2_device v4l2_dev;
>> +   struct video_device vdev;
>> +   struct vb

[PATCH v2] media: i2c-polling: add i2c-polling driver

2016-11-07 Thread Matt Ranostay
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: Attila Kinali <att...@kinali.ch>
Cc: Marek Vasut <ma...@denx.de>
Cc: Luca Barbato <lu_z...@gentoo.org>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
Changes from v1:
* correct i2c_polling_remove() operations
* fixed delay calcuation in buffer_queue()
* add include linux/slab.h

 drivers/media/i2c/Kconfig   |   8 +
 drivers/media/i2c/Makefile  |   1 +
 drivers/media/i2c/i2c-polling.c | 469 
 3 files changed, 478 insertions(+)
 create mode 100644 drivers/media/i2c/i2c-polling.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 2669b4bad910..6346eeecfaae 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -768,6 +768,14 @@ config VIDEO_M52790
 
 To compile this driver as a module, choose M here: the
 module will be called m52790.
+
+config VIDEO_I2C_POLLING
+   tristate "I2C polling video support"
+   depends on VIDEO_V4L2 && I2C
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -79,6 +79,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_POLLING)+= i2c-polling.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/i2c-polling.c b/drivers/media/i2c/i2c-polling.c
new file mode 100644
index ..807f3aa84245
--- /dev/null
+++ b/drivers/media/i2c/i2c-polling.c
@@ -0,0 +1,469 @@
+/*
+ * i2c_polling.c - Support for polling I2C video devices
+ *
+ * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
+ *
+ * Based on the orginal work drivers/media/parport/bw-qcam.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define I2C_POLLING_DRIVER "i2c-polling"
+
+struct i2c_polling_chip;
+
+struct i2c_polling_data {
+   struct i2c_client *client;
+   const struct i2c_polling_chip *chip;
+   struct mutex lock;
+   struct mutex queue_lock;
+   unsigned int last_update;
+
+   struct v4l2_device v4l2_dev;
+   struct video_device vdev;
+   struct vb2_queue vb_vidq;
+};
+
+static struct v4l2_fmtdesc amg88xx_format = {
+   .description = "12-bit Greyscale",
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct i2c_polling_chip {
+   /* video dimensions */
+   struct v4l2_fmtdesc *format;
+   struct v4l2_frmsize_discrete *size;
+
+   /* max frames per second */
+   unsigned int max_fps;
+
+   /* pixel buffer size */
+   unsigned int buffer_size;
+
+   /* xfer function */
+   int (*xfer)(struct i2c_polling_data *data, char *buf);
+};
+
+enum {
+   AMG88XX = 0,
+   I2C_POLLING_CHIP_CNT,
+};
+
+static int amg88xx_xfer(struct i2c_polling_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;
+}
+
+static const struct i2c_polling_chip i2c_polling_chips[I2C_POLLING_CHIP_CNT] = 
{
+   [AMG88XX] = {
+   .size   = _size,
+   

Re: [PATCH] media: i2c-polling: add i2c-polling driver

2016-11-06 Thread Matt Ranostay
On Sun, Nov 6, 2016 at 5:21 PM, Matt Ranostay <mranos...@gmail.com> wrote:
> 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: Attila Kinali <att...@kinali.ch>
> Cc: Marek Vasut <ma...@denx.de>
> Cc: Luca Barbato <lu_z...@gentoo.org>
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
>  drivers/media/i2c/Kconfig   |   8 +
>  drivers/media/i2c/Makefile  |   1 +
>  drivers/media/i2c/i2c-polling.c | 466 
> 
>  3 files changed, 475 insertions(+)
>  create mode 100644 drivers/media/i2c/i2c-polling.c
>
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index 2669b4bad910..6346eeecfaae 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -768,6 +768,14 @@ config VIDEO_M52790
>
>  To compile this driver as a module, choose M here: the
>  module will be called m52790.
> +
> +config VIDEO_I2C_POLLING
> +   tristate "I2C polling video support"
> +   depends on VIDEO_V4L2 && I2C
> +   select VIDEOBUF2_VMALLOC
> +   ---help---
> + Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
> --- a/drivers/media/i2c/Makefile
> +++ b/drivers/media/i2c/Makefile
> @@ -79,6 +79,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_POLLING)+= i2c-polling.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/i2c-polling.c b/drivers/media/i2c/i2c-polling.c
> new file mode 100644
> index ..753e355b5fa9
> --- /dev/null
> +++ b/drivers/media/i2c/i2c-polling.c
> @@ -0,0 +1,466 @@
> +/*
> + * i2c_polling.c - Support for polling I2C video devices
> + *
> + * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
> + *
> + * Based on the orginal work drivers/media/parport/bw-qcam.c
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * Supported:
> + * - Panasonic AMG88xx Grid-Eye Sensors
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define I2C_POLLING_DRIVER "i2c-polling"
> +
> +struct i2c_polling_chip;
> +
> +struct i2c_polling_data {
> +   struct i2c_client *client;
> +   const struct i2c_polling_chip *chip;
> +   struct mutex lock;
> +   struct mutex queue_lock;
> +   unsigned int last_update;
> +
> +   struct v4l2_device v4l2_dev;
> +   struct video_device vdev;
> +   struct vb2_queue vb_vidq;
> +};
> +
> +static struct v4l2_fmtdesc amg88xx_format = {
> +   .description = "12-bit Greyscale",
> +   .pixelformat = V4L2_PIX_FMT_Y12,
> +};
> +
> +static struct v4l2_frmsize_discrete amg88xx_size = {
> +   .width = 8,
> +   .height = 8,
> +};
> +
> +struct i2c_polling_chip {
> +   /* video dimensions */
> +   struct v4l2_fmtdesc *format;
> +   struct v4l2_frmsize_discrete *size;
> +
> +   /* max frames per second */
> +   unsigned int max_fps;
> +
> +   /* pixel buffer size */
> +   unsigned int buffer_size;
> +
> +   /* xfer function */
> +   int (*xfer)(struct i2c_polling_data *data, char *buf);
> +};
> +
> +enum {
> +   AMG88XX = 0,
> +   I2C_POLLING_CHIP_CNT,
> +};
> +
> +static int amg88xx_xfer(struct i2c_polling_data *data, char *buf)
> +{
> +   struct i2c_client *client = data->cli

[PATCH] media: i2c-polling: add i2c-polling driver

2016-11-06 Thread Matt Ranostay
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: Attila Kinali <att...@kinali.ch>
Cc: Marek Vasut <ma...@denx.de>
Cc: Luca Barbato <lu_z...@gentoo.org>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
 drivers/media/i2c/Kconfig   |   8 +
 drivers/media/i2c/Makefile  |   1 +
 drivers/media/i2c/i2c-polling.c | 466 
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/media/i2c/i2c-polling.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 2669b4bad910..6346eeecfaae 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -768,6 +768,14 @@ config VIDEO_M52790
 
 To compile this driver as a module, choose M here: the
 module will be called m52790.
+
+config VIDEO_I2C_POLLING
+   tristate "I2C polling video support"
+   depends on VIDEO_V4L2 && I2C
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enable the I2C polling 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 92773b2e6225..8182ec9f66b9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -79,6 +79,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_POLLING)+= i2c-polling.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/i2c-polling.c b/drivers/media/i2c/i2c-polling.c
new file mode 100644
index ..753e355b5fa9
--- /dev/null
+++ b/drivers/media/i2c/i2c-polling.c
@@ -0,0 +1,466 @@
+/*
+ * i2c_polling.c - Support for polling I2C video devices
+ *
+ * Copyright (C) 2016 Matt Ranostay <mranostay@ranostay.consulting>
+ *
+ * Based on the orginal work drivers/media/parport/bw-qcam.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define I2C_POLLING_DRIVER "i2c-polling"
+
+struct i2c_polling_chip;
+
+struct i2c_polling_data {
+   struct i2c_client *client;
+   const struct i2c_polling_chip *chip;
+   struct mutex lock;
+   struct mutex queue_lock;
+   unsigned int last_update;
+
+   struct v4l2_device v4l2_dev;
+   struct video_device vdev;
+   struct vb2_queue vb_vidq;
+};
+
+static struct v4l2_fmtdesc amg88xx_format = {
+   .description = "12-bit Greyscale",
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct i2c_polling_chip {
+   /* video dimensions */
+   struct v4l2_fmtdesc *format;
+   struct v4l2_frmsize_discrete *size;
+
+   /* max frames per second */
+   unsigned int max_fps;
+
+   /* pixel buffer size */
+   unsigned int buffer_size;
+
+   /* xfer function */
+   int (*xfer)(struct i2c_polling_data *data, char *buf);
+};
+
+enum {
+   AMG88XX = 0,
+   I2C_POLLING_CHIP_CNT,
+};
+
+static int amg88xx_xfer(struct i2c_polling_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;
+}
+
+static const struct i2c_polling_chip i2c_polling_chips[I2C_POLLING_CHIP_CNT] = 
{
+   [AMG88XX] = {
+   .size   = _size,
+   .format = _format,
+   .max_fps= 10,
+   .buffer_size= 128,
+   .xfer

Re: [RFC] v4l2 support for thermopile devices

2016-11-03 Thread Matt Ranostay
On Thu, Nov 3, 2016 at 8:11 AM, Luca Barbato <lu_z...@gentoo.org> wrote:
> On 03/11/2016 14:21, Attila Kinali wrote:
>> On Wed, 2 Nov 2016 23:10:41 -0700
>> Matt Ranostay <matt@ranostay.consulting> wrote:
>>
>>>
>>> So does anyone know of any software that is using V4L2_PIX_FMT_Y12
>>> currently? Want to test my driver but seems there isn't anything that
>>> uses that format (ffmpeg, mplayer, etc).
>>>
>>> Raw data seems correct but would like to visualize it :). Suspect I'll
>>> need to write a test case application though
>>
>> I was pretty sure that MPlayer supports 12bit greyscale, but I cannot
>> find where it was handled. You can of course pass it to the MPlayer
>> internas as 8bit greyscale, which would be IMGFMT_Y8 or just pass
>> it on as 16bit which would be IMGFMT_Y16_LE (LE = little endian).
>>
>> You can find the internal #defines of the image formats in
>> libmpcodecs/img_format.h and can use https://www.fourcc.org/yuv.php
>> to decode their meaning.
>>
>> The equivalent for libav would be libavutil/pixfmt.h
>>
>> Luca Barbato tells me that adding Y12 support to libav would be easy.
>>
>>   Attila Kinali
>>
>
> So easy that is [done][1], it still needs to be tested/reviewed/polished
> though.

Cool. Although needs to be processed since it is signed value, and
because it it is really just 0C based readings with 0.25C steps.. But
will look into that when I get a chance.

Anyway did hack in basic support so v4l2grab so I could test the
sensor, and seems to work well but needs some colorized processing to
be useful of course.

Soldering iron about 1 meter from sensor -> http://imgur.com/a/8totG


>
> [1]:https://github.com/lu-zero/libav/commits/gray12
>
> lu
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] v4l2 support for thermopile devices

2016-11-03 Thread Matt Ranostay
On Fri, Oct 28, 2016 at 7:59 PM, Matt Ranostay <matt@ranostay.consulting> wrote:
> On Fri, Oct 28, 2016 at 2:53 PM, Hans Verkuil <hverk...@xs4all.nl> wrote:
>> Hi Matt,
>>
>> On 28/10/16 22:14, Matt Ranostay wrote:
>>>
>>> So want to toss a few thoughts on adding support for thermopile
>>> devices (could be used for FLIR Lepton as well) that output pixel
>>> data.
>>> These typically aren't DMA'able devices since they are low speed
>>> (partly to limiting the functionality to be in compliance with ITAR)
>>> and data is piped over i2c/spi.
>>>
>>> My question is that there doesn't seem to be an other driver that
>>> polls frames off of a device and pushes it to the video buffer, and
>>> wanted to be sure that this doesn't currently exist somewhere.
>>
>>
>> Not anymore, but if you go back to kernel 3.6 then you'll find this driver:
>>
>> drivers/media/video/bw-qcam.c
>>
>> It was for a grayscale parallel port webcam (which explains why it was
>> removed in 3.7 :-) ), and it used polling to get the pixels.
>
> Yikes parallel port, but I'll take a look at that for some reference :)


So does anyone know of any software that is using V4L2_PIX_FMT_Y12
currently? Want to test my driver but seems there isn't anything that
uses that format (ffmpeg, mplayer, etc).

Raw data seems correct but would like to visualize it :). Suspect I'll
need to write a test case application though


>
>>
>>> Also more importantly does the mailing list thinks it belongs in v4l2?
>>
>>
>> I think it fits. It's a sensor, just with a very small resolution and
>> infrared
>> instead of visible light.
>>
>>> We already came up the opinion on the IIO list that it doesn't belong
>>> in that subsystem since pushing raw pixel data to a buffer is a bit
>>> hacky. Also could be generically written with regmap so other devices
>>> (namely FLIR Lepton) could be easily supported.
>>>
>>> Need some input for the video pixel data types, which the device we
>>> are using (see datasheet links below) is outputting pixel data in
>>> little endian 16-bit of which a 12-bits signed value is used.  Does it
>>> make sense to do some basic processing on the data since greyscale is
>>> going to look weird with temperatures under 0C degrees? Namely a cold
>>> object is going to be brighter than the hottest object it could read.
>>
>>
>>> Or should a new V4L2_PIX_FMT_* be defined and processing done in
>>> software?
>>
>>
>> I would recommend that. It's no big deal, as long as the new format is
>> documented.
>>
>>> Another issue is how to report the scaling value of 0.25 C
>>> for each LSB of the pixels to the respecting recording application.
>>
>>
>> Probably through a read-only control, but I'm not sure.
>>
>> Regards,
>>
>> Hans
>>
>>>
>>> Datasheet:
>>> http://media.digikey.com/pdf/Data%20Sheets/Panasonic%20Sensors%20PDFs/Grid-EYE_AMG88.pdf
>>> Datasheet:
>>> https://eewiki.net/download/attachments/13599167/Grid-EYE%20SPECIFICATIONS%28Reference%29.pdf?version=1=1380660426690=v2
>>>
>>> Thanks,
>>>
>>> Matt
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-media" in
>>> the body of a message to majord...@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] v4l2 support for thermopile devices

2016-10-28 Thread Matt Ranostay
On Fri, Oct 28, 2016 at 2:53 PM, Hans Verkuil <hverk...@xs4all.nl> wrote:
> Hi Matt,
>
> On 28/10/16 22:14, Matt Ranostay wrote:
>>
>> So want to toss a few thoughts on adding support for thermopile
>> devices (could be used for FLIR Lepton as well) that output pixel
>> data.
>> These typically aren't DMA'able devices since they are low speed
>> (partly to limiting the functionality to be in compliance with ITAR)
>> and data is piped over i2c/spi.
>>
>> My question is that there doesn't seem to be an other driver that
>> polls frames off of a device and pushes it to the video buffer, and
>> wanted to be sure that this doesn't currently exist somewhere.
>
>
> Not anymore, but if you go back to kernel 3.6 then you'll find this driver:
>
> drivers/media/video/bw-qcam.c
>
> It was for a grayscale parallel port webcam (which explains why it was
> removed in 3.7 :-) ), and it used polling to get the pixels.

Yikes parallel port, but I'll take a look at that for some reference :)

>
>> Also more importantly does the mailing list thinks it belongs in v4l2?
>
>
> I think it fits. It's a sensor, just with a very small resolution and
> infrared
> instead of visible light.
>
>> We already came up the opinion on the IIO list that it doesn't belong
>> in that subsystem since pushing raw pixel data to a buffer is a bit
>> hacky. Also could be generically written with regmap so other devices
>> (namely FLIR Lepton) could be easily supported.
>>
>> Need some input for the video pixel data types, which the device we
>> are using (see datasheet links below) is outputting pixel data in
>> little endian 16-bit of which a 12-bits signed value is used.  Does it
>> make sense to do some basic processing on the data since greyscale is
>> going to look weird with temperatures under 0C degrees? Namely a cold
>> object is going to be brighter than the hottest object it could read.
>
>
>> Or should a new V4L2_PIX_FMT_* be defined and processing done in
>> software?
>
>
> I would recommend that. It's no big deal, as long as the new format is
> documented.
>
>> Another issue is how to report the scaling value of 0.25 C
>> for each LSB of the pixels to the respecting recording application.
>
>
> Probably through a read-only control, but I'm not sure.
>
> Regards,
>
> Hans
>
>>
>> Datasheet:
>> http://media.digikey.com/pdf/Data%20Sheets/Panasonic%20Sensors%20PDFs/Grid-EYE_AMG88.pdf
>> Datasheet:
>> https://eewiki.net/download/attachments/13599167/Grid-EYE%20SPECIFICATIONS%28Reference%29.pdf?version=1=1380660426690=v2
>>
>> Thanks,
>>
>> Matt
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-media" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] v4l2 support for thermopile devices

2016-10-28 Thread Matt Ranostay
On Fri, Oct 28, 2016 at 1:30 PM, Devin Heitmueller
 wrote:
> Hi Matt,
>
>> Need some input for the video pixel data types, which the device we
>> are using (see datasheet links below) is outputting pixel data in
>> little endian 16-bit of which a 12-bits signed value is used.  Does it
>> make sense to do some basic processing on the data since greyscale is
>> going to look weird with temperatures under 0C degrees? Namely a cold
>> object is going to be brighter than the hottest object it could read.
>> Or should a new V4L2_PIX_FMT_* be defined and processing done in
>> software?  Another issue is how to report the scaling value of 0.25 C
>> for each LSB of the pixels to the respecting recording application.
>
> Regarding the format for the pixel data:  I did some research into
> this when doing some driver work for the Seek Thermal (a product
> similar to the FLIR Lepton).  While it would be nice to be able to use
> an existing application like VLC or gStreamer to just take the video
> and capture from the V4L2 interface with no additional userland code,
> the reality is that how you colorize the data is going to be highly
> user specific (e.g. what thermal ranges to show with what colors,
> etc).  If your goal is really to do a V4L2 driver which returns the
> raw data, then you're probably best returning it in the native
> greyscale format (whether that be an existing V4L2 PIX_FMT or a new
> one needs to be defined), and then in software you can figure out how
> to colorize it.
>

Good point I was leaning to having userspace do it. But didn't think
of the color mapping part though so even more reason.

> Just my opinion though
>
> Devin
>
> --
> Devin J. Heitmueller - Kernel Labs
> http://www.kernellabs.com
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] v4l2 support for thermopile devices

2016-10-28 Thread Matt Ranostay
On Fri, Oct 28, 2016 at 1:40 PM, Marek Vasut  wrote:
> On 10/28/2016 10:30 PM, Devin Heitmueller wrote:
>> Hi Matt,
>>
>>> Need some input for the video pixel data types, which the device we
>>> are using (see datasheet links below) is outputting pixel data in
>>> little endian 16-bit of which a 12-bits signed value is used.  Does it
>>> make sense to do some basic processing on the data since greyscale is
>>> going to look weird with temperatures under 0C degrees? Namely a cold
>>> object is going to be brighter than the hottest object it could read.
>>> Or should a new V4L2_PIX_FMT_* be defined and processing done in
>>> software?  Another issue is how to report the scaling value of 0.25 C
>>> for each LSB of the pixels to the respecting recording application.
>>
>> Regarding the format for the pixel data:  I did some research into
>> this when doing some driver work for the Seek Thermal (a product
>> similar to the FLIR Lepton).  While it would be nice to be able to use
>> an existing application like VLC or gStreamer to just take the video
>> and capture from the V4L2 interface with no additional userland code,
>> the reality is that how you colorize the data is going to be highly
>> user specific (e.g. what thermal ranges to show with what colors,
>> etc).  If your goal is really to do a V4L2 driver which returns the
>> raw data, then you're probably best returning it in the native
>> greyscale format (whether that be an existing V4L2 PIX_FMT or a new
>> one needs to be defined), and then in software you can figure out how
>> to colorize it.
>
> All true, I also did my share of poking into SEEK Thermal USB and it is
> an excellent candidate for a V4L2 driver, that one. But I think this
> device here is producing much smaller images, something like 8x8 pixels.

Yes this is only 64 pixel (8x8 grid) but it is video still. Does have
some major pluses over a FLIR camera though, mainly power usage is
really low, and cost is lower (although that reason is decreasing
everyday).

>
> --
> Best regards,
> Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC] v4l2 support for thermopile devices

2016-10-28 Thread Matt Ranostay
So want to toss a few thoughts on adding support for thermopile
devices (could be used for FLIR Lepton as well) that output pixel
data.
These typically aren't DMA'able devices since they are low speed
(partly to limiting the functionality to be in compliance with ITAR)
and data is piped over i2c/spi.

My question is that there doesn't seem to be an other driver that
polls frames off of a device and pushes it to the video buffer, and
wanted to be sure that this doesn't currently exist somewhere.

Also more importantly does the mailing list thinks it belongs in v4l2?
We already came up the opinion on the IIO list that it doesn't belong
in that subsystem since pushing raw pixel data to a buffer is a bit
hacky. Also could be generically written with regmap so other devices
(namely FLIR Lepton) could be easily supported.

Need some input for the video pixel data types, which the device we
are using (see datasheet links below) is outputting pixel data in
little endian 16-bit of which a 12-bits signed value is used.  Does it
make sense to do some basic processing on the data since greyscale is
going to look weird with temperatures under 0C degrees? Namely a cold
object is going to be brighter than the hottest object it could read.
Or should a new V4L2_PIX_FMT_* be defined and processing done in
software?  Another issue is how to report the scaling value of 0.25 C
for each LSB of the pixels to the respecting recording application.

Datasheet: 
http://media.digikey.com/pdf/Data%20Sheets/Panasonic%20Sensors%20PDFs/Grid-EYE_AMG88.pdf
Datasheet: 
https://eewiki.net/download/attachments/13599167/Grid-EYE%20SPECIFICATIONS%28Reference%29.pdf?version=1=1380660426690=v2

Thanks,

Matt
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html