Re: [PATCH 3/4] media: Add Mediatek MDP Driver

2016-07-21 Thread Minghsiu Tsai
On Mon, 2016-07-18 at 14:18 +0200, Hans Verkuil wrote:
> On 07/14/2016 02:18 PM, Minghsiu Tsai wrote:
> > Add MDP driver for MT8173
> > 
> > Signed-off-by: Minghsiu Tsai 
> > ---
> >  drivers/media/platform/Kconfig|   16 +
> >  drivers/media/platform/Makefile   |2 +
> >  drivers/media/platform/mtk-mdp/Makefile   |9 +
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.c |  159 +++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |   72 ++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_core.c |  294 ++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_core.h |  233 +
> >  drivers/media/platform/mtk-mdp/mtk_mdp_ipi.h  |  126 +++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  | 1304 
> > +
> >  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.h  |   22 +
> >  drivers/media/platform/mtk-mdp/mtk_mdp_regs.c |  153 +++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_regs.h |   31 +
> >  drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c  |  140 +++
> >  drivers/media/platform/mtk-mdp/mtk_mdp_vpu.h  |   41 +
> >  14 files changed, 2602 insertions(+)
> >  create mode 100644 drivers/media/platform/mtk-mdp/Makefile
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_core.c
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_core.h
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_ipi.h
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.h
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_regs.c
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_regs.h
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c
> >  create mode 100644 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.h
> > 
> > diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> > index 2c2670c..782b618 100644
> > --- a/drivers/media/platform/Kconfig
> > +++ b/drivers/media/platform/Kconfig
> > @@ -166,6 +166,22 @@ config VIDEO_MEDIATEK_VPU
> > To compile this driver as a module, choose M here: the
> > module will be called mtk-vpu.
> >  
> > +config VIDEO_MEDIATEK_MDP
> > +   tristate "Mediatek MDP driver"
> > +   depends on MTK_IOMMU || COMPILE_TEST
> > +   depends on VIDEO_DEV && VIDEO_V4L2
> > +   depends on ARCH_MEDIATEK || COMPILE_TEST
> > +   select VIDEOBUF2_DMA_CONTIG
> > +   select V4L2_MEM2MEM_DEV
> > +   select VIDEO_MEDIATEK_VPU
> > +   default n
> > +   ---help---
> > +   It is a v4l2 driver and present in Mediatek MT8173 SoCs.
> > +   The driver supports for scaling and color space conversion.
> > +
> > +   To compile this driver as a module, choose M here: the
> > +   module will be called mtk-mdp.
> > +
> >  config VIDEO_MEDIATEK_VCODEC
> > tristate "Mediatek Video Codec driver"
> > depends on MTK_IOMMU || COMPILE_TEST
> > diff --git a/drivers/media/platform/Makefile 
> > b/drivers/media/platform/Makefile
> > index c6b3b92..9c54f1a 100644
> > --- a/drivers/media/platform/Makefile
> > +++ b/drivers/media/platform/Makefile
> > @@ -62,3 +62,5 @@ ccflags-y += -I$(srctree)/drivers/media/i2c
> >  obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
> >  
> >  obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC)+= mtk-vcodec/
> > +
> > +obj-$(CONFIG_VIDEO_MEDIATEK_MDP)   += mtk-mdp/
> > diff --git a/drivers/media/platform/mtk-mdp/Makefile 
> > b/drivers/media/platform/mtk-mdp/Makefile
> > new file mode 100644
> > index 000..f802569
> > --- /dev/null
> > +++ b/drivers/media/platform/mtk-mdp/Makefile
> > @@ -0,0 +1,9 @@
> > +mtk-mdp-y += mtk_mdp_core.o
> > +mtk-mdp-y += mtk_mdp_comp.o
> > +mtk-mdp-y += mtk_mdp_m2m.o
> > +mtk-mdp-y += mtk_mdp_regs.o
> > +mtk-mdp-y += mtk_mdp_vpu.o
> > +
> > +obj-$(CONFIG_VIDEO_MEDIATEK_MDP) += mtk-mdp.o
> > +
> > +ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
> > diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
> > b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > new file mode 100644
> > index 000..aa8f9fd
> > --- /dev/null
> > +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > @@ -0,0 +1,159 @@
> > +/*
> > + * Copyright (c) 2016 MediaTek Inc.
> > + * Author: Ming Hsiu Tsai 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + *
> > + * 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.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 

Re: [PATCH v6 0/2] [media] atmel-isc: add driver for Atmel ISC

2016-07-21 Thread Wu, Songjun



On 7/21/2016 16:41, Hans Verkuil wrote:



On 07/21/2016 10:14 AM, Songjun Wu wrote:

The Image Sensor Controller driver includes two parts.
1) Driver code to implement the ISC function.
2) Device tree binding documentation, it describes how
   to add the ISC in device tree.

Test result with v4l-utils 1.10.1


Please compile from the v4l-utils repository. The version you used here is 
out-of-date.
I continually add new tests, so always compile the latest version from the repo.


OK, I will compile the latest version from the v4l-utils repository.
Thank you.


Regards,

Hans


Driver Info:
Driver name   : atmel_isc
Card type : Atmel Image Sensor Controller
Bus info  : platform:atmel_isc f0008000.isc
Driver version: 4.7.0
Capabilities  : 0x8421
Video Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0421
Video Capture
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: 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)

Test input 0:

Control ioctls:
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:
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:
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:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK

Test input 0:

Stream using all formats:
test MMAP for Format BA81, Frame Size 640x480:
Stride 640, Field None: OK
test MMAP for Format YUYV, Frame Size 640x480:
Stride 1280, Field None: OK

Total: 44, Succeeded: 44, Failed: 0, Warnings: 0

Changes in v6:
- Add "iscck" and "gck" to clock-names.

Changes in v5:
- Modify the macro definition and the related code.
- Add clock-output-names.

Changes in v4:
- Modify the isc clock code since the dt is changed.
- Remove the isc clock nodes.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.
- Remove the 'atmel,sensor-preferred'.
- Modify the isc clock node according to the Rob's remarks.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
  in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
  with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in
  'isc_queue_setup' function.
- Invoke isc_config to configure register in
  'isc_start_streaming' function.
- Add the struct completion 'comp' to 

Re: [PATCH v6 1/2] [media] atmel-isc: add the Image Sensor Controller code

2016-07-21 Thread Wu, Songjun



On 7/21/2016 17:13, Hans Verkuil wrote:



On 07/21/2016 10:14 AM, Songjun Wu wrote:

Add driver for the Image Sensor Controller. It manages
incoming data from a parallel based CMOS/CCD sensor.
It has an internal image processor, also integrates a
triple channel direct memory access controller master
interface.

Signed-off-by: Songjun Wu 
---

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
  in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
  with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in
  'isc_queue_setup' function.
- Invoke isc_config to configure register in
  'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with
  the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
  in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
  in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and
  initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner  = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with
  module_platform_driver().

 drivers/media/platform/Kconfig|1 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/atmel/Kconfig  |9 +
 drivers/media/platform/atmel/Makefile |1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c  | 1554 +
 6 files changed, 1732 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index f25344b..b23db17 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -111,6 +111,7 @@ source "drivers/media/platform/s5p-tv/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
+source "drivers/media/platform/atmel/Kconfig"

 config VIDEO_TI_CAL
tristate "TI CAL (Camera Adaptation Layer) driver"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 21771c1..37b6c75 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -58,6 +58,8 @@ obj-$(CONFIG_VIDEO_XILINX)+= xilinx/

 obj-$(CONFIG_VIDEO_RCAR_VIN)   += rcar-vin/

+obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c

 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/atmel/Kconfig 
b/drivers/media/platform/atmel/Kconfig
new file mode 100644
index 000..867dca2
--- /dev/null
+++ b/drivers/media/platform/atmel/Kconfig
@@ -0,0 +1,9 @@
+config VIDEO_ATMEL_ISC
+   tristate "ATMEL Image Sensor Controller (ISC) support"
+   depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA
+   depends on ARCH_AT91 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select REGMAP_MMIO
+   help
+  This module makes the ATMEL Image Sensor Controller available
+  as a v4l2 device.
\ No newline at end of file
diff --git a/drivers/media/platform/atmel/Makefile 
b/drivers/media/platform/atmel/Makefile
new file mode 100644
index 000..9d7c999
--- /dev/null
+++ b/drivers/media/platform/atmel/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_ATMEL_ISC) += atmel-isc.o
diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h 
b/drivers/media/platform/atmel/atmel-isc-regs.h
new file mode 100644
index 000..00c4497
--- /dev/null
+++ b/drivers/media/platform/atmel/atmel-isc-regs.h
@@ -0,0 +1,165 @@
+#ifndef __ATMEL_ISC_REGS_H
+#define __ATMEL_ISC_REGS_H
+
+#include 
+
+/* ISC Control Enable Register 0 */
+#define ISC_CTRLEN  0x
+
+/* ISC Control Disable Register 0 */
+#define ISC_CTRLDIS 0x0004
+
+/* ISC Control Status Register 0 */
+#define ISC_CTRLSR  0x0008
+
+#define ISC_CTRL_CAPTURE   BIT(0)
+#define ISC_CTRL_UPPRO BIT(1)
+#define ISC_CTRL_HISREQBIT(2)
+#define ISC_CTRL_HISCLRBIT(3)

cron job: media_tree daily build: WARNINGS

2016-07-21 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Fri Jul 22 04:00:17 CEST 2016
git branch: test
git hash:   009a620848218d521f008141c62f56bf19294dd9
gcc version:i686-linux-gcc (GCC) 5.3.0
sparse version: v0.5.0-56-g7647c77
smatch version: v0.5.0-3428-gdfe27cf
host hardware:  x86_64
host os:4.6.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-blackfin-bf561: OK
linux-git-i686: WARNINGS
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: WARNINGS
linux-2.6.36.4-i686: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.2.37-i686: WARNINGS
linux-3.3.8-i686: WARNINGS
linux-3.4.27-i686: WARNINGS
linux-3.5.7-i686: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.12.23-i686: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.16.7-i686: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.18.7-i686: WARNINGS
linux-3.19-i686: WARNINGS
linux-4.0-i686: WARNINGS
linux-4.1.1-i686: WARNINGS
linux-4.2-i686: WARNINGS
linux-4.3-i686: WARNINGS
linux-4.4-i686: WARNINGS
linux-4.5-i686: WARNINGS
linux-4.6-i686: WARNINGS
linux-4.7-rc1-i686: WARNINGS
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.37-x86_64: WARNINGS
linux-3.3.8-x86_64: WARNINGS
linux-3.4.27-x86_64: WARNINGS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.23-x86_64: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.7-x86_64: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.7-x86_64: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0-x86_64: WARNINGS
linux-4.1.1-x86_64: WARNINGS
linux-4.2-x86_64: WARNINGS
linux-4.3-x86_64: WARNINGS
linux-4.4-x86_64: WARNINGS
linux-4.5-x86_64: WARNINGS
linux-4.6-x86_64: WARNINGS
linux-4.7-rc1-x86_64: WARNINGS
apps: OK
spec-git: OK
sparse: WARNINGS
smatch: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.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: [PATCH v6 2/2] [media] atmel-isc: DT binding for Image Sensor Controller driver

2016-07-21 Thread Rob Herring
On Thu, Jul 21, 2016 at 04:14:58PM +0800, Songjun Wu wrote:
> DT binding documentation for ISC driver.
> 
> Signed-off-by: Songjun Wu 
> ---
> 
> Changes in v6:
> - Add "iscck" and "gck" to clock-names.
> 
> Changes in v5:
> - Add clock-output-names.
> 
> Changes in v4:
> - Remove the isc clock nodes.
> 
> Changes in v3:
> - Remove the 'atmel,sensor-preferred'.
> - Modify the isc clock node according to the Rob's remarks.
> 
> Changes in v2:
> - Remove the unit address of the endpoint.
> - Add the unit address to the clock node.
> - Avoid using underscores in node names.
> - Drop the "0x" in the unit address of the i2c node.
> - Modify the description of 'atmel,sensor-preferred'.
> - Add the description for the ISC internal clock.
> 
>  .../devicetree/bindings/media/atmel-isc.txt| 65 
> ++
>  1 file changed, 65 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/media/atmel-isc.txt

Acked-by: Rob Herring 
--
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


[PATCH 5/5] [media] v4l2-dev: add cross-references and improve markup

2016-07-21 Thread Mauro Carvalho Chehab
Add cross-references for the functions/structs and add
the markup tags to improve its display.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-dev.rst   | 352 +++-
 Documentation/media/kapi/v4l2-videobuf.rst  |   2 +
 Documentation/media/kapi/v4l2-videobuf2.rst |   2 +
 3 files changed, 190 insertions(+), 166 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-dev.rst 
b/Documentation/media/kapi/v4l2-dev.rst
index f9b75d211ca0..306306d8a43d 100644
--- a/Documentation/media/kapi/v4l2-dev.rst
+++ b/Documentation/media/kapi/v4l2-dev.rst
@@ -1,13 +1,13 @@
 Video device creation
 =
 
-The actual device nodes in the /dev directory are created using the
-video_device struct (v4l2-dev.h). This struct can either be allocated
-dynamically or embedded in a larger struct.
+The actual device nodes in the ``/dev`` directory are created using the
+:c:type:`video_device` struct (``v4l2-dev.h``). This struct can either be
+allocated dynamically or embedded in a larger struct.
 
-To allocate it dynamically use:
+To allocate it dynamically use :cpp:func:`video_device_alloc`:
 
-.. code-block:: none
+.. code-block:: c
 
struct video_device *vdev = video_device_alloc();
 
@@ -16,100 +16,110 @@ To allocate it dynamically use:
 
vdev->release = video_device_release;
 
-If you embed it in a larger struct, then you must set the release()
+If you embed it in a larger struct, then you must set the ``release()``
 callback to your own function:
 
-.. code-block:: none
+.. code-block:: c
 
struct video_device *vdev = _vdev->vdev;
 
vdev->release = my_vdev_release;
 
-The release callback must be set and it is called when the last user
+The ``release()`` callback must be set and it is called when the last user
 of the video device exits.
 
-The default video_device_release() callback just calls kfree to free the
-allocated memory.
-
-There is also a video_device_release_empty() function that does nothing
-(is empty) and can be used if the struct is embedded and there is nothing
-to do when it is released.
-
-You should also set these fields:
-
-- v4l2_dev: must be set to the v4l2_device parent device.
-
-- name: set to something descriptive and unique.
-
-- vfl_dir: set this to VFL_DIR_RX for capture devices (VFL_DIR_RX has value 0,
-  so this is normally already the default), set to VFL_DIR_TX for output
-  devices and VFL_DIR_M2M for mem2mem (codec) devices.
-
-- fops: set to the v4l2_file_operations struct.
-
-- ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance
-  (highly recommended to use this and it might become compulsory in the
-  future!), then set this to your v4l2_ioctl_ops struct. The vfl_type and
-  vfl_dir fields are used to disable ops that do not match the type/dir
-  combination. E.g. VBI ops are disabled for non-VBI nodes, and output ops
-  are disabled for a capture device. This makes it possible to provide
-  just one v4l2_ioctl_ops struct for both vbi and video nodes.
-
-- lock: leave to NULL if you want to do all the locking in the driver.
-  Otherwise you give it a pointer to a struct mutex_lock and before the
-  unlocked_ioctl file operation is called this lock will be taken by the
-  core and released afterwards. See the next section for more details.
-
-- queue: a pointer to the struct vb2_queue associated with this device node.
-  If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is
-  used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF,
-  QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above.
-  That way the vb2 queuing framework does not have to wait for other ioctls.
-  This queue pointer is also used by the vb2 helper functions to check for
+The default :cpp:func:`video_device_release` callback currently
+just calls ``kfree`` to free the allocated memory.
+
+There is also a ::cpp:func:`video_device_release_empty` function that does
+nothing (is empty) and should be used if the struct is embedded and there
+is nothing to do when it is released.
+
+You should also set these fields of :c:type:`video_device`:
+
+- :c:type:`video_device`->v4l2_dev: must be set to the :c:type:`v4l2_device`
+  parent device.
+
+- :c:type:`video_device`->name: set to something descriptive and unique.
+
+- :c:type:`video_device`->vfl_dir: set this to ``VFL_DIR_RX`` for capture
+  devices (``VFL_DIR_RX`` has value 0, so this is normally already the
+  default), set to ``VFL_DIR_TX`` for output devices and ``VFL_DIR_M2M`` for 
mem2mem (codec) devices.
+
+- :c:type:`video_device`->fops: set to the :c:type:`v4l2_file_operations`
+  struct.
+
+- :c:type:`video_device`->ioctl_ops: if you use the :c:type:`v4l2_ioctl_ops`
+  to simplify ioctl maintenance (highly recommended to use this and it might
+  become compulsory in the future!), then set this to your
+  :c:type:`v4l2_ioctl_ops` struct. The :c:type:`video_device`->vfl_type 

[PATCH 1/5] [media] v4l2-common.h: Add documentation for other functions

2016-07-21 Thread Mauro Carvalho Chehab
Not all functions at v4l2-common.h are documented. Add
documentation for some other ones.

Signed-off-by: Mauro Carvalho Chehab 
---
 include/media/v4l2-common.h | 43 ++-
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 9b1dfcd9e229..350cbf9fb10e 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -78,9 +78,26 @@
v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \
} while (0)
 
-/* - */
+/**
+ * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl
+ *
+ * @qctrl: pointer to the  v4l2_queryctrl to be filled
+ * @min: minimum value for the control
+ * @max: maximum value for the control
+ * @step: control step
+ * @def: default value for the control
+ *
+ * Fills the  v4l2_queryctrl fields for the query control.
+ *
+ * .. note::
+ *
+ *This function assumes that the @qctrl->id field is filled.
+ *
+ * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.
+ */
 
-int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 
step, s32 def);
+int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
+s32 min, s32 max, s32 step, s32 def);
 
 /* - */
 
@@ -172,12 +189,28 @@ const unsigned short *v4l2_i2c_tuner_addrs(enum 
v4l2_i2c_tuner_type type);
 
 struct spi_device;
 
-/* Load an spi module and return an initialized v4l2_subdev struct.
-   The client_type argument is the name of the chip that's on the adapter. */
+/**
+ *  v4l2_spi_new_subdev - Load an spi module and return an initialized
+ *  v4l2_subdev.
+ *
+ *
+ * @v4l2_dev: pointer to  v4l2_device.
+ * @master: pointer to struct spi_master.
+ * @info: pointer to struct spi_board_info.
+ *
+ * returns a  v4l2_subdev pointer.
+ */
 struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
struct spi_master *master, struct spi_board_info *info);
 
-/* Initialize a v4l2_subdev with data from an spi_device struct */
+/**
+ * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
+ * spi_device struct.
+ *
+ * @sd: pointer to  v4l2_subdev
+ * @spi: pointer to struct spi_device.
+ * @ops: pointer to  v4l2_subdev_ops
+ */
 void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
const struct v4l2_subdev_ops *ops);
 #endif
-- 
2.7.4

--
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


[PATCH 4/5] [media] doc-rst: move v4l2-dev doc to a separate file

2016-07-21 Thread Mauro Carvalho Chehab
Move the documentation for video device node creation to
a separate file.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-core.rst  |   1 +
 Documentation/media/kapi/v4l2-dev.rst   | 343 +++
 Documentation/media/kapi/v4l2-framework.rst | 344 
 3 files changed, 344 insertions(+), 344 deletions(-)
 create mode 100644 Documentation/media/kapi/v4l2-dev.rst

diff --git a/Documentation/media/kapi/v4l2-core.rst 
b/Documentation/media/kapi/v4l2-core.rst
index fc623e9ca871..6fa30f8908dd 100644
--- a/Documentation/media/kapi/v4l2-core.rst
+++ b/Documentation/media/kapi/v4l2-core.rst
@@ -5,6 +5,7 @@ Video2Linux devices
 :maxdepth: 1
 
 v4l2-framework
+v4l2-dev
 v4l2-controls
 v4l2-device
 v4l2-dv-timings
diff --git a/Documentation/media/kapi/v4l2-dev.rst 
b/Documentation/media/kapi/v4l2-dev.rst
new file mode 100644
index ..f9b75d211ca0
--- /dev/null
+++ b/Documentation/media/kapi/v4l2-dev.rst
@@ -0,0 +1,343 @@
+Video device creation
+=
+
+The actual device nodes in the /dev directory are created using the
+video_device struct (v4l2-dev.h). This struct can either be allocated
+dynamically or embedded in a larger struct.
+
+To allocate it dynamically use:
+
+.. code-block:: none
+
+   struct video_device *vdev = video_device_alloc();
+
+   if (vdev == NULL)
+   return -ENOMEM;
+
+   vdev->release = video_device_release;
+
+If you embed it in a larger struct, then you must set the release()
+callback to your own function:
+
+.. code-block:: none
+
+   struct video_device *vdev = _vdev->vdev;
+
+   vdev->release = my_vdev_release;
+
+The release callback must be set and it is called when the last user
+of the video device exits.
+
+The default video_device_release() callback just calls kfree to free the
+allocated memory.
+
+There is also a video_device_release_empty() function that does nothing
+(is empty) and can be used if the struct is embedded and there is nothing
+to do when it is released.
+
+You should also set these fields:
+
+- v4l2_dev: must be set to the v4l2_device parent device.
+
+- name: set to something descriptive and unique.
+
+- vfl_dir: set this to VFL_DIR_RX for capture devices (VFL_DIR_RX has value 0,
+  so this is normally already the default), set to VFL_DIR_TX for output
+  devices and VFL_DIR_M2M for mem2mem (codec) devices.
+
+- fops: set to the v4l2_file_operations struct.
+
+- ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance
+  (highly recommended to use this and it might become compulsory in the
+  future!), then set this to your v4l2_ioctl_ops struct. The vfl_type and
+  vfl_dir fields are used to disable ops that do not match the type/dir
+  combination. E.g. VBI ops are disabled for non-VBI nodes, and output ops
+  are disabled for a capture device. This makes it possible to provide
+  just one v4l2_ioctl_ops struct for both vbi and video nodes.
+
+- lock: leave to NULL if you want to do all the locking in the driver.
+  Otherwise you give it a pointer to a struct mutex_lock and before the
+  unlocked_ioctl file operation is called this lock will be taken by the
+  core and released afterwards. See the next section for more details.
+
+- queue: a pointer to the struct vb2_queue associated with this device node.
+  If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is
+  used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF,
+  QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above.
+  That way the vb2 queuing framework does not have to wait for other ioctls.
+  This queue pointer is also used by the vb2 helper functions to check for
+  queuing ownership (i.e. is the filehandle calling it allowed to do the
+  operation).
+
+- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY.
+  If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device.
+  If you want to have a separate priority state per (group of) device node(s),
+  then you can point it to your own struct v4l2_prio_state.
+
+- dev_parent: you only set this if v4l2_device was registered with NULL as
+  the parent device struct. This only happens in cases where one hardware
+  device has multiple PCI devices that all share the same v4l2_device core.
+
+  The cx88 driver is an example of this: one core v4l2_device struct, but
+  it is used by both a raw video PCI device (cx8800) and a MPEG PCI device
+  (cx8802). Since the v4l2_device cannot be associated with two PCI devices
+  at the same time it is setup without a parent device. But when the struct
+  video_device is initialized you *do* know which parent PCI device to use and
+  so you set dev_device to the correct PCI device.
+
+If you use v4l2_ioctl_ops, then you should set .unlocked_ioctl to video_ioctl2
+in your v4l2_file_operations struct.
+
+Do not use .ioctl! This is 

[PATCH 2/5] [media] mc-core: Fix a cross-reference

2016-07-21 Thread Mauro Carvalho Chehab
The v4l2_subdev reference was using the wrong tag. Fix it.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/mc-core.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/media/kapi/mc-core.rst 
b/Documentation/media/kapi/mc-core.rst
index 4c47f5e3611d..deae3b7c692d 100644
--- a/Documentation/media/kapi/mc-core.rst
+++ b/Documentation/media/kapi/mc-core.rst
@@ -50,7 +50,7 @@ Entities
 Entities are represented by a :c:type:`struct media_entity `
 instance, defined in ``include/media/media-entity.h``. The structure is usually
 embedded into a higher-level structure, such as
-:ref:`v4l2_subdev` or :ref:`video_device`
+:c:type:`v4l2_subdev` or :c:type:`video_device`
 instances, although drivers can allocate entities directly.
 
 Drivers initialize entity pads by calling
-- 
2.7.4

--
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


[PATCH 3/5] [media] doc-rst: document v4l2-dev.h

2016-07-21 Thread Mauro Carvalho Chehab
Add documentation for v4l2-dev.h, and put it at v4l2-framework.rst,
where struct video_device is currently documented.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-framework.rst |   5 +
 drivers/media/v4l2-core/v4l2-dev.c  |  34 ---
 include/media/v4l2-dev.h| 364 
 3 files changed, 320 insertions(+), 83 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-framework.rst 
b/Documentation/media/kapi/v4l2-framework.rst
index de341fc5b235..315388ef6593 100644
--- a/Documentation/media/kapi/v4l2-framework.rst
+++ b/Documentation/media/kapi/v4l2-framework.rst
@@ -699,3 +699,8 @@ methods.
 
 It is expected that once the CCF becomes available on all relevant
 architectures this API will be removed.
+
+video_device kAPI
+^
+
+.. kernel-doc:: include/media/v4l2-dev.h
diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index 70b559d7ca80..e6da353b39bc 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -812,40 +812,6 @@ static int video_register_media_controller(struct 
video_device *vdev, int type)
return 0;
 }
 
-/**
- * __video_register_device - register video4linux devices
- * @vdev: video device structure we want to register
- * @type: type of device to register
- * @nr:   which device node number (0 == /dev/video0, 1 == /dev/video1, ...
- * -1 == first free)
- * @warn_if_nr_in_use: warn if the desired device node number
- *was already in use and another number was chosen instead.
- * @owner: module that owns the video device node
- *
- * The registration code assigns minor numbers and device node numbers
- * based on the requested type and registers the new device node with
- * the kernel.
- *
- * This function assumes that struct video_device was zeroed when it
- * was allocated and does not contain any stale date.
- *
- * An error is returned if no free minor or device node number could be
- * found, or if the registration of the device node failed.
- *
- * Zero is returned on success.
- *
- * Valid types are
- *
- * %VFL_TYPE_GRABBER - A frame grabber
- *
- * %VFL_TYPE_VBI - Vertical blank data (undecoded)
- *
- * %VFL_TYPE_RADIO - A radio card
- *
- * %VFL_TYPE_SUBDEV - A subdevice
- *
- * %VFL_TYPE_SDR - Software Defined Radio
- */
 int __video_register_device(struct video_device *vdev, int type, int nr,
int warn_if_nr_in_use, struct module *owner)
 {
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 25a3190308fb..5921c24565cf 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -47,19 +47,105 @@ struct v4l2_ctrl_handler;
 
 /* Priority helper functions */
 
+/**
+ * struct v4l2_prio_state - stores the priority states
+ *
+ * @prios: array with elements to store the array priorities
+ *
+ *
+ * .. note::
+ *The size of @prios array matches the number of priority types defined
+ *by :ref:`enum v4l2_priority `.
+ */
 struct v4l2_prio_state {
atomic_t prios[4];
 };
 
+/**
+ * v4l2_prio_init - initializes a struct v4l2_prio_state
+ *
+ * @global: pointer to  v4l2_prio_state
+ */
 void v4l2_prio_init(struct v4l2_prio_state *global);
+
+/**
+ * v4l2_prio_change - changes the v4l2 file handler priority
+ *
+ * @global: pointer to the  v4l2_prio_state of the device node.
+ * @local: pointer to the desired priority, as defined by :ref:`enum 
v4l2_priority `
+ * @new: Priority type requested, as defined by :ref:`enum v4l2_priority 
`.
+ *
+ * .. note::
+ * This function should be used only by the V4L2 core.
+ */
 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
 enum v4l2_priority new);
+
+/**
+ * v4l2_prio_open - Implements the priority logic for a file handler open
+ *
+ * @global: pointer to the  v4l2_prio_state of the device node.
+ * @local: pointer to the desired priority, as defined by :ref:`enum 
v4l2_priority `
+ *
+ * .. note::
+ * This function should be used only by the V4L2 core.
+ */
 void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+
+/**
+ * v4l2_prio_close - Implements the priority logic for a file handler close
+ *
+ * @global: pointer to the  v4l2_prio_state of the device node.
+ * @local: priority to be released, as defined by :ref:`enum v4l2_priority 
`
+ *
+ * .. note::
+ * This function should be used only by the V4L2 core.
+ */
 void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
+
+/**
+ * v4l2_prio_max - Return the maximum priority, as stored at the @global array.
+ *
+ * @global: pointer to the  v4l2_prio_state of the device node.
+ *
+ * .. note::
+ * This function should be used only by the V4L2 core.
+ */
 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
+
+/**
+ * 

[PATCH 10/12] [media] v4l2-subdev.rst: add two sections from v4l2-framework.rst

2016-07-21 Thread Mauro Carvalho Chehab
There are two additional subdev-specific sections at the
v4l2-framework file. Move them to the subdev chapter, in order
to better organize the book.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-framework.rst | 165 ---
 Documentation/media/kapi/v4l2-subdev.rst| 166 
 2 files changed, 166 insertions(+), 165 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-framework.rst 
b/Documentation/media/kapi/v4l2-framework.rst
index a7f64b38af5c..de341fc5b235 100644
--- a/Documentation/media/kapi/v4l2-framework.rst
+++ b/Documentation/media/kapi/v4l2-framework.rst
@@ -80,171 +80,6 @@ The V4L2 framework also optionally integrates with the 
media framework. If a
 driver sets the struct v4l2_device mdev field, sub-devices and video nodes
 will automatically appear in the media framework as entities.
 
-V4L2 sub-device userspace API
--
-
-Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2
-sub-devices can also be controlled directly by userspace applications.
-
-Device nodes named v4l-subdevX can be created in /dev to access sub-devices
-directly. If a sub-device supports direct userspace configuration it must set
-the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered.
-
-After registering sub-devices, the v4l2_device driver can create device nodes
-for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by 
calling
-v4l2_device_register_subdev_nodes(). Those device nodes will be automatically
-removed when sub-devices are unregistered.
-
-The device node handles a subset of the V4L2 API.
-
-VIDIOC_QUERYCTRL
-VIDIOC_QUERYMENU
-VIDIOC_G_CTRL
-VIDIOC_S_CTRL
-VIDIOC_G_EXT_CTRLS
-VIDIOC_S_EXT_CTRLS
-VIDIOC_TRY_EXT_CTRLS
-
-   The controls ioctls are identical to the ones defined in V4L2. They
-   behave identically, with the only exception that they deal only with
-   controls implemented in the sub-device. Depending on the driver, those
-   controls can be also be accessed through one (or several) V4L2 device
-   nodes.
-
-VIDIOC_DQEVENT
-VIDIOC_SUBSCRIBE_EVENT
-VIDIOC_UNSUBSCRIBE_EVENT
-
-   The events ioctls are identical to the ones defined in V4L2. They
-   behave identically, with the only exception that they deal only with
-   events generated by the sub-device. Depending on the driver, those
-   events can also be reported by one (or several) V4L2 device nodes.
-
-   Sub-device drivers that want to use events need to set the
-   V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags and initialize
-   v4l2_subdev::nevents to events queue depth before registering the
-   sub-device. After registration events can be queued as usual on the
-   v4l2_subdev::devnode device node.
-
-   To properly support events, the poll() file operation is also
-   implemented.
-
-Private ioctls
-
-   All ioctls not in the above list are passed directly to the sub-device
-   driver through the core::ioctl operation.
-
-
-I2C sub-device drivers
---
-
-Since these drivers are so common, special helper functions are available to
-ease the use of these drivers (v4l2-common.h).
-
-The recommended method of adding v4l2_subdev support to an I2C driver is to
-embed the v4l2_subdev struct into the state struct that is created for each
-I2C device instance. Very simple devices have no state struct and in that case
-you can just create a v4l2_subdev directly.
-
-A typical state struct would look like this (where 'chipname' is replaced by
-the name of the chip):
-
-.. code-block:: none
-
-   struct chipname_state {
-   struct v4l2_subdev sd;
-   ...  /* additional state fields */
-   };
-
-Initialize the v4l2_subdev struct as follows:
-
-.. code-block:: none
-
-   v4l2_i2c_subdev_init(>sd, client, subdev_ops);
-
-This function will fill in all the fields of v4l2_subdev and ensure that the
-v4l2_subdev and i2c_client both point to one another.
-
-You should also add a helper inline function to go from a v4l2_subdev pointer
-to a chipname_state struct:
-
-.. code-block:: none
-
-   static inline struct chipname_state *to_state(struct v4l2_subdev *sd)
-   {
-   return container_of(sd, struct chipname_state, sd);
-   }
-
-Use this to go from the v4l2_subdev struct to the i2c_client struct:
-
-.. code-block:: none
-
-   struct i2c_client *client = v4l2_get_subdevdata(sd);
-
-And this to go from an i2c_client to a v4l2_subdev struct:
-
-.. code-block:: none
-
-   struct v4l2_subdev *sd = i2c_get_clientdata(client);
-
-Make sure to call v4l2_device_unregister_subdev(sd) when the remove() callback
-is called. This will unregister the sub-device from the bridge driver. It is
-safe to call this even if the sub-device was never registered.
-
-You need to do this because when the bridge driver destroys the i2c adapter
-the remove() 

[PATCH 03/12] [media] v4l2-device.rst: add contents from v4l2-framework

2016-07-21 Thread Mauro Carvalho Chehab
Part of the contents of v4l2-framework is related to the
kAPI defined by v4l2-device. Move such contents to the
v4l2-device.rst.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-device.rst| 140 +++-
 Documentation/media/kapi/v4l2-framework.rst | 139 ---
 2 files changed, 139 insertions(+), 140 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-device.rst 
b/Documentation/media/kapi/v4l2-device.rst
index e324fbcb0353..6d521b313beb 100644
--- a/Documentation/media/kapi/v4l2-device.rst
+++ b/Documentation/media/kapi/v4l2-device.rst
@@ -1,4 +1,142 @@
-V4L2 Device kAPI
+V4L2 Device register logic
+--
+
+Each device instance is represented by a struct v4l2_device (v4l2-device.h).
+Very simple devices can just allocate this struct, but most of the time you
+would embed this struct inside a larger struct.
+
+You must register the device instance:
+
+.. code-block:: none
+
+   v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);
+
+Registration will initialize the v4l2_device struct. If the dev->driver_data
+field is NULL, it will be linked to v4l2_dev.
+
+Drivers that want integration with the media device framework need to set
+dev->driver_data manually to point to the driver-specific device structure
+that embed the struct v4l2_device instance. This is achieved by a
+dev_set_drvdata() call before registering the V4L2 device instance. They must
+also set the struct v4l2_device mdev field to point to a properly initialized
+and registered media_device instance.
+
+If v4l2_dev->name is empty then it will be set to a value derived from dev
+(driver name followed by the bus_id, to be precise). If you set it up before
+calling v4l2_device_register then it will be untouched. If dev is NULL, then
+you **must** setup v4l2_dev->name before calling v4l2_device_register.
+
+You can use v4l2_device_set_name() to set the name based on a driver name and
+a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1,
+etc. If the name ends with a digit, then it will insert a dash: cx18-0,
+cx18-1, etc. This function returns the instance number.
+
+The first 'dev' argument is normally the struct device pointer of a pci_dev,
+usb_interface or platform_device. It is rare for dev to be NULL, but it happens
+with ISA devices or when one device creates multiple PCI devices, thus making
+it impossible to associate v4l2_dev with a particular parent.
+
+You can also supply a notify() callback that can be called by sub-devices to
+notify you of events. Whether you need to set this depends on the sub-device.
+Any notifications a sub-device supports must be defined in a header in
+include/media/.h.
+
+You unregister with:
+
+.. code-block:: none
+
+   v4l2_device_unregister(struct v4l2_device *v4l2_dev);
+
+If the dev->driver_data field points to v4l2_dev, it will be reset to NULL.
+Unregistering will also automatically unregister all subdevs from the device.
+
+If you have a hotpluggable device (e.g. a USB device), then when a disconnect
+happens the parent device becomes invalid. Since v4l2_device has a pointer to
+that parent device it has to be cleared as well to mark that the parent is
+gone. To do this call:
+
+.. code-block:: none
+
+   v4l2_device_disconnect(struct v4l2_device *v4l2_dev);
+
+This does *not* unregister the subdevs, so you still need to call the
+v4l2_device_unregister() function for that. If your driver is not hotpluggable,
+then there is no need to call v4l2_device_disconnect().
+
+Sometimes you need to iterate over all devices registered by a specific
+driver. This is usually the case if multiple device drivers use the same
+hardware. E.g. the ivtvfb driver is a framebuffer driver that uses the ivtv
+hardware. The same is true for alsa drivers for example.
+
+You can iterate over all registered devices as follows:
+
+.. code-block:: none
+
+   static int callback(struct device *dev, void *p)
+   {
+   struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
+
+   /* test if this device was inited */
+   if (v4l2_dev == NULL)
+   return 0;
+   ...
+   return 0;
+   }
+
+   int iterate(void *p)
+   {
+   struct device_driver *drv;
+   int err;
+
+   /* Find driver 'ivtv' on the PCI bus.
+   pci_bus_type is a global. For USB busses use usb_bus_type. */
+   drv = driver_find("ivtv", _bus_type);
+   /* iterate over all ivtv device instances */
+   err = driver_for_each_device(drv, NULL, p, callback);
+   put_driver(drv);
+   return err;
+   }
+
+Sometimes you need to keep a running counter of the device instance. This is
+commonly used to map a device instance to an index of a module option array.
+
+The recommended approach is as 

[PATCH 02/12] [media] doc-rst: Split v4l-core into one file per kAPI

2016-07-21 Thread Mauro Carvalho Chehab
Sphinx produce a 1:1 mapping between a rst file and an html file.

So, we need to split the kernel-doc tags on multiple documents.

A side effect is that we're now having a better name for each
section of the kAPI documentation.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-async.rst|  4 ++
 Documentation/media/kapi/v4l2-controls.rst |  5 ++
 Documentation/media/kapi/v4l2-core.rst | 55 --
 Documentation/media/kapi/v4l2-device.rst   |  4 ++
 Documentation/media/kapi/v4l2-dv-timings.rst   |  4 ++
 Documentation/media/kapi/v4l2-event.rst|  5 ++
 Documentation/media/kapi/v4l2-flash-led-class.rst  |  4 ++
 Documentation/media/kapi/v4l2-mc.rst   |  4 ++
 Documentation/media/kapi/v4l2-mediabus.rst |  4 ++
 Documentation/media/kapi/v4l2-mem2mem.rst  |  3 ++
 Documentation/media/kapi/v4l2-of.rst   |  3 ++
 Documentation/media/kapi/v4l2-rect.rst |  4 ++
 Documentation/media/kapi/v4l2-subdev.rst   |  4 ++
 Documentation/media/kapi/v4l2-tuner.rst|  6 +++
 Documentation/media/kapi/v4l2-tveeprom.rst |  4 ++
 .../media/kapi/{videobuf.rst => v4l2-videobuf.rst} |  0
 Documentation/media/kapi/v4l2-videobuf2.rst|  8 
 Documentation/media/media_kapi.rst |  3 --
 18 files changed, 86 insertions(+), 38 deletions(-)
 create mode 100644 Documentation/media/kapi/v4l2-async.rst
 create mode 100644 Documentation/media/kapi/v4l2-device.rst
 create mode 100644 Documentation/media/kapi/v4l2-dv-timings.rst
 create mode 100644 Documentation/media/kapi/v4l2-event.rst
 create mode 100644 Documentation/media/kapi/v4l2-flash-led-class.rst
 create mode 100644 Documentation/media/kapi/v4l2-mc.rst
 create mode 100644 Documentation/media/kapi/v4l2-mediabus.rst
 create mode 100644 Documentation/media/kapi/v4l2-mem2mem.rst
 create mode 100644 Documentation/media/kapi/v4l2-of.rst
 create mode 100644 Documentation/media/kapi/v4l2-rect.rst
 create mode 100644 Documentation/media/kapi/v4l2-subdev.rst
 create mode 100644 Documentation/media/kapi/v4l2-tuner.rst
 create mode 100644 Documentation/media/kapi/v4l2-tveeprom.rst
 rename Documentation/media/kapi/{videobuf.rst => v4l2-videobuf.rst} (100%)
 create mode 100644 Documentation/media/kapi/v4l2-videobuf2.rst

diff --git a/Documentation/media/kapi/v4l2-async.rst 
b/Documentation/media/kapi/v4l2-async.rst
new file mode 100644
index ..372aa29fbf29
--- /dev/null
+++ b/Documentation/media/kapi/v4l2-async.rst
@@ -0,0 +1,4 @@
+V4L2 Async kAPI
+^^^
+
+.. kernel-doc:: include/media/v4l2-async.h
diff --git a/Documentation/media/kapi/v4l2-controls.rst 
b/Documentation/media/kapi/v4l2-controls.rst
index 8ff9ee806042..58b6b3d74ca7 100644
--- a/Documentation/media/kapi/v4l2-controls.rst
+++ b/Documentation/media/kapi/v4l2-controls.rst
@@ -824,3 +824,8 @@ notify function is called.
 
 There can be only one notify function per control handler. Any attempt
 to set another notify function will cause a WARN_ON.
+
+V4L2 control kAPI
+-
+
+.. kernel-doc:: include/media/v4l2-ctrls.h
diff --git a/Documentation/media/kapi/v4l2-core.rst 
b/Documentation/media/kapi/v4l2-core.rst
index db571a4f498a..8c127ccdb0ae 100644
--- a/Documentation/media/kapi/v4l2-core.rst
+++ b/Documentation/media/kapi/v4l2-core.rst
@@ -1,38 +1,23 @@
 Video2Linux devices
 ---
 
-.. kernel-doc:: include/media/tuner.h
-
-.. kernel-doc:: include/media/tuner-types.h
-
-.. kernel-doc:: include/media/tveeprom.h
-
-.. kernel-doc:: include/media/v4l2-async.h
-
-.. kernel-doc:: include/media/v4l2-ctrls.h
-
-.. kernel-doc:: include/media/v4l2-device.h
-
-.. kernel-doc:: include/media/v4l2-dv-timings.h
-
-.. kernel-doc:: include/media/v4l2-event.h
-
-.. kernel-doc:: include/media/v4l2-flash-led-class.h
-
-.. kernel-doc:: include/media/v4l2-mc.h
-
-.. kernel-doc:: include/media/v4l2-mediabus.h
-
-.. kernel-doc:: include/media/v4l2-mem2mem.h
-
-.. kernel-doc:: include/media/v4l2-of.h
-
-.. kernel-doc:: include/media/v4l2-rect.h
-
-.. kernel-doc:: include/media/v4l2-subdev.h
-
-.. kernel-doc:: include/media/videobuf2-core.h
-
-.. kernel-doc:: include/media/videobuf2-v4l2.h
-
-.. kernel-doc:: include/media/videobuf2-memops.h
+.. toctree::
+:maxdepth: 1
+
+v4l2-framework
+v4l2-async
+v4l2-controls
+v4l2-device
+v4l2-dv-timings
+v4l2-event
+v4l2-flash-led-class
+v4l2-mc
+v4l2-mediabus
+v4l2-mem2mem
+v4l2-of
+v4l2-rect
+v4l2-subdev
+v4l2-tuner
+v4l2-tveeprom
+v4l2-videobuf2
+v4l2-videobuf
diff --git a/Documentation/media/kapi/v4l2-device.rst 
b/Documentation/media/kapi/v4l2-device.rst
new file mode 100644
index ..e324fbcb0353
--- /dev/null
+++ b/Documentation/media/kapi/v4l2-device.rst
@@ -0,0 +1,4 @@
+V4L2 Device kAPI
+
+
+.. kernel-doc:: include/media/v4l2-device.h
diff --git 

[PATCH 11/12] [media] v4l2-subdev.rst: add cross references to new sections

2016-07-21 Thread Mauro Carvalho Chehab
The two new sections were missing cross-references, and had
some other minor issues with the markups. Add such things.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-subdev.rst | 152 +--
 1 file changed, 82 insertions(+), 70 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-subdev.rst 
b/Documentation/media/kapi/v4l2-subdev.rst
index 2845a749409c..80982a9d002f 100644
--- a/Documentation/media/kapi/v4l2-subdev.rst
+++ b/Documentation/media/kapi/v4l2-subdev.rst
@@ -265,27 +265,28 @@ called. All three callbacks are optional.
 V4L2 sub-device userspace API
 -
 
-Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2
-sub-devices can also be controlled directly by userspace applications.
+Beside exposing a kernel API through the :c:type:`v4l2_subdev_ops` structure,
+V4L2 sub-devices can also be controlled directly by userspace applications.
 
-Device nodes named v4l-subdevX can be created in /dev to access sub-devices
-directly. If a sub-device supports direct userspace configuration it must set
-the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered.
+Device nodes named ``v4l-subdev``\ *X* can be created in ``/dev`` to access
+sub-devices directly. If a sub-device supports direct userspace configuration
+it must set the ``V4L2_SUBDEV_FL_HAS_DEVNODE`` flag before being registered.
 
-After registering sub-devices, the v4l2_device driver can create device nodes
-for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by 
calling
-v4l2_device_register_subdev_nodes(). Those device nodes will be automatically
-removed when sub-devices are unregistered.
+After registering sub-devices, the :c:type:`v4l2_device` driver can create
+device nodes for all registered sub-devices marked with
+``V4L2_SUBDEV_FL_HAS_DEVNODE`` by calling
+:cpp:func:`v4l2_device_register_subdev_nodes`. Those device nodes will be
+automatically removed when sub-devices are unregistered.
 
 The device node handles a subset of the V4L2 API.
 
-VIDIOC_QUERYCTRL
-VIDIOC_QUERYMENU
-VIDIOC_G_CTRL
-VIDIOC_S_CTRL
-VIDIOC_G_EXT_CTRLS
-VIDIOC_S_EXT_CTRLS
-VIDIOC_TRY_EXT_CTRLS
+``VIDIOC_QUERYCTRL``,
+``VIDIOC_QUERYMENU``,
+``VIDIOC_G_CTRL``,
+``VIDIOC_S_CTRL``,
+``VIDIOC_G_EXT_CTRLS``,
+``VIDIOC_S_EXT_CTRLS`` and
+``VIDIOC_TRY_EXT_CTRLS``:
 
The controls ioctls are identical to the ones defined in V4L2. They
behave identically, with the only exception that they deal only with
@@ -293,9 +294,9 @@ VIDIOC_TRY_EXT_CTRLS
controls can be also be accessed through one (or several) V4L2 device
nodes.
 
-VIDIOC_DQEVENT
-VIDIOC_SUBSCRIBE_EVENT
-VIDIOC_UNSUBSCRIBE_EVENT
+``VIDIOC_DQEVENT``,
+``VIDIOC_SUBSCRIBE_EVENT`` and
+``VIDIOC_UNSUBSCRIBE_EVENT``
 
The events ioctls are identical to the ones defined in V4L2. They
behave identically, with the only exception that they deal only with
@@ -303,12 +304,12 @@ VIDIOC_UNSUBSCRIBE_EVENT
events can also be reported by one (or several) V4L2 device nodes.
 
Sub-device drivers that want to use events need to set the
-   V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags and initialize
-   v4l2_subdev::nevents to events queue depth before registering the
-   sub-device. After registration events can be queued as usual on the
-   v4l2_subdev::devnode device node.
+   ``V4L2_SUBDEV_USES_EVENTS`` :c:type:`v4l2_subdev`.flags and initialize
+   :c:type:`v4l2_subdev`.nevents to events queue depth before registering
+   the sub-device. After registration events can be queued as usual on the
+   :c:type:`v4l2_subdev`.devnode device node.
 
-   To properly support events, the poll() file operation is also
+   To properly support events, the ``poll()`` file operation is also
implemented.
 
 Private ioctls
@@ -321,84 +322,89 @@ I2C sub-device drivers
 --
 
 Since these drivers are so common, special helper functions are available to
-ease the use of these drivers (v4l2-common.h).
+ease the use of these drivers (``v4l2-common.h``).
 
-The recommended method of adding v4l2_subdev support to an I2C driver is to
-embed the v4l2_subdev struct into the state struct that is created for each
-I2C device instance. Very simple devices have no state struct and in that case
-you can just create a v4l2_subdev directly.
+The recommended method of adding :c:type:`v4l2_subdev` support to an I2C driver
+is to embed the :c:type:`v4l2_subdev` struct into the state struct that is
+created for each I2C device instance. Very simple devices have no state
+struct and in that case you can just create a :c:type:`v4l2_subdev` directly.
 
 A typical state struct would look like this (where 'chipname' is replaced by
 the name of the chip):
 
-.. code-block:: none
+.. code-block:: c
 
struct chipname_state {
struct v4l2_subdev sd;
...  /* additional state 

[PATCH 12/12] [media] v4l2-common.h: document the subdev functions

2016-07-21 Thread Mauro Carvalho Chehab
There are some subdev-specific functions at v4l2-common.h
that are mentioned at v4l2-subdev.rst.

Document them.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-subdev.rst |  6 
 include/media/v4l2-common.h  | 49 +++-
 2 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-subdev.rst 
b/Documentation/media/kapi/v4l2-subdev.rst
index 80982a9d002f..456fdec69042 100644
--- a/Documentation/media/kapi/v4l2-subdev.rst
+++ b/Documentation/media/kapi/v4l2-subdev.rst
@@ -449,3 +449,9 @@ V4L2 sub-device asynchronous kAPI
 ^
 
 .. kernel-doc:: include/media/v4l2-async.h
+
+
+V4L2 common kAPI
+
+
+.. kernel-doc:: include/media/v4l2-common.h
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 1cc0c5ba16b3..9b1dfcd9e229 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -80,8 +80,6 @@
 
 /* - */
 
-/* Control helper function */
-
 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 
step, s32 def);
 
 /* - */
@@ -96,23 +94,60 @@ struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
 
-
-/* Load an i2c module and return an initialized v4l2_subdev struct.
-   The client_type argument is the name of the chip that's on the adapter. */
+/**
+ * v4l2_i2c_new_subdev - Load an i2c module and return an initialized
+ *  v4l2_subdev.
+ *
+ * @v4l2_dev: pointer to  v4l2_device
+ * @adapter: pointer to struct i2c_adapter
+ * @client_type:  name of the chip that's on the adapter.
+ * @addr: I2C address. If zero, it will use @probe_addrs
+ * @probe_addrs: array with a list of address. The last entry at such
+ * array should be %I2C_CLIENT_END.
+ *
+ * returns a  v4l2_subdev pointer.
+ */
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, const char *client_type,
u8 addr, const unsigned short *probe_addrs);
 
 struct i2c_board_info;
 
+/**
+ * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized
+ *  v4l2_subdev.
+ *
+ * @v4l2_dev: pointer to  v4l2_device
+ * @adapter: pointer to struct i2c_adapter
+ * @info: pointer to struct i2c_board_info used to replace the irq,
+ *  platform_data and addr arguments.
+ * @probe_addrs: array with a list of address. The last entry at such
+ * array should be %I2C_CLIENT_END.
+ *
+ * returns a  v4l2_subdev pointer.
+ */
 struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, struct i2c_board_info *info,
const unsigned short *probe_addrs);
 
-/* Initialize a v4l2_subdev with data from an i2c_client struct */
+/**
+ * v4l2_i2c_subdev_init - Initializes a  v4l2_subdev with data from
+ * an i2c_client struct.
+ *
+ * @sd: pointer to  v4l2_subdev
+ * @client: pointer to struct i2c_client
+ * @ops: pointer to  v4l2_subdev_ops
+ */
 void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
const struct v4l2_subdev_ops *ops);
-/* Return i2c client address of v4l2_subdev. */
+
+/**
+ * v4l2_i2c_subdev_addr - returns i2c client address of  v4l2_subdev.
+ *
+ * @sd: pointer to  v4l2_subdev
+ *
+ * Returns the address of an I2C sub-device
+ */
 unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
 
 enum v4l2_i2c_tuner_type {
-- 
2.7.4

--
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


[PATCH 07/12] [media] v4l2-subdev.rst: add cross-references

2016-07-21 Thread Mauro Carvalho Chehab
Enrich the subdevice description by linking it to the
functions and structs from v4l2-subdev.h.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-subdev.rst | 158 ---
 1 file changed, 83 insertions(+), 75 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-subdev.rst 
b/Documentation/media/kapi/v4l2-subdev.rst
index 3e2b25b47ff4..101902c930b9 100644
--- a/Documentation/media/kapi/v4l2-subdev.rst
+++ b/Documentation/media/kapi/v4l2-subdev.rst
@@ -7,35 +7,37 @@ encoding or decoding. For webcams common sub-devices are 
sensors and camera
 controllers.
 
 Usually these are I2C devices, but not necessarily. In order to provide the
-driver with a consistent interface to these sub-devices the v4l2_subdev struct
-(v4l2-subdev.h) was created.
+driver with a consistent interface to these sub-devices the
+:c:type:`v4l2_subdev` struct (v4l2-subdev.h) was created.
 
-Each sub-device driver must have a v4l2_subdev struct. This struct can be
-stand-alone for simple sub-devices or it might be embedded in a larger struct
-if more state information needs to be stored. Usually there is a low-level
-device struct (e.g. i2c_client) that contains the device data as setup
-by the kernel. It is recommended to store that pointer in the private
-data of v4l2_subdev using v4l2_set_subdevdata(). That makes it easy to go
-from a v4l2_subdev to the actual low-level bus-specific device data.
+Each sub-device driver must have a :c:type:`v4l2_subdev` struct. This struct
+can be stand-alone for simple sub-devices or it might be embedded in a larger
+struct if more state information needs to be stored. Usually there is a
+low-level device struct (e.g. ``i2c_client``) that contains the device data as
+setup by the kernel. It is recommended to store that pointer in the private
+data of :c:type:`v4l2_subdev` using :cpp:func:`v4l2_set_subdevdata`. That makes
+it easy to go from a :c:type:`v4l2_subdev` to the actual low-level bus-specific
+device data.
 
-You also need a way to go from the low-level struct to v4l2_subdev. For the
-common i2c_client struct the i2c_set_clientdata() call is used to store a
-v4l2_subdev pointer, for other busses you may have to use other methods.
+You also need a way to go from the low-level struct to :c:type:`v4l2_subdev`.
+For the common i2c_client struct the i2c_set_clientdata() call is used to store
+a :c:type:`v4l2_subdev` pointer, for other busses you may have to use other
+methods.
 
 Bridges might also need to store per-subdev private data, such as a pointer to
-bridge-specific per-subdev private data. The v4l2_subdev structure provides
-host private data for that purpose that can be accessed with
-v4l2_get_subdev_hostdata() and v4l2_set_subdev_hostdata().
+bridge-specific per-subdev private data. The :c:type:`v4l2_subdev` structure
+provides host private data for that purpose that can be accessed with
+:cpp:func:`v4l2_get_subdev_hostdata` and :cpp:func:`v4l2_set_subdev_hostdata`.
 
-From the bridge driver perspective you load the sub-device module and somehow
-obtain the v4l2_subdev pointer. For i2c devices this is easy: you call
-i2c_get_clientdata(). For other busses something similar needs to be done.
+From the bridge driver perspective, you load the sub-device module and somehow
+obtain the :c:type:`v4l2_subdev` pointer. For i2c devices this is easy: you 
call
+``i2c_get_clientdata()``. For other busses something similar needs to be done.
 Helper functions exists for sub-devices on an I2C bus that do most of this
 tricky work for you.
 
-Each v4l2_subdev contains function pointers that sub-device drivers can
-implement (or leave NULL if it is not applicable). Since sub-devices can do
-so many different things and you do not want to end up with a huge ops struct
+Each :c:type:`v4l2_subdev` contains function pointers that sub-device drivers
+can implement (or leave ``NULL`` if it is not applicable). Since sub-devices 
can
+do so many different things and you do not want to end up with a huge ops 
struct
 of which only a handful of ops are commonly implemented, the function pointers
 are sorted according to category and each category has its own ops struct.
 
@@ -44,7 +46,7 @@ may be NULL if the subdev driver does not support anything 
from that category.
 
 It looks like this:
 
-.. code-block:: none
+.. code-block:: c
 
struct v4l2_subdev_core_ops {
int (*log_status)(struct v4l2_subdev *sd);
@@ -83,20 +85,22 @@ audio ops and vice versa.
 This setup limits the number of function pointers while still making it easy
 to add new ops and categories.
 
-A sub-device driver initializes the v4l2_subdev struct using:
+A sub-device driver initializes the :c:type:`v4l2_subdev` struct using:
 
-.. code-block:: none
+   :cpp:func:`v4l2_subdev_init `
+   (:c:type:`sd `, &\ :c:type:`ops `).
 
-   v4l2_subdev_init(sd, );
 
-Afterwards you need to initialize subdev->name with a unique name and set the

[PATCH 08/12] [media] doc-rst: merge v4l2-async.rst with v4l2-subdev.rst

2016-07-21 Thread Mauro Carvalho Chehab
The Async API is actually part of the v4l2 subdev.
Move its declarations to it.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-async.rst  | 4 
 Documentation/media/kapi/v4l2-core.rst   | 1 -
 Documentation/media/kapi/v4l2-subdev.rst | 5 +
 3 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 100644 Documentation/media/kapi/v4l2-async.rst

diff --git a/Documentation/media/kapi/v4l2-async.rst 
b/Documentation/media/kapi/v4l2-async.rst
deleted file mode 100644
index 372aa29fbf29..
--- a/Documentation/media/kapi/v4l2-async.rst
+++ /dev/null
@@ -1,4 +0,0 @@
-V4L2 Async kAPI
-^^^
-
-.. kernel-doc:: include/media/v4l2-async.h
diff --git a/Documentation/media/kapi/v4l2-core.rst 
b/Documentation/media/kapi/v4l2-core.rst
index 8c127ccdb0ae..fc623e9ca871 100644
--- a/Documentation/media/kapi/v4l2-core.rst
+++ b/Documentation/media/kapi/v4l2-core.rst
@@ -5,7 +5,6 @@ Video2Linux devices
 :maxdepth: 1
 
 v4l2-framework
-v4l2-async
 v4l2-controls
 v4l2-device
 v4l2-dv-timings
diff --git a/Documentation/media/kapi/v4l2-subdev.rst 
b/Documentation/media/kapi/v4l2-subdev.rst
index 101902c930b9..829016940597 100644
--- a/Documentation/media/kapi/v4l2-subdev.rst
+++ b/Documentation/media/kapi/v4l2-subdev.rst
@@ -266,3 +266,8 @@ V4L2 subdev kAPI
 
 
 .. kernel-doc:: include/media/v4l2-subdev.h
+
+V4L2 subdev async kAPI
+^^
+
+.. kernel-doc:: include/media/v4l2-async.h
-- 
2.7.4

--
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


[PATCH 06/12] [media] v4l2-subdev.h: Improve documentation

2016-07-21 Thread Mauro Carvalho Chehab
This header were poorly documented, and weren't using the
kernel-doc format. Document everything but the macros using
the right format.

While here, also fix the other comments to match the
Linux CodingStyle.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-subdev.c |  10 -
 include/media/v4l2-subdev.h   | 586 ++
 2 files changed, 390 insertions(+), 206 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 953eab08e420..34a1e7c8b306 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -621,16 +621,6 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct 
v4l2_subdev_ops *ops)
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
 
-/**
- * v4l2_subdev_notify_event() - Delivers event notification for subdevice
- * @sd: The subdev for which to deliver the event
- * @ev: The event to deliver
- *
- * Will deliver the specified event to all userspace event listeners which are
- * subscribed to the v42l subdev event queue as well as to the bridge driver
- * using the notify callback. The notification type for the notify callback
- * will be V4L2_DEVICE_NOTIFY_EVENT.
- */
 void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  const struct v4l2_event *ev)
 {
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 4c880e86a1aa..996e1590cf32 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1,21 +1,17 @@
 /*
-V4L2 sub-device support header.
-
-Copyright (C) 2008  Hans Verkuil 
-
-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.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  V4L2 sub-device support header.
+ *
+ *  Copyright (C) 2008  Hans Verkuil 
+ *
+ *  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.
  */
 
 #ifndef _V4L2_SUBDEV_H
@@ -52,55 +48,64 @@ struct v4l2_subdev_fh;
 struct tuner_setup;
 struct v4l2_mbus_frame_desc;
 
-/* decode_vbi_line */
+/**
+ * struct v4l2_decode_vbi_line - used to decode_vbi_line
+ *
+ * @is_second_field: Set to 0 for the first (odd) field;
+ * set to 1 for the second (even) field.
+ * @p: Pointer to the sliced VBI data from the decoder. On exit, points to
+ * the start of the payload.
+ * @line: Line number of the sliced VBI data (1-23)
+ * @type: VBI service type (V4L2_SLICED_*). 0 if no service found
+ */
 struct v4l2_decode_vbi_line {
-   u32 is_second_field;/* Set to 0 for the first (odd) field,
-  set to 1 for the second (even) field. */
-   u8 *p;  /* Pointer to the sliced VBI data from the 
decoder.
-  On exit points to the start of the payload. 
*/
-   u32 line;   /* Line number of the sliced VBI data (1-23) */
-   u32 type;   /* VBI service type (V4L2_SLICED_*). 0 if no 
service found */
+   u32 is_second_field;
+   u8 *p;
+   u32 line;
+   u32 type;
 };
 
-/* Sub-devices are devices that are connected somehow to the main bridge
-   device. These devices are usually audio/video muxers/encoders/decoders or
-   sensors and webcam controllers.
-
-   Usually these devices are controlled through an i2c bus, but other busses
-   may also be used.
-
-   The v4l2_subdev struct provides a way of accessing these devices in a
-   generic manner. Most operations that these sub-devices support fall in
-   a few categories: core ops, audio ops, video ops and tuner ops.
-
-   More categories can be added if needed, although this should remain a
-   limited set (no more than approx. 8 categories).
-
-   Each category has its own set of ops that subdev drivers can implement.
-
-   A subdev driver can leave the pointer to the category ops NULL if
-   it 

[PATCH 01/12] [media] v4l2-device.h: document functions

2016-07-21 Thread Mauro Carvalho Chehab
The functions at v4l2-device.h are not using the proper
markups. Add it, and include at the v4l2-core.rst.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-core.rst |   2 +
 include/media/v4l2-device.h| 194 -
 2 files changed, 143 insertions(+), 53 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-core.rst 
b/Documentation/media/kapi/v4l2-core.rst
index a1b73e8d6795..db571a4f498a 100644
--- a/Documentation/media/kapi/v4l2-core.rst
+++ b/Documentation/media/kapi/v4l2-core.rst
@@ -11,6 +11,8 @@ Video2Linux devices
 
 .. kernel-doc:: include/media/v4l2-ctrls.h
 
+.. kernel-doc:: include/media/v4l2-device.h
+
 .. kernel-doc:: include/media/v4l2-dv-timings.h
 
 .. kernel-doc:: include/media/v4l2-event.h
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index d5d45a8d3998..a9d6aa41790e 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -25,100 +25,188 @@
 #include 
 #include 
 
-/* Each instance of a V4L2 device should create the v4l2_device struct,
-   either stand-alone or embedded in a larger struct.
-
-   It allows easy access to sub-devices (see v4l2-subdev.h) and provides
-   basic V4L2 device-level support.
- */
-
 #define V4L2_DEVICE_NAME_SIZE (20 + 16)
 
 struct v4l2_ctrl_handler;
 
+/**
+ * struct v4l2_device - main struct to for V4L2 device drivers
+ *
+ * @dev: pointer to struct device.
+ * @mdev: pointer to struct media_device
+ * @subdevs: used to keep track of the registered subdevs
+ * @lock: lock this struct; can be used by the driver as well
+ * if this struct is embedded into a larger struct.
+ * @name: unique device name, by default the driver name + bus ID
+ * @notify: notify callback called by some sub-devices.
+ * @ctrl_handler: The control handler. May be NULL.
+ * @prio: Device's priority state
+ * @ref: Keep track of the references to this struct.
+ * @release: Release function that is called when the ref count
+ * goes to 0.
+ *
+ * Each instance of a V4L2 device should create the v4l2_device struct,
+ * either stand-alone or embedded in a larger struct.
+ *
+ * It allows easy access to sub-devices (see v4l2-subdev.h) and provides
+ * basic V4L2 device-level support.
+ *
+ * .. note::
+ *
+ *#) dev->driver_data points to this struct.
+ *#) dev might be NULL if there is no parent device
+ */
+
 struct v4l2_device {
-   /* dev->driver_data points to this struct.
-  Note: dev might be NULL if there is no parent device
-  as is the case with e.g. ISA devices. */
struct device *dev;
 #if defined(CONFIG_MEDIA_CONTROLLER)
struct media_device *mdev;
 #endif
-   /* used to keep track of the registered subdevs */
struct list_head subdevs;
-   /* lock this struct; can be used by the driver as well if this
-  struct is embedded into a larger struct. */
spinlock_t lock;
-   /* unique device name, by default the driver name + bus ID */
char name[V4L2_DEVICE_NAME_SIZE];
-   /* notify callback called by some sub-devices. */
void (*notify)(struct v4l2_subdev *sd,
unsigned int notification, void *arg);
-   /* The control handler. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
-   /* Device's priority state */
struct v4l2_prio_state prio;
-   /* Keep track of the references to this struct. */
struct kref ref;
-   /* Release function that is called when the ref count goes to 0. */
void (*release)(struct v4l2_device *v4l2_dev);
 };
 
+/**
+ * v4l2_device_get - gets a V4L2 device reference
+ *
+ * @v4l2_dev: pointer to struct v4l2_device
+ *
+ * This is an ancillary routine meant to increment the usage for the
+ * struct v4l2_device pointed by @v4l2_dev.
+ */
 static inline void v4l2_device_get(struct v4l2_device *v4l2_dev)
 {
kref_get(_dev->ref);
 }
 
+/**
+ * v4l2_device_put - putss a V4L2 device reference
+ *
+ * @v4l2_dev: pointer to struct v4l2_device
+ *
+ * This is an ancillary routine meant to decrement the usage for the
+ * struct v4l2_device pointed by @v4l2_dev.
+ */
 int v4l2_device_put(struct v4l2_device *v4l2_dev);
 
-/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
-   dev may be NULL in rare cases (ISA devices). In that case you
-   must fill in the v4l2_dev->name field before calling this function. */
-int __must_check v4l2_device_register(struct device *dev, struct v4l2_device 
*v4l2_dev);
+/**
+ * v4l2_device_register -Initialize v4l2_dev and make dev->driver_data
+ * point to v4l2_dev.
+ *
+ * @dev: pointer to struct device
+ * @v4l2_dev: pointer to struct v4l2_device
+ *
+ * .. note::
+ * dev may be NULL in rare cases (ISA devices).
+ * In such case the caller must fill in the v4l2_dev->name field
+ * before calling this function.
+ */
+int __must_check v4l2_device_register(struct device *dev,
+ 

[PATCH 09/12] [media] v4l2-async: document the remaining stuff

2016-07-21 Thread Mauro Carvalho Chehab
There are one enum and 4 functions undocumented there.
Document them. That will fix the broken links at the
v4l2-subdev.rst file.

Signed-off-by: Mauro Carvalho Chehab 
---
 include/media/v4l2-async.h | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index 1d6d7da4c45d..8e2a236a4d03 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -23,6 +23,19 @@ struct v4l2_async_notifier;
 /* A random max subdevice number, used to allocate an array on stack */
 #define V4L2_MAX_SUBDEVS 128U
 
+/**
+ * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
+ * in order to identify a match
+ *
+ * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by 
+ * v4l2_async_subdev.match ops
+ * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name
+ * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address
+ * @V4L2_ASYNC_MATCH_OF: Match will use OF node
+ *
+ * This enum is used by the asyncrhronous sub-device logic to define the
+ * algorithm that will be used to match an asynchronous device.
+ */
 enum v4l2_async_match_type {
V4L2_ASYNC_MATCH_CUSTOM,
V4L2_ASYNC_MATCH_DEVNAME,
@@ -91,9 +104,35 @@ struct v4l2_async_notifier {
   struct v4l2_async_subdev *asd);
 };
 
+/**
+ * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
+ *
+ * @v4l2_dev: pointer to  v4l2_device
+ * @notifier: pointer to  v4l2_async_notifier
+ */
 int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
 struct v4l2_async_notifier *notifier);
+
+/**
+ * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous 
notifier
+ *
+ * @notifier: pointer to  v4l2_async_notifier
+ */
 void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
+
+/**
+ * v4l2_async_register_subdev - registers a sub-device to the asynchronous
+ * subdevice framework
+ *
+ * @sd: pointer to  v4l2_subdev
+ */
 int v4l2_async_register_subdev(struct v4l2_subdev *sd);
+
+/**
+ * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
+ * subdevice framework
+ *
+ * @sd: pointer to  v4l2_subdev
+ */
 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
 #endif
-- 
2.7.4

--
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


[PATCH 05/12] [media] v4l2-subdev.rst: add documentation from v4l2-framework.rst

2016-07-21 Thread Mauro Carvalho Chehab
There are lots of documentation about V4L2 subdevices at
v4l2-framework.rst. Move them to its specific chapter at
v4l2-subdev.rst.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-framework.rst | 257 
 Documentation/media/kapi/v4l2-subdev.rst| 256 +++
 2 files changed, 256 insertions(+), 257 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-framework.rst 
b/Documentation/media/kapi/v4l2-framework.rst
index 1fdc96bd7411..a7f64b38af5c 100644
--- a/Documentation/media/kapi/v4l2-framework.rst
+++ b/Documentation/media/kapi/v4l2-framework.rst
@@ -80,263 +80,6 @@ The V4L2 framework also optionally integrates with the 
media framework. If a
 driver sets the struct v4l2_device mdev field, sub-devices and video nodes
 will automatically appear in the media framework as entities.
 
-struct v4l2_subdev
---
-
-Many drivers need to communicate with sub-devices. These devices can do all
-sort of tasks, but most commonly they handle audio and/or video muxing,
-encoding or decoding. For webcams common sub-devices are sensors and camera
-controllers.
-
-Usually these are I2C devices, but not necessarily. In order to provide the
-driver with a consistent interface to these sub-devices the v4l2_subdev struct
-(v4l2-subdev.h) was created.
-
-Each sub-device driver must have a v4l2_subdev struct. This struct can be
-stand-alone for simple sub-devices or it might be embedded in a larger struct
-if more state information needs to be stored. Usually there is a low-level
-device struct (e.g. i2c_client) that contains the device data as setup
-by the kernel. It is recommended to store that pointer in the private
-data of v4l2_subdev using v4l2_set_subdevdata(). That makes it easy to go
-from a v4l2_subdev to the actual low-level bus-specific device data.
-
-You also need a way to go from the low-level struct to v4l2_subdev. For the
-common i2c_client struct the i2c_set_clientdata() call is used to store a
-v4l2_subdev pointer, for other busses you may have to use other methods.
-
-Bridges might also need to store per-subdev private data, such as a pointer to
-bridge-specific per-subdev private data. The v4l2_subdev structure provides
-host private data for that purpose that can be accessed with
-v4l2_get_subdev_hostdata() and v4l2_set_subdev_hostdata().
-
-From the bridge driver perspective you load the sub-device module and somehow
-obtain the v4l2_subdev pointer. For i2c devices this is easy: you call
-i2c_get_clientdata(). For other busses something similar needs to be done.
-Helper functions exists for sub-devices on an I2C bus that do most of this
-tricky work for you.
-
-Each v4l2_subdev contains function pointers that sub-device drivers can
-implement (or leave NULL if it is not applicable). Since sub-devices can do
-so many different things and you do not want to end up with a huge ops struct
-of which only a handful of ops are commonly implemented, the function pointers
-are sorted according to category and each category has its own ops struct.
-
-The top-level ops struct contains pointers to the category ops structs, which
-may be NULL if the subdev driver does not support anything from that category.
-
-It looks like this:
-
-.. code-block:: none
-
-   struct v4l2_subdev_core_ops {
-   int (*log_status)(struct v4l2_subdev *sd);
-   int (*init)(struct v4l2_subdev *sd, u32 val);
-   ...
-   };
-
-   struct v4l2_subdev_tuner_ops {
-   ...
-   };
-
-   struct v4l2_subdev_audio_ops {
-   ...
-   };
-
-   struct v4l2_subdev_video_ops {
-   ...
-   };
-
-   struct v4l2_subdev_pad_ops {
-   ...
-   };
-
-   struct v4l2_subdev_ops {
-   const struct v4l2_subdev_core_ops  *core;
-   const struct v4l2_subdev_tuner_ops *tuner;
-   const struct v4l2_subdev_audio_ops *audio;
-   const struct v4l2_subdev_video_ops *video;
-   const struct v4l2_subdev_pad_ops *video;
-   };
-
-The core ops are common to all subdevs, the other categories are implemented
-depending on the sub-device. E.g. a video device is unlikely to support the
-audio ops and vice versa.
-
-This setup limits the number of function pointers while still making it easy
-to add new ops and categories.
-
-A sub-device driver initializes the v4l2_subdev struct using:
-
-.. code-block:: none
-
-   v4l2_subdev_init(sd, );
-
-Afterwards you need to initialize subdev->name with a unique name and set the
-module owner. This is done for you if you use the i2c helper functions.
-
-If integration with the media framework is needed, you must initialize the
-media_entity struct embedded in the v4l2_subdev struct (entity field) by
-calling media_entity_pads_init(), if the entity has pads:
-
-.. code-block:: none
-
-   struct media_pad *pads = _sd->pads;
-   

[PATCH 04/12] [media] v4l2-device.rst: do cross references with kernel-doc

2016-07-21 Thread Mauro Carvalho Chehab
This document describes the main kAPI interfaces for the
v4l2-device.h header. Add cross references to the documentation
produced via kernel-doc.

While here, also use monotonic font for constants.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/media/kapi/v4l2-device.rst | 130 ---
 1 file changed, 66 insertions(+), 64 deletions(-)

diff --git a/Documentation/media/kapi/v4l2-device.rst 
b/Documentation/media/kapi/v4l2-device.rst
index 6d521b313beb..8e275d0ff0f5 100644
--- a/Documentation/media/kapi/v4l2-device.rst
+++ b/Documentation/media/kapi/v4l2-device.rst
@@ -1,67 +1,69 @@
 V4L2 Device register logic
 --
 
-Each device instance is represented by a struct v4l2_device (v4l2-device.h).
+Each device instance is represented by a struct :c:type:`v4l2_device`.
 Very simple devices can just allocate this struct, but most of the time you
 would embed this struct inside a larger struct.
 
-You must register the device instance:
+You must register the device instance by calling:
 
-.. code-block:: none
+   :cpp:func:`v4l2_device_register `
+   (dev, :c:type:`v4l2_dev `).
 
-   v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);
-
-Registration will initialize the v4l2_device struct. If the dev->driver_data
-field is NULL, it will be linked to v4l2_dev.
+Registration will initialize the :c:type:`v4l2_device` struct. If the
+dev->driver_data field is ``NULL``, it will be linked to
+:c:type:`v4l2_dev ` argument.
 
 Drivers that want integration with the media device framework need to set
 dev->driver_data manually to point to the driver-specific device structure
-that embed the struct v4l2_device instance. This is achieved by a
-dev_set_drvdata() call before registering the V4L2 device instance. They must
-also set the struct v4l2_device mdev field to point to a properly initialized
-and registered media_device instance.
-
-If v4l2_dev->name is empty then it will be set to a value derived from dev
-(driver name followed by the bus_id, to be precise). If you set it up before
-calling v4l2_device_register then it will be untouched. If dev is NULL, then
-you **must** setup v4l2_dev->name before calling v4l2_device_register.
-
-You can use v4l2_device_set_name() to set the name based on a driver name and
-a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1,
-etc. If the name ends with a digit, then it will insert a dash: cx18-0,
-cx18-1, etc. This function returns the instance number.
-
-The first 'dev' argument is normally the struct device pointer of a pci_dev,
-usb_interface or platform_device. It is rare for dev to be NULL, but it happens
-with ISA devices or when one device creates multiple PCI devices, thus making
-it impossible to associate v4l2_dev with a particular parent.
-
-You can also supply a notify() callback that can be called by sub-devices to
-notify you of events. Whether you need to set this depends on the sub-device.
-Any notifications a sub-device supports must be defined in a header in
-include/media/.h.
-
-You unregister with:
-
-.. code-block:: none
-
-   v4l2_device_unregister(struct v4l2_device *v4l2_dev);
-
-If the dev->driver_data field points to v4l2_dev, it will be reset to NULL.
-Unregistering will also automatically unregister all subdevs from the device.
+that embed the struct :c:type:`v4l2_device` instance. This is achieved by a
+``dev_set_drvdata()`` call before registering the V4L2 device instance.
+They must also set the struct :c:type:`v4l2_device` mdev field to point to a
+properly initialized and registered :c:type:`media_device` instance.
+
+If :c:type:`v4l2_dev `\ ->name is empty then it will be set to a
+value derived from dev (driver name followed by the bus_id, to be precise).
+If you set it up before  calling :cpp:func:`v4l2_device_register` then it will
+be untouched. If dev is ``NULL``, then you **must** setup
+:c:type:`v4l2_dev `\ ->name before calling
+:cpp:func:`v4l2_device_register`.
+
+You can use :cpp:func:`v4l2_device_set_name` to set the name based on a driver
+name and a driver-global atomic_t instance. This will generate names like
+``ivtv0``, ``ivtv1``, etc. If the name ends with a digit, then it will insert
+a dash: ``cx18-0``, ``cx18-1``, etc. This function returns the instance number.
+
+The first ``dev`` argument is normally the ``struct device`` pointer of a
+``pci_dev``, ``usb_interface`` or ``platform_device``. It is rare for dev to
+be ``NULL``, but it happens with ISA devices or when one device creates
+multiple PCI devices, thus making it impossible to associate
+:c:type:`v4l2_dev ` with a particular parent.
+
+You can also supply a ``notify()`` callback that can be called by sub-devices
+to notify you of events. Whether you need to set this depends on the
+sub-device. Any notifications a sub-device supports must be defined in a header
+in ``include/media/subdevice.h``.
+
+V4L2 devices are unregistered 

Sony imx219 driver?

2016-07-21 Thread Dave Stevenson

Hi All.

Just a quick query to avoid duplicating effort. Has anyone worked on a 
Sony IMX219 (or other Sony sensor) subdevice driver as yet?


With the new Raspberry Pi camera being IMX219, and as Broadcom have 
released an soc_camera based driver for the sensor already 
(https://android.googlesource.com/kernel/bcm/+/android-bcm-tetra-3.10-lollipop-wear-release/drivers/media/video/imx219.c) 
I was going to investigate converting that to a subdevice. I just wanted 
to check this wasn't already in someone else's work queue.


A further Google shows that there's also an soc_camera IMX219 driver in 
ChromiumOS, copyright Andrew Chew @ Nvidia, but author Guennadi 
Liakhovetski who I know posts on here. 
https://chromium.googlesource.com/chromiumos/third_party/kernel/+/factory-ryu-6486.14.B-chromeos-3.14/drivers/media/i2c/soc_camera/imx219.c. 
The Broadcom one supports 8MPix and 1080P, the Chromium one only 8MP. 
Perhaps a hybrid of the feature set?
Throw in 
https://github.com/ZenfoneArea/android_kernel_asus_zenfone5/blob/master/linux/modules/camera/drivers/media/i2c/imx219/imx219.h 
as well, and we have register sets for numerous readout modes, plus 
there are the ones in the Pi firmware which can be extracted if necessary.



On a related note, if putting together a system with IMX219 or similar 
producing Bayer raw 10, the data on the CSI2 bus is one of the 
V4L2_PIX_FMT_SRGGB10P formats. What's the correct way to reflect that 
from the sensor subdevice in an MEDIA_BUS_FMT_ enum?
The closest is MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE (or LE), but the data 
isn't padded (the Pi CSI2 receiver can do the unpacking and padding, but 
that just takes up more memory). Or is it MEDIA_BUS_FMT_SBGGR10_1X10 
to describe the data on the bus correctly as 10bpp Bayer, and the odd 
packing is ignored. Or do we need new enums?


Thanks.
  Dave
--
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


[PATCH] V4L2: Add documentation for SDI timings and related flags

2016-07-21 Thread Charles-Antoine Couret
Signed-off-by: Charles-Antoine Couret 
---
 Documentation/media/uapi/v4l/vidioc-enuminput.rst  | 31 +-
 .../media/uapi/v4l/vidioc-g-dv-timings.rst | 15 +++
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/Documentation/media/uapi/v4l/vidioc-enuminput.rst 
b/Documentation/media/uapi/v4l/vidioc-enuminput.rst
index 5060f54..18331b9 100644
--- a/Documentation/media/uapi/v4l/vidioc-enuminput.rst
+++ b/Documentation/media/uapi/v4l/vidioc-enuminput.rst
@@ -260,17 +260,34 @@ at index zero, incrementing by one until the driver 
returns ``EINVAL``.
 
 -  .. row 11
 
-   -  :cspan:`2` Digital Video
+   -  ``V4L2_IN_ST_NO_V_LOCK``
+
+   -  0x0400
+
+   -  No vertical sync lock.
 
 -  .. row 12
 
+   -  ``V4L2_IN_ST_NO_STD_LOCK``
+
+   -  0x0800
+
+   -  No standard format lock in case of auto-detection format
+ by the component.
+
+-  .. row 13
+
+   -  :cspan:`2` Digital Video
+
+-  .. row 14
+
-  ``V4L2_IN_ST_NO_SYNC``
 
-  0x0001
 
-  No synchronization lock.
 
--  .. row 13
+-  .. row 15
 
-  ``V4L2_IN_ST_NO_EQU``
 
@@ -278,7 +295,7 @@ at index zero, incrementing by one until the driver returns 
``EINVAL``.
 
-  No equalizer lock.
 
--  .. row 14
+-  .. row 16
 
-  ``V4L2_IN_ST_NO_CARRIER``
 
@@ -286,11 +303,11 @@ at index zero, incrementing by one until the driver 
returns ``EINVAL``.
 
-  Carrier recovery failed.
 
--  .. row 15
+-  .. row 17
 
-  :cspan:`2` VCR and Set-Top Box
 
--  .. row 16
+-  .. row 18
 
-  ``V4L2_IN_ST_MACROVISION``
 
@@ -300,7 +317,7 @@ at index zero, incrementing by one until the driver returns 
``EINVAL``.
  signal to confuse video recorders. When this flag is set
  Macrovision has been detected.
 
--  .. row 17
+-  .. row 19
 
-  ``V4L2_IN_ST_NO_ACCESS``
 
@@ -308,7 +325,7 @@ at index zero, incrementing by one until the driver returns 
``EINVAL``.
 
-  Conditional access denied.
 
--  .. row 18
+-  .. row 20
 
-  ``V4L2_IN_ST_VTR``
 
diff --git a/Documentation/media/uapi/v4l/vidioc-g-dv-timings.rst 
b/Documentation/media/uapi/v4l/vidioc-g-dv-timings.rst
index f7bf21f..9acfa19 100644
--- a/Documentation/media/uapi/v4l/vidioc-g-dv-timings.rst
+++ b/Documentation/media/uapi/v4l/vidioc-g-dv-timings.rst
@@ -339,6 +339,13 @@ EBUSY
 
-  The timings follow the VESA Generalized Timings Formula standard
 
+-  .. row 7
+
+   -  ``V4L2_DV_BT_STD_SDI``
+
+   -  The timings follow the SDI Timings standard.
+ There are no horizontal syncs/porches at all in this format.
+ Total blanking timings must be set in hsync or vsync fields only.
 
 
 .. _dv-bt-flags:
@@ -415,3 +422,11 @@ EBUSY
  R'G'B' values use limited range (i.e. 16-235) as opposed to full
  range (i.e. 0-255). All formats defined in CEA-861 except for the
  640x480p59.94 format are CE formats.
+
+-  .. row 8
+
+   -  ``V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE``
+
+   -  Some formats like SMPTE-125M have an interlaced signal with a odd
+ total height. For these formats, if this flag is set, the first
+ field has the extra line. Else, it is the second field.
-- 
2.7.4

--
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 00/18] Complete moving media documentation to ReST format

2016-07-21 Thread Jonathan Corbet
On Thu, 21 Jul 2016 16:41:53 +0200
Markus Heiser  wrote:

> Am 21.07.2016 um 01:28 schrieb Jonathan Corbet :
>
> > I would hope that most people wouldn't have to worry about it, and would
> > be able to just use what their distribution provides - that's the reason
> > for the 1.2 compatibility requirement in the first place.  
> 
> Yes, but this is not what I mean ;) ... if someone use a distro 
> with a version > 1.2 and he use features not in 1.2, you -- the
> maintainer -- will get into trouble. 

Well, that's what we keep maintainers around.  The same holds for any
maintainer if somebody adds a dependency on a too-new version of some other
tool.  Such things happen, we simply fix them when they do.

> IMHO contributors need a reference documentation (e.g. at kernel.org)
> and a reference build environment (like you, see below).

Reference documentation, yes.  But I don't think every developer needs a
Sphinx 1.2 installation, just like they don't need to have gcc 3.2 around.
It's enough that somebody has it and will catch problems.

jon
--
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


[PATCH v4 1/2] SDI: add flag for SDI formats and SMPTE 125M definition

2016-07-21 Thread Charles-Antoine Couret
Adding others generic flags, which could be used by many
components like GS1662.

Signed-off-by: Charles-Antoine Couret 
---
 drivers/media/v4l2-core/v4l2-dv-timings.c | 11 +++
 include/uapi/linux/v4l2-dv-timings.h  | 12 
 include/uapi/linux/videodev2.h|  8 
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 889de0a..730a7c3 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -306,7 +306,7 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
char *prefix,
(bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
bt->il_vsync, bt->il_vbackporch);
pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock);
-   pr_info("%s: flags (0x%x):%s%s%s%s%s%s\n", dev_prefix, bt->flags,
+   pr_info("%s: flags (0x%x):%s%s%s%s%s%s%s\n", dev_prefix, bt->flags,
(bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ?
" REDUCED_BLANKING" : "",
((bt->flags & V4L2_DV_FL_REDUCED_BLANKING) &&
@@ -318,12 +318,15 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
char *prefix,
(bt->flags & V4L2_DV_FL_HALF_LINE) ?
" HALF_LINE" : "",
(bt->flags & V4L2_DV_FL_IS_CE_VIDEO) ?
-   " CE_VIDEO" : "");
-   pr_info("%s: standards (0x%x):%s%s%s%s\n", dev_prefix, bt->standards,
+   " CE_VIDEO" : "",
+   (bt->flags & V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE) ?
+   " FIRST_FIELD_EXTRA_LINE" : "");
+   pr_info("%s: standards (0x%x):%s%s%s%s%s\n", dev_prefix, bt->standards,
(bt->standards & V4L2_DV_BT_STD_CEA861) ?  " CEA" : "",
(bt->standards & V4L2_DV_BT_STD_DMT) ?  " DMT" : "",
(bt->standards & V4L2_DV_BT_STD_CVT) ?  " CVT" : "",
-   (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "");
+   (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "",
+   (bt->standards & V4L2_DV_BT_STD_SDI) ?  " SDI" : "");
 }
 EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
 
diff --git a/include/uapi/linux/v4l2-dv-timings.h 
b/include/uapi/linux/v4l2-dv-timings.h
index 086168e..0d7ea11 100644
--- a/include/uapi/linux/v4l2-dv-timings.h
+++ b/include/uapi/linux/v4l2-dv-timings.h
@@ -934,4 +934,16 @@
V4L2_DV_FL_REDUCED_BLANKING) \
 }
 
+/* SDI timings definitions */
+
+/* SMPTE-125M */
+#define V4L2_DV_BT_SDI_720X487I60 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 487, 1, \
+   V4L2_DV_HSYNC_POS_POL, \
+   1350, 0, 137, 0, 0, 19, 0, 0, 19, 0, \
+   V4L2_DV_BT_STD_SDI, \
+   V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE) \
+}
+
 #endif
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 8f95191..37126a4 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1259,6 +1259,7 @@ struct v4l2_bt_timings {
 #define V4L2_DV_BT_STD_DMT (1 << 1)  /* VESA Discrete Monitor Timings */
 #define V4L2_DV_BT_STD_CVT (1 << 2)  /* VESA Coordinated Video Timings */
 #define V4L2_DV_BT_STD_GTF (1 << 3)  /* VESA Generalized Timings Formula */
+#define V4L2_DV_BT_STD_SDI (1 << 4)  /* SDI Timings */
 
 /* Flags */
 
@@ -1290,6 +1291,11 @@ struct v4l2_bt_timings {
  * use the range 16-235) as opposed to 0-255. All formats defined in CEA-861
  * except for the 640x480 format are CE formats. */
 #define V4L2_DV_FL_IS_CE_VIDEO (1 << 4)
+/* Some formats like SMPTE-125M have an interlaced signal with a odd
+ * total height. For these formats, if this flag is set, the first
+ * field has the extra line. If not, it is the second field.
+ */
+#define V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE  (1 << 5)
 
 /* A few useful defines to calculate the total blanking and frame sizes */
 #define V4L2_DV_BT_BLANKING_WIDTH(bt) \
@@ -1413,6 +1419,8 @@ struct v4l2_input {
 /* field 'status' - analog */
 #define V4L2_IN_ST_NO_H_LOCK   0x0100  /* No horizontal sync lock */
 #define V4L2_IN_ST_COLOR_KILL  0x0200  /* Color killer is active */
+#define V4L2_IN_ST_NO_V_LOCK   0x0400  /* No vertical sync lock */
+#define V4L2_IN_ST_NO_STD_LOCK 0x0800  /* No standard format lock */
 
 /* field 'status' - digital */
 #define V4L2_IN_ST_NO_SYNC 0x0001  /* No synchronization lock */
-- 
2.7.4

--
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 00/18] Complete moving media documentation to ReST format

2016-07-21 Thread Markus Heiser

Am 19.07.2016 um 19:18 schrieb Mauro Carvalho Chehab :

>> A bit OT, but I see that you often use tabs / I recommend to use 
>> spaces for indentation:
>> 
>> http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#whitespace
> 
> The Kernel policies are to use tabs instead of spaces,

Yes, but not in text files .. I think.

-- Markus --

> and tabs have
> size of 8. I have some git automation to avoid commit patches with
> bad whitespaces, and some tools to convert spaces into tabs.

> 
> 
> Thanks,
> Mauro
> --
> 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


[v4l-utils RFC 3/3] mediatext: Add library

2016-07-21 Thread Sakari Ailus
libmediatext is a helper library for converting configurations (Media
controller links, V4L2 controls and V4L2 sub-device media bus formats and
selections) from text-based form into IOCTLs.

libmediatext depends on libv4l2subdev and libmediactl.

Signed-off-by: Sakari Ailus 
---
 libmediatext.pc.in |   10 +
 utils/media-ctl/Makefile.am|   10 +-
 utils/media-ctl/libmediatext.pc.in |   10 +
 utils/media-ctl/mediatext-test.c   |  114 ++
 utils/media-ctl/mediatext.c| 2012 
 utils/media-ctl/mediatext.h|   33 +
 6 files changed, 2187 insertions(+), 2 deletions(-)
 create mode 100644 libmediatext.pc.in
 create mode 100644 utils/media-ctl/libmediatext.pc.in
 create mode 100644 utils/media-ctl/mediatext-test.c
 create mode 100644 utils/media-ctl/mediatext.c
 create mode 100644 utils/media-ctl/mediatext.h

diff --git a/libmediatext.pc.in b/libmediatext.pc.in
new file mode 100644
index 000..6aa6353
--- /dev/null
+++ b/libmediatext.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libmediatext
+Description: Media controller and V4L2 text-based configuration library
+Version: @PACKAGE_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -lmediatext
diff --git a/utils/media-ctl/Makefile.am b/utils/media-ctl/Makefile.am
index 8fe653d..a233f16 100644
--- a/utils/media-ctl/Makefile.am
+++ b/utils/media-ctl/Makefile.am
@@ -1,4 +1,4 @@
-noinst_LTLIBRARIES = libmediactl.la libv4l2subdev.la
+noinst_LTLIBRARIES = libmediactl.la libv4l2subdev.la libmediatext.la
 
 libmediactl_la_SOURCES = libmediactl.c mediactl-priv.h
 libmediactl_la_CFLAGS = -static $(LIBUDEV_CFLAGS)
@@ -26,9 +26,15 @@ libv4l2subdev_la_LIBADD = libmediactl.la
 libv4l2subdev_la_CFLAGS = -static
 libv4l2subdev_la_LDFLAGS = -static
 
+libmediatext_la_SOURCES = mediatext.c
+libmediatext_la_CFLAGS = -static $(LIBUDEV_CFLAGS)
+libmediatext_la_LDFLAGS = -static $(LIBUDEV_LIBS)
+
 mediactl_includedir=$(includedir)/mediactl
 noinst_HEADERS = mediactl.h v4l2subdev.h
 
-bin_PROGRAMS = media-ctl
+bin_PROGRAMS = media-ctl mediatext
 media_ctl_SOURCES = media-ctl.c options.c options.h tools.h
 media_ctl_LDADD = libmediactl.la libv4l2subdev.la
+mediatext_SOURCES = mediatext-test.c
+mediatext_LDADD = libmediatext.la libmediactl.la libv4l2subdev.la
diff --git a/utils/media-ctl/libmediatext.pc.in 
b/utils/media-ctl/libmediatext.pc.in
new file mode 100644
index 000..6aa6353
--- /dev/null
+++ b/utils/media-ctl/libmediatext.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libmediatext
+Description: Media controller and V4L2 text-based configuration library
+Version: @PACKAGE_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -lmediatext
diff --git a/utils/media-ctl/mediatext-test.c b/utils/media-ctl/mediatext-test.c
new file mode 100644
index 000..6313fa5
--- /dev/null
+++ b/utils/media-ctl/mediatext-test.c
@@ -0,0 +1,114 @@
+/*
+ * libmediatext test program
+ *
+ * Copyright (C) 2013--2016 Intel Corporation
+ *
+ * Contact: Sakari Ailus 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mediactl.h"
+#include "mediatext.h"
+
+static const struct option opts[] = {
+   { "device", 1, 0, 'd', },
+   { "fd", 1, 0, 'f', },
+   { "help", 0, 0, 'h', },
+   { "verbose", 0, 0, 'v', },
+   { 0 },
+};
+
+void help(char *myname)
+{
+   fprintf(stderr, "usage: %s  \n\n", myname);
+   fprintf(stderr, "\tstring := [ v4l2-ctrl | v4l2-mbus | link-reset | 
link-conf]\n\n");
+   fprintf(stderr, "\tv4l2-ctrl := \"entity\" ctrl_type ctrl_id 
ctrl_value\n");
+   fprintf(stderr, "\tctrl_type := [ int | int64 | bitmask ]\n");
+   fprintf(stderr, "\tctrl_value := [ %%d | %%PRId64 | bitmask_value ]\n");
+   fprintf(stderr, "\tbitmask_value := b\n\n");
+   fprintf(stderr, "\tv4l2-mbus := \n");
+   fprintf(stderr, "\tlink-conf := \"entity\":pad -> 
\"entity\":pad[link-flags]\n");
+}
+
+int main(int argc, char *argv[])
+{
+   struct media_device *device;
+   struct media_text *mt;
+   bool verbose = false;
+   char *devname = "/dev/media0";
+   int fd 

[v4l-utils RFC 0/3] mediatext library and test program

2016-07-21 Thread Sakari Ailus
Hi everyone,

We've got a number of V4L2 (and MC) test programs for about as many reasons.
The existing programs are concentrated to work on a single device node at a
time, and with a single interface, be that Media controller or V4L2.

The test programs are also command line controlled, working their way with
the device at hand based on the information passed to the test programs on
the command line. This has made perfect sense for the past 15 years, as long
as we've had such test programs: they have covered, for large part, needs to
perform testing in various cases without leaving significant gaps.

With the upcoming request API, however, this has become insufficient. The
very nature of the request API requires that requests can contain resources
(e.g. memory buffers) that is associated to a number of video device nodes.
The requests may well be different from each other, including the types of
resources that are used for each request.

So I decided we need a new test program. The scope for the original
mediatext library and test program were slightly different from what is in
this (very RFC) patchset. I deemed mediatext as the best starting point for
writing a new test program.

mediatext acts as an interface between an end user or a script and the
kernel interfaces, with an ability to work with multiple devices at a time,
including multiple video nodes:

   shell script
   |
   |
   |  <- two-way pipe
   |
   |
   mediatext
 / | \
/  |  \
 /dev/video*   | /dev/v4l-subdev*
   |
 /dev/mediaX

The shell script (which could be any other program as well but shell scripts
are convenient for the purpose) is always in the control of the main loop of
the test. Events are delivered to the script by mediatext based on file
handle state changes, so the script has a possibility to react to each of
them (e.g. buffer becoming dequeueable on one of the video nodes).

A simple example script for a UVC compliant Logitech webcam is below. It
opens the device based on the name of the entity, and sets up the device for
streaming with a specified format with three MMAP buffers. The first 50
frames are written to a file, and capturing is stopped once about 100 frames
have been captured. Dequeued buffers are immediately requeued, and this is
explicitly done by the shell script.

-8<-
#!/bin/bash

eval_line() {
while [ $# -ne 0 ]; do
local name=${1%=*}
local value=${1#*=}
p[$name]="$value"
shift
done
}

coproc mediatext -d /dev/media0 2>&1

cat <&${COPROC[1]}
v4l open entity="UVC Camera (046d:0825)" name=uvc
v4l fmt vdev=uvc type=CAPTURE width=320 height=240 \
pixelformat=YUYV bytesperline=0
v4l reqbufs vdev=uvc type=CAPTURE count=3 memory=MMAP
v4l qbuf vdev=uvc
v4l qbuf vdev=uvc
v4l qbuf vdev=uvc
  
v4l streamon vdev=uvc type=CAPTURE
EOF

while IFS= read -ru ${COPROC[0]} line; do
unset p; declare -A p
eval eval_line $line
echo $line
case ${p[event]} in
dqbuf)
if ((${p[seq]} < 50)); then
echo v4l write vdev=uvc \
sequence=${p[seq]} >&${COPROC[1]}
fi
if ((${p[seq]} > 100)); then
echo quit >&${COPROC[1]}
fi
cat <&${COPROC[1]}
v4l qbuf vdev=uvc
EOF
;;
esac;
done
-8<-

Requests are naturally supported as well, right now only for buffer-related
IOCTLs but support for other IOCTLs can be added as well. The library has
been designed to be modular and easily extensible. There are no drivers
implementing them yet, and the kernel patches are still in development.

The kernel patches from which the headers have been generated from are
available here:



As noted, the test program is still in development phase. I thought this
still would be useful for others working on the request API so I decided to
share it already.

Current todo list:

- The scope of the current media-ctl functionality command format does not
  match with the rest of the program. To be fixed.

- Support requests for non-buffer related IOCTLs. This is pending on
  relevant kernel patches.

- Clean up command parameters and event messages to make them more
  consistent.

-- 
Kind regards,
Sakari

--
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


[v4l-utils RFC 2/3] Update header files for requests

2016-07-21 Thread Sakari Ailus
Fix libv4l2 and compliance tests as well for reserved field access.

Signed-off-by: Sakari Ailus 
---
 include/linux/media.h   | 32 +
 include/linux/v4l2-subdev.h | 11 --
 include/linux/videodev2.h   |  7 +--
 lib/libv4l2/libv4l2.c   |  4 ++--
 utils/v4l2-compliance/v4l2-test-buffers.cpp |  2 +-
 5 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/include/linux/media.h b/include/linux/media.h
index fdabb28..5e12826 100644
--- a/include/linux/media.h
+++ b/include/linux/media.h
@@ -384,10 +384,42 @@ struct media_v2_topology {
 
 /* ioctls */
 
+#define MEDIA_REQ_CMD_ALLOC0
+#define MEDIA_REQ_CMD_DELETE   1
+#define MEDIA_REQ_CMD_APPLY2
+#define MEDIA_REQ_CMD_QUEUE3
+
+#define MEDIA_REQ_FL_COMPLETE_EVENT(1 << 0)
+
+
+struct __attribute__ ((packed)) media_request_cmd {
+   __u32 cmd;
+   __u32 request;
+   __u32 flags;
+};
+
+struct __attribute__ ((packed)) media_event_request_complete {
+   __u32 id;
+};
+
+#define MEDIA_EVENT_TYPE_REQUEST_COMPLETE  1
+
+struct __attribute__ ((packed)) media_event {
+   __u32 type;
+   __u32 sequence;
+   __u32 reserved[4];
+
+   union {
+   struct media_event_request_complete req_complete;
+   };
+};
+
 #define MEDIA_IOC_DEVICE_INFO  _IOWR('|', 0x00, struct 
media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES_IOWR('|', 0x01, struct 
media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS   _IOWR('|', 0x02, struct 
media_links_enum)
 #define MEDIA_IOC_SETUP_LINK   _IOWR('|', 0x03, struct media_link_desc)
 #define MEDIA_IOC_G_TOPOLOGY   _IOWR('|', 0x04, struct 
media_v2_topology)
+#define MEDIA_IOC_REQUEST_CMD  _IOWR('|', 0x05, struct 
media_request_cmd)
+#define MEDIA_IOC_DQEVENT  _IOWR('|', 0x06, struct media_event)
 
 #endif /* __LINUX_MEDIA_H */
diff --git a/include/linux/v4l2-subdev.h b/include/linux/v4l2-subdev.h
index dbce2b5..dbb7c1d 100644
--- a/include/linux/v4l2-subdev.h
+++ b/include/linux/v4l2-subdev.h
@@ -32,10 +32,12 @@
  * enum v4l2_subdev_format_whence - Media bus format type
  * @V4L2_SUBDEV_FORMAT_TRY: try format, for negotiation only
  * @V4L2_SUBDEV_FORMAT_ACTIVE: active format, applied to the device
+ * @V4L2_SUBDEV_FORMAT_REQUEST: format stored in request
  */
 enum v4l2_subdev_format_whence {
V4L2_SUBDEV_FORMAT_TRY = 0,
V4L2_SUBDEV_FORMAT_ACTIVE = 1,
+   V4L2_SUBDEV_FORMAT_REQUEST = 2,
 };
 
 /**
@@ -43,12 +45,15 @@ enum v4l2_subdev_format_whence {
  * @which: format type (from enum v4l2_subdev_format_whence)
  * @pad: pad number, as reported by the media API
  * @format: media bus format (format code and frame size)
+ * @request: request ID (when which is set to V4L2_SUBDEV_FORMAT_REQUEST)
+ * @reserved: for future use, set to zero for now
  */
 struct v4l2_subdev_format {
__u32 which;
__u32 pad;
struct v4l2_mbus_framefmt format;
-   __u32 reserved[8];
+   __u32 request;
+   __u32 reserved[7];
 };
 
 /**
@@ -139,6 +144,7 @@ struct v4l2_subdev_frame_interval_enum {
  * defined in v4l2-common.h; V4L2_SEL_TGT_* .
  * @flags: constraint flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*.
  * @r: coordinates of the selection window
+ * @request: request ID (when which is set to V4L2_SUBDEV_FORMAT_REQUEST)
  * @reserved: for future use, set to zero for now
  *
  * Hardware may use multiple helper windows to process a video stream.
@@ -151,7 +157,8 @@ struct v4l2_subdev_selection {
__u32 target;
__u32 flags;
struct v4l2_rect r;
-   __u32 reserved[8];
+   __u32 request;
+   __u32 reserved[7];
 };
 
 /* Backwards compatibility define --- to be removed */
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 5b03ed4..4c13742 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -846,6 +846,7 @@ struct v4l2_plane {
  * @length:size in bytes of the buffer (NOT its payload) for single-plane
  * buffers (when type != *_MPLANE); number of elements in the
  * planes array for multi-plane buffers
+ * @request: this buffer should use this request
  *
  * Contains data exchanged by application and driver using one of the Streaming
  * I/O methods.
@@ -869,7 +870,7 @@ struct v4l2_buffer {
__s32   fd;
} m;
__u32   length;
-   __u32   reserved2;
+   __u32   request;
__u32   reserved;
 };
 
@@ -1967,6 +1968,7 @@ struct v4l2_plane_pix_format {
  * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
  * @quantization:  enum v4l2_quantization, colorspace quantization
  * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
+ * @request:   request ID

[v4l-utils RFC 1/3] mediatext: Extract list of V4L2 pixel format strings and 4cc codes

2016-07-21 Thread Sakari Ailus
Extract the list of V4L2 pixel format strings and 4cc codes from
videodev2.h for use in mediatext in order to convert user given format
names to 4cc codes that IOCTLs use.

Signed-off-by: Sakari Ailus 
---
 utils/media-ctl/Makefile.am | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/utils/media-ctl/Makefile.am b/utils/media-ctl/Makefile.am
index ee7dcc9..8fe653d 100644
--- a/utils/media-ctl/Makefile.am
+++ b/utils/media-ctl/Makefile.am
@@ -12,7 +12,12 @@ media-bus-format-codes.h: 
../../include/linux/media-bus-format.h
sed -e '/#define MEDIA_BUS_FMT/ ! d; s/.*#define //; /FIXED/ d; 
s/\t.*//; s/.*/ &,/;' \
< $< > $@
 
-BUILT_SOURCES = media-bus-format-names.h media-bus-format-codes.h
+v4l2-pix-formats.h: ../../include/linux/videodev2.h
+   sed -e '/#define V4L2_PIX_FMT_/ ! d; s/.*FMT_//; s/[\t ].*//; s/.*/{ 
\"&\", V4L2_PIX_FMT_& },/;' \
+   < $< > $@
+
+BUILT_SOURCES = media-bus-format-names.h media-bus-format-codes.h \
+   v4l2-pix-formats.h
 CLEANFILES = $(BUILT_SOURCES)
 
 nodist_libv4l2subdev_la_SOURCES = $(BUILT_SOURCES)
-- 
2.7.4

--
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


[PATCH v4 2/2] Add GS1662 driver, a video serializer

2016-07-21 Thread Charles-Antoine Couret
You can read datasheet here:
http://www.c-dis.net/media/871/GS1662_Datasheet.pdf

It's a component which supports HD and SD CEA or SDI formats
to SDI output. It's configured through SPI bus.

GS1662 driver is implemented as v4l2 subdev.

Signed-off-by: Charles-Antoine Couret 
---
 drivers/media/Kconfig  |   1 +
 drivers/media/Makefile |   2 +-
 drivers/media/spi/Kconfig  |   9 +
 drivers/media/spi/Makefile |   1 +
 drivers/media/spi/gs1662.c | 472 +
 5 files changed, 484 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/spi/Kconfig
 create mode 100644 drivers/media/spi/Makefile
 create mode 100644 drivers/media/spi/gs1662.c

diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index a8518fb..d2fa6e7 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -215,5 +215,6 @@ config MEDIA_ATTACH
 source "drivers/media/i2c/Kconfig"
 source "drivers/media/tuners/Kconfig"
 source "drivers/media/dvb-frontends/Kconfig"
+source "drivers/media/spi/Kconfig"
 
 endif # MEDIA_SUPPORT
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index e608bbc..75bc82e 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -28,6 +28,6 @@ obj-y += rc/
 # Finally, merge the drivers that require the core
 #
 
-obj-y += common/ platform/ pci/ usb/ mmc/ firewire/
+obj-y += common/ platform/ pci/ usb/ mmc/ firewire/ spi/
 obj-$(CONFIG_VIDEO_DEV) += radio/
 
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
new file mode 100644
index 000..fa47c90
--- /dev/null
+++ b/drivers/media/spi/Kconfig
@@ -0,0 +1,9 @@
+if VIDEO_V4L2
+
+config VIDEO_GS1662
+   tristate "Gennum Serializers video"
+   depends on SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   ---help---
+ Enable the GS1662 driver which serializes video streams.
+
+endif
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
new file mode 100644
index 000..ea64013
--- /dev/null
+++ b/drivers/media/spi/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
diff --git a/drivers/media/spi/gs1662.c b/drivers/media/spi/gs1662.c
new file mode 100644
index 000..f743423
--- /dev/null
+++ b/drivers/media/spi/gs1662.c
@@ -0,0 +1,472 @@
+/*
+ * GS1662 device registration.
+ *
+ * Copyright (C) 2015-2016 Nexvision
+ * Author: Charles-Antoine Couret 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REG_STATUS 0x04
+#define REG_FORCE_FMT  0x06
+#define REG_LINES_PER_FRAME0x12
+#define REG_WORDS_PER_LINE 0x13
+#define REG_WORDS_PER_ACT_LINE 0x14
+#define REG_ACT_LINES_PER_FRAME0x15
+
+#define MASK_H_LOCK0x001
+#define MASK_V_LOCK0x002
+#define MASK_STD_LOCK  0x004
+#define MASK_FORCE_STD 0x020
+#define MASK_STD_STATUS0x3E0
+
+#define GS_WIDTH_MIN   720
+#define GS_WIDTH_MAX   2048
+#define GS_HEIGHT_MIN  487
+#define GS_HEIGHT_MAX  1080
+#define GS_PIXELCLOCK_MIN  10519200
+#define GS_PIXELCLOCK_MAX  7425
+
+struct gs {
+   struct spi_device *pdev;
+   struct v4l2_subdev sd;
+   struct v4l2_dv_timings current_timings;
+   int enabled;
+};
+
+struct gs_reg_fmt {
+   u16 reg_value;
+   struct v4l2_dv_timings format;
+};
+
+struct gs_reg_fmt_custom {
+   u16 reg_value;
+   __u32 width;
+   __u32 height;
+   __u64 pixelclock;
+   __u32 interlaced;
+};
+
+static const struct spi_device_id gs_id[] = {
+   { "gs1662", 0 },
+   { }
+};
+MODULE_DEVICE_TABLE(spi, gs_id);
+
+static const struct v4l2_dv_timings fmt_cap[] = {
+   V4L2_DV_BT_SDI_720X487I60,
+   V4L2_DV_BT_CEA_720X576P50,
+   V4L2_DV_BT_CEA_1280X720P24,
+   V4L2_DV_BT_CEA_1280X720P25,
+   V4L2_DV_BT_CEA_1280X720P30,
+   V4L2_DV_BT_CEA_1280X720P50,
+   V4L2_DV_BT_CEA_1280X720P60,
+   V4L2_DV_BT_CEA_1920X1080P24,
+   V4L2_DV_BT_CEA_1920X1080P25,
+   V4L2_DV_BT_CEA_1920X1080P30,
+   V4L2_DV_BT_CEA_1920X1080I50,
+   V4L2_DV_BT_CEA_1920X1080I60,
+};
+
+static const struct gs_reg_fmt reg_fmt[] = {
+   { 0x00, V4L2_DV_BT_CEA_1280X720P60 },
+   { 0x01, V4L2_DV_BT_CEA_1280X720P60 },
+   { 0x02, V4L2_DV_BT_CEA_1280X720P30 },
+   { 0x03, V4L2_DV_BT_CEA_1280X720P30 },
+   { 0x04, V4L2_DV_BT_CEA_1280X720P50 },
+   { 0x05, V4L2_DV_BT_CEA_1280X720P50 },
+   

Re: [RFC 7/7] [media] rc: add support for IR LEDs driven through SPI

2016-07-21 Thread Andi Shyti
Hi Sean,

> > > > +   ret = regulator_enable(idata->regulator);
> > > > +   if (ret)
> > > > +   return ret;
> > > > +
> > > > +   mutex_lock(>mutex);
> > > > +   idata->xfer.len = n;
> > > > +   idata->xfer.tx_buf = buffer;
> > > > +   mutex_unlock(>mutex);
> > > 
> > > I'm not convinced the locking works here. You want to guard against 
> > > someone modifying xfer while you are sending (so in spi_sync_transfer), 
> > > which this locking is not doing. You could declare a 
> > > local "struct spi_transfer xfer" and avoid the mutex altogether.
> > 
> > I cannot declare xfer locally because the spi framework needs
> > a statically allocated xfer, so that either I dynamically
> > allocate it in the function or I declare it global in idata.
> 
> It can be stack allocated for sync transfers. You might want to lock
> the spi bus.

no, actually it's just dirty data and laziness, a memset to 0
fixes it :)

> > With the mutex I would like to prevent different tasks to change
> > the value at the same time, it's an easy case, it shouldn't make
> > much difference.
> 
> That's cargo-cult locking. It does not achieve anything.

yes, as I said, it's not a big thing, I can remove the mutex.

Thanks,
Andi
--
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


[PATCH v4 0/2] Add GS1662 driver

2016-07-21 Thread Charles-Antoine Couret
These patches add a driver for GS1662 component, a video serializer which
supports CEA and SDI timings.
To perform that, we need to determine SDI definition and some flags.

The associated documentation will be into another patchset to be
Sphinx comaptible.

This patchset add:
* rename V4L2_DV_FIRST_FIELD_EXTRA_LINE to 
V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE
* change V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE value and comments

Charles-Antoine Couret (2):
  SDI: add flag for SDI formats and SMPTE 125M definition
  Add GS1662 driver, a video serializer

Charles-Antoine Couret (2):
  SDI: add flag for SDI formats and SMPTE 125M definition
  Add GS1662 driver, a video serializer

 drivers/media/Kconfig |   1 +
 drivers/media/Makefile|   2 +-
 drivers/media/spi/Kconfig |   9 +
 drivers/media/spi/Makefile|   1 +
 drivers/media/spi/gs1662.c| 472 ++
 drivers/media/v4l2-core/v4l2-dv-timings.c |  11 +-
 include/uapi/linux/v4l2-dv-timings.h  |  12 +
 include/uapi/linux/videodev2.h|   8 +
 8 files changed, 511 insertions(+), 5 deletions(-)
 create mode 100644 drivers/media/spi/Kconfig
 create mode 100644 drivers/media/spi/Makefile
 create mode 100644 drivers/media/spi/gs1662.c

-- 
2.7.4

--
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 5/7] [media] ir-lirc-codec: do not handle any buffer for raw transmitters

2016-07-21 Thread Sean Young
Hi Andi,

On Thu, Jul 21, 2016 at 09:48:12AM +0900, Andi Shyti wrote:
> > > Raw transmitters receive the data which need to be sent to
> > > receivers from userspace as stream of bits, they don't require
> > > any handling from the lirc framework.
> > 
> > No drivers of type RC_DRIVER_IR_RAW_TX should handle tx just like any
> > other device, so data should be provided as an array of u32 alternating
> > pulse-space. If your device does not handle input like that then convert
> > it into that format in the driver. Every other driver has to do some
> > sort of conversion of that kind.
> 
> I don't see anything wrong here, that's how it works for example
> in Tizen or in Android for the boards I'm on: userspace sends a
> stream of bits that are then submitted to the IR as they are.

This introduces a new, incompatible api with no way of detecting it.

It's not a good format. For example the leading pulse (9ms) for nec ir
with a carrier of 38000 will be 342 bits. With the pulse-space format
it will be 32 bits.

Doing the conversion in kernel space will be cheap.

> If I change it to only pulse-space domain, then I wouldn't
> provide support for those platforms. Eventually I can add a new
> protocol.

But this is forcing an new, incompatible api onto the rest of us. 

This is the code in tizen:

https://build.tizen.org/package/rdiff?linkrev=base=device-manager-plugin-exynos5433=Tizen%3AIVI=2

If this patch was merged as-is tizen would have to be changed anyway
to use different ioctls. If that is true, can it switch to use 
pulse-space format in the same change? If LIRC_GET_FREQUENCY fails then
it would be a main-line kernel, else the existent driver.

I could not find the code in android. It might be useful to see so we
can find a solution that works for everyone.


Sean
--
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 00/18] Complete moving media documentation to ReST format

2016-07-21 Thread Markus Heiser

Am 21.07.2016 um 01:28 schrieb Jonathan Corbet :

> On Wed, 20 Jul 2016 08:07:54 +0200
> Markus Heiser  wrote:
> 
>> Jon, what do you think ... could we serve this 1.2 doc 
>> on https://www.kernel.org/doc/ as reference?
> 
> Seems like a good idea.  I don't really know who controls that directory,
> though; I can ping Konstantin and see what can be done there.  Failing
> that, I'd be more than happy to put it up on lwn, of course.
> 
>> And whats about those who have 1.3 (or any version >1.2) as default 
>> in the linux distro? Should they install a virtualenv?  ... it is
>> a dilemma.
> 
> I would hope that most people wouldn't have to worry about it, and would
> be able to just use what their distribution provides - that's the reason
> for the 1.2 compatibility requirement in the first place.

Yes, but this is not what I mean ;) ... if someone use a distro 
with a version > 1.2 and he use features not in 1.2, you -- the
maintainer -- will get into trouble. 

IMHO contributors need a reference documentation (e.g. at kernel.org)
and a reference build environment (like you, see below).

> I'll make a
> point of having a 1.2 installation around that I can test things with;
> that should suffice to catch any problems that sneak in.

This is what I called the reference build environment. IMHO a 
ref build env could only be assert by a virtualenv instance.

Here is what I tried to get one  

first: create instance:

 $ virtualenv /share/sph12env

second: source the virtualenv

 $ source /share/sph12env/bin/activate
 $ which pip
 /share/sph12env/bin/pip

third: install Sphinx 1.2

$ pip install Sphinx==1.2
$ sphinx-build --version
Sphinx (sphinx-build) 1.2

seems fine ... now install rtd theme :-o

$ pip install sphinx_rtd_theme==0.1.8
Collecting sphinx_rtd_theme==0.1.8
 Downloading sphinx_rtd_theme-0.1.8-py2.py3-none-any.whl (418kB)
Collecting sphinx>=1.3 (from sphinx_rtd_theme==0.1.8)
...

since sphinx>=1.3 is a requirement [1] of the sphinx_rtd_theme package
sphinx has been updated:

$ sphinx-build --version
Sphinx (sphinx-build) 1.4.5

Aaargh ... at the least now, I have strong doubts if it is a clever
decision to use an old sphinx version as reference.

Lets lean back and remember why we need this ... whatever
sphinx version a distro ships (with it's next update) you need a
reference environment ... version 1.2 or the latest version ... equal 
if you are a maintainer or a contributor ...  

So why not installing a updated version in a virtualenv on the build
server, may be in a jail. If contributors have installed older versions,
this is not a problem, the updated one is downward compatible.

[1] https://github.com/snide/sphinx_rtd_theme/blob/0.1.8/requirements.txt

-- Markus --








--
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


[PATCH] [media] cxd2841er: force 8MHz bandwidth for DVB-C if specified bw not supported

2016-07-21 Thread Abylay Ospan
if specified DVB-C bandwidth not supported then force 8MHz.
Should work for most cases.

Signed-off-by: Abylay Ospan 
---
 drivers/media/dvb-frontends/cxd2841er.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/dvb-frontends/cxd2841er.c 
b/drivers/media/dvb-frontends/cxd2841er.c
index 3df0604..10608a9 100644
--- a/drivers/media/dvb-frontends/cxd2841er.c
+++ b/drivers/media/dvb-frontends/cxd2841er.c
@@ -2763,6 +2763,14 @@ static int cxd2841er_sleep_tc_to_active_c_band(struct 
cxd2841er_priv *priv,
u8 b10_b6[3];
u32 iffreq;
 
+   if (bandwidth != 600 &&
+   bandwidth != 700 &&
+   bandwidth != 800) {
+   dev_info(>i2c->dev, "%s(): unsupported bandwidth %d. 
Forcing 8Mhz!\n",
+   __func__, bandwidth);
+   bandwidth = 800;
+   }
+
dev_dbg(>i2c->dev, "%s() bw=%d\n", __func__, bandwidth);
cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
switch (bandwidth) {
-- 
2.7.4

--
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 v3 1/2] SDI: add flag for SDI formats and SMPTE 125M definition

2016-07-21 Thread Hans Verkuil


On 07/21/2016 02:34 PM, Charles-Antoine Couret wrote:
> Adding others generic flags, which could be used by many
> components like GS1662.
> 
> Signed-off-by: Charles-Antoine Couret 
> ---
>  drivers/media/v4l2-core/v4l2-dv-timings.c | 11 +++
>  include/uapi/linux/v4l2-dv-timings.h  | 12 
>  include/uapi/linux/videodev2.h|  5 +
>  3 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
> b/drivers/media/v4l2-core/v4l2-dv-timings.c
> index 889de0a..13fbbde 100644
> --- a/drivers/media/v4l2-core/v4l2-dv-timings.c
> +++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
> @@ -306,7 +306,7 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
> char *prefix,
>   (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
>   bt->il_vsync, bt->il_vbackporch);
>   pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock);
> - pr_info("%s: flags (0x%x):%s%s%s%s%s%s\n", dev_prefix, bt->flags,
> + pr_info("%s: flags (0x%x):%s%s%s%s%s%s%s\n", dev_prefix, bt->flags,
>   (bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ?
>   " REDUCED_BLANKING" : "",
>   ((bt->flags & V4L2_DV_FL_REDUCED_BLANKING) &&
> @@ -318,12 +318,15 @@ void v4l2_print_dv_timings(const char *dev_prefix, 
> const char *prefix,
>   (bt->flags & V4L2_DV_FL_HALF_LINE) ?
>   " HALF_LINE" : "",
>   (bt->flags & V4L2_DV_FL_IS_CE_VIDEO) ?
> - " CE_VIDEO" : "");
> - pr_info("%s: standards (0x%x):%s%s%s%s\n", dev_prefix, bt->standards,
> + " CE_VIDEO" : "",
> + (bt->flags & V4L2_DV_FIRST_FIELD_EXTRA_LINE) ?
> + " FIRST_FIELD_EXTRA_LINE" : "");
> + pr_info("%s: standards (0x%x):%s%s%s%s%s\n", dev_prefix, bt->standards,
>   (bt->standards & V4L2_DV_BT_STD_CEA861) ?  " CEA" : "",
>   (bt->standards & V4L2_DV_BT_STD_DMT) ?  " DMT" : "",
>   (bt->standards & V4L2_DV_BT_STD_CVT) ?  " CVT" : "",
> - (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "");
> + (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "",
> + (bt->standards & V4L2_DV_BT_STD_SDI) ?  " SDI" : "");
>  }
>  EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
>  
> diff --git a/include/uapi/linux/v4l2-dv-timings.h 
> b/include/uapi/linux/v4l2-dv-timings.h
> index 086168e..6ee01f1 100644
> --- a/include/uapi/linux/v4l2-dv-timings.h
> +++ b/include/uapi/linux/v4l2-dv-timings.h
> @@ -934,4 +934,16 @@
>   V4L2_DV_FL_REDUCED_BLANKING) \
>  }
>  
> +/* SDI timings definitions */
> +
> +/* SMPTE-125M */
> +#define V4L2_DV_BT_SDI_720X487I60 { \
> + .type = V4L2_DV_BT_656_1120, \
> + V4L2_INIT_BT_TIMINGS(720, 487, 1, \
> + V4L2_DV_HSYNC_POS_POL, \
> + 1350, 0, 137, 0, 0, 19, 0, 0, 19, 0, \
> + V4L2_DV_BT_STD_SDI, \
> + V4L2_DV_FIRST_FIELD_EXTRA_LINE) \
> +}
> +
>  #endif
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 8f95191..4641f13 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -1259,6 +1259,7 @@ struct v4l2_bt_timings {
>  #define V4L2_DV_BT_STD_DMT   (1 << 1)  /* VESA Discrete Monitor Timings */
>  #define V4L2_DV_BT_STD_CVT   (1 << 2)  /* VESA Coordinated Video Timings */
>  #define V4L2_DV_BT_STD_GTF   (1 << 3)  /* VESA Generalized Timings Formula */
> +#define V4L2_DV_BT_STD_SDI   (1 << 4)  /* SDI Timings */
>  
>  /* Flags */
>  
> @@ -1363,6 +1364,8 @@ struct v4l2_bt_timings_cap {
>  #define V4L2_DV_BT_CAP_REDUCED_BLANKING  (1 << 2)
>  /* Supports custom formats */
>  #define V4L2_DV_BT_CAP_CUSTOM(1 << 3)
> +/* In case of odd format, to know the field which has the extra line */
> +#define V4L2_DV_FIRST_FIELD_EXTRA_LINE   (1 << 4)

This isn't a capability, it is a flag, so this should be next to the other
V4L2_DV_FL_* defines, and its prefix should be V4L2_DV_FL_ (note the FL).

>  
>  /** struct v4l2_dv_timings_cap - DV timings capabilities
>   * @type:the type of the timings (same as in struct v4l2_dv_timings)
> @@ -1413,6 +1416,8 @@ struct v4l2_input {
>  /* field 'status' - analog */
>  #define V4L2_IN_ST_NO_H_LOCK   0x0100  /* No horizontal sync lock */
>  #define V4L2_IN_ST_COLOR_KILL  0x0200  /* Color killer is active */
> +#define V4L2_IN_ST_NO_V_LOCK   0x0400  /* No vertical sync lock */
> +#define V4L2_IN_ST_NO_STD_LOCK 0x0800  /* No standard format lock */
>  
>  /* field 'status' - digital */
>  #define V4L2_IN_ST_NO_SYNC 0x0001  /* No synchronization lock */
> 

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to 

Re: [PATCHv2 0/2] vb2: check for valid device pointer

2016-07-21 Thread Marek Szyprowski

Hi


On 2016-07-21 14:14, Hans Verkuil wrote:

From: Hans Verkuil 

Make error handling of alloc, get_userptr and attach_dmabuf systematic.

Add tests to check for a valid non-NULL device pointer.


Acked-by: Marek Szyprowski 



Regards,

Hans

Changes since v1:

- Split into two patches
- Drop pr_debug

Hans Verkuil (2):
   vb2: don't return NULL for alloc and get_userptr ops
   vb2: add WARN_ONs checking if a valid struct device was passed

  drivers/media/v4l2-core/videobuf2-core.c   | 12 
  drivers/media/v4l2-core/videobuf2-dma-contig.c |  9 +
  drivers/media/v4l2-core/videobuf2-dma-sg.c | 19 +--
  drivers/media/v4l2-core/videobuf2-vmalloc.c| 13 -
  include/media/videobuf2-core.h |  6 +++---
  5 files changed, 41 insertions(+), 18 deletions(-)



Best regards
--
Marek Szyprowski, PhD
Samsung R Institute Poland

--
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: [PATCHv2 0/2] vb2: check for valid device pointer

2016-07-21 Thread Sakari Ailus
On Thu, Jul 21, 2016 at 02:14:01PM +0200, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> Make error handling of alloc, get_userptr and attach_dmabuf systematic.
> 
> Add tests to check for a valid non-NULL device pointer.

Thanks!

Acked-by: Sakari Ailus 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
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


[PATCH v3 1/2] SDI: add flag for SDI formats and SMPTE 125M definition

2016-07-21 Thread Charles-Antoine Couret
Adding others generic flags, which could be used by many
components like GS1662.

Signed-off-by: Charles-Antoine Couret 
---
 drivers/media/v4l2-core/v4l2-dv-timings.c | 11 +++
 include/uapi/linux/v4l2-dv-timings.h  | 12 
 include/uapi/linux/videodev2.h|  5 +
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 889de0a..13fbbde 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -306,7 +306,7 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
char *prefix,
(bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
bt->il_vsync, bt->il_vbackporch);
pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock);
-   pr_info("%s: flags (0x%x):%s%s%s%s%s%s\n", dev_prefix, bt->flags,
+   pr_info("%s: flags (0x%x):%s%s%s%s%s%s%s\n", dev_prefix, bt->flags,
(bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ?
" REDUCED_BLANKING" : "",
((bt->flags & V4L2_DV_FL_REDUCED_BLANKING) &&
@@ -318,12 +318,15 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
char *prefix,
(bt->flags & V4L2_DV_FL_HALF_LINE) ?
" HALF_LINE" : "",
(bt->flags & V4L2_DV_FL_IS_CE_VIDEO) ?
-   " CE_VIDEO" : "");
-   pr_info("%s: standards (0x%x):%s%s%s%s\n", dev_prefix, bt->standards,
+   " CE_VIDEO" : "",
+   (bt->flags & V4L2_DV_FIRST_FIELD_EXTRA_LINE) ?
+   " FIRST_FIELD_EXTRA_LINE" : "");
+   pr_info("%s: standards (0x%x):%s%s%s%s%s\n", dev_prefix, bt->standards,
(bt->standards & V4L2_DV_BT_STD_CEA861) ?  " CEA" : "",
(bt->standards & V4L2_DV_BT_STD_DMT) ?  " DMT" : "",
(bt->standards & V4L2_DV_BT_STD_CVT) ?  " CVT" : "",
-   (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "");
+   (bt->standards & V4L2_DV_BT_STD_GTF) ?  " GTF" : "",
+   (bt->standards & V4L2_DV_BT_STD_SDI) ?  " SDI" : "");
 }
 EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
 
diff --git a/include/uapi/linux/v4l2-dv-timings.h 
b/include/uapi/linux/v4l2-dv-timings.h
index 086168e..6ee01f1 100644
--- a/include/uapi/linux/v4l2-dv-timings.h
+++ b/include/uapi/linux/v4l2-dv-timings.h
@@ -934,4 +934,16 @@
V4L2_DV_FL_REDUCED_BLANKING) \
 }
 
+/* SDI timings definitions */
+
+/* SMPTE-125M */
+#define V4L2_DV_BT_SDI_720X487I60 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 487, 1, \
+   V4L2_DV_HSYNC_POS_POL, \
+   1350, 0, 137, 0, 0, 19, 0, 0, 19, 0, \
+   V4L2_DV_BT_STD_SDI, \
+   V4L2_DV_FIRST_FIELD_EXTRA_LINE) \
+}
+
 #endif
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 8f95191..4641f13 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1259,6 +1259,7 @@ struct v4l2_bt_timings {
 #define V4L2_DV_BT_STD_DMT (1 << 1)  /* VESA Discrete Monitor Timings */
 #define V4L2_DV_BT_STD_CVT (1 << 2)  /* VESA Coordinated Video Timings */
 #define V4L2_DV_BT_STD_GTF (1 << 3)  /* VESA Generalized Timings Formula */
+#define V4L2_DV_BT_STD_SDI (1 << 4)  /* SDI Timings */
 
 /* Flags */
 
@@ -1363,6 +1364,8 @@ struct v4l2_bt_timings_cap {
 #define V4L2_DV_BT_CAP_REDUCED_BLANKING(1 << 2)
 /* Supports custom formats */
 #define V4L2_DV_BT_CAP_CUSTOM  (1 << 3)
+/* In case of odd format, to know the field which has the extra line */
+#define V4L2_DV_FIRST_FIELD_EXTRA_LINE (1 << 4)
 
 /** struct v4l2_dv_timings_cap - DV timings capabilities
  * @type:  the type of the timings (same as in struct v4l2_dv_timings)
@@ -1413,6 +1416,8 @@ struct v4l2_input {
 /* field 'status' - analog */
 #define V4L2_IN_ST_NO_H_LOCK   0x0100  /* No horizontal sync lock */
 #define V4L2_IN_ST_COLOR_KILL  0x0200  /* Color killer is active */
+#define V4L2_IN_ST_NO_V_LOCK   0x0400  /* No vertical sync lock */
+#define V4L2_IN_ST_NO_STD_LOCK 0x0800  /* No standard format lock */
 
 /* field 'status' - digital */
 #define V4L2_IN_ST_NO_SYNC 0x0001  /* No synchronization lock */
-- 
2.7.4

--
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


[PATCH v3 2/2] Add GS1662 driver, a video serializer

2016-07-21 Thread Charles-Antoine Couret
You can read datasheet here:
http://www.c-dis.net/media/871/GS1662_Datasheet.pdf

It's a component which supports HD and SD CEA or SDI formats
to SDI output. It's configured through SPI bus.

GS1662 driver is implemented as v4l2 subdev.

Signed-off-by: Charles-Antoine Couret 
---
 drivers/media/Kconfig  |   1 +
 drivers/media/Makefile |   2 +-
 drivers/media/spi/Kconfig  |   9 +
 drivers/media/spi/Makefile |   1 +
 drivers/media/spi/gs1662.c | 472 +
 5 files changed, 484 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/spi/Kconfig
 create mode 100644 drivers/media/spi/Makefile
 create mode 100644 drivers/media/spi/gs1662.c

diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index a8518fb..d2fa6e7 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -215,5 +215,6 @@ config MEDIA_ATTACH
 source "drivers/media/i2c/Kconfig"
 source "drivers/media/tuners/Kconfig"
 source "drivers/media/dvb-frontends/Kconfig"
+source "drivers/media/spi/Kconfig"
 
 endif # MEDIA_SUPPORT
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index e608bbc..75bc82e 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -28,6 +28,6 @@ obj-y += rc/
 # Finally, merge the drivers that require the core
 #
 
-obj-y += common/ platform/ pci/ usb/ mmc/ firewire/
+obj-y += common/ platform/ pci/ usb/ mmc/ firewire/ spi/
 obj-$(CONFIG_VIDEO_DEV) += radio/
 
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
new file mode 100644
index 000..fa47c90
--- /dev/null
+++ b/drivers/media/spi/Kconfig
@@ -0,0 +1,9 @@
+if VIDEO_V4L2
+
+config VIDEO_GS1662
+   tristate "Gennum Serializers video"
+   depends on SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   ---help---
+ Enable the GS1662 driver which serializes video streams.
+
+endif
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
new file mode 100644
index 000..ea64013
--- /dev/null
+++ b/drivers/media/spi/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
diff --git a/drivers/media/spi/gs1662.c b/drivers/media/spi/gs1662.c
new file mode 100644
index 000..f743423
--- /dev/null
+++ b/drivers/media/spi/gs1662.c
@@ -0,0 +1,472 @@
+/*
+ * GS1662 device registration.
+ *
+ * Copyright (C) 2015-2016 Nexvision
+ * Author: Charles-Antoine Couret 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REG_STATUS 0x04
+#define REG_FORCE_FMT  0x06
+#define REG_LINES_PER_FRAME0x12
+#define REG_WORDS_PER_LINE 0x13
+#define REG_WORDS_PER_ACT_LINE 0x14
+#define REG_ACT_LINES_PER_FRAME0x15
+
+#define MASK_H_LOCK0x001
+#define MASK_V_LOCK0x002
+#define MASK_STD_LOCK  0x004
+#define MASK_FORCE_STD 0x020
+#define MASK_STD_STATUS0x3E0
+
+#define GS_WIDTH_MIN   720
+#define GS_WIDTH_MAX   2048
+#define GS_HEIGHT_MIN  487
+#define GS_HEIGHT_MAX  1080
+#define GS_PIXELCLOCK_MIN  10519200
+#define GS_PIXELCLOCK_MAX  7425
+
+struct gs {
+   struct spi_device *pdev;
+   struct v4l2_subdev sd;
+   struct v4l2_dv_timings current_timings;
+   int enabled;
+};
+
+struct gs_reg_fmt {
+   u16 reg_value;
+   struct v4l2_dv_timings format;
+};
+
+struct gs_reg_fmt_custom {
+   u16 reg_value;
+   __u32 width;
+   __u32 height;
+   __u64 pixelclock;
+   __u32 interlaced;
+};
+
+static const struct spi_device_id gs_id[] = {
+   { "gs1662", 0 },
+   { }
+};
+MODULE_DEVICE_TABLE(spi, gs_id);
+
+static const struct v4l2_dv_timings fmt_cap[] = {
+   V4L2_DV_BT_SDI_720X487I60,
+   V4L2_DV_BT_CEA_720X576P50,
+   V4L2_DV_BT_CEA_1280X720P24,
+   V4L2_DV_BT_CEA_1280X720P25,
+   V4L2_DV_BT_CEA_1280X720P30,
+   V4L2_DV_BT_CEA_1280X720P50,
+   V4L2_DV_BT_CEA_1280X720P60,
+   V4L2_DV_BT_CEA_1920X1080P24,
+   V4L2_DV_BT_CEA_1920X1080P25,
+   V4L2_DV_BT_CEA_1920X1080P30,
+   V4L2_DV_BT_CEA_1920X1080I50,
+   V4L2_DV_BT_CEA_1920X1080I60,
+};
+
+static const struct gs_reg_fmt reg_fmt[] = {
+   { 0x00, V4L2_DV_BT_CEA_1280X720P60 },
+   { 0x01, V4L2_DV_BT_CEA_1280X720P60 },
+   { 0x02, V4L2_DV_BT_CEA_1280X720P30 },
+   { 0x03, V4L2_DV_BT_CEA_1280X720P30 },
+   { 0x04, V4L2_DV_BT_CEA_1280X720P50 },
+   { 0x05, V4L2_DV_BT_CEA_1280X720P50 },
+   

[PATCH v3 0/2] Add GS1662 driver

2016-07-21 Thread Charles-Antoine Couret
These patches add a driver for GS1662 component, a video serializer which
supports CEA and SDI timings.
To perform that, we need to determine SDI definition and some flags.

This third patchset add:
* flags printing in v4l2_print_dv_timings() function
* improvement of some comments
* additional comments
* timings->pad checking
* fix configuration dependencies

Charles-Antoine Couret (2):
  SDI: add flag for SDI formats and SMPTE 125M definition
  Add GS1662 driver, a video serializer

 drivers/media/Kconfig |   1 +
 drivers/media/Makefile|   2 +-
 drivers/media/spi/Kconfig |   9 +
 drivers/media/spi/Makefile|   1 +
 drivers/media/spi/gs1662.c| 472 ++
 drivers/media/v4l2-core/v4l2-dv-timings.c |  11 +-
 include/uapi/linux/v4l2-dv-timings.h  |  12 +
 include/uapi/linux/videodev2.h|   5 +
 8 files changed, 508 insertions(+), 5 deletions(-)
 create mode 100644 drivers/media/spi/Kconfig
 create mode 100644 drivers/media/spi/Makefile
 create mode 100644 drivers/media/spi/gs1662.c

-- 
2.7.4

--
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


[PATCHv2 1/2] vb2: don't return NULL for alloc and get_userptr ops

2016-07-21 Thread Hans Verkuil
From: Hans Verkuil 

Always return an ERR_PTR() instead of NULL.

This makes the behavior of alloc, get_userptr and attach_dmabuf the
same.

Update the documentation in videobuf2-core.h as well.

Signed-off-by: Hans Verkuil 
---
 drivers/media/v4l2-core/videobuf2-core.c| 12 
 drivers/media/v4l2-core/videobuf2-dma-sg.c  | 13 +++--
 drivers/media/v4l2-core/videobuf2-vmalloc.c | 13 -
 include/media/videobuf2-core.h  |  6 +++---
 4 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index ca8ffeb..4d60bdb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -198,6 +198,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
void *mem_priv;
int plane;
+   int ret = -ENOMEM;
 
/*
 * Allocate memory for all planes in this buffer
@@ -209,8 +210,11 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
mem_priv = call_ptr_memop(vb, alloc,
q->alloc_devs[plane] ? : q->dev,
q->dma_attrs, size, dma_dir, q->gfp_flags);
-   if (IS_ERR_OR_NULL(mem_priv))
+   if (IS_ERR(mem_priv)) {
+   if (mem_priv)
+   ret = PTR_ERR(mem_priv);
goto free;
+   }
 
/* Associate allocator private data with this plane */
vb->planes[plane].mem_priv = mem_priv;
@@ -224,7 +228,7 @@ free:
vb->planes[plane - 1].mem_priv = NULL;
}
 
-   return -ENOMEM;
+   return ret;
 }
 
 /**
@@ -1136,10 +1140,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
void *pb)
q->alloc_devs[plane] ? : q->dev,
planes[plane].m.userptr,
planes[plane].length, dma_dir);
-   if (IS_ERR_OR_NULL(mem_priv)) {
+   if (IS_ERR(mem_priv)) {
dprintk(1, "failed acquiring userspace "
"memory for plane %d\n", plane);
-   ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
+   ret = PTR_ERR(mem_priv);
goto err;
}
vb->planes[plane].mem_priv = mem_priv;
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index a39db8a..e2afd2c 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -107,11 +107,12 @@ static void *vb2_dma_sg_alloc(struct device *dev, const 
struct dma_attrs *dma_at
 
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, );
 
-   if (WARN_ON(dev == NULL))
-   return NULL;
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 
buf->vaddr = NULL;
buf->dma_dir = dma_dir;
@@ -169,7 +170,7 @@ fail_pages_alloc:
kfree(buf->pages);
 fail_pages_array_alloc:
kfree(buf);
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 }
 
 static void vb2_dma_sg_put(void *buf_priv)
@@ -234,7 +235,7 @@ static void *vb2_dma_sg_get_userptr(struct device *dev, 
unsigned long vaddr,
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, );
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 
buf->vaddr = NULL;
buf->dev = dev;
@@ -274,7 +275,7 @@ userptr_fail_sgtable:
vb2_destroy_framevec(vec);
 userptr_fail_pfnvec:
kfree(buf);
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 }
 
 /*
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c 
b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 7e8a07e..4fdfefd 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -41,7 +41,7 @@ static void *vb2_vmalloc_alloc(struct device *dev, const 
struct dma_attrs *attrs
 
buf = kzalloc(sizeof(*buf), GFP_KERNEL | gfp_flags);
if (!buf)
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 
buf->size = size;
buf->vaddr = vmalloc_user(buf->size);
@@ -53,7 +53,7 @@ static void *vb2_vmalloc_alloc(struct device *dev, const 
struct dma_attrs *attrs
if (!buf->vaddr) {
pr_debug("vmalloc of size %ld failed\n", buf->size);
kfree(buf);
-   return NULL;
+   return ERR_PTR(-ENOMEM);
}
 
atomic_inc(>refcount);
@@ -77,17 +77,20 @@ static void *vb2_vmalloc_get_userptr(struct 

[PATCHv2 2/2] vb2: add WARN_ONs checking if a valid struct device was passed

2016-07-21 Thread Hans Verkuil
From: Hans Verkuil 

The dma-contig and dma-sg memops require a valid struct device for
the DMA to be handled correctly.

Call WARN_ON and return ERR_PTR(-EINVAL) if it was NULL.

Setting the correct device pointer was forgotten in several new driver
submissions. This was caught during code review, but it really should be
caught in the code.

Signed-off-by: Hans Verkuil 
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 9 +
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 6 ++
 2 files changed, 15 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 863f658..925b34b 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -141,6 +141,9 @@ static void *vb2_dc_alloc(struct device *dev, const struct 
dma_attrs *attrs,
 {
struct vb2_dc_buf *buf;
 
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
@@ -499,6 +502,9 @@ static void *vb2_dc_get_userptr(struct device *dev, 
unsigned long vaddr,
return ERR_PTR(-EINVAL);
}
 
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
@@ -679,6 +685,9 @@ static void *vb2_dc_attach_dmabuf(struct device *dev, 
struct dma_buf *dbuf,
if (dbuf->size < size)
return ERR_PTR(-EFAULT);
 
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index e2afd2c..64a386d 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -232,6 +232,9 @@ static void *vb2_dma_sg_get_userptr(struct device *dev, 
unsigned long vaddr,
DEFINE_DMA_ATTRS(attrs);
struct frame_vector *vec;
 
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, );
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
@@ -618,6 +621,9 @@ static void *vb2_dma_sg_attach_dmabuf(struct device *dev, 
struct dma_buf *dbuf,
struct vb2_dma_sg_buf *buf;
struct dma_buf_attachment *dba;
 
+   if (WARN_ON(!dev))
+   return ERR_PTR(-EINVAL);
+
if (dbuf->size < size)
return ERR_PTR(-EFAULT);
 
-- 
2.8.1

--
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


[PATCHv2 0/2] vb2: check for valid device pointer

2016-07-21 Thread Hans Verkuil
From: Hans Verkuil 

Make error handling of alloc, get_userptr and attach_dmabuf systematic.

Add tests to check for a valid non-NULL device pointer.

Regards,

Hans

Changes since v1:

- Split into two patches
- Drop pr_debug

Hans Verkuil (2):
  vb2: don't return NULL for alloc and get_userptr ops
  vb2: add WARN_ONs checking if a valid struct device was passed

 drivers/media/v4l2-core/videobuf2-core.c   | 12 
 drivers/media/v4l2-core/videobuf2-dma-contig.c |  9 +
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 19 +--
 drivers/media/v4l2-core/videobuf2-vmalloc.c| 13 -
 include/media/videobuf2-core.h |  6 +++---
 5 files changed, 41 insertions(+), 18 deletions(-)

-- 
2.8.1

--
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


[PATCH v3 4/5] media: Add flags to tell whether to take graph mutex for an IOCTL

2016-07-21 Thread Sakari Ailus
New IOCTLs (especially for the request API) do not necessarily need the
graph mutex acquired. Leave this up to the drivers.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
---
 drivers/media/media-device.c | 47 ++--
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 87d17a0..6dfcc50 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -381,20 +381,25 @@ static long copy_arg_to_user(void __user *uarg, void 
*karg, unsigned int cmd)
return 0;
 }
 
-#define MEDIA_IOC_ARG(__cmd, func, from_user, to_user) \
-   [_IOC_NR(MEDIA_IOC_##__cmd)] = {\
-   .cmd = MEDIA_IOC_##__cmd,   \
+/* Do acquire the graph mutex */
+#define MEDIA_IOC_FL_GRAPH_MUTEX   BIT(0)
+
+#define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user) \
+   [_IOC_NR(MEDIA_IOC_##__cmd)] = {\
+   .cmd = MEDIA_IOC_##__cmd,   \
.fn = (long (*)(struct media_device *, void *))func,\
-   .arg_from_user = from_user, \
-   .arg_to_user = to_user, \
+   .flags = fl,\
+   .arg_from_user = from_user, \
+   .arg_to_user = to_user, \
}
 
-#define MEDIA_IOC(__cmd, func) \
-   MEDIA_IOC_ARG(__cmd, func, copy_arg_from_user, copy_arg_to_user)
+#define MEDIA_IOC(__cmd, func, fl) \
+   MEDIA_IOC_ARG(__cmd, func, fl, copy_arg_from_user, copy_arg_to_user)
 
 /* the table is indexed by _IOC_NR(cmd) */
 struct media_ioctl_info {
unsigned int cmd;
+   unsigned short flags;
long (*fn)(struct media_device *dev, void *arg);
long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
@@ -435,9 +440,13 @@ static long __media_device_ioctl(
goto out_free;
}
 
-   mutex_lock(>graph_mutex);
+   if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
+   mutex_lock(>graph_mutex);
+
ret = info->fn(dev, karg);
-   mutex_unlock(>graph_mutex);
+
+   if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
+   mutex_unlock(>graph_mutex);
 
if (!ret && info->arg_to_user)
ret = info->arg_to_user(arg, karg, cmd);
@@ -450,11 +459,11 @@ out_free:
 }
 
 static const struct media_ioctl_info ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
-   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
-   MEDIA_IOC(ENUM_LINKS, media_device_enum_links),
-   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
-   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_LINKS, media_device_enum_links, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, 
MEDIA_IOC_FL_GRAPH_MUTEX),
 };
 
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
@@ -497,11 +506,11 @@ static long from_user_enum_links32(void *karg, void 
__user *uarg,
 #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct 
media_links_enum32)
 
 static const struct media_ioctl_info compat_ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
-   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
-   MEDIA_IOC_ARG(ENUM_LINKS32, media_device_enum_links, 
from_user_enum_links32, NULL),
-   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
-   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC_ARG(ENUM_LINKS32, media_device_enum_links, 
MEDIA_IOC_FL_GRAPH_MUTEX, from_user_enum_links32, NULL),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, 
MEDIA_IOC_FL_GRAPH_MUTEX),
 };
 
 static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
-- 
2.7.4

--
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


[PATCH v3 5/5] media: Support variable size IOCTL arguments

2016-07-21 Thread Sakari Ailus
Instead of checking for a strict size for the IOCTL arguments, place
minimum and maximum limits.

As an additional bonus, IOCTL handlers will be able to check whether the
caller actually set (using the argument size) the field vs. assigning it
to zero. Separate macro can be provided for that.

This will be easier for applications as well since there is no longer the
problem of setting the reserved fields zero, or at least it is a lesser
problem.

Signed-off-by: Sakari Ailus 
---
 drivers/media/media-device.c | 52 +++-
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 6dfcc50..c7be2ce 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -384,32 +384,71 @@ static long copy_arg_to_user(void __user *uarg, void 
*karg, unsigned int cmd)
 /* Do acquire the graph mutex */
 #define MEDIA_IOC_FL_GRAPH_MUTEX   BIT(0)
 
-#define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user) \
+#define MEDIA_IOC_SZ_ARG(__cmd, func, fl, alt_sz, from_user, to_user)  \
[_IOC_NR(MEDIA_IOC_##__cmd)] = {\
.cmd = MEDIA_IOC_##__cmd,   \
.fn = (long (*)(struct media_device *, void *))func,\
.flags = fl,\
+   .alt_arg_sizes = alt_sz,\
.arg_from_user = from_user, \
.arg_to_user = to_user, \
}
 
-#define MEDIA_IOC(__cmd, func, fl) \
-   MEDIA_IOC_ARG(__cmd, func, fl, copy_arg_from_user, copy_arg_to_user)
+#define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user) \
+   MEDIA_IOC_SZ_ARG(__cmd, func, fl, NULL, from_user, to_user)
+
+#define MEDIA_IOC_SZ(__cmd, func, fl, alt_sz)  \
+   MEDIA_IOC_SZ_ARG(__cmd, func, fl, alt_sz,   \
+copy_arg_from_user, copy_arg_to_user)
+
+#define MEDIA_IOC(__cmd, func, fl) \
+   MEDIA_IOC_ARG(__cmd, func, fl,  \
+ copy_arg_from_user, copy_arg_to_user)
 
 /* the table is indexed by _IOC_NR(cmd) */
 struct media_ioctl_info {
unsigned int cmd;
unsigned short flags;
+   const unsigned short *alt_arg_sizes;
long (*fn)(struct media_device *dev, void *arg);
long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
 };
 
+#define MASK_IOC_SIZE(cmd) \
+   ((cmd) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
+
 static inline long is_valid_ioctl(const struct media_ioctl_info *info,
  unsigned int len, unsigned int cmd)
 {
-   return (_IOC_NR(cmd) >= len
-   || info[_IOC_NR(cmd)].cmd != cmd) ? -ENOIOCTLCMD : 0;
+   const unsigned short *alt_arg_sizes;
+
+   if (unlikely(_IOC_NR(cmd) >= len))
+   return -ENOIOCTLCMD;
+
+   info += _IOC_NR(cmd);
+
+   if (info->cmd == cmd)
+   return 0;
+
+   /*
+* Verify that the size-dependent patch of the IOCTL command
+* matches and that the size does not exceed the principal
+* argument size.
+*/
+   if (unlikely(MASK_IOC_SIZE(info->cmd) != MASK_IOC_SIZE(cmd)
+|| _IOC_SIZE(info->cmd) < _IOC_SIZE(cmd)))
+   return -ENOIOCTLCMD;
+
+   alt_arg_sizes = info->alt_arg_sizes;
+   if (unlikely(!alt_arg_sizes))
+   return -ENOIOCTLCMD;
+
+   for (; *alt_arg_sizes; alt_arg_sizes++)
+   if (_IOC_SIZE(cmd) == *alt_arg_sizes)
+   return 0;
+
+   return -ENOIOCTLCMD;
 }
 
 static long __media_device_ioctl(
@@ -440,6 +479,9 @@ static long __media_device_ioctl(
goto out_free;
}
 
+   /* Set the rest of the argument struct to zero */
+   memset(karg + _IOC_SIZE(cmd), 0, _IOC_SIZE(info->cmd) - _IOC_SIZE(cmd));
+
if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
mutex_lock(>graph_mutex);
 
-- 
2.7.4

--
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


[PATCH v3 2/5] media: Unify IOCTL handler calling

2016-07-21 Thread Sakari Ailus
Each IOCTL handler can be listed in an array instead of using a large and
cumbersome switch. Do that.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
---
 drivers/media/media-device.c | 81 +---
 1 file changed, 23 insertions(+), 58 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3ac526d..6fd9b77 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -419,12 +419,16 @@ static long media_device_get_topology(struct media_device 
*mdev,
return 0;
 }
 
-#define MEDIA_IOC(__cmd) \
-   [_IOC_NR(MEDIA_IOC_##__cmd)] = { .cmd = MEDIA_IOC_##__cmd }
+#define MEDIA_IOC(__cmd, func) \
+   [_IOC_NR(MEDIA_IOC_##__cmd)] = {\
+   .cmd = MEDIA_IOC_##__cmd,   \
+   .fn = (long (*)(struct media_device *, void __user *))func,\
+   }
 
 /* the table is indexed by _IOC_NR(cmd) */
 struct media_ioctl_info {
unsigned int cmd;
+   long (*fn)(struct media_device *dev, void __user *arg);
 };
 
 static inline long is_valid_ioctl(const struct media_ioctl_info *info,
@@ -440,53 +444,28 @@ static long __media_device_ioctl(
 {
struct media_devnode *devnode = media_devnode_data(filp);
struct media_device *dev = devnode->media_dev;
+   const struct media_ioctl_info *info;
long ret;
 
ret = is_valid_ioctl(info_array, info_array_len, cmd);
if (ret)
return ret;
 
+   info = _array[_IOC_NR(cmd)];
+
mutex_lock(>graph_mutex);
-   switch (cmd) {
-   case MEDIA_IOC_DEVICE_INFO:
-   ret = media_device_get_info(dev,
-   (struct media_device_info __user *)arg);
-   break;
-
-   case MEDIA_IOC_ENUM_ENTITIES:
-   ret = media_device_enum_entities(dev,
-   (struct media_entity_desc __user *)arg);
-   break;
-
-   case MEDIA_IOC_ENUM_LINKS:
-   ret = media_device_enum_links(dev,
-   (struct media_links_enum __user *)arg);
-   break;
-
-   case MEDIA_IOC_SETUP_LINK:
-   ret = media_device_setup_link(dev,
-   (struct media_link_desc __user *)arg);
-   break;
-
-   case MEDIA_IOC_G_TOPOLOGY:
-   ret = media_device_get_topology(dev,
-   (struct media_v2_topology __user *)arg);
-   break;
-
-   default:
-   ret = -ENOIOCTLCMD;
-   }
+   ret = info->fn(dev, arg);
mutex_unlock(>graph_mutex);
 
return ret;
 }
 
 static const struct media_ioctl_info ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO),
-   MEDIA_IOC(ENUM_ENTITIES),
-   MEDIA_IOC(ENUM_LINKS),
-   MEDIA_IOC(SETUP_LINK),
-   MEDIA_IOC(G_TOPOLOGY),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
+   MEDIA_IOC(ENUM_LINKS, media_device_enum_links),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
 };
 
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
@@ -528,33 +507,19 @@ static long media_device_enum_links32(struct media_device 
*mdev,
 #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct 
media_links_enum32)
 
 static const struct media_ioctl_info compat_ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO),
-   MEDIA_IOC(ENUM_ENTITIES),
-   MEDIA_IOC(ENUM_LINKS32),
-   MEDIA_IOC(SETUP_LINK),
-   MEDIA_IOC(G_TOPOLOGY),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
+   MEDIA_IOC(ENUM_LINKS32, media_device_enum_links32),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
 };
 
 static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct media_devnode *devnode = media_devnode_data(filp);
-   struct media_device *dev = devnode->media_dev;
-   long ret;
-
-   switch (cmd) {
-   case MEDIA_IOC_ENUM_LINKS32:
-   mutex_lock(>graph_mutex);
-   ret = media_device_enum_links32(dev,
-   (struct media_links_enum32 __user *)arg);
-   mutex_unlock(>graph_mutex);
-   break;
-
-   default:
-   return media_device_ioctl(filp, cmd, arg);
-   }
-
-   return ret;
+   return __media_device_ioctl(
+   filp, cmd, (void __user *)arg,
+   compat_ioctl_info, ARRAY_SIZE(compat_ioctl_info));
 }
 #endif /* CONFIG_COMPAT */
 
-- 
2.7.4

--
To 

[PATCH v3 1/5] media: Determine early whether an IOCTL is supported

2016-07-21 Thread Sakari Ailus
Preparation for refactoring media IOCTL handling to unify common parts.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
---
 drivers/media/media-device.c | 48 ++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1795abe..3ac526d 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -419,13 +419,33 @@ static long media_device_get_topology(struct media_device 
*mdev,
return 0;
 }
 
-static long media_device_ioctl(struct file *filp, unsigned int cmd,
-  unsigned long arg)
+#define MEDIA_IOC(__cmd) \
+   [_IOC_NR(MEDIA_IOC_##__cmd)] = { .cmd = MEDIA_IOC_##__cmd }
+
+/* the table is indexed by _IOC_NR(cmd) */
+struct media_ioctl_info {
+   unsigned int cmd;
+};
+
+static inline long is_valid_ioctl(const struct media_ioctl_info *info,
+ unsigned int len, unsigned int cmd)
+{
+   return (_IOC_NR(cmd) >= len
+   || info[_IOC_NR(cmd)].cmd != cmd) ? -ENOIOCTLCMD : 0;
+}
+
+static long __media_device_ioctl(
+   struct file *filp, unsigned int cmd, void __user *arg,
+   const struct media_ioctl_info *info_array, unsigned int info_array_len)
 {
struct media_devnode *devnode = media_devnode_data(filp);
struct media_device *dev = devnode->media_dev;
long ret;
 
+   ret = is_valid_ioctl(info_array, info_array_len, cmd);
+   if (ret)
+   return ret;
+
mutex_lock(>graph_mutex);
switch (cmd) {
case MEDIA_IOC_DEVICE_INFO:
@@ -461,6 +481,22 @@ static long media_device_ioctl(struct file *filp, unsigned 
int cmd,
return ret;
 }
 
+static const struct media_ioctl_info ioctl_info[] = {
+   MEDIA_IOC(DEVICE_INFO),
+   MEDIA_IOC(ENUM_ENTITIES),
+   MEDIA_IOC(ENUM_LINKS),
+   MEDIA_IOC(SETUP_LINK),
+   MEDIA_IOC(G_TOPOLOGY),
+};
+
+static long media_device_ioctl(struct file *filp, unsigned int cmd,
+  unsigned long arg)
+{
+   return __media_device_ioctl(
+   filp, cmd, (void __user *)arg,
+   ioctl_info, ARRAY_SIZE(ioctl_info));
+}
+
 #ifdef CONFIG_COMPAT
 
 struct media_links_enum32 {
@@ -491,6 +527,14 @@ static long media_device_enum_links32(struct media_device 
*mdev,
 
 #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct 
media_links_enum32)
 
+static const struct media_ioctl_info compat_ioctl_info[] = {
+   MEDIA_IOC(DEVICE_INFO),
+   MEDIA_IOC(ENUM_ENTITIES),
+   MEDIA_IOC(ENUM_LINKS32),
+   MEDIA_IOC(SETUP_LINK),
+   MEDIA_IOC(G_TOPOLOGY),
+};
+
 static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-- 
2.7.4

--
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


[PATCH v3 0/5] Refactor media IOCTL handling, add variable length arguments

2016-07-21 Thread Sakari Ailus
Hi,

This is the third version of the media IOCTL handling rework set. What's
changed since v2:

patch 3:

- Remove function to calculate maximum argument size, replace by a char 
  array of 256 or kmalloc() if that's too small.

- info->arg_from_user() may fail. Check the return code.

- Instead of providing a no-operation of a copy function, check whether one is  
  defined. If not, don't call one.  

patch 4:

- Arrange the flags field next to cmd, which is an integer. This avoids 
  creating extra holes in the struct memory layout. 

patch 5:

- Use a list of supported argument sizes instead of a minimum value.

---

The patches themselves have been reworked so I don't detail the changes 
in this set. What's noteworthy however is that the set adds support for 
variable length IOCTL arguments.

(The motivation for these patches is having found myself pondering whether  
to have nine or thirteen reserved fields for the request IOCTL. I decided   
to address the problem instead. If this is found workable on the media  
controller we could follow the same model on V4L2.) 

-- 
Kind regards,
Sakari

--
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


[PATCH v3 3/5] media: Refactor copying IOCTL arguments from and to user space

2016-07-21 Thread Sakari Ailus
Refactor copying the IOCTL argument structs from the user space and back,
in order to reduce code copied around and make the implementation more
robust.

As a result, the copying is done while not holding the graph mutex.

Signed-off-by: Sakari Ailus 
---
 drivers/media/media-device.c | 190 ---
 1 file changed, 90 insertions(+), 100 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 6fd9b77..87d17a0 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -59,27 +59,24 @@ static int media_device_close(struct file *filp)
 }
 
 static int media_device_get_info(struct media_device *dev,
-struct media_device_info __user *__info)
+struct media_device_info *info)
 {
-   struct media_device_info info;
-
-   memset(, 0, sizeof(info));
+   memset(info, 0, sizeof(*info));
 
if (dev->driver_name[0])
-   strlcpy(info.driver, dev->driver_name, sizeof(info.driver));
+   strlcpy(info->driver, dev->driver_name, sizeof(info->driver));
else
-   strlcpy(info.driver, dev->dev->driver->name, 
sizeof(info.driver));
+   strlcpy(info->driver, dev->dev->driver->name,
+   sizeof(info->driver));
 
-   strlcpy(info.model, dev->model, sizeof(info.model));
-   strlcpy(info.serial, dev->serial, sizeof(info.serial));
-   strlcpy(info.bus_info, dev->bus_info, sizeof(info.bus_info));
+   strlcpy(info->model, dev->model, sizeof(info->model));
+   strlcpy(info->serial, dev->serial, sizeof(info->serial));
+   strlcpy(info->bus_info, dev->bus_info, sizeof(info->bus_info));
 
-   info.media_version = MEDIA_API_VERSION;
-   info.hw_revision = dev->hw_revision;
-   info.driver_version = dev->driver_version;
+   info->media_version = MEDIA_API_VERSION;
+   info->hw_revision = dev->hw_revision;
+   info->driver_version = dev->driver_version;
 
-   if (copy_to_user(__info, , sizeof(*__info)))
-   return -EFAULT;
return 0;
 }
 
@@ -101,29 +98,25 @@ static struct media_entity *find_entity(struct 
media_device *mdev, u32 id)
 }
 
 static long media_device_enum_entities(struct media_device *mdev,
-  struct media_entity_desc __user *uent)
+  struct media_entity_desc *entd)
 {
struct media_entity *ent;
-   struct media_entity_desc u_ent;
-
-   memset(_ent, 0, sizeof(u_ent));
-   if (copy_from_user(_ent.id, >id, sizeof(u_ent.id)))
-   return -EFAULT;
-
-   ent = find_entity(mdev, u_ent.id);
 
+   ent = find_entity(mdev, entd->id);
if (ent == NULL)
return -EINVAL;
 
-   u_ent.id = media_entity_id(ent);
+   memset(entd, 0, sizeof(*entd));
+
+   entd->id = media_entity_id(ent);
if (ent->name)
-   strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
-   u_ent.type = ent->function;
-   u_ent.revision = 0; /* Unused */
-   u_ent.flags = ent->flags;
-   u_ent.group_id = 0; /* Unused */
-   u_ent.pads = ent->num_pads;
-   u_ent.links = ent->num_links - ent->num_backlinks;
+   strlcpy(entd->name, ent->name, sizeof(entd->name));
+   entd->type = ent->function;
+   entd->revision = 0; /* Unused */
+   entd->flags = ent->flags;
+   entd->group_id = 0; /* Unused */
+   entd->pads = ent->num_pads;
+   entd->links = ent->num_links - ent->num_backlinks;
 
/*
 * Workaround for a bug at media-ctl <= v1.10 that makes it to
@@ -139,14 +132,13 @@ static long media_device_enum_entities(struct 
media_device *mdev,
if (ent->function < MEDIA_ENT_F_OLD_BASE ||
ent->function > MEDIA_ENT_T_DEVNODE_UNKNOWN) {
if (is_media_entity_v4l2_subdev(ent))
-   u_ent.type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
+   entd->type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
else if (ent->function != MEDIA_ENT_F_IO_V4L)
-   u_ent.type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
+   entd->type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
}
 
-   memcpy(_ent.raw, >info, sizeof(ent->info));
-   if (copy_to_user(uent, _ent, sizeof(u_ent)))
-   return -EFAULT;
+   memcpy(>raw, >info, sizeof(ent->info));
+
return 0;
 }
 
@@ -158,8 +150,8 @@ static void media_device_kpad_to_upad(const struct 
media_pad *kpad,
upad->flags = kpad->flags;
 }
 
-static long __media_device_enum_links(struct media_device *mdev,
- struct media_links_enum *links)
+static long media_device_enum_links(struct media_device *mdev,
+   struct media_links_enum *links)
 {
struct 

[PATCH v2.1 4/5] media: Add flags to tell whether to take graph mutex for an IOCTL

2016-07-21 Thread Sakari Ailus
New IOCTLs (especially for the request API) do not necessarily need the
graph mutex acquired. Leave this up to the drivers.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
---
since v2:

- Arrange the flags field next to cmd, which is an integer. This avoids
  creating extra holes in the struct memory layout.

 drivers/media/media-device.c | 47 ++--
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 87d17a0..6dfcc50 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -381,20 +381,25 @@ static long copy_arg_to_user(void __user *uarg, void 
*karg, unsigned int cmd)
return 0;
 }
 
-#define MEDIA_IOC_ARG(__cmd, func, from_user, to_user) \
-   [_IOC_NR(MEDIA_IOC_##__cmd)] = {\
-   .cmd = MEDIA_IOC_##__cmd,   \
+/* Do acquire the graph mutex */
+#define MEDIA_IOC_FL_GRAPH_MUTEX   BIT(0)
+
+#define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user) \
+   [_IOC_NR(MEDIA_IOC_##__cmd)] = {\
+   .cmd = MEDIA_IOC_##__cmd,   \
.fn = (long (*)(struct media_device *, void *))func,\
-   .arg_from_user = from_user, \
-   .arg_to_user = to_user, \
+   .flags = fl,\
+   .arg_from_user = from_user, \
+   .arg_to_user = to_user, \
}
 
-#define MEDIA_IOC(__cmd, func) \
-   MEDIA_IOC_ARG(__cmd, func, copy_arg_from_user, copy_arg_to_user)
+#define MEDIA_IOC(__cmd, func, fl) \
+   MEDIA_IOC_ARG(__cmd, func, fl, copy_arg_from_user, copy_arg_to_user)
 
 /* the table is indexed by _IOC_NR(cmd) */
 struct media_ioctl_info {
unsigned int cmd;
+   unsigned short flags;
long (*fn)(struct media_device *dev, void *arg);
long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
@@ -435,9 +440,13 @@ static long __media_device_ioctl(
goto out_free;
}
 
-   mutex_lock(>graph_mutex);
+   if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
+   mutex_lock(>graph_mutex);
+
ret = info->fn(dev, karg);
-   mutex_unlock(>graph_mutex);
+
+   if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
+   mutex_unlock(>graph_mutex);
 
if (!ret && info->arg_to_user)
ret = info->arg_to_user(arg, karg, cmd);
@@ -450,11 +459,11 @@ out_free:
 }
 
 static const struct media_ioctl_info ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
-   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
-   MEDIA_IOC(ENUM_LINKS, media_device_enum_links),
-   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
-   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_LINKS, media_device_enum_links, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, 
MEDIA_IOC_FL_GRAPH_MUTEX),
 };
 
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
@@ -497,11 +506,11 @@ static long from_user_enum_links32(void *karg, void 
__user *uarg,
 #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct 
media_links_enum32)
 
 static const struct media_ioctl_info compat_ioctl_info[] = {
-   MEDIA_IOC(DEVICE_INFO, media_device_get_info),
-   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities),
-   MEDIA_IOC_ARG(ENUM_LINKS32, media_device_enum_links, 
from_user_enum_links32, NULL),
-   MEDIA_IOC(SETUP_LINK, media_device_setup_link),
-   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology),
+   MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC_ARG(ENUM_LINKS32, media_device_enum_links, 
MEDIA_IOC_FL_GRAPH_MUTEX, from_user_enum_links32, NULL),
+   MEDIA_IOC(SETUP_LINK, media_device_setup_link, 
MEDIA_IOC_FL_GRAPH_MUTEX),
+   MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, 
MEDIA_IOC_FL_GRAPH_MUTEX),
 };
 
 static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
-- 
2.7.4

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

[PATCH v2.3 3/5] media: Refactor copying IOCTL arguments from and to user space

2016-07-21 Thread Sakari Ailus
Refactor copying the IOCTL argument structs from the user space and back,
in order to reduce code copied around and make the implementation more
robust.

As a result, the copying is done while not holding the graph mutex.

Signed-off-by: Sakari Ailus 
---
since v2.2:

- Instead of providing a no-operation of a copy function, check whether one is
  defined. If not, don't call one.

 drivers/media/media-device.c | 190 ---
 1 file changed, 90 insertions(+), 100 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 6fd9b77..87d17a0 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -59,27 +59,24 @@ static int media_device_close(struct file *filp)
 }
 
 static int media_device_get_info(struct media_device *dev,
-struct media_device_info __user *__info)
+struct media_device_info *info)
 {
-   struct media_device_info info;
-
-   memset(, 0, sizeof(info));
+   memset(info, 0, sizeof(*info));
 
if (dev->driver_name[0])
-   strlcpy(info.driver, dev->driver_name, sizeof(info.driver));
+   strlcpy(info->driver, dev->driver_name, sizeof(info->driver));
else
-   strlcpy(info.driver, dev->dev->driver->name, 
sizeof(info.driver));
+   strlcpy(info->driver, dev->dev->driver->name,
+   sizeof(info->driver));
 
-   strlcpy(info.model, dev->model, sizeof(info.model));
-   strlcpy(info.serial, dev->serial, sizeof(info.serial));
-   strlcpy(info.bus_info, dev->bus_info, sizeof(info.bus_info));
+   strlcpy(info->model, dev->model, sizeof(info->model));
+   strlcpy(info->serial, dev->serial, sizeof(info->serial));
+   strlcpy(info->bus_info, dev->bus_info, sizeof(info->bus_info));
 
-   info.media_version = MEDIA_API_VERSION;
-   info.hw_revision = dev->hw_revision;
-   info.driver_version = dev->driver_version;
+   info->media_version = MEDIA_API_VERSION;
+   info->hw_revision = dev->hw_revision;
+   info->driver_version = dev->driver_version;
 
-   if (copy_to_user(__info, , sizeof(*__info)))
-   return -EFAULT;
return 0;
 }
 
@@ -101,29 +98,25 @@ static struct media_entity *find_entity(struct 
media_device *mdev, u32 id)
 }
 
 static long media_device_enum_entities(struct media_device *mdev,
-  struct media_entity_desc __user *uent)
+  struct media_entity_desc *entd)
 {
struct media_entity *ent;
-   struct media_entity_desc u_ent;
-
-   memset(_ent, 0, sizeof(u_ent));
-   if (copy_from_user(_ent.id, >id, sizeof(u_ent.id)))
-   return -EFAULT;
-
-   ent = find_entity(mdev, u_ent.id);
 
+   ent = find_entity(mdev, entd->id);
if (ent == NULL)
return -EINVAL;
 
-   u_ent.id = media_entity_id(ent);
+   memset(entd, 0, sizeof(*entd));
+
+   entd->id = media_entity_id(ent);
if (ent->name)
-   strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
-   u_ent.type = ent->function;
-   u_ent.revision = 0; /* Unused */
-   u_ent.flags = ent->flags;
-   u_ent.group_id = 0; /* Unused */
-   u_ent.pads = ent->num_pads;
-   u_ent.links = ent->num_links - ent->num_backlinks;
+   strlcpy(entd->name, ent->name, sizeof(entd->name));
+   entd->type = ent->function;
+   entd->revision = 0; /* Unused */
+   entd->flags = ent->flags;
+   entd->group_id = 0; /* Unused */
+   entd->pads = ent->num_pads;
+   entd->links = ent->num_links - ent->num_backlinks;
 
/*
 * Workaround for a bug at media-ctl <= v1.10 that makes it to
@@ -139,14 +132,13 @@ static long media_device_enum_entities(struct 
media_device *mdev,
if (ent->function < MEDIA_ENT_F_OLD_BASE ||
ent->function > MEDIA_ENT_T_DEVNODE_UNKNOWN) {
if (is_media_entity_v4l2_subdev(ent))
-   u_ent.type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
+   entd->type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
else if (ent->function != MEDIA_ENT_F_IO_V4L)
-   u_ent.type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
+   entd->type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
}
 
-   memcpy(_ent.raw, >info, sizeof(ent->info));
-   if (copy_to_user(uent, _ent, sizeof(u_ent)))
-   return -EFAULT;
+   memcpy(>raw, >info, sizeof(ent->info));
+
return 0;
 }
 
@@ -158,8 +150,8 @@ static void media_device_kpad_to_upad(const struct 
media_pad *kpad,
upad->flags = kpad->flags;
 }
 
-static long __media_device_enum_links(struct media_device *mdev,
- struct media_links_enum *links)
+static long 

Re: [PATCH] doc-rst: get rid of warnings at kernel-documentation.rst

2016-07-21 Thread Mauro Carvalho Chehab
Em Wed, 20 Jul 2016 17:33:31 +0200
Markus Heiser  escreveu:

> Am 20.07.2016 um 17:06 schrieb Mauro Carvalho Chehab 
> :
> 
> > Em Wed, 20 Jul 2016 16:49:59 +0200
> > Markus Heiser  escreveu:
> >   
> >> Am 20.07.2016 um 16:31 schrieb Jonathan Corbet :
> >>   
> >>> On Wed, 20 Jul 2016 16:23:28 +0200
> >>> Markus Heiser  wrote:
> >>>   
>  Am 20.07.2016 um 16:11 schrieb Mauro Carvalho Chehab 
>  :
>    
> > Sphinx 1.4.5 complains about some literal blocks at
> > kernel-documentation.rst:
> > 
> > Documentation/kernel-documentation.rst:373: WARNING: Could not 
> > lex literal_block as "C". Highlighting skipped.
> > Documentation/kernel-documentation.rst:378: WARNING: Could not 
> > lex literal_block as "C". Highlighting skipped.
> > Documentation/kernel-documentation.rst:576: WARNING: Could not 
> > lex literal_block as "C". Highlighting skipped.
> > 
> > Fix it by telling Sphinx to consider them as "none" type.  
>  
>  Hi Mauro,
>  
>  IMHO we should better fix this by unsetting the lexers default language 
>  in the conf.py  [1] ... currently:
>  
>  highlight_language = 'C'  # set this to 'none'
>   
>  As far as I know the default highlight_language is also the default
>  for literal blocks starting with "::"
> >>> 
> >>> The thing with that is that a lot of literal blocks *do* have C code, even
> >>> in kernel-documentation.rst.  Setting that in conf.py would turn off all C
> >>> highlighting.  I think that might actually be a desirable outcome, but it
> >>> would be good to make that decision explicitly.
> >>> 
> >>> As it happens, I'd already fixed these particular warnings in docs-next:
> >>> 
> >>>   http://permalink.gmane.org/gmane.linux.documentation/39806
> >>> 
> >>> I took a different approach; using code-block might actually be better.   
> >>>  
> >> 
> >> In some kernel-doc comments we have constructs like this:
> >> 
> >> * host point of view, the graphic address space is partitioned by multiple
> >> * vGPUs in different VMs.::
> >> *
> >> *vGPU1 view Host view
> >> * 0 --> +---+ +---+
> >> *   ^   |///| |   vGPU3   |
> >> *   |   |///| +---+
> >> *   |   |///| |   vGPU2   |
> >> *   |   +---+ +---+
> >> *mappable GM| available | ==> |   vGPU1   |
> >> *   |   +---+ +---+
> >> 
> >> I mean, in kernel-doc comments it would be nice to have no lexer
> >> active when starting a literal block with a double colon "::".
> >> Introducing a none highlighted literal block with a directive
> >> like ".. highlight::" or ".. code-block" is a bit verbose
> >> for a C comment.  And on the opposite, if one place a C construct
> >> in a literal block with a double colon "::", only the highlighting
> >> is missed, but we get now warning.
> >> 
> >> At least a code-block should be a code block, not a diagram 
> >> or anything other ...
> >> 
> >> I don't know whats the best ... but these are my 2cent :)  
> > 
> > I actually think that the best would be if we could have a way to
> > "draw" graphs inside the documentation.  
> 
> please .. not yet ;-)  ... we have so many problem sites to 
> close first ... graphiz & Co. bring additional dependencies
> to fulfill in context with sphinx 1.2 ...

Yeah, let's close the other issues first ;)

> 
> > We have a few cases of
> > diagrams like the above at the media documentation too.
> > 
> > As Sphinx seems to like ASCIIart, IMHO, the more Sphinx-style
> > way would be to have a:
> > 
> > .. code-block:: asciiart  
> 
> > 
> > markup to handle it.  
> 
> why a special markup for a literal block?

What I meant to say is to use something that would convert from
asciiart into a picture, just like Sphinx does with tables.

Anyway, this is not a top priority ;)

Thanks,
Mauro
--
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] doc-rst: get rid of warnings at kernel-documentation.rst

2016-07-21 Thread Mauro Carvalho Chehab
Em Wed, 20 Jul 2016 17:06:41 -0600
Jonathan Corbet  escreveu:

> On Wed, 20 Jul 2016 11:41:11 -0300
> Mauro Carvalho Chehab  wrote:
> 
> > > The thing with that is that a lot of literal blocks *do* have C code, even
> > > in kernel-documentation.rst.  Setting that in conf.py would turn off all C
> > > highlighting.  I think that might actually be a desirable outcome, but it
> > > would be good to make that decision explicitly.
> > 
> > Agreed. Assuming "C" as default seems a good idea to me.  
> 
> "Agreed," but there was an implied question there that, I think, deserves
> consideration.  Do we want to have a default highlighting language for
> literal blocks at all?  Those blocks will contain ascii art diagrams,
> device-tree fragments, error message examples, and who knows what else.
> Even if the majority of them are C code, having Sphinx treat all of them
> as C is going to lead to a steady stream of warnings and a lot of extra
> markup in the text.

On the documents I edited after the media conversion, I'm explicitly
telling the language (either "c" or "none") on every block. Yet,
any change like that would require to revisit all pages to be sure.
So, changing the default should not cause any change. Yet, I think
that, if we'll be changing the default, the best is to do it as
early as possible.

> Plus I'm not convinced that more color eye candy in code fragments is
> actually helpful.

I use colors on the text editors I use to edit the code and on my
shell prompt. So, I'm suspect, but, at least to me, I prefer it
colored.

Yet, I would very much prefer if, instead of changing the colors for
some random C code, it would be adding hyperlinks to all API calls.
This is what Doxygen does. So, we can include real code examples,
and the user can use them to cross reference with the corresponding
API symbols, like here:
https://linuxtv.org/docs/libdvbv5/dvbv5-scan_8c-example.html

IMHO, we should mark all C codes as such, and then pursue the goal of
having an extension that would do the same.

> So I think I might actually argue in favor of Markus's suggestion and set
> the language to "none" by default.  But others may feel strongly about
> having their bikeshed in full syntax-highlighted color.  Opinions on the
> matter?
> 
> Thanks,
> 
> jon



Thanks,
Mauro
--
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 7/7] [media] rc: add support for IR LEDs driven through SPI

2016-07-21 Thread Sean Young
Hi Andi,

On Thu, Jul 21, 2016 at 10:09:26AM +0900, Andi Shyti wrote:
> > > + ret = regulator_enable(idata->regulator);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + mutex_lock(>mutex);
> > > + idata->xfer.len = n;
> > > + idata->xfer.tx_buf = buffer;
> > > + mutex_unlock(>mutex);
> > 
> > I'm not convinced the locking works here. You want to guard against 
> > someone modifying xfer while you are sending (so in spi_sync_transfer), 
> > which this locking is not doing. You could declare a 
> > local "struct spi_transfer xfer" and avoid the mutex altogether.
> 
> I cannot declare xfer locally because the spi framework needs
> a statically allocated xfer, so that either I dynamically
> allocate it in the function or I declare it global in idata.

It can be stack allocated for sync transfers. You might want to lock
the spi bus.

> With the mutex I would like to prevent different tasks to change
> the value at the same time, it's an easy case, it shouldn't make
> much difference.

That's cargo-cult locking. It does not achieve anything.


Sean
--
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] vb2: check for NULL device pointer

2016-07-21 Thread Sakari Ailus
Hi Hans,

On Thu, Jul 21, 2016 at 11:19:11AM +0200, Hans Verkuil wrote:
> Check whether the struct device pointer is NULL and return -EINVAL in that
> case.
> 
> This also required a small change to vb2-core where it didn't call PTR_ERR to
> get the real error code.
> 
> I have seen several new driver submissions that forgot to set the vb2_queue
> dev field, so add these checks to prevent this from happening again.
> 
> The dev field is passed on to the dma-contig/sg drivers in the alloc, 
> get_userptr
> and attach_dmabuf callbacks, so this check has to be done in those three 
> places.
> 
> Signed-off-by: Hans Verkuil 

Considering this is here just to notify driver developers they're doing
something wrong, I'd just have a WARN_ON() so they can see what's wrong and
fix their code. The debug print contains no additional information.
Readability should be the preference instead --- and extra debug prints
don't really help with that.

It'd be nice if the functions always returned either NULL or an error code.
That's not really an issue with this patch, but it extends the use of both
of the options in favour of either one.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
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 v2 2/3] [media] hva: multi-format video encoder V4L2 driver

2016-07-21 Thread Hans Verkuil


On 07/21/2016 09:30 AM, Jean Christophe TROTIN wrote:
> 
> On 07/18/2016 01:45 PM, Hans Verkuil wrote:
>> Hi Jean-Christophe,
>>
>> See my review comments below. Nothing really major, but I do need to know 
>> more
>> about the g/s_parm and the restriction on the number of open()s has to be 
>> lifted.
>> That's not allowed.
>>
> 
> Hi Hans,
> 
> Thank you for your comments.
> I've explained below why I would like to keep 'hva' as driver's name and why 
> the
> frame rate is needed (g/s_parm).
> I've followed your advice for managing the hardware restriction with regards 
> to
> the number of codec instances (see also below).
> Finally, I've taken into account all the other comments.
> All these modifications will be reflected in the version 3.
> 
> Best regards,
> Jean-Christophe.
> 
>> On 07/11/2016 05:14 PM, Jean-Christophe Trotin wrote:
>>> This patch adds V4L2 HVA (Hardware Video Accelerator) video encoder
>>> driver for STMicroelectronics SoC. It uses the V4L2 mem2mem framework.
>>>
>>> This patch only contains the core parts of the driver:
>>> - the V4L2 interface with the userland (hva-v4l2.c)
>>> - the hardware services (hva-hw.c)
>>> - the memory management utilities (hva-mem.c)
>>>
>>> This patch doesn't include the support of specific codec (e.g. H.264)
>>> video encoding: this support is part of subsequent patches.
>>>
>>> Signed-off-by: Yannick Fertre 
>>> Signed-off-by: Jean-Christophe Trotin 
>>> ---
>>>   drivers/media/platform/Kconfig|   14 +
>>>   drivers/media/platform/Makefile   |1 +
>>>   drivers/media/platform/sti/hva/Makefile   |2 +
>>>   drivers/media/platform/sti/hva/hva-hw.c   |  534 
>>>   drivers/media/platform/sti/hva/hva-hw.h   |   42 +
>>>   drivers/media/platform/sti/hva/hva-mem.c  |   60 ++
>>>   drivers/media/platform/sti/hva/hva-mem.h  |   36 +
>>>   drivers/media/platform/sti/hva/hva-v4l2.c | 1299 
>>> +
>>>   drivers/media/platform/sti/hva/hva.h  |  284 +++
>>>   9 files changed, 2272 insertions(+)
>>>   create mode 100644 drivers/media/platform/sti/hva/Makefile
>>>   create mode 100644 drivers/media/platform/sti/hva/hva-hw.c
>>>   create mode 100644 drivers/media/platform/sti/hva/hva-hw.h
>>>   create mode 100644 drivers/media/platform/sti/hva/hva-mem.c
>>>   create mode 100644 drivers/media/platform/sti/hva/hva-mem.h
>>>   create mode 100644 drivers/media/platform/sti/hva/hva-v4l2.c
>>>   create mode 100644 drivers/media/platform/sti/hva/hva.h
>>>
>>> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
>>> index 382f393..182d63f 100644
>>> --- a/drivers/media/platform/Kconfig
>>> +++ b/drivers/media/platform/Kconfig
>>> @@ -227,6 +227,20 @@ config VIDEO_STI_BDISP
>>>help
>>>  This v4l2 mem2mem driver is a 2D blitter for STMicroelectronics 
>>> SoC.
>>>
>>> +config VIDEO_STI_HVA
>>> + tristate "STMicroelectronics STiH41x HVA multi-format video encoder 
>>> V4L2 driver"
>>> + depends on VIDEO_DEV && VIDEO_V4L2
>>> + depends on ARCH_STI || COMPILE_TEST
>>> + select VIDEOBUF2_DMA_CONTIG
>>> + select V4L2_MEM2MEM_DEV
>>> + help
>>> +   This V4L2 driver enables HVA multi-format video encoder of
>>
>> Please mention here what HVA stands for.
>>
> 
> Done in version 3.
> HVA stands for "Hardware Video Accelerator".
> 
>>> +   STMicroelectronics SoC STiH41x series, allowing hardware encoding 
>>> of raw
>>> +   uncompressed formats in various compressed video bitstreams format.
>>> +
>>> +   To compile this driver as a module, choose M here:
>>> +   the module will be called hva.
>>
>> How about sti-hva as the module name? 'hva' is a bit too generic.
>>
> 
> 'hva' is a generic IP which could be used on different STMicroelectronics 
> SoCs.
> That's the reason why I would like to keep this name. It's not specific to  
> the
> STiH41x series: thus, I've reworked the Kconfig's comment.

How about st-hva? I really like it to be a bit more specific.

>>> +static int hva_s_parm(struct file *file, void *fh, struct v4l2_streamparm 
>>> *sp)
>>> +{
>>> + struct hva_ctx *ctx = fh_to_ctx(file->private_data);
>>> + struct device *dev = ctx_to_dev(ctx);
>>> + struct v4l2_fract *time_per_frame = >ctrls.time_per_frame;
>>> +
>>> + time_per_frame->numerator = sp->parm.capture.timeperframe.numerator;
>>> + time_per_frame->denominator =
>>> + sp->parm.capture.timeperframe.denominator;
>>> +
>>> + dev_dbg(dev, "%s set parameters %d/%d\n", ctx->name,
>>> + time_per_frame->numerator, time_per_frame->denominator);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int hva_g_parm(struct file *file, void *fh, struct v4l2_streamparm 
>>> *sp)
>>> +{
>>> + struct hva_ctx *ctx = fh_to_ctx(file->private_data);
>>> + struct device *dev = ctx_to_dev(ctx);
>>> + struct v4l2_fract *time_per_frame = >ctrls.time_per_frame;
>>> +
>>> +   

[PATCH] vb2: check for NULL device pointer

2016-07-21 Thread Hans Verkuil
Check whether the struct device pointer is NULL and return -EINVAL in that
case.

This also required a small change to vb2-core where it didn't call PTR_ERR to
get the real error code.

I have seen several new driver submissions that forgot to set the vb2_queue
dev field, so add these checks to prevent this from happening again.

The dev field is passed on to the dma-contig/sg drivers in the alloc, 
get_userptr
and attach_dmabuf callbacks, so this check has to be done in those three places.

Signed-off-by: Hans Verkuil 
---
diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index ca8ffeb..6470819 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -198,6 +198,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
void *mem_priv;
int plane;
+   int ret = -ENOMEM;

/*
 * Allocate memory for all planes in this buffer
@@ -209,8 +210,11 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
mem_priv = call_ptr_memop(vb, alloc,
q->alloc_devs[plane] ? : q->dev,
q->dma_attrs, size, dma_dir, q->gfp_flags);
-   if (IS_ERR_OR_NULL(mem_priv))
+   if (IS_ERR_OR_NULL(mem_priv)) {
+   if (mem_priv)
+   ret = PTR_ERR(mem_priv);
goto free;
+   }

/* Associate allocator private data with this plane */
vb->planes[plane].mem_priv = mem_priv;
@@ -224,7 +228,7 @@ free:
vb->planes[plane - 1].mem_priv = NULL;
}

-   return -ENOMEM;
+   return ret;
 }

 /**
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 863f658..22b34cf 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -141,6 +141,11 @@ static void *vb2_dc_alloc(struct device *dev, const struct 
dma_attrs *attrs,
 {
struct vb2_dc_buf *buf;

+   if (WARN_ON(!dev)) {
+   pr_debug("dev is NULL\n");
+   return ERR_PTR(-EINVAL);
+   }
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
@@ -499,6 +504,11 @@ static void *vb2_dc_get_userptr(struct device *dev, 
unsigned long vaddr,
return ERR_PTR(-EINVAL);
}

+   if (WARN_ON(!dev)) {
+   pr_debug("dev is NULL\n");
+   return ERR_PTR(-EINVAL);
+   }
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
@@ -679,6 +689,11 @@ static void *vb2_dc_attach_dmabuf(struct device *dev, 
struct dma_buf *dbuf,
if (dbuf->size < size)
return ERR_PTR(-EFAULT);

+   if (WARN_ON(!dev)) {
+   pr_debug("dev is NULL\n");
+   return ERR_PTR(-EINVAL);
+   }
+
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index a39db8a..3766942 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -107,11 +107,14 @@ static void *vb2_dma_sg_alloc(struct device *dev, const 
struct dma_attrs *dma_at

dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, );

-   if (WARN_ON(dev == NULL))
-   return NULL;
+   if (WARN_ON(!dev)) {
+   pr_debug("dev is NULL\n");
+   return ERR_PTR(-EINVAL);
+   }
+
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
-   return NULL;
+   return ERR_PTR(-ENOMEM);

buf->vaddr = NULL;
buf->dma_dir = dma_dir;
@@ -169,7 +172,7 @@ fail_pages_alloc:
kfree(buf->pages);
 fail_pages_array_alloc:
kfree(buf);
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 }

 static void vb2_dma_sg_put(void *buf_priv)
@@ -231,10 +234,15 @@ static void *vb2_dma_sg_get_userptr(struct device *dev, 
unsigned long vaddr,
DEFINE_DMA_ATTRS(attrs);
struct frame_vector *vec;

+   if (WARN_ON(!dev)) {
+   pr_debug("dev is NULL\n");
+   return ERR_PTR(-EINVAL);
+   }
+
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, );
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
-   return NULL;
+   return ERR_PTR(-ENOMEM);

buf->vaddr = NULL;
buf->dev = dev;
@@ -274,7 +282,7 @@ userptr_fail_sgtable:
vb2_destroy_framevec(vec);
 userptr_fail_pfnvec:
kfree(buf);
-   return NULL;
+   return ERR_PTR(-ENOMEM);
 }

 /*
@@ -617,6 +625,11 @@ static void *vb2_dma_sg_attach_dmabuf(struct device 

Re: [PATCH v6 1/2] [media] atmel-isc: add the Image Sensor Controller code

2016-07-21 Thread Hans Verkuil


On 07/21/2016 10:14 AM, Songjun Wu wrote:
> Add driver for the Image Sensor Controller. It manages
> incoming data from a parallel based CMOS/CCD sensor.
> It has an internal image processor, also integrates a
> triple channel direct memory access controller master
> interface.
> 
> Signed-off-by: Songjun Wu 
> ---
> 
> Changes in v6: None
> Changes in v5:
> - Modify the macro definition and the related code.
> 
> Changes in v4:
> - Modify the isc clock code since the dt is changed.
> 
> Changes in v3:
> - Add pm runtime feature.
> - Modify the isc clock code since the dt is changed.
> 
> Changes in v2:
> - Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
>   in Kconfig file.
> - Correct typos and coding style according to Laurent's remarks
> - Delete the loop while in 'isc_clk_enable' function.
> - Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
>   with 'pfe_cfg0' in struct isc_subdev_entity.
> - Add the code to support VIDIOC_CREATE_BUFS in
>   'isc_queue_setup' function.
> - Invoke isc_config to configure register in
>   'isc_start_streaming' function.
> - Add the struct completion 'comp' to synchronize with
>   the frame end interrupt in 'isc_stop_streaming' function.
> - Check the return value of the clk_prepare_enable
>   in 'isc_open' function.
> - Set the default format in 'isc_open' function.
> - Add an exit condition in the loop while in 'isc_config'.
> - Delete the hardware setup operation in 'isc_set_format'.
> - Refuse format modification during streaming
>   in 'isc_s_fmt_vid_cap' function.
> - Invoke v4l2_subdev_alloc_pad_config to allocate and
>   initialize the pad config in 'isc_async_complete' function.
> - Remove the '.owner  = THIS_MODULE,' in atmel_isc_driver.
> - Replace the module_platform_driver_probe() with
>   module_platform_driver().
> 
>  drivers/media/platform/Kconfig|1 +
>  drivers/media/platform/Makefile   |2 +
>  drivers/media/platform/atmel/Kconfig  |9 +
>  drivers/media/platform/atmel/Makefile |1 +
>  drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
>  drivers/media/platform/atmel/atmel-isc.c  | 1554 
> +
>  6 files changed, 1732 insertions(+)
>  create mode 100644 drivers/media/platform/atmel/Kconfig
>  create mode 100644 drivers/media/platform/atmel/Makefile
>  create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
>  create mode 100644 drivers/media/platform/atmel/atmel-isc.c
> 
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index f25344b..b23db17 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -111,6 +111,7 @@ source "drivers/media/platform/s5p-tv/Kconfig"
>  source "drivers/media/platform/am437x/Kconfig"
>  source "drivers/media/platform/xilinx/Kconfig"
>  source "drivers/media/platform/rcar-vin/Kconfig"
> +source "drivers/media/platform/atmel/Kconfig"
>  
>  config VIDEO_TI_CAL
>   tristate "TI CAL (Camera Adaptation Layer) driver"
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 21771c1..37b6c75 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -58,6 +58,8 @@ obj-$(CONFIG_VIDEO_XILINX)  += xilinx/
>  
>  obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar-vin/
>  
> +obj-$(CONFIG_VIDEO_ATMEL_ISC)+= atmel/
> +
>  ccflags-y += -I$(srctree)/drivers/media/i2c
>  
>  obj-$(CONFIG_VIDEO_MEDIATEK_VPU) += mtk-vpu/
> diff --git a/drivers/media/platform/atmel/Kconfig 
> b/drivers/media/platform/atmel/Kconfig
> new file mode 100644
> index 000..867dca2
> --- /dev/null
> +++ b/drivers/media/platform/atmel/Kconfig
> @@ -0,0 +1,9 @@
> +config VIDEO_ATMEL_ISC
> + tristate "ATMEL Image Sensor Controller (ISC) support"
> + depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA
> + depends on ARCH_AT91 || COMPILE_TEST
> + select VIDEOBUF2_DMA_CONTIG
> + select REGMAP_MMIO
> + help
> +This module makes the ATMEL Image Sensor Controller available
> +as a v4l2 device.
> \ No newline at end of file
> diff --git a/drivers/media/platform/atmel/Makefile 
> b/drivers/media/platform/atmel/Makefile
> new file mode 100644
> index 000..9d7c999
> --- /dev/null
> +++ b/drivers/media/platform/atmel/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_ATMEL_ISC) += atmel-isc.o
> diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h 
> b/drivers/media/platform/atmel/atmel-isc-regs.h
> new file mode 100644
> index 000..00c4497
> --- /dev/null
> +++ b/drivers/media/platform/atmel/atmel-isc-regs.h
> @@ -0,0 +1,165 @@
> +#ifndef __ATMEL_ISC_REGS_H
> +#define __ATMEL_ISC_REGS_H
> +
> +#include 
> +
> +/* ISC Control Enable Register 0 */
> +#define ISC_CTRLEN  0x
> +
> +/* ISC Control Disable Register 0 */
> +#define ISC_CTRLDIS 0x0004
> +
> +/* ISC Control Status Register 0 */
> +#define 

Re: [PATCH v3 0/9] Add MT8173 Video Decoder Driver

2016-07-21 Thread tiffany lin
Hi Hans,

On Fri, 2016-07-08 at 13:44 +0200, Hans Verkuil wrote:
> On 07/07/2016 12:16 PM, tiffany lin wrote:
> > Hi Hans,
> > 
> > 
> > On Wed, 2016-07-06 at 15:19 +0200, Hans Verkuil wrote:
> >> Hi Tiffany,
> >>
> >> I plan to review this patch series on Friday, but one obvious question is
> >> what the reason for these failures is:
> >>
> >>> 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:
> >>> test VIDIOC_QUERYCTRL/MENU: OK
> >>> fail: 
> >>> ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):
> >>>  g_ctrl returned an error (11)
> >>> test VIDIOC_G/S_CTRL: FAIL
> >>> fail: 
> >>> ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):
> >>>  g_ext_ctrls returned an error (11)
> >>> test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
> > These fails are because VIDIOC_G_CTRL and VIDIOC_G_EXT_CTRLS return
> > V4L2_CID_MIN_BUFFERS_FOR_CAPTURE only when dirver in MTK_STATE_HEADER
> > state, or it will return EAGAIN.
> > This could help user space get correct value, not default value that may
> > changed base on media content.
> 
> OK, I really don't like this. I also looked what the s5p-mfc-dec driver does 
> (the only other
> driver currently implementing this), and that returns -EINVAL.
> 
> My proposal would be to change this. If this information isn't known yet, why 
> not
> just return 0 as the value? The doc would have to be updated and (preferably) 
> also
> the s5p-mfc-dec driver. I've added Samsung devs to the Cc list, let me know 
> what you
> think.
> 
We are ok with just return 0 as the value when header not parsed yet
We will update decoder with this solution.


> > 
> >>> fail: 
> >>> ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721):
> >>>  subscribe event for control 'User Controls' failed
> >>> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
> > Driver do not support subscribe event for control 'User Controls' for
> > now.
> > Do we need to support this?
> 
> I don't see why this would fail. It's OK to subscribe to such controls, 
> although
> you'll never get an event.
> 
After upgrade to latest v4l-utils,this test pass.

> >>> test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
> >>> Standard Controls: 2 Private Controls: 0
> >>>
> >>> Format ioctls:
> >>> test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
> >>> test VIDIOC_G/S_PARM: OK (Not Supported)
> >>> test VIDIOC_G_FBUF: OK (Not Supported)
> >>> fail: 
> >>> ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405):
> >>>  expected EINVAL, but got 11 when getting format for buftype 9
> >>> test VIDIOC_G_FMT: FAIL
> > This is because vidioc_vdec_g_fmt only succeed when context is in
> > MTK_STATE_HEADER state, or user space cannot get correct format data
> > using this function.
> 
> Comparing this to s5p-mfc-dec I see that -EINVAL is returned in that case.
> 
> I am not opposed to using EAGAIN in s5p-mfc-dec as well. Marek, Kamil, what is
> your opinion?
> 
> > 
> >>> test VIDIOC_TRY_FMT: OK (Not Supported)
> >>> test VIDIOC_S_FMT: OK (Not Supported)
> >>> test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
> >>>
> >>> Codec ioctls:
> >>> 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:
> >>> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
> >>> fail: 
> >>> ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):
> >>>  q.has_expbuf(node)
> > Our OUTPUT and CAPTURE queue support both VB2_DMABUF and VB2_MMAP, user
> > space can select which to use in runtime.
> > So our driver default support v4l2_m2m_ioctl_expbuf functionality.
> > In v4l2-compliance test, it will check v4l2_m2m_ioctl_expbuf only valid
> > when node->valid_memorytype is V4L2_MEMORY_MMAP.
> > So when go through node->valid_memorytype is V4L2_MEMORY_DMABUF, it
> > fail.
> 
> valid_memorytype should have both MMAP and DMABUF flags.
> 
> But v4l-utils-1.6.0 is way too old to be certain it isn't some 
> v4l2-compliance bug
> that has since been fixed.
After upgrade to latest v4l-utils, I still see this issue.

test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: v4l2-test-buffers.cpp(571): q.has_expbuf(node)

best regards,
Tiffany

> 
> Regards,
> 
>   Hans
> 
> > 
> > 
> > best regards,
> > Tiffany
> > 
> > 
> > 
> >>>   

Re: [PATCH v6 0/2] [media] atmel-isc: add driver for Atmel ISC

2016-07-21 Thread Hans Verkuil


On 07/21/2016 10:14 AM, Songjun Wu wrote:
> The Image Sensor Controller driver includes two parts.
> 1) Driver code to implement the ISC function.
> 2) Device tree binding documentation, it describes how
>to add the ISC in device tree.
> 
> Test result with v4l-utils 1.10.1

Please compile from the v4l-utils repository. The version you used here is 
out-of-date.
I continually add new tests, so always compile the latest version from the repo.

Regards,

Hans

> Driver Info:
> Driver name   : atmel_isc
> Card type : Atmel Image Sensor Controller
> Bus info  : platform:atmel_isc f0008000.isc
> Driver version: 4.7.0
> Capabilities  : 0x8421
> Video Capture
> Streaming
> Extended Pix Format
> Device Capabilities
> Device Caps   : 0x0421
> Video Capture
> Streaming
> Extended Pix Format
> 
> Compliance test for device /dev/video0 (not using libv4l2):
> 
> Required ioctls:
> test VIDIOC_QUERYCAP: OK
> 
> Allow for multiple opens:
> test second video open: OK
> test VIDIOC_QUERYCAP: OK
> test VIDIOC_G/S_PRIORITY: 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)
> 
> Test input 0:
> 
> Control ioctls:
> 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:
> 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:
> 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:
> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
> test VIDIOC_EXPBUF: OK
> 
> Test input 0:
> 
> Stream using all formats:
> test MMAP for Format BA81, Frame Size 640x480:
> Stride 640, Field None: OK
> test MMAP for Format YUYV, Frame Size 640x480:
> Stride 1280, Field None: OK
> 
> Total: 44, Succeeded: 44, Failed: 0, Warnings: 0
> 
> Changes in v6:
> - Add "iscck" and "gck" to clock-names.
> 
> Changes in v5:
> - Modify the macro definition and the related code.
> - Add clock-output-names.
> 
> Changes in v4:
> - Modify the isc clock code since the dt is changed.
> - Remove the isc clock nodes.
> 
> Changes in v3:
> - Add pm runtime feature.
> - Modify the isc clock code since the dt is changed.
> - Remove the 'atmel,sensor-preferred'.
> - Modify the isc clock node according to the Rob's remarks.
> 
> Changes in v2:
> - Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
>   in Kconfig file.
> - Correct typos and coding style according to Laurent's remarks
> - Delete the loop while in 'isc_clk_enable' function.
> - Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
>   with 'pfe_cfg0' in struct isc_subdev_entity.
> - Add the code to support VIDIOC_CREATE_BUFS in
>   'isc_queue_setup' 

Re: [PATCH 2/2 v2] Add GS1662 driver, a video serializer

2016-07-21 Thread Hans Verkuil


On 07/15/2016 03:14 PM, Charles-Antoine Couret wrote:
> From 111c02ef44dc1588891b40337fb0669fa586ec50 Mon Sep 17 00:00:00 2001
> From: Charles-Antoine Couret 
> Date: Fri, 15 Jul 2016 15:06:43 +0200
> Subject: [PATCH 2/2] Add GS1662 driver, a video serializer
> 
> You can read datasheet here:
> http://www.c-dis.net/media/871/GS1662_Datasheet.pdf
> 
> It's a component which supports HD and SD CEA or SDI formats
> to SDI output. It's configured through SPI bus.
> 
> GS1662 driver is implemented as v4l2 subdev.
> 
> Signed-off-by: Charles-Antoine Couret 
> ---
>  drivers/media/Kconfig  |   1 +
>  drivers/media/Makefile |   2 +-
>  drivers/media/spi/Kconfig  |   5 +
>  drivers/media/spi/Makefile |   1 +
>  drivers/media/spi/gs1662.c | 460 
> +
>  5 files changed, 468 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/media/spi/Kconfig
>  create mode 100644 drivers/media/spi/Makefile
>  create mode 100644 drivers/media/spi/gs1662.c
> 
> diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
> index a8518fb..d2fa6e7 100644
> --- a/drivers/media/Kconfig
> +++ b/drivers/media/Kconfig
> @@ -215,5 +215,6 @@ config MEDIA_ATTACH
>  source "drivers/media/i2c/Kconfig"
>  source "drivers/media/tuners/Kconfig"
>  source "drivers/media/dvb-frontends/Kconfig"
> +source "drivers/media/spi/Kconfig"
>  
>  endif # MEDIA_SUPPORT
> diff --git a/drivers/media/Makefile b/drivers/media/Makefile
> index e608bbc..75bc82e 100644
> --- a/drivers/media/Makefile
> +++ b/drivers/media/Makefile
> @@ -28,6 +28,6 @@ obj-y += rc/
>  # Finally, merge the drivers that require the core
>  #
>  
> -obj-y += common/ platform/ pci/ usb/ mmc/ firewire/
> +obj-y += common/ platform/ pci/ usb/ mmc/ firewire/ spi/
>  obj-$(CONFIG_VIDEO_DEV) += radio/
>  
> diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
> new file mode 100644
> index 000..df626cb
> --- /dev/null
> +++ b/drivers/media/spi/Kconfig
> @@ -0,0 +1,5 @@

Just like i2c/Kconfig, this needs to be enclosed in

if VIDEO_V4L2

...

endif

> +config VIDEO_GS1662
> + tristate "Gennum Serializers video"
> + depends on SPI
> + ---help---
> +   Enable the GS1662 driver which serializes video streams.
> diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
> new file mode 100644
> index 000..ea64013
> --- /dev/null
> +++ b/drivers/media/spi/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
> diff --git a/drivers/media/spi/gs1662.c b/drivers/media/spi/gs1662.c
> new file mode 100644
> index 000..783ab82
> --- /dev/null
> +++ b/drivers/media/spi/gs1662.c
> @@ -0,0 +1,460 @@
> +/*
> + * GS1662 device registration.
> + *
> + * Copyright (C) 2015-2016 Nexvision
> + * Author: Charles-Antoine Couret 
> + *
> + * 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.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define REG_STATUS   0x04
> +#define REG_FORCE_FMT0x06
> +#define REG_LINES_PER_FRAME  0x12
> +#define REG_WORDS_PER_LINE   0x13
> +#define REG_WORDS_PER_ACT_LINE   0x14
> +#define REG_ACT_LINES_PER_FRAME  0x15
> +
> +#define MASK_H_LOCK  0x001
> +#define MASK_V_LOCK  0x002
> +#define MASK_STD_LOCK0x004
> +#define MASK_FORCE_STD   0x020
> +#define MASK_STD_STATUS  0x3E0
> +
> +#define GS_WIDTH_MIN 0
> +#define GS_WIDTH_MAX 2048
> +#define GS_HEIGHT_MIN 0
> +#define GS_HEIGHT_MAX 1080
> +#define GS_PIXELCLOCK_MIN 10519200
> +#define GS_PIXELCLOCK_MAX 7425
> +
> +struct gs {
> + struct spi_device *pdev;
> + struct v4l2_subdev sd;
> + struct v4l2_dv_timings current_timings;
> + int enabled;
> +};
> +
> +struct gs_reg_fmt {
> + u16 reg_value;
> + struct v4l2_dv_timings format;
> +};
> +
> +struct gs_reg_fmt_custom {
> + u16 reg_value;
> + __u32 width;
> + __u32 height;
> + __u64 pixelclock;
> + __u32 interlaced;
> +};
> +
> +static const struct spi_device_id gs_id[] = {
> + { "gs1662", 0 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(spi, gs_id);
> +
> +static const struct v4l2_dv_timings fmt_cap[] = {
> + V4L2_DV_BT_SDI_720X487I60,
> + V4L2_DV_BT_CEA_720X576P50,
> + V4L2_DV_BT_CEA_1280X720P24,
> + V4L2_DV_BT_CEA_1280X720P25,
> + V4L2_DV_BT_CEA_1280X720P30,
> + V4L2_DV_BT_CEA_1280X720P50,
> + V4L2_DV_BT_CEA_1280X720P60,
> + V4L2_DV_BT_CEA_1920X1080P24,
> + 

Re: [PATCH 1/2 v2] SDI: add flag for SDI formats and SMPTE 125M definition

2016-07-21 Thread Hans Verkuil
Hi Charles-Antoine,

These new flags have to be documented. As you may have seen, we're switching
away from docbook to sphinx (doc-rst). The 'docs-next' tree in the media_tree
repository can be used for the documentation patches.

This will appear in v4.8.

What is completely missing here is a discussion about how the blanking fields
are to be filled in by SDI drivers, and how they should be interpreted.

That should be part of the documentation of the V4L2_DV_BT_STD_SDI standard.

Ideally that should also be incorporated in v4l2_match_dv_timings(), even though
your driver doesn't need it.

Regardless, v4l2_print_dv_timings() should be updated with the new flag and std.

Regards,

Hans

On 07/15/2016 03:13 PM, Charles-Antoine Couret wrote:
> From c6b157259081bd40d881a5c642dd1a4a07195ca5 Mon Sep 17 00:00:00 2001
> From: Charles-Antoine Couret 
> Date: Fri, 15 Jul 2016 15:04:57 +0200
> Subject: [PATCH 1/2] SDI: add flag for SDI formats and SMPTE 125M definition
> 
> Adding others generic flags, which could be used by many
> components like GS1662.
> 
> Signed-off-by: Charles-Antoine Couret 
> ---
>  include/uapi/linux/v4l2-dv-timings.h | 12 
>  include/uapi/linux/videodev2.h   |  5 +
>  2 files changed, 17 insertions(+)
> 
> diff --git a/include/uapi/linux/v4l2-dv-timings.h 
> b/include/uapi/linux/v4l2-dv-timings.h
> index 086168e..eb7dd02 100644
> --- a/include/uapi/linux/v4l2-dv-timings.h
> +++ b/include/uapi/linux/v4l2-dv-timings.h
> @@ -934,4 +934,16 @@
>   V4L2_DV_FL_REDUCED_BLANKING) \
>  }
>  
> +/* SDI timings definitions */
> +
> +/* SMPTE-125M */
> +#define V4L2_DV_BT_SDI_720X487I60 { \
> + .type = V4L2_DV_BT_656_1120, \
> + V4L2_INIT_BT_TIMINGS(720, 487, 1, \
> + V4L2_DV_HSYNC_POS_POL, \
> + 1350, 0, 137, 0, 0, 19, 2, 0, 17, 0, \
> + V4L2_DV_BT_STD_SDI, \
> + V4L2_DV_FIRST_FIELD_EXTRA_LINE) \
> +}
> +
>  #endif
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 8f95191..4641f13 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -1259,6 +1259,7 @@ struct v4l2_bt_timings {
>  #define V4L2_DV_BT_STD_DMT   (1 << 1)  /* VESA Discrete Monitor Timings */
>  #define V4L2_DV_BT_STD_CVT   (1 << 2)  /* VESA Coordinated Video Timings */
>  #define V4L2_DV_BT_STD_GTF   (1 << 3)  /* VESA Generalized Timings Formula */
> +#define V4L2_DV_BT_STD_SDI   (1 << 4)  /* SDI Timings */
>  
>  /* Flags */
>  
> @@ -1363,6 +1364,8 @@ struct v4l2_bt_timings_cap {
>  #define V4L2_DV_BT_CAP_REDUCED_BLANKING  (1 << 2)
>  /* Supports custom formats */
>  #define V4L2_DV_BT_CAP_CUSTOM(1 << 3)
> +/* In case of odd format, to know the field which has the extra line */
> +#define V4L2_DV_FIRST_FIELD_EXTRA_LINE   (1 << 4)
>  
>  /** struct v4l2_dv_timings_cap - DV timings capabilities
>   * @type:the type of the timings (same as in struct v4l2_dv_timings)
> @@ -1413,6 +1416,8 @@ struct v4l2_input {
>  /* field 'status' - analog */
>  #define V4L2_IN_ST_NO_H_LOCK   0x0100  /* No horizontal sync lock */
>  #define V4L2_IN_ST_COLOR_KILL  0x0200  /* Color killer is active */
> +#define V4L2_IN_ST_NO_V_LOCK   0x0400  /* No vertical sync lock */
> +#define V4L2_IN_ST_NO_STD_LOCK 0x0800  /* No standard format lock */
>  
>  /* field 'status' - digital */
>  #define V4L2_IN_ST_NO_SYNC 0x0001  /* No synchronization lock */
> 
--
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


[PATCH v6 0/2] [media] atmel-isc: add driver for Atmel ISC

2016-07-21 Thread Songjun Wu
The Image Sensor Controller driver includes two parts.
1) Driver code to implement the ISC function.
2) Device tree binding documentation, it describes how
   to add the ISC in device tree.

Test result with v4l-utils 1.10.1
Driver Info:
Driver name   : atmel_isc
Card type : Atmel Image Sensor Controller
Bus info  : platform:atmel_isc f0008000.isc
Driver version: 4.7.0
Capabilities  : 0x8421
Video Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0421
Video Capture
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: 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)

Test input 0:

Control ioctls:
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:
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:
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:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK

Test input 0:

Stream using all formats:
test MMAP for Format BA81, Frame Size 640x480:
Stride 640, Field None: OK
test MMAP for Format YUYV, Frame Size 640x480:
Stride 1280, Field None: OK

Total: 44, Succeeded: 44, Failed: 0, Warnings: 0

Changes in v6:
- Add "iscck" and "gck" to clock-names.

Changes in v5:
- Modify the macro definition and the related code.
- Add clock-output-names.

Changes in v4:
- Modify the isc clock code since the dt is changed.
- Remove the isc clock nodes.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.
- Remove the 'atmel,sensor-preferred'.
- Modify the isc clock node according to the Rob's remarks.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
  in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
  with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in
  'isc_queue_setup' function.
- Invoke isc_config to configure register in
  'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with
  the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
  in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
  in 

[PATCH v6 1/2] [media] atmel-isc: add the Image Sensor Controller code

2016-07-21 Thread Songjun Wu
Add driver for the Image Sensor Controller. It manages
incoming data from a parallel based CMOS/CCD sensor.
It has an internal image processor, also integrates a
triple channel direct memory access controller master
interface.

Signed-off-by: Songjun Wu 
---

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API"
  in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample'
  with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in
  'isc_queue_setup' function.
- Invoke isc_config to configure register in
  'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with
  the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
  in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
  in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and
  initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner  = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with
  module_platform_driver().

 drivers/media/platform/Kconfig|1 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/atmel/Kconfig  |9 +
 drivers/media/platform/atmel/Makefile |1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c  | 1554 +
 6 files changed, 1732 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index f25344b..b23db17 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -111,6 +111,7 @@ source "drivers/media/platform/s5p-tv/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
+source "drivers/media/platform/atmel/Kconfig"
 
 config VIDEO_TI_CAL
tristate "TI CAL (Camera Adaptation Layer) driver"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 21771c1..37b6c75 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -58,6 +58,8 @@ obj-$(CONFIG_VIDEO_XILINX)+= xilinx/
 
 obj-$(CONFIG_VIDEO_RCAR_VIN)   += rcar-vin/
 
+obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/atmel/Kconfig 
b/drivers/media/platform/atmel/Kconfig
new file mode 100644
index 000..867dca2
--- /dev/null
+++ b/drivers/media/platform/atmel/Kconfig
@@ -0,0 +1,9 @@
+config VIDEO_ATMEL_ISC
+   tristate "ATMEL Image Sensor Controller (ISC) support"
+   depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA
+   depends on ARCH_AT91 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select REGMAP_MMIO
+   help
+  This module makes the ATMEL Image Sensor Controller available
+  as a v4l2 device.
\ No newline at end of file
diff --git a/drivers/media/platform/atmel/Makefile 
b/drivers/media/platform/atmel/Makefile
new file mode 100644
index 000..9d7c999
--- /dev/null
+++ b/drivers/media/platform/atmel/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_ATMEL_ISC) += atmel-isc.o
diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h 
b/drivers/media/platform/atmel/atmel-isc-regs.h
new file mode 100644
index 000..00c4497
--- /dev/null
+++ b/drivers/media/platform/atmel/atmel-isc-regs.h
@@ -0,0 +1,165 @@
+#ifndef __ATMEL_ISC_REGS_H
+#define __ATMEL_ISC_REGS_H
+
+#include 
+
+/* ISC Control Enable Register 0 */
+#define ISC_CTRLEN  0x
+
+/* ISC Control Disable Register 0 */
+#define ISC_CTRLDIS 0x0004
+
+/* ISC Control Status Register 0 */
+#define ISC_CTRLSR  0x0008
+
+#define ISC_CTRL_CAPTURE   BIT(0)
+#define ISC_CTRL_UPPRO BIT(1)
+#define ISC_CTRL_HISREQBIT(2)
+#define ISC_CTRL_HISCLRBIT(3)
+
+/* ISC Parallel Front End Configuration 0 Register */
+#define ISC_PFE_CFG0

[PATCH v6 2/2] [media] atmel-isc: DT binding for Image Sensor Controller driver

2016-07-21 Thread Songjun Wu
DT binding documentation for ISC driver.

Signed-off-by: Songjun Wu 
---

Changes in v6:
- Add "iscck" and "gck" to clock-names.

Changes in v5:
- Add clock-output-names.

Changes in v4:
- Remove the isc clock nodes.

Changes in v3:
- Remove the 'atmel,sensor-preferred'.
- Modify the isc clock node according to the Rob's remarks.

Changes in v2:
- Remove the unit address of the endpoint.
- Add the unit address to the clock node.
- Avoid using underscores in node names.
- Drop the "0x" in the unit address of the i2c node.
- Modify the description of 'atmel,sensor-preferred'.
- Add the description for the ISC internal clock.

 .../devicetree/bindings/media/atmel-isc.txt| 65 ++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isc.txt

diff --git a/Documentation/devicetree/bindings/media/atmel-isc.txt 
b/Documentation/devicetree/bindings/media/atmel-isc.txt
new file mode 100644
index 000..50ab60b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/atmel-isc.txt
@@ -0,0 +1,65 @@
+Atmel Image Sensor Controller (ISC)
+--
+
+Required properties for ISC:
+- compatible
+   Must be "atmel,sama5d2-isc".
+- reg
+   Physical base address and length of the registers set for the device.
+- interrupts
+   Should contain IRQ line for the ISC.
+- clocks
+   List of clock specifiers, corresponding to entries in
+   the clock-names property;
+   Please refer to clock-bindings.txt.
+- clock-names
+   Required elements: "hclock", "iscck", "gck".
+- #clock-cells
+   Should be 0.
+- clock-output-names
+   Should be "isc-mck".
+- pinctrl-names, pinctrl-0
+   Please refer to pinctrl-bindings.txt.
+
+ISC supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+isc: isc@f0008000 {
+   compatible = "atmel,sama5d2-isc";
+   reg = <0xf0008000 0x4000>;
+   interrupts = <46 IRQ_TYPE_LEVEL_HIGH 5>;
+   clocks = <_clk>, <>, <_gclk>;
+   clock-names = "hclock", "iscck", "gck";
+   #clock-cells = <0>;
+   clock-output-names = "isc-mck";
+   pinctrl-names = "default";
+   pinctrl-0 = <_isc_base _isc_data_8bit 
_isc_data_9_10 _isc_data_11_12>;
+
+   port {
+   isc_0: endpoint {
+   remote-endpoint = <_0>;
+   hsync-active = <1>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
+   };
+   };
+};
+
+i2c1: i2c@fc028000 {
+   ov7740: camera@21 {
+   compatible = "ovti,ov7740";
+   reg = <0x21>;
+   clocks = <>;
+   clock-names = "xvclk";
+   assigned-clocks = <>;
+   assigned-clock-rates = <2400>;
+
+   port {
+   ov7740_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+};
\ No newline at end of file
-- 
2.7.4

--
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 v3 0/3] support of v4l2 encoder for STMicroelectronics SOC

2016-07-21 Thread Hans Verkuil
The module is still called 'hva'. I suggest calling it sti-hva instead.

>   Format ioctls:
>   test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
>   warn: 
> /local/home/frq08988/views/opensdk-2.1.4.1/sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(1187):
>  S_PARM is supported for buftype 1, but not ENUM_FRAMEINTERVALS
>   warn: 
> /local/home/frq08988/views/opensdk-2.1.4.1/sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(1187):
>  S_PARM is supported for buftype 2, but not ENUM_FRAMEINTERVALS

So why is S_PARM supported? I asked about that in my review, but I got no 
answer.

I've never seen that for m2m devices, and it really makes no sense IMHO.

The 'framerate' is typically driven by how often new frames are submitted by the
user. It's not up to the driver to mess with that.

Regards,

Hans
--
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


[PATCH v3 2/3] hva: multi-format video encoder V4L2 driver

2016-07-21 Thread Jean-Christophe Trotin
This patch adds V4L2 HVA (Hardware Video Accelerator) video encoder
driver for STMicroelectronics SoC. It uses the V4L2 mem2mem framework.

This patch only contains the core parts of the driver:
- the V4L2 interface with the userland (hva-v4l2.c)
- the hardware services (hva-hw.c)
- the memory management utilities (hva-mem.c)

This patch doesn't include the support of specific codec (e.g. H.264)
video encoding: this support is part of subsequent patches.

Signed-off-by: Yannick Fertre 
Signed-off-by: Jean-Christophe Trotin 
---
 drivers/media/platform/Kconfig|   14 +
 drivers/media/platform/Makefile   |1 +
 drivers/media/platform/sti/hva/Makefile   |2 +
 drivers/media/platform/sti/hva/hva-hw.c   |  538 
 drivers/media/platform/sti/hva/hva-hw.h   |   42 +
 drivers/media/platform/sti/hva/hva-mem.c  |   60 ++
 drivers/media/platform/sti/hva/hva-mem.h  |   36 +
 drivers/media/platform/sti/hva/hva-v4l2.c | 1289 +
 drivers/media/platform/sti/hva/hva.h  |  290 +++
 9 files changed, 2272 insertions(+)
 create mode 100644 drivers/media/platform/sti/hva/Makefile
 create mode 100644 drivers/media/platform/sti/hva/hva-hw.c
 create mode 100644 drivers/media/platform/sti/hva/hva-hw.h
 create mode 100644 drivers/media/platform/sti/hva/hva-mem.c
 create mode 100644 drivers/media/platform/sti/hva/hva-mem.h
 create mode 100644 drivers/media/platform/sti/hva/hva-v4l2.c
 create mode 100644 drivers/media/platform/sti/hva/hva.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index f25344b..d872d7b 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -257,6 +257,20 @@ config VIDEO_STI_BDISP
help
  This v4l2 mem2mem driver is a 2D blitter for STMicroelectronics SoC.
 
+config VIDEO_STI_HVA
+   tristate "STMicroelectronics HVA multi-format video encoder V4L2 driver"
+   depends on VIDEO_DEV && VIDEO_V4L2
+   depends on ARCH_STI || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_MEM2MEM_DEV
+   help
+ This V4L2 driver enables HVA (Hardware Video Accelerator) multi-format
+ video encoder of STMicroelectronics SoC, allowing hardware encoding of
+ raw uncompressed formats in various compressed video bitstreams 
format.
+
+ To compile this driver as a module, choose M here:
+ the module will be called hva.
+
 config VIDEO_SH_VEU
tristate "SuperH VEU mem2mem video processing driver"
depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 21771c1..fa31ec1 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D)   += s5p-g2d/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC) += exynos-gsc/
 
 obj-$(CONFIG_VIDEO_STI_BDISP)  += sti/bdisp/
+obj-$(CONFIG_VIDEO_STI_HVA)+= sti/hva/
 obj-$(CONFIG_DVB_C8SECTPFE)+= sti/c8sectpfe/
 
 obj-$(CONFIG_BLACKFIN)  += blackfin/
diff --git a/drivers/media/platform/sti/hva/Makefile 
b/drivers/media/platform/sti/hva/Makefile
new file mode 100644
index 000..7022a33
--- /dev/null
+++ b/drivers/media/platform/sti/hva/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_VIDEO_STI_HVA) := hva.o
+hva-y := hva-v4l2.o hva-hw.o hva-mem.o
diff --git a/drivers/media/platform/sti/hva/hva-hw.c 
b/drivers/media/platform/sti/hva/hva-hw.c
new file mode 100644
index 000..6919fa2
--- /dev/null
+++ b/drivers/media/platform/sti/hva/hva-hw.c
@@ -0,0 +1,538 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2015
+ * Authors: Yannick Fertre 
+ *  Hugues Fruchet 
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "hva.h"
+#include "hva-hw.h"
+
+/* HVA register offsets */
+#define HVA_HIF_REG_RST 0x0100U
+#define HVA_HIF_REG_RST_ACK 0x0104U
+#define HVA_HIF_REG_MIF_CFG 0x0108U
+#define HVA_HIF_REG_HEC_MIF_CFG 0x010CU
+#define HVA_HIF_REG_CFL 0x0110U
+#define HVA_HIF_FIFO_CMD0x0114U
+#define HVA_HIF_FIFO_STS0x0118U
+#define HVA_HIF_REG_SFL 0x011CU
+#define HVA_HIF_REG_IT_ACK  0x0120U
+#define HVA_HIF_REG_ERR_IT_ACK  0x0124U
+#define HVA_HIF_REG_LMI_ERR 0x0128U
+#define HVA_HIF_REG_EMI_ERR 0x012CU
+#define HVA_HIF_REG_HEC_MIF_ERR 0x0130U
+#define HVA_HIF_REG_HEC_STS 0x0134U
+#define HVA_HIF_REG_HVC_STS 0x0138U
+#define HVA_HIF_REG_HJE_STS 0x013CU
+#define HVA_HIF_REG_CNT 0x0140U
+#define HVA_HIF_REG_HEC_CHKSYN_DIS  0x0144U
+#define HVA_HIF_REG_CLK_GATING  0x0148U
+#define HVA_HIF_REG_VERSION 

[PATCH v3 3/3] hva: add H.264 video encoding support

2016-07-21 Thread Jean-Christophe Trotin
This patch adds the H.264 video encoding capability in the V4L2 HVA
video encoder driver for STMicroelectronics SoC (hva-h264.c).

The main supported features are:
- profile: baseline, main, high, stereo high
- level: up to 4.2
- bitrate mode: CBR, VBR
- entropy mode: CABAC, CAVLC
- video aspect: 1x1 only

Signed-off-by: Yannick Fertre 
Signed-off-by: Jean-Christophe Trotin 
---
 drivers/media/platform/sti/hva/Makefile   |2 +-
 drivers/media/platform/sti/hva/hva-h264.c | 1053 +
 drivers/media/platform/sti/hva/hva-v4l2.c |  109 ++-
 drivers/media/platform/sti/hva/hva.h  |   35 +-
 4 files changed, 1192 insertions(+), 7 deletions(-)
 create mode 100644 drivers/media/platform/sti/hva/hva-h264.c

diff --git a/drivers/media/platform/sti/hva/Makefile 
b/drivers/media/platform/sti/hva/Makefile
index 7022a33..495894b 100644
--- a/drivers/media/platform/sti/hva/Makefile
+++ b/drivers/media/platform/sti/hva/Makefile
@@ -1,2 +1,2 @@
 obj-$(CONFIG_VIDEO_STI_HVA) := hva.o
-hva-y := hva-v4l2.o hva-hw.o hva-mem.o
+hva-y := hva-v4l2.o hva-hw.o hva-mem.o hva-h264.o
diff --git a/drivers/media/platform/sti/hva/hva-h264.c 
b/drivers/media/platform/sti/hva/hva-h264.c
new file mode 100644
index 000..f7cdaa1
--- /dev/null
+++ b/drivers/media/platform/sti/hva/hva-h264.c
@@ -0,0 +1,1053 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2015
+ * Authors: Yannick Fertre 
+ *  Hugues Fruchet 
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include "hva.h"
+#include "hva-hw.h"
+
+#define MAX_SPS_PPS_SIZE 128
+
+#define BITSTREAM_OFFSET_MASK 0x7F
+
+/* video max size*/
+#define H264_MAX_SIZE_W 1920
+#define H264_MAX_SIZE_H 1920
+
+/* macroBlocs number (width & height) */
+#define MB_W(w) ((w + 0xF)  / 0x10)
+#define MB_H(h) ((h + 0xF)  / 0x10)
+
+/* formula to get temporal or spatial data size */
+#define DATA_SIZE(w, h) (MB_W(w) * MB_H(h) * 16)
+
+#define SEARCH_WINDOW_BUFFER_MAX_SIZE(w) ((4 * MB_W(w) + 42) * 256 * 3 / 2)
+#define CABAC_CONTEXT_BUFFER_MAX_SIZE(w) (MB_W(w) * 16)
+#define CTX_MB_BUFFER_MAX_SIZE(w) (MB_W(w) * 16 * 8)
+#define SLICE_HEADER_SIZE (4 * 16)
+#define BRC_DATA_SIZE (5 * 16)
+
+/* source buffer copy in YUV 420 MB-tiled format with size=16*256*3/2 */
+#define CURRENT_WINDOW_BUFFER_MAX_SIZE (16 * 256 * 3 / 2)
+
+/*
+ * 4 lines of pixels (in Luma, Chroma blue and Chroma red) of top MB
+ * for deblocking with size=4*16*MBx*2
+ */
+#define LOCAL_RECONSTRUCTED_BUFFER_MAX_SIZE(w) (4 * 16 * MB_W(w) * 2)
+
+/* factor for bitrate and cpb buffer size max values if profile >= high */
+#define H264_FACTOR_HIGH 1200
+
+/* factor for bitrate and cpb buffer size max values if profile < high */
+#define H264_FACTOR_BASELINE 1000
+
+/* number of bytes for NALU_TYPE_FILLER_DATA header and footer */
+#define H264_FILLER_DATA_SIZE 6
+
+struct h264_profile {
+   enum v4l2_mpeg_video_h264_level level;
+   u32 max_mb_per_seconds;
+   u32 max_frame_size;
+   u32 max_bitrate;
+   u32 max_cpb_size;
+   u32 min_comp_ratio;
+};
+
+static const struct h264_profile h264_infos_list[] = {
+   {V4L2_MPEG_VIDEO_H264_LEVEL_1_0, 1485, 99, 64, 175, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_1B, 1485, 99, 128, 350, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_1_1, 3000, 396, 192, 500, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_1_2, 6000, 396, 384, 1000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_1_3, 11880, 396, 768, 2000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_2_0, 11880, 396, 2000, 2000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_2_1, 19800, 792, 4000, 4000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_2_2, 20250, 1620, 4000, 4000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_3_0, 40500, 1620, 1, 1, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_3_1, 108000, 3600, 14000, 14000, 4},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_3_2, 216000, 5120, 2, 2, 4},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 245760, 8192, 2, 25000, 4},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_4_1, 245760, 8192, 5, 62500, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_4_2, 522240, 8704, 5, 62500, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_5_0, 589824, 22080, 135000, 135000, 2},
+   {V4L2_MPEG_VIDEO_H264_LEVEL_5_1, 983040, 36864, 24, 24, 2}
+};
+
+enum hva_brc_type {
+   BRC_TYPE_NONE = 0,
+   BRC_TYPE_CBR = 1,
+   BRC_TYPE_VBR = 2,
+   BRC_TYPE_VBR_LOW_DELAY = 3
+};
+
+enum hva_entropy_coding_mode {
+   CAVLC = 0,
+   CABAC = 1
+};
+
+enum hva_picture_coding_type {
+   PICTURE_CODING_TYPE_I = 0,
+   PICTURE_CODING_TYPE_P = 1,
+   PICTURE_CODING_TYPE_B = 2
+};
+
+enum hva_h264_sampling_mode {
+   SAMPLING_MODE_NV12 = 0,
+   SAMPLING_MODE_UYVY = 1,
+   SAMPLING_MODE_RGB3 = 3,
+   SAMPLING_MODE_XRGB4 = 4,
+   SAMPLING_MODE_NV21 = 8,
+   SAMPLING_MODE_VYUY = 9,
+   SAMPLING_MODE_BGR3 = 11,
+   SAMPLING_MODE_XBGR4 = 12,
+   

[PATCH v3 1/3] Documentation: DT: add bindings for STI HVA

2016-07-21 Thread Jean-Christophe Trotin
This patch adds DT binding documentation for STMicroelectronics hva
driver.

Signed-off-by: Yannick Fertre 
Signed-off-by: Jean-Christophe Trotin 
---
 .../devicetree/bindings/media/st,sti-hva.txt   | 24 ++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,sti-hva.txt

diff --git a/Documentation/devicetree/bindings/media/st,sti-hva.txt 
b/Documentation/devicetree/bindings/media/st,sti-hva.txt
new file mode 100644
index 000..d1030bb
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,sti-hva.txt
@@ -0,0 +1,24 @@
+hva: multi-format video encoder for STMicroelectronics SoC.
+
+Required properties:
+- compatible: should be "st,sti-hva".
+- reg: HVA physical address location and length, esram address location and
+  length.
+- reg-names: names of the registers listed in registers property in the same
+  order.
+- interrupts: HVA interrupt number.
+- clocks: from common clock binding: handle hardware IP needed clocks, the
+  number of clocks may depend on the SoC type.
+  See ../clock/clock-bindings.txt for details.
+- clock-names: names of the clocks listed in clocks property in the same order.
+
+Example:
+   hva@8c85000{
+   compatible = "st,sti-hva";
+   reg = <0x8c85000 0x400>, <0x600 0x4>;
+   reg-names = "hva_registers", "hva_esram";
+   interrupts = ,
+;
+   clock-names = "clk_hva";
+   clocks = <_s_c0_flexgen CLK_HVA>;
+   };
-- 
1.9.1

--
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


[PATCH v3 0/3] support of v4l2 encoder for STMicroelectronics SOC

2016-07-21 Thread Jean-Christophe Trotin
version 3:
- Comments from Nicolas, Javier and Hans about version 2 taken into account:
- Kconfig's comment reworked
- querycap: "driver" contains the name of the encoder ("hva"), "card" 
identifies the hardware version ("hva" with  
equal to 400 here, which leads to "hva400"), and "bus_info" indicates the 
location of the device ("platform:8c85000.hva")
- device_caps field of struct video_device set to V4L2_CAP_STREAMING | 
V4L2_CAP_VIDEO_M2M
- colorspace management aligned on the vim2m and mtk-vcodec drivers' 
code
- useless debug messages removed
- in case of error in start_streaming, all pending buffers for queue 
are returned to vb2 in the QUEUED state
- hardware restriction with regards to the number of codec instances 
managed in start_streaming instead of open (then, the v4l2-compliance test for 
unlimited opens passes)
- typos corrected
- V4L2 compliance successfully passed with this version (see report below)

version 2:
- List of pixel formats supported by the encoder reduced to NV12 and NV21
- x86_64 compilation warnings corrected
- V4L2 compliance successfully passed with this version (see report below)
- All remarks about version 1 of hva-v4l2.c taken into account:
- V4L2 mem2mem framework used 
- V4L2 control framework used
- allocator context initialized in the probe and cleaned up in the 
remove
- start_streaming and stop_streaming ops added
- colorspace, bytesperline and sizeimage fields initialized in TRY_FMT
- better estimation of sizeimage for compressed formats
- checks and debugging logs already covered by vb2 removed
- some dev_err changed in dev_dbg
- typos corrected

version 1:
- Initial submission.

Only one feature supported and tested:
- encode (NV12, NV21) to H.264 video format

The driver is mainly implemented across three files:
- hva-v4l2.c
- hva-h264.c
- hva-hw.c
hva-v4l2.c manages the V4L2 interface with the userland.
It calls the HW services that are implemented in hva-hw.c.
hva-h264.c manages specific part of H.264 codec.

Below is the v4l2-compliance report for the version 3 of the hva driver:

root@sti-next:/home/video_test# v4l2-compliance -d /dev/video0
Driver Info:
Driver name   : hva
Card type : hva400
Bus info  : platform:8c85000.hva
Driver version: 4.7.0
Capabilities  : 0x84208000
Video Memory-to-Memory
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x04208000
Video Memory-to-Memory
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video 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 (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 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:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 16 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
warn: 
/local/home/frq08988/views/opensdk-2.1.4.1/sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(1187):
 S_PARM is supported for buftype 1, but not ENUM_FRAMEINTERVALS
warn: 
/local/home/frq08988/views/opensdk-2.1.4.1/sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(1187):
 S_PARM is supported for buftype 2, but not ENUM_FRAMEINTERVALS
  

Re: [PATCH v2 3/3] [media] hva: add H.264 video encoding support

2016-07-21 Thread Jean Christophe TROTIN


On 07/18/2016 01:55 PM, Hans Verkuil wrote:
> On 07/11/2016 05:14 PM, Jean-Christophe Trotin wrote:
>> This patch adds the H.264 video encoding capability in the V4L2 HVA
>> video encoder driver for STMicroelectronics SoC (hva-h264.c).
>>
>> The main supported features are:
>> - profile: baseline, main, high, stereo high
>> - level: up to 4.2
>> - bitrate mode: CBR, VBR
>> - entropy mode: CABAC, CAVLC
>> - video aspect: 1x1 only
>>
>> Signed-off-by: Yannick Fertre 
>> Signed-off-by: Jean-Christophe Trotin 
>> ---
>>   drivers/media/platform/sti/hva/Makefile   |2 +-
>>   drivers/media/platform/sti/hva/hva-h264.c | 1053 
>> +
>>   drivers/media/platform/sti/hva/hva-v4l2.c |  107 ++-
>>   drivers/media/platform/sti/hva/hva.h  |  115 +++-
>>   4 files changed, 1270 insertions(+), 7 deletions(-)
>>   create mode 100644 drivers/media/platform/sti/hva/hva-h264.c
>>
>
> 
>
>> diff --git a/drivers/media/platform/sti/hva/hva.h 
>> b/drivers/media/platform/sti/hva/hva.h
>> index 9a1b503b..a81f313 100644
>> --- a/drivers/media/platform/sti/hva/hva.h
>> +++ b/drivers/media/platform/sti/hva/hva.h
>> @@ -23,6 +23,9 @@
>>
>>   #define HVA_PREFIX "[---:]"
>>
>> +extern const struct hva_enc nv12h264enc;
>> +extern const struct hva_enc nv21h264enc;
>> +
>>   /**
>>* struct hva_frameinfo - information about hva frame
>>*
>> @@ -67,13 +70,35 @@ struct hva_streaminfo {
>>* @gop_size:   groupe of picture size
>>* @bitrate:bitrate (in kbps)
>>* @aspect: video aspect
>> + * @profile:H.264 profile
>> + * @level:  H.264 level
>> + * @entropy_mode:   H.264 entropy mode (CABAC or CVLC)
>> + * @cpb_size:   coded picture buffer size (in kbps)
>> + * @dct8x8: transform mode 8x8 enable
>> + * @qpmin:  minimum quantizer
>> + * @qpmax:  maximum quantizer
>> + * @vui_sar:pixel aspect ratio enable
>> + * @vui_sar_idc:pixel aspect ratio identifier
>> + * @sei_fp: sei frame packing arrangement enable
>> + * @sei_fp_type:sei frame packing arrangement type
>>*/
>>   struct hva_controls {
>> -struct v4l2_fract   time_per_frame;
>> -enum v4l2_mpeg_video_bitrate_mode   bitrate_mode;
>> -u32 gop_size;
>> -u32 bitrate;
>> -enum v4l2_mpeg_video_aspect aspect;
>> +struct v4l2_fract   time_per_frame;
>> +enum v4l2_mpeg_video_bitrate_mode   bitrate_mode;
>> +u32 gop_size;
>> +u32 bitrate;
>> +enum v4l2_mpeg_video_aspect aspect;
>> +enum v4l2_mpeg_video_h264_profile   profile;
>> +enum v4l2_mpeg_video_h264_level level;
>> +enum v4l2_mpeg_video_h264_entropy_mode  entropy_mode;
>> +u32 cpb_size;
>> +booldct8x8;
>> +u32 qpmin;
>> +u32 qpmax;
>> +boolvui_sar;
>> +enum v4l2_mpeg_video_h264_vui_sar_idc   vui_sar_idc;
>> +boolsei_fp;
>> +enum v4l2_mpeg_video_h264_sei_fp_arrangement_type   sei_fp_type;
>>   };
>>
>>   /**
>> @@ -281,4 +306,84 @@ struct hva_enc {
>>struct hva_stream *stream);
>>   };
>>
>> +static inline const char *profile_str(unsigned int p)
>> +{
>> +switch (p) {
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
>> +return "baseline profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
>> +return "main profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED:
>> +return "extended profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
>> +return "high profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10:
>> +return "high 10 profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422:
>> +return "high 422 profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE:
>> +return "high 444 predictive profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA:
>> +return "high 10 intra profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA:
>> +return "high 422 intra profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA:
>> +return "high 444 intra profile";
>> +case V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA:
>> +return "calvc 444 intra profile";
>> +

Re: [PATCH v2 2/3] [media] hva: multi-format video encoder V4L2 driver

2016-07-21 Thread Jean Christophe TROTIN

On 07/18/2016 01:45 PM, Hans Verkuil wrote:
> Hi Jean-Christophe,
>
> See my review comments below. Nothing really major, but I do need to know more
> about the g/s_parm and the restriction on the number of open()s has to be 
> lifted.
> That's not allowed.
>

Hi Hans,

Thank you for your comments.
I've explained below why I would like to keep 'hva' as driver's name and why the
frame rate is needed (g/s_parm).
I've followed your advice for managing the hardware restriction with regards to
the number of codec instances (see also below).
Finally, I've taken into account all the other comments.
All these modifications will be reflected in the version 3.

Best regards,
Jean-Christophe.

> On 07/11/2016 05:14 PM, Jean-Christophe Trotin wrote:
>> This patch adds V4L2 HVA (Hardware Video Accelerator) video encoder
>> driver for STMicroelectronics SoC. It uses the V4L2 mem2mem framework.
>>
>> This patch only contains the core parts of the driver:
>> - the V4L2 interface with the userland (hva-v4l2.c)
>> - the hardware services (hva-hw.c)
>> - the memory management utilities (hva-mem.c)
>>
>> This patch doesn't include the support of specific codec (e.g. H.264)
>> video encoding: this support is part of subsequent patches.
>>
>> Signed-off-by: Yannick Fertre 
>> Signed-off-by: Jean-Christophe Trotin 
>> ---
>>   drivers/media/platform/Kconfig|   14 +
>>   drivers/media/platform/Makefile   |1 +
>>   drivers/media/platform/sti/hva/Makefile   |2 +
>>   drivers/media/platform/sti/hva/hva-hw.c   |  534 
>>   drivers/media/platform/sti/hva/hva-hw.h   |   42 +
>>   drivers/media/platform/sti/hva/hva-mem.c  |   60 ++
>>   drivers/media/platform/sti/hva/hva-mem.h  |   36 +
>>   drivers/media/platform/sti/hva/hva-v4l2.c | 1299 
>> +
>>   drivers/media/platform/sti/hva/hva.h  |  284 +++
>>   9 files changed, 2272 insertions(+)
>>   create mode 100644 drivers/media/platform/sti/hva/Makefile
>>   create mode 100644 drivers/media/platform/sti/hva/hva-hw.c
>>   create mode 100644 drivers/media/platform/sti/hva/hva-hw.h
>>   create mode 100644 drivers/media/platform/sti/hva/hva-mem.c
>>   create mode 100644 drivers/media/platform/sti/hva/hva-mem.h
>>   create mode 100644 drivers/media/platform/sti/hva/hva-v4l2.c
>>   create mode 100644 drivers/media/platform/sti/hva/hva.h
>>
>> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
>> index 382f393..182d63f 100644
>> --- a/drivers/media/platform/Kconfig
>> +++ b/drivers/media/platform/Kconfig
>> @@ -227,6 +227,20 @@ config VIDEO_STI_BDISP
>>help
>>  This v4l2 mem2mem driver is a 2D blitter for STMicroelectronics SoC.
>>
>> +config VIDEO_STI_HVA
>> + tristate "STMicroelectronics STiH41x HVA multi-format video encoder 
>> V4L2 driver"
>> + depends on VIDEO_DEV && VIDEO_V4L2
>> + depends on ARCH_STI || COMPILE_TEST
>> + select VIDEOBUF2_DMA_CONTIG
>> + select V4L2_MEM2MEM_DEV
>> + help
>> +   This V4L2 driver enables HVA multi-format video encoder of
>
> Please mention here what HVA stands for.
>

Done in version 3.
HVA stands for "Hardware Video Accelerator".

>> +   STMicroelectronics SoC STiH41x series, allowing hardware encoding of 
>> raw
>> +   uncompressed formats in various compressed video bitstreams format.
>> +
>> +   To compile this driver as a module, choose M here:
>> +   the module will be called hva.
>
> How about sti-hva as the module name? 'hva' is a bit too generic.
>

'hva' is a generic IP which could be used on different STMicroelectronics SoCs.
That's the reason why I would like to keep this name. It's not specific to  the
STiH41x series: thus, I've reworked the Kconfig's comment.

>> +
>>   config VIDEO_SH_VEU
>>tristate "SuperH VEU mem2mem video processing driver"
>>depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
>
> 
>
>> diff --git a/drivers/media/platform/sti/hva/hva-v4l2.c 
>> b/drivers/media/platform/sti/hva/hva-v4l2.c
>> new file mode 100644
>> index 000..bacc9ff
>> --- /dev/null
>> +++ b/drivers/media/platform/sti/hva/hva-v4l2.c
>> @@ -0,0 +1,1299 @@
>> +/*
>> + * Copyright (C) STMicroelectronics SA 2015
>> + * Authors: Yannick Fertre 
>> + *  Hugues Fruchet 
>> + * License terms:  GNU General Public License (GPL), version 2
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "hva.h"
>> +#include "hva-hw.h"
>> +
>> +#define HVA_NAME "hva"
>> +
>> +#define MIN_FRAMES   1
>> +#define MIN_STREAMS  1
>> +
>> +#define HVA_MIN_WIDTH32
>> +#define HVA_MAX_WIDTH1920
>> +#define HVA_MIN_HEIGHT   32
>> +#define HVA_MAX_HEIGHT   1920
>> +
>> +/* HVA requires a 16x16 pixels alignment for frames */
>> +#define HVA_WIDTH_ALIGNMENT  16
>> +#define HVA_HEIGHT_ALIGNMENT 16
>> +
>> +#define DEFAULT_WIDTH