[PATCH 3/3] Documentation: DT bindings: add VI and CSI bindings

2015-09-15 Thread Bryan Wu
Signed-off-by: Bryan Wu 
---
 .../bindings/gpu/nvidia,tegra20-host1x.txt | 211 -
 1 file changed, 205 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt 
b/Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
index 46d6ead..433cb52 100644
--- a/Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
+++ b/Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
@@ -40,10 +40,39 @@ of the following host1x client modules:
   - interrupts: The interrupt outputs from the controller.
   - clocks: Must contain one entry, for the module clock.
 See ../clocks/clock-bindings.txt for details.
+  - clock-names: Must include the following entries:
+- vi
+  This MUST be the first entry.
+- csi
+- parent
   - resets: Must contain an entry for each entry in reset-names.
 See ../reset/reset.txt for details.
   - reset-names: Must include the following entries:
 - vi
+  - power-domains: The power domains settings.
+See ../power/power_domain.txt
+  - iommus: The IOMMU settings.
+See ../iommu/iommu.txt
+  - ports: several VI input ports which connecting CSI ports. Ports contain
+several port and each port has one endpoint.
+See ../graph.txt and ../media/video-interfaces.txt
+  - avdd-dsi-csi-supply: a regulator required by VI.
+
+- csi: camera serial interface
+
+  Required properties:
+  - compatible: "nvidia,tegra-csi"
+  - reg: Physical base address and length of the controller's registers.
+  - interrupts: The interrupt outputs from the controller.
+  - clocks: Must contain one entry, for the module clock.
+See ../clocks/clock-bindings.txt for details.
+  - clock-names: Must include the following entries:
+- cil
+  This MUST be the first entry.
+  - ports: 2 ports presenting 2 channels of CSI. Each port has 2 endpoints:
+one connects to sensor device tree node as input and the other one connects
+to VI endpoint.
+See ../graph.txt and ../media/video-interfaces.txt
 
 - epp: encoder pre-processor
 
@@ -274,13 +303,183 @@ Example:
reset-names = "mpe";
};
 
-   vi {
-   compatible = "nvidia,tegra20-vi";
-   reg = <0x5408 0x0004>;
-   interrupts = <0 69 0x04>;
-   clocks = <_car TEGRA20_CLK_VI>;
-   resets = <_car 100>;
+   vi@0,5408 {
+   compatible = "nvidia,tegra210-vi";
+   reg = <0x0 0x5408 0x0 0x800>;
+   interrupts = ;
+   status = "disabled";
+   clocks = <_car TEGRA210_CLK_VI>,
+<_car TEGRA210_CLK_CSI>,
+<_car TEGRA210_CLK_PLL_C>;
+   clock-names = "vi", "csi", "parent";
+   resets = <_car 20>;
reset-names = "vi";
+
+   power-domains = < TEGRA_POWERGATE_VENC>;
+
+   iommus = < TEGRA_SWGROUP_VI>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   vi_in0: endpoint {
+   remote-endpoint = <_out0>;
+   };
+   };
+   port@1 {
+   reg = <1>;
+
+   vi_in1: endpoint {
+   remote-endpoint = <_out1>;
+   };
+   };
+   port@2 {
+   reg = <2>;
+
+   vi_in2: endpoint {
+   remote-endpoint = <_out2>;
+   };
+   };
+   port@3 {
+   reg = <3>;
+
+   vi_in3: endpoint {
+   remote-endpoint = <_out3>;
+   };
+   };
+   port@4 {
+   reg = <4>;
+
+   vi_in4: endpoint {
+   remote-endpoint = <_out4>;
+   };
+   };
+   port@5 {
+   reg = <5>;
+
+   vi_in5: endpoint {

[PATCH 1/3] [media] v4l: tegra: Add NVIDIA Tegra VI driver

2015-09-15 Thread Bryan Wu
NVIDIA Tegra processor contains a powerful Video Input (VI) hardware
controller which can support up to 6 MIPI CSI camera sensors.

This patch adds a V4L2 media controller and capture driver to support
Tegra VI hardware. It's verified with Tegra built-in test pattern
generator.

Signed-off-by: Bryan Wu 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/Kconfig   |   1 +
 drivers/media/platform/Makefile  |   2 +
 drivers/media/platform/tegra/Kconfig |  10 +
 drivers/media/platform/tegra/Makefile|   3 +
 drivers/media/platform/tegra/tegra-channel.c | 802 +++
 drivers/media/platform/tegra/tegra-core.c| 252 +
 drivers/media/platform/tegra/tegra-core.h| 162 ++
 drivers/media/platform/tegra/tegra-csi.c | 566 +++
 drivers/media/platform/tegra/tegra-vi.c  | 581 +++
 drivers/media/platform/tegra/tegra-vi.h  | 213 +++
 10 files changed, 2592 insertions(+)
 create mode 100644 drivers/media/platform/tegra/Kconfig
 create mode 100644 drivers/media/platform/tegra/Makefile
 create mode 100644 drivers/media/platform/tegra/tegra-channel.c
 create mode 100644 drivers/media/platform/tegra/tegra-core.c
 create mode 100644 drivers/media/platform/tegra/tegra-core.h
 create mode 100644 drivers/media/platform/tegra/tegra-csi.c
 create mode 100644 drivers/media/platform/tegra/tegra-vi.c
 create mode 100644 drivers/media/platform/tegra/tegra-vi.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index f6bed19..553867f 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -119,6 +119,7 @@ source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/s5p-tv/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
+source "drivers/media/platform/tegra/Kconfig"
 
 endif # V4L_PLATFORM_DRIVERS
 
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 114f9ab..426e0e4 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -52,4 +52,6 @@ obj-$(CONFIG_VIDEO_AM437X_VPFE)   += am437x/
 
 obj-$(CONFIG_VIDEO_XILINX) += xilinx/
 
+obj-$(CONFIG_VIDEO_TEGRA)  += tegra/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
diff --git a/drivers/media/platform/tegra/Kconfig 
b/drivers/media/platform/tegra/Kconfig
new file mode 100644
index 000..54c0e7a
--- /dev/null
+++ b/drivers/media/platform/tegra/Kconfig
@@ -0,0 +1,10 @@
+config VIDEO_TEGRA
+   tristate "NVIDIA Tegra Video Input Driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF
+   depends on TEGRA_HOST1X
+   select VIDEOBUF2_DMA_CONTIG
+   ---help---
+ Driver for Video Input (VI) controller found on NVIDIA Tegra SoC.
+
+ To compile this driver as a module, choose M here: the module will be
+ called tegra-video.
diff --git a/drivers/media/platform/tegra/Makefile 
b/drivers/media/platform/tegra/Makefile
new file mode 100644
index 000..18a1c16
--- /dev/null
+++ b/drivers/media/platform/tegra/Makefile
@@ -0,0 +1,3 @@
+tegra-video-objs += tegra-core.o tegra-csi.o tegra-vi.o tegra-channel.o
+
+obj-$(CONFIG_VIDEO_TEGRA) += tegra-video.o
diff --git a/drivers/media/platform/tegra/tegra-channel.c 
b/drivers/media/platform/tegra/tegra-channel.c
new file mode 100644
index 000..8149016
--- /dev/null
+++ b/drivers/media/platform/tegra/tegra-channel.c
@@ -0,0 +1,802 @@
+/*
+ * NVIDIA Tegra Video Input Device
+ *
+ * Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * Author: Bryan Wu 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "tegra-vi.h"
+
+#define TEGRA_VI_SYNCPT_WAIT_TIMEOUT   200
+
+/* VI registers */
+#define TEGRA_VI_CFG_VI_INCR_SYNCPT0x000
+#define   VI_CFG_VI_INCR_SYNCPT_COND(x)(((x) & 0xff) 
<< 8)
+#define   VI_CSI_PP_LINE_START(port)   (4 + (port) * 4)
+#define   VI_CSI_PP_FRAME_START(port)  (5 + (port) * 4)
+#define   VI_CSI_MW_REQ_DONE(port) (6 + (port) * 4)
+#define   VI_CSI_MW_ACK_DONE(port) (7 + (port) * 4)
+
+#define TEGRA_VI_CFG_VI_INCR_SYNCPT_CNTRL  0x004
+#define TEGRA_VI_CFG_VI_INCR_SYNCPT_ERROR  0x008
+#define TEGRA_VI_CFG_CTXSW 0x020
+#define TEGRA_VI_CFG_INTSTATUS 0x024
+#define 

[PATCH 0/3 RFC v2] media: platform: add NVIDIA Tegra VI driver

2015-09-15 Thread Bryan Wu
This patchset add and enable V4L2 driver for latest NVIDIA Tegra
Video Input hardware controller.

It's based on the staging/work branch of Thierry Reding Tegra
upstream kernel github repo, which is based on 4.2-rc1.
(https://github.com/thierryreding/linux/tree/staging/work) 

v2:
  - allocate kthread for each channel instead of workqueue
  - create tegra-csi as a separated V4L2 subdevice
  - define all the register bits needed in this driver
  - add device tree binding document
  - update things according to Hans and Thierry's review.

Bryan Wu (3):
  [media] v4l: tegra: Add NVIDIA Tegra VI driver
  ARM64: add tegra-vi support in T210 device-tree
  Documentation: DT bindings: add VI and CSI bindings

 .../bindings/gpu/nvidia,tegra20-host1x.txt | 211 +-
 arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts  |   8 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi   | 174 -
 drivers/media/platform/Kconfig |   1 +
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/tegra/Kconfig   |  10 +
 drivers/media/platform/tegra/Makefile  |   3 +
 drivers/media/platform/tegra/tegra-channel.c   | 802 +
 drivers/media/platform/tegra/tegra-core.c  | 252 +++
 drivers/media/platform/tegra/tegra-core.h  | 162 +
 drivers/media/platform/tegra/tegra-csi.c   | 566 +++
 drivers/media/platform/tegra/tegra-vi.c| 581 +++
 drivers/media/platform/tegra/tegra-vi.h| 213 ++
 13 files changed, 2978 insertions(+), 7 deletions(-)
 create mode 100644 drivers/media/platform/tegra/Kconfig
 create mode 100644 drivers/media/platform/tegra/Makefile
 create mode 100644 drivers/media/platform/tegra/tegra-channel.c
 create mode 100644 drivers/media/platform/tegra/tegra-core.c
 create mode 100644 drivers/media/platform/tegra/tegra-core.h
 create mode 100644 drivers/media/platform/tegra/tegra-csi.c
 create mode 100644 drivers/media/platform/tegra/tegra-vi.c
 create mode 100644 drivers/media/platform/tegra/tegra-vi.h

-- 
2.1.4


---
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
---
--
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 2/3] ARM64: add tegra-vi support in T210 device-tree

2015-09-15 Thread Bryan Wu
Following device tree support for Tegra VI now:
 - "vi" node which might have 6 ports/endpoints
 - in TPG mode, "vi" node don't need to define any ports/endpoints
 - ports/endpoints defines the link between VI and external sensors.

Signed-off-by: Bryan Wu 
---
 arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts |   8 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi  | 174 +-
 2 files changed, 181 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts 
b/arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts
index d4ee460..534ada52 100644
--- a/arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts
+++ b/arch/arm64/boot/dts/nvidia/tegra210-p2571-e01.dts
@@ -7,6 +7,14 @@
model = "NVIDIA Tegra210 P2571 reference board (E.1)";
compatible = "nvidia,p2571-e01", "nvidia,tegra210";
 
+   host1x@0,5000 {
+   vi@0,5408 {
+   status = "okay";
+
+   avdd-dsi-csi-supply = <_dsi_csi>;
+   };
+   };
+
pinmux: pinmux@0,78d4 {
pinctrl-names = "boot";
pinctrl-0 = <_boot>;
diff --git a/arch/arm64/boot/dts/nvidia/tegra210.dtsi 
b/arch/arm64/boot/dts/nvidia/tegra210.dtsi
index 1168bcd..3f6501f 100644
--- a/arch/arm64/boot/dts/nvidia/tegra210.dtsi
+++ b/arch/arm64/boot/dts/nvidia/tegra210.dtsi
@@ -109,9 +109,181 @@
 
vi@0,5408 {
compatible = "nvidia,tegra210-vi";
-   reg = <0x0 0x5408 0x0 0x0004>;
+   reg = <0x0 0x5408 0x0 0x800>;
interrupts = ;
status = "disabled";
+   clocks = <_car TEGRA210_CLK_VI>,
+<_car TEGRA210_CLK_CSI>,
+<_car TEGRA210_CLK_PLL_C>;
+   clock-names = "vi", "csi", "parent";
+   resets = <_car 20>;
+   reset-names = "vi";
+
+   power-domains = < TEGRA_POWERGATE_VENC>;
+
+   iommus = < TEGRA_SWGROUP_VI>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   vi_in0: endpoint {
+   remote-endpoint = <_out0>;
+   };
+   };
+   port@1 {
+   reg = <1>;
+
+   vi_in1: endpoint {
+   remote-endpoint = <_out1>;
+   };
+   };
+   port@2 {
+   reg = <2>;
+
+   vi_in2: endpoint {
+   remote-endpoint = <_out2>;
+   };
+   };
+   port@3 {
+   reg = <3>;
+
+   vi_in3: endpoint {
+   remote-endpoint = <_out3>;
+   };
+   };
+   port@4 {
+   reg = <4>;
+
+   vi_in4: endpoint {
+   remote-endpoint = <_out4>;
+   };
+   };
+   port@5 {
+   reg = <5>;
+
+   vi_in5: endpoint {
+   remote-endpoint = <_out5>;
+   };
+   };
+
+   };
+   };
+
+   csi@0,54080838 {
+   compatible = "nvidia,tegra210-csi";
+   reg = <0x0 0x54080838 0x0 0x700>;
+   clocks = <_car TEGRA210_CLK_CILAB>;
+   clock-names = "cil";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   csi_in0: endpoint@0 {
+   reg = <0x0>;
+   };
+

cron job: media_tree daily build: OK

2015-09-15 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:   Wed Sep 16 04:00:18 CEST 2015
git branch: test
git hash:   9ddf9071ea17b83954358b2dac42b34e5857a9af
gcc version:i686-linux-gcc (GCC) 5.1.0
sparse version: v0.5.0-51-ga53cea2
smatch version: 0.4.1-3153-g7d56ab3
host hardware:  x86_64
host os:4.0.0-3.slh.1-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-exynos: OK
linux-git-arm-mx: OK
linux-git-arm-omap: OK
linux-git-arm-omap1: OK
linux-git-arm-pxa: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.32.27-i686: OK
linux-2.6.33.7-i686: OK
linux-2.6.34.7-i686: OK
linux-2.6.35.9-i686: OK
linux-2.6.36.4-i686: OK
linux-2.6.37.6-i686: OK
linux-2.6.38.8-i686: OK
linux-2.6.39.4-i686: OK
linux-3.0.60-i686: OK
linux-3.1.10-i686: OK
linux-3.2.37-i686: OK
linux-3.3.8-i686: OK
linux-3.4.27-i686: OK
linux-3.5.7-i686: OK
linux-3.6.11-i686: OK
linux-3.7.4-i686: OK
linux-3.8-i686: OK
linux-3.9.2-i686: OK
linux-3.10.1-i686: OK
linux-3.11.1-i686: OK
linux-3.12.23-i686: OK
linux-3.13.11-i686: OK
linux-3.14.9-i686: OK
linux-3.15.2-i686: OK
linux-3.16.7-i686: OK
linux-3.17.8-i686: OK
linux-3.18.7-i686: OK
linux-3.19-i686: OK
linux-4.0-i686: OK
linux-4.1.1-i686: OK
linux-4.2-i686: OK
linux-4.3-rc1-i686: OK
linux-2.6.32.27-x86_64: OK
linux-2.6.33.7-x86_64: OK
linux-2.6.34.7-x86_64: OK
linux-2.6.35.9-x86_64: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.60-x86_64: OK
linux-3.1.10-x86_64: OK
linux-3.2.37-x86_64: OK
linux-3.3.8-x86_64: OK
linux-3.4.27-x86_64: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-x86_64: OK
linux-3.7.4-x86_64: OK
linux-3.8-x86_64: OK
linux-3.9.2-x86_64: OK
linux-3.10.1-x86_64: OK
linux-3.11.1-x86_64: OK
linux-3.12.23-x86_64: OK
linux-3.13.11-x86_64: OK
linux-3.14.9-x86_64: OK
linux-3.15.2-x86_64: OK
linux-3.16.7-x86_64: OK
linux-3.17.8-x86_64: OK
linux-3.18.7-x86_64: OK
linux-3.19-x86_64: OK
linux-4.0-x86_64: OK
linux-4.1.1-x86_64: OK
linux-4.2-x86_64: OK
linux-4.3-rc1-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS
smatch: ERRORS

Detailed results are available here:

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

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Wednesday.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


vim2m: small cleanup: use assignment instead of memcpy

2015-09-15 Thread Hans Verkuil
Use a type-safe assignment instead of memcpy. And it is easier to read as well.

Signed-off-by: Hans Verkuil 

diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index 295fde5..d47cfba 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -233,12 +233,9 @@ static int device_process(struct vim2m_ctx *ctx,
 
out_vb->v4l2_buf.sequence = get_q_data(ctx, 
V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++;
in_vb->v4l2_buf.sequence = q_data->sequence++;
-   memcpy(_vb->v4l2_buf.timestamp,
-   _vb->v4l2_buf.timestamp,
-   sizeof(struct timeval));
+   out_vb->v4l2_buf.timestamp = in_vb->v4l2_buf.timestamp;
if (in_vb->v4l2_buf.flags & V4L2_BUF_FLAG_TIMECODE)
-   memcpy(_vb->v4l2_buf.timecode, _vb->v4l2_buf.timecode,
-   sizeof(struct v4l2_timecode));
+   out_vb->v4l2_buf.timecode = in_vb->v4l2_buf.timecode;
out_vb->v4l2_buf.field = in_vb->v4l2_buf.field;
out_vb->v4l2_buf.flags = in_vb->v4l2_buf.flags &
(V4L2_BUF_FLAG_TIMECODE |
--
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 RESEND 03/11] vb2: Move cache synchronisation from buffer done to dqbuf handler

2015-09-15 Thread Sakari Ailus
Hi Hans,

Thank you for the review!

Hans Verkuil wrote:
> On 09/11/2015 01:50 PM, Sakari Ailus wrote:
>> The cache synchronisation may be a time consuming operation and thus not
>> best performed in an interrupt which is a typical context for
>> vb2_buffer_done() calls. This may consume up to tens of ms on some
>> machines, depending on the buffer size.
>>
>> Signed-off-by: Sakari Ailus 
>> ---
>>  drivers/media/v4l2-core/videobuf2-core.c | 20 ++--
>>  1 file changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
>> b/drivers/media/v4l2-core/videobuf2-core.c
>> index 64fce4d..c5c0707a 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -1177,7 +1177,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
>> vb2_buffer_state state)
>>  {
>>  struct vb2_queue *q = vb->vb2_queue;
>>  unsigned long flags;
>> -unsigned int plane;
>>  
>>  if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
>>  return;
>> @@ -1197,10 +1196,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
>> vb2_buffer_state state)
>>  dprintk(4, "done processing on buffer %d, state: %d\n",
>>  vb->v4l2_buf.index, state);
>>  
>> -/* sync buffers */
>> -for (plane = 0; plane < vb->num_planes; ++plane)
>> -call_void_memop(vb, finish, vb->planes[plane].mem_priv);
>> -
> 
> Ah, OK, so it is removed here,

I can merge the two patches for the next version if you prefer that.

> 
>>  /* Add the buffer to the done buffers list */
>>  spin_lock_irqsave(>done_lock, flags);
>>  vb->state = state;
>> @@ -2086,7 +2081,7 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
>>  static void __vb2_dqbuf(struct vb2_buffer *vb)
>>  {
>>  struct vb2_queue *q = vb->vb2_queue;
>> -unsigned int i;
>> +unsigned int plane;
>>  
>>  /* nothing to do if the buffer is already dequeued */
>>  if (vb->state == VB2_BUF_STATE_DEQUEUED)
>> @@ -2094,13 +2089,18 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
>>  
>>  vb->state = VB2_BUF_STATE_DEQUEUED;
>>  
>> +/* sync buffers */
>> +for (plane = 0; plane < vb->num_planes; plane++)
>> +call_void_memop(vb, finish, vb->planes[plane].mem_priv);
>> +
> 
> to here.
> 
> I'm not sure if this is correct... So __vb2_dqbuf is called from 
> __vb2_queue_cancel(),
> but now the buf_finish() callback is called *before* the memop finish() 
> callback,
> where this was the other way around in __vb2_queue_cancel(). I don't think 
> that is
> right since buf_finish() expects that the buffer is synced for the cpu.

I don't mind reordering them. The vb->state will be different as
__vb2_dqbuf() has already been called, there's at least one buffer state
check in a driver. However, __vb2_dqbuf() unconditionally sets the
buffer state to DEQUEUED, overriding e.g. ERROR which a driver would be
interested in.

I think the cache sync needs to be moved out of __vb2_dqbuf() to the
same level where it's called so proper ordering can be maintained while
still flushing cache before buf_finish() is called.

> 
> Was this tested with CONFIG_VIDEO_ADV_DEBUG set and with 'v4l2-compliance -s'?
> Not that that would help if things are done in the wrong order...

I'll do that the next time.

-- 
Regards,

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


Re: [RFC RESEND 05/11] v4l2-core: Don't sync cache for a buffer if so requested

2015-09-15 Thread Sakari Ailus
Hi Hans,

Hans Verkuil wrote:
> On 09/11/2015 01:50 PM, Sakari Ailus wrote:
>> From: Samu Onkalo 
>>
>> The user may request to the driver (vb2) to skip the cache maintenance
>> operations in case the buffer does not need cache synchronisation, e.g. in
>> cases where the buffer is passed between hardware blocks without it being
>> touched by the CPU.
>>
>> Also document that the prepare and finish vb2_mem_ops might not get called
>> every time the buffer ownership changes between the kernel and the user
>> space.
>>
>> Signed-off-by: Samu Onkalo 
>> Signed-off-by: Sakari Ailus 
>> ---
>>  drivers/media/v4l2-core/videobuf2-core.c | 52 
>> +---
>>  include/media/videobuf2-core.h   | 12 +---
>>  2 files changed, 49 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
>> b/drivers/media/v4l2-core/videobuf2-core.c
>> index c5c0707a..b664024 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -187,6 +187,28 @@ static void __vb2_queue_cancel(struct vb2_queue *q);
>>  static void __enqueue_in_driver(struct vb2_buffer *vb);
>>  
>>  /**
>> + * __mem_prepare_planes() - call finish mem op for all planes of the buffer
>> + */
>> +static void __mem_prepare_planes(struct vb2_buffer *vb)
>> +{
>> +unsigned int plane;
>> +
>> +for (plane = 0; plane < vb->num_planes; ++plane)
>> +call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
>> +}
>> +
>> +/**
>> + * __mem_finish_planes() - call finish mem op for all planes of the buffer
>> + */
>> +static void __mem_finish_planes(struct vb2_buffer *vb)
>> +{
>> +unsigned int plane;
>> +
>> +for (plane = 0; plane < vb->num_planes; ++plane)
>> +call_void_memop(vb, finish, vb->planes[plane].mem_priv);
>> +}
>> +
>> +/**
>>   * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
>>   */
>>  static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
>> @@ -1391,6 +1413,10 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
>> const struct v4l2_buffer *b
>>  static int __prepare_mmap(struct vb2_buffer *vb, const struct v4l2_buffer 
>> *b)
>>  {
>>  __fill_vb2_buffer(vb, b, vb->v4l2_planes);
>> +
>> +if (!(b->flags & V4L2_BUF_FLAG_NO_CACHE_SYNC))
>> +__mem_prepare_planes(vb);
>> +
>>  return call_vb_qop(vb, buf_prepare, vb);
>>  }
>>  
>> @@ -1476,6 +1502,11 @@ static int __prepare_userptr(struct vb2_buffer *vb,
>>  dprintk(1, "buffer initialization failed\n");
>>  goto err;
>>  }
>> +
>> +/* This is new buffer memory --- always synchronise cache. */
>> +__mem_prepare_planes(vb);
>> +} else if (!(b->flags & V4L2_BUF_FLAG_NO_CACHE_SYNC)) {
>> +__mem_prepare_planes(vb);
>>  }
>>  
>>  ret = call_vb_qop(vb, buf_prepare, vb);
>> @@ -1601,6 +1632,11 @@ static int __prepare_dmabuf(struct vb2_buffer *vb, 
>> const struct v4l2_buffer *b)
>>  dprintk(1, "buffer initialization failed\n");
>>  goto err;
>>  }
>> +
>> +/* This is new buffer memory --- always synchronise cache. */
>> +__mem_prepare_planes(vb);
>> +} else if (!(b->flags & V4L2_BUF_FLAG_NO_CACHE_SYNC)) {
>> +__mem_prepare_planes(vb);
>>  }
>>  
>>  ret = call_vb_qop(vb, buf_prepare, vb);
>> @@ -1624,7 +1660,6 @@ err:
>>  static void __enqueue_in_driver(struct vb2_buffer *vb)
>>  {
>>  struct vb2_queue *q = vb->vb2_queue;
>> -unsigned int plane;
>>  
>>  vb->state = VB2_BUF_STATE_ACTIVE;
>>  atomic_inc(>owned_by_drv_count);
>> @@ -1691,10 +1726,6 @@ static int __buf_prepare(struct vb2_buffer *vb, const 
>> struct v4l2_buffer *b)
>>  return ret;
>>  }
>>  
>> -/* sync buffers */
>> -for (plane = 0; plane < vb->num_planes; ++plane)
>> -call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
>> -
> 
> Why not keep the prepare memop call here? Why push it down into the 
> __prepare_*
> functions?

I think flushing the buffer the first time it's used is a good thing to
do regardless of what the user suggests, since it's freshly allocated
memory and there could data in the CPU write cache. Once streaming is
ongoing, the user process owns the buffer memory.

> 
> It is wrong too, since the prepare memop should be called *after* the 
> buf_prepare
> callback (buf_prepare should be allowed to touch the buffer for fixups for 
> video
> output).

This is a different matter. I'll reorder the calls.

> 
> With the begin/end_cpu_access() code from my patch series buf_prepare would 
> handle
> this correctly, but we might be doing unnecessary syncs.
> 
> The more I review this, the more I think that the first step should be to 
> take my
> begin/end_cpu_access patch series. With that in place it is at least 

Re: [RFC RESEND 05/11] v4l2-core: Don't sync cache for a buffer if so requested

2015-09-15 Thread Hans Verkuil
On 09/15/15 10:22, Sakari Ailus wrote:
> Could you rebase and re-post what's not in upstream of that set, please?

Done. Available here:

http://git.linuxtv.org/cgit.cgi/hverkuil/media_tree.git/log/?h=vb2-cpu-access

These drivers need work to replace vb2_plane_vaddr by
vb2_plane_begin/end_cpu_access():

$ git grep vb2_plane_vaddr
drivers/media/pci/netup_unidvb/netup_unidvb_core.c: u8 *p = 
vb2_plane_vaddr(>vb, 0);
drivers/media/platform/coda/coda-bit.c: n = kfifo_in(>bitstream_fifo, 
vb2_plane_vaddr(src_buf, 0),
drivers/media/platform/coda/coda-bit.c: if (vb2_plane_vaddr(src_buf, 0) == 
NULL) {
drivers/media/platform/coda/coda-bit.c: memset(vb2_plane_vaddr(buf, 0), 
0, 64);
drivers/media/platform/coda/coda-bit.c: if (((char 
*)vb2_plane_vaddr(buf, 0))[i] != 0)
drivers/media/platform/coda/coda-bit.c: memcpy(header, vb2_plane_vaddr(buf, 0), 
*size);
drivers/media/platform/coda/coda-bit.c: memcpy(vb2_plane_vaddr(dst_buf, 
0),
drivers/media/platform/coda/coda-bit.c: memcpy(vb2_plane_vaddr(dst_buf, 
0) + ctx->vpu_header_size[0],
drivers/media/platform/coda/coda-bit.c: memcpy(vb2_plane_vaddr(dst_buf, 
0) + ctx->vpu_header_size[0] +
drivers/media/platform/coda/coda-jpeg.c:void *vaddr = 
vb2_plane_vaddr(vb, 0);
drivers/media/platform/exynos4-is/fimc-capture.c:   vaddr = 
vb2_plane_vaddr(_buf->vb, plane);
drivers/media/platform/rcar_jpu.c:  void *buffer = 
vb2_plane_vaddr(vb, 0);
drivers/media/platform/rcar_jpu.c:  buffer = vb2_plane_vaddr(vb, 0);
drivers/media/usb/au0828/au0828-vbi.c:  buf->mem = vb2_plane_vaddr(vb, 0);
drivers/media/usb/au0828/au0828-video.c:outp = 
vb2_plane_vaddr(>vb, 0);
drivers/media/usb/au0828/au0828-video.c:vbioutp = 
vb2_plane_vaddr(_buf->vb, 0);
drivers/media/usb/au0828/au0828-video.c:
vbioutp = vb2_plane_vaddr(
drivers/media/usb/au0828/au0828-video.c:
outp = vb2_plane_vaddr(>vb, 0);
drivers/media/usb/au0828/au0828-video.c:buf->mem = vb2_plane_vaddr(vb, 
0);
drivers/media/usb/au0828/au0828-video.c:vid_data = 
vb2_plane_vaddr(>vb, 0);
drivers/media/usb/au0828/au0828-video.c:vbi_data = 
vb2_plane_vaddr(>vb, 0);

The coda and exynos4-is I never converted and the others are new.

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


Re: [RFC RESEND 07/11] vb2: dma-contig: Remove redundant sgt_base field

2015-09-15 Thread Sakari Ailus
Hi Hans,

Hans Verkuil wrote:
> On 09/11/2015 01:50 PM, Sakari Ailus wrote:
>> The struct vb2_dc_buf contains two struct sg_table fields: sgt_base and
>> dma_sgt. The former is used by DMA-BUF buffers whereas the latter is used
>> by USERPTR.
>>
>> Unify the two, leaving dma_sgt.
>>
>> MMAP buffers do not need cache flushing since they have been allocated
>> using dma_alloc_coherent().
> 
> I would have to see this again after it is rebased on 4.3-rc1. That will 
> contain
> Jan Kara's vb2 changes which might well affect this patch.

Ok. I'll do that.

> 
> Are there use-cases where we want to allocate non-coherent memory? I know we
> don't support this today, but is this something we might want in the future?

Yes. Not all hardware supports coherent memory access, not even on x86.
Or coherent memory (sometimes uncached!) may be slower than non-coherent
access, including the time it takes to flush the cache first.

-- 
Kind regards,

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


[PATCH v3 1/2] [media] media-device: check before unregister if mdev was registered

2015-09-15 Thread Javier Martinez Canillas
Most media functions that unregister, check if the corresponding register
function succeed before. So these functions can safely be called even if a
registration was never made or the component as already been unregistered.

Add the same check to media_device_unregister() function for consistency.

This will also allow to split the media_device_register() function in an
initialization and registration functions without the need to change the
generic cleanup functions and error code paths for all the media drivers.

Suggested-by: Sakari Ailus 
Signed-off-by: Javier Martinez Canillas 
Acked-by: Sakari Ailus 

---

Changes in v3: None
Changes in v2:
- Reword the documentation for media_device_unregister(). Suggested by Sakari.
- Added Sakari's Acked-by tag for patch #1.

 drivers/media/media-device.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1312e93ebd6e..47d09ffe6a9b 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -574,6 +574,8 @@ EXPORT_SYMBOL_GPL(__media_device_register);
  * media_device_unregister - unregister a media device
  * @mdev:  The media device
  *
+ * It is safe to call this function on an unregistered
+ * (but initialised) media device.
  */
 void media_device_unregister(struct media_device *mdev)
 {
@@ -582,6 +584,10 @@ void media_device_unregister(struct media_device *mdev)
struct media_link *link, *tmp_link;
struct media_interface *intf, *tmp_intf;
 
+   /* Check if mdev was ever registered at all */
+   if (!media_devnode_is_registered(>devnode))
+   return;
+
/* Remove interface links from the media device */
list_for_each_entry_safe(link, tmp_link, >links,
 graph_obj.list) {
-- 
2.4.3

--
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] [media] media-device: split media initialization and registration

2015-09-15 Thread Javier Martinez Canillas
The media device node is registered and so made visible to user-space
before entities are registered and links created which means that the
media graph obtained by user-space could be only partially enumerated
if that happens too early before all the graph has been created.

To avoid this race condition, split the media init and registration
in separate functions and only register the media device node when
all the pending subdevices have been registered, either explicitly
by the driver or asynchronously using v4l2_async_register_subdev().

The media_device_register() had a check for drivers not filling dev
and model fields but all drivers in mainline set them and not doing
it will be a driver bug so change the function return to void and
add a BUG_ON() instead.

Also, add a media_device_cleanup() function that will destroy the
graph_mutex that is initialized in media_device_init().

Suggested-by: Sakari Ailus 
Signed-off-by: Javier Martinez Canillas 

---

Changes in v3:
- Replace the WARN_ON() in media_device_init() for a BUG_ON().
  Suggested by Sakari Ailus.

Changes in v2:
- Change media_device_init() to return void instead of an error.
  Suggested by Sakari Ailus.
- Remove the error messages when media_device_register() fails.
  Suggested by Sakari Ailus.
- Fix typos in commit message of patch #2. Suggested by Sakari Ailus.

 drivers/media/common/siano/smsdvb-main.c  |  1 +
 drivers/media/media-device.c  | 36 ++-
 drivers/media/platform/exynos4-is/media-dev.c | 15 ++-
 drivers/media/platform/omap3isp/isp.c | 14 +--
 drivers/media/platform/s3c-camif/camif-core.c | 15 +++
 drivers/media/platform/vsp1/vsp1_drv.c| 12 -
 drivers/media/platform/xilinx/xilinx-vipp.c   | 12 +++--
 drivers/media/usb/au0828/au0828-core.c| 27 ++--
 drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +++---
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c   | 23 +
 drivers/media/usb/dvb-usb/dvb-usb-dvb.c   | 24 ++
 drivers/media/usb/siano/smsusb.c  |  5 ++--
 drivers/media/usb/uvc/uvc_driver.c| 10 +---
 include/media/media-device.h  |  2 ++
 14 files changed, 131 insertions(+), 95 deletions(-)

diff --git a/drivers/media/common/siano/smsdvb-main.c 
b/drivers/media/common/siano/smsdvb-main.c
index ab345490a43a..8a1ea2192439 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -617,6 +617,7 @@ static void smsdvb_media_device_unregister(struct 
smsdvb_client_t *client)
if (!coredev->media_dev)
return;
media_device_unregister(coredev->media_dev);
+   media_device_cleanup(coredev->media_dev);
kfree(coredev->media_dev);
coredev->media_dev = NULL;
 #endif
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 47d09ffe6a9b..9355378d9634 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -526,7 +526,7 @@ static void media_device_release(struct media_devnode *mdev)
 }
 
 /**
- * media_device_register - register a media device
+ * media_device_init() - initialize a media device
  * @mdev:  The media device
  *
  * The caller is responsible for initializing the media device before
@@ -535,13 +535,10 @@ static void media_device_release(struct media_devnode 
*mdev)
  * - dev must point to the parent device
  * - model must be filled with the device model name
  */
-int __must_check __media_device_register(struct media_device *mdev,
-struct module *owner)
+void media_device_init(struct media_device *mdev)
 {
-   int ret;
 
-   if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
-   return -EINVAL;
+   BUG_ON(mdev->dev == NULL || mdev->model[0] == 0);
 
INIT_LIST_HEAD(>entities);
INIT_LIST_HEAD(>interfaces);
@@ -550,6 +547,33 @@ int __must_check __media_device_register(struct 
media_device *mdev,
spin_lock_init(>lock);
mutex_init(>graph_mutex);
 
+   dev_dbg(mdev->dev, "Media device initialized\n");
+}
+EXPORT_SYMBOL_GPL(media_device_init);
+
+/**
+ * media_device_cleanup() - Cleanup a media device
+ * @mdev:  The media device
+ *
+ */
+void media_device_cleanup(struct media_device *mdev)
+{
+   mutex_destroy(>graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_device_cleanup);
+
+/**
+ * __media_device_register() - register a media device
+ * @mdev:  The media device
+ * @owner: The module owner
+ *
+ * returns zero on success or a negative error code.
+ */
+int __must_check __media_device_register(struct media_device *mdev,
+struct module *owner)
+{
+   int ret;
+
/* Register the device node. */
mdev->devnode.fops = _device_fops;
mdev->devnode.parent 

[PATCH v3 0/2] [media] Fix race between graph enumeration and entities registration

2015-09-15 Thread Javier Martinez Canillas
Hello,

The Media Controller framework has an issue in which the media device node
is registered before all the media entities and pads links are created so
if user-space tries to enumerate the graph too early, it may get a partial
graph since not everything has been registered yet.

This series fixes the issue by separate the media device registration from
the initialization so drives can first initialize the media device, create
the graph and then finally register the media device node once is finished.
The solution was suggested by Sakari Ailus.

This is the third version of the series that fixes issues pointed out by
Sakari Ailus. The first version was [0] and the second version was [1].

Patch #1 adds a check to the media_device_unregister() function to know if
the media device has been registed yet so calling it will be safe and the
cleanup functions of the drivers won't need to be changed in case register
failed.

Patch #2 does the init and registration split, changing all the drivers to
make the change atomic and also adds a cleanup function for media devices.

The patches are on top of Mauro's "[PATCH v8 00/55] MC next generation" [2]
but is not a dependency for that series, it was only be based on that patch
series to avoid conflicts with in-flight patches.

The patches have been tested on an OMAP3 IGEPv2 board that has a OMAP3 ISP
device and an Exynos5800 Chromebook with a built-in UVC camera.

[0]: https://lkml.org/lkml/2015/9/10/311
[1]: https://lkml.org/lkml/2015/9/14/276
[2]: http://permalink.gmane.org/gmane.linux.drivers.driver-project.devel/74515

Best regards,
Javier

Changes in v3:
- Replace the WARN_ON() in media_device_init() for a BUG_ON().
  Suggested by Sakari Ailus.

Changes in v2:
- Reword the documentation for media_device_unregister(). Suggested by Sakari.
- Added Sakari's Acked-by tag for patch #1.
- Change media_device_init() to return void instead of an error.
  Suggested by Sakari Ailus.
- Remove the error messages when media_device_register() fails.
  Suggested by Sakari Ailus.
- Fix typos in commit message of patch #2. Suggested by Sakari Ailus.

Javier Martinez Canillas (2):
  [media] media-device: check before unregister if mdev was registered
  [media] media-device: split media initialization and registration

 drivers/media/common/siano/smsdvb-main.c  |  1 +
 drivers/media/media-device.c  | 42 +++
 drivers/media/platform/exynos4-is/media-dev.c | 15 +-
 drivers/media/platform/omap3isp/isp.c | 14 -
 drivers/media/platform/s3c-camif/camif-core.c | 15 ++
 drivers/media/platform/vsp1/vsp1_drv.c| 12 
 drivers/media/platform/xilinx/xilinx-vipp.c   | 12 +++-
 drivers/media/usb/au0828/au0828-core.c| 27 +
 drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +--
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c   | 23 ---
 drivers/media/usb/dvb-usb/dvb-usb-dvb.c   | 24 ---
 drivers/media/usb/siano/smsusb.c  |  5 ++--
 drivers/media/usb/uvc/uvc_driver.c| 10 +--
 include/media/media-device.h  |  2 ++
 14 files changed, 137 insertions(+), 95 deletions(-)

-- 
2.4.3

--
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 7/7] [RFC] [media] introduce v4l2_timespec type for timestamps

2015-09-15 Thread Hans Verkuil
On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
> The v4l2 event queue uses a 'struct timespec' to pass monotonic
> timestamps. This is not a problem by itself, but it breaks when user
> space redefines timespec to use 'long long' on 32-bit systems.
> 
> To avoid that problem, we define our own replacement for timespec here,
> using 'long' tv_sec and tv_nsec members. This means no change to the
> existing API, but lets us keep using it with a y2038 compatible libc.
> 
> As a side-effect, this changes the API for x32 programs to be the same
> as native 32-bit, using a 32-bit tv_sec/tv_nsec value, but both old and
> new kernels already support both formats for on the binary level for
> compat and x32.
> 
> Alternatively, we could leave the header file to define the interface
> based on 'struct timespec', and implement both ioctls for native
> processes. I picked the approach in this case because it matches what
> we do for v4l2_timeval in the respective patch, but both would work
> equally well here.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/v4l2-core/v4l2-event.c | 20 +---
>  include/uapi/linux/videodev2.h   |  8 +++-
>  2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-event.c 
> b/drivers/media/v4l2-core/v4l2-event.c
> index 8d3171c6bee8..2a26ad591f59 100644
> --- a/drivers/media/v4l2-core/v4l2-event.c
> +++ b/drivers/media/v4l2-core/v4l2-event.c
> @@ -108,7 +108,7 @@ static struct v4l2_subscribed_event 
> *v4l2_event_subscribed(
>  }
>  
>  static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct 
> v4l2_event *ev,
> - const struct timespec *ts)
> + const struct v4l2_timespec *ts)
>  {
>   struct v4l2_subscribed_event *sev;
>   struct v4l2_kevent *kev;
> @@ -170,17 +170,20 @@ void v4l2_event_queue(struct video_device *vdev, const 
> struct v4l2_event *ev)
>  {
>   struct v4l2_fh *fh;
>   unsigned long flags;
> - struct timespec timestamp;
> + struct timespec64 timestamp;
> + struct v4l2_timespec vts;
>  
>   if (vdev == NULL)
>   return;
>  
> - ktime_get_ts();
> + ktime_get_ts64();
> + vts.tv_sec = timestamp.tv_sec;
> + vts.tv_nsec = timestamp.tv_nsec;

I prefer to take this opportunity to create a v4l2_get_timespec helper
function, just like v4l2_get_timeval.

>  
>   spin_lock_irqsave(>fh_lock, flags);
>  
>   list_for_each_entry(fh, >fh_list, list)
> - __v4l2_event_queue_fh(fh, ev, );
> + __v4l2_event_queue_fh(fh, ev, );
>  
>   spin_unlock_irqrestore(>fh_lock, flags);
>  }
> @@ -189,12 +192,15 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);
>  void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
>  {
>   unsigned long flags;
> - struct timespec timestamp;
> + struct timespec64 timestamp;
> + struct v4l2_timespec vts;
>  
> - ktime_get_ts();
> + ktime_get_ts64();
> + vts.tv_sec = timestamp.tv_sec;
> + vts.tv_nsec = timestamp.tv_nsec;
>  
>   spin_lock_irqsave(>vdev->fh_lock, flags);
> - __v4l2_event_queue_fh(fh, ev, );
> + __v4l2_event_queue_fh(fh, ev, );
>   spin_unlock_irqrestore(>vdev->fh_lock, flags);
>  }
>  EXPORT_SYMBOL_GPL(v4l2_event_queue_fh);
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index b02cf054fbb8..bc659be87260 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -809,6 +809,12 @@ struct v4l2_timeval {
>   long tv_usec;
>  };
>  
> +/* used for monotonic times, therefore y2038 safe */
> +struct v4l2_timespec {
> + long tv_sec;
> + long tv_nsec;
> +};
> +
>  /**
>   * struct v4l2_buffer - video buffer info
>   * @index:   id number of the buffer
> @@ -2088,7 +2094,7 @@ struct v4l2_event {
>   } u;
>   __u32   pending;
>   __u32   sequence;
> - struct timespec timestamp;
> + struct v4l2_timespectimestamp;
>   __u32   id;
>   __u32   reserved[8];
>  };
> 

I think I am OK with this. This timestamp is used much more rarely and I do
not expect this ABI change to cause any problems in userspace.

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


Re: [PATCH 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-15 Thread Hans Verkuil
On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
> The v4l2 API uses a 'struct timeval' to communicate time stamps to user
> space. This is broken on 32-bit architectures as soon as we have a C library
> that defines time_t as 64 bit, which then changes the structure layout of
> struct v4l2_buffer.
> 
> Fortunately, almost all v4l2 drivers use monotonic timestamps and call
> v4l2_get_timestamp(), which means they don't also have a y2038 problem.
> This means we can keep using the existing binary layout of the structure
> and do not need to worry about defining a new kernel interface for
> userland with 64-bit time_t.
> 
> A possible downside of this approach is that it breaks any user space
> that tries to assign the timeval structure returned from the kernel
> to another timeval, or to pass a pointer to it into a function that
> expects a timeval. Those will cause a build-time warning or error
> that can be fixed up in a backwards compatible way.
> 
> The alternative to this patch is to leave the structure using
> 'struct timeval', but then we have to rework the kernel to let
> it handle both 32-bit and 64-bit time_t for 32-bit user space
> processes.

Cool. Only this morning I was thinking about what would be needed in v4l2
to be y2038 safe, and here it is!

> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 3228fbebcd63..b02cf054fbb8 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -803,6 +803,12 @@ struct v4l2_plane {
>   __u32   reserved[11];
>  };
>  
> +/* used for monotonic times, therefore y2038 safe */
> +struct v4l2_timeval {
> + long tv_sec;
> + long tv_usec;
> +};
> +
>  /**
>   * struct v4l2_buffer - video buffer info
>   * @index:   id number of the buffer
> @@ -839,7 +845,7 @@ struct v4l2_buffer {
>   __u32   bytesused;
>   __u32   flags;
>   __u32   field;
> - struct timeval  timestamp;
> + struct v4l2_timeval timestamp;
>   struct v4l2_timecodetimecode;
>   __u32   sequence;
>  
> 

I suspect that quite a few apps use assign the timestamp to another timeval
struct. A quick grep in v4l-utils (which we maintain) shows at least two of
those assignments. Ditto for xawtv3.

So I don't think v4l2_timeval is an option as it would break userspace too 
badly.

An alternative to supporting a 64-bit timeval for 32-bit userspace is to make a
new y2038-aware struct and a new set of ioctls and use this opportunity to clean
up and extend the v4l2_buffer struct.

So any 32-bit app that needs to be y2038 compliant would just use the new
struct and ioctls.

But this is something to discuss among the v4l2 developers.

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 1/7] [media] dvb: use ktime_t for internal timeout

2015-09-15 Thread Arnd Bergmann
The dvb demuxer code uses a 'struct timespec' to pass a timeout
as absolute time. This will cause problems on 32-bit architectures
in 2038 when time_t overflows, and it is racy with a concurrent
settimeofday() call.

This patch changes the code to use ktime_get() instead, using
the monotonic time base to avoid both the race and the overflow.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/dvb-core/demux.h |  2 +-
 drivers/media/dvb-core/dmxdev.c|  2 +-
 drivers/media/dvb-core/dvb_demux.c | 17 ++---
 drivers/media/dvb-core/dvb_demux.h |  4 ++--
 drivers/media/dvb-core/dvb_net.c   |  2 +-
 5 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/media/dvb-core/demux.h b/drivers/media/dvb-core/demux.h
index 833191bcd810..d8e2b1213bef 100644
--- a/drivers/media/dvb-core/demux.h
+++ b/drivers/media/dvb-core/demux.h
@@ -92,7 +92,7 @@ struct dmx_ts_feed {
int type,
enum dmx_ts_pes pes_type,
size_t circular_buffer_size,
-   struct timespec timeout);
+   ktime_t timeout);
int (*start_filtering) (struct dmx_ts_feed* feed);
int (*stop_filtering) (struct dmx_ts_feed* feed);
 };
diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index d0e3f9d85f34..0d20b379eeec 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -558,7 +558,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
 struct dmxdev_filter *filter,
 struct dmxdev_feed *feed)
 {
-   struct timespec timeout = { 0 };
+   ktime_t timeout = ktime_set(0, 0);
struct dmx_pes_filter_params *para = >params.pes;
dmx_output_t otype;
int ret;
diff --git a/drivers/media/dvb-core/dvb_demux.c 
b/drivers/media/dvb-core/dvb_demux.c
index 6c7ff0cdcd32..d83dd0eb5757 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -399,28 +399,23 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux 
*demux, const u8 *buf)
int dvr_done = 0;
 
if (dvb_demux_speedcheck) {
-   struct timespec cur_time, delta_time;
+   ktime_t cur_time;
u64 speed_bytes, speed_timedelta;
 
demux->speed_pkts_cnt++;
 
/* show speed every SPEED_PKTS_INTERVAL packets */
if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) {
-   cur_time = current_kernel_time();
+   cur_time = ktime_get();
 
-   if (demux->speed_last_time.tv_sec != 0 &&
-   demux->speed_last_time.tv_nsec != 0) {
-   delta_time = timespec_sub(cur_time,
-   demux->speed_last_time);
+   if (ktime_to_ns(demux->speed_last_time) == 0) {
speed_bytes = (u64)demux->speed_pkts_cnt
* 188 * 8;
/* convert to 1024 basis */
speed_bytes = 1000 * div64_u64(speed_bytes,
1024);
-   speed_timedelta =
-   (u64)timespec_to_ns(_time);
-   speed_timedelta = div64_u64(speed_timedelta,
-   100); /* nsec -> usec */
+   speed_timedelta = ktime_ms_delta(cur_time,
+   demux->speed_last_time);
printk(KERN_INFO "TS speed %llu Kbits/sec \n",
div64_u64(speed_bytes,
speed_timedelta));
@@ -667,7 +662,7 @@ out:
 
 static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
   enum dmx_ts_pes pes_type,
-  size_t circular_buffer_size, struct timespec timeout)
+  size_t circular_buffer_size, ktime_t timeout)
 {
struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
struct dvb_demux *demux = feed->demux;
diff --git a/drivers/media/dvb-core/dvb_demux.h 
b/drivers/media/dvb-core/dvb_demux.h
index ae7fc33c3231..5ed3cab4ad28 100644
--- a/drivers/media/dvb-core/dvb_demux.h
+++ b/drivers/media/dvb-core/dvb_demux.h
@@ -83,7 +83,7 @@ struct dvb_demux_feed {
u8 *buffer;
int buffer_size;
 
-   struct timespec timeout;
+   ktime_t timeout;
struct dvb_demux_filter *filter;
 
int ts_type;
@@ -134,7 +134,7 @@ struct dvb_demux {
 
uint8_t *cnt_storage; /* for TS continuity check */
 
-   struct timespec speed_last_time; /* for TS speed check */
+   ktime_t 

[PATCH 0/7] [media] y2038 conversion for subsystem

2015-09-15 Thread Arnd Bergmann
Hi everyone,

This is a conversion of all subsystem-wide v4l2 code to avoid the
use of types based on time_t. The first five patches should all
be harmless and obvious, so they can get applied for 4.3 after
normal review.

The last two patches are marked RFC for now because their possible
impact on the user space ABI and to decide if this is the best
approach or whether we should instead introduce extra code in
the kernel to handle modified user space.

There are a few device drivers beyond this series that rely on
time_t/timeval/timespec internally, but they are all easy to fix
and can be taken care of later.

Arnd

Arnd Bergmann (7):
  [media] dvb: use ktime_t for internal timeout
  [media] dvb: remove unused systime() function
  [media] dvb: don't use 'time_t' in event ioctl
  [media] exynos4-is: use monotonic timestamps as advertized
  [media] use v4l2_get_timestamp where possible
  [RFC] [media]: v4l2: introduce v4l2_timeval
  [RFC] [media] introduce v4l2_timespec type for timestamps

 drivers/media/dvb-core/demux.h   |  2 +-
 drivers/media/dvb-core/dmxdev.c  |  2 +-
 drivers/media/dvb-core/dvb_demux.c   | 17 ++---
 drivers/media/dvb-core/dvb_demux.h   |  4 ++--
 drivers/media/dvb-core/dvb_net.c |  2 +-
 drivers/media/dvb-frontends/dibx000_common.c | 10 --
 drivers/media/dvb-frontends/dibx000_common.h |  2 --
 drivers/media/pci/bt8xx/bttv-driver.c|  7 ++-
 drivers/media/pci/cx18/cx18-mailbox.c|  2 +-
 drivers/media/pci/meye/meye.h|  2 +-
 drivers/media/pci/zoran/zoran.h  |  2 +-
 drivers/media/platform/coda/coda.h   |  2 +-
 drivers/media/platform/exynos4-is/fimc-capture.c |  8 +---
 drivers/media/platform/exynos4-is/fimc-lite.c|  7 +--
 drivers/media/platform/omap/omap_vout.c  |  4 ++--
 drivers/media/platform/omap3isp/ispstat.c|  5 ++---
 drivers/media/platform/omap3isp/ispstat.h|  2 +-
 drivers/media/platform/s3c-camif/camif-capture.c |  8 +---
 drivers/media/platform/vim2m.c   |  2 +-
 drivers/media/platform/vivid/vivid-ctrls.c   |  2 +-
 drivers/media/usb/cpia2/cpia2.h  |  2 +-
 drivers/media/usb/cpia2/cpia2_v4l.c  |  2 +-
 drivers/media/usb/gspca/gspca.c  |  6 +++---
 drivers/media/usb/usbvision/usbvision.h  |  2 +-
 drivers/media/v4l2-core/v4l2-common.c|  6 +++---
 drivers/media/v4l2-core/v4l2-event.c | 20 +---
 drivers/staging/media/omap4iss/iss_video.c   |  5 +
 include/media/v4l2-common.h  |  2 +-
 include/media/videobuf-core.h|  2 +-
 include/trace/events/v4l2.h  | 12 ++--
 include/uapi/linux/dvb/video.h   |  3 ++-
 include/uapi/linux/omap3isp.h|  2 +-
 include/uapi/linux/videodev2.h   | 16 ++--
 33 files changed, 79 insertions(+), 93 deletions(-)

-- 
2.1.0.rc2

--
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] [media] Fix race between graph enumeration and entities registration

2015-09-15 Thread Javier Martinez Canillas
Hello,

The Media Controller framework has an issue in which the media device node
is registered before all the media entities and pads links are created so
if user-space tries to enumerate the graph too early, it may get a partial
graph since not everything has been registered yet.

This series fixes the issue by separate the media device registration from
the initialization so drives can first initialize the media device, create
the graph and then finally register the media device node once is finished.
The solution was suggested by Sakari Ailus.

This is the fourth version of the series that fixes issues pointed out by
Sakari Ailus.

Patch #1 adds a check to the media_device_unregister() function to know if
the media device has been registed yet so calling it will be safe and the
cleanup functions of the drivers won't need to be changed in case register
failed.

Patch #2 does the init and registration split, changing all the drivers to
make the change atomic and also adds a cleanup function for media devices.

The patches are on top of Mauro's "[PATCH v8 00/55] MC next generation" [0]
but is not a dependency for that series, it was only be based on that patch
series to avoid conflicts with in-flight patches.

The patches have been tested on an OMAP3 IGEPv2 board that has a OMAP3 ISP
device and an Exynos5800 Chromebook with a built-in UVC camera.

[0]: http://permalink.gmane.org/gmane.linux.drivers.driver-project.devel/74515

Best regards,
Javier

Changes in v4:
- Remove the model check from BUG_ON() since shold not be fatal.
  Suggested by Sakari Ailus.

Changes in v3:
- Replace the WARN_ON() in media_device_init() for a BUG_ON().
  Suggested by Sakari Ailus.

Changes in v2:
- Reword the documentation for media_device_unregister(). Suggested by Sakari.
- Added Sakari's Acked-by tag for patch #1.
- Change media_device_init() to return void instead of an error.
  Suggested by Sakari Ailus.
- Remove the error messages when media_device_register() fails.
  Suggested by Sakari Ailus.
- Fix typos in commit message of patch #2. Suggested by Sakari Ailus.

Javier Martinez Canillas (2):
  [media] media-device: check before unregister if mdev was registered
  [media] media-device: split media initialization and registration

 drivers/media/common/siano/smsdvb-main.c  |  1 +
 drivers/media/media-device.c  | 42 +++
 drivers/media/platform/exynos4-is/media-dev.c | 15 +-
 drivers/media/platform/omap3isp/isp.c | 14 -
 drivers/media/platform/s3c-camif/camif-core.c | 15 ++
 drivers/media/platform/vsp1/vsp1_drv.c| 12 
 drivers/media/platform/xilinx/xilinx-vipp.c   | 12 +++-
 drivers/media/usb/au0828/au0828-core.c| 27 +
 drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +--
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c   | 23 ---
 drivers/media/usb/dvb-usb/dvb-usb-dvb.c   | 24 ---
 drivers/media/usb/siano/smsusb.c  |  5 ++--
 drivers/media/usb/uvc/uvc_driver.c| 10 +--
 include/media/media-device.h  |  2 ++
 14 files changed, 137 insertions(+), 95 deletions(-)

-- 
2.4.3

--
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] [media] media-device: split media initialization and registration

2015-09-15 Thread Javier Martinez Canillas
The media device node is registered and so made visible to user-space
before entities are registered and links created which means that the
media graph obtained by user-space could be only partially enumerated
if that happens too early before all the graph has been created.

To avoid this race condition, split the media init and registration
in separate functions and only register the media device node when
all the pending subdevices have been registered, either explicitly
by the driver or asynchronously using v4l2_async_register_subdev().

The media_device_register() had a check for drivers not filling dev
and model fields but all drivers in mainline set them and not doing
it will be a driver bug so change the function return to void and
add a BUG_ON() for dev being NULL instead.

Also, add a media_device_cleanup() function that will destroy the
graph_mutex that is initialized in media_device_init().

Suggested-by: Sakari Ailus 
Signed-off-by: Javier Martinez Canillas 

---

Changes in v4:
- Remove the model check from BUG_ON() since shold not be fatal.
  Suggested by Sakari Ailus.

Changes in v3:
- Replace the WARN_ON() in media_device_init() for a BUG_ON().
  Suggested by Sakari Ailus.

Changes in v2:
- Change media_device_init() to return void instead of an error.
  Suggested by Sakari Ailus.
- Remove the error messages when media_device_register() fails.
  Suggested by Sakari Ailus.
- Fix typos in commit message of patch #2. Suggested by Sakari Ailus.

 drivers/media/common/siano/smsdvb-main.c  |  1 +
 drivers/media/media-device.c  | 36 ++-
 drivers/media/platform/exynos4-is/media-dev.c | 15 ++-
 drivers/media/platform/omap3isp/isp.c | 14 +--
 drivers/media/platform/s3c-camif/camif-core.c | 15 +++
 drivers/media/platform/vsp1/vsp1_drv.c| 12 -
 drivers/media/platform/xilinx/xilinx-vipp.c   | 12 +++--
 drivers/media/usb/au0828/au0828-core.c| 27 ++--
 drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +++---
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c   | 23 +
 drivers/media/usb/dvb-usb/dvb-usb-dvb.c   | 24 ++
 drivers/media/usb/siano/smsusb.c  |  5 ++--
 drivers/media/usb/uvc/uvc_driver.c| 10 +---
 include/media/media-device.h  |  2 ++
 14 files changed, 131 insertions(+), 95 deletions(-)

diff --git a/drivers/media/common/siano/smsdvb-main.c 
b/drivers/media/common/siano/smsdvb-main.c
index ab345490a43a..8a1ea2192439 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -617,6 +617,7 @@ static void smsdvb_media_device_unregister(struct 
smsdvb_client_t *client)
if (!coredev->media_dev)
return;
media_device_unregister(coredev->media_dev);
+   media_device_cleanup(coredev->media_dev);
kfree(coredev->media_dev);
coredev->media_dev = NULL;
 #endif
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 47d09ffe6a9b..c18175801748 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -526,7 +526,7 @@ static void media_device_release(struct media_devnode *mdev)
 }
 
 /**
- * media_device_register - register a media device
+ * media_device_init() - initialize a media device
  * @mdev:  The media device
  *
  * The caller is responsible for initializing the media device before
@@ -535,13 +535,10 @@ static void media_device_release(struct media_devnode 
*mdev)
  * - dev must point to the parent device
  * - model must be filled with the device model name
  */
-int __must_check __media_device_register(struct media_device *mdev,
-struct module *owner)
+void media_device_init(struct media_device *mdev)
 {
-   int ret;
 
-   if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
-   return -EINVAL;
+   BUG_ON(mdev->dev == NULL);
 
INIT_LIST_HEAD(>entities);
INIT_LIST_HEAD(>interfaces);
@@ -550,6 +547,33 @@ int __must_check __media_device_register(struct 
media_device *mdev,
spin_lock_init(>lock);
mutex_init(>graph_mutex);
 
+   dev_dbg(mdev->dev, "Media device initialized\n");
+}
+EXPORT_SYMBOL_GPL(media_device_init);
+
+/**
+ * media_device_cleanup() - Cleanup a media device
+ * @mdev:  The media device
+ *
+ */
+void media_device_cleanup(struct media_device *mdev)
+{
+   mutex_destroy(>graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_device_cleanup);
+
+/**
+ * __media_device_register() - register a media device
+ * @mdev:  The media device
+ * @owner: The module owner
+ *
+ * returns zero on success or a negative error code.
+ */
+int __must_check __media_device_register(struct media_device *mdev,
+struct module *owner)
+{
+   int ret;
+
   

[PATCH v4 1/2] [media] media-device: check before unregister if mdev was registered

2015-09-15 Thread Javier Martinez Canillas
Most media functions that unregister, check if the corresponding register
function succeed before. So these functions can safely be called even if a
registration was never made or the component as already been unregistered.

Add the same check to media_device_unregister() function for consistency.

This will also allow to split the media_device_register() function in an
initialization and registration functions without the need to change the
generic cleanup functions and error code paths for all the media drivers.

Suggested-by: Sakari Ailus 
Signed-off-by: Javier Martinez Canillas 
Acked-by: Sakari Ailus 

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- Reword the documentation for media_device_unregister(). Suggested by Sakari.
- Added Sakari's Acked-by tag for patch #1.

 drivers/media/media-device.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1312e93ebd6e..47d09ffe6a9b 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -574,6 +574,8 @@ EXPORT_SYMBOL_GPL(__media_device_register);
  * media_device_unregister - unregister a media device
  * @mdev:  The media device
  *
+ * It is safe to call this function on an unregistered
+ * (but initialised) media device.
  */
 void media_device_unregister(struct media_device *mdev)
 {
@@ -582,6 +584,10 @@ void media_device_unregister(struct media_device *mdev)
struct media_link *link, *tmp_link;
struct media_interface *intf, *tmp_intf;
 
+   /* Check if mdev was ever registered at all */
+   if (!media_devnode_is_registered(>devnode))
+   return;
+
/* Remove interface links from the media device */
list_for_each_entry_safe(link, tmp_link, >links,
 graph_obj.list) {
-- 
2.4.3

--
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 v4 2/2] [media] media-device: split media initialization and registration

2015-09-15 Thread Sakari Ailus
Hi Javier,

Javier Martinez Canillas wrote:
> The media device node is registered and so made visible to user-space
> before entities are registered and links created which means that the
> media graph obtained by user-space could be only partially enumerated
> if that happens too early before all the graph has been created.
> 
> To avoid this race condition, split the media init and registration
> in separate functions and only register the media device node when
> all the pending subdevices have been registered, either explicitly
> by the driver or asynchronously using v4l2_async_register_subdev().
> 
> The media_device_register() had a check for drivers not filling dev
> and model fields but all drivers in mainline set them and not doing
> it will be a driver bug so change the function return to void and
> add a BUG_ON() for dev being NULL instead.
> 
> Also, add a media_device_cleanup() function that will destroy the
> graph_mutex that is initialized in media_device_init().
> 
> Suggested-by: Sakari Ailus 
> Signed-off-by: Javier Martinez Canillas 

Thanks!

For drivers/media/media-device.c, drivers/media/platform/omap3isp/isp.c
and include/media/media-device.h:

Acked-by: Sakari Ailus 

Laurent, could you ack these if you're fine with them?

They depend on Mauro's patches so they should be applied after them.

-- 
Kind regards,

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


[PATCH] [media] c8sectpfe: fix ininitialized error return on firmware load failure

2015-09-15 Thread Colin King
From: Colin Ian King 

static analysis with cppcheck detected the following error:

[drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c:1210]:
  (error) Uninitialized variable: ret

ret is never initialised, so garbage is being returned. Instead
return the error return from the call of request_firmware_nowait

Signed-off-by: Colin Ian King 
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c 
b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
index 486aef5..16aa494 100644
--- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
+++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
@@ -1192,7 +1192,6 @@ err:
 
 static int load_c8sectpfe_fw_step1(struct c8sectpfei *fei)
 {
-   int ret;
int err;
 
dev_info(fei->dev, "Loading firmware: %s\n", FIRMWARE_MEMDMA);
@@ -1207,7 +1206,7 @@ static int load_c8sectpfe_fw_step1(struct c8sectpfei *fei)
if (err) {
dev_err(fei->dev, "request_firmware_nowait err: %d.\n", err);
complete_all(>fw_ack);
-   return ret;
+   return err;
}
 
return 0;
-- 
2.5.0

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


randconfig build errors with next-20150915, in drivers/media/i2c

2015-09-15 Thread Jim Davis
Building with the attached random configuration file,

warning: (VIDEO_COBALT) selects VIDEO_ADV7511 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API)
warning: (VIDEO_COBALT) selects VIDEO_ADV7604 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API && (GPIOLIB || COMPILE_TEST))
warning: (VIDEO_COBALT) selects VIDEO_ADV7842 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API)
warning: (SND_SOC_INTEL_BYTCR_RT5640_MACH &&
SND_SOC_INTEL_CHT_BSW_RT5672_MACH && SND_SOC_INTEL_CHT_BSW_RT5645_MACH
&& SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH) selects SND_SST_IPC_ACPI
which has unmet direct dependencies (SOUND && !M68K && !UML && SND &&
SND_SOC && ACPI)
warning: (VIDEO_COBALT) selects VIDEO_ADV7511 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API)
warning: (VIDEO_COBALT) selects VIDEO_ADV7604 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API && (GPIOLIB || COMPILE_TEST))
warning: (VIDEO_COBALT) selects VIDEO_ADV7842 which has unmet direct
dependencies (MEDIA_SUPPORT && VIDEO_V4L2 && I2C &&
VIDEO_V4L2_SUBDEV_API)
warning: (SND_SOC_INTEL_BYTCR_RT5640_MACH &&
SND_SOC_INTEL_CHT_BSW_RT5672_MACH && SND_SOC_INTEL_CHT_BSW_RT5645_MACH
&& SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH) selects SND_SST_IPC_ACPI
which has unmet direct dependencies (SOUND && !M68K && !UML && SND &&
SND_SOC && ACPI)

drivers/media/i2c/adv7842.c: In function ‘adv7842_get_format’:
drivers/media/i2c/adv7842.c:2093:3: error: implicit declaration of
function ‘v4l2_subdev_get_try_format’
[-Werror=implicit-function-declaration]
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7842.c:2093:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7842.c: In function ‘adv7842_set_format’:
drivers/media/i2c/adv7842.c:2125:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7604.c: In function ‘adv76xx_get_format’:
drivers/media/i2c/adv7604.c:1878:3: error: implicit declaration of
function ‘v4l2_subdev_get_try_format’
[-Werror=implicit-function-declaration]
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7604.c:1878:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7604.c: In function ‘adv76xx_set_format’:
drivers/media/i2c/adv7604.c:1907:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^

drivers/media/i2c/adv7511.c: In function ‘adv7511_get_fmt’:
drivers/media/i2c/adv7511.c:968:3: error: implicit declaration of
function ‘v4l2_subdev_get_try_format’
[-Werror=implicit-function-declaration]
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7511.c:968:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7511.c: In function ‘adv7511_set_fmt’:
drivers/media/i2c/adv7511.c:1021:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^

cc1: some warnings being treated as errors

drivers/media/i2c/adv7511.c: In function ‘adv7511_get_fmt’:
drivers/media/i2c/adv7511.c:968:3: error: implicit declaration of
function ‘v4l2_subdev_get_try_format’
[-Werror=implicit-function-declaration]
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7511.c:968:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^
drivers/media/i2c/adv7511.c: In function ‘adv7511_set_fmt’:
drivers/media/i2c/adv7511.c:1021:7: warning: assignment makes pointer
from integer without a cast
   fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
   ^

-- 
Jim
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 4.3.0-rc1 Kernel Configuration
#
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_PERF_EVENTS_INTEL_UNCORE=y
CONFIG_OUTPUT_FORMAT="elf64-x86-64"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_HAVE_LATENCYTOP_SUPPORT=y
CONFIG_MMU=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_ARCH_HAS_CPU_RELAX=y
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
CONFIG_HAVE_SETUP_PER_CPU_AREA=y
CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y

[PATCH 4/7] [media] exynos4-is: use monotonic timestamps as advertized

2015-09-15 Thread Arnd Bergmann
The exynos4 fimc capture driver claims to use monotonic
timestamps but calls ktime_get_real_ts(). This is both
an incorrect API use, and a bad idea because of the y2038
problem and the fact that the wall clock time is not reliable
for timestamps across suspend or settimeofday().

This changes the driver to use the normal v4l2_get_timestamp()
function like all other drivers.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/platform/exynos4-is/fimc-capture.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c 
b/drivers/media/platform/exynos4-is/fimc-capture.c
index cfebf292e15a..776ea6d78d03 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -183,8 +183,6 @@ void fimc_capture_irq_handler(struct fimc_dev *fimc, int 
deq_buf)
struct v4l2_subdev *csis = p->subdevs[IDX_CSIS];
struct fimc_frame *f = >ctx->d_frame;
struct fimc_vid_buffer *v_buf;
-   struct timeval *tv;
-   struct timespec ts;
 
if (test_and_clear_bit(ST_CAPT_SHUT, >state)) {
wake_up(>irq_queue);
@@ -193,13 +191,9 @@ void fimc_capture_irq_handler(struct fimc_dev *fimc, int 
deq_buf)
 
if (!list_empty(>active_buf_q) &&
test_bit(ST_CAPT_RUN, >state) && deq_buf) {
-   ktime_get_real_ts();
-
v_buf = fimc_active_queue_pop(cap);
 
-   tv = _buf->vb.v4l2_buf.timestamp;
-   tv->tv_sec = ts.tv_sec;
-   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+   v4l2_get_timestamp(_buf->vb.v4l2_buf.timestamp);
v_buf->vb.v4l2_buf.sequence = cap->frame_count++;
 
vb2_buffer_done(_buf->vb, VB2_BUF_STATE_DONE);
-- 
2.1.0.rc2

--
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/7] [media] dvb: don't use 'time_t' in event ioctl

2015-09-15 Thread Arnd Bergmann
'struct video_event' is used for the VIDEO_GET_EVENT ioctl, implemented
by drivers/media/pci/ivtv/ivtv-ioctl.c and
drivers/media/pci/ttpci/av7110_av.c. The structure contains a 'time_t',
which will be redefined in the future to be 64-bit wide, causing an
incompatible ABI change for this ioctl.

As it turns out, neither of the drivers currently sets the timestamp
field, and it is presumably useless anyway because of the limited
resolutions (no sub-second times). This means we can simply change
the structure definition to use a 'long' instead of 'time_t' and
remain compatible with all existing user space binaries when time_t
gets changed.

If anybody ever starts using this field, they have to make sure not
to use 1970 based seconds in there, as those overflow in 2038.

Signed-off-by: Arnd Bergmann 
---
 include/uapi/linux/dvb/video.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/dvb/video.h b/include/uapi/linux/dvb/video.h
index d3d14a59d2d5..6c7f9298d7c2 100644
--- a/include/uapi/linux/dvb/video.h
+++ b/include/uapi/linux/dvb/video.h
@@ -135,7 +135,8 @@ struct video_event {
 #define VIDEO_EVENT_FRAME_RATE_CHANGED 2
 #define VIDEO_EVENT_DECODER_STOPPED3
 #define VIDEO_EVENT_VSYNC  4
-   __kernel_time_t timestamp;
+   /* unused, make sure to use atomic time for y2038 if it ever gets used 
*/
+   long timestamp;
union {
video_size_t size;
unsigned int frame_rate;/* in frames per 1000sec */
-- 
2.1.0.rc2

--
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 2/7] [media] dvb: remove unused systime() function

2015-09-15 Thread Arnd Bergmann
The systime function uses struct timespec, which we want to stop
using in the kernel because it overflows in 2038. Fortunately,
this use in dibx000_common is in a function that is never called,
so we can just remove it.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/dvb-frontends/dibx000_common.c | 10 --
 drivers/media/dvb-frontends/dibx000_common.h |  2 --
 2 files changed, 12 deletions(-)

diff --git a/drivers/media/dvb-frontends/dibx000_common.c 
b/drivers/media/dvb-frontends/dibx000_common.c
index 43be7238311e..79cb007b401f 100644
--- a/drivers/media/dvb-frontends/dibx000_common.c
+++ b/drivers/media/dvb-frontends/dibx000_common.c
@@ -500,16 +500,6 @@ void dibx000_exit_i2c_master(struct dibx000_i2c_master 
*mst)
 }
 EXPORT_SYMBOL(dibx000_exit_i2c_master);
 
-
-u32 systime(void)
-{
-   struct timespec t;
-
-   t = current_kernel_time();
-   return (t.tv_sec * 1) + (t.tv_nsec / 10);
-}
-EXPORT_SYMBOL(systime);
-
 MODULE_AUTHOR("Patrick Boettcher ");
 MODULE_DESCRIPTION("Common function the DiBcom demodulator family");
 MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/dibx000_common.h 
b/drivers/media/dvb-frontends/dibx000_common.h
index b538e0555c95..61f4152f24ee 100644
--- a/drivers/media/dvb-frontends/dibx000_common.h
+++ b/drivers/media/dvb-frontends/dibx000_common.h
@@ -47,8 +47,6 @@ extern void dibx000_exit_i2c_master(struct dibx000_i2c_master 
*mst);
 extern void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst);
 extern int dibx000_i2c_set_speed(struct i2c_adapter *i2c_adap, u16 speed);
 
-extern u32 systime(void);
-
 #define BAND_LBAND 0x01
 #define BAND_UHF   0x02
 #define BAND_VHF   0x04
-- 
2.1.0.rc2

--
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 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-15 Thread Arnd Bergmann
The v4l2 API uses a 'struct timeval' to communicate time stamps to user
space. This is broken on 32-bit architectures as soon as we have a C library
that defines time_t as 64 bit, which then changes the structure layout of
struct v4l2_buffer.

Fortunately, almost all v4l2 drivers use monotonic timestamps and call
v4l2_get_timestamp(), which means they don't also have a y2038 problem.
This means we can keep using the existing binary layout of the structure
and do not need to worry about defining a new kernel interface for
userland with 64-bit time_t.

A possible downside of this approach is that it breaks any user space
that tries to assign the timeval structure returned from the kernel
to another timeval, or to pass a pointer to it into a function that
expects a timeval. Those will cause a build-time warning or error
that can be fixed up in a backwards compatible way.

The alternative to this patch is to leave the structure using
'struct timeval', but then we have to rework the kernel to let
it handle both 32-bit and 64-bit time_t for 32-bit user space
processes.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/pci/bt8xx/bttv-driver.c  |  2 +-
 drivers/media/pci/meye/meye.h  |  2 +-
 drivers/media/pci/zoran/zoran.h|  2 +-
 drivers/media/platform/coda/coda.h |  2 +-
 drivers/media/platform/omap/omap_vout.c|  4 ++--
 drivers/media/platform/omap3isp/ispstat.h  |  2 +-
 drivers/media/platform/vim2m.c |  2 +-
 drivers/media/platform/vivid/vivid-ctrls.c |  2 +-
 drivers/media/usb/cpia2/cpia2.h|  2 +-
 drivers/media/usb/cpia2/cpia2_v4l.c|  2 +-
 drivers/media/usb/gspca/gspca.c|  2 +-
 drivers/media/usb/usbvision/usbvision.h|  2 +-
 drivers/media/v4l2-core/v4l2-common.c  |  6 +++---
 include/media/v4l2-common.h|  2 +-
 include/media/videobuf-core.h  |  2 +-
 include/trace/events/v4l2.h| 12 ++--
 include/uapi/linux/omap3isp.h  |  2 +-
 include/uapi/linux/videodev2.h |  8 +++-
 18 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/drivers/media/pci/bt8xx/bttv-driver.c 
b/drivers/media/pci/bt8xx/bttv-driver.c
index 15a4ebc2844d..b0ed8d799c14 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -3585,7 +3585,7 @@ static void
 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
  struct bttv_buffer_set *curr, unsigned int state)
 {
-   struct timeval ts;
+   struct v4l2_timeval ts;
 
v4l2_get_timestamp();
 
diff --git a/drivers/media/pci/meye/meye.h b/drivers/media/pci/meye/meye.h
index 751be5e533c7..a06aa5ba9abc 100644
--- a/drivers/media/pci/meye/meye.h
+++ b/drivers/media/pci/meye/meye.h
@@ -281,7 +281,7 @@
 struct meye_grab_buffer {
int state;  /* state of buffer */
unsigned long size; /* size of jpg frame */
-   struct timeval timestamp;   /* timestamp */
+   struct v4l2_timeval timestamp;  /* timestamp */
unsigned long sequence; /* sequence number */
 };
 
diff --git a/drivers/media/pci/zoran/zoran.h b/drivers/media/pci/zoran/zoran.h
index 4e7db8939c2b..9a9f782cede9 100644
--- a/drivers/media/pci/zoran/zoran.h
+++ b/drivers/media/pci/zoran/zoran.h
@@ -39,7 +39,7 @@ struct zoran_sync {
unsigned long frame;/* number of buffer that has been free'd */
unsigned long length;   /* number of code bytes in buffer (capture 
only) */
unsigned long seq;  /* frame sequence number */
-   struct timeval timestamp;   /* timestamp */
+   struct v4l2_timeval timestamp;  /* timestamp */
 };
 
 
diff --git a/drivers/media/platform/coda/coda.h 
b/drivers/media/platform/coda/coda.h
index 59b2af9c7749..fa1e15a757cd 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -138,7 +138,7 @@ struct coda_buffer_meta {
struct list_headlist;
u32 sequence;
struct v4l2_timecodetimecode;
-   struct timeval  timestamp;
+   struct v4l2_timeval timestamp;
u32 start;
u32 end;
 };
diff --git a/drivers/media/platform/omap/omap_vout.c 
b/drivers/media/platform/omap/omap_vout.c
index 70c28d19ea04..974a238a86fe 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -513,7 +513,7 @@ static int omapvid_apply_changes(struct omap_vout_device 
*vout)
 }
 
 static int omapvid_handle_interlace_display(struct omap_vout_device *vout,
-   unsigned int irqstatus, struct timeval timevalue)
+   unsigned int irqstatus, struct v4l2_timeval timevalue)
 {
u32 fid;
 
@@ -557,7 +557,7 @@ static void omap_vout_isr(void *arg, unsigned int irqstatus)
int ret, fid, mgr_id;
u32 addr, irq;
struct 

[PATCH 5/7] [media] use v4l2_get_timestamp where possible

2015-09-15 Thread Arnd Bergmann
This is a preparation for a change to the type of v4l2 timestamps.
v4l2_get_timestamp() is a helper function that reads the monotonic
time and stores it into a 'struct timeval'. Multiple drivers implement
the same thing themselves for historic reasons.

Changing them all to use v4l2_get_timestamp() is more consistent
and reduces the amount of code duplication, and most importantly
simplifies the following changes.

If desired, this patch can easily be split up into one patch per
driver.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/pci/bt8xx/bttv-driver.c| 5 +
 drivers/media/pci/cx18/cx18-mailbox.c| 2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c| 7 +--
 drivers/media/platform/omap3isp/ispstat.c| 5 ++---
 drivers/media/platform/omap3isp/ispstat.h| 2 +-
 drivers/media/platform/s3c-camif/camif-capture.c | 8 +---
 drivers/media/usb/gspca/gspca.c  | 4 ++--
 drivers/staging/media/omap4iss/iss_video.c   | 5 +
 8 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/drivers/media/pci/bt8xx/bttv-driver.c 
b/drivers/media/pci/bt8xx/bttv-driver.c
index 3632958f2158..15a4ebc2844d 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -3625,13 +3625,10 @@ static void
 bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
unsigned int state)
 {
-   struct timeval ts;
-
if (NULL == wakeup)
return;
 
-   v4l2_get_timestamp();
-   wakeup->vb.ts = ts;
+   v4l2_get_timestamp(>vb.ts);
wakeup->vb.field_count = btv->field_count;
wakeup->vb.state = state;
wake_up(>vb.done);
diff --git a/drivers/media/pci/cx18/cx18-mailbox.c 
b/drivers/media/pci/cx18/cx18-mailbox.c
index eabf00c6351b..1f8aa9a749a1 100644
--- a/drivers/media/pci/cx18/cx18-mailbox.c
+++ b/drivers/media/pci/cx18/cx18-mailbox.c
@@ -202,7 +202,7 @@ static void cx18_mdl_send_to_videobuf(struct cx18_stream *s,
}
 
if (dispatch) {
-   vb_buf->vb.ts = ktime_to_timeval(ktime_get());
+   v4l2_get_timestamp(_buf->vb.ts);
list_del(_buf->vb.queue);
vb_buf->vb.state = VIDEOBUF_DONE;
wake_up(_buf->vb.done);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c 
b/drivers/media/platform/exynos4-is/fimc-lite.c
index ca6261a86a5f..459bc65b545d 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -254,8 +254,6 @@ static irqreturn_t flite_irq_handler(int irq, void *priv)
struct fimc_lite *fimc = priv;
struct flite_buffer *vbuf;
unsigned long flags;
-   struct timeval *tv;
-   struct timespec ts;
u32 intsrc;
 
spin_lock_irqsave(>slock, flags);
@@ -294,10 +292,7 @@ static irqreturn_t flite_irq_handler(int irq, void *priv)
test_bit(ST_FLITE_RUN, >state) &&
!list_empty(>active_buf_q)) {
vbuf = fimc_lite_active_queue_pop(fimc);
-   ktime_get_ts();
-   tv = >vb.v4l2_buf.timestamp;
-   tv->tv_sec = ts.tv_sec;
-   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+   v4l2_get_timestamp(>vb.v4l2_buf.timestamp);
vbuf->vb.v4l2_buf.sequence = fimc->frame_count++;
flite_hw_mask_dma_buffer(fimc, vbuf->index);
vb2_buffer_done(>vb, VB2_BUF_STATE_DONE);
diff --git a/drivers/media/platform/omap3isp/ispstat.c 
b/drivers/media/platform/omap3isp/ispstat.c
index 20434e83e801..94d4c295d3d0 100644
--- a/drivers/media/platform/omap3isp/ispstat.c
+++ b/drivers/media/platform/omap3isp/ispstat.c
@@ -235,7 +235,7 @@ static int isp_stat_buf_queue(struct ispstat *stat)
if (!stat->active_buf)
return STAT_NO_BUF;
 
-   ktime_get_ts(>active_buf->ts);
+   v4l2_get_timestamp(>active_buf->ts);
 
stat->active_buf->buf_size = stat->buf_size;
if (isp_stat_buf_check_magic(stat, stat->active_buf)) {
@@ -496,8 +496,7 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
return PTR_ERR(buf);
}
 
-   data->ts.tv_sec = buf->ts.tv_sec;
-   data->ts.tv_usec = buf->ts.tv_nsec / NSEC_PER_USEC;
+   data->ts = buf->ts;
data->config_counter = buf->config_counter;
data->frame_number = buf->frame_number;
data->buf_size = buf->buf_size;
diff --git a/drivers/media/platform/omap3isp/ispstat.h 
b/drivers/media/platform/omap3isp/ispstat.h
index b79380d83fcf..6d9b0244f320 100644
--- a/drivers/media/platform/omap3isp/ispstat.h
+++ b/drivers/media/platform/omap3isp/ispstat.h
@@ -39,7 +39,7 @@ struct ispstat_buffer {
struct sg_table sgt;
void *virt_addr;
dma_addr_t dma_addr;
-   struct timespec ts;
+   struct timeval ts;
u32 buf_size;
u32 frame_number;
u16 config_counter;
diff --git 

[PATCH 7/7] [RFC] [media] introduce v4l2_timespec type for timestamps

2015-09-15 Thread Arnd Bergmann
The v4l2 event queue uses a 'struct timespec' to pass monotonic
timestamps. This is not a problem by itself, but it breaks when user
space redefines timespec to use 'long long' on 32-bit systems.

To avoid that problem, we define our own replacement for timespec here,
using 'long' tv_sec and tv_nsec members. This means no change to the
existing API, but lets us keep using it with a y2038 compatible libc.

As a side-effect, this changes the API for x32 programs to be the same
as native 32-bit, using a 32-bit tv_sec/tv_nsec value, but both old and
new kernels already support both formats for on the binary level for
compat and x32.

Alternatively, we could leave the header file to define the interface
based on 'struct timespec', and implement both ioctls for native
processes. I picked the approach in this case because it matches what
we do for v4l2_timeval in the respective patch, but both would work
equally well here.

Signed-off-by: Arnd Bergmann 
---
 drivers/media/v4l2-core/v4l2-event.c | 20 +---
 include/uapi/linux/videodev2.h   |  8 +++-
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-event.c 
b/drivers/media/v4l2-core/v4l2-event.c
index 8d3171c6bee8..2a26ad591f59 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -108,7 +108,7 @@ static struct v4l2_subscribed_event *v4l2_event_subscribed(
 }
 
 static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event 
*ev,
-   const struct timespec *ts)
+   const struct v4l2_timespec *ts)
 {
struct v4l2_subscribed_event *sev;
struct v4l2_kevent *kev;
@@ -170,17 +170,20 @@ void v4l2_event_queue(struct video_device *vdev, const 
struct v4l2_event *ev)
 {
struct v4l2_fh *fh;
unsigned long flags;
-   struct timespec timestamp;
+   struct timespec64 timestamp;
+   struct v4l2_timespec vts;
 
if (vdev == NULL)
return;
 
-   ktime_get_ts();
+   ktime_get_ts64();
+   vts.tv_sec = timestamp.tv_sec;
+   vts.tv_nsec = timestamp.tv_nsec;
 
spin_lock_irqsave(>fh_lock, flags);
 
list_for_each_entry(fh, >fh_list, list)
-   __v4l2_event_queue_fh(fh, ev, );
+   __v4l2_event_queue_fh(fh, ev, );
 
spin_unlock_irqrestore(>fh_lock, flags);
 }
@@ -189,12 +192,15 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);
 void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
 {
unsigned long flags;
-   struct timespec timestamp;
+   struct timespec64 timestamp;
+   struct v4l2_timespec vts;
 
-   ktime_get_ts();
+   ktime_get_ts64();
+   vts.tv_sec = timestamp.tv_sec;
+   vts.tv_nsec = timestamp.tv_nsec;
 
spin_lock_irqsave(>vdev->fh_lock, flags);
-   __v4l2_event_queue_fh(fh, ev, );
+   __v4l2_event_queue_fh(fh, ev, );
spin_unlock_irqrestore(>vdev->fh_lock, flags);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_queue_fh);
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index b02cf054fbb8..bc659be87260 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -809,6 +809,12 @@ struct v4l2_timeval {
long tv_usec;
 };
 
+/* used for monotonic times, therefore y2038 safe */
+struct v4l2_timespec {
+   long tv_sec;
+   long tv_nsec;
+};
+
 /**
  * struct v4l2_buffer - video buffer info
  * @index: id number of the buffer
@@ -2088,7 +2094,7 @@ struct v4l2_event {
} u;
__u32   pending;
__u32   sequence;
-   struct timespec timestamp;
+   struct v4l2_timespectimestamp;
__u32   id;
__u32   reserved[8];
 };
-- 
2.1.0.rc2

--
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 1/7] [media] dvb: use ktime_t for internal timeout

2015-09-15 Thread Andreas Oberritter
Hello Arnd,

On 15.09.2015 17:49, Arnd Bergmann wrote:
> The dvb demuxer code uses a 'struct timespec' to pass a timeout
> as absolute time. This will cause problems on 32-bit architectures
> in 2038 when time_t overflows, and it is racy with a concurrent
> settimeofday() call.
> 
> This patch changes the code to use ktime_get() instead, using
> the monotonic time base to avoid both the race and the overflow.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/dvb-core/demux.h |  2 +-
>  drivers/media/dvb-core/dmxdev.c|  2 +-
>  drivers/media/dvb-core/dvb_demux.c | 17 ++---
>  drivers/media/dvb-core/dvb_demux.h |  4 ++--
>  drivers/media/dvb-core/dvb_net.c   |  2 +-
>  5 files changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/demux.h b/drivers/media/dvb-core/demux.h
> index 833191bcd810..d8e2b1213bef 100644
> --- a/drivers/media/dvb-core/demux.h
> +++ b/drivers/media/dvb-core/demux.h
> @@ -92,7 +92,7 @@ struct dmx_ts_feed {
>   int type,
>   enum dmx_ts_pes pes_type,
>   size_t circular_buffer_size,
> - struct timespec timeout);
> + ktime_t timeout);
>   int (*start_filtering) (struct dmx_ts_feed* feed);
>   int (*stop_filtering) (struct dmx_ts_feed* feed);
>  };
> diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
> index d0e3f9d85f34..0d20b379eeec 100644
> --- a/drivers/media/dvb-core/dmxdev.c
> +++ b/drivers/media/dvb-core/dmxdev.c
> @@ -558,7 +558,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
>struct dmxdev_filter *filter,
>struct dmxdev_feed *feed)
>  {
> - struct timespec timeout = { 0 };
> + ktime_t timeout = ktime_set(0, 0);
>   struct dmx_pes_filter_params *para = >params.pes;
>   dmx_output_t otype;
>   int ret;
> diff --git a/drivers/media/dvb-core/dvb_demux.c 
> b/drivers/media/dvb-core/dvb_demux.c
> index 6c7ff0cdcd32..d83dd0eb5757 100644
> --- a/drivers/media/dvb-core/dvb_demux.c
> +++ b/drivers/media/dvb-core/dvb_demux.c
> @@ -399,28 +399,23 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux 
> *demux, const u8 *buf)
>   int dvr_done = 0;
>  
>   if (dvb_demux_speedcheck) {
> - struct timespec cur_time, delta_time;
> + ktime_t cur_time;
>   u64 speed_bytes, speed_timedelta;
>  
>   demux->speed_pkts_cnt++;
>  
>   /* show speed every SPEED_PKTS_INTERVAL packets */
>   if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) {
> - cur_time = current_kernel_time();
> + cur_time = ktime_get();
>  
> - if (demux->speed_last_time.tv_sec != 0 &&
> - demux->speed_last_time.tv_nsec != 0) {
> - delta_time = timespec_sub(cur_time,
> - demux->speed_last_time);
> + if (ktime_to_ns(demux->speed_last_time) == 0) {

if ktime_to_ns does what I think it does, then you should invert the logic.

Regards,
Andreas

>   speed_bytes = (u64)demux->speed_pkts_cnt
>   * 188 * 8;
>   /* convert to 1024 basis */
>   speed_bytes = 1000 * div64_u64(speed_bytes,
>   1024);
> - speed_timedelta =
> - (u64)timespec_to_ns(_time);
> - speed_timedelta = div64_u64(speed_timedelta,
> - 100); /* nsec -> usec */
> + speed_timedelta = ktime_ms_delta(cur_time,
> + demux->speed_last_time);
>   printk(KERN_INFO "TS speed %llu Kbits/sec \n",
>   div64_u64(speed_bytes,
>   speed_timedelta));
> @@ -667,7 +662,7 @@ out:
>  
>  static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
>  enum dmx_ts_pes pes_type,
> -size_t circular_buffer_size, struct timespec timeout)
> +size_t circular_buffer_size, ktime_t timeout)
>  {
>   struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
>   struct dvb_demux *demux = feed->demux;
> diff --git a/drivers/media/dvb-core/dvb_demux.h 
> b/drivers/media/dvb-core/dvb_demux.h
> index ae7fc33c3231..5ed3cab4ad28 100644
> --- a/drivers/media/dvb-core/dvb_demux.h
> +++ b/drivers/media/dvb-core/dvb_demux.h
> @@ -83,7 +83,7 @@ struct dvb_demux_feed {
>   u8 *buffer;
>   int buffer_size;
>  
> - struct timespec timeout;
> + ktime_t timeout;
>   

Re: [Y2038] [PATCH 1/7] [media] dvb: use ktime_t for internal timeout

2015-09-15 Thread Arnd Bergmann
On Tuesday 15 September 2015 19:55:35 Andreas Oberritter wrote:

> > /* show speed every SPEED_PKTS_INTERVAL packets */
> > if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) {
> > -   cur_time = current_kernel_time();
> > +   cur_time = ktime_get();
> >  
> > -   if (demux->speed_last_time.tv_sec != 0 &&
> > -   demux->speed_last_time.tv_nsec != 0) {
> > -   delta_time = timespec_sub(cur_time,
> > -   demux->speed_last_time);
> > +   if (ktime_to_ns(demux->speed_last_time) == 0) {
> 
> if ktime_to_ns does what I think it does, then you should invert the logic.

Thanks for taking a critical look here, you are absolutely right, and I've
now fixed it.

Arnd
--
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 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-15 Thread Arnd Bergmann
On Tuesday 15 September 2015 18:27:19 Hans Verkuil wrote:
> On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
> > The v4l2 API uses a 'struct timeval' to communicate time stamps to user
> > space. This is broken on 32-bit architectures as soon as we have a C library
> > that defines time_t as 64 bit, which then changes the structure layout of
> > struct v4l2_buffer.
> > 
> > Fortunately, almost all v4l2 drivers use monotonic timestamps and call
> > v4l2_get_timestamp(), which means they don't also have a y2038 problem.
> > This means we can keep using the existing binary layout of the structure
> > and do not need to worry about defining a new kernel interface for
> > userland with 64-bit time_t.
> > 
> > A possible downside of this approach is that it breaks any user space
> > that tries to assign the timeval structure returned from the kernel
> > to another timeval, or to pass a pointer to it into a function that
> > expects a timeval. Those will cause a build-time warning or error
> > that can be fixed up in a backwards compatible way.
> > 
> > The alternative to this patch is to leave the structure using
> > 'struct timeval', but then we have to rework the kernel to let
> > it handle both 32-bit and 64-bit time_t for 32-bit user space
> > processes.
> 
> Cool. Only this morning I was thinking about what would be needed in v4l2
> to be y2038 safe, and here it is!

Nice!

fwiw, I also have a list of drivers at
https://docs.google.com/spreadsheets/d/1HCYwHXxs48TsTb6IGUduNjQnmfRvMPzCN6T_0YiQwis/edit?usp=sharing
which lists all known files that still need changing, in case you are
wondering what else needs to be done, though it currently only covers
things that nobody so far has started working on, and I have a couple
patches on my disk that need polishing (I pushed out the v4l2 portion
of that as a start)

> > @@ -839,7 +845,7 @@ struct v4l2_buffer {
> > __u32   bytesused;
> > __u32   flags;
> > __u32   field;
> > -   struct timeval  timestamp;
> > +   struct v4l2_timeval timestamp;
> > struct v4l2_timecodetimecode;
> > __u32   sequence;
> >  
> > 
> 
> I suspect that quite a few apps use assign the timestamp to another timeval
> struct. A quick grep in v4l-utils (which we maintain) shows at least two of
> those assignments. Ditto for xawtv3.

Ok, that is very helpful information, thanks for finding that!

> So I don't think v4l2_timeval is an option as it would break userspace too 
> badly.

Agreed, we definitely don't want to break building user space with
existing environments, i.e. 64-bit architectures, or 32-bit architectures
with 32-bit time_t.

> An alternative to supporting a 64-bit timeval for 32-bit userspace is to make 
> a
> new y2038-aware struct and a new set of ioctls and use this opportunity to 
> clean
> up and extend the v4l2_buffer struct.
> 
> So any 32-bit app that needs to be y2038 compliant would just use the new
> struct and ioctls.
> 
> But this is something to discuss among the v4l2 developers.

Ok. We generally to require as few source level changes to user space
as possible for the conversion, and we want to make sure that when
using a 32-bit libc with 64-bit time_t, we don't accidentally get
broken interfaces (i.e. we should get a compile error whenever we
can't get it right automatically).

One aspect that makes v4l2_buffer special is that the binary format
is already clean for y2038 (once patch 4/7 "exynos4-is: use monotonic
timestamps as advertized" gets merged), and we only need to worry about
what happens when user space disagrees about the size of timeval.

Let me describe the options that I can think of here:

a) Similar to my first attempt, define a new struct v4l2_timeval, but
   only use it when building with a y2038-aware libc, so we don't break
   existing environments:

/* some compile-time conditional that we first need to agree on with 
libc */
#if __BITS_PER_TIME_T > __BITS_PER_LONG
struct v4l2_timeval { long tv_sec; long tv_usec; }
#else
#define v4l2_timeval timeval
#endif

   This means that any user space that currently assumes the timestamp
   member to be a 'struct timeval' has to be changed to access the members
   individually, or get a build error.
   The __BITS_PER_TIME_T trick has to be used in a couple of other subsystems
   too, as some of them have no other way to identify an interface

b) Keep the header file unchanged, but deal with both formats of v4l2_buffer
   in the kernel. Fortunately, all ioctls that pass a v4l2_buffer have
   properly defined command codes, and it does not get passed using a
   read/write style interface. This means we move the v4l2_buffer32
   handling from v4l2-compat-ioctl32.c to v4l2-ioctl.c and add an in-kernel
   v4l2_buffer64 that matches the 64-bit variant of v4l2_buffer.
   This way, user space can use either definition of time_t, and the
   kernel will just handle them 

Re: [Y2038] [PATCH 7/7] [RFC] [media] introduce v4l2_timespec type for timestamps

2015-09-15 Thread Arnd Bergmann
On Tuesday 15 September 2015 18:32:36 Hans Verkuil wrote:
> >  
> > - ktime_get_ts();
> > + ktime_get_ts64();
> > + vts.tv_sec = timestamp.tv_sec;
> > + vts.tv_nsec = timestamp.tv_nsec;
> 
> I prefer to take this opportunity to create a v4l2_get_timespec helper
> function, just like v4l2_get_timeval.

Ok, good idea. I'll do that once we have agreed on the ABI.

> > @@ -2088,7 +2094,7 @@ struct v4l2_event {
> >   } u;
> >   __u32   pending;
> >   __u32   sequence;
> > - struct timespec timestamp;
> > + struct v4l2_timespectimestamp;
> >   __u32   id;
> >   __u32   reserved[8];
> >  };
> > 
> 
> I think I am OK with this. This timestamp is used much more rarely and I do
> not expect this ABI change to cause any problems in userspace.

I'd still wait the outcome of the v4l2_timeval discussion though. It may
be useful for consistency to pick the same approach for both structures.

Arnd
--
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: fix kernel-doc warnings in v4l2-dv-timings.h

2015-09-15 Thread Geliang Tang
Fix the following 'make htmldocs' warnings:

  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'frame_height'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'hfreq'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'vsync'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'active_width'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'polarities'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'interlaced'
  .//include/media/v4l2-dv-timings.h:147: warning: No description found for 
parameter 'fmt'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'frame_height'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'hfreq'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'vsync'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'polarities'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'interlaced'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'aspect'
  .//include/media/v4l2-dv-timings.h:171: warning: No description found for 
parameter 'fmt'
  .//include/media/v4l2-dv-timings.h:184: warning: No description found for 
parameter 'hor_landscape'
  .//include/media/v4l2-dv-timings.h:184: warning: No description found for 
parameter 'vert_portrait'

Signed-off-by: Geliang Tang 
---
 include/media/v4l2-dv-timings.h | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/media/v4l2-dv-timings.h b/include/media/v4l2-dv-timings.h
index b6130b5..9c7147b 100644
--- a/include/media/v4l2-dv-timings.h
+++ b/include/media/v4l2-dv-timings.h
@@ -127,16 +127,16 @@ void v4l2_print_dv_timings(const char *dev_prefix, const 
char *prefix,
 /**
  * v4l2_detect_cvt - detect if the given timings follow the CVT standard
  *
- * @frame_height - the total height of the frame (including blanking) in lines.
- * @hfreq - the horizontal frequency in Hz.
- * @vsync - the height of the vertical sync in lines.
- * @active_width - active width of image (does not include blanking). This
+ * @frame_height: the total height of the frame (including blanking) in lines.
+ * @hfreq: the horizontal frequency in Hz.
+ * @vsync: the height of the vertical sync in lines.
+ * @active_width: active width of image (does not include blanking). This
  * information is needed only in case of version 2 of reduced blanking.
  * In other cases, this parameter does not have any effect on timings.
- * @polarities - the horizontal and vertical polarities (same as struct
+ * @polarities: the horizontal and vertical polarities (same as struct
  * v4l2_bt_timings polarities).
- * @interlaced - if this flag is true, it indicates interlaced format
- * @fmt - the resulting timings.
+ * @interlaced: if this flag is true, it indicates interlaced format
+ * @fmt: the resulting timings.
  *
  * This function will attempt to detect if the given values correspond to a
  * valid CVT format. If so, then it will return true, and fmt will be filled
@@ -149,18 +149,18 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned 
hfreq, unsigned vsync,
 /**
  * v4l2_detect_gtf - detect if the given timings follow the GTF standard
  *
- * @frame_height - the total height of the frame (including blanking) in lines.
- * @hfreq - the horizontal frequency in Hz.
- * @vsync - the height of the vertical sync in lines.
- * @polarities - the horizontal and vertical polarities (same as struct
+ * @frame_height: the total height of the frame (including blanking) in lines.
+ * @hfreq: the horizontal frequency in Hz.
+ * @vsync: the height of the vertical sync in lines.
+ * @polarities: the horizontal and vertical polarities (same as struct
  * v4l2_bt_timings polarities).
- * @interlaced - if this flag is true, it indicates interlaced format
- * @aspect - preferred aspect ratio. GTF has no method of determining the
+ * @interlaced: if this flag is true, it indicates interlaced format
+ * @aspect: preferred aspect ratio. GTF has no method of determining the
  * aspect ratio in order to derive the image width from the
  * image height, so it has to be passed explicitly. Usually
  * the native screen aspect ratio is used for this. If it
  * is not filled in correctly, then 16:9 will be assumed.
- * @fmt - the resulting timings.
+ * @fmt: the resulting timings.
  *
  * This function will attempt to detect if the given values correspond to a
  * valid GTF format. If so, then it will return true, and fmt will be filled
@@ -174,8 +174,8 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, 
unsigned 

Re: Terratec H7 Rev. 4 is DVBSky

2015-09-15 Thread Olli Salonen
Hi Erik,

Your patch looks good to my eyes. I heard already earlier that the new
H7 is the same as the DVBSky receiver and your experience seems to
confirm that. Could you resend the patch again with a proper title and
a signed-off line to the mailing list?
https://www.kernel.org/doc/Documentation/SubmittingPatches is good
reading as well.

Cheers,
-olli


On 11 September 2015 at 17:04, Erik Andresen  wrote:
> Hi,
>
> I recently got a Terratec H7 in Revision 4 and turned out that it is not
> just a new revision, but a new product with USB ProductID 0x10a5.
> Previous revisions have been AZ6007, but this revision does not work
> with this driver [1].
>
> Output of lsusb (extended output attached):
> Bus 001 Device 011: ID 0ccd:10a5 TerraTec Electronic GmbH
>
> The revision 4 seems to a DVBSky variant, adding its Product ID to
> dvbsky.c with the attached patch enabled me to scan for channels and
> watch DVB-C and DVB-T.
>
> greetings,
> Erik
>
> [1] https://www.mail-archive.com/linux-media@vger.kernel.org/msg70934.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