cron job: media_tree daily build: WARNINGS

2017-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:   Sat Sep 16 05:00:21 CEST 2017
media-tree git hash:1efdf1776e2253b77413c997bed862410e4b6aaf
media_build git hash:   19087750b61fc0c5528e798c47ff845f9234
v4l-utils git hash: 7cf84ef0d4ea82039be977fc9304677b7ffd
gcc version:i686-linux-gcc (GCC) 7.1.0
sparse version: v0.5.0
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.12.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: 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.36.4-i686: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.2.37-i686: WARNINGS
linux-3.3.8-i686: WARNINGS
linux-3.4.27-i686: WARNINGS
linux-3.5.7-i686: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.12.67-i686: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.16.7-i686: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.18.7-i686: WARNINGS
linux-3.19-i686: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.1.33-i686: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.4.22-i686: WARNINGS
linux-4.5.7-i686: WARNINGS
linux-4.6.7-i686: WARNINGS
linux-4.7.5-i686: WARNINGS
linux-4.8-i686: OK
linux-4.9.26-i686: OK
linux-4.10.14-i686: OK
linux-4.11-i686: OK
linux-4.12.1-i686: OK
linux-4.13-i686: OK
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.37-x86_64: WARNINGS
linux-3.3.8-x86_64: WARNINGS
linux-3.4.27-x86_64: WARNINGS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.67-x86_64: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.7-x86_64: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.7-x86_64: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.33-x86_64: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.22-x86_64: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-x86_64: WARNINGS
linux-4.8-x86_64: WARNINGS
linux-4.9.26-x86_64: WARNINGS
linux-4.10.14-x86_64: WARNINGS
linux-4.11-x86_64: WARNINGS
linux-4.12.1-x86_64: WARNINGS
linux-4.13-x86_64: OK
apps: OK
spec-git: OK

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


Re: IMX6 ADV7180 no /dev/media

2017-09-15 Thread Steve Longerbeam



On 09/15/2017 04:46 PM, Fabio Estevam wrote:

Hi Steve,

On Fri, Sep 15, 2017 at 8:39 PM, Steve Longerbeam  wrote:


Agreed, but I notice now that CONFIG_MEDIA_CONTROLLER and
CONFIG_VIDEO_V4L2_SUBDEV_API are not enabled there anymore.

I do see them enabled in mainline with imx_v6_v7_defconfig.


Ah, I was looking at mediatree/master, the commit that
enables MEDIA_CONTROLLER hasn't hit mediatree yet.

Steve



Tim,

Care to send the patch enabling CONFIG_VIDEO_MUX?

Thanks




Re: IMX6 ADV7180 no /dev/media

2017-09-15 Thread Fabio Estevam
Hi Steve,

On Fri, Sep 15, 2017 at 8:39 PM, Steve Longerbeam  wrote:

> Agreed, but I notice now that CONFIG_MEDIA_CONTROLLER and
> CONFIG_VIDEO_V4L2_SUBDEV_API are not enabled there anymore.

I do see them enabled in mainline with imx_v6_v7_defconfig.

Tim,

Care to send the patch enabling CONFIG_VIDEO_MUX?

Thanks


Re: IMX6 ADV7180 no /dev/media

2017-09-15 Thread Steve Longerbeam



On 09/15/2017 04:28 PM, Tim Harvey wrote:

On Fri, Sep 15, 2017 at 3:26 PM, Steve Longerbeam  wrote:

Hi Tim,


On 09/15/2017 02:26 PM, Tim Harvey wrote:

Greetings,

I'm testing Linux master built with imx_v6_v7_defconfig on a GW51xx which
has an ADV7180 analog video decoder and am not seeing the imx6 /dev/media
node get created:

[0.00] OF: fdt: Machine model: Gateworks Ventana i.MX6 Dual/Quad
GW51XX
...
[6.089039] imx-media: Registered subdev ipu1_vdic
[6.094505] imx-media: Registered subdev ipu2_vdic
[6.099851] imx-media: Registered subdev ipu1_ic_prp
[6.105074] imx-media: Registered subdev ipu1_ic_prpenc
[6.111346] ipu1_ic_prpenc: Registered ipu1_ic_prpenc capture as
/dev/video0
[6.119007] imx-media: Registered subdev ipu1_ic_prpvf
[6.124733] ipu1_ic_prpvf: Registered ipu1_ic_prpvf capture as
/dev/video1
[6.131867] imx-media: Registered subdev ipu2_ic_prp
[6.137125] imx-media: Registered subdev ipu2_ic_prpenc
[6.142921] ipu2_ic_prpenc: Registered ipu2_ic_prpenc capture as
/dev/video2
[6.150226] imx-media: Registered subdev ipu2_ic_prpvf
[6.155934] ipu2_ic_prpvf: Registered ipu2_ic_prpvf capture as
/dev/video3
[6.164011] imx-media: Registered subdev ipu1_csi0
[6.169768] ipu1_csi0: Registered ipu1_csi0 capture as /dev/video4
[6.176281] imx-media: Registered subdev ipu1_csi1
[6.181681] ipu1_csi1: Registered ipu1_csi1 capture as /dev/video5
[6.188189] imx-media: Registered subdev ipu2_csi0
[6.193680] ipu2_csi0: Registered ipu2_csi0 capture as /dev/video6
[6.200108] imx-media: Registered subdev ipu2_csi1
[6.205577] ipu2_csi1: Registered ipu2_csi1 capture as /dev/video7
...
[   96.981117] adv7180 2-0020: chip found @ 0x20 (21a8000.i2c)
[   97.019674] imx-media: Registered subdev adv7180 2-0020
[   97.019712] imx-media capture-subsystem: Entity type for entity adv7180
2-0020 was not initialized!

I suspect the failure of the adv7180 is causing the issue. Steve mentioned
some time ago that this was an error that needed to be fixed upstream but
I'm not clear if that is still the case.


That does need fixing but is not the cause.


I haven't looked at IMX media drivers since they were accepted to mainline
a few months back. Perhaps I'm simply forgetting to enable something in the
kernel that imx_v6_v7_defconfig doesn't turn on?


Yes, it looks like you are missing the video-mux. Enable CONFIG_VIDEO_MUX
and CONFIG_MUX_MMIO.


Steve,

Indeed that was it! What clued you into that being the missing component?


It was easy :) There needs to be the following message from imx-media:

imx-media: Registered subdev ipu1_csi0_mux
imx-media: Registered subdev ipu2_csi1_mux

for quad, and

imx-media: Registered subdev ipu1_csi0_mux
imx-media: Registered subdev ipu1_csi1_mux

for D/L.

All imx6 platforms require the video-mux for video capture.

Steve



Sounds like we need to enable that for imx_v6_v7_defconfig.


Agreed, but I notice now that CONFIG_MEDIA_CONTROLLER and
CONFIG_VIDEO_V4L2_SUBDEV_API are not enabled there anymore.
I guess there was some config conflict that necessitated disabling
them, but without them there is no media platform device support at
all anyway. Those must be enabled first before getting CONFIG_VIDEO_MUX.

Steve



Re: [PATCH] [media] solo6x10: hide unused variable

2017-09-15 Thread Ismael Luceno
On 15/Sep/2017 21:52, Arnd Bergmann wrote:
> When building without CONFIG_GPIOLIB, we get a harmless
> warning about an unused variable:
> 
> drivers/media/pci/solo6x10/solo6x10-gpio.c: In function 'solo_gpio_init':
> drivers/media/pci/solo6x10/solo6x10-gpio.c:165:6: error: unused variable 
> 'ret' [-Werror=unused-variable]
> 
> This adds another #ifdef around the declaration.
> 
> Fixes: d3202d1981dc ("media: solo6x10: export hardware GPIO pins 8:31 to 
> gpiolib interface")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/pci/solo6x10/solo6x10-gpio.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/pci/solo6x10/solo6x10-gpio.c 
> b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> index 3d0d1aa2f6a8..7b4641a2cb84 100644
> --- a/drivers/media/pci/solo6x10/solo6x10-gpio.c
> +++ b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> @@ -162,7 +162,9 @@ static void solo_gpiochip_set(struct gpio_chip *chip,
>  
>  int solo_gpio_init(struct solo_dev *solo_dev)
>  {
> +#ifdef CONFIG_GPIOLIB
>   int ret;
> +#endif
>  
>   solo_gpio_config(solo_dev);
>  #ifdef CONFIG_GPIOLIB
> -- 
> 2.9.0
> 

Signed-off-by: Ismael Luceno 


Re: IMX6 ADV7180 no /dev/media

2017-09-15 Thread Tim Harvey
On Fri, Sep 15, 2017 at 3:26 PM, Steve Longerbeam  wrote:
> Hi Tim,
>
>
> On 09/15/2017 02:26 PM, Tim Harvey wrote:
>>
>> Greetings,
>>
>> I'm testing Linux master built with imx_v6_v7_defconfig on a GW51xx which
>> has an ADV7180 analog video decoder and am not seeing the imx6 /dev/media
>> node get created:
>>
>> [0.00] OF: fdt: Machine model: Gateworks Ventana i.MX6 Dual/Quad
>> GW51XX
>> ...
>> [6.089039] imx-media: Registered subdev ipu1_vdic
>> [6.094505] imx-media: Registered subdev ipu2_vdic
>> [6.099851] imx-media: Registered subdev ipu1_ic_prp
>> [6.105074] imx-media: Registered subdev ipu1_ic_prpenc
>> [6.111346] ipu1_ic_prpenc: Registered ipu1_ic_prpenc capture as
>> /dev/video0
>> [6.119007] imx-media: Registered subdev ipu1_ic_prpvf
>> [6.124733] ipu1_ic_prpvf: Registered ipu1_ic_prpvf capture as
>> /dev/video1
>> [6.131867] imx-media: Registered subdev ipu2_ic_prp
>> [6.137125] imx-media: Registered subdev ipu2_ic_prpenc
>> [6.142921] ipu2_ic_prpenc: Registered ipu2_ic_prpenc capture as
>> /dev/video2
>> [6.150226] imx-media: Registered subdev ipu2_ic_prpvf
>> [6.155934] ipu2_ic_prpvf: Registered ipu2_ic_prpvf capture as
>> /dev/video3
>> [6.164011] imx-media: Registered subdev ipu1_csi0
>> [6.169768] ipu1_csi0: Registered ipu1_csi0 capture as /dev/video4
>> [6.176281] imx-media: Registered subdev ipu1_csi1
>> [6.181681] ipu1_csi1: Registered ipu1_csi1 capture as /dev/video5
>> [6.188189] imx-media: Registered subdev ipu2_csi0
>> [6.193680] ipu2_csi0: Registered ipu2_csi0 capture as /dev/video6
>> [6.200108] imx-media: Registered subdev ipu2_csi1
>> [6.205577] ipu2_csi1: Registered ipu2_csi1 capture as /dev/video7
>> ...
>> [   96.981117] adv7180 2-0020: chip found @ 0x20 (21a8000.i2c)
>> [   97.019674] imx-media: Registered subdev adv7180 2-0020
>> [   97.019712] imx-media capture-subsystem: Entity type for entity adv7180
>> 2-0020 was not initialized!
>>
>> I suspect the failure of the adv7180 is causing the issue. Steve mentioned
>> some time ago that this was an error that needed to be fixed upstream but
>> I'm not clear if that is still the case.
>>
>
> That does need fixing but is not the cause.
>
>> I haven't looked at IMX media drivers since they were accepted to mainline
>> a few months back. Perhaps I'm simply forgetting to enable something in the
>> kernel that imx_v6_v7_defconfig doesn't turn on?
>
>
> Yes, it looks like you are missing the video-mux. Enable CONFIG_VIDEO_MUX
> and CONFIG_MUX_MMIO.
>

Steve,

Indeed that was it! What clued you into that being the missing component?

Sounds like we need to enable that for imx_v6_v7_defconfig.

Thanks!

Tim


Re: IMX6 ADV7180 no /dev/media

2017-09-15 Thread Steve Longerbeam

Hi Tim,

On 09/15/2017 02:26 PM, Tim Harvey wrote:

Greetings,

I'm testing Linux master built with imx_v6_v7_defconfig on a GW51xx 
which has an ADV7180 analog video decoder and am not seeing the imx6 
/dev/media node get created:


[    0.00] OF: fdt: Machine model: Gateworks Ventana i.MX6 
Dual/Quad GW51XX

...
[    6.089039] imx-media: Registered subdev ipu1_vdic
[    6.094505] imx-media: Registered subdev ipu2_vdic
[    6.099851] imx-media: Registered subdev ipu1_ic_prp
[    6.105074] imx-media: Registered subdev ipu1_ic_prpenc
[    6.111346] ipu1_ic_prpenc: Registered ipu1_ic_prpenc capture as 
/dev/video0

[    6.119007] imx-media: Registered subdev ipu1_ic_prpvf
[    6.124733] ipu1_ic_prpvf: Registered ipu1_ic_prpvf capture as 
/dev/video1

[    6.131867] imx-media: Registered subdev ipu2_ic_prp
[    6.137125] imx-media: Registered subdev ipu2_ic_prpenc
[    6.142921] ipu2_ic_prpenc: Registered ipu2_ic_prpenc capture as 
/dev/video2

[    6.150226] imx-media: Registered subdev ipu2_ic_prpvf
[    6.155934] ipu2_ic_prpvf: Registered ipu2_ic_prpvf capture as 
/dev/video3

[    6.164011] imx-media: Registered subdev ipu1_csi0
[    6.169768] ipu1_csi0: Registered ipu1_csi0 capture as /dev/video4
[    6.176281] imx-media: Registered subdev ipu1_csi1
[    6.181681] ipu1_csi1: Registered ipu1_csi1 capture as /dev/video5
[    6.188189] imx-media: Registered subdev ipu2_csi0
[    6.193680] ipu2_csi0: Registered ipu2_csi0 capture as /dev/video6
[    6.200108] imx-media: Registered subdev ipu2_csi1
[    6.205577] ipu2_csi1: Registered ipu2_csi1 capture as /dev/video7
...
[   96.981117] adv7180 2-0020: chip found @ 0x20 (21a8000.i2c)
[   97.019674] imx-media: Registered subdev adv7180 2-0020
[   97.019712] imx-media capture-subsystem: Entity type for entity 
adv7180 2-0020 was not initialized!


I suspect the failure of the adv7180 is causing the issue. Steve 
mentioned some time ago that this was an error that needed to be fixed 
upstream but I'm not clear if that is still the case.




That does need fixing but is not the cause.

I haven't looked at IMX media drivers since they were accepted to 
mainline a few months back. Perhaps I'm simply forgetting to enable 
something in the kernel that imx_v6_v7_defconfig doesn't turn on?


Yes, it looks like you are missing the video-mux. Enable CONFIG_VIDEO_MUX
and CONFIG_MUX_MMIO.

Steve



Re: [PATCH v2 00/10] media: rc: gpio-ir-recv: driver update

2017-09-15 Thread Ladislav Michl
On Mon, Sep 11, 2017 at 09:13:32AM +0200, Ladislav Michl wrote:
> On Mon, Sep 11, 2017 at 11:58:43AM +0900, Andi Shyti wrote:
> > Hi Ladislav,
> > 
> > > > > Serie was rebased on top of current linux.git, but something
> > > > > happened there and my userspace decoder no longer works: driver
> > > > > reports completely bogus timing such as (rc-5):
> > > > > ^427, _1342, ^945, _183, ^1128, _671, ^1586, _91, ^1189, _1525,
> > > > > ^1738, _1433, ^915, _1159, ^1464, _1525, ^213, _1067, ^793, _0
> > > > > (^ used for pulse and _ for space)
> > > > > As it has nothing to do with my changes, I'm sending it anyway
> > > > > for review, which I do not expect to happen until merge window
> > > > > ends.
> > > > 
> > > > This means that your patch is anyway untested.
> > > 
> > > Previous version is pretty well tested. GPIO IR stopped working
> > > after pulling other changes from linux.git yesterday. And does not
> > > work even without this patch set. I'll try to bisect later as omiting
> > > linux-media merge did not fix it either.
> > 
> > OK
> 
> In all truth, changes were developed on top of 4.9.40, testing was done at
> customer's site and for generally usefull changes usual attempt for merge
> was done :-) I tried unmodified driver over weekend:
> 4.9.0: Not OK
> 4.9.40: OK
> 4.9.13: Not OK
> linux.git: Not OK
> Tested on IGEPv2 board based on DM3730, so something went wrong again.
> Based on driver principle I suspect either ktime_get returning "strange"
> values or interrupts are broken again (but that does not explain those
> short pulses and spaces):
> https://www.spinics.net/lists/linux-omap/msg135915.html
> Verifying that would require some test setup with signal generator and
> scope, as described in said email thread; or combine that test driver
> with this one and look what is really happening. Unfortunately I'm not
> able to do this any time soon, so if someone has hardware reliably working
> with current mainline and is willing to test this patch serie I would
> be very happy to see it happen.

So, turns out to be GPIO edge interrupt handling bug on OMAPs.
Proper fix still needs to be investigated, but it does not affect
this patch serie.

> > > > In any case I don't see much use if patch 1/10 as it doesn't
> > > > simplify much, but the rest (from 2 to 10) looks good to me.
> > > 
> > > Just look at patch 9 and imagine how it would look without this
> > > change. If you are still unconvinced I'll drop this change.
> > 
> > You don't need to, that's just my personal taste and I'm not
> > strong with it. Patch 1 is quite common and not a big deal anyway.
> > If you like it you like you can leave it :)
> > 
> > > > P.S. I don't see in this V2 the changelog from V1. Next time,
> > > > please add the changelog.
> > > 
> > > It was just a rebase with conflicts resolved. I do not see how
> > > to describe it better than I did.
> > 
> > You could write the above (i.e. V2 fixed rebase conflicts :) ).
> > The reason is that as no change is stated, I have to anyway, as
> > reviewer, compare side by side all patches to figure out if there
> > is any difference (even if small) that is not expected.
> 
> Fair enough. Let's wait if there will any more comments and I'll do
> better in V3.
> 
> > Thanks,
> > Andi
> 
> Best regards,
>   ladis


[PATCH 2/2] [media] ma901: Improve a size determination in usb_ma901radio_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 22:23:42 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/radio/radio-ma901.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/radio/radio-ma901.c 
b/drivers/media/radio/radio-ma901.c
index c386fbd63703..61d1657f1ee7 100644
--- a/drivers/media/radio/radio-ma901.c
+++ b/drivers/media/radio/radio-ma901.c
@@ -357,5 +357,5 @@ static int usb_ma901radio_probe(struct usb_interface *intf,
|| strncmp(dev->manufacturer, "www.masterkit.ru", 16) != 0))
return -ENODEV;
 
-   radio = kzalloc(sizeof(struct ma901radio_device), GFP_KERNEL);
+   radio = kzalloc(sizeof(*radio), GFP_KERNEL);
if (!radio) {
-- 
2.14.1



[PATCH 1/2] [media] ma901: Delete two error messages for a failed memory allocation in usb_ma901radio_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 22:20:04 +0200

Omit extra messages for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/radio/radio-ma901.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/radio/radio-ma901.c 
b/drivers/media/radio/radio-ma901.c
index fdc481257efd..c386fbd63703 100644
--- a/drivers/media/radio/radio-ma901.c
+++ b/drivers/media/radio/radio-ma901.c
@@ -361,10 +361,8 @@ static int usb_ma901radio_probe(struct usb_interface *intf,
if (!radio) {
-   dev_err(>dev, "kzalloc for ma901radio_device failed\n");
retval = -ENOMEM;
goto err;
}
 
radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
if (!radio->buffer) {
-   dev_err(>dev, "kmalloc for radio->buffer failed\n");
retval = -ENOMEM;
-- 
2.14.1



[PATCH 0/2] [media] MA901: Adjustments for usb_ma901radio_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 22:31:23 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete two error messages for a failed memory allocation
  Improve a size determination

 drivers/media/radio/radio-ma901.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

-- 
2.14.1



[PATCH] [media] exynos4-is: properly initialize frame format

2017-09-15 Thread Arnd Bergmann
We copy the subdev frame format from a partially initialized
structure, which is not entirely well-defined. Older compilers
like gcc-4.4 can copy uninitialized stack data here and warn
about it:

drivers/media/platform/exynos4-is/fimc-isp.c: In function 
'fimc_isp_subdev_open':
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[10u]' 
may be used uninitialized in this function
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[9u]' may 
be used uninitialized in this function
...
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[0u]' may 
be used uninitialized in this function
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.xfer_func' may be 
used uninitialized in this function

On newer compilers, only the initialized fields get copied, but
we should not rely on that, so this changes the code to zero-out
the remaining fields first.

Fixes: 9a761e436843 ("[media] exynos4-is: Add Exynos4x12 FIMC-IS driver")
Signed-off-by: Arnd Bergmann 
---
 drivers/media/platform/exynos4-is/fimc-isp.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c 
b/drivers/media/platform/exynos4-is/fimc-isp.c
index fd793d3ac072..9a48c0f69320 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -366,16 +366,16 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev 
*sd, int on)
 static int fimc_isp_subdev_open(struct v4l2_subdev *sd,
struct v4l2_subdev_fh *fh)
 {
-   struct v4l2_mbus_framefmt fmt;
struct v4l2_mbus_framefmt *format;
+   struct v4l2_mbus_framefmt fmt = {
+   .colorspace = V4L2_COLORSPACE_SRGB,
+   .code = fimc_isp_formats[0].mbus_code,
+   .width = DEFAULT_PREVIEW_STILL_WIDTH + 
FIMC_ISP_CAC_MARGIN_WIDTH,
+   .height = DEFAULT_PREVIEW_STILL_HEIGHT + 
FIMC_ISP_CAC_MARGIN_HEIGHT,
+   .field = V4L2_FIELD_NONE,
+   };
 
format = v4l2_subdev_get_try_format(sd, fh->pad, FIMC_ISP_SD_PAD_SINK);
-
-   fmt.colorspace = V4L2_COLORSPACE_SRGB;
-   fmt.code = fimc_isp_formats[0].mbus_code;
-   fmt.width = DEFAULT_PREVIEW_STILL_WIDTH + FIMC_ISP_CAC_MARGIN_WIDTH;
-   fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT + FIMC_ISP_CAC_MARGIN_HEIGHT;
-   fmt.field = V4L2_FIELD_NONE;
*format = fmt;
 
format = v4l2_subdev_get_try_format(sd, fh->pad, 
FIMC_ISP_SD_PAD_SRC_FIFO);
-- 
2.9.0



[PATCH] [media] solo6x10: hide unused variable

2017-09-15 Thread Arnd Bergmann
When building without CONFIG_GPIOLIB, we get a harmless
warning about an unused variable:

drivers/media/pci/solo6x10/solo6x10-gpio.c: In function 'solo_gpio_init':
drivers/media/pci/solo6x10/solo6x10-gpio.c:165:6: error: unused variable 'ret' 
[-Werror=unused-variable]

This adds another #ifdef around the declaration.

Fixes: d3202d1981dc ("media: solo6x10: export hardware GPIO pins 8:31 to 
gpiolib interface")
Signed-off-by: Arnd Bergmann 
---
 drivers/media/pci/solo6x10/solo6x10-gpio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/pci/solo6x10/solo6x10-gpio.c 
b/drivers/media/pci/solo6x10/solo6x10-gpio.c
index 3d0d1aa2f6a8..7b4641a2cb84 100644
--- a/drivers/media/pci/solo6x10/solo6x10-gpio.c
+++ b/drivers/media/pci/solo6x10/solo6x10-gpio.c
@@ -162,7 +162,9 @@ static void solo_gpiochip_set(struct gpio_chip *chip,
 
 int solo_gpio_init(struct solo_dev *solo_dev)
 {
+#ifdef CONFIG_GPIOLIB
int ret;
+#endif
 
solo_gpio_config(solo_dev);
 #ifdef CONFIG_GPIOLIB
-- 
2.9.0



Re: [media] stm32-dcmi: Improve four size determinations

2017-09-15 Thread SF Markus Elfring
>> +memcpy(dcmi->sd_formats, sd_fmts, num_fmts * sizeof(*dcmi->sd_formats));
> 
> devm_kmemdup

Are function variants provided which handle memory duplications
for arrays explicitly?

Regards,
Markus


[PATCH 2/2] [media] ti-vpe: Adjust nine checks for null pointers

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 20:22:44 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/ti-vpe/csc.c   |  2 +-
 drivers/media/platform/ti-vpe/vpdma.c |  2 +-
 drivers/media/platform/ti-vpe/vpe.c   | 14 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index 135fc9993679..b6568e620a8d 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -181,7 +181,7 @@ struct csc_data *csc_create(struct platform_device *pdev, 
const char *res_name)
 
csc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
res_name);
-   if (csc->res == NULL) {
+   if (!csc->res) {
dev_err(>dev, "missing '%s' platform resources data\n",
res_name);
return ERR_PTR(-ENODEV);
diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index e2cf2b90e500..b9acd29ebd9a 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -1145,7 +1145,7 @@ int vpdma_create(struct platform_device *pdev, struct 
vpdma_data *vpdma,
spin_lock_init(>lock);
 
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
-   if (res == NULL) {
+   if (!res) {
dev_err(>dev, "missing platform resources data\n");
return -ENODEV;
}
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 45bd10544189..6bc210e68f6a 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -601,7 +601,7 @@ static void free_vbs(struct vpe_ctx *ctx)
struct vpe_dev *dev = ctx->dev;
unsigned long flags;
 
-   if (ctx->src_vbs[2] == NULL)
+   if (!ctx->src_vbs[2])
return;
 
spin_lock_irqsave(>lock, flags);
@@ -1216,22 +1216,22 @@ static void device_run(void *priv)
 * It will be removed when using bottom field
 */
ctx->src_vbs[0] = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
-   WARN_ON(ctx->src_vbs[0] == NULL);
+   WARN_ON(!ctx->src_vbs[0]);
} else {
ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
-   WARN_ON(ctx->src_vbs[0] == NULL);
+   WARN_ON(!ctx->src_vbs[0]);
}
 
ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
-   WARN_ON(ctx->dst_vb == NULL);
+   WARN_ON(!ctx->dst_vb);
 
if (ctx->deinterlacing) {
 
-   if (ctx->src_vbs[2] == NULL) {
+   if (!ctx->src_vbs[2]) {
ctx->src_vbs[2] = ctx->src_vbs[0];
-   WARN_ON(ctx->src_vbs[2] == NULL);
+   WARN_ON(!ctx->src_vbs[2]);
ctx->src_vbs[1] = ctx->src_vbs[0];
-   WARN_ON(ctx->src_vbs[1] == NULL);
+   WARN_ON(!ctx->src_vbs[1]);
}
 
/*
-- 
2.14.1



[PATCH 1/2] [media] ti-vpe: Delete an error message for a failed memory allocation in two functions

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 20:15:17 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/ti-vpe/csc.c | 4 +---
 drivers/media/platform/ti-vpe/sc.c  | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index 44b8465cf101..135fc9993679 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -176,8 +176,6 @@ struct csc_data *csc_create(struct platform_device *pdev, 
const char *res_name)
csc = devm_kzalloc(>dev, sizeof(*csc), GFP_KERNEL);
-   if (!csc) {
-   dev_err(>dev, "couldn't alloc csc_data\n");
+   if (!csc)
return ERR_PTR(-ENOMEM);
-   }
 
csc->pdev = pdev;
 
diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index e9273b713782..e9e307875feb 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -284,8 +284,6 @@ struct sc_data *sc_create(struct platform_device *pdev, 
const char *res_name)
sc = devm_kzalloc(>dev, sizeof(*sc), GFP_KERNEL);
-   if (!sc) {
-   dev_err(>dev, "couldn't alloc sc_data\n");
+   if (!sc)
return ERR_PTR(-ENOMEM);
-   }
 
sc->pdev = pdev;
 
-- 
2.14.1



[PATCH 0/2] [media] TI-VPE: Adjustments for five function implementations

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 20:30:40 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation in two functions
  Adjust nine checks for null pointers

 drivers/media/platform/ti-vpe/csc.c   |  6 ++
 drivers/media/platform/ti-vpe/sc.c|  4 +---
 drivers/media/platform/ti-vpe/vpdma.c |  2 +-
 drivers/media/platform/ti-vpe/vpe.c   | 14 +++---
 4 files changed, 11 insertions(+), 15 deletions(-)

-- 
2.14.1



Re: [PATCH v1 2/3] drm: rcar-du: Add suspend resume helpers

2017-09-15 Thread Laurent Pinchart
Hi Kieran,

On Friday, 15 September 2017 20:49:15 EEST Kieran Bingham wrote:
> On 15/09/17 18:02, Laurent Pinchart wrote:
> > On Friday, 15 September 2017 19:42:06 EEST Kieran Bingham wrote:
> >> The pipeline needs to ensure that the hardware is idle for suspend and
> >> resume operations.
> > 
> > I'm not sure to really understand this sentence.
> 
> It makes sense to me ... :) - But I'm not the (only) target audience.
> 
> How about re-wording it in a similar way to your suggestion in [1/3]
> 
> """
> To support system suspend operations we must ensure the hardware is stopped,
> and resumed explicitly from the suspend and resume handlers.
> 
> Implement suspend and resume functions using the DRM atomic helper
> functions.
> """

Sounds good to me. I'll update the commit message in my tree, and update the 
subject line to "drm: rcar-du: Implement system suspend/resume support".

> >> Implement suspend and resume functions using the DRM atomic helper
> >> functions.
> >> 
> >> CC: dri-de...@lists.freedesktop.org
> >> 
> >> Signed-off-by: Kieran Bingham 
> > 
> > The rest of the patch looks good to me. With the commit message clarified,
> > 
> > Reviewed-by: Laurent Pinchart 
> > 
> >> ---
> >> 
> >>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 18 +++---
> >>  drivers/gpu/drm/rcar-du/rcar_du_drv.h |  1 +
> >>  2 files changed, 16 insertions(+), 3 deletions(-)

[snip]

-- 
Regards,

Laurent Pinchart



Re: [PATCH 2/2] [media] stm32-dcmi: Improve four size determinations

2017-09-15 Thread Joe Perches
On Fri, 2017-09-15 at 19:29 +0200, SF Markus Elfring wrote:
> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
> b/drivers/media/platform/stm32/stm32-dcmi.c
[]
> @@ -1372,9 +1372,8 @@ static int dcmi_formats_init(struct stm32_dcmi *dcmi)
>   dcmi->sd_formats = devm_kcalloc(dcmi->dev,
> - num_fmts, sizeof(struct dcmi_format *),
> + num_fmts, sizeof(*dcmi->sd_formats),
>   GFP_KERNEL);
>   if (!dcmi->sd_formats)
>   return -ENOMEM;
>  
> - memcpy(dcmi->sd_formats, sd_fmts,
> -num_fmts * sizeof(struct dcmi_format *));
> + memcpy(dcmi->sd_formats, sd_fmts, num_fmts * sizeof(*dcmi->sd_formats));

devm_kmemdup



Re: [PATCHv4 3/5] dt-bindings: document the CEC GPIO bindings

2017-09-15 Thread Rob Herring
On Fri, Sep 15, 2017 at 3:40 AM, Hans Verkuil  wrote:
> Hi Rob,
>
> On 09/13/17 10:21, Hans Verkuil wrote:
>> On 09/12/2017 04:43 PM, Rob Herring wrote:
>>> On Thu, Aug 31, 2017 at 01:01:54PM +0200, Hans Verkuil wrote:
 From: Hans Verkuil 

 Document the bindings for the cec-gpio module for hardware where the
 CEC line and optionally the HPD line are connected to GPIO lines.

 Signed-off-by: Hans Verkuil 
 ---
  .../devicetree/bindings/media/cec-gpio.txt | 22 
 ++
  1 file changed, 22 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/media/cec-gpio.txt

 diff --git a/Documentation/devicetree/bindings/media/cec-gpio.txt 
 b/Documentation/devicetree/bindings/media/cec-gpio.txt
 new file mode 100644
 index ..db20a7452dbd
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/media/cec-gpio.txt
 @@ -0,0 +1,22 @@
 +* HDMI CEC GPIO driver
 +
 +The HDMI CEC GPIO module supports CEC implementations where the CEC line
 +is hooked up to a pull-up GPIO line and - optionally - the HPD line is
 +hooked up to another GPIO line.
 +
 +Required properties:
 +  - compatible: value must be "cec-gpio"
 +  - cec-gpio: gpio that the CEC line is connected to
>>>
>>> cec-gpios
>>
>> Will change.
>>
>>>
 +
 +Optional property:
 +  - hpd-gpio: gpio that the HPD line is connected to
>>>
>>> hpd-gpios
>>
>> Will change.
>>
>>>
>>> However, HPD is already part of the HDMI connector binding. Having it in
>>> 2 places would be wrong.
>>
>> No. This is not an HDMI receiver/transmitter. There are two use-cases for 
>> this
>> driver:
>>
>> 1) For HDMI receivers/transmitters that connect the CEC pin of an HDMI 
>> connector
>>to a GPIO pin. In that case the HPD goes to the HDMI transmitter/receiver 
>> and
>>not to this driver. As you say, that would not make any sense.
>>
>>But currently no such devices are in the kernel (I know they exist, 
>> though).
>>Once such a driver would appear in the kernel then these bindings need to 
>> be
>>extended with an hdmi-phandle.
>>
>> 2) This driver is used for debugging CEC like this:
>>
>>   https://hverkuil.home.xs4all.nl/rpi3-cec.jpg
>>
>>Here the CEC pin of an HDMI breakout connector is hooked up to a 
>> Raspberry Pi
>>GPIO pin and the RPi monitors it. It's a cheap but very effective CEC 
>> analyzer.
>>In this use-case it is very helpful to also monitor the HPD pin since some
>>displays do weird things with the HPD and knowing the state of the HPD 
>> helps
>>a lot when debugging CEC problems. It's optional and it only monitors the 
>> pin.
>>
>>Actually, there does not have to be an HDMI connector involved at all: 
>> you can
>>make two cec-gpio instances and just connect the two GPIO pins together in
>>order to emulate two CEC adapters and play with that.
>
> Is it OK to define a binding but not (yet) implement it? I have seen that in 
> other
> bindings (well, OK, one other binding :-) ). If that is fine, then I can 
> write the
> following:

It's preferred over adding a property one by one.

>
> 
> Required properties:
>   - compatible: value must be "cec-gpio".
>   - cec-gpios: gpio that the CEC line is connected to.
>
> If the CEC line is associated with an HDMI receiver/transmitter, then the 
> following
> property is also required:
>
>   - hdmi-phandle - phandle to the HDMI controller, see also cec.txt.
>
> If the CEC line is not associated with an HDMI receiver/transmitter, then the
> following property is optional:
>
>   - hpd-gpios: gpio that the HPD line is connected to.
> 

Yes, this seems fine.

Rob


Re: [PATCH v1 2/3] drm: rcar-du: Add suspend resume helpers

2017-09-15 Thread Kieran Bingham
Hi Laurent,

Thanks for your speedy review!

On 15/09/17 18:02, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Friday, 15 September 2017 19:42:06 EEST Kieran Bingham wrote:
>> The pipeline needs to ensure that the hardware is idle for suspend and
>> resume operations.
> 
> I'm not sure to really understand this sentence.

It makes sense to me ... :) - But I'm not the (only) target audience.

How about re-wording it in a similar way to your suggestion in [1/3]

"""
To support system suspend operations we must ensure the hardware is stopped, and
resumed explicitly from the suspend and resume handlers.

Implement suspend and resume functions using the DRM atomic helper
functions.
"""


> 
>> Implement suspend and resume functions using the DRM atomic helper
>> functions.
>>
>> CC: dri-de...@lists.freedesktop.org
>>
>> Signed-off-by: Kieran Bingham 
> 
> The rest of the patch looks good to me. With the commit message clarified,
> 
> Reviewed-by: Laurent Pinchart 
> 
>> ---
>>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 18 +++---
>>  drivers/gpu/drm/rcar-du/rcar_du_drv.h |  1 +
>>  2 files changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 09fbceade6b1..01b91d0c169c
>> 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> @@ -22,6 +22,7 @@
>>  #include 
>>
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -267,9 +268,19 @@ static struct drm_driver rcar_du_driver = {
>>  static int rcar_du_pm_suspend(struct device *dev)
>>  {
>>  struct rcar_du_device *rcdu = dev_get_drvdata(dev);
>> +struct drm_atomic_state *state;
>>
>>  drm_kms_helper_poll_disable(rcdu->ddev);
>> -/* TODO Suspend the CRTC */
>> +drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, true);
>> +
>> +state = drm_atomic_helper_suspend(rcdu->ddev);
>> +if (IS_ERR(state)) {
>> +drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
>> +drm_kms_helper_poll_enable(rcdu->ddev);
>> +return PTR_ERR(state);
>> +}
>> +
>> +rcdu->suspend_state = state;
>>
>>  return 0;
>>  }
>> @@ -278,9 +289,10 @@ static int rcar_du_pm_resume(struct device *dev)
>>  {
>>  struct rcar_du_device *rcdu = dev_get_drvdata(dev);
>>
>> -/* TODO Resume the CRTC */
>> -
>> +drm_atomic_helper_resume(rcdu->ddev, rcdu->suspend_state);
>> +drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
>>  drm_kms_helper_poll_enable(rcdu->ddev);
>> +
>>  return 0;
>>  }
>>  #endif
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.h
>> b/drivers/gpu/drm/rcar-du/rcar_du_drv.h index f8cd79488ece..f400fde65a0c
>> 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.h
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.h
>> @@ -81,6 +81,7 @@ struct rcar_du_device {
>>
>>  struct drm_device *ddev;
>>  struct drm_fbdev_cma *fbdev;
>> +struct drm_atomic_state *suspend_state;
>>
>>  struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
>>  unsigned int num_crtcs;
> 
> 


[PATCH 2/2] [media] stm32-dcmi: Improve four size determinations

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 18:48:14 +0200

Replace the specification of data types by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/stm32/stm32-dcmi.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index df12d10bd230..c4895cc95cc1 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1372,9 +1372,8 @@ static int dcmi_formats_init(struct stm32_dcmi *dcmi)
dcmi->sd_formats = devm_kcalloc(dcmi->dev,
-   num_fmts, sizeof(struct dcmi_format *),
+   num_fmts, sizeof(*dcmi->sd_formats),
GFP_KERNEL);
if (!dcmi->sd_formats)
return -ENOMEM;
 
-   memcpy(dcmi->sd_formats, sd_fmts,
-  num_fmts * sizeof(struct dcmi_format *));
+   memcpy(dcmi->sd_formats, sd_fmts, num_fmts * sizeof(*dcmi->sd_formats));
dcmi->sd_format = dcmi->sd_formats[0];
@@ -1406,3 +1405,3 @@ static int dcmi_framesizes_init(struct stm32_dcmi *dcmi)
dcmi->sd_framesizes = devm_kcalloc(dcmi->dev, num_fsize,
-  sizeof(struct dcmi_framesize),
+  sizeof(*dcmi->sd_framesizes),
   GFP_KERNEL);
@@ -1570,5 +1569,5 @@ static int dcmi_probe(struct platform_device *pdev)
return -ENODEV;
}
 
-   dcmi = devm_kzalloc(>dev, sizeof(struct stm32_dcmi), GFP_KERNEL);
+   dcmi = devm_kzalloc(>dev, sizeof(*dcmi), GFP_KERNEL);
if (!dcmi)
-- 
2.14.1



[PATCH 1/2] [media] stm32-dcmi: Delete an error message for a failed memory allocation in two functions

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 18:38:25 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/stm32/stm32-dcmi.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 35ba6f211b79..df12d10bd230 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -1374,6 +1374,4 @@ static int dcmi_formats_init(struct stm32_dcmi *dcmi)
GFP_KERNEL);
-   if (!dcmi->sd_formats) {
-   dev_err(dcmi->dev, "Could not allocate memory\n");
+   if (!dcmi->sd_formats)
return -ENOMEM;
-   }
 
@@ -1410,7 +1408,5 @@ static int dcmi_framesizes_init(struct stm32_dcmi *dcmi)
   GFP_KERNEL);
-   if (!dcmi->sd_framesizes) {
-   dev_err(dcmi->dev, "Could not allocate memory\n");
+   if (!dcmi->sd_framesizes)
return -ENOMEM;
-   }
 
/* Fill array with sensor supported framesizes */
-- 
2.14.1



[PATCH 0/2] [media] STM32-DCMI: Adjustments for three function implementations

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 19:01:23 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation in two functions
  Improve four size determinations

 drivers/media/platform/stm32/stm32-dcmi.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

-- 
2.14.1



Re: [PATCH v1 3/3] drm: rcar-du: Remove unused CRTC suspend/resume functions

2017-09-15 Thread Laurent Pinchart
Hi Kieran,

Thank you for the patch.

On Friday, 15 September 2017 19:42:07 EEST Kieran Bingham wrote:
> An early implementation of suspend-resume helpers are available in the
> CRTC module, however they are unused and no longer needed.
> 
> With suspend and resume handled by the core DRM atomic helpers, we can
> remove the unused functions.
> 
> CC: dri-de...@lists.freedesktop.org
> 
> Signed-off-by: Kieran Bingham 

Reviewed-by: Laurent Pinchart 

I'll take this in my tree with patch 2/3.

> ---
>  drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 35 +---
>  1 file changed, 35 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c index 301ea1a8018e..b492063a6e1f
> 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> @@ -557,41 +557,6 @@ static void rcar_du_crtc_stop(struct rcar_du_crtc
> *rcrtc) rcar_du_group_start_stop(rcrtc->group, false);
>  }
> 
> -void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc)
> -{
> - if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE))
> - rcar_du_vsp_disable(rcrtc);
> -
> - rcar_du_crtc_stop(rcrtc);
> - rcar_du_crtc_put(rcrtc);
> -}
> -
> -void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc)
> -{
> - unsigned int i;
> -
> - if (!rcrtc->crtc.state->active)
> - return;
> -
> - rcar_du_crtc_get(rcrtc);
> - rcar_du_crtc_setup(rcrtc);
> -
> - /* Commit the planes state. */
> - if (!rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) {
> - for (i = 0; i < rcrtc->group->num_planes; ++i) {
> - struct rcar_du_plane *plane = >group->planes[i];
> -
> - if (plane->plane.state->crtc != >crtc)
> - continue;
> -
> - rcar_du_plane_setup(plane);
> - }
> - }
> -
> - rcar_du_crtc_update_planes(rcrtc);
> - rcar_du_crtc_start(rcrtc);
> -}
> -
>  /* 
>   * CRTC Functions
>   */


-- 
Regards,

Laurent Pinchart



Re: [PATCH v1 2/3] drm: rcar-du: Add suspend resume helpers

2017-09-15 Thread Laurent Pinchart
Hi Kieran,

Thank you for the patch.

On Friday, 15 September 2017 19:42:06 EEST Kieran Bingham wrote:
> The pipeline needs to ensure that the hardware is idle for suspend and
> resume operations.

I'm not sure to really understand this sentence.

> Implement suspend and resume functions using the DRM atomic helper
> functions.
> 
> CC: dri-de...@lists.freedesktop.org
> 
> Signed-off-by: Kieran Bingham 

The rest of the patch looks good to me. With the commit message clarified,

Reviewed-by: Laurent Pinchart 

> ---
>  drivers/gpu/drm/rcar-du/rcar_du_drv.c | 18 +++---
>  drivers/gpu/drm/rcar-du/rcar_du_drv.h |  1 +
>  2 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> b/drivers/gpu/drm/rcar-du/rcar_du_drv.c index 09fbceade6b1..01b91d0c169c
> 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
> @@ -22,6 +22,7 @@
>  #include 
> 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -267,9 +268,19 @@ static struct drm_driver rcar_du_driver = {
>  static int rcar_du_pm_suspend(struct device *dev)
>  {
>   struct rcar_du_device *rcdu = dev_get_drvdata(dev);
> + struct drm_atomic_state *state;
> 
>   drm_kms_helper_poll_disable(rcdu->ddev);
> - /* TODO Suspend the CRTC */
> + drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, true);
> +
> + state = drm_atomic_helper_suspend(rcdu->ddev);
> + if (IS_ERR(state)) {
> + drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
> + drm_kms_helper_poll_enable(rcdu->ddev);
> + return PTR_ERR(state);
> + }
> +
> + rcdu->suspend_state = state;
> 
>   return 0;
>  }
> @@ -278,9 +289,10 @@ static int rcar_du_pm_resume(struct device *dev)
>  {
>   struct rcar_du_device *rcdu = dev_get_drvdata(dev);
> 
> - /* TODO Resume the CRTC */
> -
> + drm_atomic_helper_resume(rcdu->ddev, rcdu->suspend_state);
> + drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
>   drm_kms_helper_poll_enable(rcdu->ddev);
> +
>   return 0;
>  }
>  #endif
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.h
> b/drivers/gpu/drm/rcar-du/rcar_du_drv.h index f8cd79488ece..f400fde65a0c
> 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.h
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.h
> @@ -81,6 +81,7 @@ struct rcar_du_device {
> 
>   struct drm_device *ddev;
>   struct drm_fbdev_cma *fbdev;
> + struct drm_atomic_state *suspend_state;
> 
>   struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
>   unsigned int num_crtcs;


-- 
Regards,

Laurent Pinchart



Re: [PATCH v1 1/3] media: vsp1: Prevent resuming DRM pipelines

2017-09-15 Thread Laurent Pinchart
Hi Kieran,

Thank you for the patch.

On Friday, 15 September 2017 19:42:05 EEST Kieran Bingham wrote:
> DRM pipelines utilising the VSP must stop all frame processing as part
> of the suspend operation to ensure the hardware is idle. Upon resume,
> the pipeline must not be started until the DU performs an atomic flush
> to restore the hardware configuration and state.
> 
> Therefore the vsp1_pipeline_resume() call is not needed for DRM
> pipelines, and we can disable it in this instance.

Being familiar with the issue I certainly understand the commit message, but I 
think it can be a bit confusing to a reader not familiar to the VSP/DU. How 
about something similar to the following ?

"When used as part of a display pipeline, the VSP is stopped and restarted 
explicitly by the DU from its suspend and resume handlers. There is thus no 
need to stop or restart pipelines in the VSP suspend and resume handlers."

> CC: linux-media@vger.kernel.org
> 
> Signed-off-by: Kieran Bingham 
> ---
>  drivers/media/platform/vsp1/vsp1_drv.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/vsp1/vsp1_drv.c
> b/drivers/media/platform/vsp1/vsp1_drv.c index 962e4c304076..7604c7994c74
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_drv.c
> +++ b/drivers/media/platform/vsp1/vsp1_drv.c
> @@ -582,7 +582,13 @@ static int __maybe_unused vsp1_pm_resume(struct device
> *dev) struct vsp1_device *vsp1 = dev_get_drvdata(dev);
> 
>   pm_runtime_force_resume(vsp1->dev);
> - vsp1_pipelines_resume(vsp1);
> +
> + /*
> +  * DRM pipelines are stopped before suspend, and will be resumed after
> +  * the DRM subsystem has reconfigured its pipeline with an atomic flush
> +  */

I would also adapt this comment similarly to the commit message.

> + if (!vsp1->drm)
> + vsp1_pipelines_resume(vsp1);

Should we do the same in vsp1_pm_suspend() ? I know it shouldn't be strictly 
needed at the moment as vsp1_pipelines_suspend() should be a no-op when the 
pipelines are already stopped, but a symmetrical implementation sounds better 
to me.

I also wonder whether the check shouldn't be moved inside the 
vsp1_pipelines_suspend() and vsp1_pipelines_resume() functions as we will 
likely need to handle suspend/resume of display pipelines when adding 
writeback support, but we could do so later.

>   return 0;
>  }

-- 
Regards,

Laurent Pinchart



[PATCH v1 3/3] drm: rcar-du: Remove unused CRTC suspend/resume functions

2017-09-15 Thread Kieran Bingham
An early implementation of suspend-resume helpers are available in the
CRTC module, however they are unused and no longer needed.

With suspend and resume handled by the core DRM atomic helpers, we can
remove the unused functions.

CC: dri-de...@lists.freedesktop.org

Signed-off-by: Kieran Bingham 
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 35 +---
 1 file changed, 35 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c 
b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 301ea1a8018e..b492063a6e1f 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -557,41 +557,6 @@ static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
rcar_du_group_start_stop(rcrtc->group, false);
 }
 
-void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc)
-{
-   if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE))
-   rcar_du_vsp_disable(rcrtc);
-
-   rcar_du_crtc_stop(rcrtc);
-   rcar_du_crtc_put(rcrtc);
-}
-
-void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc)
-{
-   unsigned int i;
-
-   if (!rcrtc->crtc.state->active)
-   return;
-
-   rcar_du_crtc_get(rcrtc);
-   rcar_du_crtc_setup(rcrtc);
-
-   /* Commit the planes state. */
-   if (!rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) {
-   for (i = 0; i < rcrtc->group->num_planes; ++i) {
-   struct rcar_du_plane *plane = >group->planes[i];
-
-   if (plane->plane.state->crtc != >crtc)
-   continue;
-
-   rcar_du_plane_setup(plane);
-   }
-   }
-
-   rcar_du_crtc_update_planes(rcrtc);
-   rcar_du_crtc_start(rcrtc);
-}
-
 /* 
-
  * CRTC Functions
  */
-- 
git-series 0.9.1


[PATCH v1 0/3] drm/media: Implement DU Suspend and Resume on VSP pipelines

2017-09-15 Thread Kieran Bingham
This short series covers two subsystems and implements support for suspend and
resume operations on the DU pipelines on Gen3 Rcar platforms.

Patch 1: Prevent resuming DRM pipelines,
  - Ensures that the VSP does not incorrectly start DU pipelines.

Patch 2: Add suspend resume helpers
  - Makes use of the atomic helper functions to control the CRTCs
and fbdev emulation.

Patch 3: Remove unused CRTC suspend/resume functions
  - Cleans up some old, related but unused functions that are not
necessary to keep in the code base.

Whilst this is posted as a single series, there are no hard dependencies
between any of the three patches. They can be picked up independently as
and when they are successfully reviewed.

This series can be fetched from the following:

 git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git 
tags/vsp-du/du-suspend-resume/v1
  
It is based upon a merge of both the current linux-media master branch and the 
DRM drm-next tree.

Kieran Bingham (3):
  media: vsp1: Prevent resuming DRM pipelines
  drm: rcar-du: Add suspend resume helpers
  drm: rcar-du: Remove unused CRTC suspend/resume functions

 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 35 +---
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  | 18 +++---
 drivers/gpu/drm/rcar-du/rcar_du_drv.h  |  1 +-
 drivers/media/platform/vsp1/vsp1_drv.c |  8 +-
 4 files changed, 23 insertions(+), 39 deletions(-)

base-commit: 8d2ec9ae96657bbd539d88dbc9d01088f2c9ee63
-- 
git-series 0.9.1


[PATCH v1 1/3] media: vsp1: Prevent resuming DRM pipelines

2017-09-15 Thread Kieran Bingham
DRM pipelines utilising the VSP must stop all frame processing as part
of the suspend operation to ensure the hardware is idle. Upon resume,
the pipeline must not be started until the DU performs an atomic flush
to restore the hardware configuration and state.

Therefore the vsp1_pipeline_resume() call is not needed for DRM
pipelines, and we can disable it in this instance.

CC: linux-media@vger.kernel.org

Signed-off-by: Kieran Bingham 
---
 drivers/media/platform/vsp1/vsp1_drv.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index 962e4c304076..7604c7994c74 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -582,7 +582,13 @@ static int __maybe_unused vsp1_pm_resume(struct device 
*dev)
struct vsp1_device *vsp1 = dev_get_drvdata(dev);
 
pm_runtime_force_resume(vsp1->dev);
-   vsp1_pipelines_resume(vsp1);
+
+   /*
+* DRM pipelines are stopped before suspend, and will be resumed after
+* the DRM subsystem has reconfigured its pipeline with an atomic flush
+*/
+   if (!vsp1->drm)
+   vsp1_pipelines_resume(vsp1);
 
return 0;
 }
-- 
git-series 0.9.1


[PATCH v1 2/3] drm: rcar-du: Add suspend resume helpers

2017-09-15 Thread Kieran Bingham
The pipeline needs to ensure that the hardware is idle for suspend and
resume operations.

Implement suspend and resume functions using the DRM atomic helper
functions.

CC: dri-de...@lists.freedesktop.org

Signed-off-by: Kieran Bingham 
---
 drivers/gpu/drm/rcar-du/rcar_du_drv.c | 18 +++---
 drivers/gpu/drm/rcar-du/rcar_du_drv.h |  1 +
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c 
b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index 09fbceade6b1..01b91d0c169c 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -22,6 +22,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -267,9 +268,19 @@ static struct drm_driver rcar_du_driver = {
 static int rcar_du_pm_suspend(struct device *dev)
 {
struct rcar_du_device *rcdu = dev_get_drvdata(dev);
+   struct drm_atomic_state *state;
 
drm_kms_helper_poll_disable(rcdu->ddev);
-   /* TODO Suspend the CRTC */
+   drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, true);
+
+   state = drm_atomic_helper_suspend(rcdu->ddev);
+   if (IS_ERR(state)) {
+   drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
+   drm_kms_helper_poll_enable(rcdu->ddev);
+   return PTR_ERR(state);
+   }
+
+   rcdu->suspend_state = state;
 
return 0;
 }
@@ -278,9 +289,10 @@ static int rcar_du_pm_resume(struct device *dev)
 {
struct rcar_du_device *rcdu = dev_get_drvdata(dev);
 
-   /* TODO Resume the CRTC */
-
+   drm_atomic_helper_resume(rcdu->ddev, rcdu->suspend_state);
+   drm_fbdev_cma_set_suspend_unlocked(rcdu->fbdev, false);
drm_kms_helper_poll_enable(rcdu->ddev);
+
return 0;
 }
 #endif
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.h 
b/drivers/gpu/drm/rcar-du/rcar_du_drv.h
index f8cd79488ece..f400fde65a0c 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.h
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.h
@@ -81,6 +81,7 @@ struct rcar_du_device {
 
struct drm_device *ddev;
struct drm_fbdev_cma *fbdev;
+   struct drm_atomic_state *suspend_state;
 
struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
unsigned int num_crtcs;
-- 
git-series 0.9.1


[PATCH 2/2] [media] c8sectpfe: Improve two size determinations in c8sectpfe_frontend_attach()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 17:30:38 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c 
b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
index 1b23b188cd65..c3b09a9e30ec 100644
--- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
+++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
@@ -164,12 +164,10 @@ int c8sectpfe_frontend_attach(struct dvb_frontend **fe,
tda18212 = devm_kzalloc(c8sectpfe->device,
-   sizeof(struct tda18212_config),
+   sizeof(*tda18212),
GFP_KERNEL);
if (!tda18212)
return -ENOMEM;
 
-   memcpy(tda18212, _conf,
-   sizeof(struct tda18212_config));
-
+   memcpy(tda18212, _conf, sizeof(*tda18212));
tda18212->fe = (*fe);
 
tda18212_info.platform_data = tda18212;
-- 
2.14.1



[PATCH 1/2] [media] c8sectpfe: Delete an error message for a failed memory allocation in c8sectpfe_frontend_attach()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 17:20:48 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c 
b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
index 2c0015b1264d..1b23b188cd65 100644
--- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
+++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
@@ -166,7 +166,4 @@ int c8sectpfe_frontend_attach(struct dvb_frontend **fe,
GFP_KERNEL);
-   if (!tda18212) {
-   dev_err(c8sectpfe->device,
-   "%s: devm_kzalloc failed\n", __func__);
+   if (!tda18212)
return -ENOMEM;
-   }
 
-- 
2.14.1



[PATCH 0/2] [media] C8SECTPFE: Adjustments for c8sectpfe_frontend_attach()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 17:55:43 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation
  Improve two size determinations

 drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

-- 
2.14.1



[PATCH 2/2] vivid: add support for Y10 and Y12

2017-09-15 Thread Hans Verkuil
From: Hans Verkuil 

Add support for 10 and 12 bit luma formats.

Signed-off-by: Hans Verkuil 
---
 drivers/media/platform/vivid/vivid-vid-common.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/media/platform/vivid/vivid-vid-common.c 
b/drivers/media/platform/vivid/vivid-vid-common.c
index f0f423c7ca41..a651527d80db 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -188,6 +188,22 @@ struct vivid_fmt vivid_formats[] = {
.planes   = 1,
.buffers = 1,
},
+   {
+   .fourcc   = V4L2_PIX_FMT_Y10,
+   .vdownsampling = { 1 },
+   .bit_depth = { 16 },
+   .color_enc = TGP_COLOR_ENC_LUMA,
+   .planes   = 1,
+   .buffers = 1,
+   },
+   {
+   .fourcc   = V4L2_PIX_FMT_Y12,
+   .vdownsampling = { 1 },
+   .bit_depth = { 16 },
+   .color_enc = TGP_COLOR_ENC_LUMA,
+   .planes   = 1,
+   .buffers = 1,
+   },
{
.fourcc   = V4L2_PIX_FMT_Y16,
.vdownsampling = { 1 },
-- 
2.14.1



[PATCH 1/2] v4l2-tpg: add Y10 and Y12 support

2017-09-15 Thread Hans Verkuil
From: Hans Verkuil 

Support the 10 and 12 bit luma formats.

Signed-off-by: Hans Verkuil 
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index a772976cfe26..f96968c11312 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -238,6 +238,8 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
tpg->color_enc = TGP_COLOR_ENC_RGB;
break;
case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_Y10:
+   case V4L2_PIX_FMT_Y12:
case V4L2_PIX_FMT_Y16:
case V4L2_PIX_FMT_Y16_BE:
tpg->color_enc = TGP_COLOR_ENC_LUMA;
@@ -352,6 +354,8 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
case V4L2_PIX_FMT_YUV444:
case V4L2_PIX_FMT_YUV555:
case V4L2_PIX_FMT_YUV565:
+   case V4L2_PIX_FMT_Y10:
+   case V4L2_PIX_FMT_Y12:
case V4L2_PIX_FMT_Y16:
case V4L2_PIX_FMT_Y16_BE:
tpg->twopixelsize[0] = 2 * 2;
@@ -1056,6 +1060,14 @@ static void gen_twopix(struct tpg_data *tpg,
case V4L2_PIX_FMT_GREY:
buf[0][offset] = r_y_h;
break;
+   case V4L2_PIX_FMT_Y10:
+   buf[0][offset] = (r_y_h << 2) & 0xff;
+   buf[0][offset+1] = r_y_h >> 6;
+   break;
+   case V4L2_PIX_FMT_Y12:
+   buf[0][offset] = (r_y_h << 4) & 0xff;
+   buf[0][offset+1] = r_y_h >> 4;
+   break;
case V4L2_PIX_FMT_Y16:
/*
 * Ideally both bytes should be set to r_y_h, but then you won't
-- 
2.14.1



[PATCH] [media] sh_mobile_ceu_camera: Delete an error message for a failed memory allocation in sh_mobile_ceu_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 16:15:47 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c 
b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 36762ec954e7..28b1d6d1275a 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -1653,10 +1653,8 @@ static int sh_mobile_ceu_probe(struct platform_device 
*pdev)
}
 
pcdev = devm_kzalloc(>dev, sizeof(*pcdev), GFP_KERNEL);
-   if (!pcdev) {
-   dev_err(>dev, "Could not allocate pcdev\n");
+   if (!pcdev)
return -ENOMEM;
-   }
 
INIT_LIST_HEAD(>capture);
spin_lock_init(>lock);
-- 
2.14.1



[PATCH v13 22/25] et8ek8: Add support for flash and lens devices

2017-09-15 Thread Sakari Ailus
From: Pavel Machek 

Parse async sub-devices by using
v4l2_subdev_fwnode_reference_parse_sensor_common().

These types devices aren't directly related to the sensor, but are
nevertheless handled by the et8ek8 driver due to the relationship of these
component to the main part of the camera module --- the sensor.

[Sakari Ailus: Rename fwnode function, check for ret < 0 only.]
Signed-off-by: Pavel Machek 
Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/i2c/et8ek8/et8ek8_driver.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/et8ek8/et8ek8_driver.c 
b/drivers/media/i2c/et8ek8/et8ek8_driver.c
index c14f0fd6ded3..0ef1b8025935 100644
--- a/drivers/media/i2c/et8ek8/et8ek8_driver.c
+++ b/drivers/media/i2c/et8ek8/et8ek8_driver.c
@@ -34,10 +34,12 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #include "et8ek8_reg.h"
 
@@ -46,6 +48,7 @@
 #define ET8EK8_MAX_MSG 8
 
 struct et8ek8_sensor {
+   struct v4l2_async_notifier notifier;
struct v4l2_subdev subdev;
struct media_pad pad;
struct v4l2_mbus_framefmt format;
@@ -1446,6 +1449,11 @@ static int et8ek8_probe(struct i2c_client *client,
sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
sensor->subdev.internal_ops = _internal_ops;
 
+   ret = v4l2_async_notifier_parse_fwnode_sensor_common(
+   >dev, >notifier);
+   if (ret < 0)
+   goto err_release;
+
sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(>subdev.entity, 1, >pad);
if (ret < 0) {
@@ -1453,18 +1461,27 @@ static int et8ek8_probe(struct i2c_client *client,
goto err_mutex;
}
 
+   ret = v4l2_async_subdev_notifier_register(>subdev,
+ >notifier);
+   if (ret)
+   goto err_entity;
+
ret = v4l2_async_register_subdev(>subdev);
if (ret < 0)
-   goto err_entity;
+   goto err_async;
 
dev_dbg(dev, "initialized!\n");
 
return 0;
 
+err_async:
+   v4l2_async_notifier_unregister(>notifier);
 err_entity:
media_entity_cleanup(>subdev.entity);
 err_mutex:
mutex_destroy(>power_lock);
+err_release:
+   v4l2_async_notifier_release(>notifier);
return ret;
 }
 
@@ -1480,6 +1497,8 @@ static int __exit et8ek8_remove(struct i2c_client *client)
}
 
v4l2_device_unregister_subdev(>subdev);
+   v4l2_async_notifier_unregister(>notifier);
+   v4l2_async_notifier_release(>notifier);
device_remove_file(>dev, _attr_priv_mem);
v4l2_ctrl_handler_free(>ctrl_handler);
v4l2_async_unregister_subdev(>subdev);
-- 
2.11.0



[PATCH v13 14/25] v4l: async: Allow binding notifiers to sub-devices

2017-09-15 Thread Sakari Ailus
Registering a notifier has required the knowledge of struct v4l2_device
for the reason that sub-devices generally are registered to the
v4l2_device (as well as the media device, also available through
v4l2_device).

This information is not available for sub-device drivers at probe time.

What this patch does is that it allows registering notifiers without
having v4l2_device around. Instead the sub-device pointer is stored in the
notifier. Once the sub-device of the driver that registered the notifier
is registered, the notifier will gain the knowledge of the v4l2_device,
and the binding of async sub-devices from the sub-device driver's notifier
may proceed.

The root notifier's complete callback is only called when all sub-device
notifiers are completed.

Signed-off-by: Sakari Ailus 
---
 drivers/media/v4l2-core/v4l2-async.c | 218 ++-
 include/media/v4l2-async.h   |  16 ++-
 2 files changed, 203 insertions(+), 31 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 4be2f16af051..52fe22b9b6b4 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -53,6 +53,10 @@ static int v4l2_async_notifier_call_complete(struct 
v4l2_async_notifier *n)
return n->ops->complete(n);
 }
 
+static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
+  struct v4l2_subdev *sd,
+  struct v4l2_async_subdev *asd);
+
 static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
 #if IS_ENABLED(CONFIG_I2C)
@@ -124,14 +128,127 @@ static struct v4l2_async_subdev *v4l2_async_find_match(
return NULL;
 }
 
+/* Find the sub-device notifier registered by a sub-device driver. */
+static struct v4l2_async_notifier *v4l2_async_find_subdev_notifier(
+   struct v4l2_subdev *sd)
+{
+   struct v4l2_async_notifier *n;
+
+   list_for_each_entry(n, _list, list)
+   if (n->sd == sd)
+   return n;
+
+   return NULL;
+}
+
+/* Return true if all sub-device notifiers are complete, false otherwise. */
+static bool v4l2_async_subdev_notifiers_complete(
+   struct v4l2_async_notifier *notifier)
+{
+   struct v4l2_subdev *sd;
+
+   if (!list_empty(>waiting))
+   return false;
+
+   list_for_each_entry(sd, >done, async_list) {
+   struct v4l2_async_notifier *subdev_notifier =
+   v4l2_async_find_subdev_notifier(sd);
+
+   if (subdev_notifier &&
+   !v4l2_async_subdev_notifiers_complete(subdev_notifier))
+   return false;
+   }
+
+   return true;
+}
+
+/* Get v4l2_device related to the notifier if one can be found. */
+static struct v4l2_device *v4l2_async_notifier_find_v4l2_dev(
+   struct v4l2_async_notifier *notifier)
+{
+   while (notifier->parent)
+   notifier = notifier->parent;
+
+   return notifier->v4l2_dev;
+}
+
+/* Test all async sub-devices in a notifier for a match. */
+static int v4l2_async_notifier_try_all_subdevs(
+   struct v4l2_async_notifier *notifier)
+{
+   struct v4l2_subdev *sd;
+
+   if (!v4l2_async_notifier_find_v4l2_dev(notifier))
+   return 0;
+
+again:
+   list_for_each_entry(sd, _list, async_list) {
+   struct v4l2_async_subdev *asd;
+   int ret;
+
+   asd = v4l2_async_find_match(notifier, sd);
+   if (!asd)
+   continue;
+
+   ret = v4l2_async_match_notify(notifier, sd, asd);
+   if (ret < 0)
+   return ret;
+
+   /*
+* v4l2_async_match_notify() may lead to registering a
+* new notifier and thus changing the async subdevs
+* list. In order to proceed safely from here, restart
+* parsing the list from the beginning.
+*/
+   goto again;
+   }
+
+   return 0;
+}
+
+/* Try completing a notifier. */
+static int v4l2_async_notifier_try_complete(
+   struct v4l2_async_notifier *notifier)
+{
+   do {
+   int ret;
+
+   /* Any local async sub-devices left? */
+   if (!list_empty(>waiting))
+   return 0;
+
+   /*
+* Any sub-device notifiers waiting for async subdevs
+* to be bound?
+*/
+   if (!v4l2_async_subdev_notifiers_complete(notifier))
+   return 0;
+
+   /* Proceed completing the notifier */
+   ret = v4l2_async_notifier_call_complete(notifier);
+   if (ret < 0)
+   return ret;
+
+   /*
+* Obtain notifier's parent. If there is one, repeat
+* the process, otherwise we're done 

[PATCH v13 17/25] v4l: fwnode: Add a helper function for parsing generic references

2017-09-15 Thread Sakari Ailus
Add function v4l2_fwnode_reference_parse() for parsing them as async
sub-devices. This can be done on e.g. flash or lens async sub-devices that
are not part of but are associated with a sensor.

Signed-off-by: Sakari Ailus 
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 69 +++
 1 file changed, 69 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
b/drivers/media/v4l2-core/v4l2-fwnode.c
index 44ee35f6aad5..65e84ea1cc35 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -498,6 +498,75 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
 }
 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port);
 
+/*
+ * v4l2_fwnode_reference_parse - parse references for async sub-devices
+ * @dev: the device node the properties of which are parsed for references
+ * @notifier: the async notifier where the async subdevs will be added
+ * @prop: the name of the property
+ *
+ * Return: 0 on success
+ *-ENOENT if no entries were found
+ *-ENOMEM if memory allocation failed
+ *-EINVAL if property parsing failed
+ */
+static int v4l2_fwnode_reference_parse(
+   struct device *dev, struct v4l2_async_notifier *notifier,
+   const char *prop)
+{
+   struct fwnode_reference_args args;
+   unsigned int index;
+   int ret;
+
+   for (index = 0;
+!(ret = fwnode_property_get_reference_args(
+  dev_fwnode(dev), prop, NULL, 0, index, ));
+index++)
+   fwnode_handle_put(args.fwnode);
+
+   if (!index)
+   return -ENOENT;
+
+   /*
+* Note that right now both -ENODATA and -ENOENT may signal
+* out-of-bounds access. Return the error in cases other than that.
+*/
+   if (ret != -ENOENT && ret != -ENODATA)
+   return ret;
+
+   ret = v4l2_async_notifier_realloc(notifier,
+ notifier->num_subdevs + index);
+   if (ret)
+   return ret;
+
+   for (index = 0; !fwnode_property_get_reference_args(
+dev_fwnode(dev), prop, NULL, 0, index, );
+index++) {
+   struct v4l2_async_subdev *asd;
+
+   if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) {
+   ret = -EINVAL;
+   goto error;
+   }
+
+   asd = kzalloc(sizeof(*asd), GFP_KERNEL);
+   if (!asd) {
+   ret = -ENOMEM;
+   goto error;
+   }
+
+   notifier->subdevs[notifier->num_subdevs] = asd;
+   asd->match.fwnode.fwnode = args.fwnode;
+   asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
+   notifier->num_subdevs++;
+   }
+
+   return 0;
+
+error:
+   fwnode_handle_put(args.fwnode);
+   return ret;
+}
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Sakari Ailus ");
 MODULE_AUTHOR("Sylwester Nawrocki ");
-- 
2.11.0



[PATCH v13 21/25] smiapp: Add support for flash and lens devices

2017-09-15 Thread Sakari Ailus
Parse async sub-devices by using
v4l2_subdev_fwnode_reference_parse_sensor_common().

These types devices aren't directly related to the sensor, but are
nevertheless handled by the smiapp driver due to the relationship of these
component to the main part of the camera module --- the sensor.

This does not yet address providing the user space with information on how
to associate the sensor or lens devices but the kernel now has the
necessary information to do that.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 drivers/media/i2c/smiapp/smiapp-core.c | 38 +++---
 drivers/media/i2c/smiapp/smiapp.h  |  4 +++-
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c 
b/drivers/media/i2c/smiapp/smiapp-core.c
index 700f433261d0..a4735a96ea41 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -31,7 +31,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -2887,17 +2887,24 @@ static int smiapp_probe(struct i2c_client *client,
v4l2_i2c_subdev_init(>src->sd, client, _ops);
sensor->src->sd.internal_ops = _internal_src_ops;
 
+   rval = v4l2_async_notifier_parse_fwnode_sensor_common(
+   >dev, >notifier);
+   if (rval < 0)
+   return rval;
+
sensor->vana = devm_regulator_get(>dev, "vana");
if (IS_ERR(sensor->vana)) {
dev_err(>dev, "could not get regulator for vana\n");
-   return PTR_ERR(sensor->vana);
+   rval = PTR_ERR(sensor->vana);
+   goto out_release_async_notifier;
}
 
sensor->ext_clk = devm_clk_get(>dev, NULL);
if (IS_ERR(sensor->ext_clk)) {
dev_err(>dev, "could not get clock (%ld)\n",
PTR_ERR(sensor->ext_clk));
-   return -EPROBE_DEFER;
+   rval = -EPROBE_DEFER;
+   goto out_release_async_notifier;
}
 
rval = clk_set_rate(sensor->ext_clk, sensor->hwcfg->ext_clk);
@@ -2905,17 +2912,19 @@ static int smiapp_probe(struct i2c_client *client,
dev_err(>dev,
"unable to set clock freq to %u\n",
sensor->hwcfg->ext_clk);
-   return rval;
+   goto out_release_async_notifier;
}
 
sensor->xshutdown = devm_gpiod_get_optional(>dev, "xshutdown",
GPIOD_OUT_LOW);
-   if (IS_ERR(sensor->xshutdown))
-   return PTR_ERR(sensor->xshutdown);
+   if (IS_ERR(sensor->xshutdown)) {
+   rval = PTR_ERR(sensor->xshutdown);
+   goto out_release_async_notifier;
+   }
 
rval = smiapp_power_on(>dev);
if (rval < 0)
-   return rval;
+   goto out_release_async_notifier;
 
rval = smiapp_identify_module(sensor);
if (rval) {
@@ -3092,9 +3101,14 @@ static int smiapp_probe(struct i2c_client *client,
if (rval < 0)
goto out_media_entity_cleanup;
 
+   rval = v4l2_async_subdev_notifier_register(>src->sd,
+  >notifier);
+   if (rval)
+   goto out_media_entity_cleanup;
+
rval = v4l2_async_register_subdev(>src->sd);
if (rval < 0)
-   goto out_media_entity_cleanup;
+   goto out_unregister_async_notifier;
 
pm_runtime_set_active(>dev);
pm_runtime_get_noresume(>dev);
@@ -3105,6 +3119,9 @@ static int smiapp_probe(struct i2c_client *client,
 
return 0;
 
+out_unregister_async_notifier:
+   v4l2_async_notifier_unregister(>notifier);
+
 out_media_entity_cleanup:
media_entity_cleanup(>src->sd.entity);
 
@@ -3114,6 +3131,9 @@ static int smiapp_probe(struct i2c_client *client,
 out_power_off:
smiapp_power_off(>dev);
 
+out_release_async_notifier:
+   v4l2_async_notifier_release(>notifier);
+
return rval;
 }
 
@@ -3124,6 +3144,8 @@ static int smiapp_remove(struct i2c_client *client)
unsigned int i;
 
v4l2_async_unregister_subdev(subdev);
+   v4l2_async_notifier_unregister(>notifier);
+   v4l2_async_notifier_release(>notifier);
 
pm_runtime_disable(>dev);
if (!pm_runtime_status_suspended(>dev))
diff --git a/drivers/media/i2c/smiapp/smiapp.h 
b/drivers/media/i2c/smiapp/smiapp.h
index f74d695018b9..be92cb5713f4 100644
--- a/drivers/media/i2c/smiapp/smiapp.h
+++ b/drivers/media/i2c/smiapp/smiapp.h
@@ -20,9 +20,10 @@
 #define __SMIAPP_PRIV_H_
 
 #include 
+#include 
+#include 
 #include 
 #include 
-#include 
 
 #include "smiapp-pll.h"
 #include "smiapp-reg.h"
@@ -172,6 +173,7 @@ struct smiapp_subdev {
  * struct smiapp_sensor - Main device structure
  */
 struct smiapp_sensor {
+   struct 

[PATCH v13 18/25] v4l: fwnode: Add a helper function to obtain device / integer references

2017-09-15 Thread Sakari Ailus
v4l2_fwnode_reference_parse_int_prop() will find an fwnode such that under
the device's own fwnode, it will follow child fwnodes with the given
property-value pair and return the resulting fwnode.

Signed-off-by: Sakari Ailus 
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 201 ++
 1 file changed, 201 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
b/drivers/media/v4l2-core/v4l2-fwnode.c
index 65e84ea1cc35..968a345a288f 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -567,6 +567,207 @@ static int v4l2_fwnode_reference_parse(
return ret;
 }
 
+/*
+ * v4l2_fwnode_reference_get_int_prop - parse a reference with integer
+ * arguments
+ * @dev: struct device pointer
+ * @notifier: notifier for @dev
+ * @prop: the name of the property
+ * @index: the index of the reference to get
+ * @props: the array of integer property names
+ * @nprops: the number of integer property names in @nprops
+ *
+ * Find fwnodes referred to by a property @prop, then under that
+ * iteratively, @nprops times, follow each child node which has a
+ * property in @props array at a given child index the value of which
+ * matches the integer argument at an index.
+ *
+ * For example, if this function was called with arguments and values
+ * @dev corresponding to device "SEN", @prop == "flash-leds", @index
+ * == 1, @props == { "led" }, @nprops == 1, with the ASL snippet below
+ * it would return the node marked with THISONE. The @dev argument in
+ * the ASL below.
+ *
+ * Device (LED)
+ * {
+ * Name (_DSD, Package () {
+ * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
+ * Package () {
+ * Package () { "led0", "LED0" },
+ * Package () { "led1", "LED1" },
+ * }
+ * })
+ * Name (LED0, Package () {
+ * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ * Package () {
+ * Package () { "led", 0 },
+ * }
+ * })
+ * Name (LED1, Package () {
+ * // THISONE
+ * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ * Package () {
+ * Package () { "led", 1 },
+ * }
+ * })
+ * }
+ *
+ * Device (SEN)
+ * {
+ * Name (_DSD, Package () {
+ * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ * Package () {
+ * Package () {
+ * "flash-leds",
+ * Package () { ^LED, 0, ^LED, 1 },
+ * }
+ * }
+ * })
+ * }
+ *
+ * where
+ *
+ * LED LED driver device
+ * LED0First LED
+ * LED1Second LED
+ * SEN Camera sensor device (or another device the LED is
+ * related to)
+ *
+ * Return: 0 on success
+ *-ENOENT if no entries (or the property itself) were found
+ *-EINVAL if property parsing otherwise failed
+ *-ENOMEM if memory allocation failed
+ */
+static struct fwnode_handle *v4l2_fwnode_reference_get_int_prop(
+   struct fwnode_handle *fwnode, const char *prop, unsigned int index,
+   const char **props, unsigned int nprops)
+{
+   struct fwnode_reference_args fwnode_args;
+   unsigned int *args = fwnode_args.args;
+   struct fwnode_handle *child;
+   int ret;
+
+   /*
+* Obtain remote fwnode as well as the integer arguments.
+*
+* Note that right now both -ENODATA and -ENOENT may signal
+* out-of-bounds access. Return -ENOENT in that case.
+*/
+   ret = fwnode_property_get_reference_args(fwnode, prop, NULL, nprops,
+index, _args);
+   if (ret)
+   return ERR_PTR(ret == -ENODATA ? -ENOENT : ret);
+
+   /*
+* Find a node in the tree under the referred fwnode corresponding the
+* integer arguments.
+*/
+   fwnode = fwnode_args.fwnode;
+   while (nprops--) {
+   u32 val;
+
+   /* Loop over all child nodes under fwnode. */
+   fwnode_for_each_child_node(fwnode, child) {
+   if (fwnode_property_read_u32(child, *props, ))
+   continue;
+
+   /* Found property, see if its value matches. */
+   if (val == *args)
+   break;
+   }
+
+   fwnode_handle_put(fwnode);
+
+   /* No property found; return an error here. */
+   if (!child) {
+   fwnode = 

[PATCH v13 16/25] dt: bindings: Add lens-focus binding for image sensors

2017-09-15 Thread Sakari Ailus
The lens-focus property contains a phandle to the lens voice coil driver
that is associated to the sensor; typically both are contained in the same
camera module.

Signed-off-by: Sakari Ailus 
Acked-by: Pavel Machek 
Reviewed-by: Sebastian Reichel 
Acked-by: Rob Herring 
Acked-by: Hans Verkuil 
---
 Documentation/devicetree/bindings/media/video-interfaces.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/video-interfaces.txt 
b/Documentation/devicetree/bindings/media/video-interfaces.txt
index fdba30479b47..b535bdde861c 100644
--- a/Documentation/devicetree/bindings/media/video-interfaces.txt
+++ b/Documentation/devicetree/bindings/media/video-interfaces.txt
@@ -74,6 +74,8 @@ Optional properties
 - flash-leds: An array of phandles, each referring to a flash LED, a sub-node
   of the LED driver device node.
 
+- lens-focus: A phandle to the node of the focus lens controller.
+
 
 Optional endpoint properties
 
-- 
2.11.0



[PATCH v13 24/25] ov13858: Add support for flash and lens devices

2017-09-15 Thread Sakari Ailus
Parse async sub-devices by using
v4l2_subdev_fwnode_reference_parse_sensor_common().

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/i2c/ov13858.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index af7af0d14c69..a8a9fb0a1756 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define OV13858_REG_VALUE_08BIT1
 #define OV13858_REG_VALUE_16BIT2
@@ -1028,6 +1029,7 @@ static const struct ov13858_mode supported_modes[] = {
 struct ov13858 {
struct v4l2_subdev sd;
struct media_pad pad;
+   struct v4l2_async_notifier notifier;
 
struct v4l2_ctrl_handler ctrl_handler;
/* V4L2 Controls */
@@ -1715,6 +1717,11 @@ static int ov13858_probe(struct i2c_client *client,
if (!ov13858)
return -ENOMEM;
 
+   ret = v4l2_async_notifier_parse_fwnode_sensor_common(
+   >dev, >notifier);
+   if (ret < 0)
+   return ret;
+
/* Initialize subdev */
v4l2_i2c_subdev_init(>sd, client, _subdev_ops);
 
@@ -1722,7 +1729,7 @@ static int ov13858_probe(struct i2c_client *client,
ret = ov13858_identify_module(ov13858);
if (ret) {
dev_err(>dev, "failed to find sensor: %d\n", ret);
-   return ret;
+   goto error_notifier_release;
}
 
/* Set default mode to max resolution */
@@ -1730,7 +1737,7 @@ static int ov13858_probe(struct i2c_client *client,
 
ret = ov13858_init_controls(ov13858);
if (ret)
-   return ret;
+   goto error_notifier_release;
 
/* Initialize subdev */
ov13858->sd.internal_ops = _internal_ops;
@@ -1746,9 +1753,14 @@ static int ov13858_probe(struct i2c_client *client,
goto error_handler_free;
}
 
+   ret = v4l2_async_subdev_notifier_register(>sd,
+ >notifier);
+   if (ret)
+   goto error_media_entity;
+
ret = v4l2_async_register_subdev(>sd);
if (ret < 0)
-   goto error_media_entity;
+   goto error_notifier_unregister;
 
/*
 * Device is already turned on by i2c-core with ACPI domain PM.
@@ -1761,11 +1773,17 @@ static int ov13858_probe(struct i2c_client *client,
 
return 0;
 
+error_notifier_unregister:
+   v4l2_async_notifier_unregister(>notifier);
+
 error_media_entity:
media_entity_cleanup(>sd.entity);
 
 error_handler_free:
ov13858_free_controls(ov13858);
+
+error_notifier_release:
+   v4l2_async_notifier_release(>notifier);
dev_err(>dev, "%s failed:%d\n", __func__, ret);
 
return ret;
@@ -1777,6 +1795,8 @@ static int ov13858_remove(struct i2c_client *client)
struct ov13858 *ov13858 = to_ov13858(sd);
 
v4l2_async_unregister_subdev(sd);
+   v4l2_async_notifier_unregister(>notifier);
+   v4l2_async_notifier_release(>notifier);
media_entity_cleanup(>entity);
ov13858_free_controls(ov13858);
 
-- 
2.11.0



[PATCH v13 25/25] arm: dts: omap3: N9/N950: Add flash references to the camera

2017-09-15 Thread Sakari Ailus
Add flash and indicator LED phandles to the sensor node.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 arch/arm/boot/dts/omap3-n9.dts   | 1 +
 arch/arm/boot/dts/omap3-n950-n9.dtsi | 4 ++--
 arch/arm/boot/dts/omap3-n950.dts | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/omap3-n9.dts b/arch/arm/boot/dts/omap3-n9.dts
index b9e58c536afd..39e35f8b8206 100644
--- a/arch/arm/boot/dts/omap3-n9.dts
+++ b/arch/arm/boot/dts/omap3-n9.dts
@@ -26,6 +26,7 @@
clocks = < 0>;
clock-frequency = <960>;
nokia,nvm-size = <(16 * 64)>;
+   flash-leds = <_flash _indicator>;
port {
smia_1_1: endpoint {
link-frequencies = /bits/ 64 <19920 
21000 49920>;
diff --git a/arch/arm/boot/dts/omap3-n950-n9.dtsi 
b/arch/arm/boot/dts/omap3-n950-n9.dtsi
index 1b0bd72945f2..12fbb3da5fce 100644
--- a/arch/arm/boot/dts/omap3-n950-n9.dtsi
+++ b/arch/arm/boot/dts/omap3-n950-n9.dtsi
@@ -271,14 +271,14 @@
#size-cells = <0>;
reg = <0x30>;
compatible = "ams,as3645a";
-   flash@0 {
+   as3645a_flash: flash@0 {
reg = <0x0>;
flash-timeout-us = <15>;
flash-max-microamp = <32>;
led-max-microamp = <6>;
ams,input-max-microamp = <175>;
};
-   indicator@1 {
+   as3645a_indicator: indicator@1 {
reg = <0x1>;
led-max-microamp = <1>;
};
diff --git a/arch/arm/boot/dts/omap3-n950.dts b/arch/arm/boot/dts/omap3-n950.dts
index 646601a3ebd8..c354a1ed1e70 100644
--- a/arch/arm/boot/dts/omap3-n950.dts
+++ b/arch/arm/boot/dts/omap3-n950.dts
@@ -60,6 +60,7 @@
clocks = < 0>;
clock-frequency = <960>;
nokia,nvm-size = <(16 * 64)>;
+   flash-leds = <_flash _indicator>;
port {
smia_1_1: endpoint {
link-frequencies = /bits/ 64 <21000 
33360 39840>;
-- 
2.11.0



[PATCH v13 23/25] ov5670: Add support for flash and lens devices

2017-09-15 Thread Sakari Ailus
Parse async sub-devices by using
v4l2_subdev_fwnode_reference_parse_sensor_common().

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/i2c/ov5670.c | 33 +
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
index 6f7a1d6d2200..a791701fa2b9 100644
--- a/drivers/media/i2c/ov5670.c
+++ b/drivers/media/i2c/ov5670.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define OV5670_REG_CHIP_ID 0x300a
 #define OV5670_CHIP_ID 0x005670
@@ -1807,6 +1808,7 @@ static const struct ov5670_mode supported_modes[] = {
 struct ov5670 {
struct v4l2_subdev sd;
struct media_pad pad;
+   struct v4l2_async_notifier notifier;
 
struct v4l2_ctrl_handler ctrl_handler;
/* V4L2 Controls */
@@ -2473,11 +2475,13 @@ static int ov5670_probe(struct i2c_client *client)
return -EINVAL;
 
ov5670 = devm_kzalloc(>dev, sizeof(*ov5670), GFP_KERNEL);
-   if (!ov5670) {
-   ret = -ENOMEM;
-   err_msg = "devm_kzalloc() error";
-   goto error_print;
-   }
+   if (!ov5670)
+   return -ENOMEM;
+
+   ret = v4l2_async_notifier_parse_fwnode_sensor_common(
+   >dev, >notifier);
+   if (ret < 0)
+   return ret;
 
/* Initialize subdev */
v4l2_i2c_subdev_init(>sd, client, _subdev_ops);
@@ -2486,7 +2490,7 @@ static int ov5670_probe(struct i2c_client *client)
ret = ov5670_identify_module(ov5670);
if (ret) {
err_msg = "ov5670_identify_module() error";
-   goto error_print;
+   goto error_release_notifier;
}
 
mutex_init(>mutex);
@@ -2513,11 +2517,18 @@ static int ov5670_probe(struct i2c_client *client)
goto error_handler_free;
}
 
+   ret = v4l2_async_subdev_notifier_register(>sd,
+ >notifier);
+   if (ret) {
+   err_msg = "can't register async notifier";
+   goto error_entity_cleanup;
+   }
+
/* Async register for subdev */
ret = v4l2_async_register_subdev(>sd);
if (ret < 0) {
err_msg = "v4l2_async_register_subdev() error";
-   goto error_entity_cleanup;
+   goto error_unregister_notifier;
}
 
ov5670->streaming = false;
@@ -2533,6 +2544,9 @@ static int ov5670_probe(struct i2c_client *client)
 
return 0;
 
+error_unregister_notifier:
+   v4l2_async_notifier_unregister(>notifier);
+
 error_entity_cleanup:
media_entity_cleanup(>sd.entity);
 
@@ -2542,7 +2556,8 @@ static int ov5670_probe(struct i2c_client *client)
 error_mutex_destroy:
mutex_destroy(>mutex);
 
-error_print:
+error_release_notifier:
+   v4l2_async_notifier_release(>notifier);
dev_err(>dev, "%s: %s %d\n", __func__, err_msg, ret);
 
return ret;
@@ -2554,6 +2569,8 @@ static int ov5670_remove(struct i2c_client *client)
struct ov5670 *ov5670 = to_ov5670(sd);
 
v4l2_async_unregister_subdev(sd);
+   v4l2_async_notifier_unregister(>notifier);
+   v4l2_async_notifier_release(>notifier);
media_entity_cleanup(>entity);
v4l2_ctrl_handler_free(sd->ctrl_handler);
mutex_destroy(>mutex);
-- 
2.11.0



[PATCH v13 15/25] dt: bindings: Add a binding for flash LED devices associated to a sensor

2017-09-15 Thread Sakari Ailus
Camera flash drivers (and LEDs) are separate from the sensor devices in
DT. In order to make an association between the two, provide the
association information to the software.

Signed-off-by: Sakari Ailus 
Acked-by: Rob Herring 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 Documentation/devicetree/bindings/media/video-interfaces.txt | 8 
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/video-interfaces.txt 
b/Documentation/devicetree/bindings/media/video-interfaces.txt
index 852041a7480c..fdba30479b47 100644
--- a/Documentation/devicetree/bindings/media/video-interfaces.txt
+++ b/Documentation/devicetree/bindings/media/video-interfaces.txt
@@ -67,6 +67,14 @@ are required in a relevant parent node:
identifier, should be 1.
  - #size-cells: should be zero.
 
+
+Optional properties
+---
+
+- flash-leds: An array of phandles, each referring to a flash LED, a sub-node
+  of the LED driver device node.
+
+
 Optional endpoint properties
 
 
-- 
2.11.0



[PATCH v13 20/25] dt: bindings: smiapp: Document lens-focus and flash-leds properties

2017-09-15 Thread Sakari Ailus
Document optional lens-focus and flash-leds properties for the smiapp
driver.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 Documentation/devicetree/bindings/media/i2c/nokia,smia.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt 
b/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
index 855e1faf73e2..33f10a94c381 100644
--- a/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
+++ b/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
@@ -27,6 +27,8 @@ Optional properties
 - nokia,nvm-size: The size of the NVM, in bytes. If the size is not given,
   the NVM contents will not be read.
 - reset-gpios: XSHUTDOWN GPIO
+- flash-leds: See ../video-interfaces.txt
+- lens-focus: See ../video-interfaces.txt
 
 
 Endpoint node mandatory properties
-- 
2.11.0



[PATCH v13 19/25] v4l: fwnode: Add convenience function for parsing common external refs

2017-09-15 Thread Sakari Ailus
Add v4l2_fwnode_parse_reference_sensor_common for parsing common
sensor properties that refer to adjacent devices such as flash or lens
driver chips.

As this is an association only, there's little a regular driver needs to
know about these devices as such.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 35 +++
 include/media/v4l2-async.h|  3 ++-
 include/media/v4l2-fwnode.h   | 21 +
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
b/drivers/media/v4l2-core/v4l2-fwnode.c
index 968a345a288f..7de2fd195e19 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -768,6 +768,41 @@ static int v4l2_fwnode_reference_parse_int_props(
return ret;
 }
 
+int v4l2_async_notifier_parse_fwnode_sensor_common(
+   struct device *dev, struct v4l2_async_notifier *notifier)
+{
+   static const char *led_props[] = { "led" };
+   static const struct {
+   const char *name;
+   const char **props;
+   unsigned int nprops;
+   } props[] = {
+   { "flash-leds", led_props, ARRAY_SIZE(led_props) },
+   { "lens-focus", NULL, 0 },
+   };
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(props); i++) {
+   int ret;
+
+   if (props[i].props && is_acpi_node(dev_fwnode(dev)))
+   ret = v4l2_fwnode_reference_parse_int_props(
+   dev, notifier, props[i].name,
+   props[i].props, props[i].nprops);
+   else
+   ret = v4l2_fwnode_reference_parse(
+   dev, notifier, props[i].name);
+   if (ret && ret != -ENOENT) {
+   dev_warn(dev, "parsing property \"%s\" failed (%d)\n",
+props[i].name, ret);
+   return ret;
+   }
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Sakari Ailus ");
 MODULE_AUTHOR("Sylwester Nawrocki ");
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index a13803a6371d..378e20e3b44d 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -155,7 +155,8 @@ void v4l2_async_notifier_unregister(struct 
v4l2_async_notifier *notifier);
  * Release memory resources related to a notifier, including the async
  * sub-devices allocated for the purposes of the notifier. The user is
  * responsible for releasing the notifier's resources after calling
- * @v4l2_async_notifier_parse_fwnode_endpoints.
+ * @v4l2_async_notifier_parse_fwnode_endpoints or
+ * @v4l2_fwnode_reference_parse_sensor_common.
  *
  * There is no harm from calling v4l2_async_notifier_release in other
  * cases as long as its memory has been zeroed after it has been
diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index 83afac48ea6b..7f315383c0ae 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -318,4 +318,25 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
  struct v4l2_fwnode_endpoint *vep,
  struct v4l2_async_subdev *asd));
 
+/**
+ * v4l2_fwnode_reference_parse_sensor_common - parse common references on
+ *sensors for async sub-devices
+ * @dev: the device node the properties of which are parsed for references
+ * @notifier: the async notifier where the async subdevs will be added
+ *
+ * Parse common sensor properties for remote devices related to the
+ * sensor and set up async sub-devices for them.
+ *
+ * Any notifier populated using this function must be released with a call to
+ * v4l2_async_notifier_release() after it has been unregistered and the async
+ * sub-devices are no longer in use, even in the case the function returned an
+ * error.
+ *
+ * Return: 0 on success
+ *-ENOMEM if memory allocation failed
+ *-EINVAL if property parsing failed
+ */
+int v4l2_async_notifier_parse_fwnode_sensor_common(
+   struct device *dev, struct v4l2_async_notifier *notifier);
+
 #endif /* _V4L2_FWNODE_H */
-- 
2.11.0



[PATCH v13 07/25] rcar-vin: Use generic parser for parsing fwnode endpoints

2017-09-15 Thread Sakari Ailus
Instead of using driver implementation, use
v4l2_async_notifier_parse_fwnode_endpoints() to parse the fwnode endpoints
of the device.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 112 +---
 drivers/media/platform/rcar-vin/rcar-dma.c  |  10 +--
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  14 ++--
 drivers/media/platform/rcar-vin/rcar-vin.h  |   4 +-
 4 files changed, 48 insertions(+), 92 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 142de447..62b4a94f9a39 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "rcar-vin.h"
@@ -77,14 +78,14 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
int ret;
 
/* Verify subdevices mbus format */
-   if (!rvin_mbus_supported(>digital)) {
+   if (!rvin_mbus_supported(vin->digital)) {
vin_err(vin, "Unsupported media bus format for %s\n",
-   vin->digital.subdev->name);
+   vin->digital->subdev->name);
return -EINVAL;
}
 
vin_dbg(vin, "Found media bus format for %s: %d\n",
-   vin->digital.subdev->name, vin->digital.code);
+   vin->digital->subdev->name, vin->digital->code);
 
ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
if (ret < 0) {
@@ -103,7 +104,7 @@ static void rvin_digital_notify_unbind(struct 
v4l2_async_notifier *notifier,
 
vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
rvin_v4l2_remove(vin);
-   vin->digital.subdev = NULL;
+   vin->digital->subdev = NULL;
 }
 
 static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier,
@@ -120,117 +121,70 @@ static int rvin_digital_notify_bound(struct 
v4l2_async_notifier *notifier,
ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SOURCE);
if (ret < 0)
return ret;
-   vin->digital.source_pad = ret;
+   vin->digital->source_pad = ret;
 
ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK);
-   vin->digital.sink_pad = ret < 0 ? 0 : ret;
+   vin->digital->sink_pad = ret < 0 ? 0 : ret;
 
-   vin->digital.subdev = subdev;
+   vin->digital->subdev = subdev;
 
vin_dbg(vin, "bound subdev %s source pad: %u sink pad: %u\n",
-   subdev->name, vin->digital.source_pad,
-   vin->digital.sink_pad);
+   subdev->name, vin->digital->source_pad,
+   vin->digital->sink_pad);
 
return 0;
 }
 
-static int rvin_digitial_parse_v4l2(struct rvin_dev *vin,
-   struct device_node *ep,
-   struct v4l2_mbus_config *mbus_cfg)
+static int rvin_digital_parse_v4l2(struct device *dev,
+  struct v4l2_fwnode_endpoint *vep,
+  struct v4l2_async_subdev *asd)
 {
-   struct v4l2_fwnode_endpoint v4l2_ep;
-   int ret;
+   struct rvin_dev *vin = dev_get_drvdata(dev);
+   struct rvin_graph_entity *rvge =
+   container_of(asd, struct rvin_graph_entity, asd);
 
-   ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), _ep);
-   if (ret) {
-   vin_err(vin, "Could not parse v4l2 endpoint\n");
-   return -EINVAL;
-   }
+   if (vep->base.port || vep->base.id)
+   return -ENOTCONN;
 
-   mbus_cfg->type = v4l2_ep.bus_type;
+   rvge->mbus_cfg.type = vep->bus_type;
 
-   switch (mbus_cfg->type) {
+   switch (rvge->mbus_cfg.type) {
case V4L2_MBUS_PARALLEL:
vin_dbg(vin, "Found PARALLEL media bus\n");
-   mbus_cfg->flags = v4l2_ep.bus.parallel.flags;
+   rvge->mbus_cfg.flags = vep->bus.parallel.flags;
break;
case V4L2_MBUS_BT656:
vin_dbg(vin, "Found BT656 media bus\n");
-   mbus_cfg->flags = 0;
+   rvge->mbus_cfg.flags = 0;
break;
default:
vin_err(vin, "Unknown media bus type\n");
return -EINVAL;
}
 
-   return 0;
-}
-
-static int rvin_digital_graph_parse(struct rvin_dev *vin)
-{
-   struct device_node *ep, *np;
-   int ret;
-
-   vin->digital.asd.match.fwnode.fwnode = NULL;
-   vin->digital.subdev = NULL;
-
-   /*
-* Port 0 id 0 is local digital input, try to get it.
-* Not all instances can or will have this, that is OK
-*/
-   ep = of_graph_get_endpoint_by_regs(vin->dev->of_node, 0, 0);
-   if (!ep)
-   return 0;
-
-   np = of_graph_get_remote_port_parent(ep);
-   if (!np) {
-   vin_err(vin, "No remote parent 

[PATCH v13 06/25] omap3isp: Use generic parser for parsing fwnode endpoints

2017-09-15 Thread Sakari Ailus
Instead of using driver implementation, use
v4l2_async_notifier_parse_fwnode_endpoints() to parse the fwnode endpoints
of the device.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/platform/omap3isp/isp.c | 115 +++---
 drivers/media/platform/omap3isp/isp.h |   5 +-
 2 files changed, 37 insertions(+), 83 deletions(-)

diff --git a/drivers/media/platform/omap3isp/isp.c 
b/drivers/media/platform/omap3isp/isp.c
index 1a428fe9f070..a546cf774d40 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2001,6 +2001,7 @@ static int isp_remove(struct platform_device *pdev)
__omap3isp_put(isp, false);
 
media_entity_enum_cleanup(>crashed);
+   v4l2_async_notifier_release(>notifier);
 
return 0;
 }
@@ -2011,44 +2012,41 @@ enum isp_of_phy {
ISP_OF_PHY_CSIPHY2,
 };
 
-static int isp_fwnode_parse(struct device *dev, struct fwnode_handle *fwnode,
-   struct isp_async_subdev *isd)
+static int isp_fwnode_parse(struct device *dev,
+   struct v4l2_fwnode_endpoint *vep,
+   struct v4l2_async_subdev *asd)
 {
+   struct isp_async_subdev *isd =
+   container_of(asd, struct isp_async_subdev, asd);
struct isp_bus_cfg *buscfg = >bus;
-   struct v4l2_fwnode_endpoint vep;
-   unsigned int i;
-   int ret;
bool csi1 = false;
-
-   ret = v4l2_fwnode_endpoint_parse(fwnode, );
-   if (ret)
-   return ret;
+   unsigned int i;
 
dev_dbg(dev, "parsing endpoint %pOF, interface %u\n",
-   to_of_node(fwnode), vep.base.port);
+   to_of_node(vep->base.local_fwnode), vep->base.port);
 
-   switch (vep.base.port) {
+   switch (vep->base.port) {
case ISP_OF_PHY_PARALLEL:
buscfg->interface = ISP_INTERFACE_PARALLEL;
buscfg->bus.parallel.data_lane_shift =
-   vep.bus.parallel.data_shift;
+   vep->bus.parallel.data_shift;
buscfg->bus.parallel.clk_pol =
-   !!(vep.bus.parallel.flags
+   !!(vep->bus.parallel.flags
   & V4L2_MBUS_PCLK_SAMPLE_FALLING);
buscfg->bus.parallel.hs_pol =
-   !!(vep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW);
+   !!(vep->bus.parallel.flags & 
V4L2_MBUS_VSYNC_ACTIVE_LOW);
buscfg->bus.parallel.vs_pol =
-   !!(vep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW);
+   !!(vep->bus.parallel.flags & 
V4L2_MBUS_HSYNC_ACTIVE_LOW);
buscfg->bus.parallel.fld_pol =
-   !!(vep.bus.parallel.flags & V4L2_MBUS_FIELD_EVEN_LOW);
+   !!(vep->bus.parallel.flags & V4L2_MBUS_FIELD_EVEN_LOW);
buscfg->bus.parallel.data_pol =
-   !!(vep.bus.parallel.flags & V4L2_MBUS_DATA_ACTIVE_LOW);
-   buscfg->bus.parallel.bt656 = vep.bus_type == V4L2_MBUS_BT656;
+   !!(vep->bus.parallel.flags & V4L2_MBUS_DATA_ACTIVE_LOW);
+   buscfg->bus.parallel.bt656 = vep->bus_type == V4L2_MBUS_BT656;
break;
 
case ISP_OF_PHY_CSIPHY1:
case ISP_OF_PHY_CSIPHY2:
-   switch (vep.bus_type) {
+   switch (vep->bus_type) {
case V4L2_MBUS_CCP2:
case V4L2_MBUS_CSI1:
dev_dbg(dev, "CSI-1/CCP-2 configuration\n");
@@ -2060,11 +2058,11 @@ static int isp_fwnode_parse(struct device *dev, struct 
fwnode_handle *fwnode,
break;
default:
dev_err(dev, "unsupported bus type %u\n",
-   vep.bus_type);
+   vep->bus_type);
return -EINVAL;
}
 
-   switch (vep.base.port) {
+   switch (vep->base.port) {
case ISP_OF_PHY_CSIPHY1:
if (csi1)
buscfg->interface = ISP_INTERFACE_CCP2B_PHY1;
@@ -2080,47 +2078,47 @@ static int isp_fwnode_parse(struct device *dev, struct 
fwnode_handle *fwnode,
}
if (csi1) {
buscfg->bus.ccp2.lanecfg.clk.pos =
-   vep.bus.mipi_csi1.clock_lane;
+   vep->bus.mipi_csi1.clock_lane;
buscfg->bus.ccp2.lanecfg.clk.pol =
-   vep.bus.mipi_csi1.lane_polarity[0];
+   vep->bus.mipi_csi1.lane_polarity[0];
dev_dbg(dev, "clock lane polarity %u, pos %u\n",
buscfg->bus.ccp2.lanecfg.clk.pol,

[PATCH v13 08/25] omap3isp: Fix check for our own sub-devices

2017-09-15 Thread Sakari Ailus
We only want to link sub-devices that were bound to the async notifier the
isp driver registered but there may be other sub-devices in the
v4l2_device as well. Check for the correct async notifier.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 drivers/media/platform/omap3isp/isp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/omap3isp/isp.c 
b/drivers/media/platform/omap3isp/isp.c
index a546cf774d40..3b1a9cd0e591 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2155,7 +2155,7 @@ static int isp_subdev_notifier_complete(struct 
v4l2_async_notifier *async)
return ret;
 
list_for_each_entry(sd, _dev->subdevs, list) {
-   if (!sd->asd)
+   if (sd->notifier != >notifier)
continue;
 
ret = isp_link_entity(isp, >entity,
-- 
2.11.0



[PATCH v13 11/25] v4l: async: Introduce helpers for calling async ops callbacks

2017-09-15 Thread Sakari Ailus
Add three helper functions to call async operations callbacks. Besides
simplifying callbacks, this allows async notifiers to have no ops set,
i.e. it can be left NULL.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-async.c | 49 ++--
 include/media/v4l2-async.h   |  1 +
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 7b2125b3d62f..c35d04b9122f 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -25,6 +25,34 @@
 #include 
 #include 
 
+static int v4l2_async_notifier_call_bound(struct v4l2_async_notifier *n,
+ struct v4l2_subdev *subdev,
+ struct v4l2_async_subdev *asd)
+{
+   if (!n->ops || !n->ops->bound)
+   return 0;
+
+   return n->ops->bound(n, subdev, asd);
+}
+
+static void v4l2_async_notifier_call_unbind(struct v4l2_async_notifier *n,
+   struct v4l2_subdev *subdev,
+   struct v4l2_async_subdev *asd)
+{
+   if (!n->ops || !n->ops->unbind)
+   return;
+
+   n->ops->unbind(n, subdev, asd);
+}
+
+static int v4l2_async_notifier_call_complete(struct v4l2_async_notifier *n)
+{
+   if (!n->ops || !n->ops->complete)
+   return 0;
+
+   return n->ops->complete(n);
+}
+
 static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
 #if IS_ENABLED(CONFIG_I2C)
@@ -102,16 +130,13 @@ static int v4l2_async_match_notify(struct 
v4l2_async_notifier *notifier,
 {
int ret;
 
-   if (notifier->ops->bound) {
-   ret = notifier->ops->bound(notifier, sd, asd);
-   if (ret < 0)
-   return ret;
-   }
+   ret = v4l2_async_notifier_call_bound(notifier, sd, asd);
+   if (ret < 0)
+   return ret;
 
ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
if (ret < 0) {
-   if (notifier->ops->unbind)
-   notifier->ops->unbind(notifier, sd, asd);
+   v4l2_async_notifier_call_unbind(notifier, sd, asd);
return ret;
}
 
@@ -123,8 +148,8 @@ static int v4l2_async_match_notify(struct 
v4l2_async_notifier *notifier,
/* Move from the global subdevice list to notifier's done */
list_move(>async_list, >done);
 
-   if (list_empty(>waiting) && notifier->ops->complete)
-   return notifier->ops->complete(notifier);
+   if (list_empty(>waiting))
+   return v4l2_async_notifier_call_complete(notifier);
 
return 0;
 }
@@ -210,8 +235,7 @@ void v4l2_async_notifier_unregister(struct 
v4l2_async_notifier *notifier)
list_for_each_entry_safe(sd, tmp, >done, async_list) {
v4l2_async_cleanup(sd);
 
-   if (notifier->ops->unbind)
-   notifier->ops->unbind(notifier, sd, sd->asd);
+   v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
}
 
mutex_unlock(_lock);
@@ -300,8 +324,7 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 
v4l2_async_cleanup(sd);
 
-   if (notifier->ops->unbind)
-   notifier->ops->unbind(notifier, sd, sd->asd);
+   v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
 
mutex_unlock(_lock);
 }
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index 3c48f8b66d12..3bc8a7c0d83f 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -164,4 +164,5 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  * @sd: pointer to  v4l2_subdev
  */
 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
+
 #endif
-- 
2.11.0



[PATCH v13 10/25] v4l: async: Move async subdev notifier operations to a separate structure

2017-09-15 Thread Sakari Ailus
From: Laurent Pinchart 

The async subdev notifier .bound(), .unbind() and .complete() operations
are function pointers stored directly in the v4l2_async_subdev
structure. As the structure isn't immutable, this creates a potential
security risk as the function pointers are mutable.

To fix this, move the function pointers to a new
v4l2_async_subdev_operations structure that can be made const in
drivers.

Signed-off-by: Laurent Pinchart 
Acked-by: Hans Verkuil 
---
 drivers/media/platform/am437x/am437x-vpfe.c|  8 +--
 drivers/media/platform/atmel/atmel-isc.c   | 10 ++---
 drivers/media/platform/atmel/atmel-isi.c   | 10 ++---
 drivers/media/platform/davinci/vpif_capture.c  |  8 +--
 drivers/media/platform/davinci/vpif_display.c  |  8 +--
 drivers/media/platform/exynos4-is/media-dev.c  |  8 +--
 drivers/media/platform/omap3isp/isp.c  |  6 +-
 drivers/media/platform/pxa_camera.c|  8 +--
 drivers/media/platform/qcom/camss-8x16/camss.c |  8 +--
 drivers/media/platform/rcar-vin/rcar-core.c| 10 ++---
 drivers/media/platform/rcar_drif.c | 10 ++---
 drivers/media/platform/soc_camera/soc_camera.c | 14 +++--
 drivers/media/platform/stm32/stm32-dcmi.c  | 10 ++---
 drivers/media/platform/ti-vpe/cal.c|  8 +--
 drivers/media/platform/xilinx/xilinx-vipp.c|  8 +--
 drivers/media/v4l2-core/v4l2-async.c   | 20 +-
 drivers/staging/media/imx/imx-media-dev.c  |  8 +--
 include/media/v4l2-async.h | 29 +-
 18 files changed, 131 insertions(+), 60 deletions(-)

diff --git a/drivers/media/platform/am437x/am437x-vpfe.c 
b/drivers/media/platform/am437x/am437x-vpfe.c
index dfcc484cab89..0997c640191d 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -2417,6 +2417,11 @@ static int vpfe_async_complete(struct 
v4l2_async_notifier *notifier)
return vpfe_probe_complete(vpfe);
 }
 
+static const struct v4l2_async_notifier_operations vpfe_async_ops = {
+   .bound = vpfe_async_bound,
+   .complete = vpfe_async_complete,
+};
+
 static struct vpfe_config *
 vpfe_get_pdata(struct platform_device *pdev)
 {
@@ -2590,8 +2595,7 @@ static int vpfe_probe(struct platform_device *pdev)
 
vpfe->notifier.subdevs = vpfe->cfg->asd;
vpfe->notifier.num_subdevs = ARRAY_SIZE(vpfe->cfg->asd);
-   vpfe->notifier.bound = vpfe_async_bound;
-   vpfe->notifier.complete = vpfe_async_complete;
+   vpfe->notifier.ops = _async_ops;
ret = v4l2_async_notifier_register(>v4l2_dev,
>notifier);
if (ret) {
diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index d7103c5f92c3..48544c4137cb 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -1639,6 +1639,12 @@ static int isc_async_complete(struct v4l2_async_notifier 
*notifier)
return 0;
 }
 
+static const struct v4l2_async_notifier_operations isc_async_ops = {
+   .bound = isc_async_bound,
+   .unbind = isc_async_unbind,
+   .complete = isc_async_complete,
+};
+
 static void isc_subdev_cleanup(struct isc_device *isc)
 {
struct isc_subdev_entity *subdev_entity;
@@ -1851,9 +1857,7 @@ static int atmel_isc_probe(struct platform_device *pdev)
list_for_each_entry(subdev_entity, >subdev_entities, list) {
subdev_entity->notifier.subdevs = _entity->asd;
subdev_entity->notifier.num_subdevs = 1;
-   subdev_entity->notifier.bound = isc_async_bound;
-   subdev_entity->notifier.unbind = isc_async_unbind;
-   subdev_entity->notifier.complete = isc_async_complete;
+   subdev_entity->notifier.ops = _async_ops;
 
ret = v4l2_async_notifier_register(>v4l2_dev,
   _entity->notifier);
diff --git a/drivers/media/platform/atmel/atmel-isi.c 
b/drivers/media/platform/atmel/atmel-isi.c
index 891fa2505efa..eadbf9def358 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -1105,6 +1105,12 @@ static int isi_graph_notify_bound(struct 
v4l2_async_notifier *notifier,
return 0;
 }
 
+static const struct v4l2_async_notifier_operations isi_graph_notify_ops = {
+   .bound = isi_graph_notify_bound,
+   .unbind = isi_graph_notify_unbind,
+   .complete = isi_graph_notify_complete,
+};
+
 static int isi_graph_parse(struct atmel_isi *isi, struct device_node *node)
 {
struct device_node *ep = NULL;
@@ -1152,9 +1158,7 @@ static int isi_graph_init(struct atmel_isi *isi)
 
isi->notifier.subdevs = subdevs;
isi->notifier.num_subdevs = 1;
-   

[PATCH v13 13/25] v4l: async: Allow async notifier register call succeed with no subdevs

2017-09-15 Thread Sakari Ailus
The information on how many async sub-devices would be bindable to a
notifier is typically dependent on information from platform firmware and
it's not driver's business to be aware of that.

Many V4L2 main drivers are perfectly usable (and useful) without async
sub-devices and so if there aren't any around, just proceed call the
notifier's complete callback immediately without registering the notifier
itself.

If a driver needs to check whether there are async sub-devices available,
it can be done by inspecting the notifier's num_subdevs field which tells
the number of async sub-devices.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-async.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 9895b610e2a0..4be2f16af051 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -170,14 +170,16 @@ int v4l2_async_notifier_register(struct v4l2_device 
*v4l2_dev,
struct v4l2_async_subdev *asd;
int i;
 
-   if (!v4l2_dev || !notifier->num_subdevs ||
-   notifier->num_subdevs > V4L2_MAX_SUBDEVS)
+   if (!v4l2_dev || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
return -EINVAL;
 
notifier->v4l2_dev = v4l2_dev;
INIT_LIST_HEAD(>waiting);
INIT_LIST_HEAD(>done);
 
+   if (!notifier->num_subdevs)
+   return v4l2_async_notifier_call_complete(notifier);
+
for (i = 0; i < notifier->num_subdevs; i++) {
asd = notifier->subdevs[i];
 
-- 
2.11.0



[PATCH v13 09/25] omap3isp: Print the name of the entity where no source pads could be found

2017-09-15 Thread Sakari Ailus
If no source pads are found in an entity, print the name of the entity.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 drivers/media/platform/omap3isp/isp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/omap3isp/isp.c 
b/drivers/media/platform/omap3isp/isp.c
index 3b1a9cd0e591..9a694924e46e 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1669,8 +1669,8 @@ static int isp_link_entity(
break;
}
if (i == entity->num_pads) {
-   dev_err(isp->dev, "%s: no source pad in external entity\n",
-   __func__);
+   dev_err(isp->dev, "%s: no source pad in external entity %s\n",
+   __func__, entity->name);
return -EINVAL;
}
 
-- 
2.11.0



[PATCH v13 12/25] v4l: async: Register sub-devices before calling bound callback

2017-09-15 Thread Sakari Ailus
Register the sub-device before calling the notifier's bound callback.
Doing this the other way around is problematic as the struct v4l2_device
has not assigned for the sub-device yet and may be required by the bound
callback.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-async.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index c35d04b9122f..9895b610e2a0 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -130,13 +130,13 @@ static int v4l2_async_match_notify(struct 
v4l2_async_notifier *notifier,
 {
int ret;
 
-   ret = v4l2_async_notifier_call_bound(notifier, sd, asd);
+   ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
if (ret < 0)
return ret;
 
-   ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
+   ret = v4l2_async_notifier_call_bound(notifier, sd, asd);
if (ret < 0) {
-   v4l2_async_notifier_call_unbind(notifier, sd, asd);
+   v4l2_device_unregister_subdev(sd);
return ret;
}
 
-- 
2.11.0



[PATCH v13 00/25] Unified fwnode endpoint parser, async sub-device notifier support, N9 flash DTS

2017-09-15 Thread Sakari Ailus
Hi folks,

We have a large influx of new, unmerged, drivers that are now parsing
fwnode endpoints and each one of them is doing this a little bit
differently. The needs are still exactly the same for the graph data
structure is device independent. This is still a non-trivial task and the
majority of the driver implementations are buggy, just buggy in different
ways.

Facilitate parsing endpoints by adding a convenience function for parsing
the endpoints, and make the omap3isp and rcar-vin drivers use them as an
example.

To show where we're getting with this, I've added support for async
sub-device notifier support that is notifiers that can be registered by
sub-device drivers as well as V4L2 fwnode improvements to make use of them
and the DTS changes for the Nokia N9. Some of these patches I've posted
previously in this set here:



Since that, the complete callback of the master notifier registering the
V4L2 device is only called once all sub-notifiers have been completed as
well. This way the device node creation can be postponed until all devices
have been successfully initialised.

With this, the as3645a driver successfully registers a sub-device to the
media device created by the omap3isp driver. The kernel also has the
information it's related to the sensor driven by the smiapp driver but we
don't have a way to expose that information yet.

since v12:

- Merge patches "v4l: fwnode: Support generic parsing of graph endpoints
  in a device" and "v4l: fwnode: Support generic parsing of graph
  endpoints, per port". Improve the commit and KernelDoc documentation as
  well.

- Reformat loop conditions in v4l2_async_notifier_try_complete() and
  v4l2_fwnode_reference_get_int_prop(). Improve comments in
  fwnode_property_get_reference_args() return value handling. Also check
  for -ENODATA in v4l2_fwnode_reference_parse_int_props().

- Add an ACPI example for v4l2_fwnode_reference_get_int_prop().

- Document index parameter, document nprops parameter better and fix
  -EINVAL error code documentation for
  v4l2_fwnode_reference_get_int_prop().

- Use WARN_ON_ONCE(true) instead of WARN_ON_ONCE(1) in
  v4l2_async_notifier_release().

since v11:

- Add patch "et8ek8: Add support for flash and lens devices".

- Add patch "v4l: fwnode: Support generic parsing of graph endpoints, per
  port". The use case for this is to parse only upstream ports in a device
  with sources and sinks. The downstream ports have already been parsed by
  other drivers.

- Rename v4l2_fwnode_reference_parse_sensor_common as
  v4l2_async_notifier_parse_fwnode_sensor_common. This is in line with
  other functions that parse information using fwnode API and set up async
  sub-devices in the notifier.

since v10:

- Rename v4l2_async_get_subdev_notifier as
  v4l2_async_find_subdev_notifier, as this is what it effectively does:
  finds a notifier for a sub-device. Same for v4l2_async_notifier_get_v4l2_dev
  / v4l2_async_notifier_get_v4l2_dev.

- Initialise lists before calling v4l2_async_notifier_call_complete() if
  there are no sub-devices in a notifier.

- Warn on missing sub-device or existing v4l2_device on sub-device
  notifier register, and conversely missing v4l2_device or existing
  sub-device for a master notifier.

- Set notifier's sd and v4l2_dev fields NULL when the sub-device is
  unregistered.

- Document the newly added helper functions for parsing external
  references in v4l2-fwnode.c better.

- Return -ENOENT in v4l2_fwnode_reference_parse if no entries are found,
  and other errors as they occur.

- Turn the loop in v4l2_fwnode_reference_get_int_prop a while loop (was
  for).

- Don't put fwnodes in v4l2_fwnode_reference_parse_int_props.

- Fix description of parent field in struct v4l2_async_notifier.

- In the documentation of v4l2_async_notifier_release, document that this
  function must be called also after
  v4l2_fwnode_reference_parse_sensor_common, not just
  v4l2_async_notifier_parse_fwnode_endpoints. The same goes for
  v4l2_async_notifier_parse_fwnode_endpoints as well as
  v4l2_fwnode_reference_parse_sensor_common.

since v9:

- Drop "as3645a: Switch to fwnode property API" and "ACPI: Document how to
  refer to LEDs from remote nodes" patches. They're better off separately
  from this set.

- Address property documentation redundancy in smiapp DT binding
  documentation.

- Add patches "ov5670: Add support for flash and lens devices" and
  "ov13858: Add support for flash and lens devices".

since v8:

- Improve terminology for notifiers. Instead of master / subdev, we
  have root, parent and subdev notifiers.

- Renamed "flash" property as "flash-leds". There are many, and currently
  we make assumptions in a lot of places (e.g. LED bindings) that these
  are LEDs. While we don't have any other types of flashes supported right
  now (e.g. Xenon), it's safer to assume we might have them in the future.

- Use ENOTCONN instead of EPERM to tell from 

[PATCH v13 04/25] v4l: async: Add V4L2 async documentation to the documentation build

2017-09-15 Thread Sakari Ailus
The V4L2 async wasn't part of the documentation build. Fix this.

Signed-off-by: Sakari Ailus 
Reviewed-by: Niklas Söderlund 
Acked-by: Hans Verkuil 
Reviewed-by: Laurent Pinchart 
---
 Documentation/media/kapi/v4l2-async.rst | 3 +++
 Documentation/media/kapi/v4l2-core.rst  | 1 +
 2 files changed, 4 insertions(+)
 create mode 100644 Documentation/media/kapi/v4l2-async.rst

diff --git a/Documentation/media/kapi/v4l2-async.rst 
b/Documentation/media/kapi/v4l2-async.rst
new file mode 100644
index ..523ff9eb09a0
--- /dev/null
+++ b/Documentation/media/kapi/v4l2-async.rst
@@ -0,0 +1,3 @@
+V4L2 async kAPI
+^^^
+.. kernel-doc:: include/media/v4l2-async.h
diff --git a/Documentation/media/kapi/v4l2-core.rst 
b/Documentation/media/kapi/v4l2-core.rst
index c7434f38fd9c..5cf292037a48 100644
--- a/Documentation/media/kapi/v4l2-core.rst
+++ b/Documentation/media/kapi/v4l2-core.rst
@@ -19,6 +19,7 @@ Video4Linux devices
 v4l2-mc
 v4l2-mediabus
 v4l2-mem2mem
+v4l2-async
 v4l2-fwnode
 v4l2-rect
 v4l2-tuner
-- 
2.11.0



[PATCH v13 05/25] v4l: fwnode: Support generic parsing of graph endpoints in a device

2017-09-15 Thread Sakari Ailus
Add two functions for parsing devices graph endpoints:
v4l2_async_notifier_parse_fwnode_endpoints and
v4l2_async_notifier_parse_fwnode_endpoints_by_port. The former iterates
over all endpoints whereas the latter only iterates over the endpoints in
a given port.

The former is mostly useful for existing drivers that currently implement
the iteration over all the endpoints themselves whereas the latter is
especially intended for devices with both sinks and sources: async
sub-devices for external devices connected to the device's sources will
have already been set up, or they are part of the master device.

Signed-off-by: Sakari Ailus 
---
 drivers/media/v4l2-core/v4l2-async.c  |  30 ++
 drivers/media/v4l2-core/v4l2-fwnode.c | 185 ++
 include/media/v4l2-async.h|  24 -
 include/media/v4l2-fwnode.h   | 117 +
 4 files changed, 354 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 831f185ecd47..bf0215dde616 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -22,6 +22,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
@@ -219,6 +220,35 @@ void v4l2_async_notifier_unregister(struct 
v4l2_async_notifier *notifier)
 }
 EXPORT_SYMBOL(v4l2_async_notifier_unregister);
 
+void v4l2_async_notifier_release(struct v4l2_async_notifier *notifier)
+{
+   unsigned int i;
+
+   if (!notifier->max_subdevs)
+   return;
+
+   for (i = 0; i < notifier->num_subdevs; i++) {
+   struct v4l2_async_subdev *asd = notifier->subdevs[i];
+
+   switch (asd->match_type) {
+   case V4L2_ASYNC_MATCH_FWNODE:
+   fwnode_handle_put(asd->match.fwnode.fwnode);
+   break;
+   default:
+   WARN_ON_ONCE(true);
+   }
+
+   kfree(asd);
+   }
+
+   notifier->max_subdevs = 0;
+   notifier->num_subdevs = 0;
+
+   kvfree(notifier->subdevs);
+   notifier->subdevs = NULL;
+}
+EXPORT_SYMBOL_GPL(v4l2_async_notifier_release);
+
 int v4l2_async_register_subdev(struct v4l2_subdev *sd)
 {
struct v4l2_async_notifier *notifier;
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
b/drivers/media/v4l2-core/v4l2-fwnode.c
index 706f9e7b90f1..44ee35f6aad5 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -19,6 +19,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +27,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 enum v4l2_fwnode_bus_type {
@@ -313,6 +315,189 @@ void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link)
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link);
 
+static int v4l2_async_notifier_realloc(struct v4l2_async_notifier *notifier,
+  unsigned int max_subdevs)
+{
+   struct v4l2_async_subdev **subdevs;
+
+   if (max_subdevs <= notifier->max_subdevs)
+   return 0;
+
+   subdevs = kvmalloc_array(
+   max_subdevs, sizeof(*notifier->subdevs),
+   GFP_KERNEL | __GFP_ZERO);
+   if (!subdevs)
+   return -ENOMEM;
+
+   if (notifier->subdevs) {
+   memcpy(subdevs, notifier->subdevs,
+  sizeof(*subdevs) * notifier->num_subdevs);
+
+   kvfree(notifier->subdevs);
+   }
+
+   notifier->subdevs = subdevs;
+   notifier->max_subdevs = max_subdevs;
+
+   return 0;
+}
+
+static int v4l2_async_notifier_fwnode_parse_endpoint(
+   struct device *dev, struct v4l2_async_notifier *notifier,
+   struct fwnode_handle *endpoint, unsigned int asd_struct_size,
+   int (*parse_endpoint)(struct device *dev,
+   struct v4l2_fwnode_endpoint *vep,
+   struct v4l2_async_subdev *asd))
+{
+   struct v4l2_async_subdev *asd;
+   struct v4l2_fwnode_endpoint *vep;
+   int ret = 0;
+
+   asd = kzalloc(asd_struct_size, GFP_KERNEL);
+   if (!asd)
+   return -ENOMEM;
+
+   asd->match.fwnode.fwnode =
+   fwnode_graph_get_remote_port_parent(endpoint);
+   if (!asd->match.fwnode.fwnode) {
+   dev_warn(dev, "bad remote port parent\n");
+   ret = -EINVAL;
+   goto out_err;
+   }
+
+   /* Ignore endpoints the parsing of which failed. */
+   vep = v4l2_fwnode_endpoint_alloc_parse(endpoint);
+   if (IS_ERR(vep)) {
+   ret = PTR_ERR(vep);
+   dev_warn(dev, "unable to parse V4L2 fwnode endpoint (%d)\n",
+ret);
+   goto out_err;
+   }
+
+   ret = parse_endpoint ? parse_endpoint(dev, vep, asd) : 0;
+   if (ret == -ENOTCONN)
+   dev_dbg(dev, 

[PATCH v13 03/25] v4l: async: Use more intuitive names for internal functions

2017-09-15 Thread Sakari Ailus
Rename internal functions to make the names of the functions better
describe what they do.

Old nameNew name
v4l2_async_test_notify  v4l2_async_match_notify
v4l2_async_belongs  v4l2_async_find_match

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
Reviewed-by: Laurent Pinchart 
---
 drivers/media/v4l2-core/v4l2-async.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index e109d9da4653..831f185ecd47 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -60,8 +60,8 @@ static LIST_HEAD(subdev_list);
 static LIST_HEAD(notifier_list);
 static DEFINE_MUTEX(list_lock);
 
-static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier 
*notifier,
-   struct v4l2_subdev *sd)
+static struct v4l2_async_subdev *v4l2_async_find_match(
+   struct v4l2_async_notifier *notifier, struct v4l2_subdev *sd)
 {
bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *);
struct v4l2_async_subdev *asd;
@@ -95,9 +95,9 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct 
v4l2_async_notifier *
return NULL;
 }
 
-static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
- struct v4l2_subdev *sd,
- struct v4l2_async_subdev *asd)
+static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
+  struct v4l2_subdev *sd,
+  struct v4l2_async_subdev *asd)
 {
int ret;
 
@@ -175,11 +175,11 @@ int v4l2_async_notifier_register(struct v4l2_device 
*v4l2_dev,
list_for_each_entry_safe(sd, tmp, _list, async_list) {
int ret;
 
-   asd = v4l2_async_belongs(notifier, sd);
+   asd = v4l2_async_find_match(notifier, sd);
if (!asd)
continue;
 
-   ret = v4l2_async_test_notify(notifier, sd, asd);
+   ret = v4l2_async_match_notify(notifier, sd, asd);
if (ret < 0) {
mutex_unlock(_lock);
return ret;
@@ -236,9 +236,10 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
INIT_LIST_HEAD(>async_list);
 
list_for_each_entry(notifier, _list, list) {
-   struct v4l2_async_subdev *asd = v4l2_async_belongs(notifier, 
sd);
+   struct v4l2_async_subdev *asd = v4l2_async_find_match(notifier,
+ sd);
if (asd) {
-   int ret = v4l2_async_test_notify(notifier, sd, asd);
+   int ret = v4l2_async_match_notify(notifier, sd, asd);
mutex_unlock(_lock);
return ret;
}
-- 
2.11.0



[PATCH v13 01/25] v4l: fwnode: Move KernelDoc documentation to the header

2017-09-15 Thread Sakari Ailus
In V4L2 the practice is to have the KernelDoc documentation in the header
and not in .c source code files. This consequently makes the V4L2 fwnode
function documentation part of the Media documentation build.

Also correct the link related function and argument naming in
documentation.

Signed-off-by: Sakari Ailus 
Reviewed-by: Niklas Söderlund 
Acked-by: Hans Verkuil 
Acked-by: Pavel Machek 
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 75 
 include/media/v4l2-fwnode.h   | 81 ++-
 2 files changed, 80 insertions(+), 76 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
b/drivers/media/v4l2-core/v4l2-fwnode.c
index 40b2fbfe8865..706f9e7b90f1 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -181,25 +181,6 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle 
*fwnode,
vep->bus_type = V4L2_MBUS_CSI1;
 }
 
-/**
- * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
- * @vep: pointer to the V4L2 fwnode data structure
- *
- * All properties are optional. If none are found, we don't set any flags. This
- * means the port has a static configuration and no properties have to be
- * specified explicitly. If any properties that identify the bus as parallel
- * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
- * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
- * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
- * reference to @fwnode.
- *
- * NOTE: This function does not parse properties the size of which is variable
- * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in
- * new drivers instead.
- *
- * Return: 0 on success or a negative error code on failure.
- */
 int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
   struct v4l2_fwnode_endpoint *vep)
 {
@@ -239,14 +220,6 @@ int v4l2_fwnode_endpoint_parse(struct fwnode_handle 
*fwnode,
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse);
 
-/*
- * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by
- * v4l2_fwnode_endpoint_alloc_parse()
- * @vep - the V4L2 fwnode the resources of which are to be released
- *
- * It is safe to call this function with NULL argument or on a V4L2 fwnode the
- * parsing of which failed.
- */
 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep)
 {
if (IS_ERR_OR_NULL(vep))
@@ -257,29 +230,6 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint 
*vep)
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free);
 
-/**
- * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
- *
- * All properties are optional. If none are found, we don't set any flags. This
- * means the port has a static configuration and no properties have to be
- * specified explicitly. If any properties that identify the bus as parallel
- * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
- * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
- * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
- * reference to @fwnode.
- *
- * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
- * v4l2_fwnode_endpoint_parse():
- *
- * 1. It also parses variable size data.
- *
- * 2. The memory it has allocated to store the variable size data must be freed
- *using v4l2_fwnode_endpoint_free() when no longer needed.
- *
- * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer
- * on error.
- */
 struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
struct fwnode_handle *fwnode)
 {
@@ -322,24 +272,6 @@ struct v4l2_fwnode_endpoint 
*v4l2_fwnode_endpoint_alloc_parse(
 }
 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse);
 
-/**
- * v4l2_fwnode_endpoint_parse_link() - parse a link between two endpoints
- * @__fwnode: pointer to the endpoint's fwnode at the local end of the link
- * @link: pointer to the V4L2 fwnode link data structure
- *
- * Fill the link structure with the local and remote nodes and port numbers.
- * The local_node and remote_node fields are set to point to the local and
- * remote port's parent nodes respectively (the port parent node being the
- * parent node of the port node if that node isn't a 'ports' node, or the
- * grand-parent node of the port node otherwise).
- *
- * A reference is taken to both the local and remote nodes, the caller must use
- * v4l2_fwnode_endpoint_put_link() to drop the references when done with the
- * link.
- *
- * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be
- * found.
- */
 int v4l2_fwnode_parse_link(struct fwnode_handle 

[PATCH v13 02/25] v4l: async: Remove re-probing support

2017-09-15 Thread Sakari Ailus
Remove V4L2 async re-probing support. The re-probing support has been
there to support cases where the sub-devices require resources provided by
the main driver's hardware to function, such as clocks.

Reprobing has allowed unbinding and again binding the main driver without
explicilty unbinding the sub-device drivers. This is certainly not a
common need, and the responsibility will be the user's going forward.

An alternative could have been to introduce notifier specific locks.
Considering the complexity of the re-probing and that it isn't really a
solution to a problem but a workaround, remove re-probing instead.

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-async.c | 54 
 1 file changed, 54 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index d741a8e0fdac..e109d9da4653 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -198,78 +198,24 @@ EXPORT_SYMBOL(v4l2_async_notifier_register);
 void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
 {
struct v4l2_subdev *sd, *tmp;
-   unsigned int notif_n_subdev = notifier->num_subdevs;
-   unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS);
-   struct device **dev;
-   int i = 0;
 
if (!notifier->v4l2_dev)
return;
 
-   dev = kvmalloc_array(n_subdev, sizeof(*dev), GFP_KERNEL);
-   if (!dev) {
-   dev_err(notifier->v4l2_dev->dev,
-   "Failed to allocate device cache!\n");
-   }
-
mutex_lock(_lock);
 
list_del(>list);
 
list_for_each_entry_safe(sd, tmp, >done, async_list) {
-   struct device *d;
-
-   d = get_device(sd->dev);
-
v4l2_async_cleanup(sd);
 
-   /* If we handled USB devices, we'd have to lock the parent too 
*/
-   device_release_driver(d);
-
if (notifier->unbind)
notifier->unbind(notifier, sd, sd->asd);
-
-   /*
-* Store device at the device cache, in order to call
-* put_device() on the final step
-*/
-   if (dev)
-   dev[i++] = d;
-   else
-   put_device(d);
}
 
mutex_unlock(_lock);
 
-   /*
-* Call device_attach() to reprobe devices
-*
-* NOTE: If dev allocation fails, i is 0, and the whole loop won't be
-* executed.
-*/
-   while (i--) {
-   struct device *d = dev[i];
-
-   if (d && device_attach(d) < 0) {
-   const char *name = "(none)";
-   int lock = device_trylock(d);
-
-   if (lock && d->driver)
-   name = d->driver->name;
-   dev_err(d, "Failed to re-probe to %s\n", name);
-   if (lock)
-   device_unlock(d);
-   }
-   put_device(d);
-   }
-   kvfree(dev);
-
notifier->v4l2_dev = NULL;
-
-   /*
-* Don't care about the waiting list, it is initialised and populated
-* upon notifier registration.
-*/
 }
 EXPORT_SYMBOL(v4l2_async_notifier_unregister);
 
-- 
2.11.0



Re: [PATCH v12 18/26] v4l: fwnode: Add a helper function for parsing generic references

2017-09-15 Thread Sakari Ailus
Hi Hans,

On Wed, Sep 13, 2017 at 12:32:17PM +0200, Hans Verkuil wrote:
> On 09/13/17 12:07, Sakari Ailus wrote:
> > Hi Hans,
> > 
> > On Wed, Sep 13, 2017 at 11:28:44AM +0200, Hans Verkuil wrote:
> >> On 09/13/17 11:24, Sakari Ailus wrote:
> >>> Hi Hans,
> >>>
> >>> Thanks for the review!
> >>>
> >>> On Wed, Sep 13, 2017 at 09:27:34AM +0200, Hans Verkuil wrote:
>  On 09/12/2017 03:41 PM, Sakari Ailus wrote:
> > Add function v4l2_fwnode_reference_count() for counting external
> 
>   There is no function v4l2_fwnode_reference_count()?!
> >>>
> >>> It got removed during the revisions but the commit message was not changed
> >>> accordingly, I do that now.
> >>>
> 
> > references and v4l2_fwnode_reference_parse() for parsing them as async
> > sub-devices.
> >
> > This can be done on e.g. flash or lens async sub-devices that are not 
> > part
> > of but are associated with a sensor.
> >
> > struct v4l2_async_notifier.max_subdevs field is added to contain the
> > maximum number of sub-devices in a notifier to reflect the memory
> > allocated for the subdevs array.
> 
>  You forgot to remove this outdated paragraph.
> >>>
> >>> Oops. Removed it now.
> >>>
> 
> >
> > Signed-off-by: Sakari Ailus 
> > ---
> >  drivers/media/v4l2-core/v4l2-fwnode.c | 69 
> > +++
> >  1 file changed, 69 insertions(+)
> >
> > diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> > b/drivers/media/v4l2-core/v4l2-fwnode.c
> > index 44ee35f6aad5..a32473f95be1 100644
> > --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> > +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> > @@ -498,6 +498,75 @@ int 
> > v4l2_async_notifier_parse_fwnode_endpoints_by_port(
> >  }
> >  EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port);
> >  
> > +/*
> > + * v4l2_fwnode_reference_parse - parse references for async sub-devices
> > + * @dev: the device node the properties of which are parsed for 
> > references
> > + * @notifier: the async notifier where the async subdevs will be added
> > + * @prop: the name of the property
> > + *
> > + * Return: 0 on success
> > + *-ENOENT if no entries were found
> > + *-ENOMEM if memory allocation failed
> > + *-EINVAL if property parsing failed
> > + */
> > +static int v4l2_fwnode_reference_parse(
> > +   struct device *dev, struct v4l2_async_notifier *notifier,
> > +   const char *prop)
> > +{
> > +   struct fwnode_reference_args args;
> > +   unsigned int index;
> > +   int ret;
> > +
> > +   for (index = 0;
> > +!(ret = fwnode_property_get_reference_args(
> > +  dev_fwnode(dev), prop, NULL, 0, index, ));
> > +index++)
> > +   fwnode_handle_put(args.fwnode);
> > +
> > +   if (!index)
> > +   return -ENOENT;
> > +
> > +   /*
> > +* To-do: handle -ENODATA when "device property: Align return
> > +* codes of acpi_fwnode_get_reference_with_args" is merged.
> > +*/
> > +   if (ret != -ENOENT && ret != -ENODATA)
> 
>  So while that patch referenced in the To-do above is not merged yet,
>  what does fwnode_property_get_reference_args return? ENOENT or ENODATA?
>  Or ENOENT now and ENODATA later? Or vice versa?
> 
>  I can't tell based on that information whether this code is correct or 
>  not.
> 
>  The comment needs to explain this a bit better.
> >>>
> >>> I'll add this:
> >>>
> >>> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> >>> b/drivers/media/v4l2-core/v4l2-fwnode.c
> >>> index a32473f95be1..74fcc3ba9ebd 100644
> >>> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> >>> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> >>> @@ -529,6 +529,9 @@ static int v4l2_fwnode_reference_parse(
> >>>   /*
> >>>* To-do: handle -ENODATA when "device property: Align return
> >>>* codes of acpi_fwnode_get_reference_with_args" is merged.
> >>
> >> So after this patch referred to in the To-do is applied it will only
> >> return ENODATA?
> >>
> >> In that case, change 'handle' to 'handle only'.
> > 
> > That depends a bit in which form the patch will be eventually accepted. The
> > underlying issue there is that different error codes are used to signal
> > conditions for out-of-bounds access and missing entry. After aligning them
> > the code here can be updated.
> 
> Ah. In that case I'd drop the 'To-do' sentence.
> 
> > 
> >>
> >>> +  * Right now, both -ENODATA and -ENOENT signal the end of
> >>> +  * references where only a single error code should be used
> >>> +  * for the purpose.
> 
> And add something like: "This might change in the future, in which
> case this code should be updated."

I'll 

Re: [PATCH v2] [DVB][FRONTEND] Added a new ioctl for optimizing frontend property set operation

2017-09-15 Thread Mauro Carvalho Chehab
Em Fri, 15 Sep 2017 06:18:20 -0400
Satendra Singh Thakur  escreveu:

> Hello  Mr Chehab,
> Thanks for the comments.
> I have modified dtv_property_process_set and
> also added documentation.
> Please let me know if any further modifications required.

That's a way better. Just a few minor things to modify for it to be
ready for merging.

> Signed-off-by: Satendra Singh Thakur 
> ---
>  .../media/uapi/dvb/fe-set-property-short.rst   |  60 +
>  Documentation/media/uapi/dvb/frontend_fcalls.rst   |   1 +
>  drivers/media/dvb-core/dvb_frontend.c  | 143 
> +
>  include/uapi/linux/dvb/frontend.h  |  24 
>  4 files changed, 173 insertions(+), 55 deletions(-)
>  create mode 100644 Documentation/media/uapi/dvb/fe-set-property-short.rst
> 
> diff --git a/Documentation/media/uapi/dvb/fe-set-property-short.rst 
> b/Documentation/media/uapi/dvb/fe-set-property-short.rst
> new file mode 100644
> index 000..7da1e8d
> --- /dev/null
> +++ b/Documentation/media/uapi/dvb/fe-set-property-short.rst
> @@ -0,0 +1,60 @@
> +.. -*- coding: utf-8; mode: rst -*-
> +
> +.. _FE_SET_PROPERTY_SHORT:
> +
> +**
> +ioctl FE_SET_PROPERTY_SHORT
> +**
> +
> +Name
> +
> +
> +FE_SET_PROPERTY_SHORT  sets one or more frontend properties.
> +
> +
> +Synopsis
> +
> +
> +
> +.. c:function:: int ioctl( int fd, FE_SET_PROPERTY_SHORT, struct 
> dtv_properties_short *argp )
> +:name: FE_SET_PROPERTY_SHORT
> +
> +
> +Arguments
> +=
> +
> +``fd``
> +File descriptor returned by :ref:`open() `.
> +
> +``argp``
> +pointer to struct :c:type:`dtv_properties_short`,
> + which is a shorter variant of struct dtv_properties.
> +
> +
> +Description
> +===
> +
> +All DVB frontend devices support the ``FE_SET_PROPERTY_SHORT`` ioctl.
> +This ioctl is a shorter variant of ioctl FE_SET_PROPERTY.

Please use, instead:

:ref:`FE_SET_PROPERTY`

in order to generate cross-reference with the other ioctl.

Also, please add a note at fe-set-property.rst mentioning the
FE_SET_PROPERTY_SHORT variant.

Btw, I'm actually in doubt if the best wouldn't be to just add
this new ioctl to fe-get-property.rst.

> +The supported properties and statistics depend on the delivery system
> +and on the device:
> +
> +-  ``FE_SET_PROPERTY_SHORT:``
> +
> +   -  This ioctl is used to set one or more frontend properties.
> +
> +   -  This is the basic command to request the frontend to tune into
> +  some frequency and to start decoding the digital TV signal.
> +
> +   -  This call requires read/write access to the device.
> +
> +   -  At return, the values are updated to reflect the actual parameters
> +  used.
> +
> +
> +Return Value
> +
> +
> +On success 0 is returned, on error -1 and the ``errno`` variable is set
> +appropriately. The generic error codes are described at the
> +:ref:`Generic Error Codes ` chapter.
> diff --git a/Documentation/media/uapi/dvb/frontend_fcalls.rst 
> b/Documentation/media/uapi/dvb/frontend_fcalls.rst
> index b03f9ca..a1246c6 100644
> --- a/Documentation/media/uapi/dvb/frontend_fcalls.rst
> +++ b/Documentation/media/uapi/dvb/frontend_fcalls.rst
> @@ -14,6 +14,7 @@ Frontend Function Calls
>  fe-get-info
>  fe-read-status
>  fe-get-property
> +fe-set-property-short
>  fe-diseqc-reset-overload
>  fe-diseqc-send-master-cmd
>  fe-diseqc-recv-slave-reply
> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index e3fff8f..6616474 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -1738,23 +1738,28 @@ static int dvbv3_set_delivery_system(struct 
> dvb_frontend *fe)
>   return emulate_delivery_system(fe, delsys);
>  }
>  
> +/**
> + * dtv_property_process_set

Nitpick: please add a short description for the function.

> + * @fe: Pointer to struct dvb_frontend
> + * @file: Pointer to struct file
> + * @cmd: Property name
> + * @data: Property value
> + *
> + * helper function for dvb_frontend_ioctl_properties,
> + * which can be used to set a single dtv property
> + * It assigns property value to corresponding member of
> + * property-cache structure
> + * Returns:
> + * Zero on success, negative errno on failure.
> + */
>  static int dtv_property_process_set(struct dvb_frontend *fe,
> - struct dtv_property *tvp,
> - struct file *file)
> + struct file *file,
> + u32 cmd, u32 data)
>  {
>   int r = 0;
>   struct dtv_frontend_properties *c = >dtv_property_cache;
>  
> - /* Allow the frontend to validate incoming properties */
> - if (fe->ops.set_property) {
> - r = fe->ops.set_property(fe, tvp);
> - if (r < 0)
> -  

Re: [PATCH] [media] cec: GIVE_PHYSICAL_ADDR should respond to unregistered device

2017-09-15 Thread Jose Abreu
Hi Hans,

On 14-09-2017 16:46, Hans Verkuil wrote:
> On 09/14/2017 05:30 PM, Jose Abreu wrote:
>>
>> On 14-09-2017 16:09, Hans Verkuil wrote:
>>> On 09/14/17 15:28, Jose Abreu wrote:
>>>
 Actually, I have at least one more fix which I don't know if it's
 valid and I didn't manage to actually write it in a nice way.
 This one is for CEC 2.0. My test equipment (which is certified)
 in some tests sends msgs only with the opcode. As the received
 msg length does not match the expected one CEC core is rejecting
 the message and my compliance test is failling (test is 4.2.3).
>>> In the HDMI 1.4 spec in CEC 7.3 (Frame Validation) it says that a follower
>>> should ignore frames that are too small.
>>>
>>> At the same time unsupported opcodes should result in a Feature Abort.
>>>
>>> If you don't send a properly formed message, then it's not clear to me
>>> what should happen. Which opcode failed?
>> Hmm, yeah, the spec confirms. The failing opcodes are the ones
>> that have arguments, the test equipment is just sending the
>> header plus opcode. Anyway, for this failing test the MOI for
>> this equipment is not approved so I will probably carry this fix
>> only locally and send it upstream only if the MOI gets approved.
> So is this test just running through all opcodes from 1-255 and see
> what happens? Or is it only doing this for a subset of opcodes?
> And if so, which?

Its running through the opcodes that the sink does not support
and sending only the opcode. By spec sink should respond with
Feature Abort. But, as you said, only sending opcode is out of
spec (for opcodes that have arguments).

>
> I'm just curious to see how this is done.
>
> Which test equipment do you use?

Its a QD980.

Best regards,
Jose Miguel Abreu

>
> We don't actually have any certified CEC 2.0 test equipment, only 1.4,
> so I'm grateful that you did it for me :-)
>
> Regards,
>
>   Hans
>
 Have you run this test? Did it pass?
>>> No, we haven't. Never got around to that.
>> Ok. I can say that CEC 1.4 + CEC 2.0 all pass compliance with
>> this patch and with my local fix + my test app!
>>
>> Best regards,
>> Jose Miguel Abreu
>>
>>> Regards,
>>>
>>> Hans
>>>
 Best regards,
 Jose Miguel Abreu

> Regards,
>
>   Hans



Re: [PATCH] util: qv4l2: fix discrete frame size selection.

2017-09-15 Thread Hans Verkuil
Hi Konstantin,

On 09/15/17 11:28, Konstantin Oblaukhov wrote:
> qv4l2 hasn't work correctly with discrete frame sizes. 
> In case of capture device with discrete frame sizes, size combo-box wasn't 
> shown.

Apparently this is a device driver that uses both V4L2_IN_CAP_DV_TIMINGS
and has discrete frame sizes. That makes no sense. Which device driver is that?

> In case of output device with discrete frame sizes, qv4l2 was segfaulting.

Same question: which device driver uses discrete frame sizes for output?
I am not aware of any, which is the reason this is not implemented in qv4l2.

> This patch fix discrete size combo-box both for capture and output devices.
> 
> Also Qt's project file got updated.

Please post this as a separate patch.

Regards,

Hans

> 
> ---
>  utils/qv4l2/general-tab.cpp | 30 ++
>  utils/qv4l2/qv4l2.pro   |  5 -
>  2 files changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/utils/qv4l2/general-tab.cpp b/utils/qv4l2/general-tab.cpp
> index 9c1dbc7e..78c5cb2d 100644
> --- a/utils/qv4l2/general-tab.cpp
> +++ b/utils/qv4l2/general-tab.cpp
> @@ -595,8 +595,11 @@ void GeneralTab::outputSection(v4l2_output vout)
>   return;
>  
>   QWidget *wFrameWH = new QWidget();
> + QWidget *wFrameSR = new QWidget();
>   QGridLayout *m_wh = new QGridLayout(wFrameWH);
> + QGridLayout *m_sr = new QGridLayout(wFrameSR);
>   m_grids.append(m_wh);
> + m_grids.append(m_sr);
>  
>   m_wh->addWidget(new QLabel("Frame Width", parentWidget()), 0, 0, 
> Qt::AlignLeft);
>   m_frameWidth = new QSpinBox(parentWidget());
> @@ -608,7 +611,18 @@ void GeneralTab::outputSection(v4l2_output vout)
>   m_wh->addWidget(m_frameHeight, 0, 3, Qt::AlignLeft);
>   connect(m_frameHeight, SIGNAL(editingFinished()), 
> SLOT(frameHeightChanged()));
>  
> + m_sr->addWidget(new QLabel("Frame Size", parentWidget()), 0, 0, 
> Qt::AlignLeft);
> + m_frameSize = new QComboBox(parentWidget());
> + m_sr->addWidget(m_frameSize, 0, 1, Qt::AlignLeft);
> + connect(m_frameSize, SIGNAL(activated(int)), 
> SLOT(frameSizeChanged(int)));
> +
> + m_sr->addWidget(new QLabel("Frame Rate", parentWidget()), 0, 2, 
> Qt::AlignLeft);
> + m_frameInterval = new QComboBox(parentWidget());
> + m_sr->addWidget(m_frameInterval, 0, 3, Qt::AlignLeft);
> + connect(m_frameInterval, SIGNAL(activated(int)), 
> SLOT(frameIntervalChanged(int)));
> +
>   m_stackedFrameSettings->addWidget(wFrameWH);
> + m_stackedFrameSettings->addWidget(wFrameSR);
>  
>   QGridLayout::addWidget(m_stackedFrameSettings, m_row, 0, 1, m_cols, 
> Qt::AlignVCenter);
>   m_row++;
> @@ -1184,7 +1198,7 @@ void GeneralTab::updateGUIInput(__u32 input)
>   m_stackedStandards->show();
>   m_stackedFrequency->hide();
>   } else if (in.capabilities & V4L2_IN_CAP_DV_TIMINGS) {
> - m_stackedFrameSettings->setCurrentIndex(0);
> + m_stackedFrameSettings->setCurrentIndex(m_discreteSizes ? 1 : 
> 0);
>   m_stackedFrameSettings->show();
>   m_stackedStandards->setCurrentIndex(1);
>   m_stackedStandards->show();
> @@ -1216,8 +1230,8 @@ void GeneralTab::updateGUIOutput(__u32 output)
>   m_stackedStandards->setCurrentIndex(0);
>   m_stackedStandards->show();
>   m_stackedFrequency->hide();
> - } else if (out.capabilities & V4L2_OUT_CAP_DV_TIMINGS) {
> - m_stackedFrameSettings->setCurrentIndex(0);
> + } else if (out.capabilities & V4L2_OUT_CAP_DV_TIMINGS) {
> + m_stackedFrameSettings->setCurrentIndex(m_discreteSizes ? 1 : 
> 0);
>   m_stackedFrameSettings->show();
>   m_stackedStandards->setCurrentIndex(1);
>   m_stackedStandards->show();
> @@ -2157,7 +2171,12 @@ void GeneralTab::updateFrameSize()
>   m_frameSize->setCurrentIndex(frmsize.index);
>   } while (!enum_framesizes(frmsize));
>  
> +
>   m_discreteSizes = true;
> + if (m_frameSize)
> + m_frameSize->setEnabled(true);
> + m_stackedFrameSettings->setCurrentIndex(1);
> +
>   m_frameWidth->setEnabled(false);
>   m_frameWidth->blockSignals(true);
>   m_frameWidth->setMinimum(m_width);
> @@ -2171,7 +2190,9 @@ void GeneralTab::updateFrameSize()
>   m_frameHeight->setMaximum(m_height);
>   m_frameHeight->setValue(m_height);
>   m_frameHeight->blockSignals(false);
> - m_frameSize->setEnabled(!m_haveBuffers);
> +m_frameSize->setEnabled(!m_haveBuffers);
> +
> +
>   updateFrameInterval();
>   return;
>   }
> @@ -2186,6 +2207,7 @@ void GeneralTab::updateFrameSize()
>   m_discreteSizes = false;
>   if (m_frameSize)
>   m_frameSize->setEnabled(false);
> + 

[PATCH v2] [DVB][FRONTEND] Added a new ioctl for optimizing frontend property set operation

2017-09-15 Thread Satendra Singh Thakur
Hello  Mr Chehab,
Thanks for the comments.
I have modified dtv_property_process_set and
also added documentation.
Please let me know if any further modifications required.

Signed-off-by: Satendra Singh Thakur 
---
 .../media/uapi/dvb/fe-set-property-short.rst   |  60 +
 Documentation/media/uapi/dvb/frontend_fcalls.rst   |   1 +
 drivers/media/dvb-core/dvb_frontend.c  | 143 +
 include/uapi/linux/dvb/frontend.h  |  24 
 4 files changed, 173 insertions(+), 55 deletions(-)
 create mode 100644 Documentation/media/uapi/dvb/fe-set-property-short.rst

diff --git a/Documentation/media/uapi/dvb/fe-set-property-short.rst 
b/Documentation/media/uapi/dvb/fe-set-property-short.rst
new file mode 100644
index 000..7da1e8d
--- /dev/null
+++ b/Documentation/media/uapi/dvb/fe-set-property-short.rst
@@ -0,0 +1,60 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _FE_SET_PROPERTY_SHORT:
+
+**
+ioctl FE_SET_PROPERTY_SHORT
+**
+
+Name
+
+
+FE_SET_PROPERTY_SHORT  sets one or more frontend properties.
+
+
+Synopsis
+
+
+
+.. c:function:: int ioctl( int fd, FE_SET_PROPERTY_SHORT, struct 
dtv_properties_short *argp )
+:name: FE_SET_PROPERTY_SHORT
+
+
+Arguments
+=
+
+``fd``
+File descriptor returned by :ref:`open() `.
+
+``argp``
+pointer to struct :c:type:`dtv_properties_short`,
+   which is a shorter variant of struct dtv_properties.
+
+
+Description
+===
+
+All DVB frontend devices support the ``FE_SET_PROPERTY_SHORT`` ioctl.
+This ioctl is a shorter variant of ioctl FE_SET_PROPERTY.
+The supported properties and statistics depend on the delivery system
+and on the device:
+
+-  ``FE_SET_PROPERTY_SHORT:``
+
+   -  This ioctl is used to set one or more frontend properties.
+
+   -  This is the basic command to request the frontend to tune into
+  some frequency and to start decoding the digital TV signal.
+
+   -  This call requires read/write access to the device.
+
+   -  At return, the values are updated to reflect the actual parameters
+  used.
+
+
+Return Value
+
+
+On success 0 is returned, on error -1 and the ``errno`` variable is set
+appropriately. The generic error codes are described at the
+:ref:`Generic Error Codes ` chapter.
diff --git a/Documentation/media/uapi/dvb/frontend_fcalls.rst 
b/Documentation/media/uapi/dvb/frontend_fcalls.rst
index b03f9ca..a1246c6 100644
--- a/Documentation/media/uapi/dvb/frontend_fcalls.rst
+++ b/Documentation/media/uapi/dvb/frontend_fcalls.rst
@@ -14,6 +14,7 @@ Frontend Function Calls
 fe-get-info
 fe-read-status
 fe-get-property
+fe-set-property-short
 fe-diseqc-reset-overload
 fe-diseqc-send-master-cmd
 fe-diseqc-recv-slave-reply
diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index e3fff8f..6616474 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1738,23 +1738,28 @@ static int dvbv3_set_delivery_system(struct 
dvb_frontend *fe)
return emulate_delivery_system(fe, delsys);
 }
 
+/**
+ * dtv_property_process_set
+ * @fe: Pointer to struct dvb_frontend
+ * @file: Pointer to struct file
+ * @cmd: Property name
+ * @data: Property value
+ *
+ * helper function for dvb_frontend_ioctl_properties,
+ * which can be used to set a single dtv property
+ * It assigns property value to corresponding member of
+ * property-cache structure
+ * Returns:
+ * Zero on success, negative errno on failure.
+ */
 static int dtv_property_process_set(struct dvb_frontend *fe,
-   struct dtv_property *tvp,
-   struct file *file)
+   struct file *file,
+   u32 cmd, u32 data)
 {
int r = 0;
struct dtv_frontend_properties *c = >dtv_property_cache;
 
-   /* Allow the frontend to validate incoming properties */
-   if (fe->ops.set_property) {
-   r = fe->ops.set_property(fe, tvp);
-   if (r < 0)
-   return r;
-   }
-
-   dtv_property_dump(fe, true, tvp);
-
-   switch(tvp->cmd) {
+   switch (cmd) {
case DTV_CLEAR:
/*
 * Reset a cache of data specific to the frontend here. This 
does
@@ -1767,140 +1772,140 @@ static int dtv_property_process_set(struct 
dvb_frontend *fe,
 * tunerequest so we can pass validation in the FE_SET_FRONTEND
 * ioctl.
 */
-   c->state = tvp->cmd;
+   c->state = cmd;
dev_dbg(fe->dvb->device, "%s: Finalised property cache\n",
__func__);
 
r = dtv_set_frontend(fe);
break;
case DTV_FREQUENCY:
-   c->frequency = tvp->u.data;
+  

Re: [PATCH 5/5] media: dvb_frontend: get rid of set_property() callback

2017-09-15 Thread Mauro Carvalho Chehab
Em Fri, 15 Sep 2017 06:11:01 -0300
Mauro Carvalho Chehab  escreveu:

> Now that all clients of set_property() were removed, get rid
> of this callback.
> 
> Signed-off-by: Mauro Carvalho Chehab 
> ---
>  drivers/media/dvb-core/dvb_frontend.c | 7 ---
>  drivers/media/dvb-core/dvb_frontend.h | 2 --
>  2 files changed, 9 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index 5d00e46d9432..8abe4f541a36 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -1766,13 +1766,6 @@ static int dtv_property_process_set(struct 
> dvb_frontend *fe,
>   int r = 0;
>   struct dtv_frontend_properties *c = >dtv_property_cache;
>  
> - /* Allow the frontend to validate incoming properties */
> - if (fe->ops.set_property) {
> - r = fe->ops.set_property(fe, tvp);
> - if (r < 0)
> - return r;
> - }
> -
>   dtv_property_dump(fe, true, tvp);
>  
>   switch(tvp->cmd) {
> diff --git a/drivers/media/dvb-core/dvb_frontend.h 
> b/drivers/media/dvb-core/dvb_frontend.h
> index 4d05846f2c1c..a50f8216ab76 100644
> --- a/drivers/media/dvb-core/dvb_frontend.h
> +++ b/drivers/media/dvb-core/dvb_frontend.h
> @@ -401,8 +401,6 @@ struct dtv_frontend_properties;
>   * @search:  callback function used on some custom algo search algos.
>   * @tuner_ops:   pointer to struct dvb_tuner_ops
>   * @analog_ops:  pointer to struct analog_demod_ops
> - * @set_property:callback function to allow the frontend to validade
> - *   incoming properties. Should not be used on new drivers.
>   */
>  struct dvb_frontend_ops {

Hmm... actually, the patch is missing the removal of set_property().

The enclosed one should fix it.

Regards,
Mauro

---

[PATCH] media: dvb_frontend: get rid of set_property() callback

Now that all clients of set_property() were removed, get rid
of this callback.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 5d00e46d9432..8abe4f541a36 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1766,13 +1766,6 @@ static int dtv_property_process_set(struct dvb_frontend 
*fe,
int r = 0;
struct dtv_frontend_properties *c = >dtv_property_cache;
 
-   /* Allow the frontend to validate incoming properties */
-   if (fe->ops.set_property) {
-   r = fe->ops.set_property(fe, tvp);
-   if (r < 0)
-   return r;
-   }
-
dtv_property_dump(fe, true, tvp);
 
switch(tvp->cmd) {
diff --git a/drivers/media/dvb-core/dvb_frontend.h 
b/drivers/media/dvb-core/dvb_frontend.h
index 4d05846f2c1c..852b91ba49d2 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -401,11 +401,8 @@ struct dtv_frontend_properties;
  * @search:callback function used on some custom algo search algos.
  * @tuner_ops: pointer to struct dvb_tuner_ops
  * @analog_ops:pointer to struct analog_demod_ops
- * @set_property:  callback function to allow the frontend to validade
- * incoming properties. Should not be used on new drivers.
  */
 struct dvb_frontend_ops {
-
struct dvb_frontend_info info;
 
u8 delsys[MAX_DELSYS];
@@ -464,8 +461,6 @@ struct dvb_frontend_ops {
 
struct dvb_tuner_ops tuner_ops;
struct analog_demod_ops analog_ops;
-
-   int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
 };
 
 #ifdef __DVB_CORE__


[PATCH] dma-fence: fix dma_fence_get_rcu_safe v2

2017-09-15 Thread Christian König
From: Christian König 

When dma_fence_get_rcu() fails to acquire a reference it doesn't necessary
mean that there is no fence at all.

It usually mean that the fence was replaced by a new one and in this situation
we certainly want to have the new one as result and *NOT* NULL.

v2: Keep extra check after dma_fence_get_rcu().

Signed-off-by: Christian König 
Cc: Chris Wilson 
Cc: Daniel Vetter 
Cc: Sumit Semwal 
Cc: linux-media@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc: linaro-mm-...@lists.linaro.org
---
 include/linux/dma-fence.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 0a186c4..f4f23cb 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -248,9 +248,12 @@ dma_fence_get_rcu_safe(struct dma_fence * __rcu *fencep)
struct dma_fence *fence;
 
fence = rcu_dereference(*fencep);
-   if (!fence || !dma_fence_get_rcu(fence))
+   if (!fence)
return NULL;
 
+   if (!dma_fence_get_rcu(fence))
+   continue;
+
/* The atomic_inc_not_zero() inside dma_fence_get_rcu()
 * provides a full memory barrier upon success (such as now).
 * This is paired with the write barrier from assigning
-- 
2.7.4



Re: [PATCH 2/5] media: stv6110: get rid of a srate dead code

2017-09-15 Thread Mauro Carvalho Chehab
Em Fri, 15 Sep 2017 11:30:11 +0200
Honza Petrouš  escreveu:

> Mauro, you are so speedy :)
> 
> 2017-09-15 11:10 GMT+02:00 Mauro Carvalho Chehab :
> > The stv6110 has a weird code that checks if get_property
> > and set_property ioctls are defined. If they're, it initializes
> > a "srate" var from properties cache. Otherwise, it sets to
> > 15MBaud, with won't make any sense.
> >
> > Thankfully, it seems that someone already noticed, as the
> > "srate" is not used anywhere!  
> 
> Hehe! "Someone else" :)

Yeah, true!

Just to be clear, I meant to say above that probably someone
noticed it in the past, and got rid of the usage of srate upstream,
but forgot to remove the var :-)

I updated the text. See enclosed.

> 
> >
> > So, get rid of that really weird dead code logic.
> >
> > Signed-off-by: Mauro Carvalho Chehab   
> 
> Reported-by: Honza Petrous 

Thanks for reporting it!

Thanks,
Mauro

-

[PATCH] media: stv6110: get rid of a srate dead code

The stv6110 has a weird code that checks if get_property
and set_property ioctls are defined. If they're, it initializes
a "srate" var from properties cache. Otherwise, it sets to
15MBaud, with won't make any sense.

Thankfully, it seems that someone else discovered the issue in
the past, as "srate" is currently not used anywhere!

So, get rid of that really weird dead code logic.

Reported-by: Honza Petrous 
Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-frontends/stv6110.c 
b/drivers/media/dvb-frontends/stv6110.c
index e4fd9c1b0560..2821f6da6764 100644
--- a/drivers/media/dvb-frontends/stv6110.c
+++ b/drivers/media/dvb-frontends/stv6110.c
@@ -262,7 +262,6 @@ static int stv6110_set_frequency(struct dvb_frontend *fe, 
u32 frequency)
u8 ret = 0x04;
u32 divider, ref, p, presc, i, result_freq, vco_freq;
s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
-   s32 srate;
 
dprintk("%s, freq=%d kHz, mclk=%d Hz\n", __func__,
frequency, priv->mclk);
@@ -273,13 +272,6 @@ static int stv6110_set_frequency(struct dvb_frontend *fe, 
u32 frequency)
priv->mclk / 100) - 16) & 0x1f) << 3);
 
/* BB_GAIN = db/2 */
-   if (fe->ops.set_property && fe->ops.get_property) {
-   srate = c->symbol_rate;
-   dprintk("%s: Get Frontend parameters: srate=%d\n",
-   __func__, srate);
-   } else
-   srate = 1500;
-
priv->regs[RSTV6110_CTRL2] &= ~0x0f;
priv->regs[RSTV6110_CTRL2] |= (priv->gain & 0x0f);
 



Re: [PATCH 2/5] media: stv6110: get rid of a srate dead code

2017-09-15 Thread Honza Petrouš
Mauro, you are so speedy :)

2017-09-15 11:10 GMT+02:00 Mauro Carvalho Chehab :
> The stv6110 has a weird code that checks if get_property
> and set_property ioctls are defined. If they're, it initializes
> a "srate" var from properties cache. Otherwise, it sets to
> 15MBaud, with won't make any sense.
>
> Thankfully, it seems that someone already noticed, as the
> "srate" is not used anywhere!

Hehe! "Someone else" :)

>
> So, get rid of that really weird dead code logic.
>
> Signed-off-by: Mauro Carvalho Chehab 

Reported-by: Honza Petrous 

> ---
>  drivers/media/dvb-frontends/stv6110.c | 8 
>  1 file changed, 8 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/stv6110.c 
> b/drivers/media/dvb-frontends/stv6110.c
> index e4fd9c1b0560..2821f6da6764 100644
> --- a/drivers/media/dvb-frontends/stv6110.c
> +++ b/drivers/media/dvb-frontends/stv6110.c
> @@ -262,7 +262,6 @@ static int stv6110_set_frequency(struct dvb_frontend *fe, 
> u32 frequency)
> u8 ret = 0x04;
> u32 divider, ref, p, presc, i, result_freq, vco_freq;
> s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
> -   s32 srate;
>
> dprintk("%s, freq=%d kHz, mclk=%d Hz\n", __func__,
> frequency, priv->mclk);
> @@ -273,13 +272,6 @@ static int stv6110_set_frequency(struct dvb_frontend 
> *fe, u32 frequency)
> priv->mclk / 100) - 16) & 0x1f) << 3);
>
> /* BB_GAIN = db/2 */
> -   if (fe->ops.set_property && fe->ops.get_property) {
> -   srate = c->symbol_rate;
> -   dprintk("%s: Get Frontend parameters: srate=%d\n",
> -   __func__, srate);
> -   } else
> -   srate = 1500;
> -
> priv->regs[RSTV6110_CTRL2] &= ~0x0f;
> priv->regs[RSTV6110_CTRL2] |= (priv->gain & 0x0f);
>
> --
> 2.13.5
>

Don't be offended, I simply smiled on the therm "someone else"

/Honza


[PATCH] util: qv4l2: fix discrete frame size selection.

2017-09-15 Thread Konstantin Oblaukhov
qv4l2 hasn't work correctly with discrete frame sizes. 
In case of capture device with discrete frame sizes, size combo-box wasn't 
shown.
In case of output device with discrete frame sizes, qv4l2 was segfaulting.
This patch fix discrete size combo-box both for capture and output devices.

Also Qt's project file got updated.

---
 utils/qv4l2/general-tab.cpp | 30 ++
 utils/qv4l2/qv4l2.pro   |  5 -
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/utils/qv4l2/general-tab.cpp b/utils/qv4l2/general-tab.cpp
index 9c1dbc7e..78c5cb2d 100644
--- a/utils/qv4l2/general-tab.cpp
+++ b/utils/qv4l2/general-tab.cpp
@@ -595,8 +595,11 @@ void GeneralTab::outputSection(v4l2_output vout)
return;
 
QWidget *wFrameWH = new QWidget();
+   QWidget *wFrameSR = new QWidget();
QGridLayout *m_wh = new QGridLayout(wFrameWH);
+   QGridLayout *m_sr = new QGridLayout(wFrameSR);
m_grids.append(m_wh);
+   m_grids.append(m_sr);
 
m_wh->addWidget(new QLabel("Frame Width", parentWidget()), 0, 0, 
Qt::AlignLeft);
m_frameWidth = new QSpinBox(parentWidget());
@@ -608,7 +611,18 @@ void GeneralTab::outputSection(v4l2_output vout)
m_wh->addWidget(m_frameHeight, 0, 3, Qt::AlignLeft);
connect(m_frameHeight, SIGNAL(editingFinished()), 
SLOT(frameHeightChanged()));
 
+   m_sr->addWidget(new QLabel("Frame Size", parentWidget()), 0, 0, 
Qt::AlignLeft);
+   m_frameSize = new QComboBox(parentWidget());
+   m_sr->addWidget(m_frameSize, 0, 1, Qt::AlignLeft);
+   connect(m_frameSize, SIGNAL(activated(int)), 
SLOT(frameSizeChanged(int)));
+
+   m_sr->addWidget(new QLabel("Frame Rate", parentWidget()), 0, 2, 
Qt::AlignLeft);
+   m_frameInterval = new QComboBox(parentWidget());
+   m_sr->addWidget(m_frameInterval, 0, 3, Qt::AlignLeft);
+   connect(m_frameInterval, SIGNAL(activated(int)), 
SLOT(frameIntervalChanged(int)));
+
m_stackedFrameSettings->addWidget(wFrameWH);
+   m_stackedFrameSettings->addWidget(wFrameSR);
 
QGridLayout::addWidget(m_stackedFrameSettings, m_row, 0, 1, m_cols, 
Qt::AlignVCenter);
m_row++;
@@ -1184,7 +1198,7 @@ void GeneralTab::updateGUIInput(__u32 input)
m_stackedStandards->show();
m_stackedFrequency->hide();
} else if (in.capabilities & V4L2_IN_CAP_DV_TIMINGS) {
-   m_stackedFrameSettings->setCurrentIndex(0);
+   m_stackedFrameSettings->setCurrentIndex(m_discreteSizes ? 1 : 
0);
m_stackedFrameSettings->show();
m_stackedStandards->setCurrentIndex(1);
m_stackedStandards->show();
@@ -1216,8 +1230,8 @@ void GeneralTab::updateGUIOutput(__u32 output)
m_stackedStandards->setCurrentIndex(0);
m_stackedStandards->show();
m_stackedFrequency->hide();
-   } else if (out.capabilities & V4L2_OUT_CAP_DV_TIMINGS) {
-   m_stackedFrameSettings->setCurrentIndex(0);
+   } else if (out.capabilities & V4L2_OUT_CAP_DV_TIMINGS) {
+   m_stackedFrameSettings->setCurrentIndex(m_discreteSizes ? 1 : 
0);
m_stackedFrameSettings->show();
m_stackedStandards->setCurrentIndex(1);
m_stackedStandards->show();
@@ -2157,7 +2171,12 @@ void GeneralTab::updateFrameSize()
m_frameSize->setCurrentIndex(frmsize.index);
} while (!enum_framesizes(frmsize));
 
+
m_discreteSizes = true;
+   if (m_frameSize)
+   m_frameSize->setEnabled(true);
+   m_stackedFrameSettings->setCurrentIndex(1);
+
m_frameWidth->setEnabled(false);
m_frameWidth->blockSignals(true);
m_frameWidth->setMinimum(m_width);
@@ -2171,7 +2190,9 @@ void GeneralTab::updateFrameSize()
m_frameHeight->setMaximum(m_height);
m_frameHeight->setValue(m_height);
m_frameHeight->blockSignals(false);
-   m_frameSize->setEnabled(!m_haveBuffers);
+m_frameSize->setEnabled(!m_haveBuffers);
+
+
updateFrameInterval();
return;
}
@@ -2186,6 +2207,7 @@ void GeneralTab::updateFrameSize()
m_discreteSizes = false;
if (m_frameSize)
m_frameSize->setEnabled(false);
+   m_stackedFrameSettings->setCurrentIndex(0);
if (!m_frameWidth) {
updateFrameInterval();
return;
diff --git a/utils/qv4l2/qv4l2.pro b/utils/qv4l2/qv4l2.pro
index 6420fa24..be59dced 100644
--- a/utils/qv4l2/qv4l2.pro
+++ b/utils/qv4l2/qv4l2.pro
@@ -26,6 +26,7 @@ HEADERS += general-tab.h
 HEADERS += qv4l2.h
 HEADERS += raw2sliced.h
 HEADERS += vbi-tab.h
+HEADERS += alsa_stream.h
 HEADERS += ../common/v4l2-tpg.h
 HEADERS += ../common/v4l2-tpg-colors.h
 HEADERS += ../../config.h
@@ -39,12 +40,14 @@ SOURCES += qv4l2.cpp
 

[PATCH 4/5] media: dvb_frontend: get rid of get_property() callback

2017-09-15 Thread Mauro Carvalho Chehab
Only lg2160 implement gets_property, but there's no need for that,
as no other driver calls this callback, as get_frontend() does the
same, and set_frontend() also calls lg2160 get_frontend().

So, get rid of it.

Signed-off-by: Mauro Carvalho Chehab 
Reviewed-by: Michael Ira Krufky 
---
 drivers/media/dvb-core/dvb_frontend.c |  9 +
 drivers/media/dvb-core/dvb_frontend.h |  3 ---
 drivers/media/dvb-frontends/lg2160.c  | 14 --
 3 files changed, 1 insertion(+), 25 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 9139d01ba7ed..5d00e46d9432 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1325,7 +1325,7 @@ static int dtv_property_process_get(struct dvb_frontend 
*fe,
struct dtv_property *tvp,
struct file *file)
 {
-   int r, ncaps;
+   int ncaps;
 
switch(tvp->cmd) {
case DTV_ENUM_DELSYS:
@@ -1536,13 +1536,6 @@ static int dtv_property_process_get(struct dvb_frontend 
*fe,
return -EINVAL;
}
 
-   /* Allow the frontend to override outgoing properties */
-   if (fe->ops.get_property) {
-   r = fe->ops.get_property(fe, tvp);
-   if (r < 0)
-   return r;
-   }
-
dtv_property_dump(fe, false, tvp);
 
return 0;
diff --git a/drivers/media/dvb-core/dvb_frontend.h 
b/drivers/media/dvb-core/dvb_frontend.h
index 907a05bde162..4d05846f2c1c 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -403,8 +403,6 @@ struct dtv_frontend_properties;
  * @analog_ops:pointer to struct analog_demod_ops
  * @set_property:  callback function to allow the frontend to validade
  * incoming properties. Should not be used on new drivers.
- * @get_property:  callback function to allow the frontend to override
- * outcoming properties. Should not be used on new drivers.
  */
 struct dvb_frontend_ops {
 
@@ -468,7 +466,6 @@ struct dvb_frontend_ops {
struct analog_demod_ops analog_ops;
 
int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
-   int (*get_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
 };
 
 #ifdef __DVB_CORE__
diff --git a/drivers/media/dvb-frontends/lg2160.c 
b/drivers/media/dvb-frontends/lg2160.c
index 5798079add10..9854096839ae 100644
--- a/drivers/media/dvb-frontends/lg2160.c
+++ b/drivers/media/dvb-frontends/lg2160.c
@@ -1048,16 +1048,6 @@ static int lg216x_get_frontend(struct dvb_frontend *fe,
return ret;
 }
 
-static int lg216x_get_property(struct dvb_frontend *fe,
-  struct dtv_property *tvp)
-{
-   struct dtv_frontend_properties *c = >dtv_property_cache;
-
-   return (DTV_ATSCMH_FIC_VER == tvp->cmd) ?
-   lg216x_get_frontend(fe, c) : 0;
-}
-
-
 static int lg2160_set_frontend(struct dvb_frontend *fe)
 {
struct lg216x_state *state = fe->demodulator_priv;
@@ -1368,8 +1358,6 @@ static const struct dvb_frontend_ops lg2160_ops = {
.init = lg216x_init,
.sleep= lg216x_sleep,
 #endif
-   .get_property = lg216x_get_property,
-
.set_frontend = lg2160_set_frontend,
.get_frontend = lg216x_get_frontend,
.get_tune_settings= lg216x_get_tune_settings,
@@ -1396,8 +1384,6 @@ static const struct dvb_frontend_ops lg2161_ops = {
.init = lg216x_init,
.sleep= lg216x_sleep,
 #endif
-   .get_property = lg216x_get_property,
-
.set_frontend = lg2160_set_frontend,
.get_frontend = lg216x_get_frontend,
.get_tune_settings= lg216x_get_tune_settings,
-- 
2.13.5



[PATCH 3/5] media: friio-fe: get rid of set_property()

2017-09-15 Thread Mauro Carvalho Chehab
This callback is not actually doing anything but making it to
return an error depending on the DTV frontend command. Well,
that could break userspace for no good reason, and, if needed,
should be implemented, instead, at set_frontend() callback.

So, get rid of it.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/friio-fe.c | 24 
 1 file changed, 24 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/friio-fe.c 
b/drivers/media/usb/dvb-usb/friio-fe.c
index 0251a4e91d47..41261317bd5c 100644
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ b/drivers/media/usb/dvb-usb/friio-fe.c
@@ -261,28 +261,6 @@ static int jdvbt90502_read_signal_strength(struct 
dvb_frontend *fe,
return 0;
 }
 
-
-/* filter out un-supported properties to notify users */
-static int jdvbt90502_set_property(struct dvb_frontend *fe,
-  struct dtv_property *tvp)
-{
-   int r = 0;
-
-   switch (tvp->cmd) {
-   case DTV_DELIVERY_SYSTEM:
-   if (tvp->u.data != SYS_ISDBT)
-   r = -EINVAL;
-   break;
-   case DTV_CLEAR:
-   case DTV_TUNE:
-   case DTV_FREQUENCY:
-   break;
-   default:
-   r = -EINVAL;
-   }
-   return r;
-}
-
 static int jdvbt90502_set_frontend(struct dvb_frontend *fe)
 {
struct dtv_frontend_properties *p = >dtv_property_cache;
@@ -457,8 +435,6 @@ static const struct dvb_frontend_ops jdvbt90502_ops = {
.init = jdvbt90502_init,
.write = _jdvbt90502_write,
 
-   .set_property = jdvbt90502_set_property,
-
.set_frontend = jdvbt90502_set_frontend,
 
.read_status = jdvbt90502_read_status,
-- 
2.13.5



[PATCH 1/5] media: stv0288: get rid of set_property boilerplate

2017-09-15 Thread Mauro Carvalho Chehab
This driver doesn't implement support for set_property(). Yet,
it implements a boilerplate for it. Get rid of it.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/dvb-frontends/stv0288.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0288.c 
b/drivers/media/dvb-frontends/stv0288.c
index 45cbc898ad25..67f91814b9f7 100644
--- a/drivers/media/dvb-frontends/stv0288.c
+++ b/drivers/media/dvb-frontends/stv0288.c
@@ -447,12 +447,6 @@ static int stv0288_read_ucblocks(struct dvb_frontend *fe, 
u32 *ucblocks)
return 0;
 }
 
-static int stv0288_set_property(struct dvb_frontend *fe, struct dtv_property 
*p)
-{
-   dprintk("%s(..)\n", __func__);
-   return 0;
-}
-
 static int stv0288_set_frontend(struct dvb_frontend *fe)
 {
struct stv0288_state *state = fe->demodulator_priv;
@@ -567,7 +561,6 @@ static const struct dvb_frontend_ops stv0288_ops = {
.set_tone = stv0288_set_tone,
.set_voltage = stv0288_set_voltage,
 
-   .set_property = stv0288_set_property,
.set_frontend = stv0288_set_frontend,
 };
 
-- 
2.13.5



[PATCH 2/5] media: stv6110: get rid of a srate dead code

2017-09-15 Thread Mauro Carvalho Chehab
The stv6110 has a weird code that checks if get_property
and set_property ioctls are defined. If they're, it initializes
a "srate" var from properties cache. Otherwise, it sets to
15MBaud, with won't make any sense.

Thankfully, it seems that someone already noticed, as the
"srate" is not used anywhere!

So, get rid of that really weird dead code logic.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/dvb-frontends/stv6110.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv6110.c 
b/drivers/media/dvb-frontends/stv6110.c
index e4fd9c1b0560..2821f6da6764 100644
--- a/drivers/media/dvb-frontends/stv6110.c
+++ b/drivers/media/dvb-frontends/stv6110.c
@@ -262,7 +262,6 @@ static int stv6110_set_frequency(struct dvb_frontend *fe, 
u32 frequency)
u8 ret = 0x04;
u32 divider, ref, p, presc, i, result_freq, vco_freq;
s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
-   s32 srate;
 
dprintk("%s, freq=%d kHz, mclk=%d Hz\n", __func__,
frequency, priv->mclk);
@@ -273,13 +272,6 @@ static int stv6110_set_frequency(struct dvb_frontend *fe, 
u32 frequency)
priv->mclk / 100) - 16) & 0x1f) << 3);
 
/* BB_GAIN = db/2 */
-   if (fe->ops.set_property && fe->ops.get_property) {
-   srate = c->symbol_rate;
-   dprintk("%s: Get Frontend parameters: srate=%d\n",
-   __func__, srate);
-   } else
-   srate = 1500;
-
priv->regs[RSTV6110_CTRL2] &= ~0x0f;
priv->regs[RSTV6110_CTRL2] |= (priv->gain & 0x0f);
 
-- 
2.13.5



[PATCH 5/5] media: dvb_frontend: get rid of set_property() callback

2017-09-15 Thread Mauro Carvalho Chehab
Now that all clients of set_property() were removed, get rid
of this callback.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/dvb-core/dvb_frontend.c | 7 ---
 drivers/media/dvb-core/dvb_frontend.h | 2 --
 2 files changed, 9 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 5d00e46d9432..8abe4f541a36 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1766,13 +1766,6 @@ static int dtv_property_process_set(struct dvb_frontend 
*fe,
int r = 0;
struct dtv_frontend_properties *c = >dtv_property_cache;
 
-   /* Allow the frontend to validate incoming properties */
-   if (fe->ops.set_property) {
-   r = fe->ops.set_property(fe, tvp);
-   if (r < 0)
-   return r;
-   }
-
dtv_property_dump(fe, true, tvp);
 
switch(tvp->cmd) {
diff --git a/drivers/media/dvb-core/dvb_frontend.h 
b/drivers/media/dvb-core/dvb_frontend.h
index 4d05846f2c1c..a50f8216ab76 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -401,8 +401,6 @@ struct dtv_frontend_properties;
  * @search:callback function used on some custom algo search algos.
  * @tuner_ops: pointer to struct dvb_tuner_ops
  * @analog_ops:pointer to struct analog_demod_ops
- * @set_property:  callback function to allow the frontend to validade
- * incoming properties. Should not be used on new drivers.
  */
 struct dvb_frontend_ops {
 
-- 
2.13.5



Re: [PATCH v1] [DVB][FRONTEND] Added a new ioctl for optimizing frontend property set operation

2017-09-15 Thread Mauro Carvalho Chehab
Em Fri, 15 Sep 2017 01:50:29 -0400
Satendra Singh Thakur  escreveu:

> Hello  Mr Chehab,
> Thanks for reviewing the patch.
> I have modified the patch as per your comments.
> Please check if it looks fine now.

Forgot to mention, but, for the patch series to be applied, you'll need to
also patch Documentation/media/uapi/dvb.

> Signed-off-by: Satendra Singh Thakur 
> ---
>  drivers/media/dvb-core/dvb_frontend.c | 212 
> +-
>  include/uapi/linux/dvb/frontend.h |  24 
>  2 files changed, 234 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index e3fff8f..bc35a86 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -1914,6 +1914,188 @@ static int dtv_property_process_set(struct 
> dvb_frontend *fe,
>   return r;
>  }
>  
> +/**
> + * dtv_property_short_process_set
> + * @fe: Pointer to struct dvb_frontend
> + * @file: Pointer to struct file
> + * @cmd: Property name
> + * @data: Property value
> + *
> + * helper function for dvb_frontend_ioctl_properties,
> + * which can be used to set dtv property using ioctl
> + * cmd FE_SET_PROPERTY_SHORT.
> + * It assigns property value to corresponding member of
> + * property-cache structure
> + * This func is a variant of the func dtv_property_process_set
> + * Returns:
> + * Zero on success, negative errno on failure.
> + */
> +static int dtv_property_short_process_set(struct dvb_frontend *fe,
> + struct file *file,
> + u32 cmd, u32 data)
> +{
> + int r = 0;
> + struct dtv_frontend_properties *c = >dtv_property_cache;
> + switch (cmd) {
> + case DTV_CLEAR:
> + /*
> +  * Reset a cache of data specific to the frontend here. This
> +  * does not effect hardware.
> +  */
> + dvb_frontend_clear_cache(fe);
> + break;

No, you got me wrong. What I want is to have just *one* switch that
would work for both the normal and the short version of this ioctl.

In other words, I was expecting you to patch the existing
dtv_property_process_set() for it to take u32 cmd and u32 data as
arguments and to be used by both FE_SET_PROPERTY and FE_SET_PROPERTY_SHORT
handling.

> + case DTV_TUNE:
> + /* interpret the cache of data, build either a traditional
> +  * frontend tune request so we can pass validation in the
> +  * FE_SET_FRONTEND  ioctl.
> +  */
> + c->state = cmd;
> + dev_dbg(fe->dvb->device, "%s: Finalised property cache\n",
> + __func__);
> +
> + r = dtv_set_frontend(fe);
> + break;
> + case DTV_FREQUENCY:
> + c->frequency = data;
> + break;
> + case DTV_MODULATION:
> + c->modulation = data;
> + break;
> + case DTV_BANDWIDTH_HZ:
> + c->bandwidth_hz = data;
> + break;
> + case DTV_INVERSION:
> + c->inversion = data;
> + break;
> + case DTV_SYMBOL_RATE:
> + c->symbol_rate = data;
> + break;
> + case DTV_INNER_FEC:
> + c->fec_inner = data;
> + break;
> + case DTV_PILOT:
> + c->pilot = data;
> + break;
> + case DTV_ROLLOFF:
> + c->rolloff = data;
> + break;
> + case DTV_DELIVERY_SYSTEM:
> + r = dvbv5_set_delivery_system(fe, data);
> + break;
> + case DTV_VOLTAGE:
> + c->voltage = data;
> + r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE,
> + (void *)c->voltage);
> + break;
> + case DTV_TONE:
> + c->sectone = data;
> + r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE,
> + (void *)c->sectone);
> + break;
> + case DTV_CODE_RATE_HP:
> + c->code_rate_HP = data;
> + break;
> + case DTV_CODE_RATE_LP:
> + c->code_rate_LP = data;
> + break;
> + case DTV_GUARD_INTERVAL:
> + c->guard_interval = data;
> + break;
> + case DTV_TRANSMISSION_MODE:
> + c->transmission_mode = data;
> + break;
> + case DTV_HIERARCHY:
> + c->hierarchy = data;
> + break;
> + case DTV_INTERLEAVING:
> + c->interleaving = data;
> + break;
> +
> + /* ISDB-T Support here */
> + case DTV_ISDBT_PARTIAL_RECEPTION:
> + c->isdbt_partial_reception = data;
> + break;
> + case DTV_ISDBT_SOUND_BROADCASTING:
> + c->isdbt_sb_mode = data;
> + break;
> + case DTV_ISDBT_SB_SUBCHANNEL_ID:
> + c->isdbt_sb_subchannel = data;
> +

Re: [PATCH] dma-buf: remove redundant initialization of sg_table

2017-09-15 Thread Chris Wilson
Quoting Colin King (2017-09-15 00:05:16)
> From: Colin Ian King 
> 
> sg_table is being initialized and is never read before it is updated
> again later on, hence making the initialization redundant. Remove
> the initialization.
> 
> Detected by clang scan-build:
> "warning: Value stored to 'sg_table' during its initialization is
> never read"
> 
> Signed-off-by: Colin Ian King 
Reviewed-by: Chris Wilson 
-Chris


Re: [PATCHv4 3/5] dt-bindings: document the CEC GPIO bindings

2017-09-15 Thread Hans Verkuil
Hi Rob,

On 09/13/17 10:21, Hans Verkuil wrote:
> On 09/12/2017 04:43 PM, Rob Herring wrote:
>> On Thu, Aug 31, 2017 at 01:01:54PM +0200, Hans Verkuil wrote:
>>> From: Hans Verkuil 
>>>
>>> Document the bindings for the cec-gpio module for hardware where the
>>> CEC line and optionally the HPD line are connected to GPIO lines.
>>>
>>> Signed-off-by: Hans Verkuil 
>>> ---
>>>  .../devicetree/bindings/media/cec-gpio.txt | 22 
>>> ++
>>>  1 file changed, 22 insertions(+)
>>>  create mode 100644 Documentation/devicetree/bindings/media/cec-gpio.txt
>>>
>>> diff --git a/Documentation/devicetree/bindings/media/cec-gpio.txt 
>>> b/Documentation/devicetree/bindings/media/cec-gpio.txt
>>> new file mode 100644
>>> index ..db20a7452dbd
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/media/cec-gpio.txt
>>> @@ -0,0 +1,22 @@
>>> +* HDMI CEC GPIO driver
>>> +
>>> +The HDMI CEC GPIO module supports CEC implementations where the CEC line
>>> +is hooked up to a pull-up GPIO line and - optionally - the HPD line is
>>> +hooked up to another GPIO line.
>>> +
>>> +Required properties:
>>> +  - compatible: value must be "cec-gpio"
>>> +  - cec-gpio: gpio that the CEC line is connected to
>>
>> cec-gpios
> 
> Will change.
> 
>>
>>> +
>>> +Optional property:
>>> +  - hpd-gpio: gpio that the HPD line is connected to
>>
>> hpd-gpios
> 
> Will change.
> 
>>
>> However, HPD is already part of the HDMI connector binding. Having it in 
>> 2 places would be wrong.
> 
> No. This is not an HDMI receiver/transmitter. There are two use-cases for this
> driver:
> 
> 1) For HDMI receivers/transmitters that connect the CEC pin of an HDMI 
> connector
>to a GPIO pin. In that case the HPD goes to the HDMI transmitter/receiver 
> and
>not to this driver. As you say, that would not make any sense.
> 
>But currently no such devices are in the kernel (I know they exist, 
> though).
>Once such a driver would appear in the kernel then these bindings need to 
> be
>extended with an hdmi-phandle.
> 
> 2) This driver is used for debugging CEC like this:
> 
>   https://hverkuil.home.xs4all.nl/rpi3-cec.jpg
> 
>Here the CEC pin of an HDMI breakout connector is hooked up to a Raspberry 
> Pi
>GPIO pin and the RPi monitors it. It's a cheap but very effective CEC 
> analyzer.
>In this use-case it is very helpful to also monitor the HPD pin since some
>displays do weird things with the HPD and knowing the state of the HPD 
> helps
>a lot when debugging CEC problems. It's optional and it only monitors the 
> pin.
> 
>Actually, there does not have to be an HDMI connector involved at all: you 
> can
>make two cec-gpio instances and just connect the two GPIO pins together in
>order to emulate two CEC adapters and play with that.

Is it OK to define a binding but not (yet) implement it? I have seen that in 
other
bindings (well, OK, one other binding :-) ). If that is fine, then I can write 
the
following:


Required properties:
  - compatible: value must be "cec-gpio".
  - cec-gpios: gpio that the CEC line is connected to.

If the CEC line is associated with an HDMI receiver/transmitter, then the 
following
property is also required:

  - hdmi-phandle - phandle to the HDMI controller, see also cec.txt.

If the CEC line is not associated with an HDMI receiver/transmitter, then the
following property is optional:

  - hpd-gpios: gpio that the HPD line is connected to.


I have plans to support hdmi-phandle in the driver, but that probably won't be 
ready
in time for 4.15.

Regards,

Hans

> 
>>
>> I think we should have either:
>>
>> hdmi-connector {
>>  compatible = 'hdmi-connector-a";
>>  hpd-gpios = <...>;
>>  cec-gpios = <...>;
>>  ports {
>>  // port to HDMI controller
>>  ...
>>  };
>> };
>>
>> Or:
>>
>> hdmi-connector {
>> compatible = 'hdmi-connector-a";
>> hpd-gpios = <...>;
>> cec = <>;
>> ... 
>> };
>>
>> cec: cec-gpio {
>>  compatible = "cec-gpio";
>>  cec-gpios = <...>;
>> };
>>
>> My preference is probably the former. The latter just helps create a 
>> device to bind to a driver, but DT is not the only way to create 
>> devices. Then again, if you have a phandle to real CEC controllers in 
>> the HDMI connector node, it may make sense to do the same thing with 
>> cec-gpio. 
>>
>>> +
>>> +Example for the Raspberry Pi 3 where the CEC line is connected to
>>> +pin 26 aka BCM7 aka CE1 on the GPIO pin header and the HPD line is
>>> +connected to pin 11 aka BCM17:
>>> +
>>> +cec-gpio@7 {
>>
>> unit address is not valid. Build your dts's with W=2.
> 
> I'll do that.
> 
>>
>>> +   compatible = "cec-gpio";
>>> +   cec-gpio = < 7 GPIO_OPEN_DRAIN>;
>>> +   hpd-gpio = < 17 

Re: [RFC] [DVB][FRONTEND] Added a new ioctl for optimizing frontend property set operation

2017-09-15 Thread Honza Petrouš
2017-09-14 22:50 GMT+02:00 Mauro Carvalho Chehab :
> Hi Satendra,
>
> Em Thu, 14 Sep 2017 05:59:27 -0400
> Satendra Singh Thakur  escreveu:
>
>> -For setting one frontend property , one FE_SET_PROPERTY ioctl is called
>> -Since, size of struct dtv_property is 72 bytes, this ioctl requires
>> ---allocating 72 bytes of memory in user space
>> ---allocating 72 bytes of memory in kernel space
>> ---copying 72 bytes of data from user space to kernel space
>> -However, for all the properties, only 8 out of 72 bytes are used
>>  for setting the property
>
> That's true. Yet, for get, the size can be bigger, as ISDB-T can
> return statistics per layer, plus a global one.
>
>> -Four bytes are needed for specifying property type and another 4 for
>>  property value
>> -Moreover, there are 2 properties DTV_CLEAR and DTV_TUNE which use
>>  only 4 bytes for property name
>> ---They don't use property value
>> -Therefore, we have defined new short variant/forms/version of currently
>>  used structures for such 8 byte properties.
>> -This results in 89% (8*100/72) of memory saving in user and kernel space
>>  each.
>> -This also results in faster copy (8 bytes as compared to 72 bytes) from
>>  user to kernel space
>> -We have added new ioctl FE_SET_PROPERTY_SHORT which utilizes above
>>  mentioned new property structures
>> -This ioctl can co-exist with present ioctl FE_SET_PROPERTY
>> -If the apps wish to use shorter forms they can use
>>  proposed FE_SET_PROPERTY_SHORT, rest of them can continue to use
>>  current versions FE_SET_PROPERTY
>
>> -We are currently not validating incoming properties in
>>  function dtv_property_short_process_set because most of
>>  the frontend drivers in linux source are not using the
>>  method ops.set_property. Just two drivers are using it
>>  drivers/media/dvb-frontends/stv0288.c
>>  driver/media/usb/dvb-usb/friio-fe.c
>>  -Moreover, stv0288 driver implemments blank function
>>  for set_property.
>> -If needed in future, we can define a new
>>  ops.set_property_short method to support
>>  struct dtv_property_short.
>
> Nah. Better to just get rid of get_property()/set_froperty() for good.
>
> Just sent a RFC patch series doing that.
>
> The only thing is that stv6110 seems to have a dirty hack that may
> depend on that. Someone need to double-check if the patch series
> I just sent doesn't break anything. If it breaks, then we'll need
> to add an extra parameter to stv6110 attach for it to know what
> behavior is needed there.

Do you mean in stv6110_set_frequency()?

I must say I was shocked by the beginning of it.
Can somebody explain me the reason for such strange
srate computation?

See the head of function:

static int stv6110_set_frequency(struct dvb_frontend *fe, u32 frequency)
{
struct stv6110_priv *priv = fe->tuner_priv;
struct dtv_frontend_properties *c = >dtv_property_cache;
u8 ret = 0x04;
u32 divider, ref, p, presc, i, result_freq, vco_freq;
s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
s32 srate;

dprintk("%s, freq=%d kHz, mclk=%d Hz\n", __func__,
frequency, priv->mclk);

/* K = (Reference / 100) - 16 */
priv->regs[RSTV6110_CTRL1] &= ~(0x1f << 3);
priv->regs[RSTV6110_CTRL1] |=
priv->mclk / 100) - 16) & 0x1f) << 3);

/* BB_GAIN = db/2 */
if (fe->ops.set_property && fe->ops.get_property) {
srate = c->symbol_rate;
dprintk("%s: Get Frontend parameters: srate=%d\n",
__func__, srate);
} else
srate = 1500;

 here I would like to note, there there is NO MORE
anything dependant on srate. It looks like some dead code for me.

And the condition sentence looks even more funny - is it
for real to check of retrieval of srate only in case
if some other function pointers are not null?

/Honza

PS: Don't forget that we have duplicated drivers for STV6110,
stv6110 by Igor and stv6110x by Manu.


RE: [PATCH] [media] rcar_drif: fix potential uninitialized variable use

2017-09-15 Thread Ramesh Shanmugasundaram
Hi Arnd,

Thank you for the patch.

> Subject: [PATCH] [media] rcar_drif: fix potential uninitialized variable
> use
> 
> Older compilers like gcc-4.6 may run into a case that returns an
> uninitialized variable from rcar_drif_enable_rx() if that function was
> ever called with an empty cur_ch_mask:
> 
> drivers/media/platform/rcar_drif.c:658:2: error: ‘ret’ may be used
> uninitialized in this function [-Werror=uninitialized]
> 
> Newer compilers don't have that problem as they optimize the 'ret'
> variable away and just return zero in that case.
> 
> This changes the function to return -EINVAL for this particular failure,
> to make it consistent across all compiler versions.
> In case gcc gets changed to report a warning for it in the future, it's
> also a good idea to shut it up now.
> 
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82203
> Signed-off-by: Arnd Bergmann 

Acked-by: Ramesh Shanmugasundaram 

Thanks,
Ramesh


[GIT FIXES FOR v4.14] Two CEC fixes

2017-09-15 Thread Hans Verkuil
Hi Mauro,

Two CEC fixes for 4.14. Both are also CC-ed to stable. These fixes fall in the
category 'important but not urgent'.

Regards,

Hans

The following changes since commit 1efdf1776e2253b77413c997bed862410e4b6aaf:

  media: leds: as3645a: add V4L2_FLASH_LED_CLASS dependency (2017-09-05 
16:32:45 -0400)

are available in the git repository at:

  git://linuxtv.org/hverkuil/media_tree.git for-v4.14n

for you to fetch changes up to 2f4c7705f22e53a13de2e4932f62f1393816fa73:

  cec: Respond to unregistered initiators, when applicable (2017-09-15 10:04:28 
+0200)


Hans Verkuil (1):
  s5p-cec: add NACK detection support

Jose Abreu (1):
  cec: Respond to unregistered initiators, when applicable

 drivers/media/cec/cec-adap.c | 13 ++---
 drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c |  3 ++-
 drivers/media/platform/s5p-cec/s5p_cec.c | 11 ++-
 drivers/media/platform/s5p-cec/s5p_cec.h |  2 ++
 4 files changed, 24 insertions(+), 5 deletions(-)


[PATCH 9/9] [media] tm6000: Use common error handling code in tm6000_prepare_isoc()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 08:02:33 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-video.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-video.c 
b/drivers/media/usb/tm6000/tm6000-video.c
index 0d45f35e1697..bfdeb41ed3a1 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -602,7 +602,5 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
-   if (!dev->isoc_ctl.transfer_buffer) {
-   kfree(dev->isoc_ctl.urb);
-   return -ENOMEM;
-   }
+   if (!dev->isoc_ctl.transfer_buffer)
+   goto free_urb;
 
dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets (%d bytes) 
of %d bytes each to handle %u size\n",
max_packets, num_bufs, sb_size,
@@ -616,7 +614,6 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
tm6000_free_urb_buffers(dev);
-   kfree(dev->isoc_ctl.urb);
kfree(dev->isoc_ctl.transfer_buffer);
-   return -ENOMEM;
+   goto free_urb;
}
 
/* allocate urbs and transfer buffers */
@@ -646,6 +643,10 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
}
 
return 0;
+
+free_urb:
+   kfree(dev->isoc_ctl.urb);
+   return -ENOMEM;
 }
 
 static int tm6000_start_thread(struct tm6000_core *dev)
-- 
2.14.1



[PATCH 8/9] [media] tm6000: Use common error handling code in tm6000_start_stream()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 07:47:41 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-dvb.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-dvb.c 
b/drivers/media/usb/tm6000/tm6000-dvb.c
index 855874134fcf..b45e54d5cab9 100644
--- a/drivers/media/usb/tm6000/tm6000-dvb.c
+++ b/drivers/media/usb/tm6000/tm6000-dvb.c
@@ -134,8 +134,8 @@ static int tm6000_start_stream(struct tm6000_core *dev)
 
dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
if (!dvb->bulk_urb->transfer_buffer) {
-   usb_free_urb(dvb->bulk_urb);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto free_urb;
}
 
usb_fill_bulk_urb(dvb->bulk_urb, dev->udev, pipe,
@@ -160,11 +160,14 @@ static int tm6000_start_stream(struct tm6000_core *dev)
ret);
 
kfree(dvb->bulk_urb->transfer_buffer);
-   usb_free_urb(dvb->bulk_urb);
-   return ret;
+   goto free_urb;
}
 
return 0;
+
+free_urb:
+   usb_free_urb(dvb->bulk_urb);
+   return ret;
 }
 
 static void tm6000_stop_stream(struct tm6000_core *dev)
-- 
2.14.1



[PATCH 7/9] [media] tm6000: Improve a size determination in dvb_init()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 07:33:24 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-dvb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/tm6000/tm6000-dvb.c 
b/drivers/media/usb/tm6000/tm6000-dvb.c
index 2bc584f75f87..855874134fcf 100644
--- a/drivers/media/usb/tm6000/tm6000-dvb.c
+++ b/drivers/media/usb/tm6000/tm6000-dvb.c
@@ -398,7 +398,7 @@ static int dvb_init(struct tm6000_core *dev)
return 0;
}
 
-   dvb = kzalloc(sizeof(struct tm6000_dvb), GFP_KERNEL);
+   dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
if (!dvb)
return -ENOMEM;
 
-- 
2.14.1



[PATCH 6/9] [media] tm6000: Use common error handling code in tm6000_cards_setup()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 16:26:42 +0200

Add a jump target so that a bit of exception handling can be better reused
in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index 72dd6b80394f..502e0b38b7f1 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -872,15 +872,14 @@ int tm6000_cards_setup(struct tm6000_core *dev)
for (i = 0; i < 2; i++) {
rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
dev->gpio.tuner_reset, 0x00);
-   if (rc < 0) {
-   printk(KERN_ERR "Error %i doing tuner reset\n", 
rc);
-   return rc;
-   }
+   if (rc < 0)
+   goto report_failure;
 
msleep(10); /* Just to be conservative */
rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
dev->gpio.tuner_reset, 0x01);
if (rc < 0) {
+report_failure:
printk(KERN_ERR "Error %i doing tuner reset\n", 
rc);
return rc;
}
-- 
2.14.1



[PATCH 5/9] [media] tm6000: Delete an unnecessary variable initialisation in tm6000_usb_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 16:13:56 +0200

The local variable "rc" will be set to an appropriate value a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index 77347541904d..72dd6b80394f 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1185,7 +1185,7 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
 {
struct usb_device *usbdev;
struct tm6000_core *dev;
-   int i, rc = 0;
+   int i, rc;
int nr = 0;
char *speed;
 
-- 
2.14.1



[PATCH 4/9] [media] tm6000: One function call less in tm6000_usb_probe() after error detection

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 16:11:55 +0200

* Adjust jump targets so that the function "kfree" will be always called
  with a non-null pointer.

* Delete an initialisation for the local variable "dev"
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index e18632056976..77347541904d 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1184,7 +1184,7 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
const struct usb_device_id *id)
 {
struct usb_device *usbdev;
-   struct tm6000_core *dev = NULL;
+   struct tm6000_core *dev;
int i, rc = 0;
int nr = 0;
char *speed;
@@ -1194,7 +1194,7 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
/* Selects the proper interface */
rc = usb_set_interface(usbdev, 0, 1);
if (rc < 0)
-   goto err;
+   goto report_failure;
 
/* Check to see next free device and mark as used */
nr = find_first_zero_bit(_devused, TM6000_MAXBOARDS);
@@ -1312,8 +1312,7 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
if (!dev->isoc_in.endp) {
printk(KERN_ERR "tm6000: probing error: no IN ISOC 
endpoint!\n");
rc = -ENODEV;
-
-   goto err;
+   goto free_device;
}
 
/* save our data pointer in this interface device */
@@ -1323,16 +1322,16 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
 
rc = tm6000_init_dev(dev);
if (rc < 0)
-   goto err;
+   goto free_device;
 
return 0;
 
-err:
+free_device:
+   kfree(dev);
+report_failure:
printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
 
clear_bit(nr, _devused);
-
-   kfree(dev);
 put_device:
usb_put_dev(usbdev);
return rc;
-- 
2.14.1



[PATCH v5 1/2] media:imx274 device tree binding file

2017-09-15 Thread Leon Luo
The binding file for imx274 CMOS sensor V4l2 driver

Signed-off-by: Leon Luo 
---
v5:
 - add 'port' and 'endpoint' information
v4:
 - no changes
v3:
 - remove redundant properties and references
 - document 'reg' property
v2:
 - no changes
---
 .../devicetree/bindings/media/i2c/imx274.txt   | 33 ++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/imx274.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/imx274.txt 
b/Documentation/devicetree/bindings/media/i2c/imx274.txt
new file mode 100644
index ..80f2e89568e1
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/imx274.txt
@@ -0,0 +1,33 @@
+* Sony 1/2.5-Inch 8.51Mp CMOS Digital Image Sensor
+
+The Sony imx274 is a 1/2.5-inch CMOS active pixel digital image sensor with
+an active array size of 3864H x 2202V. It is programmable through I2C
+interface. The I2C address is fixed to 0x1a as per sensor data sheet.
+Image data is sent through MIPI CSI-2, which is configured as 4 lanes
+at 1440 Mbps.
+
+
+Required Properties:
+- compatible: value should be "sony,imx274" for imx274 sensor
+- reg: I2C bus address of the device
+
+Optional Properties:
+- reset-gpios: Sensor reset GPIO
+
+The imx274 device node should contain one 'port' child node with
+an 'endpoint' subnode. For further reading on port node refer to
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+   sensor@1a {
+   compatible = "sony,imx274";
+   reg = <0x1a>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reset-gpios = <_sensor 0 0>;
+   port {
+   sensor_out: endpoint {
+   remote-endpoint = <_in>;
+   };
+   };
+   };
-- 
2.14.0.rc1



[PATCH v5 2/2] media:imx274 V4l2 driver for Sony imx274 CMOS sensor

2017-09-15 Thread Leon Luo
The imx274 is a Sony CMOS image sensor that has 1/2.5 image size.
It supports up to 3840x2160 (4K) 60fps, 1080p 120fps. The interface
is 4-lane MIPI CSI-2 running at 1.44Gbps each.

This driver has been tested on Xilinx ZCU102 platform with a Leopard
LI-IMX274MIPI-FMC camera board.

Support for the following features:
-Resolutions: 3840x2160, 1920x1080, 1280x720
-Frame rate: 3840x2160 : 5 – 60fps
1920x1080 : 5 – 120fps
1280x720 : 5 – 120fps
-Exposure time: 16 – (frame interval) micro-seconds
-Gain: 1x - 180x
-VFLIP: enable/disabledrivers/media/i2c/imx274.c
-Test pattern: 12 test patterns

Signed-off-by: Leon Luo 
Tested-by: Sören Brinkmann 
---
v5:
 - no changes
v4:
 - use 32-bit data type to avoid __divdi3 compile error for i386
 - clean up OR together error codes
v3:
 - clean up header files
 - use struct directly instead of alias #define
 - use v4l2_ctrl_s_ctrl instead of v4l2_s_ctrl
 - revise debug output
 - move static helpers closer to their call site
 - don't OR toegether error codes
 - use closest valid gain value instead of erroring out
 - assigne lock to the control handler and omit explicit locking
 - acquire mutex lock for imx274_get_fmt
 - remove format->pad check in imx274_set_fmt since the pad is always 0
 - pass struct v4l2_ctrl pointer in gain/exposure/vlip/test pattern controls
 - remove priv->ctrls.vflip->val = val in imx274_set_vflip()
 - remove priv->ctrls.test_pattern->val = val in imx274_set_test_pattern()
 - remove empty open/close callbacks
 - remove empty core ops
 - add more error labels in probe
 - use v4l2_async_unregister_subdev instead of v4l2_device_unregister_subdev
 - use dynamic debug
 - split start_stream to two steps: imx274_mode_regs() and imx274_start_stream()
   frame rate & exposure can be updated
   between imx274_mode_regs() & imx274_start_stream()

v2:
 - Fix Kconfig to not remove existing options
---
 drivers/media/i2c/Kconfig  |7 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx274.c | 1808 
 3 files changed, 1816 insertions(+)
 create mode 100644 drivers/media/i2c/imx274.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 94153895fcd4..ad2e70a02363 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -547,6 +547,13 @@ config VIDEO_APTINA_PLL
 config VIDEO_SMIAPP_PLL
tristate
 
+config VIDEO_IMX274
+   tristate "Sony IMX274 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   ---help---
+ This is a V4L2 sensor-level driver for the Sony IMX274
+ CMOS image sensor.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index c843c181dfb9..f8d57e453936 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -92,5 +92,6 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)  += ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
+obj-$(CONFIG_VIDEO_IMX274) += imx274.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c
new file mode 100644
index ..66cbfa81c030
--- /dev/null
+++ b/drivers/media/i2c/imx274.c
@@ -0,0 +1,1808 @@
+/*
+ * imx274.c - IMX274 CMOS Image Sensor driver
+ *
+ * Copyright (C) 2017, Leopard Imaging, Inc.
+ *
+ * Leon Luo 
+ * Edwin Zou 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * See "SHR, SVR Setting" in datasheet
+ */
+#define IMX274_DEFAULT_FRAME_LENGTH(4550)
+#define IMX274_MAX_FRAME_LENGTH(0x000f)
+
+/*
+ * See "Frame Rate Adjustment" in datasheet
+ */
+#define IMX274_PIXCLK_CONST1   (7200)
+#define IMX274_PIXCLK_CONST2   (100)
+
+/*
+ * The input gain is shifted by IMX274_GAIN_SHIFT to get
+ * decimal number. The real gain is
+ * (float)input_gain_value / (1 << IMX274_GAIN_SHIFT)
+ */
+#define IMX274_GAIN_SHIFT  (8)

[PATCH 3/9] [media] tm6000: Use common error handling code in tm6000_usb_probe()

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 16:00:47 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index ef37fb1f05e4..e18632056976 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1200,15 +1200,15 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
nr = find_first_zero_bit(_devused, TM6000_MAXBOARDS);
if (nr >= TM6000_MAXBOARDS) {
printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", 
TM6000_MAXBOARDS);
-   usb_put_dev(usbdev);
-   return -ENOMEM;
+   rc = -ENOMEM;
+   goto put_device;
}
 
/* Create and initialize dev struct */
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
-   usb_put_dev(usbdev);
-   return -ENOMEM;
+   rc = -ENOMEM;
+   goto put_device;
}
spin_lock_init(>slock);
mutex_init(>usb_lock);
@@ -1331,9 +1331,10 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
 
clear_bit(nr, _devused);
-   usb_put_dev(usbdev);
 
kfree(dev);
+put_device:
+   usb_put_dev(usbdev);
return rc;
 }
 
-- 
2.14.1



[PATCH 2/9] [media] tm6000: Adjust seven checks for null pointers

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 14:51:15 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c | 2 +-
 drivers/media/usb/tm6000/tm6000-dvb.c   | 6 +++---
 drivers/media/usb/tm6000/tm6000-input.c | 2 +-
 drivers/media/usb/tm6000/tm6000-video.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index 817bae8cb6a1..ef37fb1f05e4 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1206,7 +1206,7 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
 
/* Create and initialize dev struct */
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-   if (dev == NULL) {
+   if (!dev) {
usb_put_dev(usbdev);
return -ENOMEM;
}
diff --git a/drivers/media/usb/tm6000/tm6000-dvb.c 
b/drivers/media/usb/tm6000/tm6000-dvb.c
index 61a4e0a52716..2bc584f75f87 100644
--- a/drivers/media/usb/tm6000/tm6000-dvb.c
+++ b/drivers/media/usb/tm6000/tm6000-dvb.c
@@ -123,7 +123,7 @@ static int tm6000_start_stream(struct tm6000_core *dev)
}
 
dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
-   if (dvb->bulk_urb == NULL)
+   if (!dvb->bulk_urb)
return -ENOMEM;
 
pipe = usb_rcvbulkpipe(dev->udev, 
dev->bulk_in.endp->desc.bEndpointAddress
@@ -133,7 +133,7 @@ static int tm6000_start_stream(struct tm6000_core *dev)
size = size * 15; /* 512 x 8 or 12 or 15 */
 
dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
-   if (dvb->bulk_urb->transfer_buffer == NULL) {
+   if (!dvb->bulk_urb->transfer_buffer) {
usb_free_urb(dvb->bulk_urb);
return -ENOMEM;
}
@@ -360,7 +360,7 @@ static void unregister_dvb(struct tm6000_core *dev)
 {
struct tm6000_dvb *dvb = dev->dvb;
 
-   if (dvb->bulk_urb != NULL) {
+   if (dvb->bulk_urb) {
struct urb *bulk_urb = dvb->bulk_urb;
 
kfree(bulk_urb->transfer_buffer);
diff --git a/drivers/media/usb/tm6000/tm6000-input.c 
b/drivers/media/usb/tm6000/tm6000-input.c
index 91889ad9cdd7..397990afe00b 100644
--- a/drivers/media/usb/tm6000/tm6000-input.c
+++ b/drivers/media/usb/tm6000/tm6000-input.c
@@ -352,7 +352,7 @@ static int __tm6000_ir_int_start(struct rc_dev *rc)
dprintk(1, "IR max size: %d\n", size);
 
ir->int_urb->transfer_buffer = kzalloc(size, GFP_ATOMIC);
-   if (ir->int_urb->transfer_buffer == NULL) {
+   if (!ir->int_urb->transfer_buffer) {
usb_free_urb(ir->int_urb);
return err;
}
diff --git a/drivers/media/usb/tm6000/tm6000-video.c 
b/drivers/media/usb/tm6000/tm6000-video.c
index 701494e72edc..0d45f35e1697 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -470,7 +470,7 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
int num_bufs = TM6000_NUM_URB_BUF;
int i;
 
-   if (dev->urb_buffer != NULL)
+   if (dev->urb_buffer)
return 0;
 
dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
@@ -503,7 +503,7 @@ static int tm6000_free_urb_buffers(struct tm6000_core *dev)
 {
int i;
 
-   if (dev->urb_buffer == NULL)
+   if (!dev->urb_buffer)
return 0;
 
for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
-- 
2.14.1



[PATCH 1/9] [media] tm6000: Delete seven error messages for a failed memory allocation

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 14 Sep 2017 14:34:39 +0200

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/media/usb/tm6000/tm6000-cards.c |  1 -
 drivers/media/usb/tm6000/tm6000-dvb.c   |  5 +
 drivers/media/usb/tm6000/tm6000-video.c | 13 +++--
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-cards.c 
b/drivers/media/usb/tm6000/tm6000-cards.c
index 2537643a1808..817bae8cb6a1 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1210,4 +1210,3 @@ static int tm6000_usb_probe(struct usb_interface 
*interface,
-   printk(KERN_ERR "tm6000" ": out of memory!\n");
usb_put_dev(usbdev);
return -ENOMEM;
}
diff --git a/drivers/media/usb/tm6000/tm6000-dvb.c 
b/drivers/media/usb/tm6000/tm6000-dvb.c
index 097ac321b7e1..61a4e0a52716 100644
--- a/drivers/media/usb/tm6000/tm6000-dvb.c
+++ b/drivers/media/usb/tm6000/tm6000-dvb.c
@@ -137,5 +137,4 @@ static int tm6000_start_stream(struct tm6000_core *dev)
usb_free_urb(dvb->bulk_urb);
-   printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n");
return -ENOMEM;
}
 
@@ -403,7 +402,5 @@ static int dvb_init(struct tm6000_core *dev)
-   if (!dvb) {
-   printk(KERN_INFO "Cannot allocate memory\n");
+   if (!dvb)
return -ENOMEM;
-   }
 
dev->dvb = dvb;
 
diff --git a/drivers/media/usb/tm6000/tm6000-video.c 
b/drivers/media/usb/tm6000/tm6000-video.c
index ec8c4d2534dc..701494e72edc 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -477,13 +477,9 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core 
*dev)
-   if (!dev->urb_buffer) {
-   tm6000_err("cannot allocate memory for urb buffers\n");
+   if (!dev->urb_buffer)
return -ENOMEM;
-   }
 
dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
-   if (!dev->urb_dma) {
-   tm6000_err("cannot allocate memory for urb dma pointers\n");
+   if (!dev->urb_dma)
return -ENOMEM;
-   }
 
for (i = 0; i < num_bufs; i++) {
dev->urb_buffer[i] = usb_alloc_coherent(
@@ -601,12 +597,9 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
-   if (!dev->isoc_ctl.urb) {
-   tm6000_err("cannot alloc memory for usb buffers\n");
+   if (!dev->isoc_ctl.urb)
return -ENOMEM;
-   }
 
dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
   GFP_KERNEL);
if (!dev->isoc_ctl.transfer_buffer) {
-   tm6000_err("cannot allocate memory for usbtransfer\n");
kfree(dev->isoc_ctl.urb);
return -ENOMEM;
}
-- 
2.14.1



[PATCH 0/9] [media] TM6000: Adjustments for some function implementations

2017-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 15 Sep 2017 08:24:56 +0200

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (9):
  Delete seven error messages for a failed memory allocation
  Adjust seven checks for null pointers
  Use common error handling code in tm6000_usb_probe()
  One function call less in tm6000_usb_probe() after error detection
  Delete an unnecessary variable initialisation in tm6000_usb_probe()
  Use common error handling code in tm6000_cards_setup()
  Improve a size determination in dvb_init()
  Use common error handling code in tm6000_start_stream()
  Use common error handling code in tm6000_prepare_isoc()

 drivers/media/usb/tm6000/tm6000-cards.c | 36 -
 drivers/media/usb/tm6000/tm6000-dvb.c   | 24 +++---
 drivers/media/usb/tm6000/tm6000-input.c |  2 +-
 drivers/media/usb/tm6000/tm6000-video.c | 30 +++
 4 files changed, 42 insertions(+), 50 deletions(-)

-- 
2.14.1



Re: [PATCH v1] media: ov13858: Fix 4224x3136 video flickering at some vblanks

2017-09-15 Thread Tomasz Figa
Hi Chiranjeevi,

On Thu, Sep 14, 2017 at 7:38 AM, Chiranjeevi Rapolu
 wrote:
> Previously, the sensor was outputting blank every other frame at 4224x3136
> video when vblank was in the range [79, 86]. This resulted in video
> flickering.
>
> Omni Vision recommends us to use their settings for crop start/end for
> 4224x3136.

The change of register values itself doesn't give any information
about what is changed. Could you explain the following:
- What is the "crop" in this case?
- What value was it set to before and why was it wrong?
- What is the new value and why is it good?

Best regards,
Tomasz


[PATCH resend] [media] uvcvideo: zero seq number when disabling stream

2017-09-15 Thread Hans Yang
For bulk-based devices, when disabling the video stream,
in addition to issue CLEAR_FEATURE(HALT), it is better to set
alternate setting 0 as well or the sequnce number in host
side will probably not reset to zero.

Then in next time video stream start, the device will expect
host starts packet from 0 sequence number but host actually
continue the sequence number from last transaction and this
causes transaction errors.

This commit fixes this by adding set alternate setting 0 back
as what isoch-based devices do.

Below error message will also be eliminated for some devices:
uvcvideo: Non-zero status (-71) in video completion handler.

Signed-off-by: Hans Yang 
---
 drivers/media/usb/uvc/uvc_video.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c 
b/drivers/media/usb/uvc/uvc_video.c
index fb86d6af398d..ad80c2a6da6a 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1862,10 +1862,9 @@ int uvc_video_enable(struct uvc_streaming *stream, int 
enable)
 
if (!enable) {
uvc_uninit_video(stream, 1);
-   if (stream->intf->num_altsetting > 1) {
-   usb_set_interface(stream->dev->udev,
+   usb_set_interface(stream->dev->udev,
  stream->intfnum, 0);
-   } else {
+   if (stream->intf->num_altsetting == 1) {
/* UVC doesn't specify how to inform a bulk-based device
 * when the video stream is stopped. Windows sends a
 * CLEAR_FEATURE(HALT) request to the video streaming
-- 
2.1.4