Re: Problem with VMAP_STACK=y

2016-10-07 Thread Jiri Kosina
On Thu, 6 Oct 2016, Mauro Carvalho Chehab wrote:

> I can't see any other obvious error on the conversion. You could try to 
> enable debug options at DVB core/dvb-usb and/or add some printk's to the 
> driver and see what's happening.

Mauro, also please don't forget that there are many more places in 
drivers/media that still perform DMA on stack, and so have to be fixed for 
4.9 (as VMAP_STACK makes that to be immediately visible problem even on 
x86_64, which it wasn't the case before).

Thanks,

-- 
Jiri Kosina
SUSE Labs

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


Re: Problem with VMAP_STACK=y

2016-10-07 Thread Mauro Carvalho Chehab
Em Fri, 7 Oct 2016 09:52:56 +0200 (CEST)
Jiri Kosina  escreveu:

> On Thu, 6 Oct 2016, Mauro Carvalho Chehab wrote:
> 
> > I can't see any other obvious error on the conversion. You could try to 
> > enable debug options at DVB core/dvb-usb and/or add some printk's to the 
> > driver and see what's happening.
> 
> Mauro, also please don't forget that there are many more places in 
> drivers/media that still perform DMA on stack, and so have to be fixed for 
> 4.9 (as VMAP_STACK makes that to be immediately visible problem even on 
> x86_64, which it wasn't the case before).

Yes, I'm aware of that. I'm doing the conversion of drivers under dvb-usb,
at:

https://git.linuxtv.org/mchehab/experimental.git/log/?h=media_dmastack_fixes

I'll be sending the patches to the ML after ready.

I'll then take a look on other USB drivers that use the stack. I guess
the non-USB media drivers are safe from this issue.

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


Reply

2016-10-07 Thread Henry williams
Dear Friend,

I have a business proposal for you that will be of mutual benefit to
both of us. It’s about the death of my late client and some money he
left behind before his death. I want you to stand as his next of kin
since you bear the same surname with him, so that the bank can
release/transfer his money to you as his next of kin. Contact me for
more details contact us via our official email address
(henryw...@gmail.com)

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


Re: [PATCH v2] cinergyT2-core: don't do DMA on stack

2016-10-07 Thread Jörg Otte
2016-10-06 20:29 GMT+02:00 Mauro Carvalho Chehab :
> Em Thu, 6 Oct 2016 10:27:56 -0700
> Andy Lutomirski  escreveu:
>
>> On Wed, Oct 5, 2016 at 11:58 AM, Mauro Carvalho Chehab
>>  wrote:
>> > Sorry, forgot to C/C people that are at the "Re: Problem with VMAP_STACK=y"
>> > thread.
>> >
>> > Forwarded message:
>> >
>> > Date: Wed,  5 Oct 2016 15:54:18 -0300
>> > From: Mauro Carvalho Chehab 
>> > To: Linux Doc Mailing List 
>> > Cc: Mauro Carvalho Chehab , Mauro Carvalho 
>> > Chehab , Mauro Carvalho Chehab 
>> > Subject: [PATCH v2] cinergyT2-core: don't do DMA on stack
>> >
>> >
>> > The USB control messages require DMA to work. We cannot pass
>> > a stack-allocated buffer, as it is not warranted that the
>> > stack would be into a DMA enabled area.
>> >
>> > Signed-off-by: Mauro Carvalho Chehab 
>> > ---
>> >
>> > Added the fixups made by Johannes Stezenbach
>> >
>> >  drivers/media/usb/dvb-usb/cinergyT2-core.c | 45 
>> > ++
>> >  1 file changed, 27 insertions(+), 18 deletions(-)
>> >
>> > diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
>> > b/drivers/media/usb/dvb-usb/cinergyT2-core.c
>> > index 9fd1527494eb..8267e3777af6 100644
>> > --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
>> > +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
>> > @@ -41,6 +41,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
>> >
>> >  struct cinergyt2_state {
>> > u8 rc_counter;
>> > +   unsigned char data[64];
>> >  };
>> >
>> >  /* We are missing a release hook with usb_device data */
>> > @@ -50,29 +51,36 @@ static struct dvb_usb_device_properties 
>> > cinergyt2_properties;
>> >
>> >  static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int 
>> > enable)
>> >  {
>> > -   char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 
>> > 0 };
>> > -   char result[64];
>> > -   return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
>> > -   sizeof(result), 0);
>> > +   struct dvb_usb_device *d = adap->dev;
>> > +   struct cinergyt2_state *st = d->priv;
>> > +
>> > +   st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
>> > +   st->data[1] = enable ? 1 : 0;
>> > +
>> > +   return dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
>> >  }
>> >
>> >  static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
>> >  {
>>
>> This...
>>
>> > -   char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
>> > -   char state[3];
>> > -   return dvb_usb_generic_rw(d, buf, sizeof(buf), state, 
>> > sizeof(state), 0);
>> > +   struct cinergyt2_state *st = d->priv;
>> > +
>> > +   st->data[0] = CINERGYT2_EP1_SLEEP_MODE;
>>
>> ...does not match this:
>>
>> > +   st->data[1] = enable ? 1 : 0;
>>
>> --Andy
>
> Gah! Yes. This is what happens when coding using cut-and-paste ;)
>
> Jörg,
>
> Please test it with the condition reversed with the enclosed patch.
>
> if this doesn't work, you can enable dvb-usb debug at runtime,
> by loading it with debug parameter:
>
> parm:   debug:set debugging level 
> (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64,mem=128,uxfer=256  (or-able)). 
> (debugging is not enabled) (int)
>
> debug=2 should show the control messages sent to the device on dmesg.
>
> Regards,
> Mauro
>
>
> [PATCH] cinergyT2-core: don't do DMA on stack
>
> The USB control messages require DMA to work. We cannot pass
> a stack-allocated buffer, as it is not warranted that the
> stack would be into a DMA enabled area.
>
> Signed-off-by: Mauro Carvalho Chehab 
>
> diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
> b/drivers/media/usb/dvb-usb/cinergyT2-core.c
> index 9fd1527494eb..91640c927776 100644
> --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
> +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
> @@ -41,6 +41,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
>
>  struct cinergyt2_state {
> u8 rc_counter;
> +   unsigned char data[64];
>  };
>
>  /* We are missing a release hook with usb_device data */
> @@ -50,29 +51,36 @@ static struct dvb_usb_device_properties 
> cinergyt2_properties;
>
>  static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
>  {
> -   char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 
> };
> -   char result[64];
> -   return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
> -   sizeof(result), 0);
> +   struct dvb_usb_device *d = adap->dev;
> +   struct cinergyt2_state *st = d->priv;
> +
> +   st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
> +   st->data[1] = enable ? 1 : 0;
> +
> +   return dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
>  }
>
>  static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
>  {
> -   char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
> -   char state[3];
> -   return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 
> 0);
> +

Re: [PATCH v10 0/3] Secure Memory Allocation Framework

2016-10-07 Thread Benjamin Gaignard
Rob,

how do you know which devices are concerned when listing the constraints ?
Does combine_capabilities is done from each allocation or can it be cached ?

Regards,
Benjmain

2016-10-06 18:54 GMT+02:00 Rob Clark :
> so there is discussion about a "central userspace allocator" (ie. more
> like a common userspace API that could be implemented on top of
> various devices/APIs) to decide in a generic way which device could
> allocate.
>
>   https://github.com/cubanismo/allocator
>
> and I wrote up some rough thoughts/proposal about how the usage might
> look.. just rough, so don't try to compile it or anything, and not
> consensus yet so it will probably change/evolve..
>
>   https://github.com/robclark/allocator/blob/master/USAGE.md
>
> I think ion could be just another device to share buffers with, which
> happens to not impose any specific constraints.  How "liballoc-ion.so"
> backend figures out how to map constraints/usage to a heap is a bit
> hand-wavey at the moment.
>
> BR,
> -R
>
> On Wed, Oct 5, 2016 at 9:40 AM, Benjamin Gaignard
>  wrote:
>> because with ion it is up to userland to decide which heap to use
>> and until now userland doesn't have any way to get device constraints...
>>
>> I will prefer let a central allocator (in kernel) decide from the
>> attached devices
>> which allocator is the best. It is what I have implemented in smaf.
>>
>> Benjamin
>>
>>
>> 2016-10-05 15:19 GMT+02:00 Daniel Vetter :
>>> On Tue, Oct 04, 2016 at 01:47:21PM +0200, Benjamin Gaignard wrote:
 version 10 changes:
  - rebased on kernel 4.8 tag
  - minor typo fix

 version 9 changes:
  - rebased on 4.8-rc5
  - struct dma_attrs doesn't exist anymore so update CMA allocator
to compile with new dma_*_attr functions
  - add example SMAF use case in cover letter

 version 8 changes:
  - rework of the structures used within ioctl
by adding a version field and padding to be futur proof
  - rename fake secure moduel to test secure module
  - fix the various remarks done on the previous patcheset

 version 7 changes:
  - rebased on kernel 4.6-rc7
  - simplify secure module API
  - add vma ops to be able to detect mmap/munmap calls
  - add ioctl to get number and allocator names
  - update libsmaf with adding tests
https://git.linaro.org/people/benjamin.gaignard/libsmaf.git
  - add debug log in fake secure module

 version 6 changes:
  - rebased on kernel 4.5-rc4
  - fix mmapping bug while requested allocation size isn't a a multiple of
PAGE_SIZE (add a test for this in libsmaf)

 version 5 changes:
  - rebased on kernel 4.3-rc6
  - rework locking schema and make handle status use an atomic_t
  - add a fake secure module to allow performing tests without trusted
environment

 version 4 changes:
  - rebased on kernel 4.3-rc3
  - fix missing EXPORT_SYMBOL for smaf_create_handle()

 version 3 changes:
  - Remove ioctl for allocator selection instead provide the name of
the targeted allocator with allocation request.
Selecting allocator from userland isn't the prefered way of working
but is needed when the first user of the buffer is a software component.
  - Fix issues in case of error while creating smaf handle.
  - Fix module license.
  - Update libsmaf and tests to care of the SMAF API evolution
https://git.linaro.org/people/benjamin.gaignard/libsmaf.git

 version 2 changes:
  - Add one ioctl to allow allocator selection from userspace.
This is required for the uses case where the first user of
the buffer is a software IP which can't perform dma_buf attachement.
  - Add name and ranking to allocator structure to be able to sort them.
  - Create a tiny library to test SMAF:
https://git.linaro.org/people/benjamin.gaignard/libsmaf.git
  - Fix one issue when try to secure buffer without secure module registered

 SMAF aim to solve two problems: allocating memory that fit with hardware 
 IPs
 constraints and secure those data from bus point of view.

 One example of SMAF usage is camera preview: on SoC you may use either an 
 USB
 webcam or the built-in camera interface and the frames could be send 
 directly
 to the dipslay Ip or handle by GPU.
 Most of USB interfaces and GPU have mmu but almost all built-in camera
 interace and display Ips don't have mmu so when selecting how allocate
 buffer you need to be aware of each devices constraints (contiguous memroy,
 stride, boundary, alignment ...).
 ION has solve this problem by let userland decide which allocator (heap) 
 to use
 but this require to adapt userland for each platform and sometime for each
 use case.

 To be sure to select the best allocation method for devices SMAF implement
 deferred allocation mechanism: me

Re: [PATCH v10 0/3] Secure Memory Allocation Framework

2016-10-07 Thread Rob Clark
probably should keep the discussion on github (USAGE.md was updated a
bit more and merged into https://github.com/cubanismo/allocator so
look there for the latest)..

but briefly:

1) my expectation is if the user is implementing some use-case, it
knows what devices and APIs are involved, otherwise it wouldn't be
able to pass a buffer to that device/API..

2) if assertion/usage/devices haven't changed, you can re-use the
merged caps for however many buffer allocations

BR,
-R

On Fri, Oct 7, 2016 at 9:54 AM, Benjamin Gaignard
 wrote:
> Rob,
>
> how do you know which devices are concerned when listing the constraints ?
> Does combine_capabilities is done from each allocation or can it be cached ?
>
> Regards,
> Benjmain
>
> 2016-10-06 18:54 GMT+02:00 Rob Clark :
>> so there is discussion about a "central userspace allocator" (ie. more
>> like a common userspace API that could be implemented on top of
>> various devices/APIs) to decide in a generic way which device could
>> allocate.
>>
>>   https://github.com/cubanismo/allocator
>>
>> and I wrote up some rough thoughts/proposal about how the usage might
>> look.. just rough, so don't try to compile it or anything, and not
>> consensus yet so it will probably change/evolve..
>>
>>   https://github.com/robclark/allocator/blob/master/USAGE.md
>>
>> I think ion could be just another device to share buffers with, which
>> happens to not impose any specific constraints.  How "liballoc-ion.so"
>> backend figures out how to map constraints/usage to a heap is a bit
>> hand-wavey at the moment.
>>
>> BR,
>> -R
>>
>> On Wed, Oct 5, 2016 at 9:40 AM, Benjamin Gaignard
>>  wrote:
>>> because with ion it is up to userland to decide which heap to use
>>> and until now userland doesn't have any way to get device constraints...
>>>
>>> I will prefer let a central allocator (in kernel) decide from the
>>> attached devices
>>> which allocator is the best. It is what I have implemented in smaf.
>>>
>>> Benjamin
>>>
>>>
>>> 2016-10-05 15:19 GMT+02:00 Daniel Vetter :
 On Tue, Oct 04, 2016 at 01:47:21PM +0200, Benjamin Gaignard wrote:
> version 10 changes:
>  - rebased on kernel 4.8 tag
>  - minor typo fix
>
> version 9 changes:
>  - rebased on 4.8-rc5
>  - struct dma_attrs doesn't exist anymore so update CMA allocator
>to compile with new dma_*_attr functions
>  - add example SMAF use case in cover letter
>
> version 8 changes:
>  - rework of the structures used within ioctl
>by adding a version field and padding to be futur proof
>  - rename fake secure moduel to test secure module
>  - fix the various remarks done on the previous patcheset
>
> version 7 changes:
>  - rebased on kernel 4.6-rc7
>  - simplify secure module API
>  - add vma ops to be able to detect mmap/munmap calls
>  - add ioctl to get number and allocator names
>  - update libsmaf with adding tests
>https://git.linaro.org/people/benjamin.gaignard/libsmaf.git
>  - add debug log in fake secure module
>
> version 6 changes:
>  - rebased on kernel 4.5-rc4
>  - fix mmapping bug while requested allocation size isn't a a multiple of
>PAGE_SIZE (add a test for this in libsmaf)
>
> version 5 changes:
>  - rebased on kernel 4.3-rc6
>  - rework locking schema and make handle status use an atomic_t
>  - add a fake secure module to allow performing tests without trusted
>environment
>
> version 4 changes:
>  - rebased on kernel 4.3-rc3
>  - fix missing EXPORT_SYMBOL for smaf_create_handle()
>
> version 3 changes:
>  - Remove ioctl for allocator selection instead provide the name of
>the targeted allocator with allocation request.
>Selecting allocator from userland isn't the prefered way of working
>but is needed when the first user of the buffer is a software 
> component.
>  - Fix issues in case of error while creating smaf handle.
>  - Fix module license.
>  - Update libsmaf and tests to care of the SMAF API evolution
>https://git.linaro.org/people/benjamin.gaignard/libsmaf.git
>
> version 2 changes:
>  - Add one ioctl to allow allocator selection from userspace.
>This is required for the uses case where the first user of
>the buffer is a software IP which can't perform dma_buf attachement.
>  - Add name and ranking to allocator structure to be able to sort them.
>  - Create a tiny library to test SMAF:
>https://git.linaro.org/people/benjamin.gaignard/libsmaf.git
>  - Fix one issue when try to secure buffer without secure module 
> registered
>
> SMAF aim to solve two problems: allocating memory that fit with hardware 
> IPs
> constraints and secure those data from bus point of view.
>
> One example of SMAF usage is camera preview: on SoC you may use either an 
> USB
> webcam or the built-in camera interf

[PATCH 00/22] Basic i.MX IPUv3 capture support

2016-10-07 Thread Philipp Zabel
Hi,

this series adds very basic IPUv3 capture support for i.MX5/6 SoCs via a SoC
global media controller device that collects all IPUv3 CSIs and their direct
sources from the device tree via of_graph bindings. The device is probed from
device tree using a capture-subsystem node similarly to the already existing
display-subsystem node for imx-drm.
Each subdevice is then allowed to add further still missing subdevices to the
asynchronous subdevice notifier waitlist until the graph is complete.

Each CSI subdevice gets assigned an ipu-capture video_device that corresponds
to one direct CSI -> SMFC -> IDMAC channel path.
This series does not contain IC support yet. I'd like to add the IC as another
subdevice with one sink pad (PRP) that can be connected to either CSI, and two
source pads (PRP VF and PRP ENC) that each would get their own video_device.

Also included are drivers for the video bus multiplexers in front of the CSIs
and for the DesignWare MIPI CSI-2 Host Controller and an example device tree
configuration for TC358743 on Nitrogen6X.
This is the output of media-ctl --print-dot:

digraph board {
rankdir=TB
n0001 [label="{{ 0} | IPU0 CSI0\n/dev/v4l-subdev0 | { 
1}}", shape=Mrecord, style=filled, fillcolor=green]
n0001:port1 -> n0004
n0004 [label="imx-ipuv3-capture.0\n/dev/video0", shape=box, 
style=filled, fillcolor=yellow]
n000a [label="{{ 0} | IPU0 CSI1\n/dev/v4l-subdev1 | { 
1}}", shape=Mrecord, style=filled, fillcolor=green]
n000a:port1 -> n000d
n000d [label="imx-ipuv3-capture.1\n/dev/video1", shape=box, 
style=filled, fillcolor=yellow]
n0013 [label="{{ 0} | IPU1 CSI0\n/dev/v4l-subdev2 | { 
1}}", shape=Mrecord, style=filled, fillcolor=green]
n0013:port1 -> n0016
n0016 [label="imx-ipuv3-capture.0\n/dev/video2", shape=box, 
style=filled, fillcolor=yellow]
n001c [label="{{ 0} | IPU1 CSI1\n/dev/v4l-subdev3 | { 
1}}", shape=Mrecord, style=filled, fillcolor=green]
n001c:port1 -> n001f
n001f [label="imx-ipuv3-capture.1\n/dev/video3", shape=box, 
style=filled, fillcolor=yellow]
n0025 [label="{{ 0 |  1} | 
mipi_ipu1_mux\n/dev/v4l-subdev4 | { 2}}", shape=Mrecord, style=filled, 
fillcolor=green]
n0025:port2 -> n0001:port0
n0029 [label="{{ 0 |  1} | 
mipi_ipu2_mux\n/dev/v4l-subdev5 | { 2}}", shape=Mrecord, style=filled, 
fillcolor=green]
n0029:port2 -> n001c:port0 [style=dashed]
n002d [label="{{ 0} | mipi-csi2\n/dev/v4l-subdev6 | { 
1 |  2 |  3 |  4}}", shape=Mrecord, style=filled, 
fillcolor=green]
n002d:port1 -> n0025:port0
n002d:port4 -> n0029:port0 [style=dashed]
n002d:port3 -> n0013:port0 [style=dashed]
n002d:port2 -> n000a:port0 [style=dashed]
n0033 [label="{{} | tc358743 1-000f\n/dev/v4l-subdev7 | { 
0}}", shape=Mrecord, style=filled, fillcolor=green]
n0033:port0 -> n002d:port0
}

regards
Philipp

Philipp Zabel (21):
  [media] v4l2-async: move code out of v4l2_async_notifier_register into
v4l2_async_test_nofity_all
  [media] v4l2-async: allow subdevices to add further subdevices to the
notifier waiting list
  [media] v4l: of: add v4l2_of_subdev_registered
  [media] v4l2-subdev.h: add prepare_stream op
  [media] v4l2-async: add new subdevices to the tail of subdev_list
  [media] imx: Add i.MX SoC wide media device driver
  [media] imx-ipu: Add i.MX IPUv3 CSI subdevice driver
  [media] imx: Add i.MX IPUv3 capture driver
  [media] platform: add video-multiplexer subdevice driver
  [media] imx: Add i.MX MIPI CSI-2 subdevice driver
  [media] tc358743: put lanes in STOP state before starting streaming
  ARM: dts: imx6qdl: Add capture-subsystem node
  ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their
connections
  ARM: dts: imx6qdl: Add MIPI CSI-2 D-PHY compatible and clocks
  ARM: dts: nitrogen6x: Add dtsi for BD_HDMI_MIPI HDMI to MIPI CSI-2
receiver board
  gpu: ipuv3: add ipu_csi_set_downsize
  [media] imx-ipuv3-csi: support downsizing
  [media] add mux and video interface bridge entity functions
  [media] video-multiplexer: set entity function to mux
  [media] imx: Set i.MX MIPI CSI-2 entity function to bridge
  [media] tc358743: set entity function to video interface bridge

Sascha Hauer (1):
  [media] imx: Add IPUv3 media common code

 .../devicetree/bindings/media/fsl-imx-capture.txt  |   92 ++
 .../bindings/media/video-multiplexer.txt   |   59 ++
 Documentation/media/uapi/mediactl/media-types.rst  |   22 +
 arch/arm/boot/dts/imx6dl.dtsi  |  187 
 arch/arm/boot/dts/imx6q.dtsi   |  123 +++
 .../boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi  |   73 ++
 arch/arm/boot/dts/imx6qdl.dtsi |   17 +-
 drivers/gpu/ipu-v3/ipu-csi.c   |   16 +
 drivers/media/i2c/tc35

[PATCH 02/22] [media] v4l2-async: allow subdevices to add further subdevices to the notifier waiting list

2016-10-07 Thread Philipp Zabel
Currently the v4l2_async_notifier needs to be given a list of matches
for all expected subdevices on creation. When chaining subdevices that
are asynchronously probed via device tree, the bridge device that sets
up the notifier does not know the complete list of subdevices, as it
can only parse its own device tree node to obtain information about
the nearest neighbor subdevices.
To support indirectly connected subdevices, we need to support amending
the existing notifier waiting list with newly found neighbor subdevices
with each registered subdevice.

This can be achieved by adding new v42l_async_subdev matches to the
notifier waiting list during the v4l2_subdev registered callback, which
is called under the list lock from either v4l2_async_register_subdev or
v4l2_async_notifier_register. For this purpose a new exported function
__v4l2_async_notifier_add_subdev is added.

Signed-off-by: Philipp Zabel 
---
 drivers/media/v4l2-core/v4l2-async.c | 78 ++--
 include/media/v4l2-async.h   | 12 ++
 2 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index c4f1930..404eeea 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -109,6 +109,7 @@ static int v4l2_async_test_notify(struct 
v4l2_async_notifier *notifier,
if (ret < 0)
return ret;
}
+
/* Move from the global subdevice list to notifier's done */
list_move(&sd->async_list, ¬ifier->done);
 
@@ -158,7 +159,7 @@ int v4l2_async_notifier_register(struct v4l2_device 
*v4l2_dev,
 struct v4l2_async_notifier *notifier)
 {
struct v4l2_async_subdev *asd;
-   int ret;
+   struct list_head *tail;
int i;
 
if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
@@ -191,17 +192,71 @@ int v4l2_async_notifier_register(struct v4l2_device 
*v4l2_dev,
/* Keep also completed notifiers on the list */
list_add(¬ifier->list, ¬ifier_list);
 
+   do {
+   int ret;
+
+   tail = notifier->waiting.prev;
+
+   ret = v4l2_async_test_notify_all(notifier);
+   if (ret < 0) {
+   mutex_unlock(&list_lock);
+   return ret;
+   }
+
+   /*
+* If entries were added to the notifier waiting list, check
+* again if the corresponding subdevices are already available.
+*/
+   } while (tail != notifier->waiting.prev);
+
mutex_unlock(&list_lock);
 
-   return ret;
+   return 0;
 }
 EXPORT_SYMBOL(v4l2_async_notifier_register);
 
+int __v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
+struct v4l2_async_subdev *asd)
+{
+   struct v4l2_async_subdev *tmp_asd;
+
+   lockdep_assert_held(&list_lock);
+
+   if (asd->match_type != V4L2_ASYNC_MATCH_OF)
+   return -EINVAL;
+
+   /*
+* First check if the same notifier is already on the waiting or done
+* lists. This can happen if a subdevice with multiple outputs is added
+* by all its downstream subdevices.
+*/
+   list_for_each_entry(tmp_asd, ¬ifier->waiting, list)
+   if (tmp_asd->match.of.node == asd->match.of.node)
+   return 0;
+   list_for_each_entry(tmp_asd, ¬ifier->done, list)
+   if (tmp_asd->match.of.node == asd->match.of.node)
+   return 0;
+
+   /*
+* Add the new async subdev to the notifier waiting list, so
+* v4l2_async_belongs may use it to compare against entries in
+* subdev_list.
+* In case the subdev matching asd has already been passed in the
+* subdev_list walk in v4l2_async_notifier_register, or if
+* we are called from v4l2_async_register_subdev, the subdev_list
+* will have to be walked again.
+*/
+   list_add_tail(&asd->list, ¬ifier->waiting);
+
+   return 0;
+}
+
 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);
+   unsigned int notif_n_subdev = 0;
+   unsigned int n_subdev;
+   struct list_head *list;
struct device **dev;
int i = 0;
 
@@ -218,6 +273,10 @@ void v4l2_async_notifier_unregister(struct 
v4l2_async_notifier *notifier)
 
list_del(¬ifier->list);
 
+   list_for_each(list, ¬ifier->done)
+   ++notif_n_subdev;
+   n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS);
+
list_for_each_entry_safe(sd, tmp, ¬ifier->done, async_list) {
struct device *d;
 
@@ -294,8 +353,19 @@ int v4l2_async_register_su

[PATCH 04/22] [media] v4l2-subdev.h: add prepare_stream op

2016-10-07 Thread Philipp Zabel
In some cases, for example MIPI CSI-2 input on i.MX6, the sending and
receiving subdevice need to be prepared in lock-step before the actual
streaming can start. In the i.MX6 MIPI CSI-2 case, the sender needs to
put its MIPI CSI-2 transmitter lanes into stop state, and the receiver
needs to configure its D-PHY and detect the stop state on all active
lanes. Only then the sender can be enabled to stream data and the
receiver can lock its PLL to the clock lane.

This patch adds a prepare_stream(sd) callback that can be issued to all
v4l2_subdevs before calling s_stream(sd, 1).

Signed-off-by: Philipp Zabel 
---
 include/media/v4l2-subdev.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index cf778c5..6502f43 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -395,6 +395,7 @@ struct v4l2_subdev_video_ops {
int (*g_tvnorms)(struct v4l2_subdev *sd, v4l2_std_id *std);
int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
+   int (*prepare_stream)(struct v4l2_subdev *sd);
int (*s_stream)(struct v4l2_subdev *sd, int enable);
int (*g_pixelaspect)(struct v4l2_subdev *sd, struct v4l2_fract *aspect);
int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
-- 
2.9.3

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


[PATCH 01/22] [media] v4l2-async: move code out of v4l2_async_notifier_register into v4l2_async_test_nofity_all

2016-10-07 Thread Philipp Zabel
This will be reused in the following patch to catch already registered,
newly added asynchronous subdevices from v4l2_async_register_subdev.

Signed-off-by: Philipp Zabel 
---
 drivers/media/v4l2-core/v4l2-async.c | 38 +---
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 5bada20..c4f1930 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -134,11 +134,31 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)
sd->dev = NULL;
 }
 
+static int v4l2_async_test_notify_all(struct v4l2_async_notifier *notifier)
+{
+   struct v4l2_subdev *sd, *tmp;
+
+   list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
+   struct v4l2_async_subdev *asd;
+   int ret;
+
+   asd = v4l2_async_belongs(notifier, sd);
+   if (!asd)
+   continue;
+
+   ret = v4l2_async_test_notify(notifier, sd, asd);
+   if (ret < 0)
+   return ret;
+   }
+
+   return 0;
+}
+
 int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
 struct v4l2_async_notifier *notifier)
 {
-   struct v4l2_subdev *sd, *tmp;
struct v4l2_async_subdev *asd;
+   int ret;
int i;
 
if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
@@ -171,23 +191,9 @@ int v4l2_async_notifier_register(struct v4l2_device 
*v4l2_dev,
/* Keep also completed notifiers on the list */
list_add(¬ifier->list, ¬ifier_list);
 
-   list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
-   int ret;
-
-   asd = v4l2_async_belongs(notifier, sd);
-   if (!asd)
-   continue;
-
-   ret = v4l2_async_test_notify(notifier, sd, asd);
-   if (ret < 0) {
-   mutex_unlock(&list_lock);
-   return ret;
-   }
-   }
-
mutex_unlock(&list_lock);
 
-   return 0;
+   return ret;
 }
 EXPORT_SYMBOL(v4l2_async_notifier_register);
 
-- 
2.9.3

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


[PATCH 15/22] ARM: dts: imx6qdl: Add MIPI CSI-2 D-PHY compatible and clocks

2016-10-07 Thread Philipp Zabel
>From the data sheets it is not quite clear what the clock inputs should
be named, but freescale code calls them "dphy_clk" (would that be per?)
and "pixel_clk" and connects them to the mipi_core_cfg and emi_podf
clocks, respectively.  The mipi_core_cfg control is called hsi_tx
currently, but it really gates a whole lot of other clocks, too.

Signed-off-by: Philipp Zabel 
---
 arch/arm/boot/dts/imx6qdl.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index cd325bd..2be6de4 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1123,9 +1123,16 @@
};
 
mipi_csi: mipi@021dc000 {
+   compatible = "fsl,imx6q-mipi-csi2", 
"dw-mipi-csi2";
reg = <0x021dc000 0x4000>;
+   clocks = <&clks IMX6QDL_CLK_HSI_TX>,/* 
mipi_core_cfg/ipg_clk_root */
+<&clks IMX6QDL_CLK_HSI_TX>,/* 
mipi_core_cfg/video_27m_clk_root */
+<&clks IMX6QDL_CLK_HSI_TX>,/* 
mipi_core_cfg/video_27m_clk_root */
+<&clks IMX6QDL_CLK_EIM_PODF>;  /* 
shoid be ipu1_ipu_hsp_clk_root on S/DL, axi_clk_root on D/Q */
+   clock-names = "pclk", "cfg", "ref", "pixel";
#address-cells = <1>;
#size-cells = <0>;
+   status = "disabled";
};
 
mipi_dsi: mipi@021e {
-- 
2.9.3

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


[PATCH 17/22] gpu: ipuv3: add ipu_csi_set_downsize

2016-10-07 Thread Philipp Zabel
Support downsizing to 1/2 width and/or height in the CSI.

Signed-off-by: Philipp Zabel 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 16 
 include/video/imx-ipu-v3.h   |  1 +
 2 files changed, 17 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 06631ac..77f172e 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -527,6 +527,22 @@ void ipu_csi_set_window(struct ipu_csi *csi, struct 
v4l2_rect *w)
 }
 EXPORT_SYMBOL_GPL(ipu_csi_set_window);
 
+void ipu_csi_set_downsize(struct ipu_csi *csi, bool horiz, bool vert)
+{
+   unsigned long flags;
+   u32 reg;
+
+   spin_lock_irqsave(&csi->lock, flags);
+
+   reg = ipu_csi_read(csi, CSI_OUT_FRM_CTRL);
+   reg &= ~(CSI_HORI_DOWNSIZE_EN | CSI_VERT_DOWNSIZE_EN);
+   reg |= (horiz ? CSI_HORI_DOWNSIZE_EN : 0) |
+  (vert ? CSI_VERT_DOWNSIZE_EN : 0);
+   ipu_csi_write(csi, reg, CSI_OUT_FRM_CTRL);
+
+   spin_unlock_irqrestore(&csi->lock, flags);
+}
+
 void ipu_csi_set_test_generator(struct ipu_csi *csi, bool active,
u32 r_value, u32 g_value, u32 b_value,
u32 pix_clk)
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 7adeaae0..5f2f26d 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -271,6 +271,7 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 bool ipu_csi_is_interlaced(struct ipu_csi *csi);
 void ipu_csi_get_window(struct ipu_csi *csi, struct v4l2_rect *w);
 void ipu_csi_set_window(struct ipu_csi *csi, struct v4l2_rect *w);
+void ipu_csi_set_downsize(struct ipu_csi *csi, bool horiz, bool vert);
 void ipu_csi_set_test_generator(struct ipu_csi *csi, bool active,
u32 r_value, u32 g_value, u32 b_value,
u32 pix_clk);
-- 
2.9.3

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


[PATCH 10/22] [media] platform: add video-multiplexer subdevice driver

2016-10-07 Thread Philipp Zabel
This driver can handle SoC internal and external video bus multiplexers,
controlled either by register bit fields or by a GPIO. The subdevice
passes through frame interval and mbus configuration of the active input
to the output side.

Signed-off-by: Sascha Hauer 
Signed-off-by: Philipp Zabel 
---
 .../bindings/media/video-multiplexer.txt   |  59 +++
 drivers/media/platform/Kconfig |   8 +
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/video-multiplexer.c | 444 +
 4 files changed, 513 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/video-multiplexer.txt
 create mode 100644 drivers/media/platform/video-multiplexer.c

diff --git a/Documentation/devicetree/bindings/media/video-multiplexer.txt 
b/Documentation/devicetree/bindings/media/video-multiplexer.txt
new file mode 100644
index 000..9d133d9
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/video-multiplexer.txt
@@ -0,0 +1,59 @@
+Video Multiplexer
+=
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.
+
+Example:
+
+syscon {
+   compatible = "syscon", "simple-mfd";
+
+   mux {
+   compatible = "video-multiplexer";
+   /* Single bit (1 << 19) in syscon register 0x04: */
+   reg = <0x04>;
+   bit-mask = <1>;
+   bit-shift = <19>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   mux_in0: endpoint {
+   remote-endpoint = <&video_source0_out>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   mux_in1: endpoint {
+   remote-endpoint = <&video_source1_out>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   mux_out: endpoint {
+   remote-endpoint = <&capture_interface_in>;
+   };
+   };
+   };
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 105bf57..92680f6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -76,6 +76,14 @@ config VIDEO_M32R_AR_M64278
  To compile this driver as a module, choose M here: the
  module will be called arv.
 
+config VIDEO_MULTIPLEXER
+   tristate "Video Multiplexer"
+   depends on VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
+   help
+ This driver provides support for SoC internal N:1 video bus
+ multiplexers controlled by register bitfields as well as external
+ 2:1 video multiplexers controlled by a single GPIO.
+
 config VIDEO_OMAP3
tristate "OMAP 3 Camera support"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index f7f9008..a251755a 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,8 @@ obj-$(CONFIG_VIDEO_SH_VEU)+= sh_veu.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)+= m2m-deinterlace.o
 
+obj-$(CONFIG_VIDEO_MULTIPLEXER)+= video-multiplexer.o
+
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
diff --git a/drivers/media/platform/video-multiplexer.c 
b/drivers/media/platform/video-multiplexer.c
new file mode 100644
index 000..e9137ba
--- /dev/null
+++ b/drivers/media/platform/video-multiplexer.c
@@ -0,0 +1,444 @@
+/*
+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer 
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Softwa

[PATCH 09/22] [media] imx: Add i.MX IPUv3 capture driver

2016-10-07 Thread Philipp Zabel
This driver uses the IDMAC module's double buffering feature to do the
processing of finished frames in the new frame acknowledge (NFACK)
interrupt handler while the next frame is already being captured. This
avoids a race condition between the end of frame interrupt and NFACK for
very short blanking intervals, but causes the driver to need at least
two buffers in flight. The last remaining frame will never be handed out
to userspace until a new one is queued.
It supports interlaced input and allows to translate between sequential
and interlaced field formats using the IDMAC scan order and interlace
offset parameters.
Currently the direct CSI -> SMFC -> IDMAC path is supported.

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/imx/Kconfig   |9 +
 drivers/media/platform/imx/Makefile  |1 +
 drivers/media/platform/imx/imx-ipu-capture.c | 1085 ++
 drivers/media/platform/imx/imx-ipu.h |9 +
 drivers/media/platform/imx/imx-ipuv3-csi.c   |   25 +
 5 files changed, 1129 insertions(+)
 create mode 100644 drivers/media/platform/imx/imx-ipu-capture.c

diff --git a/drivers/media/platform/imx/Kconfig 
b/drivers/media/platform/imx/Kconfig
index a88c4f7..69e8648 100644
--- a/drivers/media/platform/imx/Kconfig
+++ b/drivers/media/platform/imx/Kconfig
@@ -9,6 +9,15 @@ config MEDIA_IMX
 config VIDEO_IMX_IPU_COMMON
tristate
 
+config VIDEO_IMX_IPU_CAPTURE
+   tristate "i.MX5/6 Video Capture driver"
+   depends on IMX_IPUV3_CORE && VIDEO_V4L2_SUBDEV_API && MEDIA_IMX
+   select VIDEOBUF2_DMA_CONTIG
+   select VIDEO_IMX_IPU_COMMON
+   select VIDEO_IMX_IPUV3
+   help
+ This is a v4l2 video capture driver for the IPUv3 on i.MX5/6.
+
 config VIDEO_IMX_IPU_CSI
tristate "i.MX5/6 CMOS Sensor Interface driver"
depends on VIDEO_DEV && IMX_IPUV3_CORE && MEDIA_IMX
diff --git a/drivers/media/platform/imx/Makefile 
b/drivers/media/platform/imx/Makefile
index 82a3616..919eaa1 100644
--- a/drivers/media/platform/imx/Makefile
+++ b/drivers/media/platform/imx/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_MEDIA_IMX)+= imx-media.o
 obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o
+obj-$(CONFIG_VIDEO_IMX_IPU_CAPTURE)+= imx-ipu-capture.o
 obj-$(CONFIG_VIDEO_IMX_IPU_CSI)+= imx-ipuv3-csi.o
diff --git a/drivers/media/platform/imx/imx-ipu-capture.c 
b/drivers/media/platform/imx/imx-ipu-capture.c
new file mode 100644
index 000..7d760b0
--- /dev/null
+++ b/drivers/media/platform/imx/imx-ipu-capture.c
@@ -0,0 +1,1085 @@
+/*
+ * i.MX IPUv3 V4L2 Capture Driver
+ *
+ * Copyright (C) 2016, Pengutronix, Philipp Zabel 
+ *
+ * Based on code
+ * Copyright (C) 2006, Pengutronix, Sascha Hauer 
+ * Copyright (C) 2008, Guennadi Liakhovetski 
+ * Copyright (C) 2008, Paulius Zaleckas 
+ * Copyright (C) 2009, Darius Augulis 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "imx-ipu.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "imx-ipuv3-capture"
+
+/* buffer for one video frame */
+struct ipu_capture_buffer {
+   struct vb2_v4l2_buffer  vb;
+   struct list_headqueue;
+};
+
+struct ipu_capture {
+   struct video_device vdev;
+
+   struct device   *dev;
+   struct v4l2_fh  fh;
+   struct vb2_queuevb2_vidq;
+   struct media_padpad;
+   struct media_pipeline   pipe;
+   struct v4l2_format  format;
+
+   struct v4l2_subdev  *csi_sd;
+   struct ipu_smfc *smfc;
+   struct ipuv3_channel*ipuch;
+   struct ipu_soc  *ipu;
+   int id;
+
+   spinlock_t  lock;
+   struct mutexmutex;
+
+   /* The currently active buffer, set by NFACK and cleared by EOF 
interrupt */
+   struct ipu_capture_buffer   *active;
+   struct list_headcapture;
+   int ilo;
+   int sequence;
+
+   int done_count;
+   int skip_count;
+};
+
+
+static struct ipu_capture_buffer *to_ipu_capture_buffer(struct vb2_buffer *vb)
+{
+   return container_of(vb, struct ipu_capture_buffer, vb.vb2_buf);
+}
+
+static inline void ipu_capture_set_inactive_buffer(struct ipu_capture *priv,
+  struct vb2_buffer *vb)
+{
+   

[PATCH 13/22] ARM: dts: imx6qdl: Add capture-subsystem node

2016-10-07 Thread Philipp Zabel
Signed-off-by: Philipp Zabel 
---
 arch/arm/boot/dts/imx6dl.dtsi | 5 +
 arch/arm/boot/dts/imx6q.dtsi  | 5 +
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 9a4c22c..3c817de 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -100,6 +100,11 @@
};
};
 
+   capture-subsystem {
+   compatible = "fsl,imx-capture-subsystem";
+   ports = <&ipu1_csi0>, <&ipu1_csi1>;
+   };
+
display-subsystem {
compatible = "fsl,imx-display-subsystem";
ports = <&ipu1_di0>, <&ipu1_di1>;
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index c30c836..0c87a69 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -198,6 +198,11 @@
};
};
 
+   capture-subsystem {
+   compatible = "fsl,imx-capture-subsystem";
+   ports = <&ipu1_csi0>, <&ipu1_csi1>, <&ipu2_csi0>, <&ipu2_csi1>;
+   };
+
display-subsystem {
compatible = "fsl,imx-display-subsystem";
ports = <&ipu1_di0>, <&ipu1_di1>, <&ipu2_di0>, <&ipu2_di1>;
-- 
2.9.3

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


[PATCH 19/22] [media] add mux and video interface bridge entity functions

2016-10-07 Thread Philipp Zabel
Signed-off-by: Philipp Zabel 
---
 Documentation/media/uapi/mediactl/media-types.rst | 22 ++
 include/uapi/linux/media.h|  6 ++
 2 files changed, 28 insertions(+)

diff --git a/Documentation/media/uapi/mediactl/media-types.rst 
b/Documentation/media/uapi/mediactl/media-types.rst
index 3e03dc2..023be29 100644
--- a/Documentation/media/uapi/mediactl/media-types.rst
+++ b/Documentation/media/uapi/mediactl/media-types.rst
@@ -298,6 +298,28 @@ Types and flags used to represent the media graph elements
  received on its sink pad and outputs the statistics data on
  its source pad.
 
+-  ..  row 29
+
+   ..  _MEDIA-ENT-F-MUX:
+
+   -  ``MEDIA_ENT_F_MUX``
+
+   - Video multiplexer. An entity capable of multiplexing must have at
+ least two sink pads and one source pad, and must pass the video
+ frame(s) received from the active sink pad to the source pad. Video
+ frame(s) from the inactive sink pads are discarded.
+
+-  ..  row 30
+
+   ..  _MEDIA-ENT-F-VID-IF-BRIDGE:
+
+   -  ``MEDIA_ENT_F_VID_IF_BRIDGE``
+
+   - Video interface bridge. A video interface bridge entity must have at
+ least one sink pad and one source pad. It receives video frame(s) on
+ its sink pad in one bus format (HDMI, eDP, MIPI CSI-2, ...) and
+ converts them and outputs them on its source pad in another bus format
+ (eDP, MIPI CSI-2, parallel, ...).
 
 ..  tabularcolumns:: |p{5.5cm}|p{12.0cm}|
 
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 4890787..08a8bfa 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -105,6 +105,12 @@ struct media_device_info {
 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS  (MEDIA_ENT_F_BASE + 0x4006)
 
 /*
+ * Switch and bridge entitites
+ */
+#define MEDIA_ENT_F_MUX(MEDIA_ENT_F_BASE + 
0x5001)
+#define MEDIA_ENT_F_VID_IF_BRIDGE  (MEDIA_ENT_F_BASE + 0x5002)
+
+/*
  * Connectors
  */
 /* It is a responsibility of the entity drivers to add connectors and links */
-- 
2.9.3

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


[PATCH 21/22] [media] imx: Set i.MX MIPI CSI-2 entity function to bridge

2016-10-07 Thread Philipp Zabel
The i.MX6 MIPI CSI2 bridge converts the external MIPI CSI2 input into
a SoC internal parallel bus connected to the IPU CSIs via the CSI2IPU
gasket.

Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/imx/imx-mipi-csi2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/imx/imx-mipi-csi2.c 
b/drivers/media/platform/imx/imx-mipi-csi2.c
index 0613187..85d2ef7 100644
--- a/drivers/media/platform/imx/imx-mipi-csi2.c
+++ b/drivers/media/platform/imx/imx-mipi-csi2.c
@@ -585,6 +585,7 @@ static int mipi_csi2_probe(struct platform_device *pdev)
csi2->pads[2].flags = MEDIA_PAD_FL_SOURCE;
csi2->pads[3].flags = MEDIA_PAD_FL_SOURCE;
csi2->pads[4].flags = MEDIA_PAD_FL_SOURCE;
+   csi2->subdev.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
ret = media_entity_pads_init(&csi2->subdev.entity, MIPI_CSI2_PADS,
csi2->pads);
if (ret < 0)
-- 
2.9.3

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


[PATCH 07/22] [media] imx: Add IPUv3 media common code

2016-10-07 Thread Philipp Zabel
From: Sascha Hauer 

Add video4linux API routines common to drivers for units that
accept or provide video data via the i.MX IPU IDMAC channels,
such as capture, mem2mem scaler or deinterlacer drivers.

Signed-off-by: Sascha Hauer 
Signed-off-by: Lucas Stach 
Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/imx/Kconfig   |   3 +
 drivers/media/platform/imx/Makefile  |   1 +
 drivers/media/platform/imx/imx-ipu.c | 321 +++
 drivers/media/platform/imx/imx-ipu.h |  34 
 4 files changed, 359 insertions(+)
 create mode 100644 drivers/media/platform/imx/imx-ipu.c
 create mode 100644 drivers/media/platform/imx/imx-ipu.h

diff --git a/drivers/media/platform/imx/Kconfig 
b/drivers/media/platform/imx/Kconfig
index 3bd699c..1662bb0b 100644
--- a/drivers/media/platform/imx/Kconfig
+++ b/drivers/media/platform/imx/Kconfig
@@ -5,3 +5,6 @@ config MEDIA_IMX
---help---
  This driver provides a SoC wide media controller device that all
  multimedia components in i.MX5 and i.MX6 SoCs can register with.
+
+config VIDEO_IMX_IPU_COMMON
+   tristate
diff --git a/drivers/media/platform/imx/Makefile 
b/drivers/media/platform/imx/Makefile
index 74bed76..0ba601a 100644
--- a/drivers/media/platform/imx/Makefile
+++ b/drivers/media/platform/imx/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_MEDIA_IMX)+= imx-media.o
+obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o
diff --git a/drivers/media/platform/imx/imx-ipu.c 
b/drivers/media/platform/imx/imx-ipu.c
new file mode 100644
index 000..da1deb0
--- /dev/null
+++ b/drivers/media/platform/imx/imx-ipu.c
@@ -0,0 +1,321 @@
+/*
+ * i.MX IPUv3 common v4l2 support
+ *
+ * Copyright (C) 2011 Pengutronix, Sascha Hauer 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "imx-ipu.h"
+
+/*
+ * These formats are in order of preference: interleaved YUV first,
+ * because those are the most bandwidth efficient, followed by
+ * chroma-interleaved formats, and planar formats last.
+ * In each category, YUV 4:2:0 may be preferrable to 4:2:2 for bandwidth
+ * reasons, if the IDMAC channel supports double read/write reduction
+ * (all write channels, VDIC read channels).
+ */
+static struct ipu_fmt ipu_fmt_yuv[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_YUYV,
+   .bytes_per_pixel = 2,
+   }, {
+   .fourcc = V4L2_PIX_FMT_UYVY,
+   .bytes_per_pixel = 2,
+   }, {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .bytes_per_pixel = 1,
+   }, {
+   .fourcc = V4L2_PIX_FMT_NV16,
+   .bytes_per_pixel = 1,
+   }, {
+   .fourcc = V4L2_PIX_FMT_YUV420,
+   .bytes_per_pixel = 1,
+   }, {
+   .fourcc = V4L2_PIX_FMT_YVU420,
+   .bytes_per_pixel = 1,
+   }, {
+   .fourcc = V4L2_PIX_FMT_YUV422P,
+   .bytes_per_pixel = 1,
+   },
+};
+
+static struct ipu_fmt ipu_fmt_rgb[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_RGB32,
+   .bytes_per_pixel = 4,
+   }, {
+   .fourcc = V4L2_PIX_FMT_RGB24,
+   .bytes_per_pixel = 3,
+   }, {
+   .fourcc = V4L2_PIX_FMT_BGR24,
+   .bytes_per_pixel = 3,
+   }, {
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .bytes_per_pixel = 2,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_BGR32,
+   .bytes_per_pixel = 4,
+   },
+};
+
+struct ipu_fmt *ipu_find_fmt_yuv(unsigned int pixelformat)
+{
+   struct ipu_fmt *fmt;
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(ipu_fmt_yuv); i++) {
+   fmt = &ipu_fmt_yuv[i];
+   if (fmt->fourcc == pixelformat)
+   return fmt;
+   }
+
+   return NULL;
+}
+EXPORT_SYMBOL_GPL(ipu_find_fmt_yuv);
+
+struct ipu_fmt *ipu_find_fmt_rgb(unsigned int pixelformat)
+{
+   struct ipu_fmt *fmt;
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(ipu_fmt_rgb); i++) {
+   fmt = &ipu_fmt_rgb[i];
+   if (fmt->fourcc == pixelformat)
+   return fmt;
+   }
+
+   return NULL;
+}
+EXPORT_SYMBOL_GPL(ipu_find_fmt_rgb);
+
+static struct ipu_fmt *ipu_find_fmt(unsigned long pixelformat)
+{
+   struct ipu_fmt *fmt;
+
+   fmt = ipu_find_fmt_yuv(pixelformat);
+   if (fmt)
+   return fmt;
+   fmt = ipu_find_fmt_rgb(pixelformat);
+
+   return fmt;
+}
+EXPOR

[PATCH 05/22] [media] v4l2-async: add new subdevices to the tail of subdev_list

2016-10-07 Thread Philipp Zabel
That way the asynchronous notifier will pick them up in the order they
were registered.

Signed-off-by: Philipp Zabel 
---
 drivers/media/v4l2-core/v4l2-async.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 404eeea..1a62ed7 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -371,7 +371,7 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
}
 
/* None matched, wait for hot-plugging */
-   list_add(&sd->async_list, &subdev_list);
+   list_add_tail(&sd->async_list, &subdev_list);
 
mutex_unlock(&list_lock);
 
-- 
2.9.3

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


[PATCH 22/22] [media] tc358743: set entity function to video interface bridge

2016-10-07 Thread Philipp Zabel
The TC358743 is an HDMI to MIPI CSI2-2 bridge.

Signed-off-by: Philipp Zabel 
---
 drivers/media/i2c/tc358743.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index dfa45d2..c7a8f55 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1891,6 +1891,7 @@ static int tc358743_probe(struct i2c_client *client,
}
 
state->pad.flags = MEDIA_PAD_FL_SOURCE;
+   sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
err = media_entity_pads_init(&sd->entity, 1, &state->pad);
if (err < 0)
goto err_hdl;
-- 
2.9.3

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


[PATCH 20/22] [media] video-multiplexer: set entity function to mux

2016-10-07 Thread Philipp Zabel
Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/video-multiplexer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/video-multiplexer.c 
b/drivers/media/platform/video-multiplexer.c
index e9137ba..bcd1688 100644
--- a/drivers/media/platform/video-multiplexer.c
+++ b/drivers/media/platform/video-multiplexer.c
@@ -138,6 +138,7 @@ static int vidsw_async_init(struct vidsw *vidsw, struct 
device_node *node)
vidsw->pads[i].flags = MEDIA_PAD_FL_SINK;
vidsw->pads[numports - 1].flags = MEDIA_PAD_FL_SOURCE;
 
+   vidsw->subdev.entity.function = MEDIA_ENT_F_MUX;
ret = media_entity_pads_init(&vidsw->subdev.entity, numports,
 vidsw->pads);
if (ret < 0)
-- 
2.9.3

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


[PATCH 03/22] [media] v4l: of: add v4l2_of_subdev_registered

2016-10-07 Thread Philipp Zabel
Provide a default registered callback for device tree probed subdevices
that use OF graph bindings to add still missing source subdevices to
the async notifier waiting list.
This is only necessary for subdevices that have input ports to which
other subdevices are connected that are not initially known to the
master/bridge device when it sets up the notifier.

Signed-off-by: Philipp Zabel 
---
 drivers/media/v4l2-core/v4l2-of.c | 68 +++
 include/media/v4l2-of.h   | 12 +++
 2 files changed, 80 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-of.c 
b/drivers/media/v4l2-core/v4l2-of.c
index 93b3368..fbdd6b4 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -19,6 +19,7 @@
 #include 
 
 #include 
+#include 
 
 static int v4l2_of_parse_csi_bus(const struct device_node *node,
 struct v4l2_of_endpoint *endpoint)
@@ -314,3 +315,70 @@ void v4l2_of_put_link(struct v4l2_of_link *link)
of_node_put(link->remote_node);
 }
 EXPORT_SYMBOL(v4l2_of_put_link);
+
+struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
+struct device_node *node)
+{
+   struct v4l2_subdev *sd;
+
+   list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+   if (sd->of_node == node)
+   return sd;
+   }
+
+   return NULL;
+}
+EXPORT_SYMBOL(v4l2_find_subdev_by_node);
+
+/**
+ * v4l2_of_subdev_registered() - default OF probed subdev registered callback
+ * @subdev: subdevice with initialized entities
+ *
+ * Parse all OF graph endpoints corrensponding to the subdev's entity input 
pads
+ * and add the remote subdevs to the async subdev notifier.
+ */
+int v4l2_of_subdev_registered(struct v4l2_subdev *sd)
+{
+   struct device_node *ep;
+
+   for_each_endpoint_of_node(sd->of_node, ep) {
+   struct v4l2_of_link link;
+   struct media_entity *entity;
+   unsigned int pad;
+   int ret;
+
+   ret = v4l2_of_parse_link(ep, &link);
+   if (ret)
+   continue;
+
+   /*
+* Assume 1:1 correspondence between OF node and entity,
+* and between OF port numbers and pad indices.
+*/
+   entity = &sd->entity;
+   pad = link.local_port;
+
+   if (pad >= entity->num_pads)
+   return -EINVAL;
+
+   /* Add source subdevs to async notifier */
+   if (entity->pads[pad].flags & MEDIA_PAD_FL_SINK) {
+   struct v4l2_async_subdev *asd;
+
+   asd = devm_kzalloc(sd->dev, sizeof(*asd), GFP_KERNEL);
+   if (!asd) {
+   v4l2_of_put_link(&link);
+   return -ENOMEM;
+   }
+
+   asd->match_type = V4L2_ASYNC_MATCH_OF;
+   asd->match.of.node = link.remote_node;
+
+   __v4l2_async_notifier_add_subdev(sd->notifier, asd);
+   }
+
+   v4l2_of_put_link(&link);
+   }
+
+   return 0;
+}
diff --git a/include/media/v4l2-of.h b/include/media/v4l2-of.h
index 4dc34b2..67d4f8b 100644
--- a/include/media/v4l2-of.h
+++ b/include/media/v4l2-of.h
@@ -22,6 +22,8 @@
 #include 
 
 struct device_node;
+struct v4l2_device;
+struct v4l2_subdev;
 
 /**
  * struct v4l2_of_bus_mipi_csi2 - MIPI CSI-2 bus data structure
@@ -95,6 +97,9 @@ void v4l2_of_free_endpoint(struct v4l2_of_endpoint *endpoint);
 int v4l2_of_parse_link(const struct device_node *node,
   struct v4l2_of_link *link);
 void v4l2_of_put_link(struct v4l2_of_link *link);
+int v4l2_of_subdev_registered(struct v4l2_subdev *sd);
+struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
+struct device_node *node);
 #else /* CONFIG_OF */
 
 static inline int v4l2_of_parse_endpoint(const struct device_node *node,
@@ -123,6 +128,13 @@ static inline void v4l2_of_put_link(struct v4l2_of_link 
*link)
 {
 }
 
+#define v4l2_of_subdev_registered NULL
+
+struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
+struct device_node *node)
+{
+   return NULL;
+}
 #endif /* CONFIG_OF */
 
 #endif /* _V4L2_OF_H */
-- 
2.9.3

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


[PATCH 06/22] [media] imx: Add i.MX SoC wide media device driver

2016-10-07 Thread Philipp Zabel
This driver registers a single, SoC wide media device, which all entities
in the media graph can be registered to. It is probed from device tree
using a capture-subsystem node, listing the IPUv3 input ports, similarly
to the already existing display-subsystem node that lists the IPUv3 output
ports.

Signed-off-by: Philipp Zabel 
---
 .../devicetree/bindings/media/fsl-imx-capture.txt  |  25 +++
 drivers/media/platform/Kconfig |   2 +
 drivers/media/platform/Makefile|   1 +
 drivers/media/platform/imx/Kconfig |   7 +
 drivers/media/platform/imx/Makefile|   1 +
 drivers/media/platform/imx/imx-media.c | 249 +
 6 files changed, 285 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/fsl-imx-capture.txt
 create mode 100644 drivers/media/platform/imx/Kconfig
 create mode 100644 drivers/media/platform/imx/Makefile
 create mode 100644 drivers/media/platform/imx/imx-media.c

diff --git a/Documentation/devicetree/bindings/media/fsl-imx-capture.txt 
b/Documentation/devicetree/bindings/media/fsl-imx-capture.txt
new file mode 100644
index 000..5805331
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/fsl-imx-capture.txt
@@ -0,0 +1,25 @@
+Freescale i.MX IPUv3 capture subsystem
+==
+
+The i.MX5/6 IPUv3 capture subsystem consists of one or two IPUs and all
+external subdevices connected to the IPU CSI input ports. On i.MX5 these
+are only external subdevices. On i.MX6, there are additional SoC internal
+multiplexers and a MIPI CSI-2 bridge connected to the CSI input ports via
+of_graph bindings.
+
+On i.MX6 variants with two IPUs, either a single capture subsystem node may be
+defined, containing all CSI ports, or two separate capture subsystem nodes may
+be defined, each containing the CSI ports of a single IPU. In the latter case
+there must be no external of_graph links between the two subsystems.
+
+Required properties:
+- compatible: should be "fsl,imx-capture-subsystem"
+- ports: should contain a list of phandles pointing to the capture interface
+  ports of IPU devices
+
+Example:
+
+capture-subsystem {
+compatible = "fsl,imx-capture-subsystem";
+ports = <&ipu1_csi0>, <&ipu1_csi1>, <&ipu2_csi0>, <&ipu2_csi1>;
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ce4a96f..105bf57 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -29,6 +29,8 @@ config VIDEO_VIA_CAMERA
 
 source "drivers/media/platform/davinci/Kconfig"
 
+source "drivers/media/platform/imx/Kconfig"
+
 source "drivers/media/platform/omap/Kconfig"
 
 source "drivers/media/platform/blackfin/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 40b18d1..f7f9008 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FCP)   += rcar-fcp.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-y  += imx/
 obj-y  += omap/
 
 obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
diff --git a/drivers/media/platform/imx/Kconfig 
b/drivers/media/platform/imx/Kconfig
new file mode 100644
index 000..3bd699c
--- /dev/null
+++ b/drivers/media/platform/imx/Kconfig
@@ -0,0 +1,7 @@
+config MEDIA_IMX
+   tristate "Multimedia Support for Freescale i.MX"
+   depends on MEDIA_CONTROLLER
+   default y if IMX_IPUV3_CORE
+   ---help---
+ This driver provides a SoC wide media controller device that all
+ multimedia components in i.MX5 and i.MX6 SoCs can register with.
diff --git a/drivers/media/platform/imx/Makefile 
b/drivers/media/platform/imx/Makefile
new file mode 100644
index 000..74bed76
--- /dev/null
+++ b/drivers/media/platform/imx/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MEDIA_IMX)+= imx-media.o
diff --git a/drivers/media/platform/imx/imx-media.c 
b/drivers/media/platform/imx/imx-media.c
new file mode 100644
index 000..1f1fab4
--- /dev/null
+++ b/drivers/media/platform/imx/imx-media.c
@@ -0,0 +1,249 @@
+/*
+ * i.MX V4L2 Capture Driver
+ *
+ * Copyright (C) 2016, Pengutronix, Philipp Zabel 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX_MEDIA_MAX_PORTS4
+
+struct imx_media {
+   struct media_device mdev;
+   struct v4l2_device v4l2_dev;
+   struct v4l2_async_notifier subdev_notifier;
+   struct v4l2_async_subdev subdevs[IMX_MEDIA_MAX_PORTS];
+};
+
+static int v4l2_of_create_pad_link(struct v4l2_subdev *sd,
+  struct v4l2_of_link *link)
+{

[PATCH 08/22] [media] imx-ipu: Add i.MX IPUv3 CSI subdevice driver

2016-10-07 Thread Philipp Zabel
This adds a V4L2 subdevice driver for the two CMOS Sensor Interface (CSI)
modules contained in each IPUv3. These sample video data from the
parallel CSI0/1 pads or from the the MIPI CSI-2 bridge via IOMUXC video
bus multiplexers and write to IPU internal FIFOs to deliver data to
either the IDMAC or IC modules.

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/imx/Kconfig |   7 +
 drivers/media/platform/imx/Makefile|   1 +
 drivers/media/platform/imx/imx-ipuv3-csi.c | 522 +
 3 files changed, 530 insertions(+)
 create mode 100644 drivers/media/platform/imx/imx-ipuv3-csi.c

diff --git a/drivers/media/platform/imx/Kconfig 
b/drivers/media/platform/imx/Kconfig
index 1662bb0b..a88c4f7 100644
--- a/drivers/media/platform/imx/Kconfig
+++ b/drivers/media/platform/imx/Kconfig
@@ -8,3 +8,10 @@ config MEDIA_IMX
 
 config VIDEO_IMX_IPU_COMMON
tristate
+
+config VIDEO_IMX_IPU_CSI
+   tristate "i.MX5/6 CMOS Sensor Interface driver"
+   depends on VIDEO_DEV && IMX_IPUV3_CORE && MEDIA_IMX
+   select VIDEO_IMX_IPUV3
+   ---help---
+ This is a v4l2 subdevice driver for two CSI modules in each IPUv3.
diff --git a/drivers/media/platform/imx/Makefile 
b/drivers/media/platform/imx/Makefile
index 0ba601a..82a3616 100644
--- a/drivers/media/platform/imx/Makefile
+++ b/drivers/media/platform/imx/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_MEDIA_IMX)+= imx-media.o
 obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o
+obj-$(CONFIG_VIDEO_IMX_IPU_CSI)+= imx-ipuv3-csi.o
diff --git a/drivers/media/platform/imx/imx-ipuv3-csi.c 
b/drivers/media/platform/imx/imx-ipuv3-csi.c
new file mode 100644
index 000..316175b
--- /dev/null
+++ b/drivers/media/platform/imx/imx-ipuv3-csi.c
@@ -0,0 +1,522 @@
+/*
+ * i.MX IPUv3 CSI V4L2 Subdevice Driver
+ *
+ * Copyright (C) 2016, Pengutronix, Philipp Zabel 
+ *
+ * Based on code
+ * Copyright (C) 2006, Sascha Hauer, Pengutronix
+ * Copyright (C) 2008, Guennadi Liakhovetski 
+ * Copyright (C) 2008, Paulius Zaleckas 
+ * Copyright (C) 2009, Darius Augulis 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "imx-ipu.h"
+
+#define DRIVER_NAME "imx-ipuv3-csi"
+
+struct ipucsi {
+   struct v4l2_subdev  subdev;
+
+   struct device   *dev;
+   u32 id;
+
+   struct ipu_csi  *csi;
+   struct ipu_soc  *ipu;
+   struct v4l2_of_endpoint endpoint;
+   enum ipu_csi_dest   csi_dest;
+
+   struct media_padsubdev_pad[2];
+   struct v4l2_mbus_framefmt   format_mbus[2];
+   struct v4l2_fract   timeperframe[2];
+};
+
+static int ipu_csi_get_mbus_config(struct ipucsi *ipucsi,
+  struct v4l2_mbus_config *config)
+{
+   struct v4l2_subdev *sd;
+   struct media_pad *pad;
+   int ret;
+
+   /*
+* Retrieve media bus configuration from the entity connected directly
+* to the CSI subdev sink pad.
+*/
+   pad = media_entity_remote_pad(&ipucsi->subdev_pad[0]);
+   if (!pad) {
+   dev_err(ipucsi->dev,
+   "failed to retrieve mbus config from source entity\n");
+   return -ENODEV;
+   }
+   sd = media_entity_to_v4l2_subdev(pad->entity);
+   ret = v4l2_subdev_call(sd, video, g_mbus_config, config);
+   if (ret == -ENOIOCTLCMD) {
+   /* Fall back to static mbus configuration from device tree */
+   config->type = ipucsi->endpoint.bus_type;
+   config->flags = ipucsi->endpoint.bus.parallel.flags;
+   ret = 0;
+   }
+
+   return ret;
+}
+
+static struct v4l2_mbus_framefmt *
+__ipucsi_get_pad_format(struct v4l2_subdev *sd,
+   struct v4l2_subdev_pad_config *cfg,
+   unsigned int pad, u32 which)
+{
+   struct ipucsi *ipucsi = container_of(sd, struct ipucsi, subdev);
+
+   switch (which) {
+   case V4L2_SUBDEV_FORMAT_TRY:
+   return v4l2_subdev_get_try_format(sd, cfg, pad);
+   case V4L2_SUBDEV_FORMAT_ACTIVE:
+   return &ipucsi->format_mbus[pad ? 1 : 0];
+   default:
+   return NULL;
+   }
+}
+
+static int ipucsi_subdev_log_status(struct v4l2_subdev *subdev)
+{
+   struct ipucsi *ipucsi = container_of(subdev, struct ipucsi, subdev);
+
+   

[PATCH 11/22] [media] imx: Add i.MX MIPI CSI-2 subdevice driver

2016-10-07 Thread Philipp Zabel
Add a v4l2 subdevice driver for the Synopsys DesignWare MIPI CSI-2 host
controller on i.MX6. Here its output is connected to the CSI2IPU gasket,
which distributes the time division multiplexed virtual channels to the
four IPU CSI inputs, directly or through video bus multiplexers.

Signed-off-by: Philipp Zabel 
---
 .../devicetree/bindings/media/fsl-imx-capture.txt  |  67 ++
 drivers/media/platform/imx/Kconfig |   7 +
 drivers/media/platform/imx/Makefile|   1 +
 drivers/media/platform/imx/imx-mipi-csi2.c | 676 +
 4 files changed, 751 insertions(+)
 create mode 100644 drivers/media/platform/imx/imx-mipi-csi2.c

diff --git a/Documentation/devicetree/bindings/media/fsl-imx-capture.txt 
b/Documentation/devicetree/bindings/media/fsl-imx-capture.txt
index 5805331..b5ef101 100644
--- a/Documentation/devicetree/bindings/media/fsl-imx-capture.txt
+++ b/Documentation/devicetree/bindings/media/fsl-imx-capture.txt
@@ -23,3 +23,70 @@ capture-subsystem {
 compatible = "fsl,imx-capture-subsystem";
 ports = <&ipu1_csi0>, <&ipu1_csi1>, <&ipu2_csi0>, <&ipu2_csi1>;
 };
+
+i.MX MIPI CSI-2 Host Controller
+===
+
+The i.MX6 contains an implementation of a Synopsys DesignWare MIPI CSI-2 host
+controller combined with a CSI2IPU gasket that distributes the virtual channels
+to up to four IPUv3 CSIs.
+
+Required properties:
+- compatible: should be "fsl,imx6q-mipi-csi2", "snps,dw-mipi-csi2"
+- reg: should be register base and length as documented in the SoC
+  reference manual
+- clocks: should contain the pclk, cfg, ref, and pixel clocks, in the
+  order determined by the clock-names property.
+- clock-names: should be "pclk", "cfg", "ref", "pixel"
+- address-cells: should be 1
+- size-cells: should be 0
+- port@*: five port nodes using of_graph bindings, one input port and four
+  output ports corresponding to the virtual channels.
+
+Example:
+
+mipi_csi: mipi@021dc000 {
+   compatible = "fsl,imx6q-mipi-csi2", "snps,dw-mipi-csi2";
+   reg = <0x021dc000 0x4000>;
+   clocks = <&clks IMX6QDL_CLK_HSI_TX>, <&clks IMX6QDL_CLK_HSI_TX>,
+<&clks IMX6QDL_CLK_HSI_TX>, <&clks IMX6QDL_CLK_EIM_PODF>;
+   clock-names = "pclk", "cfg", "ref", "pixel";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   };
+
+   port@1 {
+   reg = <1>;
+
+   vc0: endpoint {
+   remote-endpoint = <&csi0_in>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   vc1: endpoint {
+   remote-endpoint = <&csi1_in>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   vc2: endpoint {
+   remote-endpoint = <&csi2_in>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   vc3: endpoint {
+   remote-endpoint = <&csi3_in>;
+   };
+   };
+};
diff --git a/drivers/media/platform/imx/Kconfig 
b/drivers/media/platform/imx/Kconfig
index 69e8648..db04e64 100644
--- a/drivers/media/platform/imx/Kconfig
+++ b/drivers/media/platform/imx/Kconfig
@@ -6,6 +6,13 @@ config MEDIA_IMX
  This driver provides a SoC wide media controller device that all
  multimedia components in i.MX5 and i.MX6 SoCs can register with.
 
+config MEDIA_IMX_MIPI_CSI2
+   tristate "i.MX MIPI CSI-2 Host Controller"
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This driver provides support for the MIPI CSI-2 Host Controller that
+ is connected to the IPU CSI input multiplexers on i.MX6 SoCs.
+
 config VIDEO_IMX_IPU_COMMON
tristate
 
diff --git a/drivers/media/platform/imx/Makefile 
b/drivers/media/platform/imx/Makefile
index 919eaa1..22d86fd 100644
--- a/drivers/media/platform/imx/Makefile
+++ b/drivers/media/platform/imx/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_MEDIA_IMX)+= imx-media.o
+obj-$(CONFIG_MEDIA_IMX_MIPI_CSI2)  += imx-mipi-csi2.o
 obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o
 obj-$(CONFIG_VIDEO_IMX_IPU_CAPTURE)+= imx-ipu-capture.o
 obj-$(CONFIG_VIDEO_IMX_IPU_CSI)+= imx-ipuv3-csi.o
diff --git a/drivers/media/platform/imx/imx-mipi-csi2.c 
b/drivers/media/platform/imx/imx-mipi-csi2.c
new file mode 100644
index 000..0613187
--- /dev/null
+++ b/drivers/media/platform/imx/imx-mipi-csi2.c
@@ -0,0 +1,676 @@
+/*
+ * i.MX MIPI CSI-2 Host Controller driver
+ *
+ * Copyright (C) 2016, Pengutronix, Philipp Zabel 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MIPI_CSI2_VERSION  0x00

[PATCH 18/22] [media] imx-ipuv3-csi: support downsizing

2016-10-07 Thread Philipp Zabel
Add support for the CSI internal horizontal and vertical downsizing.

Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/imx/imx-ipuv3-csi.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/imx/imx-ipuv3-csi.c 
b/drivers/media/platform/imx/imx-ipuv3-csi.c
index 699460e6..e8a6a7b 100644
--- a/drivers/media/platform/imx/imx-ipuv3-csi.c
+++ b/drivers/media/platform/imx/imx-ipuv3-csi.c
@@ -167,8 +167,16 @@ static int ipucsi_subdev_set_format(struct v4l2_subdev *sd,
width = clamp_t(unsigned int, sdformat->format.width, 16, 8192);
height = clamp_t(unsigned int, sdformat->format.height, 16, 
4096);
} else {
-   width = ipucsi->format_mbus[0].width;
-   height = ipucsi->format_mbus[0].height;
+   if (sdformat->format.width <
+   (ipucsi->format_mbus[0].width * 3 / 4))
+   width = ipucsi->format_mbus[0].width / 2;
+   else
+   width = ipucsi->format_mbus[0].width;
+   if (sdformat->format.height <
+   (ipucsi->format_mbus[0].height * 3 / 4))
+   height = ipucsi->format_mbus[0].height / 2;
+   else
+   height = ipucsi->format_mbus[0].height;
}
 
mbusformat = __ipucsi_get_pad_format(sd, cfg, sdformat->pad,
@@ -212,14 +220,14 @@ static int ipucsi_subdev_s_stream(struct v4l2_subdev *sd, 
int enable)
window.width = fmt[0].width;
window.height = fmt[0].height;
ipu_csi_set_window(ipucsi->csi, &window);
+   ipu_csi_set_downsize(ipucsi->csi,
+fmt[0].width == 2 * fmt[1].width,
+fmt[0].height == 2 * fmt[1].height);
 
/* Is CSI data source MCT (MIPI)? */
mux_mct = (mbus_config.type == V4L2_MBUS_CSI2);
-
ipu_set_csi_src_mux(ipucsi->ipu, ipucsi->id, mux_mct);
-   if (mux_mct)
-   ipu_csi_set_mipi_datatype(ipucsi->csi, /*VC*/ 0,
- &fmt[0]);
+   ipu_csi_set_mipi_datatype(ipucsi->csi, /*VC*/ 0, &fmt[0]);
 
ret = ipu_csi_init_interface(ipucsi->csi, &mbus_config,
 &fmt[0]);
-- 
2.9.3

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


[PATCH 12/22] [media] tc358743: put lanes in STOP state before starting streaming

2016-10-07 Thread Philipp Zabel
Without calling tc358743_set_csi from the new prepare_stream callback
(or calling tc358743_s_dv_timings or tc358743_set_fmt from userspace
after stopping the stream), the i.MX6 MIPI CSI2 input fails waiting
for lanes to enter STOP state when streaming is started again.

Signed-off-by: Philipp Zabel 
---
 drivers/media/i2c/tc358743.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 1e3a0dd2..dfa45d2 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1463,6 +1463,14 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd,
return 0;
 }
 
+static int tc358743_prepare_stream(struct v4l2_subdev *sd)
+{
+   /* Put all lanes in PL-11 state (STOPSTATE) */
+   tc358743_set_csi(sd);
+
+   return 0;
+}
+
 static int tc358743_s_stream(struct v4l2_subdev *sd, int enable)
 {
enable_stream(sd, enable);
@@ -1637,6 +1645,7 @@ static const struct v4l2_subdev_video_ops 
tc358743_video_ops = {
.g_dv_timings = tc358743_g_dv_timings,
.query_dv_timings = tc358743_query_dv_timings,
.g_mbus_config = tc358743_g_mbus_config,
+   .prepare_stream = tc358743_prepare_stream,
.s_stream = tc358743_s_stream,
 };
 
-- 
2.9.3

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


[PATCH 14/22] ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their connections

2016-10-07 Thread Philipp Zabel
This patch adds the device tree graph connecting the input multiplexers
to the IPU CSIs and the MIPI-CSI2 gasket on i.MX6. The MIPI_IPU
multiplexers are added as children of the iomuxc-gpr syscon device node.
On i.MX6Q/D two two-input multiplexers in front of IPU1 CSI0 and IPU2
CSI1 allow to select between CSI0/1 parallel input pads and the MIPI
CSI-2 virtual channels 0/3.
On i.MX6DL/S two five-input multiplexers in front of IPU1 CSI0 and IPU1
CSI1 allow to select between CSI0/1 parallel input pads and any of the
four MIPI CSI-2 virtual channels.

Signed-off-by: Philipp Zabel 
---
 arch/arm/boot/dts/imx6dl.dtsi  | 182 +
 arch/arm/boot/dts/imx6q.dtsi   | 118 ++
 arch/arm/boot/dts/imx6qdl.dtsi |  10 ++-
 3 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 3c817de..7ed4efd6f 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -133,6 +133,188 @@
  "di0", "di1";
 };
 
+&gpr {
+   ipu_csi0_mux {
+   compatible = "video-multiplexer";
+   reg = <0x34>;
+   bit-mask = <0x7>;
+   bit-shift = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   ipu_csi0_mux_from_mipi_csi0: endpoint {
+   remote-endpoint = <&mipi_csi0_to_ipu_csi0_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu_csi0_mux_from_mipi_csi1: endpoint {
+   remote-endpoint = <&mipi_csi1_to_ipu_csi0_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu_csi0_mux_from_mipi_csi2: endpoint {
+   remote-endpoint = <&mipi_csi2_to_ipu_csi0_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu_csi0_mux_from_mipi_csi3: endpoint {
+   remote-endpoint = <&mipi_csi3_to_ipu_csi0_mux>;
+   };
+   };
+
+   csi0: port@4 {
+   reg = <4>;
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu_csi0_mux_to_ipu1_csi0: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_from_ipu_csi0_mux>;
+   };
+   };
+   };
+
+   ipu_csi1_mux {
+   compatible = "video-multiplexer";
+   reg = <0x34>;
+   bit-mask = <0x7>;
+   bit-shift = <3>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   ipu_csi1_mux_from_mipi_csi0: endpoint {
+   remote-endpoint = <&mipi_csi0_to_ipu_csi1_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu_csi1_mux_from_mipi_csi1: endpoint {
+   remote-endpoint = <&mipi_csi1_to_ipu_csi1_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu_csi1_mux_from_mipi_csi2: endpoint {
+   remote-endpoint = <&mipi_csi2_to_ipu_csi1_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu_csi1_mux_from_mipi_csi3: endpoint {
+   remote-endpoint = <&mipi_csi3_to_ipu_csi1_mux>;
+   };
+   };
+
+   csi1: port@4 {
+   reg = <4>;
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu_csi1_mux_to_ipu1_csi1: endpoint {
+   remote-endpoint = 
<&ipu1_csi1_from_ipu_csi1_mux>;
+   };
+   };
+   };
+};
+
+&ipu1_csi0 {
+   ipu1_csi0_from_ipu_csi0_mux: endpoint {
+   remote-endpoint = <&ipu_csi0_mux_to_ipu1_csi0>;
+   };
+};
+
+&ipu1_csi1 {
+   ipu1_csi1_from_ipu_csi1_mux: endpoint {
+   remote-endpoint = <&ipu_csi1_mux_to_ipu1_csi1>;
+   };
+};
+
+&mipi_csi {
+   port@0 {
+   reg = <0>;
+   };
+
+   port@1 {
+   reg = <1>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_csi0_to_ipu_csi0_mux: endpoint@0 {
+   remote-endpoint = <&ipu_csi0_mux_from_mipi_csi0>;
+   };
+
+   mipi_csi0_to_ipu_csi1_mux: endpoint@1 {
+  

[PATCH 16/22] ARM: dts: nitrogen6x: Add dtsi for BD_HDMI_MIPI HDMI to MIPI CSI-2 receiver board

2016-10-07 Thread Philipp Zabel
Add device tree nodes for the BD_HDMI_MIPI HDMI to MIPI CSI-2 receiver
board with a TC358743 connected to the Nitrogen6X MIPI CSI-2 input
connector.

Signed-off-by: Philipp Zabel 
---
 .../boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi  | 73 ++
 1 file changed, 73 insertions(+)
 create mode 100644 arch/arm/boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi

diff --git a/arch/arm/boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi 
b/arch/arm/boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi
new file mode 100644
index 000..e110874
--- /dev/null
+++ b/arch/arm/boot/dts/imx6qdl-nitrogen6x-bd-hdmi-mipi.dtsi
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Philipp Zabel, Pengutronix
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include 
+#include 
+
+/ {
+   hdmi_osc: hdmi-osc {
+   compatible = "fixed-clock";
+   clock-output-names = "hdmi-osc";
+   clock-frequency = <2700>;
+   #clock-cells = <0>;
+   };
+};
+
+&i2c2 {
+   tc358743: tc358743@0f {
+   compatible = "toshiba,tc358743";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tc358743>;
+   reg = <0x0f>;
+   clocks = <&hdmi_osc>;
+   clock-names = "refclk";
+   reset-gpios = <&gpio6 9 GPIO_ACTIVE_LOW>;
+   interrupt-parent = <&gpio2>;
+   interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
+
+   port@0 {
+   tc358743_out: endpoint {
+   remote-endpoint = <&mipi_csi2_in>;
+   data-lanes = <1 2 3 4>;
+   clock-lanes = <0>;
+   clock-noncontinuous;
+   link-frequencies = /bits/ 64 <29700>;
+   };
+   };
+   };
+};
+
+&iomuxc {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_hog>;
+
+   imx6q-nitrogen6x-tc358743 {
+   pinctrl_tc358743: tc358743grp {
+   fsl,pins = <
+   MX6QDL_PAD_NANDF_WP_B__GPIO6_IO09 0x4000b0b0
/* RESETN */
+   MX6QDL_PAD_NANDF_D5__GPIO2_IO05   0x400130b0
/* INT */
+   >;
+   };
+   };
+};
+
+&mipi_csi {
+   status = "okay";
+
+   port@0 {
+   mipi_csi2_in: endpoint {
+   remote-endpoint = <&tc358743_out>;
+   data-lanes = <1 2 3 4>;
+   clock-lanes = <0>;
+   clock-noncontinuous;
+   link-frequencies = /bits/ 64 <29700>;
+   };
+   };
+};
-- 
2.9.3

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


Re: [PATCH 01/22] [media] v4l2-async: move code out of v4l2_async_notifier_register into v4l2_async_test_nofity_all

2016-10-07 Thread Marek Vasut
On 10/07/2016 06:00 PM, Philipp Zabel wrote:
> This will be reused in the following patch to catch already registered,
> newly added asynchronous subdevices from v4l2_async_register_subdev.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 38 
> +---
>  1 file changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index 5bada20..c4f1930 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -134,11 +134,31 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)
>   sd->dev = NULL;
>  }
>  
> +static int v4l2_async_test_notify_all(struct v4l2_async_notifier *notifier)
> +{
> + struct v4l2_subdev *sd, *tmp;
> +
> + list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
> + struct v4l2_async_subdev *asd;
> + int ret;
> +
> + asd = v4l2_async_belongs(notifier, sd);
> + if (!asd)
> + continue;
> +
> + ret = v4l2_async_test_notify(notifier, sd, asd);
> + if (ret < 0)
> + return ret;
> + }
> +
> + return 0;
> +}
> +
>  int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
>struct v4l2_async_notifier *notifier)
>  {
> - struct v4l2_subdev *sd, *tmp;
>   struct v4l2_async_subdev *asd;
> + int ret;
>   int i;
>  
>   if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
> @@ -171,23 +191,9 @@ int v4l2_async_notifier_register(struct v4l2_device 
> *v4l2_dev,
>   /* Keep also completed notifiers on the list */
>   list_add(¬ifier->list, ¬ifier_list);
>  
> - list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
> - int ret;
> -
> - asd = v4l2_async_belongs(notifier, sd);
> - if (!asd)
> - continue;
> -
> - ret = v4l2_async_test_notify(notifier, sd, asd);
> - if (ret < 0) {
> - mutex_unlock(&list_lock);
> - return ret;
> - }
> - }

Shouldn't you call ret = v4l2_async_test_notify_all() here now instead ?

>   mutex_unlock(&list_lock);
>  
> - return 0;
> + return ret;
>  }
>  EXPORT_SYMBOL(v4l2_async_notifier_register);
>  
> 


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


Re: [PATCH 01/22] [media] v4l2-async: move code out of v4l2_async_notifier_register into v4l2_async_test_nofity_all

2016-10-07 Thread Philipp Zabel
Am Freitag, den 07.10.2016, 18:30 +0200 schrieb Marek Vasut:
> On 10/07/2016 06:00 PM, Philipp Zabel wrote:
> > This will be reused in the following patch to catch already registered,
> > newly added asynchronous subdevices from v4l2_async_register_subdev.
> > 
> > Signed-off-by: Philipp Zabel 
> > ---
> >  drivers/media/v4l2-core/v4l2-async.c | 38 
> > +---
> >  1 file changed, 22 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> > b/drivers/media/v4l2-core/v4l2-async.c
> > index 5bada20..c4f1930 100644
> > --- a/drivers/media/v4l2-core/v4l2-async.c
> > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > @@ -134,11 +134,31 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)
> > sd->dev = NULL;
> >  }
> >  
> > +static int v4l2_async_test_notify_all(struct v4l2_async_notifier *notifier)
> > +{
> > +   struct v4l2_subdev *sd, *tmp;
> > +
> > +   list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
> > +   struct v4l2_async_subdev *asd;
> > +   int ret;
> > +
> > +   asd = v4l2_async_belongs(notifier, sd);
> > +   if (!asd)
> > +   continue;
> > +
> > +   ret = v4l2_async_test_notify(notifier, sd, asd);
> > +   if (ret < 0)
> > +   return ret;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >  int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
> >  struct v4l2_async_notifier *notifier)
> >  {
> > -   struct v4l2_subdev *sd, *tmp;
> > struct v4l2_async_subdev *asd;
> > +   int ret;
> > int i;
> >  
> > if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
> > @@ -171,23 +191,9 @@ int v4l2_async_notifier_register(struct v4l2_device 
> > *v4l2_dev,
> > /* Keep also completed notifiers on the list */
> > list_add(¬ifier->list, ¬ifier_list);
> >  
> > -   list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
> > -   int ret;
> > -
> > -   asd = v4l2_async_belongs(notifier, sd);
> > -   if (!asd)
> > -   continue;
> > -
> > -   ret = v4l2_async_test_notify(notifier, sd, asd);
> > -   if (ret < 0) {
> > -   mutex_unlock(&list_lock);
> > -   return ret;
> > -   }
> > -   }
> 
> Shouldn't you call ret = v4l2_async_test_notify_all() here now instead ?

Absolutely, thanks. I've lost this in a rebase and the problem got
hidden by patch 2 replacing it again.

regards
Philipp

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


[PATCH v1] [media] v4l2-ctrls: add mpeg2 parser metadata

2016-10-07 Thread Hugues Fruchet
---
 drivers/media/v4l2-core/v4l2-ctrls.c |   2 +-
 include/uapi/linux/v4l2-controls.h   | 163 +--
 2 files changed, 140 insertions(+), 25 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index c8bc4d4..6187dfc 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -2115,7 +2115,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct 
v4l2_ctrl_handler *hdl,
elem_size = sizeof(u32);
break;
case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR:
-   elem_size = sizeof(struct v4l2_ctrl_mpeg2_frame_hdr);
+   elem_size = sizeof(struct v4l2_ctrl_mpeg2_meta);
break;
default:
if (type < V4L2_CTRL_COMPOUND_TYPES)
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index cdf9497..cb685a7 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -549,6 +549,145 @@ enum v4l2_mpeg_video_mpeg4_profile {
 
 #define V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR (V4L2_CID_MPEG_BASE+450)
 
+/* MPEG2 frame API metadata */
+#define MPEG2_QUANTISER_MATRIX_SIZE   64
+
+struct mpeg_video_sequence_hdr {
+   unsigned short width, height;
+   unsigned char aspect_ratio_info;
+   unsigned char frame_rate_code;
+   unsigned int bitrate_value;
+   unsigned short vbv_buffer_size_value;
+   unsigned char constrained_parameters_flag;
+   unsigned char load_intra_flag, load_non_intra_flag;
+   unsigned char intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX_SIZE];
+   unsigned char non_intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX_SIZE];
+   unsigned int par_w, par_h;
+   unsigned int fps_n, fps_d;
+   unsigned int bitrate;
+};
+
+struct mpeg_video_sequence_ext {
+   unsigned char profile_and_level;
+   unsigned char progressive;
+   unsigned char chroma_format;
+   unsigned char horiz_size_ext, vert_size_ext;
+   unsigned short bitrate_ext;
+   unsigned char vbv_buffer_size_extension;
+   unsigned char low_delay;
+   unsigned char fps_n_ext, fps_d_ext;
+};
+
+struct mpeg_video_sequence_display_ext {
+   unsigned char video_format;
+   unsigned char colour_description_flag;
+   unsigned char colour_primaries;
+   unsigned char transfer_characteristics;
+   unsigned char matrix_coefficients;
+   unsigned short display_horizontal_size;
+   unsigned short display_vertical_size;
+};
+
+struct mpeg_video_sequence_scalable_ext {
+   unsigned char scalable_mode;
+   unsigned char layer_id;
+   unsigned short lower_layer_prediction_horizontal_size;
+   unsigned short lower_layer_prediction_vertical_size;
+   unsigned char horizontal_subsampling_factor_m;
+   unsigned char horizontal_subsampling_factor_n;
+   unsigned char vertical_subsampling_factor_m;
+   unsigned char vertical_subsampling_factor_n;
+   unsigned char picture_mux_enable;
+   unsigned char mux_to_progressive_sequence;
+   unsigned char picture_mux_order;
+   unsigned char picture_mux_factor;
+};
+
+struct mpeg_video_gop {
+   unsigned char drop_frame_flag;
+   unsigned char hour, minute, second, frame;
+   unsigned char closed_gop;
+   unsigned char broken_link;
+};
+
+struct mpeg_video_picture_hdr {
+   unsigned short tsn;
+   unsigned char pic_type;
+   unsigned short vbv_delay;
+   unsigned char full_pel_forward_vector, full_pel_backward_vector;
+   unsigned char f_f_code;
+   unsigned char b_f_code;
+};
+
+struct mpeg_video_picture_ext {
+   unsigned char f_code[2][2];
+   unsigned char intra_dc_precision;
+   unsigned char picture_structure;
+   unsigned char top_field_first;
+   unsigned char frame_pred_frame_dct;
+   unsigned char concealment_motion_vectors;
+   unsigned char q_scale_type;
+   unsigned char intra_vlc_format;
+   unsigned char alternate_scan;
+   unsigned char repeat_first_field;
+   unsigned char chroma_420_type;
+   unsigned char progressive_frame;
+   unsigned char composite_display_flag;
+   unsigned char v_axis;
+   unsigned char field_sequence;
+   unsigned char sub_carrier;
+   unsigned char burst_amplitude;
+   unsigned char sub_carrier_phase;
+};
+
+struct mpeg_video_quant_matrix_ext {
+   unsigned char load_intra_quantiser_matrix;
+   unsigned char intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX_SIZE];
+   unsigned char load_non_intra_quantiser_matrix;
+   unsigned char non_intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX_SIZE];
+   unsigned char load_chroma_intra_quantiser_matrix;
+   unsigned char 
chroma_intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX_SIZE];
+   unsigned char load_chroma_non_intra_quantiser_matrix;
+   unsigned char 
chroma_non_intra_quantiser_matrix[MPEG2_QUANTISER_MATRIX

[PATCH v1] Enhance MPEG2 video decoder frame API

2016-10-07 Thread Hugues Fruchet
This patchset refine the original MPEG2 controls introduced by
Florent Revest in [1] by adding support of various MPEG2 extensions,
including frame & field interlaced bistream.
This is a work in progress in order to start discussion around
V4L2 frame API standardisation.

[1] http://www.spinics.net/lists/linux-media/msg104824.html

Hugues Fruchet (1):
  [media] v4l2-ctrls: add mpeg2 parser metadata

 drivers/media/v4l2-core/v4l2-ctrls.c |   2 +-
 include/uapi/linux/v4l2-controls.h   | 163 +--
 2 files changed, 140 insertions(+), 25 deletions(-)

-- 
1.9.1

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


[PATCH v1 3/3] libv4l-delta: add mpeg header parser

2016-10-07 Thread Hugues Fruchet
From: Tiphaine Inguere 

If the input stream format is MPEG1 or MPEG2, the stream is parsed
using mpeg parser library to build mpeg metadata.

Change-Id: I767cd0a8ea546755bcdc031ca4a2808690cccf63
signed-off-by: Tiphaine Inguere 
Signed-off-by: Hugues Fruchet 
---
 lib/libv4l-delta/Makefile.am  |   4 +
 lib/libv4l-delta/libv4l-delta-mpeg2.c | 211 ++
 lib/libv4l-delta/libv4l-delta.c   |   6 +-
 3 files changed, 220 insertions(+), 1 deletion(-)
 create mode 100644 lib/libv4l-delta/libv4l-delta-mpeg2.c

diff --git a/lib/libv4l-delta/Makefile.am b/lib/libv4l-delta/Makefile.am
index fa401b6..3812de5 100644
--- a/lib/libv4l-delta/Makefile.am
+++ b/lib/libv4l-delta/Makefile.am
@@ -6,6 +6,10 @@ SUBDIRS = codecparsers
 
 libv4l_delta_la_SOURCES = libv4l-delta.c libv4l-delta.h
 
+# MPEG2 decoder #
+libv4l_delta_la_SOURCES += libv4l-delta-mpeg2.c
+
+# Codecparser interface  #
 libv4l_delta_la_CPPFLAGS = $(CFLAG_VISIBILITY)
 libv4l_delta_la_CFLAGS =   $(GST_CFLAGS)   -DGST_USE_UNSTABLE_API
 libv4l_delta_la_LDFLAGS = -avoid-version -module -shared -export-dynamic 
-lpthread
diff --git a/lib/libv4l-delta/libv4l-delta-mpeg2.c 
b/lib/libv4l-delta/libv4l-delta-mpeg2.c
new file mode 100644
index 000..7f69dd4
--- /dev/null
+++ b/lib/libv4l-delta/libv4l-delta-mpeg2.c
@@ -0,0 +1,211 @@
+/*
+ * libv4l-delta-mpeg2.c
+ *
+ * Copyright (C) STMicroelectronics SA 2014
+ * Authors: Tifaine Inguere 
+ *  Hugues Fruchet 
+ */
+#include 
+#include 
+#include 
+
+#include "codecparsers/gstmpegvideoparser.h"
+#include "libv4l-delta.h"
+
+/* FIXME
+ * - meta coherency check (what is mandatory vs optional)
+ * - meta compatibility check (GST types must be aligned with V4L2 ones)
+ * - parsing errors tracing (trace in case of gst_parse_xxx fails)
+ * - do not parse all access unit (currently needed to detect the
+ *   second slice of a field interlaced bitstream)
+ */
+
+unsigned int delta_mpeg2_decode_header(void *au_addr,
+  
unsigned int au_size,
+  
struct v4l2_ctrl_mpeg2_meta *meta)
+{
+   unsigned char ExtensionCode;
+   unsigned int startcode_found = 0;
+   unsigned int header_found = 0;
+   GstMpegVideoPacket packet_data;
+   unsigned int slice_index = 0;
+
+   DELTA_LOG_DEBUG("> %s\n", __func__);
+
+   if ((!au_addr) || (!au_size) || (!meta)) {
+   DELTA_LOG_ERR("%s: invalid input: au_addr=%p, au_size=%d, 
meta=%p\n",
+ __func__, au_addr, au_size, meta);
+   return 0;
+   }
+
+   memset(meta, 0, sizeof(*meta));
+   meta->struct_size = sizeof(*meta);
+
+   memset(&packet_data, 0, sizeof(packet_data));
+
+   while (((packet_data.offset + 4) < au_size)) {
+   DELTA_LOG_DEBUG("%s: parsing input from offset=%d\n", __func__,
+   packet_data.offset);
+   startcode_found = gst_mpeg_video_parse(&packet_data, au_addr, 
au_size,
+   
   packet_data.offset);
+   if (!startcode_found) {
+   DELTA_LOG_DEBUG("%s: parsing is over\n", __func__);
+break;
+   }
+   DELTA_LOG_DEBUG("%s: found starcode @offset=%u, code=0x%02x\n",
+   __func__, packet_data.offset - 
4, packet_data.type);
+
+   switch (packet_data.type) {
+   case GST_MPEG_VIDEO_PACKET_PICTURE:
+   if (gst_mpeg_video_packet_parse_picture_header
+   (&packet_data,
+(GstMpegVideoPictureHdr 
*)&(meta->pic[slice_index].pic_h))) {
+   meta->flags |= V4L2_CTRL_MPEG2_FLAG_PIC;
+   meta->pic[slice_index].flags |= 
MPEG2_META_PIC_FLAG_HDR;
+   DELTA_LOG_DEBUG("%s: 
MPEG2_META_PIC_FLAG_HDR\n", __func__);
+   header_found = 1;
+   }
+   break;
+
+   case GST_MPEG_VIDEO_PACKET_SLICE_MIN:
+   /* new slice encountered */
+   /* FIXME we can avoid to parse too much data here by 
stopping
+   * at first slice encountered but not in the case of 
field
+   * interlaced where 2 slices are expected
+   */
+   if (slice_index > 1) {
+   DELTA_LOG_ERR("%s: more than 2 slices detected 
@offset=%d, ignoring this slice...\n",
+ __func__, 
packet_data.offset);
+   break;
+   }
+
+   /* store its offset & 

[PATCH v1 0/2] Add MPEG2 support to STMicroelectronics DELTA video decoder

2016-10-07 Thread Hugues Fruchet
This patchset adds MPEG2 support to STMicroelectronics DELTA driver [1].
MPEG2 support requires V4L2 "frame API" in order that MPEG2 parsed metadata
are received in addition to MPEG2 video bitstream buffers.
To do so those patchset are based on work from Florent Revest on MPEG2 low
level decoder [2], which have been enhanced to support more MPEG2 features
(see additional patchset on subject). This work also needs the V4L2 "request
API" [3].
A reference libv4l-delta plugin implementation is sent separately which embeds
a MPEG2 parser generating the headers metadata needed by DELTA video decoder.

[1] http://www.mail-archive.com/linux-media@vger.kernel.org/msg102894.html
[2] http://www.spinics.net/lists/linux-media/msg104824.html
[3] https://lwn.net/Articles/641204/

Hugues Fruchet (2):
  [media] st-delta: add parser meta controls
  [media] st-delta: add mpeg2 support

 drivers/media/platform/Kconfig |6 +
 drivers/media/platform/sti/delta/Makefile  |3 +
 drivers/media/platform/sti/delta/delta-cfg.h   |5 +
 drivers/media/platform/sti/delta/delta-mpeg2-dec.c | 1412 
 drivers/media/platform/sti/delta/delta-mpeg2-fw.h  |  415 ++
 drivers/media/platform/sti/delta/delta-v4l2.c  |   96 +-
 drivers/media/platform/sti/delta/delta.h   |8 +-
 7 files changed, 1943 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-dec.c
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-fw.h

-- 
1.9.1

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


[PATCH v1 1/2] [media] st-delta: add parser meta controls

2016-10-07 Thread Hugues Fruchet
---
 drivers/media/platform/sti/delta/delta-v4l2.c | 92 ++-
 drivers/media/platform/sti/delta/delta.h  |  8 ++-
 2 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/sti/delta/delta-v4l2.c 
b/drivers/media/platform/sti/delta/delta-v4l2.c
index 1014d04..a0d2f3e 100644
--- a/drivers/media/platform/sti/delta/delta-v4l2.c
+++ b/drivers/media/platform/sti/delta/delta-v4l2.c
@@ -1051,6 +1051,38 @@ static int delta_subscribe_event(struct v4l2_fh *fh,
return 0;
 }
 
+
+static int delta_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct delta_ctx *ctx =
+   container_of(ctrl->handler, struct delta_ctx, ctrl_handler);
+   struct delta_dev *delta = ctx->dev;
+
+   switch (ctrl->id) {
+   case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR:
+   break;
+   default:
+   dev_err(delta->dev, "%s unsupported control (%d)\n",
+   ctx->name, ctrl->id);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct v4l2_ctrl_ops delta_ctrl_ops = {
+   .s_ctrl = delta_s_ctrl,
+};
+
+static const struct v4l2_ctrl_config delta_ctrl_mpeg2_meta = {
+   .ops = &delta_ctrl_ops,
+   .id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR,
+   .type = V4L2_CTRL_TYPE_PRIVATE,
+   .name = "MPEG2 frame/slice metadata",
+   .max_reqs = VIDEO_MAX_FRAME,
+   .elem_size = sizeof(struct v4l2_ctrl_mpeg2_meta),
+};
+
 /* v4l2 ioctl ops */
 static const struct v4l2_ioctl_ops delta_ioctl_ops = {
.vidioc_querycap = delta_querycap,
@@ -1112,6 +1144,15 @@ static void delta_run_work(struct work_struct *work)
au->size = vb2_get_plane_payload(&vbuf->vb2_buf, 0);
au->dts = vbuf->vb2_buf.timestamp;
 
+   /* get access unit meta data */
+   ret = v4l2_ctrl_apply_request(&ctx->ctrl_handler, vbuf->request);
+   if (ret) {
+   dev_err(delta->dev, "%s failed to apply metadata control 
request (%d)\n",
+   ctx->name, ret);
+   goto out;
+   }
+   au->meta = ctx->meta_ctrl->p_new.p;
+
/* dump access unit */
dev_dbg(delta->dev, "%s dump %s", ctx->name,
dump_au(au, str, sizeof(str)));
@@ -1507,6 +1548,15 @@ static int delta_vb2_au_start_streaming(struct vb2_queue 
*q,
au->size = vb2_get_plane_payload(&vbuf->vb2_buf, 0);
au->dts = vbuf->vb2_buf.timestamp;
 
+   /* get access unit meta data */
+   ret = v4l2_ctrl_apply_request(&ctx->ctrl_handler, vbuf->request);
+   if (ret) {
+   dev_err(delta->dev, "%s failed to start streaming, cannot apply 
metadata control request (%d)\n",
+   ctx->name, ret);
+   goto err;
+   }
+   au->meta = ctx->meta_ctrl->p_new.p;
+
delta_push_dts(ctx, au->dts);
 
/* dump access unit */
@@ -1758,6 +1808,7 @@ static int queue_init(void *priv,
q->mem_ops = &vb2_dma_contig_memops;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
q->lock = &delta->lock;
+   q->v4l2_allow_requests = true;
ret = vb2_queue_init(q);
if (ret)
return ret;
@@ -1778,6 +1829,33 @@ static int queue_init(void *priv,
return vb2_queue_init(q);
 }
 
+static int delta_ctrls_setup(struct delta_ctx *ctx)
+{
+   struct delta_dev *delta = ctx->dev;
+   struct v4l2_ctrl_handler *hdl;
+
+   hdl = &ctx->ctrl_handler;
+   v4l2_ctrl_handler_init(hdl, 1);
+
+//FIXME, switch codec... so we can do this only when codec is known !
+   ctx->meta_ctrl = v4l2_ctrl_new_custom(hdl, &delta_ctrl_mpeg2_meta,
+ NULL);
+   ctx->meta_ctrl->flags |= V4L2_CTRL_FLAG_REQ_KEEP;
+
+   if (hdl->error) {
+   int err = hdl->error;
+
+   dev_err(delta->dev, "%s controls setup failed (%d)\n",
+   ctx->name, err);
+   v4l2_ctrl_handler_free(hdl);
+   return err;
+   }
+
+   v4l2_ctrl_handler_setup(hdl);
+
+   return 0;
+}
+
 static int delta_open(struct file *file)
 {
struct delta_dev *delta = video_drvdata(file);
@@ -1797,6 +1875,14 @@ static int delta_open(struct file *file)
file->private_data = &ctx->fh;
v4l2_fh_add(&ctx->fh);
 
+   ret = delta_ctrls_setup(ctx);
+   if (ret) {
+   dev_err(delta->dev, "%s failed to setup controls (%d)\n",
+   DELTA_PREFIX, ret);
+   goto err_fh_del;
+   }
+   ctx->fh.ctrl_handler = &ctx->ctrl_handler;
+
INIT_WORK(&ctx->run_work, delta_run_work);
mutex_init(&ctx->lock);
 
@@ -1806,7 +1892,7 @@ static int delta_open(struct file *file)
ret = PTR_ERR(ctx->fh.m2m_ctx);
dev_err(delta->dev, "%s failed to initialize m2m context 
(%d)\n",
DELTA_PREFIX, ret);
-   goto err_fh_del;
+   goto err_ctrls;
}
 
  

[PATCH v1 0/3] Add a libv4l mpeg2 parser plugin for st-delta video decoder

2016-10-07 Thread Hugues Fruchet
ST DELTA video decoder is a frame API based decoder which requires
headers metadata in addition to compressed video bitstream data.
This libv4l plugin aims to abstract DELTA frame API under
usual stream API, so compatibility with existing V4L2-based
frameworks such as GStreamer V4L2 video decoder plugin is ensured.
As a proof of concept, MPEG2 video decoding is covered relying
on GStreamer codecparser codebase.
This proof of concept aims to help to standardize the MPEG2 frame
API controls in V4L2 headers by showing a functional reference implementation.
Second aim of this prototype is to show the premice of a libv4l2 plugin
infrastructure allowing to use any appropriate proprietary or open-source
bitstream parser needed by frame API based video hardware accelerators.

Hugues Fruchet (1):
  add a libv4l plugin for st-delta video decoder

Tiphaine Inguere (2):
  libv4l-delta: add GStreamer mpeg codecparser
  libv4l-delta: add mpeg header parser

 configure.ac   |3 +
 lib/Makefile.am|3 +-
 lib/libv4l-delta/Makefile.am   |   23 +
 lib/libv4l-delta/codecparsers/Makefile.am  |   40 +
 lib/libv4l-delta/codecparsers/gstmpegvideoparser.c | 1304 
 lib/libv4l-delta/codecparsers/gstmpegvideoparser.h |  560 +
 lib/libv4l-delta/codecparsers/parserutils.c|   57 +
 lib/libv4l-delta/codecparsers/parserutils.h|  108 ++
 lib/libv4l-delta/libv4l-delta-mpeg2.c  |  211 
 lib/libv4l-delta/libv4l-delta.c|  348 ++
 lib/libv4l-delta/libv4l-delta.h|   97 ++
 lib/libv4l-delta/libv4l-delta.pc.in|   12 +
 12 files changed, 2765 insertions(+), 1 deletion(-)
 create mode 100644 lib/libv4l-delta/Makefile.am
 create mode 100644 lib/libv4l-delta/codecparsers/Makefile.am
 create mode 100644 lib/libv4l-delta/codecparsers/gstmpegvideoparser.c
 create mode 100644 lib/libv4l-delta/codecparsers/gstmpegvideoparser.h
 create mode 100644 lib/libv4l-delta/codecparsers/parserutils.c
 create mode 100644 lib/libv4l-delta/codecparsers/parserutils.h
 create mode 100644 lib/libv4l-delta/libv4l-delta-mpeg2.c
 create mode 100644 lib/libv4l-delta/libv4l-delta.c
 create mode 100644 lib/libv4l-delta/libv4l-delta.h
 create mode 100644 lib/libv4l-delta/libv4l-delta.pc.in

-- 
1.9.1

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


[PATCH v1 2/3] libv4l-delta: add GStreamer mpeg codecparser

2016-10-07 Thread Hugues Fruchet
From: Tiphaine Inguere 

The mpeg related files from gst-plugins-bad codecparser are added to
the libv4l-delta plugin.
This is a proof of concept which aims to validate the
interoperability of a standard mpeg parser with ST DELTA video decoder.
An implementation based on a common codecparser library shared
between GStreamer and V4L2 would be a far better implementation.

Change-Id: I7722c64e80101d833bbf9c973df846f60c3b8ee7
signed-off-by: Tiphaine Inguere 
Signed-off-by: Hugues Fruchet 
---
 configure.ac   |1 +
 lib/libv4l-delta/Makefile.am   |   12 +-
 lib/libv4l-delta/codecparsers/Makefile.am  |   40 +
 lib/libv4l-delta/codecparsers/gstmpegvideoparser.c | 1304 
 lib/libv4l-delta/codecparsers/gstmpegvideoparser.h |  560 +
 lib/libv4l-delta/codecparsers/parserutils.c|   57 +
 lib/libv4l-delta/codecparsers/parserutils.h|  108 ++
 7 files changed, 2081 insertions(+), 1 deletion(-)
 create mode 100644 lib/libv4l-delta/codecparsers/Makefile.am
 create mode 100644 lib/libv4l-delta/codecparsers/gstmpegvideoparser.c
 create mode 100644 lib/libv4l-delta/codecparsers/gstmpegvideoparser.h
 create mode 100644 lib/libv4l-delta/codecparsers/parserutils.c
 create mode 100644 lib/libv4l-delta/codecparsers/parserutils.h

diff --git a/configure.ac b/configure.ac
index bb656fd..c1c290a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,6 +19,7 @@ AC_CONFIG_FILES([Makefile
lib/libv4l-mplane/Makefile
lib/libv4l-hva/Makefile
lib/libv4l-delta/Makefile
+   lib/libv4l-delta/codecparsers/Makefile
 
utils/Makefile
utils/libv4l2util/Makefile
diff --git a/lib/libv4l-delta/Makefile.am b/lib/libv4l-delta/Makefile.am
index 0ec1dd7..fa401b6 100644
--- a/lib/libv4l-delta/Makefile.am
+++ b/lib/libv4l-delta/Makefile.am
@@ -2,8 +2,18 @@ if WITH_V4L_PLUGINS
 libv4l2plugin_LTLIBRARIES = libv4l-delta.la
 endif
 
+SUBDIRS = codecparsers
+
 libv4l_delta_la_SOURCES = libv4l-delta.c libv4l-delta.h
 
 libv4l_delta_la_CPPFLAGS = $(CFLAG_VISIBILITY)
+libv4l_delta_la_CFLAGS =   $(GST_CFLAGS)   -DGST_USE_UNSTABLE_API
 libv4l_delta_la_LDFLAGS = -avoid-version -module -shared -export-dynamic 
-lpthread
-libv4l_delta_la_LIBADD = ../libv4l2/libv4l2.la
+libv4l_delta_la_LDFLAGS += $(GST_LIB_LDFLAGS)
+
+libv4l_delta_la_LIBADD = ../libv4l2/libv4l2.la \
+   $(GLIB_LIBS)\
+   $(GST_BASE_LIBS) \
+   $(GST_LIBS) \
+   codecparsers/libgstcodecparsers.la  \
+   $(NULL)
diff --git a/lib/libv4l-delta/codecparsers/Makefile.am 
b/lib/libv4l-delta/codecparsers/Makefile.am
new file mode 100644
index 000..bd77573
--- /dev/null
+++ b/lib/libv4l-delta/codecparsers/Makefile.am
@@ -0,0 +1,40 @@
+lib_LTLIBRARIES = libgstcodecparsers.la
+
+libgstcodecparsers_la_SOURCES = \
+   gstmpegvideoparser.c \
+   parserutils.c \
+   gstmpegvideoparser.h \
+   $(NULL)
+
+noinst_HEADERS = parserutils.h
+
+libgstcodecparsers_la_CFLAGS = \
+   $(GST_BASE_CFLAGS) \
+   -DGST_USE_UNSTABLE_API \
+   $(GST_CFLAGS)
+
+libgstcodecparsers_la_LIBADD = \
+   $(GST_BASE_LIBS) \
+   $(GST_LIBS) \
+   $(LIBM)
+
+libgstcodecparsers_la_LDFLAGS = \
+   $(GST_LIB_LDFLAGS) \
+   $(GST_ALL_LDFLAGS) \
+   $(GST_LT_LDFLAGS)
+
+Android.mk:  $(BUILT_SOURCES) Makefile.am
+   androgenizer -:PROJECT libgstcodecparsers -:STATIC 
libgstcodecparsers-@GST_API_VERSION@ \
+-:TAGS eng debug \
+ -:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \
+-:SOURCES $(libgstcodecparsers_@GST_API_VERSION@_la_SOURCES) \
+ $(built_sources) \
+-:CFLAGS $(DEFS) $(libgstcodecparsers_@GST_API_VERSION@_la_CFLAGS) \
+-:LDFLAGS $(libgstcodecparsers_@GST_API_VERSION@_la_LDFLAGS) \
+  $(libgstcodecparsers@GST_API_VERSION@_la_LIBADD) \
+  -ldl \
+-:HEADER_TARGET gstreamer-@GST_API_VERSION@/gst/codecparsers \
+-:HEADERS $(libgstcodecparsersinclude_HEADERS) \
+ $(built_headers) \
+-:PASSTHROUGH LOCAL_ARM_MODE:=arm \
+   > $@
diff --git a/lib/libv4l-delta/codecparsers/gstmpegvideoparser.c 
b/lib/libv4l-delta/codecparsers/gstmpegvideoparser.c
new file mode 100644
index 000..cd0533e
--- /dev/null
+++ b/lib/libv4l-delta/codecparsers/gstmpegvideoparser.c
@@ -0,0 +1,1304 @@
+/* Gstreamer
+ * Copyright (C) <2011> Intel Corporation
+ * Copyright (C) <2011> Collabora Ltd.
+ * Copyright (C) <2011> Thibault Saunier 
+ *
+ * From bad/sys/vdpau/mpeg/mpegutil.c:
+ *   Copyright (C) <2007> Jan Schmidt 
+ *   Copyright (C) <2009> Carl-Anton Ingmarsson 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distribu

[PATCH v1 2/2] [media] st-delta: add mpeg2 support

2016-10-07 Thread Hugues Fruchet
Change-Id: Ic586e3b2c7c15e76ea9aff318f8580eb3493e21b
Signed-off-by: Hugues Fruchet 
---
 drivers/media/platform/Kconfig |6 +
 drivers/media/platform/sti/delta/Makefile  |3 +
 drivers/media/platform/sti/delta/delta-cfg.h   |5 +
 drivers/media/platform/sti/delta/delta-mpeg2-dec.c | 1412 
 drivers/media/platform/sti/delta/delta-mpeg2-fw.h  |  415 ++
 drivers/media/platform/sti/delta/delta-v4l2.c  |4 +
 6 files changed, 1845 insertions(+)
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-dec.c
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-fw.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 29d7dee..94a71bb 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -288,6 +288,12 @@ config VIDEO_STI_DELTA_MJPEG
help
Enables DELTA MJPEG hardware support.
 
+config VIDEO_STI_DELTA_MPEG2
+   bool "STMicroelectronics DELTA MPEG2/MPEG1 support"
+   default y
+   help
+   Enables DELTA MPEG2 hardware support.
+
 endif # VIDEO_STI_DELTA
 
 config VIDEO_SH_VEU
diff --git a/drivers/media/platform/sti/delta/Makefile 
b/drivers/media/platform/sti/delta/Makefile
index f95580e..e509bcb 100644
--- a/drivers/media/platform/sti/delta/Makefile
+++ b/drivers/media/platform/sti/delta/Makefile
@@ -4,3 +4,6 @@ st-delta-y := delta-v4l2.o delta-mem.o delta-ipc.o delta-debug.o
 # MJPEG support
 st-delta-$(CONFIG_VIDEO_STI_DELTA_MJPEG) += delta-mjpeg-hdr.o
 st-delta-$(CONFIG_VIDEO_STI_DELTA_MJPEG) += delta-mjpeg-dec.o
+
+# MPEG2 support
+st-delta-$(CONFIG_VIDEO_STI_DELTA_MPEG2) += delta-mpeg2-dec.o
diff --git a/drivers/media/platform/sti/delta/delta-cfg.h 
b/drivers/media/platform/sti/delta/delta-cfg.h
index cf30e50..9129e4d 100644
--- a/drivers/media/platform/sti/delta/delta-cfg.h
+++ b/drivers/media/platform/sti/delta/delta-cfg.h
@@ -59,4 +59,9 @@
 extern const struct delta_dec mjpegdec;
 #endif
 
+#ifdef CONFIG_VIDEO_STI_DELTA_MPEG2
+extern const struct delta_dec mpeg2dec;
+extern const struct delta_dec mpeg1dec;
+#endif
+
 #endif /* DELTA_CFG_H */
diff --git a/drivers/media/platform/sti/delta/delta-mpeg2-dec.c 
b/drivers/media/platform/sti/delta/delta-mpeg2-dec.c
new file mode 100644
index 000..7885b072
--- /dev/null
+++ b/drivers/media/platform/sti/delta/delta-mpeg2-dec.c
@@ -0,0 +1,1412 @@
+/*
+ * Copyright (C) STMicroelectronics SA 2015
+ * Authors: Hugues Fruchet 
+ *  Chetan Nanda 
+ *  Jean-Christophe Trotin 
+ *  for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include "delta.h"
+#include "delta-ipc.h"
+#include "delta-mem.h"
+#include "delta-mpeg2-fw.h"
+
+#define DELTA_MPEG2_MAX_RESO DELTA_MAX_RESO
+
+/* minimal number of frames for decoding = 1 dec + 2 refs frames */
+#define DELTA_MPEG2_DPB_FRAMES_NEEDED 3
+
+struct delta_mpeg2_ctx {
+   /* ipc */
+   void *ipc_hdl;
+   struct delta_buf *ipc_buf;
+
+   /* stream information */
+   struct delta_streaminfo streaminfo;
+
+   unsigned int header_parsed;
+
+   /* reference frames mgt */
+   struct delta_mpeg2_frame *prev_ref_frame;
+   struct delta_mpeg2_frame *next_ref_frame;
+
+   /* output frames reordering management */
+   struct delta_frame *out_frame;
+   struct delta_frame *delayed_frame;
+
+   /* interlaced frame management */
+   struct delta_frame *last_frame;
+   enum mpeg2_picture_structure_t accumulated_picture_structure;
+
+   unsigned char str[3000];
+};
+
+/* codec specific frame struct */
+struct delta_mpeg2_frame {
+   struct delta_frame frame;
+   struct timeval dts;
+   struct delta_buf omega_buf; /* 420mb buffer for decoding */
+};
+
+#define to_ctx(ctx) ((struct delta_mpeg2_ctx *)ctx->priv)
+#define to_mpeg2_frame(frame) ((struct delta_mpeg2_frame *)frame)
+#define to_frame(mpeg2_frame) ((struct delta_frame *)mpeg2_frame)
+
+static u8 default_intra_matrix[] = {
+   /* non-scan ordered */
+   0x08, 0x10, 0x13, 0x16, 0x1a, 0x1b, 0x1d, 0x22,
+   0x10, 0x10, 0x16, 0x18, 0x1b, 0x1d, 0x22, 0x25,
+   0x13, 0x16, 0x1a, 0x1b, 0x1d, 0x22, 0x22, 0x26,
+   0x16, 0x16, 0x1a, 0x1b, 0x1d, 0x22, 0x25, 0x28,
+   0x16, 0x1a, 0x1B, 0x1d, 0x20, 0x23, 0x28, 0x30,
+   0x1a, 0x1b, 0x1d, 0x20, 0x23, 0x28, 0x30, 0x3a,
+   0x1a, 0x1b, 0x1d, 0x22, 0x26, 0x2e, 0x38, 0x45,
+   0x1b, 0x1d, 0x23, 0x26, 0x2e, 0x38, 0x45, 0x53
+};
+
+static u8 default_non_intra_matrix[] = {
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+   0x10, 0x10,

[PATCH v1 1/3] add a libv4l plugin for st-delta video decoder

2016-10-07 Thread Hugues Fruchet
ST DELTA video decoder is a frame API based decoder
which requires headers metadata in addition to compressed
video bitstream data.
This libv4l plugin aims to abstract DELTA frame API under
usual stream API, so compatibility with existing V4L2-based
frameworks such as GStreamer is ensured.
To do so, S_FMT(OUTPUT) call is intercepted to detect the format
of video bitstream and so select the right parser to be used.
REQBUFS/QUERYBUF(OUTPUT) calls are intercepted in order to mmap each
buffer containing video bitstream to be parsed and associate to each
buffer a metadata space where to store the corresponding headers.
QBUF(OUTPUT) call is then intercepted to get the metadata headers
by parsing input buffer and send those metadata to V4L2 kernel
driver using V4L2 control & request API.

Change-Id: I524e1e4a5746c7a678a1cdbc5dac56af16f7c863
signed-off-by: Tiphaine Inguere 
Signed-off-by: Hugues Fruchet 
---
 configure.ac|   2 +
 lib/Makefile.am |   3 +-
 lib/libv4l-delta/Makefile.am|   9 +
 lib/libv4l-delta/libv4l-delta.c | 344 
 lib/libv4l-delta/libv4l-delta.h |  97 ++
 lib/libv4l-delta/libv4l-delta.pc.in |  12 ++
 6 files changed, 466 insertions(+), 1 deletion(-)
 create mode 100644 lib/libv4l-delta/Makefile.am
 create mode 100644 lib/libv4l-delta/libv4l-delta.c
 create mode 100644 lib/libv4l-delta/libv4l-delta.h
 create mode 100644 lib/libv4l-delta/libv4l-delta.pc.in

diff --git a/configure.ac b/configure.ac
index 84199a3..bb656fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,6 +18,7 @@ AC_CONFIG_FILES([Makefile
lib/libv4l2rds/Makefile
lib/libv4l-mplane/Makefile
lib/libv4l-hva/Makefile
+   lib/libv4l-delta/Makefile
 
utils/Makefile
utils/libv4l2util/Makefile
@@ -43,6 +44,7 @@ AC_CONFIG_FILES([Makefile
lib/libv4lconvert/libv4lconvert.pc
lib/libv4l1/libv4l1.pc
lib/libv4l2/libv4l2.pc
+   lib/libv4l-delta/libv4l-delta.pc
lib/libdvbv5/libdvbv5.pc
lib/libv4l2rds/libv4l2rds.pc
utils/media-ctl/libmediactl.pc
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 38914bb..cf5ce03 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,10 +3,11 @@ SUBDIRS = \
libv4l2 \
libv4l1 \
libv4l2rds \
+   libv4l-delta \
libv4l-mplane \
libv4l-hva
 
 if LINUX_OS
 SUBDIRS += \
libdvbv5
-endif
+endif
\ No newline at end of file
diff --git a/lib/libv4l-delta/Makefile.am b/lib/libv4l-delta/Makefile.am
new file mode 100644
index 000..0ec1dd7
--- /dev/null
+++ b/lib/libv4l-delta/Makefile.am
@@ -0,0 +1,9 @@
+if WITH_V4L_PLUGINS
+libv4l2plugin_LTLIBRARIES = libv4l-delta.la
+endif
+
+libv4l_delta_la_SOURCES = libv4l-delta.c libv4l-delta.h
+
+libv4l_delta_la_CPPFLAGS = $(CFLAG_VISIBILITY)
+libv4l_delta_la_LDFLAGS = -avoid-version -module -shared -export-dynamic 
-lpthread
+libv4l_delta_la_LIBADD = ../libv4l2/libv4l2.la
diff --git a/lib/libv4l-delta/libv4l-delta.c b/lib/libv4l-delta/libv4l-delta.c
new file mode 100644
index 000..aa33e94
--- /dev/null
+++ b/lib/libv4l-delta/libv4l-delta.c
@@ -0,0 +1,344 @@
+/*
+ * libv4l-delta.c
+ *
+ * Copyright (C) STMicroelectronics SA 2016
+ * Authors: Tifaine Inguere 
+ *  Hugues Fruchet 
+ *  for STMicroelectronics.
+ */
+
+/*
+ * (C) 2012 Mauro Carvalho Chehab
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../libv4lconvert/libv4lsyscall-priv.h"
+#include "libv4l-plugin.h"
+#include "libv4l-delta.h"
+
+#if HAVE_VISIBILITY
+#define PLUGIN_PUBLIC __attribute__ ((visibility("default")))
+#else
+#define PLUGIN_PUBLIC
+#endif
+
+
+#define type_to_str(type) ((type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ? "OUTPUT" : \
+   ((type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? "CAPTURE" : "?"))
+
+/* available metadata builders */
+const struct delta_metadata *delta_meta[] = {
+
+};
+
+static void *delta_plugin_init(int fd)
+{
+   struct delta_plugin *delta = NULL;
+   struct v4l2_capability cap;
+   int ret;
+
+   DELTA_LOG_DEBUG("> %s\n", __func__);
+
+   /* check if device needs delta plugin */
+   mems

[PATCH 26/26] digitv: handle error code on RC query

2016-10-07 Thread Mauro Carvalho Chehab
There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/digitv.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 09f8c28bd4db..4284f6984dc1 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -29,7 +29,9 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
struct digitv_state *st = d->priv;
-   int wo = (rbuf == NULL || rlen == 0); /* write-only */
+   int ret, wo;
+
+   wo = (rbuf == NULL || rlen == 0); /* write-only */
 
memset(st->sndbuf, 0, 7);
memset(st->rcvbuf, 0, 7);
@@ -40,12 +42,12 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
 
if (wo) {
memcpy(&st->sndbuf[3], wbuf, wlen);
-   dvb_usb_generic_write(d, st->sndbuf, 7);
+   ret = dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   ret = dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
memcpy(rbuf, &st->rcvbuf[3], rlen);
}
-   return 0;
+   return ret;
 }
 
 /* I2C */
-- 
2.7.4


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


[PATCH 10/26] dibusb: handle error code on RC query

2016-10-07 Thread Mauro Carvalho Chehab
There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dibusb-common.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 76b26dc7339c..36f958876383 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -355,6 +355,7 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
u8 *buf;
+   int ret;
 
buf = kmalloc(5, GFP_KERNEL);
if (!buf)
@@ -362,7 +363,9 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
 
-   dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
dvb_usb_nec_rc_key_to_event(d, buf, event, state);
 
@@ -371,6 +374,7 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
kfree(buf);
 
-   return 0;
+ret:
+   return ret;
 }
 EXPORT_SYMBOL(dibusb_rc_query);
-- 
2.7.4


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


[PATCH 05/26] cinergyT2-fe: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 45 
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index fd8edcb56e61..03ba66ef1f28 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,9 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+
+   unsigned char data[64];
+
struct dvbt_get_status_msg status;
 };
 
@@ -146,28 +149,28 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
enum fe_status *status)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg result;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
-   sizeof(result), 0);
+   state->data[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
+
+   ret = dvb_usb_generic_rw(state->d, state->data, 1,
+state->data, sizeof(state->status), 0);
if (ret < 0)
return ret;
 
-   state->status = result;
+   memcpy(&state->status, state->data, sizeof(state->status));
 
*status = 0;
 
-   if (0x - le16_to_cpu(result.gain) > 30)
+   if (0x - le16_to_cpu(state->status.gain) > 30)
*status |= FE_HAS_SIGNAL;
-   if (result.lock_bits & (1 << 6))
+   if (state->status.lock_bits & (1 << 6))
*status |= FE_HAS_LOCK;
-   if (result.lock_bits & (1 << 5))
+   if (state->status.lock_bits & (1 << 5))
*status |= FE_HAS_SYNC;
-   if (result.lock_bits & (1 << 4))
+   if (state->status.lock_bits & (1 << 4))
*status |= FE_HAS_CARRIER;
-   if (result.lock_bits & (1 << 1))
+   if (state->status.lock_bits & (1 << 1))
*status |= FE_HAS_VITERBI;
 
if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
@@ -232,31 +235,29 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend 
*fe)
 {
struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_set_parameters_msg param;
-   char result[2];
+   struct dvbt_set_parameters_msg *param = (void *)state->data;
int err;
 
-   param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
-   param.tps = cpu_to_le16(compute_tps(fep));
-   param.freq = cpu_to_le32(fep->frequency / 1000);
-   param.flags = 0;
+   param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
+   param->tps = cpu_to_le16(compute_tps(fep));
+   param->freq = cpu_to_le32(fep->frequency / 1000);
+   param->flags = 0;
 
switch (fep->bandwidth_hz) {
default:
case 800:
-   param.bandwidth = 8;
+   param->bandwidth = 8;
break;
case 700:
-   param.bandwidth = 7;
+   param->bandwidth = 7;
break;
case 600:
-   param.bandwidth = 6;
+   param->bandwidth = 6;
break;
}
 
-   err = dvb_usb_generic_rw(state->d,
-   (char *)¶m, sizeof(param),
-   result, sizeof(result), 0);
+   err = dvb_usb_generic_rw(state->d, state->data, sizeof(*param),
+state->data, 2, 0);
if (err < 0)
err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
 
-- 
2.7.4


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


[PATCH 11/26] digitv: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/digitv.c | 20 +++-
 drivers/media/usb/dvb-usb/digitv.h |  3 +++
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 63134335c994..09f8c28bd4db 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -28,20 +28,22 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
+   struct digitv_state *st = d->priv;
int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[7],rcvbuf[7];
-   memset(sndbuf,0,7); memset(rcvbuf,0,7);
 
-   sndbuf[0] = cmd;
-   sndbuf[1] = vv;
-   sndbuf[2] = wo ? wlen : rlen;
+   memset(st->sndbuf, 0, 7);
+   memset(st->rcvbuf, 0, 7);
+
+   st->sndbuf[0] = cmd;
+   st->sndbuf[1] = vv;
+   st->sndbuf[2] = wo ? wlen : rlen;
 
if (wo) {
-   memcpy(&sndbuf[3],wbuf,wlen);
-   dvb_usb_generic_write(d,sndbuf,7);
+   memcpy(&st->sndbuf[3], wbuf, wlen);
+   dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
-   memcpy(rbuf,&rcvbuf[3],rlen);
+   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   memcpy(rbuf, &st->rcvbuf[3], rlen);
}
return 0;
 }
diff --git a/drivers/media/usb/dvb-usb/digitv.h 
b/drivers/media/usb/dvb-usb/digitv.h
index 908c09f4966b..cf104689bdff 100644
--- a/drivers/media/usb/dvb-usb/digitv.h
+++ b/drivers/media/usb/dvb-usb/digitv.h
@@ -6,6 +6,9 @@
 
 struct digitv_state {
 int is_nxt6000;
+
+unsigned char sndbuf[7];
+unsigned char rcvbuf[7];
 };
 
 /* protocol (from usblogging and the SDK:
-- 
2.7.4


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


[PATCH 19/26] nova-t-usb2: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/nova-t-usb2.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index fc7569e2728d..26d7188a1163 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -74,22 +74,29 @@ static struct rc_map_table rc_map_haupp_table[] = {
  */
 static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
-   u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
+   u8 *buf, data, toggle, custom;
u16 raw;
int i;
struct dibusb_device_state *st = d->priv;
 
-   dvb_usb_generic_rw(d,cmd,2,key,5,0);
+   buf = kmalloc(5, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   buf[0] = DIBUSB_REQ_POLL_REMOTE;
+   buf[1] = 0x35;
+   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
 
*state = REMOTE_NO_KEY_PRESSED;
-   switch (key[0]) {
+   switch (buf[0]) {
case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
-   raw = ((key[1] << 8) | key[2]) >> 3;
+   raw = ((buf[1] << 8) | buf[2]) >> 3;
toggle = !!(raw & 0x800);
data = raw & 0x3f;
custom = (raw >> 6) & 0x1f;
 
-   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
+   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",
+  buf[1], buf[2], buf[3], custom, data, toggle);
 
for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
if (rc5_data(&rc_map_haupp_table[i]) == data &&
@@ -117,6 +124,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+   kfree(buf);
return 0;
 }
 
-- 
2.7.4


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


[PATCH 18/26] gp8psk: don't go past the buffer size

2016-10-07 Thread Mauro Carvalho Chehab
Add checks to avoid going out of the buffer.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/gp8psk.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index fa215ad37f7b..a745cf636846 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -60,6 +60,9 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
struct gp8psk_state *st = d->priv;
int ret = 0,try = 0;
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
return ret;
 
@@ -98,6 +101,9 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 
value,
deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
debug_dump(b,blen,deb_xfer);
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
return ret;
 
@@ -151,6 +157,11 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
err("failed to load bcm4500 firmware.");
goto out_free;
}
+   if (buflen > 64) {
+   err("firmare chunk size bigger than 64 bytes.");
+   goto out_free;
+   }
+
memcpy(buf, ptr, buflen);
if (dvb_usb_generic_write(d, buf, buflen)) {
err("failed to load bcm4500 firmware.");
-- 
2.7.4


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


[PATCH 25/26] dw2102: return error if su3000_power_ctrl() fails

2016-10-07 Thread Mauro Carvalho Chehab
Instead of silently ignoring the error, return it.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dw2102.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 5fb0c650926e..2c720cb2fb00 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -852,7 +852,7 @@ static int su3000_power_ctrl(struct dvb_usb_device *d, int 
i)
if (i && !state->initialized) {
state->initialized = 1;
/* reset board */
-   dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
+   return dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
}
 
return 0;
-- 
2.7.4


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


[PATCH 00/26] Don't use stack for DMA transers on dvb-usb drivers

2016-10-07 Thread Mauro Carvalho Chehab
Sending URB control messages from stack was never supported. Yet, on x86,
the stack was usually at a memory region that allows DMA transfer.

So, several drivers got it wrong. On Kernel 4.9, if VMAP_STACK=y, none of
those drivers will work, as the stack won't be on a DMA-able area anymore.

So, fix the dvb-usb drivers that requre it.

Please notice that, while all those patches compile, I don't have devices
using those drivers to test. So, I really appreciate if people with devices
using those drivers could test and report if they don't break anything.

Thanks!
Mauro

Mauro Carvalho Chehab (26):
  af9005: don't do DMA on stack
  cinergyT2-core: don't do DMA on stack
  cinergyT2-core:: handle error code on RC query
  cinergyT2-fe: cache stats at cinergyt2_fe_read_status()
  cinergyT2-fe: don't do DMA on stack
  cxusb: don't do DMA on stack
  dib0700: be sure that dib0700_ctrl_rd() users can do DMA
  dib0700_core: don't use stack on I2C reads
  dibusb: don't do DMA on stack
  dibusb: handle error code on RC query
  digitv: don't do DMA on stack
  dtt200u-fe: don't do DMA on stack
  dtt200u-fe: handle errors on USB control messages
  dtt200u: don't do DMA on stack
  dtt200u: handle USB control message errors
  dtv5100: : don't do DMA on stack
  gp8psk: don't do DMA on stack
  gp8psk: don't go past the buffer size
  nova-t-usb2: don't do DMA on stack
  pctv452e: don't do DMA on stack
  pctv452e: don't call BUG_ON() on non-fatal error
  technisat-usb2: use DMA buffers for I2C transfers
  dvb-usb: warn if return value for USB read/write routines is not
checked
  nova-t-usb2: handle error code on RC query
  dw2102: return error if su3000_power_ctrl() fails
  digitv: handle error code on RC query

 drivers/media/usb/dvb-usb/af9005.c  | 211 +++-
 drivers/media/usb/dvb-usb/cinergyT2-core.c  |  52 ---
 drivers/media/usb/dvb-usb/cinergyT2-fe.c|  91 
 drivers/media/usb/dvb-usb/cxusb.c   |  20 +--
 drivers/media/usb/dvb-usb/cxusb.h   |   5 +
 drivers/media/usb/dvb-usb/dib0700_core.c|  31 +++-
 drivers/media/usb/dvb-usb/dib0700_devices.c |  25 ++--
 drivers/media/usb/dvb-usb/dibusb-common.c   | 112 +++
 drivers/media/usb/dvb-usb/dibusb.h  |   5 +
 drivers/media/usb/dvb-usb/digitv.c  |  26 ++--
 drivers/media/usb/dvb-usb/digitv.h  |   3 +
 drivers/media/usb/dvb-usb/dtt200u-fe.c  |  90 
 drivers/media/usb/dvb-usb/dtt200u.c |  80 +++
 drivers/media/usb/dvb-usb/dtv5100.c |  10 +-
 drivers/media/usb/dvb-usb/dvb-usb.h |   6 +-
 drivers/media/usb/dvb-usb/dw2102.c  |   2 +-
 drivers/media/usb/dvb-usb/gp8psk.c  |  25 +++-
 drivers/media/usb/dvb-usb/nova-t-usb2.c |  25 +++-
 drivers/media/usb/dvb-usb/pctv452e.c| 118 
 drivers/media/usb/dvb-usb/technisat-usb2.c  |  16 ++-
 20 files changed, 577 insertions(+), 376 deletions(-)

-- 
2.7.4


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


[PATCH 13/26] dtt200u-fe: handle errors on USB control messages

2016-10-07 Thread Mauro Carvalho Chehab
If something goes wrong, return an error code, instead of
assuming that everything went fine.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dtt200u-fe.c | 38 +++---
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 9ed68429e950..ede6e1bc7315 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -26,10 +26,15 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
state->data[0] = GET_TUNE_STATUS;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret < 0) {
+   *stat = 0;
+   return ret;
+   }
 
switch (state->data[0]) {
case 0x01:
@@ -50,10 +55,14 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
state->data[0] = GET_VIT_ERR_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret < 0)
+   return ret;
+
*ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
return 0;
 }
@@ -61,10 +70,13 @@ static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 
*ber)
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
state->data[0] = GET_RS_UNCOR_BLK_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   if (ret < 0)
+   return ret;
 
*unc = (state->data[0] << 8) | state->data[1];
return 0;
@@ -73,10 +85,13 @@ static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* 
fe, u32 *unc)
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
state->data[0] = GET_AGC;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret < 0)
+   return ret;
 
*strength = (state->data[0] << 8) | state->data[0];
return 0;
@@ -85,10 +100,13 @@ static int dtt200u_fe_read_signal_strength(struct 
dvb_frontend* fe, u16 *strengt
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
state->data[0] = GET_SNR;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret < 0)
+   return ret;
 
*snr = ~((state->data[0] << 8) | state->data[0]);
return 0;
@@ -120,7 +138,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
 {
struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   int i;
+   int i, ret;
enum fe_status st;
u16 freq = fep->frequency / 25;
 
@@ -139,12 +157,16 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
return -EINVAL;
}
 
-   dvb_usb_generic_write(state->d, state->data, 2);
+   ret = dvb_usb_generic_write(state->d, state->data, 2);
+   if (ret < 0)
+   return ret;
 
state->data[0] = SET_RF_FREQ;
state->data[1] = freq & 0xff;
state->data[2] = (freq >> 8) & 0xff;
-   dvb_usb_generic_write(state->d, state->data, 3);
+   ret = dvb_usb_generic_write(state->d, state->data, 3);
+   if (ret < 0)
+   return ret;
 
for (i = 0; i < 30; i++) {
msleep(20);
-- 
2.7.4


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


[PATCH 03/26] cinergyT2-core:: handle error code on RC query

2016-10-07 Thread Mauro Carvalho Chehab
There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cinergyT2-core.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index 91640c927776..c9633f5dd482 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -89,7 +89,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter 
*adap)
/* Copy this pointer as we are gonna need it in the release phase */
cinergyt2_usb_device = adap->dev;
 
-   return 0;
+   return ret;
 }
 
 static struct rc_map_table rc_map_cinergyt2_table[] = {
@@ -149,13 +149,16 @@ static int repeatable_keys[] = {
 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
struct cinergyt2_state *st = d->priv;
-   int i;
+   int i, ret;
 
*state = REMOTE_NO_KEY_PRESSED;
 
st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
 
-   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (ret < 0)
+   return ret;
+
if (st->data[4] == 0xff) {
/* key repeat */
st->rc_counter++;
-- 
2.7.4


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


[PATCH 02/26] cinergyT2-core: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cinergyT2-core.c | 45 ++
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index 9fd1527494eb..91640c927776 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -41,6 +41,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 struct cinergyt2_state {
u8 rc_counter;
+   unsigned char data[64];
 };
 
 /* We are missing a release hook with usb_device data */
@@ -50,29 +51,36 @@ static struct dvb_usb_device_properties 
cinergyt2_properties;
 
 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
-   char result[64];
-   return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
-   sizeof(result), 0);
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
+
+   st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
+   st->data[1] = enable ? 1 : 0;
+
+   return dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
 }
 
 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
-   char state[3];
-   return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
+   struct cinergyt2_state *st = d->priv;
+
+   st->data[0] = CINERGYT2_EP1_SLEEP_MODE;
+   st->data[1] = enable ? 0 : 1;
+
+   return dvb_usb_generic_rw(d, st->data, 2, st->data, 3, 0);
 }
 
 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
 {
-   char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
-   char state[3];
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
int ret;
 
adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
 
-   ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
-   sizeof(state), 0);
+   st->data[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
+
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0);
if (ret < 0) {
deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
"state info\n");
@@ -141,13 +149,14 @@ static int repeatable_keys[] = {
 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
struct cinergyt2_state *st = d->priv;
-   u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
int i;
 
*state = REMOTE_NO_KEY_PRESSED;
 
-   dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
-   if (key[4] == 0xff) {
+   st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (st->data[4] == 0xff) {
/* key repeat */
st->rc_counter++;
if (st->rc_counter > RC_REPEAT_DELAY) {
@@ -166,13 +175,13 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, 
u32 *event, int *state)
}
 
/* hack to pass checksum on the custom field */
-   key[2] = ~key[1];
-   dvb_usb_nec_rc_key_to_event(d, key, event, state);
-   if (key[0] != 0) {
+   st->data[2] = ~st->data[1];
+   dvb_usb_nec_rc_key_to_event(d, st->data, event, state);
+   if (st->data[0] != 0) {
if (*event != d->last_event)
st->rc_counter = 0;
 
-   deb_rc("key: %*ph\n", 5, key);
+   deb_rc("key: %*ph\n", 5, st->data);
}
return 0;
 }
-- 
2.7.4


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


[PATCH 20/26] pctv452e: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/pctv452e.c | 110 ++-
 1 file changed, 58 insertions(+), 52 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index c05de1b088a4..855fe9d34b59 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -97,13 +97,14 @@ struct pctv452e_state {
u8 c;  /* transaction counter, wraps around...  */
u8 initialized; /* set to 1 if 0x15 has been sent */
u16 last_rc_key;
+
+   unsigned char data[80];
 };
 
 static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
 unsigned int write_len, unsigned int read_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
unsigned int rlen;
int ret;
@@ -114,30 +115,30 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 
cmd, u8 *data,
 
id = state->c++;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = cmd;
-   buf[3] = write_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = cmd;
+   state->data[3] = write_len;
 
-   memcpy(buf + 4, data, write_len);
+   memcpy(state->data + 4, data, write_len);
 
rlen = (read_len > 0) ? 64 : 0;
-   ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
- buf, rlen, /* delay_ms */ 0);
+   ret = dvb_usb_generic_rw(d, state->data, 4 + write_len,
+ state->data, rlen, /* delay_ms */ 0);
if (0 != ret)
goto failed;
 
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
-   memcpy(data, buf + 4, read_len);
+   memcpy(data, state->data + 4, read_len);
 
return 0;
 
 failed:
err("CI error %d; %02X %02X %02X -> %*ph.",
-ret, SYNC_BYTE_OUT, id, cmd, 3, buf);
+ret, SYNC_BYTE_OUT, id, cmd, 3, state->data);
 
return ret;
 }
@@ -405,7 +406,6 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 
addr,
u8 *rcv_buf, u8 rcv_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
int ret;
 
@@ -415,42 +415,40 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 
addr,
if (snd_len > 64 - 7 || rcv_len > 64 - 7)
goto failed;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = PCTV_CMD_I2C;
-   buf[3] = snd_len + 3;
-   buf[4] = addr << 1;
-   buf[5] = snd_len;
-   buf[6] = rcv_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = PCTV_CMD_I2C;
+   state->data[3] = snd_len + 3;
+   state->data[4] = addr << 1;
+   state->data[5] = snd_len;
+   state->data[6] = rcv_len;
 
-   memcpy(buf + 7, snd_buf, snd_len);
+   memcpy(state->data + 7, snd_buf, snd_len);
 
-   ret = dvb_usb_generic_rw(d, buf, 7 + snd_len,
- buf, /* rcv_len */ 64,
+   ret = dvb_usb_generic_rw(d, state->data, 7 + snd_len,
+ state->data, /* rcv_len */ 64,
  /* delay_ms */ 0);
if (ret < 0)
goto failed;
 
/* TT USB protocol error. */
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
/* I2C device didn't respond as expected. */
ret = -EREMOTEIO;
-   if (buf[5] < snd_len || buf[6] < rcv_len)
+   if (state->data[5] < snd_len || state->data[6] < rcv_len)
goto failed;
 
-   memcpy(rcv_buf, buf + 7, rcv_len);
+   memcpy(rcv_buf, state->data + 7, rcv_len);
 
return rcv_len;
 
 failed:
-   err("I2C error %d; %02X %02X  %02X %02X %02X -> "
-"%02X %02X  %02X %02X %02X.",
+   err("I2C error %d; %02X %02X  %02X %02X %02X -> %*ph",
 ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len,
-buf[0], buf[1], buf[4], buf[5], buf[6]);
-
+7, state->data);
return ret;
 }
 
@@ -499,8 +497,7 @@ static u32 pctv452e_i2c_func(struct i2c_adapter *adapter)
 static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 b0[] = { 0xaa, 0, PCTV_CMD_RESET, 1, 0 };
-   u8 rx[PCTV_ANSWER_LEN];
+   u8 *rx;
int ret;
 
info("%s: %d\n", __func__, i);
@@ -511,6 +508,10 @@ static i

Re: [PATCH v2] cinergyT2-core: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
Em Fri, 7 Oct 2016 15:50:40 +0200
Jörg Otte  escreveu:

> 2016-10-06 20:29 GMT+02:00 Mauro Carvalho Chehab :
> > Em Thu, 6 Oct 2016 10:27:56 -0700
> > Andy Lutomirski  escreveu:
> >  
 
> Patch works for me!
> Thanks, Jörg

Thanks for testing!

I just sent a 26 patch series to address this issue. There are 4 patches
on it that affects cinergyT2 (one is this patch, but the other ones
should be addressing other problems there).

Could you please test them, and if they're ok, reply to me with a
Tested-by: tag?

PS.: I'm also putting those patches on my development tree, at:
git://git.linuxtv.org/mchehab/experimental.git media_dmastack_fixes

(please notice that my tree is based on Kernel 4.8 - so, to test with
VMAP_STACK, you'll likely need to pull also from Linus tree)

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


[PATCH 04/26] cinergyT2-fe: cache stats at cinergyt2_fe_read_status()

2016-10-07 Thread Mauro Carvalho Chehab
Instead of sending USB commands for every stats call, collect
them once, when status is updated. As the frontend kthread
will call it on every few seconds, the stats will still be
collected.

Besides reducing the amount of USB/I2C transfers, this also
warrants that all stats will be collected at the same time,
and makes easier to convert it to DVBv5 stats in the future.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 48 +---
 1 file changed, 7 insertions(+), 41 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index b3ec743a7a2e..fd8edcb56e61 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,7 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+   struct dvbt_get_status_msg status;
 };
 
 static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
@@ -154,6 +155,8 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
if (ret < 0)
return ret;
 
+   state->status = result;
+
*status = 0;
 
if (0x - le16_to_cpu(result.gain) > 30)
@@ -177,34 +180,16 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
-   sizeof(status), 0);
-   if (ret < 0)
-   return ret;
-
-   *ber = le32_to_cpu(status.viterbi_error_rate);
+   *ber = le32_to_cpu(state->status.viterbi_error_rate);
return 0;
 }
 
 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
-   ret);
-   return ret;
-   }
-   *unc = le32_to_cpu(status.uncorrected_block_count);
+   *unc = le32_to_cpu(state->status.uncorrected_block_count);
return 0;
 }
 
@@ -212,35 +197,16 @@ static int cinergyt2_fe_read_signal_strength(struct 
dvb_frontend *fe,
u16 *strength)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_signal_strength() Failed!"
-   " (Error=%d)\n", ret);
-   return ret;
-   }
-   *strength = (0x - le16_to_cpu(status.gain));
+   *strength = (0x - le16_to_cpu(state->status.gain));
return 0;
 }
 
 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
-   return ret;
-   }
-   *snr = (status.snr << 8) | status.snr;
+   *snr = (state->status.snr << 8) | state->status.snr;
return 0;
 }
 
-- 
2.7.4


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


[PATCH 24/26] nova-t-usb2: handle error code on RC query

2016-10-07 Thread Mauro Carvalho Chehab
There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/nova-t-usb2.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index 26d7188a1163..1babd3341910 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -76,7 +76,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 {
u8 *buf, data, toggle, custom;
u16 raw;
-   int i;
+   int i, ret;
struct dibusb_device_state *st = d->priv;
 
buf = kmalloc(5, GFP_KERNEL);
@@ -85,7 +85,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
buf[1] = 0x35;
-   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
*state = REMOTE_NO_KEY_PRESSED;
switch (buf[0]) {
@@ -124,8 +126,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+ret:
kfree(buf);
-   return 0;
+   return ret;
 }
 
 static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
-- 
2.7.4


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


[PATCH 14/26] dtt200u: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dtt200u.c | 73 +
 1 file changed, 49 insertions(+), 24 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index d2a01b50af0d..d6023fb6a1d4 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -20,73 +20,88 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 
(or-able))." DVB_USB
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtt200u_state {
+   unsigned char data[80];
+};
+
 static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-   u8 b = SET_INIT;
+   struct dtt200u_state *st = d->priv;
+
+   st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d,&b,2);
+   dvb_usb_generic_write(d, st->data, 2);
 
return 0;
 }
 
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-   u8 b_streaming[2] = { SET_STREAMING, onoff };
-   u8 b_rst_pid = RESET_PID_FILTER;
+   struct dtt200u_state *st = adap->dev->priv;
 
-   dvb_usb_generic_write(adap->dev, b_streaming, 2);
+   st->data[0] = SET_STREAMING;
+   st->data[1] = onoff;
+
+   dvb_usb_generic_write(adap->dev, st->data, 2);
+
+   if (onoff)
+   return 0;
+
+   st->data[0] = RESET_PID_FILTER;
+   dvb_usb_generic_write(adap->dev, st->data, 1);
 
-   if (onoff == 0)
-   dvb_usb_generic_write(adap->dev, &b_rst_pid, 1);
return 0;
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
 {
-   u8 b_pid[4];
+   struct dtt200u_state *st = adap->dev->priv;
+
pid = onoff ? pid : 0;
 
-   b_pid[0] = SET_PID_FILTER;
-   b_pid[1] = index;
-   b_pid[2] = pid & 0xff;
-   b_pid[3] = (pid >> 8) & 0x1f;
+   st->data[0] = SET_PID_FILTER;
+   st->data[1] = index;
+   st->data[2] = pid & 0xff;
+   st->data[3] = (pid >> 8) & 0x1f;
 
-   return dvb_usb_generic_write(adap->dev, b_pid, 4);
+   return dvb_usb_generic_write(adap->dev, st->data, 4);
 }
 
 static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
-   u8 key[5],cmd = GET_RC_CODE;
+   struct dtt200u_state *st = d->priv;
u32 scancode;
 
-   dvb_usb_generic_rw(d,&cmd,1,key,5,0);
-   if (key[0] == 1) {
+   st->data[0] = GET_RC_CODE;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
-   scancode = key[1];
-   if ((u8) ~key[1] != key[2]) {
+   scancode = st->data[1];
+   if ((u8) ~st->data[1] != st->data[2]) {
/* Extended NEC */
scancode = scancode << 8;
-   scancode |= key[2];
+   scancode |= st->data[2];
proto = RC_TYPE_NECX;
}
scancode = scancode << 8;
-   scancode |= key[3];
+   scancode |= st->data[3];
 
/* Check command checksum is ok */
-   if ((u8) ~key[3] == key[4])
+   if ((u8) ~st->data[3] == st->data[4])
rc_keydown(d->rc_dev, proto, scancode, 0);
else
rc_keyup(d->rc_dev);
-   } else if (key[0] == 2) {
+   } else if (st->data[0] == 2) {
rc_repeat(d->rc_dev);
} else {
rc_keyup(d->rc_dev);
}
 
-   if (key[0] != 0)
-   deb_info("key: %*ph\n", 5, key);
+   if (st->data[0] != 0)
+   deb_info("st->data: %*ph\n", 5, st->data);
 
return 0;
 }
@@ -140,6 +155,8 @@ static struct dvb_usb_device_properties dtt200u_properties 
= {
.usb_ctrl = CYPRESS_FX2,
.firmware = "dvb-usb-dtt200u-01.fw",
 
+   .size_of_priv = sizeof(struct dtt200u_state),
+
.num_adapters = 1,
.adapter = {
{
@@ -190,6 +207,8 @@ static struct dvb_usb_device_properties wt220u_properties = 
{
.usb_ctrl = CYPRESS_FX2,
.firmware = "dvb-usb-wt220u-02.fw",
 
+   .size_of_priv = sizeof(struct dtt200u_state),
+
.num_adapters = 1,
.adapter = {
{
@@ -240,6 +259,8 @@ static struct dvb_usb_device_properties 
wt220u_fc_properties = {
.usb_ctrl = CYPRESS_FX2,
.firmware = "dvb-usb-wt220u-fc03.fw",
 
+   .size_of_priv = sizeof(struct dtt200u_state),
+
.num_adapters = 1,
.adapter = {
{
@@ -290,6 +311,8 @@ static struct dvb_usb_device_properties 
wt220u_zl0353_properties = {
.

[PATCH 12/26] dtt200u-fe: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dtt200u-fe.c | 66 +-
 1 file changed, 41 insertions(+), 25 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index c09332bd99cb..9ed68429e950 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -18,17 +18,20 @@ struct dtt200u_fe_state {
 
struct dtv_frontend_properties fep;
struct dvb_frontend frontend;
+
+   unsigned char data[80];
 };
 
 static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 st = GET_TUNE_STATUS, b[3];
 
-   dvb_usb_generic_rw(state->d,&st,1,b,3,0);
+   state->data[0] = GET_TUNE_STATUS;
 
-   switch (b[0]) {
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+
+   switch (state->data[0]) {
case 0x01:
*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
@@ -47,45 +50,57 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_VIT_ERR_CNT,b[3];
-   dvb_usb_generic_rw(state->d,&bw,1,b,3,0);
-   *ber = (b[0] << 16) | (b[1] << 8) | b[2];
+
+   state->data[0] = GET_VIT_ERR_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
return 0;
 }
 
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_RS_UNCOR_BLK_CNT,b[2];
 
-   dvb_usb_generic_rw(state->d,&bw,1,b,2,0);
-   *unc = (b[0] << 8) | b[1];
+   state->data[0] = GET_RS_UNCOR_BLK_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+
+   *unc = (state->data[0] << 8) | state->data[1];
return 0;
 }
 
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_AGC, b;
-   dvb_usb_generic_rw(state->d,&bw,1,&b,1,0);
-   *strength = (b << 8) | b;
+
+   state->data[0] = GET_AGC;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   *strength = (state->data[0] << 8) | state->data[0];
return 0;
 }
 
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_SNR,br;
-   dvb_usb_generic_rw(state->d,&bw,1,&br,1,0);
-   *snr = ~((br << 8) | br);
+
+   state->data[0] = GET_SNR;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   *snr = ~((state->data[0] << 8) | state->data[0]);
return 0;
 }
 
 static int dtt200u_fe_init(struct dvb_frontend* fe)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 b = SET_INIT;
-   return dvb_usb_generic_write(state->d,&b,1);
+
+   state->data[0] = SET_INIT;
+
+   return dvb_usb_generic_write(state->d, state->data, 1);
 }
 
 static int dtt200u_fe_sleep(struct dvb_frontend* fe)
@@ -108,27 +123,28 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
int i;
enum fe_status st;
u16 freq = fep->frequency / 25;
-   u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
 
+   state->data[0] = SET_BANDWIDTH;
switch (fep->bandwidth_hz) {
case 800:
-   bwbuf[1] = 8;
+   state->data[1] = 8;
break;
case 700:
-   bwbuf[1] = 7;
+   state->data[1] = 7;
break;
case 600:
-   bwbuf[1] = 6;
+   state->data[1] = 6;
break;
default:
return -EINVAL;
}
 
-   dvb_usb_generic_write(state->d,bwbuf,2);
+   dvb_usb_generic_write(state->d, state->data, 2);
 
-   freqbuf[1] = freq & 0xff;
-   freqbuf[2] = (freq >> 8) & 0xff;
-   dvb_usb_generic_write(state->d,freqbuf,3);
+   state->data[0] = SET_RF_FREQ;
+   state->data[1] = freq & 0xff;
+   state->data[2] = (freq >> 8) & 0xff;
+   dvb_usb_generic_write(state->d, state->data, 3);
 
for (i = 0; i < 30; i++) {
msleep(20);
-- 
2.7.4


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

[PATCH 08/26] dib0700_core: don't use stack on I2C reads

2016-10-07 Thread Mauro Carvalho Chehab
Be sure that I2C reads won't use stack by passing
a pointer to the state buffer, that we know it was
allocated via kmalloc, instead of relying on the buffer
allocated by an I2C client.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dib0700_core.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index 515f89dba199..92d5408684ac 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -213,7 +213,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
 usb_rcvctrlpipe(d->udev, 0),
 REQUEST_NEW_I2C_READ,
 USB_TYPE_VENDOR | USB_DIR_IN,
-value, index, msg[i].buf,
+value, index, st->buf,
 msg[i].len,
 USB_CTRL_GET_TIMEOUT);
if (result < 0) {
@@ -221,6 +221,14 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
break;
}
 
+   if (msg[i].len > sizeof(st->buf)) {
+   deb_info("buffer too small to fit %d bytes\n",
+msg[i].len);
+   return -EIO;
+   }
+
+   memcpy(msg[i].buf, st->buf, msg[i].len);
+
deb_data("<<< ");
debug_dump(msg[i].buf, msg[i].len, deb_data);
 
@@ -238,6 +246,13 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
/* I2C ctrl + FE bus; */
st->buf[3] = ((gen_mode << 6) & 0xC0) |
 ((bus_mode << 4) & 0x30);
+
+   if (msg[i].len > sizeof(st->buf) - 4) {
+   deb_info("i2c message to big: %d\n",
+msg[i].len);
+   return -EIO;
+   }
+
/* The Actual i2c payload */
memcpy(&st->buf[4], msg[i].buf, msg[i].len);
 
@@ -283,6 +298,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
/* fill in the address */
st->buf[1] = msg[i].addr << 1;
/* fill the buffer */
+   if (msg[i].len > sizeof(st->buf) - 2) {
+   deb_info("i2c xfer to big: %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(&st->buf[2], msg[i].buf, msg[i].len);
 
/* write/read request */
@@ -299,6 +319,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
break;
}
 
+   if (msg[i + 1].len > sizeof(st->buf)) {
+   deb_info("i2c xfer buffer to small for %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
 
msg[i+1].len = len;
-- 
2.7.4


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


[PATCH 15/26] dtt200u: handle USB control message errors

2016-10-07 Thread Mauro Carvalho Chehab
If something bad happens while an USB control message is
transfered, return an error code.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dtt200u.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index d6023fb6a1d4..ca8965b8b610 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -31,7 +31,7 @@ static int dtt200u_power_ctrl(struct dvb_usb_device *d, int 
onoff)
st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d, st->data, 2);
+   return dvb_usb_generic_write(d, st->data, 2);
 
return 0;
 }
@@ -39,19 +39,20 @@ static int dtt200u_power_ctrl(struct dvb_usb_device *d, int 
onoff)
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
struct dtt200u_state *st = adap->dev->priv;
+   int ret;
 
st->data[0] = SET_STREAMING;
st->data[1] = onoff;
 
-   dvb_usb_generic_write(adap->dev, st->data, 2);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 2);
+   if (ret < 0)
+   return ret;
 
if (onoff)
return 0;
 
st->data[0] = RESET_PID_FILTER;
-   dvb_usb_generic_write(adap->dev, st->data, 1);
-
-   return 0;
+   return dvb_usb_generic_write(adap->dev, st->data, 1);
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
@@ -72,10 +73,14 @@ static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
struct dtt200u_state *st = d->priv;
u32 scancode;
+   int ret;
 
st->data[0] = GET_RC_CODE;
 
-   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (ret < 0)
+   return ret;
+
if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
-- 
2.7.4


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


[PATCH 16/26] dtv5100: : don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dtv5100.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtv5100.c 
b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d11df41cac0..c60fb54f445f 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -31,9 +31,14 @@ module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtv5100_state {
+   unsigned char data[80];
+};
+
 static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
   u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
 {
+   struct dtv5100_state *st = d->priv;
u8 request;
u8 type;
u16 value;
@@ -60,9 +65,10 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
}
index = (addr << 8) + wbuf[0];
 
+   memcpy(st->data, rbuf, rlen);
msleep(1); /* avoid I2C errors */
return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
-  type, value, index, rbuf, rlen,
+  type, value, index, st->data, rlen,
   DTV5100_USB_TIMEOUT);
 }
 
@@ -176,7 +182,7 @@ static struct dvb_usb_device_properties dtv5100_properties 
= {
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
.usb_ctrl = DEVICE_SPECIFIC,
 
-   .size_of_priv = 0,
+   .size_of_priv = sizeof(struct dtv5100_state),
 
.num_adapters = 1,
.adapter = {{
-- 
2.7.4


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


[PATCH 21/26] pctv452e: don't call BUG_ON() on non-fatal error

2016-10-07 Thread Mauro Carvalho Chehab
There are some conditions on this driver that are tested with
BUG_ON() with are not serious enough to hang a machine.

So, just return an error if this happens.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/pctv452e.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index 855fe9d34b59..14bd927c50d8 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -109,9 +109,11 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, 
u8 *data,
unsigned int rlen;
int ret;
 
-   BUG_ON(NULL == data && 0 != (write_len | read_len));
-   BUG_ON(write_len > 64 - 4);
-   BUG_ON(read_len > 64 - 4);
+   if (NULL == data && 0 != (write_len | read_len) ||
+   write_len > 64 - 4) || (read_len > 64 - 4)) {
+   ret = -EIO;
+   goto failed;
+   };
 
id = state->c++;
 
-- 
2.7.4


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


[PATCH 09/26] dibusb: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dibusb-common.c | 106 +-
 drivers/media/usb/dvb-usb/dibusb.h|   5 ++
 2 files changed, 81 insertions(+), 30 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 4b08c2a47ae2..76b26dc7339c 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -12,9 +12,6 @@
 #include 
 #include "dibusb.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  64
-
 static int debug;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." 
DVB_USB_DEBUG_STATUS);
@@ -63,72 +60,109 @@ EXPORT_SYMBOL(dibusb_pid_filter_ctrl);
 
 int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-   u8 b[3];
+   u8 *b;
int ret;
+
+   b = kmalloc(3, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
+
b[0] = DIBUSB_REQ_SET_IOCTL;
b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP : DIBUSB_IOCTL_POWER_SLEEP;
-   ret = dvb_usb_generic_write(d,b,3);
+
+   ret = dvb_usb_generic_write(d, b, 3);
+
+   kfree(b);
+
msleep(10);
+
return ret;
 }
 EXPORT_SYMBOL(dibusb_power_ctrl);
 
 int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-   u8 b[3] = { 0 };
+   struct dibusb_state *st = adap->priv;
int ret;
 
if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
return ret;
 
if (onoff) {
-   b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
-   b[1] = 0x00;
-   if ((ret = dvb_usb_generic_write(adap->dev,b,2)) < 0)
+   st->data[0] = DIBUSB_REQ_SET_STREAMING_MODE;
+   st->data[1] = 0x00;
+   ret = dvb_usb_generic_write(adap->dev, st->data, 2);
+   if (ret  < 0)
return ret;
}
 
-   b[0] = DIBUSB_REQ_SET_IOCTL;
-   b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : 
DIBUSB_IOCTL_CMD_DISABLE_STREAM;
-   return dvb_usb_generic_write(adap->dev,b,3);
+   st->data[0] = DIBUSB_REQ_SET_IOCTL;
+   st->data[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : 
DIBUSB_IOCTL_CMD_DISABLE_STREAM;
+   return dvb_usb_generic_write(adap->dev, st->data, 3);
 }
 EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
 
 int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-   if (onoff) {
-   u8 b[3] = { DIBUSB_REQ_SET_IOCTL, DIBUSB_IOCTL_CMD_POWER_MODE, 
DIBUSB_IOCTL_POWER_WAKEUP };
-   return dvb_usb_generic_write(d,b,3);
-   } else
+   u8 *b;
+   int ret;
+
+   if (!onoff)
return 0;
+
+   b = kmalloc(3, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
+
+   b[0] = DIBUSB_REQ_SET_IOCTL;
+   b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
+   b[2] = DIBUSB_IOCTL_POWER_WAKEUP;
+
+   ret = dvb_usb_generic_write(d, b, 3);
+
+   kfree(b);
+
+   return ret;
 }
 EXPORT_SYMBOL(dibusb2_0_power_ctrl);
 
 static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
  u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
 {
-   u8 sndbuf[MAX_XFER_SIZE]; /* lead(1) devaddr,direction(1) addr(2) 
data(wlen) (len(2) (when reading)) */
+   u8 *sndbuf;
+   int ret, wo, len;
+
/* write only ? */
-   int wo = (rbuf == NULL || rlen == 0),
-   len = 2 + wlen + (wo ? 0 : 2);
+   wo = (rbuf == NULL || rlen == 0);
 
-   if (4 + wlen > sizeof(sndbuf)) {
+   len = 2 + wlen + (wo ? 0 : 2);
+
+   sndbuf = kmalloc(MAX_XFER_SIZE, GFP_KERNEL);
+   if (!sndbuf)
+   return -ENOMEM;
+
+   if (4 + wlen > MAX_XFER_SIZE) {
warn("i2c wr: len=%d is too big!\n", wlen);
-   return -EOPNOTSUPP;
+   ret = -EOPNOTSUPP;
+   goto ret;
}
 
sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
 
-   memcpy(&sndbuf[2],wbuf,wlen);
+   memcpy(&sndbuf[2], wbuf, wlen);
 
if (!wo) {
-   sndbuf[wlen+2] = (rlen >> 8) & 0xff;
-   sndbuf[wlen+3] = rlen & 0xff;
+   sndbuf[wlen + 2] = (rlen >> 8) & 0xff;
+   sndbuf[wlen + 3] = rlen & 0xff;
}
 
-   return dvb_usb_generic_rw(d,sndbuf,len,rbuf,rlen,0);
+   ret = dvb_usb_generic_rw(d, sndbuf, len, rbuf, rlen, 0);
+
+ret:
+   kfree(sndbuf);
+   return ret;
 }
 
 /*
@@ -320,11 +354,23 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
 
 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
-   u8 key[5],cmd = DIBUSB_REQ_POLL_REMOTE;
-   dvb_usb_generic_rw(d,&cmd,1,k

[PATCH 01/26] af9005: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/af9005.c | 211 +++--
 1 file changed, 111 insertions(+), 100 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/af9005.c 
b/drivers/media/usb/dvb-usb/af9005.c
index efa782ed6e2d..cc5815de1cfb 100644
--- a/drivers/media/usb/dvb-usb/af9005.c
+++ b/drivers/media/usb/dvb-usb/af9005.c
@@ -52,17 +52,15 @@ u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 
0xff };
 struct af9005_device_state {
u8 sequence;
int led_state;
+   unsigned char data[256];
 };
 
 static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
  int readwrite, int type, u8 * values, int len)
 {
struct af9005_device_state *st = d->priv;
-   u8 obuf[16] = { 0 };
-   u8 ibuf[17] = { 0 };
-   u8 command;
-   int i;
-   int ret;
+   u8 command, seq;
+   int i, ret;
 
if (len < 1) {
err("generic read/write, less than 1 byte. Makes no sense.");
@@ -73,16 +71,16 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
return -EINVAL;
}
 
-   obuf[0] = 14;   /* rest of buffer length low */
-   obuf[1] = 0;/* rest of buffer length high */
+   st->data[0] = 14;   /* rest of buffer length low */
+   st->data[1] = 0;/* rest of buffer length high */
 
-   obuf[2] = AF9005_REGISTER_RW;   /* register operation */
-   obuf[3] = 12;   /* rest of buffer length */
+   st->data[2] = AF9005_REGISTER_RW;   /* register operation */
+   st->data[3] = 12;   /* rest of buffer length */
 
-   obuf[4] = st->sequence++;   /* sequence number */
+   st->data[4] = seq = st->sequence++; /* sequence number */
 
-   obuf[5] = (u8) (reg >> 8);  /* register address */
-   obuf[6] = (u8) (reg & 0xff);
+   st->data[5] = (u8) (reg >> 8);  /* register address */
+   st->data[6] = (u8) (reg & 0xff);
 
if (type == AF9005_OFDM_REG) {
command = AF9005_CMD_OFDM_REG;
@@ -96,49 +94,43 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
command |= readwrite;
if (readwrite == AF9005_CMD_WRITE)
for (i = 0; i < len; i++)
-   obuf[8 + i] = values[i];
+   st->data[8 + i] = values[i];
else if (type == AF9005_TUNER_REG)
/* read command for tuner, the first byte contains the i2c 
address */
-   obuf[8] = values[0];
-   obuf[7] = command;
+   st->data[8] = values[0];
+   st->data[7] = command;
 
-   ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 17, 0);
if (ret)
return ret;
 
/* sanity check */
-   if (ibuf[2] != AF9005_REGISTER_RW_ACK) {
+   if (st->data[2] != AF9005_REGISTER_RW_ACK) {
err("generic read/write, wrong reply code.");
return -EIO;
}
-   if (ibuf[3] != 0x0d) {
+   if (st->data[3] != 0x0d) {
err("generic read/write, wrong length in reply.");
return -EIO;
}
-   if (ibuf[4] != obuf[4]) {
+   if (st->data[4] != seq) {
err("generic read/write, wrong sequence in reply.");
return -EIO;
}
/*
-  Windows driver doesn't check these fields, in fact sometimes
-  the register in the reply is different that what has been sent
-
-  if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
-  err("generic read/write, wrong register in reply.");
-  return -EIO;
-  }
-  if (ibuf[7] != command) {
-  err("generic read/write wrong command in reply.");
-  return -EIO;
-  }
+* In thesis, both input and output buffers should have
+* identical values for st->data[5] to st->data[8].
+* However, windows driver doesn't check these fields, in fact
+* sometimes the register in the reply is different that what
+* has been sent
 */
-   if (ibuf[16] != 0x01) {
+   if (st->data[16] != 0x01) {
err("generic read/write wrong status code in reply.");
return -EIO;
}
if (readwrite == AF9005_CMD_READ)
for (i = 0; i < len; i++)
-   values[i] = ibuf[8 + i];
+   values[i] = st->data[8 + i];
 
return 0;
 
@@ -464,8 +456,7 @@ int af9005_send_command(struct dvb_usb_device *d, u8 
command, u8 * wbuf,
struct af9005_device_state *st = d->priv;
 
int ret, i, packet_len;
-   u8 buf[64];
-   u8 ib

[PATCH 17/26] gp8psk: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/gp8psk.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index 5d0384dd45b5..fa215ad37f7b 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -24,6 +24,10 @@ MODULE_PARM_DESC(debug, "set debugging level 
(1=info,xfer=2,rc=4 (or-able))." DV
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct gp8psk_state {
+   unsigned char data[80];
+};
+
 static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
 {
return (gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6));
@@ -53,17 +57,19 @@ static void gp8psk_info(struct dvb_usb_device *d)
 
 int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, 
u8 *b, int blen)
 {
+   struct gp8psk_state *st = d->priv;
int ret = 0,try = 0;
 
if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
return ret;
 
while (ret >= 0 && ret != blen && try < 3) {
+   memcpy(st->data, b, blen);
ret = usb_control_msg(d->udev,
usb_rcvctrlpipe(d->udev,0),
req,
USB_TYPE_VENDOR | USB_DIR_IN,
-   value,index,b,blen,
+   value, index, st->data, blen,
2000);
deb_info("reading number %d (ret: %d)\n",try,ret);
try++;
@@ -86,6 +92,7 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
 int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
 u16 index, u8 *b, int blen)
 {
+   struct gp8psk_state *st = d->priv;
int ret;
 
deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
@@ -94,11 +101,12 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, 
u16 value,
if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
return ret;
 
+   memcpy(st->data, b, blen);
if (usb_control_msg(d->udev,
usb_sndctrlpipe(d->udev,0),
req,
USB_TYPE_VENDOR | USB_DIR_OUT,
-   value,index,b,blen,
+   value,index, st->data, blen,
2000) != blen) {
warn("usb out operation failed.");
ret = -EIO;
@@ -265,6 +273,8 @@ static struct dvb_usb_device_properties gp8psk_properties = 
{
.usb_ctrl = CYPRESS_FX2,
.firmware = "dvb-usb-gp8psk-01.fw",
 
+   .size_of_priv = sizeof(struct gp8psk_state),
+
.num_adapters = 1,
.adapter = {
{
-- 
2.7.4


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


[PATCH 07/26] dib0700: be sure that dib0700_ctrl_rd() users can do DMA

2016-10-07 Thread Mauro Carvalho Chehab
dib0700_ctrl_rd() takes a RX and a TX pointer. Be sure that
both will point to a memory allocated via kmalloc().

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dib0700_core.c|  4 +++-
 drivers/media/usb/dvb-usb/dib0700_devices.c | 25 +
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index f3196658fb70..515f89dba199 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -292,13 +292,15 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
 
/* special thing in the current firmware: when length 
is zero the read-failed */
len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2,
-   msg[i+1].buf, msg[i+1].len);
+ st->buf, msg[i + 1].len);
if (len <= 0) {
deb_info("I2C read failed on address 0x%02x\n",
msg[i].addr);
break;
}
 
+   memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
+
msg[i+1].len = len;
 
i++;
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 0857b56e652c..ef1b8ee75c57 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -508,8 +508,6 @@ static int stk7700ph_tuner_attach(struct dvb_usb_adapter 
*adap)
 
 #define DEFAULT_RC_INTERVAL 50
 
-static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
-
 /*
  * This function is used only when firmware is < 1.20 version. Newer
  * firmwares use bulk mode, with functions implemented at dib0700_core,
@@ -517,7 +515,6 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
  */
 static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
 {
-   u8 key[4];
enum rc_type protocol;
u32 scancode;
u8 toggle;
@@ -532,39 +529,43 @@ static int dib0700_rc_query_old_firmware(struct 
dvb_usb_device *d)
return 0;
}
 
-   i = dib0700_ctrl_rd(d, rc_request, 2, key, 4);
+   st->buf[0] = REQUEST_POLL_RC;
+   st->buf[1] = 0;
+
+   i = dib0700_ctrl_rd(d, st->buf, 2, st->buf, 4);
if (i <= 0) {
err("RC Query Failed");
-   return -1;
+   return -EIO;
}
 
/* losing half of KEY_0 events from Philipps rc5 remotes.. */
-   if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0)
+   if (st->buf[0] == 0 && st->buf[1] == 0
+   && st->buf[2] == 0 && st->buf[3] == 0)
return 0;
 
-   /* info("%d: %2X %2X %2X 
%2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]);
  */
+   /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)st->buf[3 - 
2],(int)st->buf[3 - 3],(int)st->buf[3 - 1],(int)st->buf[3]);  */
 
dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false 
events */
 
switch (d->props.rc.core.protocol) {
case RC_BIT_NEC:
/* NEC protocol sends repeat code as 0 0 0 FF */
-   if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
-   (key[3] == 0xff)) {
+   if ((st->buf[3 - 2] == 0x00) && (st->buf[3 - 3] == 0x00) &&
+   (st->buf[3] == 0xff)) {
rc_repeat(d->rc_dev);
return 0;
}
 
protocol = RC_TYPE_NEC;
-   scancode = RC_SCANCODE_NEC(key[3-2], key[3-3]);
+   scancode = RC_SCANCODE_NEC(st->buf[3 - 2], st->buf[3 - 3]);
toggle = 0;
break;
 
default:
/* RC-5 protocol changes toggle bit on new keypress */
protocol = RC_TYPE_RC5;
-   scancode = RC_SCANCODE_RC5(key[3-2], key[3-3]);
-   toggle = key[3-1];
+   scancode = RC_SCANCODE_RC5(st->buf[3 - 2], st->buf[3 - 3]);
+   toggle = st->buf[3 - 1];
break;
}
 
-- 
2.7.4


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


[PATCH 22/26] technisat-usb2: use DMA buffers for I2C transfers

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

On this driver, most of the transfers are OK, but the I2C
one was using stack.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/technisat-usb2.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c 
b/drivers/media/usb/dvb-usb/technisat-usb2.c
index d9f3262bf071..4706628a3ed5 100644
--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
@@ -89,9 +89,13 @@ struct technisat_usb2_state {
 static int technisat_usb2_i2c_access(struct usb_device *udev,
u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
 {
-   u8 b[64];
+   u8 *b;
int ret, actual_length;
 
+   b = kmalloc(64, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
+
deb_i2c("i2c-access: %02x, tx: ", device_addr);
debug_dump(tx, txlen, deb_i2c);
deb_i2c(" ");
@@ -123,7 +127,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
if (ret < 0) {
err("i2c-error: out failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
ret = usb_bulk_msg(udev,
@@ -131,7 +135,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
b, 64, &actual_length, 1000);
if (ret < 0) {
err("i2c-error: in failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
if (b[0] != I2C_STATUS_OK) {
@@ -140,7 +144,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
if (!(b[0] == I2C_STATUS_NAK &&
device_addr == 0x60
/* && device_is_technisat_usb2 */))
-   return -ENODEV;
+   goto err;
}
 
deb_i2c("status: %d, ", b[0]);
@@ -154,7 +158,9 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
deb_i2c("\n");
 
-   return 0;
+err:
+   kfree(b);
+   return ret;
 }
 
 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg 
*msg,
-- 
2.7.4


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


[PATCH 06/26] cxusb: don't do DMA on stack

2016-10-07 Thread Mauro Carvalho Chehab
The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cxusb.c | 20 +++-
 drivers/media/usb/dvb-usb/cxusb.h |  5 +
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 907ac01ae297..f3615349de52 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -45,9 +45,6 @@
 #include "si2168.h"
 #include "si2157.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  80
-
 /* debug */
 static int dvb_usb_cxusb_debug;
 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -61,23 +58,20 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int cxusb_ctrl_msg(struct dvb_usb_device *d,
  u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
+   struct cxusb_state *st = d->priv;
int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[MAX_XFER_SIZE];
 
-   if (1 + wlen > sizeof(sndbuf)) {
-   warn("i2c wr: len=%d is too big!\n",
-wlen);
+   if (1 + wlen > MAX_XFER_SIZE) {
+   warn("i2c wr: len=%d is too big!\n", wlen);
return -EOPNOTSUPP;
}
 
-   memset(sndbuf, 0, 1+wlen);
-
-   sndbuf[0] = cmd;
-   memcpy(&sndbuf[1], wbuf, wlen);
+   st->data[0] = cmd;
+   memcpy(&st->data[1], wbuf, wlen);
if (wo)
-   return dvb_usb_generic_write(d, sndbuf, 1+wlen);
+   return dvb_usb_generic_write(d, st->data, 1 + wlen);
else
-   return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
+   return dvb_usb_generic_rw(d, st->data, 1 + wlen, rbuf, rlen, 0);
 }
 
 /* GPIO */
diff --git a/drivers/media/usb/dvb-usb/cxusb.h 
b/drivers/media/usb/dvb-usb/cxusb.h
index 527ff7905e15..18acda19527a 100644
--- a/drivers/media/usb/dvb-usb/cxusb.h
+++ b/drivers/media/usb/dvb-usb/cxusb.h
@@ -28,10 +28,15 @@
 #define CMD_ANALOG0x50
 #define CMD_DIGITAL   0x51
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  80
+
 struct cxusb_state {
u8 gpio_write_state[3];
struct i2c_client *i2c_client_demod;
struct i2c_client *i2c_client_tuner;
+
+   unsigned char data[MAX_XFER_SIZE];
 };
 
 #endif
-- 
2.7.4


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


[PATCH 23/26] dvb-usb: warn if return value for USB read/write routines is not checked

2016-10-07 Thread Mauro Carvalho Chehab
the return values for dvb_usb_generic_rw() and dvb_usb_generic_write()
should be checked, as otherwise the drivers won't be doing the right
thing in the case of errors.

So, add __must_check to both declarations.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/dvb-usb.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dvb-usb.h 
b/drivers/media/usb/dvb-usb/dvb-usb.h
index 639c4678c65b..1448c3d27ea2 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb.h
+++ b/drivers/media/usb/dvb-usb/dvb-usb.h
@@ -462,8 +462,10 @@ extern int dvb_usb_device_init(struct usb_interface *,
 extern void dvb_usb_device_exit(struct usb_interface *);
 
 /* the generic read/write method for device control */
-extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, 
u16,int);
-extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
+extern int __must_check
+dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
+extern int __must_check
+dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
 
 /* commonly used remote control parsing */
 extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, 
int *);
-- 
2.7.4


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


DVB-T2 for ug-All, Kampala

2016-10-07 Thread Joseph Zik
Hi Oliver,
Here's a patch for DVB-T2 ug-All for Kampala, Uganda
Thanks

diff --git a/dvb-t/ug-All b/dvb-t/ug-All
index ce2a286..2d29959 100644
--- a/dvb-t/ug-All
+++ b/dvb-t/ug-All
@@ -1,45 +1,55 @@
 # location and provider : Kampala-Uganda
-# date : 2013-11-01
+# date : 2016-10-07
 # provided by : Joseph Zikusooka
 #   : http://joseph.zikusooka.com
-#   : jos...@zikusooka.com
+#   : joseph...@gmail.com
 #
 #--
-[UCC Primary]
- DELIVERY_SYSTEM = DVBT
+
+[CHANNEL]
+ DELIVERY_SYSTEM = DVBT2
  FREQUENCY = 47400
  BANDWIDTH_HZ = 800
- CODE_RATE_HP = 2/3
+ CODE_RATE_HP = 1/2
  CODE_RATE_LP = NONE
  MODULATION = QPSK
- TRANSMISSION_MODE = 8K
- GUARD_INTERVAL = 1/4
+ TRANSMISSION_MODE = 2K
+ GUARD_INTERVAL = 1/32
  HIERARCHY = NONE
  INVERSION = AUTO

 [CHANNEL]
  DELIVERY_SYSTEM = DVBT2
- FREQUENCY = 53800
+ FREQUENCY = 59400
  BANDWIDTH_HZ = 800
- CODE_RATE_HP = AUTO
- CODE_RATE_LP = AUTO
- MODULATION = QAM/AUTO
- TRANSMISSION_MODE = 32K
- GUARD_INTERVAL = 1/16
- HIERARCHY = AUTO
- STREAM_ID = 1
+ CODE_RATE_HP = 1/2
+ CODE_RATE_LP = NONE
+ MODULATION = QPSK
+ TRANSMISSION_MODE = 2K
+ GUARD_INTERVAL = 1/32
+ HIERARCHY = NONE
  INVERSION = AUTO

 [CHANNEL]
  DELIVERY_SYSTEM = DVBT2
- FREQUENCY = 58600
+ FREQUENCY = 71400
  BANDWIDTH_HZ = 800
- CODE_RATE_HP = AUTO
- CODE_RATE_LP = AUTO
- MODULATION = QAM/AUTO
- TRANSMISSION_MODE = 32K
- GUARD_INTERVAL = 1/16
- HIERARCHY = AUTO
- STREAM_ID = 9
+ CODE_RATE_HP = 1/2
+ CODE_RATE_LP = NONE
+ MODULATION = QPSK
+ TRANSMISSION_MODE = 2K
+ GUARD_INTERVAL = 1/32
+ HIERARCHY = NONE
  INVERSION = AUTO

+[CHANNEL]
+ DELIVERY_SYSTEM = DVBT2
+ FREQUENCY = 73000
+ BANDWIDTH_HZ = 800
+ CODE_RATE_HP = 1/2
+ CODE_RATE_LP = NONE
+ MODULATION = QPSK
+ TRANSMISSION_MODE = 2K
+ GUARD_INTERVAL = 1/32
+ HIERARCHY = NONE
+ INVERSION = AUTO

-- 
Joseph Zik
diff --git a/dvb-t/ug-All b/dvb-t/ug-All
index ce2a286..2d29959 100644
--- a/dvb-t/ug-All
+++ b/dvb-t/ug-All
@@ -1,45 +1,55 @@
 # location and provider	: Kampala-Uganda
-# date			: 2013-11-01
+# date			: 2016-10-07
 # provided by		: Joseph Zikusooka
 # 	   	: http://joseph.zikusooka.com
-# 	   	: jos...@zikusooka.com
+# 	   	: joseph...@gmail.com
 #
 #--
-[UCC Primary]
-	DELIVERY_SYSTEM = DVBT
+
+[CHANNEL]
+	DELIVERY_SYSTEM = DVBT2
 	FREQUENCY = 47400
 	BANDWIDTH_HZ = 800
-	CODE_RATE_HP = 2/3
+	CODE_RATE_HP = 1/2
 	CODE_RATE_LP = NONE
 	MODULATION = QPSK
-	TRANSMISSION_MODE = 8K
-	GUARD_INTERVAL = 1/4
+	TRANSMISSION_MODE = 2K
+	GUARD_INTERVAL = 1/32
 	HIERARCHY = NONE
 	INVERSION = AUTO
 
 [CHANNEL]
 	DELIVERY_SYSTEM = DVBT2
-	FREQUENCY = 53800
+	FREQUENCY = 59400
 	BANDWIDTH_HZ = 800
-	CODE_RATE_HP = AUTO
-	CODE_RATE_LP = AUTO
-	MODULATION = QAM/AUTO
-	TRANSMISSION_MODE = 32K
-	GUARD_INTERVAL = 1/16
-	HIERARCHY = AUTO
-	STREAM_ID = 1
+	CODE_RATE_HP = 1/2
+	CODE_RATE_LP = NONE
+	MODULATION = QPSK
+	TRANSMISSION_MODE = 2K
+	GUARD_INTERVAL = 1/32
+	HIERARCHY = NONE
 	INVERSION = AUTO
 
 [CHANNEL]
 	DELIVERY_SYSTEM = DVBT2
-	FREQUENCY = 58600
+	FREQUENCY = 71400
 	BANDWIDTH_HZ = 800
-	CODE_RATE_HP = AUTO
-	CODE_RATE_LP = AUTO
-	MODULATION = QAM/AUTO
-	TRANSMISSION_MODE = 32K
-	GUARD_INTERVAL = 1/16
-	HIERARCHY = AUTO
-	STREAM_ID = 9
+	CODE_RATE_HP = 1/2
+	CODE_RATE_LP = NONE
+	MODULATION = QPSK
+	TRANSMISSION_MODE = 2K
+	GUARD_INTERVAL = 1/32
+	HIERARCHY = NONE
 	INVERSION = AUTO
 
+[CHANNEL]
+	DELIVERY_SYSTEM = DVBT2
+	FREQUENCY = 73000
+	BANDWIDTH_HZ = 800
+	CODE_RATE_HP = 1/2
+	CODE_RATE_LP = NONE
+	MODULATION = QPSK
+	TRANSMISSION_MODE = 2K
+	GUARD_INTERVAL = 1/32
+	HIERARCHY = NONE
+	INVERSION = AUTO


Re: [PATCH 03/22] [media] v4l: of: add v4l2_of_subdev_registered

2016-10-07 Thread Marek Vasut
On 10/07/2016 06:00 PM, Philipp Zabel wrote:
> Provide a default registered callback for device tree probed subdevices
> that use OF graph bindings to add still missing source subdevices to
> the async notifier waiting list.
> This is only necessary for subdevices that have input ports to which
> other subdevices are connected that are not initially known to the
> master/bridge device when it sets up the notifier.
> 
> Signed-off-by: Philipp Zabel 

[...]

> +int v4l2_of_subdev_registered(struct v4l2_subdev *sd)
> +{
> + struct device_node *ep;
> +
> + for_each_endpoint_of_node(sd->of_node, ep) {
> + struct v4l2_of_link link;
> + struct media_entity *entity;
> + unsigned int pad;
> + int ret;
> +
> + ret = v4l2_of_parse_link(ep, &link);
> + if (ret)
> + continue;
> +
> + /*
> +  * Assume 1:1 correspondence between OF node and entity,
> +  * and between OF port numbers and pad indices.
> +  */
> + entity = &sd->entity;

This here will not compile if CONFIG_MEDIA_CONTROLLER is not set,
because ->entity will be missing from struct v4l2_subdev {} .

> + pad = link.local_port;
> +
> + if (pad >= entity->num_pads)
> + return -EINVAL;
> +
> + /* Add source subdevs to async notifier */
> + if (entity->pads[pad].flags & MEDIA_PAD_FL_SINK) {
> + struct v4l2_async_subdev *asd;
> +
> + asd = devm_kzalloc(sd->dev, sizeof(*asd), GFP_KERNEL);
> + if (!asd) {
> + v4l2_of_put_link(&link);
> + return -ENOMEM;
> + }
> +
> + asd->match_type = V4L2_ASYNC_MATCH_OF;
> + asd->match.of.node = link.remote_node;
> +
> + __v4l2_async_notifier_add_subdev(sd->notifier, asd);
> + }
> +
> + v4l2_of_put_link(&link);
> + }
> +
> + return 0;
> +}
> diff --git a/include/media/v4l2-of.h b/include/media/v4l2-of.h
> index 4dc34b2..67d4f8b 100644
> --- a/include/media/v4l2-of.h
> +++ b/include/media/v4l2-of.h
> @@ -22,6 +22,8 @@
>  #include 
>  
>  struct device_node;
> +struct v4l2_device;
> +struct v4l2_subdev;
>  
>  /**
>   * struct v4l2_of_bus_mipi_csi2 - MIPI CSI-2 bus data structure
> @@ -95,6 +97,9 @@ void v4l2_of_free_endpoint(struct v4l2_of_endpoint 
> *endpoint);
>  int v4l2_of_parse_link(const struct device_node *node,
>  struct v4l2_of_link *link);
>  void v4l2_of_put_link(struct v4l2_of_link *link);
> +int v4l2_of_subdev_registered(struct v4l2_subdev *sd);
> +struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
> +  struct device_node *node);
>  #else /* CONFIG_OF */
>  
>  static inline int v4l2_of_parse_endpoint(const struct device_node *node,
> @@ -123,6 +128,13 @@ static inline void v4l2_of_put_link(struct v4l2_of_link 
> *link)
>  {
>  }
>  
> +#define v4l2_of_subdev_registered NULL
> +
> +struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
> +  struct device_node *node)
> +{
> + return NULL;
> +}
>  #endif /* CONFIG_OF */
>  
>  #endif /* _V4L2_OF_H */
> 


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


Re: [PATCH 12/22] [media] tc358743: put lanes in STOP state before starting streaming

2016-10-07 Thread Marek Vasut
On 10/07/2016 06:00 PM, Philipp Zabel wrote:
> Without calling tc358743_set_csi from the new prepare_stream callback
> (or calling tc358743_s_dv_timings or tc358743_set_fmt from userspace
> after stopping the stream), the i.MX6 MIPI CSI2 input fails waiting
> for lanes to enter STOP state when streaming is started again.

What is the impact of that failure ? How does it manifest itself ?

> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/i2c/tc358743.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
> index 1e3a0dd2..dfa45d2 100644
> --- a/drivers/media/i2c/tc358743.c
> +++ b/drivers/media/i2c/tc358743.c
> @@ -1463,6 +1463,14 @@ static int tc358743_g_mbus_config(struct v4l2_subdev 
> *sd,
>   return 0;
>  }
>  
> +static int tc358743_prepare_stream(struct v4l2_subdev *sd)
> +{
> + /* Put all lanes in PL-11 state (STOPSTATE) */
> + tc358743_set_csi(sd);
> +
> + return 0;
> +}
> +
>  static int tc358743_s_stream(struct v4l2_subdev *sd, int enable)
>  {
>   enable_stream(sd, enable);
> @@ -1637,6 +1645,7 @@ static const struct v4l2_subdev_video_ops 
> tc358743_video_ops = {
>   .g_dv_timings = tc358743_g_dv_timings,
>   .query_dv_timings = tc358743_query_dv_timings,
>   .g_mbus_config = tc358743_g_mbus_config,
> + .prepare_stream = tc358743_prepare_stream,
>   .s_stream = tc358743_s_stream,
>  };
>  
> 


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


Re: [PATCH 18/22] [media] imx-ipuv3-csi: support downsizing

2016-10-07 Thread Marek Vasut
On 10/07/2016 06:01 PM, Philipp Zabel wrote:
> Add support for the CSI internal horizontal and vertical downsizing.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/platform/imx/imx-ipuv3-csi.c | 20 ++--
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/imx/imx-ipuv3-csi.c 
> b/drivers/media/platform/imx/imx-ipuv3-csi.c
> index 699460e6..e8a6a7b 100644
> --- a/drivers/media/platform/imx/imx-ipuv3-csi.c
> +++ b/drivers/media/platform/imx/imx-ipuv3-csi.c
> @@ -167,8 +167,16 @@ static int ipucsi_subdev_set_format(struct v4l2_subdev 
> *sd,
>   width = clamp_t(unsigned int, sdformat->format.width, 16, 8192);
>   height = clamp_t(unsigned int, sdformat->format.height, 16, 
> 4096);
>   } else {
> - width = ipucsi->format_mbus[0].width;
> - height = ipucsi->format_mbus[0].height;
> + if (sdformat->format.width <
> + (ipucsi->format_mbus[0].width * 3 / 4))
> + width = ipucsi->format_mbus[0].width / 2;
> + else
> + width = ipucsi->format_mbus[0].width;
> + if (sdformat->format.height <
> + (ipucsi->format_mbus[0].height * 3 / 4))
> + height = ipucsi->format_mbus[0].height / 2;
> + else
> + height = ipucsi->format_mbus[0].height;
>   }
>  
>   mbusformat = __ipucsi_get_pad_format(sd, cfg, sdformat->pad,
> @@ -212,14 +220,14 @@ static int ipucsi_subdev_s_stream(struct v4l2_subdev 
> *sd, int enable)
>   window.width = fmt[0].width;
>   window.height = fmt[0].height;
>   ipu_csi_set_window(ipucsi->csi, &window);
> + ipu_csi_set_downsize(ipucsi->csi,
> +  fmt[0].width == 2 * fmt[1].width,
> +  fmt[0].height == 2 * fmt[1].height);
>  
>   /* Is CSI data source MCT (MIPI)? */
>   mux_mct = (mbus_config.type == V4L2_MBUS_CSI2);
> -
>   ipu_set_csi_src_mux(ipucsi->ipu, ipucsi->id, mux_mct);
> - if (mux_mct)
> - ipu_csi_set_mipi_datatype(ipucsi->csi, /*VC*/ 0,
> -   &fmt[0]);
> + ipu_csi_set_mipi_datatype(ipucsi->csi, /*VC*/ 0, &fmt[0]);

This probably needs fixing , so that the correct VC is passed in ?

>   ret = ipu_csi_init_interface(ipucsi->csi, &mbus_config,
>&fmt[0]);
> 


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


[linux-review:Mauro-Carvalho-Chehab/Don-t-use-stack-for-DMA-transers-on-dvb-usb-drivers/20161008-021635 21/26] drivers/media/usb/dvb-usb/pctv452e.c:113:26: error: expected expression before '||' token

2016-10-07 Thread kbuild test robot
tree:   https://github.com/0day-ci/linux 
Mauro-Carvalho-Chehab/Don-t-use-stack-for-DMA-transers-on-dvb-usb-drivers/20161008-021635
head:   01e4e9b657c0de0c857817353b4ffbb3da5b9cb3
commit: 71eb7f5998d859d9de08128ebd4f3187b5f9fcbf [21/26] pctv452e: don't call 
BUG_ON() on non-fatal error
config: x86_64-rhel (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
git checkout 71eb7f5998d859d9de08128ebd4f3187b5f9fcbf
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/media/usb/dvb-usb/pctv452e.c: In function 'tt3650_ci_msg':
>> drivers/media/usb/dvb-usb/pctv452e.c:112:19: warning: suggest parentheses 
>> around '&&' within '||' [-Wparentheses]
 if (NULL == data && 0 != (write_len | read_len) ||
   
>> drivers/media/usb/dvb-usb/pctv452e.c:113:26: error: expected expression 
>> before '||' token
 write_len > 64 - 4) || (read_len > 64 - 4)) {
 ^~
   drivers/media/usb/dvb-usb/pctv452e.c:112:2: warning: this 'if' clause does 
not guard... [-Wmisleading-indentation]
 if (NULL == data && 0 != (write_len | read_len) ||
 ^~
   drivers/media/usb/dvb-usb/pctv452e.c:113:48: note: ...this statement, but 
the latter is misleadingly indented as if it is guarded by the 'if'
 write_len > 64 - 4) || (read_len > 64 - 4)) {
   ^
>> drivers/media/usb/dvb-usb/pctv452e.c:113:48: error: expected statement 
>> before ')' token

vim +113 drivers/media/usb/dvb-usb/pctv452e.c

   106  {
   107  struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
   108  u8 id;
   109  unsigned int rlen;
   110  int ret;
   111  
 > 112  if (NULL == data && 0 != (write_len | read_len) ||
 > 113  write_len > 64 - 4) || (read_len > 64 - 4)) {
   114  ret = -EIO;
   115  goto failed;
   116  };

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH 0/2] [media] dvb-tc90522: Fine-tuning for two function implementations

2016-10-07 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 7 Oct 2016 21:38:12 +0200

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

Markus Elfring (2):
  Use kmalloc_array()
  Rename a jump label

 drivers/media/dvb-frontends/tc90522.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

-- 
2.10.1

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


[PATCH 1/2] [media] dvb-tc90522: Use kmalloc_array() in tc90522_master_xfer()

2016-10-07 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 7 Oct 2016 21:07:43 +0200

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

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

diff --git a/drivers/media/dvb-frontends/tc90522.c 
b/drivers/media/dvb-frontends/tc90522.c
index 31cd325..c2d45f0 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -656,7 +656,7 @@ tc90522_master_xfer(struct i2c_adapter *adap, struct 
i2c_msg *msgs, int num)
for (i = 0; i < num; i++)
if (msgs[i].flags & I2C_M_RD)
rd_num++;
-   new_msgs = kmalloc(sizeof(*new_msgs) * (num + rd_num), GFP_KERNEL);
+   new_msgs = kmalloc_array(num + rd_num, sizeof(*new_msgs), GFP_KERNEL);
if (!new_msgs)
return -ENOMEM;
 
-- 
2.10.1

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


[PATCH 2/2] [media] dvb-tc90522: Rename a jump label in tc90522_probe()

2016-10-07 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 7 Oct 2016 21:13:57 +0200

Adjust a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/media/dvb-frontends/tc90522.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/tc90522.c 
b/drivers/media/dvb-frontends/tc90522.c
index c2d45f0..4687e15 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -794,14 +794,13 @@ static int tc90522_probe(struct i2c_client *client,
i2c_set_adapdata(adap, state);
ret = i2c_add_adapter(adap);
if (ret < 0)
-   goto err;
+   goto free_state;
cfg->tuner_i2c = state->cfg.tuner_i2c = adap;
 
i2c_set_clientdata(client, &state->cfg);
dev_info(&client->dev, "Toshiba TC90522 attached.\n");
return 0;
-
-err:
+free_state:
kfree(state);
return ret;
 }
-- 
2.10.1

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


[PATCH 1/3] [media] exynos-gsc: don't release a non-dynamically allocated video_device

2016-10-07 Thread Javier Martinez Canillas
The struct v4l2_device instance for the G-Scaler is not dyanmically
allocated but a member of the struct gsc_dev. In fact, the assigned
.release callback is video_device_release_empty().

But gsc_register_m2m_device() attempts to release the v4l2_device by
calling video_device_release() in its error path. This is wrong since
the v4l2_device wasn't allocated directly and will be freed once its
parent struct gsc_dev is freed.

While being there, rename the remaining goto label in the error path
to something that better explains the error path cleanup.

Signed-off-by: Javier Martinez Canillas 
---

 drivers/media/platform/exynos-gsc/gsc-m2m.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c 
b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index e2a16b52f87d..a1cac52ea230 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -760,24 +760,21 @@ int gsc_register_m2m_device(struct gsc_dev *gsc)
gsc->m2m.m2m_dev = v4l2_m2m_init(&gsc_m2m_ops);
if (IS_ERR(gsc->m2m.m2m_dev)) {
dev_err(&pdev->dev, "failed to initialize v4l2-m2m device\n");
-   ret = PTR_ERR(gsc->m2m.m2m_dev);
-   goto err_m2m_r1;
+   return PTR_ERR(gsc->m2m.m2m_dev);
}
 
ret = video_register_device(&gsc->vdev, VFL_TYPE_GRABBER, -1);
if (ret) {
dev_err(&pdev->dev,
 "%s(): failed to register video device\n", __func__);
-   goto err_m2m_r2;
+   goto err_m2m_release;
}
 
pr_debug("gsc m2m driver registered as /dev/video%d", gsc->vdev.num);
return 0;
 
-err_m2m_r2:
+err_m2m_release:
v4l2_m2m_release(gsc->m2m.m2m_dev);
-err_m2m_r1:
-   video_device_release(gsc->m2m.vfd);
 
return ret;
 }
-- 
2.7.4

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


[PATCH 3/3] [media] exynos-gsc: cleanup m2m src and dst vb2 queues on STREAMOFF

2016-10-07 Thread Javier Martinez Canillas
Media drivers that use the videobuf2 framework have to give back to vb2
all the buffers that received from vb2 using its .buf_queue callback.

But the exynos-gsc driver isn't doing a proper cleanup so vb2 complains
that the number of buffers enqueued and received are not balanced:

WARNING: CPU: 2 PID: 660 at drivers/media/v4l2-core/videobuf2-core.c:1654 
__vb2_queue_cancel+0xec/0x150 [videobuf2_core]
Modules linked in: mwifiex_sdio mwifiex uvcvideo exynos_gsc videobuf2_vmalloc 
s5p_mfc s5p_jpeg
CPU: 2 PID: 660 Comm: lt-gst-validate Not tainted 4.8.0
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[] (unwind_backtrace) from [] (show_stack+0x10/0x14)
[] (show_stack) from [] (dump_stack+0x88/0x9c)
[] (dump_stack) from [] (__warn+0xe8/0x100)
[] (__warn) from [] (warn_slowpath_null+0x20/0x28)
[] (warn_slowpath_null) from [] 
(__vb2_queue_cancel+0xec/0x150 [videobuf2_core])
[] (__vb2_queue_cancel [videobuf2_core]) from [] 
(vb2_core_streamoff+0x34/0x9c [videobuf2_core])
[] (vb2_core_streamoff [videobuf2_core]) from [] 
(v4l2_m2m_streamoff+0x2c/0xe4 [v4l2_mem2mem])
[] (v4l2_m2m_streamoff [v4l2_mem2mem]) from [] 
(__video_do_ioctl+0x298/0x30c [videodev])
[] (__video_do_ioctl [videodev]) from [] 
(video_usercopy+0x174/0x4e8 [videodev])
[] (video_usercopy [videodev]) from [] 
(v4l2_ioctl+0xc4/0xd8 [videodev])
[] (v4l2_ioctl [videodev]) from [] (do_vfs_ioctl+0x9c/0x8f4)
[] (do_vfs_ioctl) from [] (SyS_ioctl+0x34/0x5c)
[] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x3c)

Fix this by passing back to vb2 all the received buffers that were not
processed.

Signed-off-by: Javier Martinez Canillas 

---

 drivers/media/platform/exynos-gsc/gsc-m2m.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c 
b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index c8c0bcec35ed..f49f24b4462a 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -66,12 +66,29 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, 
unsigned int count)
return ret > 0 ? 0 : ret;
 }
 
+static void __gsc_m2m_cleanup_queue(struct gsc_ctx *ctx)
+{
+   struct vb2_v4l2_buffer *src_vb, *dst_vb;
+
+   while (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) > 0) {
+   src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+   v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_ERROR);
+   }
+
+   while (v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) > 0) {
+   dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
+   v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_ERROR);
+   }
+}
+
 static void gsc_m2m_stop_streaming(struct vb2_queue *q)
 {
struct gsc_ctx *ctx = q->drv_priv;
 
__gsc_m2m_job_abort(ctx);
 
+   __gsc_m2m_cleanup_queue(ctx);
+
pm_runtime_put(&ctx->gsc_dev->pdev->dev);
 }
 
-- 
2.7.4

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


[PATCH 2/3] [media] exynos-gsc: unregister video device node on driver removal

2016-10-07 Thread Javier Martinez Canillas
The driver doesn't unregister the video device node when the driver is
removed, this keeps video device nodes that makes the machine to crash
with a NULL pointer dereference when nodes are attempted to be opened:

[   36.530006] Unable to handle kernel paging request at virtual address 
bf1f8200
[   36.535985] pgd = edbbc000
[   36.538486] [bf1f8200] *pgd=6d99a811, *pte=, *ppte=
[   36.544727] Internal error: Oops: 7 [#1] PREEMPT SMP ARM
[   36.550016] Modules linked in: s5p_jpeg s5p_mfc v4l2_mem2mem 
videobuf2_dma_contig
[   36.566303] CPU: 6 PID: 533 Comm: v4l2-ctl Not tainted 4.8.0
[   36.574466] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[   36.580526] task: ee3cc600 task.stack: ed626000
[   36.585046] PC is at try_module_get+0x1c/0xac
[   36.589364] LR is at try_module_get+0x1c/0xac
[   36.593698] pc : []lr : []psr: 80070013
[   36.593698] sp : ed627de0  ip : a0070013  fp : 
[   36.605156] r10: 0002  r9 : ed627ed0  r8 : 
[   36.610331] r7 : c01e5f14  r6 : ed57be00  r5 : bf1f8200  r4 : bf1f8200
[   36.616834] r3 : 0002  r2 : 0002  r1 : 01930192  r0 : 0001
..
[   36.785004] [] (try_module_get) from [] 
(cdev_get+0x1c/0x4c)
[   36.792362] [] (cdev_get) from [] 
(chrdev_open+0x2c/0x178)
[   36.799555] [] (chrdev_open) from [] 
(do_dentry_open+0x1e0/0x300)
[   36.807360] [] (do_dentry_open) from [] 
(path_openat+0x35c/0xf58)
[   36.815154] [] (path_openat) from [] 
(do_filp_open+0x5c/0xc0)
[   36.822606] [] (do_filp_open) from [] 
(do_sys_open+0x10c/0x1bc)
[   36.830235] [] (do_sys_open) from [] 
(ret_fast_syscall+0x0/0x3c)
[   36.837942] Code: 0a1c e1a04000 e3a1 ebfec92d (e5943000)

Signed-off-by: Javier Martinez Canillas 
---

 drivers/media/platform/exynos-gsc/gsc-m2m.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c 
b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index a1cac52ea230..c8c0bcec35ed 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -781,6 +781,8 @@ err_m2m_release:
 
 void gsc_unregister_m2m_device(struct gsc_dev *gsc)
 {
-   if (gsc)
+   if (gsc) {
v4l2_m2m_release(gsc->m2m.m2m_dev);
+   video_unregister_device(&gsc->vdev);
+   }
 }
-- 
2.7.4

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


[PATCH 0/3] [media] exynos-gsc: Another round of cleanup and fixes

2016-10-07 Thread Javier Martinez Canillas
Hello,

This series contains another set of cleanup and fixes for the exynos-gsc
driver. The patches are on top of the previous posted set [0], although
there's no dependency and the patch-sets can be applied in any order.

Patch 1/3 is a cleanup for the gsc_register_m2m_device() error path

Patch 2/3 fixes a NULL pointer deference that happens when the driver
module is removed due the video device node not being unregistered.

Patch 3/3 fixes a warning due the driver not doing proper cleanup of
the m2m source and destination queues.

[0]: https://lkml.org/lkml/2016/9/30/413

Best regards,
Javier


Javier Martinez Canillas (3):
  [media] exynos-gsc: don't release a non-dynamically allocated
video_device
  [media] exynos-gsc: unregister video device node on driver removal
  [media] exynos-gsc: cleanup m2m src and dst vb2 queues on STREAMOFF

 drivers/media/platform/exynos-gsc/gsc-m2m.c | 30 ++---
 1 file changed, 23 insertions(+), 7 deletions(-)

-- 
2.7.4

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


[linux-review:Mauro-Carvalho-Chehab/Don-t-use-stack-for-DMA-transers-on-dvb-usb-drivers/20161008-021635 21/26] drivers/media/usb/dvb-usb/pctv452e.c:112:2: warning: this 'if' clause does not guard...

2016-10-07 Thread kbuild test robot
tree:   https://github.com/0day-ci/linux 
Mauro-Carvalho-Chehab/Don-t-use-stack-for-DMA-transers-on-dvb-usb-drivers/20161008-021635
head:   01e4e9b657c0de0c857817353b4ffbb3da5b9cb3
commit: 71eb7f5998d859d9de08128ebd4f3187b5f9fcbf [21/26] pctv452e: don't call 
BUG_ON() on non-fatal error
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 71eb7f5998d859d9de08128ebd4f3187b5f9fcbf
# save the attached .config to linux build tree
make.cross ARCH=sparc64 

All warnings (new ones prefixed by >>):

   drivers/media/usb/dvb-usb/pctv452e.c: In function 'tt3650_ci_msg':
   drivers/media/usb/dvb-usb/pctv452e.c:112:19: warning: suggest parentheses 
around '&&' within '||' [-Wparentheses]
 if (NULL == data && 0 != (write_len | read_len) ||
   
   drivers/media/usb/dvb-usb/pctv452e.c:113:26: error: expected expression 
before '||' token
 write_len > 64 - 4) || (read_len > 64 - 4)) {
 ^~
>> drivers/media/usb/dvb-usb/pctv452e.c:112:2: warning: this 'if' clause does 
>> not guard... [-Wmisleading-indentation]
 if (NULL == data && 0 != (write_len | read_len) ||
 ^~
   drivers/media/usb/dvb-usb/pctv452e.c:113:48: note: ...this statement, but 
the latter is misleadingly indented as if it is guarded by the 'if'
 write_len > 64 - 4) || (read_len > 64 - 4)) {
   ^
   drivers/media/usb/dvb-usb/pctv452e.c:113:48: error: expected statement 
before ')' token

vim +/if +112 drivers/media/usb/dvb-usb/pctv452e.c

96  
97  u8 c;  /* transaction counter, wraps around...  */
98  u8 initialized; /* set to 1 if 0x15 has been sent */
99  u16 last_rc_key;
   100  
   101  unsigned char data[80];
   102  };
   103  
   104  static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
   105   unsigned int write_len, unsigned int read_len)
   106  {
   107  struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
   108  u8 id;
   109  unsigned int rlen;
   110  int ret;
   111  
 > 112  if (NULL == data && 0 != (write_len | read_len) ||
   113  write_len > 64 - 4) || (read_len > 64 - 4)) {
   114  ret = -EIO;
   115  goto failed;
   116  };
   117  
   118  id = state->c++;
   119  
   120  state->data[0] = SYNC_BYTE_OUT;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH] [media] vb2: move dma-buf unmap from __vb2_dqbuf() to vb2_buffer_done()

2016-10-07 Thread Sakari Ailus
Hi Javier,

On Tue, Aug 16, 2016 at 05:26:31PM -0400, Javier Martinez Canillas wrote:
> Hello Sakari,
> 
> On 08/16/2016 05:13 PM, Sakari Ailus wrote:
> > Hi Javier,
> > 
> > Javier Martinez Canillas wrote:
> >> Hello Sakari,
> >>
> >> On 08/16/2016 04:47 PM, Sakari Ailus wrote:
> >>> Hi Javier,
> >>>
> >>> Javier Martinez Canillas wrote:
>  Hello Hans,
> 
>  Thanks a lot for your feedback.
> 
>  On 08/13/2016 09:47 AM, Hans Verkuil wrote:
> > On 07/20/2016 08:22 PM, Javier Martinez Canillas wrote:
> >> Currently the dma-buf is unmapped when the buffer is dequeued by 
> >> userspace
> >> but it's not used anymore after the driver finished processing the 
> >> buffer.
> >>
> >> So instead of doing the dma-buf unmapping in __vb2_dqbuf(), it can be 
> >> made
> >> in vb2_buffer_done() after the driver notified that buf processing is 
> >> done.
> >>
> >> Decoupling the buffer dequeue from the dma-buf unmapping has also the 
> >> side
> >> effect of making possible to add dma-buf fence support in the future 
> >> since
> >> the buffer could be dequeued even before the driver has finished using 
> >> it.
> >>
> >> Signed-off-by: Javier Martinez Canillas 
> >>
> >> ---
> >> Hello,
> >>
> >> I've tested this patch doing DMA buffer sharing between a
> >> vivid input and output device with both v4l2-ctl and gst:
> >>
> >> $ v4l2-ctl -d0 -e1 --stream-dmabuf --stream-out-mmap
> >> $ v4l2-ctl -d0 -e1 --stream-mmap --stream-out-dmabuf
> >> $ gst-launch-1.0 v4l2src device=/dev/video0 io-mode=dmabuf ! v4l2sink 
> >> device=/dev/video1 io-mode=dmabuf-import
> >>
> >> And I didn't find any issues but more testing will be appreciated.
> >>
> >> Best regards,
> >> Javier
> >>
> >>  drivers/media/v4l2-core/videobuf2-core.c | 34 
> >> +---
> >>  1 file changed, 22 insertions(+), 12 deletions(-)
> >>
> >> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
> >> b/drivers/media/v4l2-core/videobuf2-core.c
> >> index 7128b09810be..973331efaf79 100644
> >> --- a/drivers/media/v4l2-core/videobuf2-core.c
> >> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> >> @@ -958,6 +958,22 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, 
> >> unsigned int plane_no)
> >>  EXPORT_SYMBOL_GPL(vb2_plane_cookie);
> >>  
> >>  /**
> >> + * __vb2_unmap_dmabuf() - unmap dma-buf attached to buffer planes
> >> + */
> >> +static void __vb2_unmap_dmabuf(struct vb2_buffer *vb)
> >> +{
> >> +  int i;
> >> +
> >> +  for (i = 0; i < vb->num_planes; ++i) {
> >> +  if (!vb->planes[i].dbuf_mapped)
> >> +  continue;
> >> +  call_void_memop(vb, unmap_dmabuf,
> >> +  vb->planes[i].mem_priv);
> >
> > Does unmap_dmabuf work in interrupt context? Since vb2_buffer_done can 
> > be called from
> > an irq handler this is a concern.
> >
> 
>  Good point, I believe it shouldn't be called from atomic context since 
>  both
>  the dma_buf_vunmap() and dma_buf_unmap_attachment() functions can sleep.
>   
> > That said, vb2_buffer_done already calls call_void_memop(vb, finish, 
> > vb->planes[plane].mem_priv);
> > to sync buffers, and that can take a long time as well. So it is not a 
> > good idea to
> > have this in vb2_buffer_done.
> >
> 
>  I see.
> 
> > What I would like to see is to have vb2 handle this finish() call and 
> > the vb2_unmap_dmabuf
> > in some workthread or equivalent.
> >
> > It would complicate matters somewhat in vb2, but it would simplify 
> > drivers since these
> > actions would not longer take place in interrupt context.
> >
> > I think this patch makes sense, but I would prefer that this is moved 
> > out of the interrupt
> > context.
> >
> 
>  Ok, I can take a look to this and handle the finish() and unmap_dmabuf()
>  out of interrupt context as you suggested.
> >>>
> >>> I have a patch doing the former which is a part of my cache management
> >>> fix patchset:
> >>>
> >>> http://git.retiisi.org.uk/?p=~sailus/linux.git;a=commitdiff;h=b57f937627abda158ada01a3297dbb0f0a57b515>
> >>> http://git.retiisi.org.uk/?p=~sailus/linux.git;a=shortlog;h=refs/heads/vb2-dc-noncoherent>
> >>>
> >>
> >> Interesting, thanks for the links.
> >>  
> >>> There were a few drivers doing nasty things with memory that I couldn't
> >>> quite fix back then. Just FYI.
> >>>
> >>
> >> Did you mean that there were issues with moving finish mem op call to 
> >> DQBUF?
> >>
> >> Do you recall what these drivers were or what were doing that caused 
> >> problems?
> > 
> > Not any particular drivers --- the problem is that flushing the cache
> 
> Ah, you were explaining the rational

Re: [PATCH 02/22] [media] v4l2-async: allow subdevices to add further subdevices to the notifier waiting list

2016-10-07 Thread Sakari Ailus
Hi Philipp,

On Fri, Oct 07, 2016 at 06:00:47PM +0200, Philipp Zabel wrote:
> Currently the v4l2_async_notifier needs to be given a list of matches
> for all expected subdevices on creation. When chaining subdevices that
> are asynchronously probed via device tree, the bridge device that sets
> up the notifier does not know the complete list of subdevices, as it
> can only parse its own device tree node to obtain information about
> the nearest neighbor subdevices.
> To support indirectly connected subdevices, we need to support amending
> the existing notifier waiting list with newly found neighbor subdevices
> with each registered subdevice.

Could you elaborate a little what's the exact use case for this? What kind
of a device?

Thanks.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/22] [media] v4l2-async: allow subdevices to add further subdevices to the notifier waiting list

2016-10-07 Thread Sakari Ailus
Hi Philipp,

On Fri, Oct 07, 2016 at 06:00:47PM +0200, Philipp Zabel wrote:
> Currently the v4l2_async_notifier needs to be given a list of matches
> for all expected subdevices on creation. When chaining subdevices that
> are asynchronously probed via device tree, the bridge device that sets
> up the notifier does not know the complete list of subdevices, as it
> can only parse its own device tree node to obtain information about
> the nearest neighbor subdevices.
> To support indirectly connected subdevices, we need to support amending
> the existing notifier waiting list with newly found neighbor subdevices
> with each registered subdevice.
> 
> This can be achieved by adding new v42l_async_subdev matches to the
> notifier waiting list during the v4l2_subdev registered callback, which
> is called under the list lock from either v4l2_async_register_subdev or
> v4l2_async_notifier_register. For this purpose a new exported function
> __v4l2_async_notifier_add_subdev is added.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 78 
> ++--
>  include/media/v4l2-async.h   | 12 ++
>  2 files changed, 86 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index c4f1930..404eeea 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -109,6 +109,7 @@ static int v4l2_async_test_notify(struct 
> v4l2_async_notifier *notifier,
>   if (ret < 0)
>   return ret;
>   }
> +
>   /* Move from the global subdevice list to notifier's done */
>   list_move(&sd->async_list, ¬ifier->done);
>  
> @@ -158,7 +159,7 @@ int v4l2_async_notifier_register(struct v4l2_device 
> *v4l2_dev,
>struct v4l2_async_notifier *notifier)
>  {
>   struct v4l2_async_subdev *asd;
> - int ret;
> + struct list_head *tail;
>   int i;
>  
>   if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
> @@ -191,17 +192,71 @@ int v4l2_async_notifier_register(struct v4l2_device 
> *v4l2_dev,
>   /* Keep also completed notifiers on the list */
>   list_add(¬ifier->list, ¬ifier_list);
>  
> + do {
> + int ret;
> +
> + tail = notifier->waiting.prev;
> +
> + ret = v4l2_async_test_notify_all(notifier);
> + if (ret < 0) {
> + mutex_unlock(&list_lock);
> + return ret;
> + }
> +
> + /*
> +  * If entries were added to the notifier waiting list, check
> +  * again if the corresponding subdevices are already available.
> +  */
> + } while (tail != notifier->waiting.prev);
> +
>   mutex_unlock(&list_lock);
>  
> - return ret;
> + return 0;
>  }
>  EXPORT_SYMBOL(v4l2_async_notifier_register);
>  
> +int __v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
> +  struct v4l2_async_subdev *asd)
> +{
> + struct v4l2_async_subdev *tmp_asd;
> +
> + lockdep_assert_held(&list_lock);
> +
> + if (asd->match_type != V4L2_ASYNC_MATCH_OF)
> + return -EINVAL;
> +
> + /*
> +  * First check if the same notifier is already on the waiting or done
> +  * lists. This can happen if a subdevice with multiple outputs is added
> +  * by all its downstream subdevices.
> +  */
> + list_for_each_entry(tmp_asd, ¬ifier->waiting, list)
> + if (tmp_asd->match.of.node == asd->match.of.node)
> + return 0;
> + list_for_each_entry(tmp_asd, ¬ifier->done, list)
> + if (tmp_asd->match.of.node == asd->match.of.node)
> + return 0;
> +
> + /*
> +  * Add the new async subdev to the notifier waiting list, so
> +  * v4l2_async_belongs may use it to compare against entries in
> +  * subdev_list.
> +  * In case the subdev matching asd has already been passed in the
> +  * subdev_list walk in v4l2_async_notifier_register, or if
> +  * we are called from v4l2_async_register_subdev, the subdev_list
> +  * will have to be walked again.
> +  */
> + list_add_tail(&asd->list, ¬ifier->waiting);
> +
> + return 0;
> +}
> +
>  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);
> + unsigned int notif_n_subdev = 0;
> + unsigned int n_subdev;
> + struct list_head *list;
>   struct device **dev;
>   int i = 0;
>  
> @@ -218,6 +273,10 @@ void v4l2_async_notifier_unregister(struct 
> v4l2_async_notifier *notifier)
>  
>   list_del(¬ifier->list);
>  
> + list_for_each(list, ¬ifier->done)
> + ++notif_n_subdev;
> + n_

Re: [PATCH 03/22] [media] v4l: of: add v4l2_of_subdev_registered

2016-10-07 Thread Sakari Ailus
Hi Philipp,

On Fri, Oct 07, 2016 at 06:00:48PM +0200, Philipp Zabel wrote:
> Provide a default registered callback for device tree probed subdevices
> that use OF graph bindings to add still missing source subdevices to
> the async notifier waiting list.
> This is only necessary for subdevices that have input ports to which
> other subdevices are connected that are not initially known to the
> master/bridge device when it sets up the notifier.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/v4l2-core/v4l2-of.c | 68 
> +++
>  include/media/v4l2-of.h   | 12 +++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-of.c 
> b/drivers/media/v4l2-core/v4l2-of.c
> index 93b3368..fbdd6b4 100644
> --- a/drivers/media/v4l2-core/v4l2-of.c
> +++ b/drivers/media/v4l2-core/v4l2-of.c
> @@ -19,6 +19,7 @@
>  #include 
>  
>  #include 
> +#include 

Alphabetical order, please.

>  
>  static int v4l2_of_parse_csi_bus(const struct device_node *node,
>struct v4l2_of_endpoint *endpoint)
> @@ -314,3 +315,70 @@ void v4l2_of_put_link(struct v4l2_of_link *link)
>   of_node_put(link->remote_node);
>  }
>  EXPORT_SYMBOL(v4l2_of_put_link);
> +
> +struct v4l2_subdev *v4l2_find_subdev_by_node(struct v4l2_device *v4l2_dev,
> +  struct device_node *node)
> +{
> + struct v4l2_subdev *sd;
> +
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> + if (sd->of_node == node)
> + return sd;
> + }

The braces aren't really needed. Up to you.

> +
> + return NULL;
> +}

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 04/22] [media] v4l2-subdev.h: add prepare_stream op

2016-10-07 Thread Sakari Ailus
Hi Philipp,

On Fri, Oct 07, 2016 at 06:00:49PM +0200, Philipp Zabel wrote:
> In some cases, for example MIPI CSI-2 input on i.MX6, the sending and
> receiving subdevice need to be prepared in lock-step before the actual
> streaming can start. In the i.MX6 MIPI CSI-2 case, the sender needs to
> put its MIPI CSI-2 transmitter lanes into stop state, and the receiver
> needs to configure its D-PHY and detect the stop state on all active
> lanes. Only then the sender can be enabled to stream data and the
> receiver can lock its PLL to the clock lane.

Is there a need to explicitly control this? Shouldn't this already be the
case when the transmitting device is powered on and is not streaming?

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


cron job: media_tree daily build: ERRORS

2016-10-07 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 Oct  8 05:00:18 CEST 2016
media-tree git hash:9fce0c226536fc36c7fb0a8ca38a995be43e
media_build git hash:   ecfc9bfca3012b0c6e19967ce90f621f71a6da94
v4l-utils git hash: 2cd2699a8cfe8dce32dd35033a364c8375839d51
gcc version:i686-linux-gcc (GCC) 6.2.0
sparse version: v0.5.0-3553-g78b2ea6
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.7.0-164

linux-git-arm-at91: ERRORS
linux-git-arm-davinci: ERRORS
linux-git-arm-multi: ERRORS
linux-git-arm-pxa: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: WARNINGS
linux-git-mips: ERRORS
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: ERRORS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: ERRORS
linux-3.2.37-i686: ERRORS
linux-3.3.8-i686: ERRORS
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: OK
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-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: ERRORS
linux-3.2.37-x86_64: ERRORS
linux-3.3.8-x86_64: ERRORS
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: OK
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: OK
apps: WARNINGS
spec-git: OK
smatch: ERRORS
sparse: WARNINGS

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