cron job: media_tree daily build: ERRORS

2016-11-12 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:   Sun Nov 13 05:00:16 CET 2016
media-tree git hash:bd676c0c04ec94bd830b9192e2c33f2c4532278d
media_build git hash:   bce0dfbb3eca1600249a7ebc5eaea2e19bfaf56b
v4l-utils git hash: db397c130912446d58c9ad3e0a81bacc0c54c159
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-Module.symvers: ERRORS
linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.2.37-i686: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.8-i686: ERRORS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.11.1-i686: OK
linux-3.12.67-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-4.9-rc1-i686: OK
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-x86_64: ERRORS
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: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: OK
linux-3.12.67-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
linux-4.9-rc1-x86_64: OK
apps: WARNINGS
spec-git: OK
smatch: ERRORS
sparse: WARNINGS

Detailed results are available here:

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

Full logs are available here:

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


Re: [v4.9-rc4] dvb-usb/cinergyT2 NULL pointer dereference

2016-11-12 Thread Benjamin Larsson

On 11/11/2016 02:55 PM, Mauro Carvalho Chehab wrote:

Em Thu, 10 Nov 2016 12:15:39 +0100

Benjamin,

Could you please test it?

Thanks!
Mauro


Hi, I the device is in use now. Can't test it with a new tree. I am 
using an old tree for it.


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


[PATCH] [media] zoran: fix spelling mistake in dprintk message

2016-11-12 Thread Colin King
From: Colin Ian King 

Trivial fix to spelling mistake "unnsupported" to "unsupported"
in debug message.

Signed-off-by: Colin Ian King 
---
 drivers/media/pci/zoran/zoran_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/zoran/zoran_driver.c 
b/drivers/media/pci/zoran/zoran_driver.c
index d6b631a..2170e17 100644
--- a/drivers/media/pci/zoran/zoran_driver.c
+++ b/drivers/media/pci/zoran/zoran_driver.c
@@ -1488,7 +1488,7 @@ zoran_set_input (struct zoran *zr,
if (input < 0 || input >= zr->card.inputs) {
dprintk(1,
KERN_ERR
-   "%s: %s - unnsupported input %d\n",
+   "%s: %s - unsupported input %d\n",
ZR_DEVNAME(zr), __func__, input);
return -EINVAL;
}
-- 
2.10.2

--
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] gp8psk: fix gp8psk_usb_in_op() logic

2016-11-12 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

Changeset bc29131ecb10 ("[media] gp8psk: don't do DMA on stack")
fixed the usage of DMA on stack, but the memcpy was wrong
for gp8psk_usb_in_op(). Fix it.

>From Derek's email:
"Fix confirmed using 2 different Skywalker models with
 HD mpeg4, SD mpeg2."

Suggested-by: Johannes Stezenbach 
Fixes: bc29131ecb10 ("[media] gp8psk: don't do DMA on stack")
Tested-by: Derek 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/gp8psk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index adfd76491451..2829e3082d15 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -67,7 +67,6 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
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,
@@ -81,8 +80,10 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
if (ret < 0 || ret != blen) {
warn("usb in %d operation failed.", req);
ret = -EIO;
-   } else
+   } else {
ret = 0;
+   memcpy(b, st->data, blen);
+   }
 
deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
debug_dump(b,blen,deb_xfer);
-- 
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 1/3] [media] dvb-usb: move data_mutex to struct dvb_usb_device

2016-11-12 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

The data_mutex is initialized too late, as it is needed for
each device driver's power control, causing an OOPS:

dvb-usb: found a 'TerraTec/qanu USB2.0 Highspeed DVB-T Receiver' in 
warm state.
BUG: unable to handle kernel NULL pointer dereference at   
(null)
IP: [] __mutex_lock_slowpath+0x6f/0x100 PGD 0
Oops: 0002 [#1] SMP
Modules linked in: dvb_usb_cinergyT2(+) dvb_usb
CPU: 0 PID: 2029 Comm: modprobe Not tainted 4.9.0-rc4-dvbmod #24
Hardware name: FUJITSU LIFEBOOK A544/FJNBB35 , BIOS Version 1.17 
05/09/2014
task: 88020e943840 task.stack: 8801f36ec000
RIP: 0010:[]  [] 
__mutex_lock_slowpath+0x6f/0x100
RSP: 0018:8801f36efb10  EFLAGS: 00010282
RAX:  RBX: 88021509bdc8 RCX: c100
RDX: 0001 RSI:  RDI: 88021509bdcc
RBP: 8801f36efb58 R08: 88021f216320 R09: 0010
R10: 88021f216320 R11: 0023fee6c5a1 R12: 88020e943840
R13: 88021509bdcc R14:  R15: 88021509bdd0
FS:  7f21adb86740() GS:88021f20() 
knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2:  CR3: 000215bce000 CR4: 001406f0
Stack:
 88021509bdd0   c0137c80
 88021509bdc8 8801f5944000 0001 c0136b00
 880213e52000 88021509bdc8 84661856 88021509bd80
Call Trace:
 [] ? mutex_lock+0x16/0x25
 [] ? cinergyt2_power_ctrl+0x1f/0x60 
[dvb_usb_cinergyT2]
 [] ? dvb_usb_device_init+0x21e/0x5d0 [dvb_usb]
 [] ? cinergyt2_usb_probe+0x21/0x50 
[dvb_usb_cinergyT2]
 [] ? usb_probe_interface+0xf3/0x2a0
 [] ? driver_probe_device+0x208/0x2b0
 [] ? __driver_attach+0x87/0x90
 [] ? driver_probe_device+0x2b0/0x2b0
 [] ? bus_for_each_dev+0x52/0x80
 [] ? bus_add_driver+0x1a3/0x220
 [] ? driver_register+0x56/0xd0
 [] ? usb_register_driver+0x77/0x130
 [] ? 0xc013a000
 [] ? do_one_initcall+0x46/0x180
 [] ? free_vmap_area_noflush+0x38/0x70
 [] ? kmem_cache_alloc+0x84/0xc0
 [] ? do_init_module+0x50/0x1be
 [] ? load_module+0x1d8b/0x2100
 [] ? find_symbol_in_section+0xa0/0xa0
 [] ? SyS_finit_module+0x89/0x90
 [] ? entry_SYSCALL_64_fastpath+0x13/0x94
Code: e8 a7 1d 00 00 8b 03 83 f8 01 0f 84 97 00 00 00 48 8b 43 10 4c 8d 
7b 08 48 89 63 10 4c 89 3c 24 41 be ff ff ff ff 48 89 44 24 08 <48> 89 20 4c 89 
64 24 10 eb 1a 49 c7 44 24 08 02 00 00 00 c6 43 RIP  [] 
__mutex_lock_slowpath+0x6f/0x100 RSP 
CR2: 

So, move it to the struct dvb_usb_device and initialize it
before calling the driver's callbacks.

Reported-by: Jörg Otte 
Tested-by: Jörg Otte 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/af9005.c | 33 
 drivers/media/usb/dvb-usb/cinergyT2-core.c | 33 
 drivers/media/usb/dvb-usb/cxusb.c  | 39 -
 drivers/media/usb/dvb-usb/cxusb.h  |  1 -
 drivers/media/usb/dvb-usb/dtt200u.c| 40 +-
 drivers/media/usb/dvb-usb/dvb-usb-init.c   |  1 +
 drivers/media/usb/dvb-usb/dvb-usb.h|  9 +--
 7 files changed, 61 insertions(+), 95 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/af9005.c 
b/drivers/media/usb/dvb-usb/af9005.c
index b257780fb380..7853261906b1 100644
--- a/drivers/media/usb/dvb-usb/af9005.c
+++ b/drivers/media/usb/dvb-usb/af9005.c
@@ -53,7 +53,6 @@ struct af9005_device_state {
u8 sequence;
int led_state;
unsigned char data[256];
-   struct mutex data_mutex;
 };
 
 static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
@@ -72,7 +71,7 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
return -EINVAL;
}
 
-   mutex_lock(>data_mutex);
+   mutex_lock(>data_mutex);
st->data[0] = 14;   /* rest of buffer length low */
st->data[1] = 0;/* rest of buffer length high */
 
@@ -140,7 +139,7 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
values[i] = st->data[8 + i];
 
 ret:
-   mutex_unlock(>data_mutex);
+   mutex_unlock(>data_mutex);
return ret;
 
 }
@@ -481,7 +480,7 @@ int af9005_send_command(struct dvb_usb_device *d, u8 
command, u8 * wbuf,
}
packet_len = wlen + 5;
 
-   mutex_lock(>data_mutex);
+   mutex_lock(>data_mutex);
 
st->data[0] = (u8) (packet_len & 0xff);
st->data[1] = (u8) 

[PATCH 3/3] [media] gp8psk: Fix DVB frontend attach

2016-11-12 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

The DVB binding schema at the DVB core assumes that the
frontend is a separate driver. Faling to do that causes
OOPS when the module is removed, as it tries to do a
symbol_put_addr on an internal symbol, causing craches like:

 WARNING: CPU: 1 PID: 28102 at kernel/module.c:1108 module_put+0x57/0x70
 Modules linked in: dvb_usb_gp8psk(-) dvb_usb dvb_core nvidia_drm(PO) 
nvidia_modeset(PO) snd_hda_codec_hdmi snd_hda_intel snd_hda_codec snd_hwdep 
snd_hda_core snd_pcm snd_timer snd soundcore nvidia(PO) [last unloaded: rc_core]
 CPU: 1 PID: 28102 Comm: rmmod Tainted: PWC O 4.8.4-build.1 #1
 Hardware name: MSI MS-7309/MS-7309, BIOS V1.12 02/23/2009
  c12ba080   c103ed6a c1616014 0001 6dc6
 c1615862 0454 c109e8a7 c109e8a7 0009   f13f6a10
 f5f5a600 c103ee33 0009   c109e8a7 f80ca4d0 c109f617
 Call Trace:
  [] ? dump_stack+0x44/0x64
  [] ? __warn+0xfa/0x120
  [] ? module_put+0x57/0x70
  [] ? module_put+0x57/0x70
  [] ? warn_slowpath_null+0x23/0x30
  [] ? module_put+0x57/0x70
  [] ? gp8psk_fe_set_frontend+0x460/0x460 [dvb_usb_gp8psk]
  [] ? symbol_put_addr+0x27/0x50
  [] ? dvb_usb_adapter_frontend_exit+0x3a/0x70 [dvb_usb]

>From Derek's tests:
"Attach bug is fixed, tuning works, module unloads without
 crashing. Everything seems ok!"

Reported-by: Derek 
Tested-by: Derek 
Signed-off-by: Mauro Carvalho Chehab 

---
 drivers/media/dvb-frontends/Kconfig|   5 +
 drivers/media/dvb-frontends/Makefile   |   1 +
 .../{usb/dvb-usb => dvb-frontends}/gp8psk-fe.c | 139 -
 drivers/media/dvb-frontends/gp8psk-fe.h|  82 
 drivers/media/usb/dvb-usb/Makefile |   2 +-
 drivers/media/usb/dvb-usb/gp8psk.c | 106 +++-
 drivers/media/usb/dvb-usb/gp8psk.h |  63 --
 7 files changed, 246 insertions(+), 152 deletions(-)
 rename drivers/media/{usb/dvb-usb => dvb-frontends}/gp8psk-fe.c (72%)
 create mode 100644 drivers/media/dvb-frontends/gp8psk-fe.h

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 012225587c25..b71b747ee0ba 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -513,6 +513,11 @@ config DVB_AS102_FE
depends on DVB_CORE
default DVB_AS102
 
+config DVB_GP8PSK_FE
+   tristate
+   depends on DVB_CORE
+   default DVB_USB_GP8PSK
+
 comment "DVB-C (cable) frontends"
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index e90165ad361b..93921a4eaa27 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -121,6 +121,7 @@ obj-$(CONFIG_DVB_RTL2832_SDR) += rtl2832_sdr.o
 obj-$(CONFIG_DVB_M88RS2000) += m88rs2000.o
 obj-$(CONFIG_DVB_AF9033) += af9033.o
 obj-$(CONFIG_DVB_AS102_FE) += as102_fe.o
+obj-$(CONFIG_DVB_GP8PSK_FE) += gp8psk-fe.o
 obj-$(CONFIG_DVB_TC90522) += tc90522.o
 obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
 obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
diff --git a/drivers/media/usb/dvb-usb/gp8psk-fe.c 
b/drivers/media/dvb-frontends/gp8psk-fe.c
similarity index 72%
rename from drivers/media/usb/dvb-usb/gp8psk-fe.c
rename to drivers/media/dvb-frontends/gp8psk-fe.c
index db6eb79cde07..be19afeed7a9 100644
--- a/drivers/media/usb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb-frontends/gp8psk-fe.c
@@ -14,11 +14,27 @@
  *
  * see Documentation/dvb/README.dvb-usb for more information
  */
-#include "gp8psk.h"
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "gp8psk-fe.h"
+#include "dvb_frontend.h"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
+
+#define dprintk(fmt, arg...) do {  \
+   if (debug)  \
+   printk(KERN_DEBUG pr_fmt("%s: " fmt),   \
+  __func__, ##arg);\
+} while (0)
 
 struct gp8psk_fe_state {
struct dvb_frontend fe;
-   struct dvb_usb_device *d;
+   void *priv;
+   const struct gp8psk_fe_ops *ops;
+   bool is_rev1;
u8 lock;
u16 snr;
unsigned long next_status_check;
@@ -29,22 +45,24 @@ static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
 {
struct gp8psk_fe_state *st = fe->demodulator_priv;
u8 status;
-   gp8psk_usb_in_op(st->d, GET_8PSK_CONFIG, 0, 0, , 1);
+
+   st->ops->in(st->priv, GET_8PSK_CONFIG, 0, 0, , 1);
return status & bmDCtuned;
 }
 
 static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
 {
-   struct gp8psk_fe_state *state = fe->demodulator_priv;
-   return gp8psk_usb_out_op(state->d, 

[PATCH 0/3] Media fixes for Kernel 4.9-rc5

2016-11-12 Thread Mauro Carvalho Chehab
Hi Linus,

This patch series contain two patches fixing problems with my
patch series meant to make USB drivers to work again after the
DMA on stack changes.

The last patch on this series is actually not related to DMA on
stack. It solves a longstanding bug affecting module unload,
causing module_put() to be called twice. It was reported by the
user who reported and tested the issues with the gp8psk driver
with the DMA fixup patches. As we're late at -rc cycle, maybe you
prefer to not apply it right now. If this is the case, I'll
add to the pile of patches for 4.10.

Regards,
Mauro

PS.: Exceptionally this time, I'm sending the patches via e-mail,
because I'm on another trip, and won't be able to use the usual
procedure until Monday. Also, it is only three patches, and you
followed already the discussions about the first one.

Mauro Carvalho Chehab (3):
  [media] dvb-usb: move data_mutex to struct dvb_usb_device
  [media] gp8psk: fix gp8psk_usb_in_op() logic
  [media] gp8psk: Fix DVB frontend attach

 drivers/media/dvb-frontends/Kconfig|   5 +
 drivers/media/dvb-frontends/Makefile   |   1 +
 .../{usb/dvb-usb => dvb-frontends}/gp8psk-fe.c | 139 -
 drivers/media/dvb-frontends/gp8psk-fe.h|  82 
 drivers/media/usb/dvb-usb/Makefile |   2 +-
 drivers/media/usb/dvb-usb/af9005.c |  33 ++---
 drivers/media/usb/dvb-usb/cinergyT2-core.c |  33 ++---
 drivers/media/usb/dvb-usb/cxusb.c  |  39 +++---
 drivers/media/usb/dvb-usb/cxusb.h  |   1 -
 drivers/media/usb/dvb-usb/dtt200u.c|  40 +++---
 drivers/media/usb/dvb-usb/dvb-usb-init.c   |   1 +
 drivers/media/usb/dvb-usb/dvb-usb.h|   9 +-
 drivers/media/usb/dvb-usb/gp8psk.c | 111 +++-
 drivers/media/usb/dvb-usb/gp8psk.h |  63 --
 14 files changed, 310 insertions(+), 249 deletions(-)
 rename drivers/media/{usb/dvb-usb => dvb-frontends}/gp8psk-fe.c (72%)
 create mode 100644 drivers/media/dvb-frontends/gp8psk-fe.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


Re: [PATCH v2 00/11] getting back -Wmaybe-uninitialized

2016-11-12 Thread Jonathan Cameron
On 11/11/16 19:49, Arnd Bergmann wrote:
> On Friday, November 11, 2016 9:13:00 AM CET Linus Torvalds wrote:
>> On Thu, Nov 10, 2016 at 8:44 AM, Arnd Bergmann  wrote:
>>>
>>> Please merge these directly if you are happy with the result.
>>
>> I will take this.
> 
> Thanks a lot!
>  
>> I do see two warnings, but they both seem to be valid and recent,
>> though, so I have no issues with the spurious cases.
> 
> Ok, both of them should have my fixes coming your way already.
> 
>> Warning #1:
>>
>>   sound/soc/qcom/lpass-platform.c: In function ‘lpass_platform_pcmops_open’:
>>   sound/soc/qcom/lpass-platform.c:83:29: warning: ‘dma_ch’ may be used
>> uninitialized in this function [-Wmaybe-uninitialized]
>> drvdata->substream[dma_ch] = substream;
>> ~~~^~~
>>
>> and 'dma_ch' usage there really is crazy and wrong. Broken by
>> 022d00ee0b55 ("ASoC: lpass-platform: Fix broken pcm data usage")
> 
> Right, the patches crossed here, the bugfix patch that introduced
> this came into linux-next over the kernel summit, and the fix I
> sent on Tuesday made it into Mark Brown's tree on Wednesday but not
> before you pulled alsa tree. It should be fixed the next time you
> pull from the alsa tree, the commit is
> 
> 3b89e4b77ef9 ("ASoC: lpass-platform: initialize dma channel number")
>  
>> Warning #2 is not a real bug, but it's reasonable that gcc doesn't
>> know that storage_bytes (chip->read_size) has to be 2/4. Again,
>> introduced recently by commit 231147ee77f3 ("iio: maxim_thermocouple:
>> Align 16 bit big endian value of raw reads"), so you didn't see it.
> 
> This is the one I mentioned in the commit message as one that
> is fixed in linux-next and that should make it in soon.
> 
>>   drivers/iio/temperature/maxim_thermocouple.c: In function
>> ‘maxim_thermocouple_read_raw’:
>>   drivers/iio/temperature/maxim_thermocouple.c:141:5: warning: ‘ret’
>> may be used uninitialized in this function [-Wmaybe-uninitialized]
>> if (ret)
>>^
>>   drivers/iio/temperature/maxim_thermocouple.c:128:6: note: ‘ret’ was
>> declared here
>> int ret;
>> ^~~
>>
>> and I guess that code can just initialize 'ret' to '-EINVAL' or
>> something to just make the theoretical "somehow we had a wrong
>> chip->read_size" case error out cleanly.
> 
> Right, that was my conclusion too. I sent the bugfix on Oct 25
> for linux-next but it didn't make it in until this Monday, after
> you pulled the patch that introduced it on Oct 29.
> 
> The commit in staging-testing is
> 32cb7d27e65d ("iio: maxim_thermocouple: detect invalid storage size in 
> read()")
> 
> Greg and Jonathan, I see now that this is part of the 'iio-for-4.10b'
> branch, so I suspect you were not planning to send this before the
> merge window. Could you make sure this ends up in v4.9 so we get
> a clean build when -Wmaybe-uninitialized gets enabled again?
I'll queue this up and send a pull to Greg tomorrow.

Was highly doubtful that a false warning suppression (be it an
understandable one) was worth sending mid cycle, hence it was
taking the slow route.

Jonathan
> 
>   Arnd
> 

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


[PATCHv2 08/32] media: rcar-vin: move subdev source and sink pad index to rvin_graph_entity

2016-11-12 Thread Niklas Söderlund
Move the sink and source pad index from struct rvin_dev to struct
rvin_graph_entity. This is done in preparation of Gen3 support where the
active subdeivce can be changed during runtime. And if the subdevice is
changed the pad numbers are different so it's better to read them a
rvin_graph_entity then from directly from the rvin_dev.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 45 ++---
 drivers/media/platform/rcar-vin/rcar-vin.h  | 17 ++-
 2 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 370bb18..f8ff7c4 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -109,9 +109,14 @@ static int rvin_reset_format(struct rvin_dev *vin)
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
struct v4l2_mbus_framefmt *mf = 
+   struct rvin_graph_entity *rent;
int ret;
 
-   fmt.pad = vin->src_pad_idx;
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
+   fmt.pad = rent->source_pad_idx;
 
ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, );
if (ret)
@@ -182,7 +187,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
if (pad_cfg == NULL)
return -ENOMEM;
 
-   format.pad = vin->src_pad_idx;
+   format.pad = rent->source_pad_idx;
 
field = pix->field;
 
@@ -560,12 +565,17 @@ static int rvin_enum_dv_timings(struct file *file, void 
*priv_fh,
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
+   struct rvin_graph_entity *rent;
int ret;
 
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
if (timings->pad)
return -EINVAL;
 
-   timings->pad = vin->sink_pad_idx;
+   timings->pad = rent->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
 
@@ -612,12 +622,17 @@ static int rvin_dv_timings_cap(struct file *file, void 
*priv_fh,
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
+   struct rvin_graph_entity *rent;
int ret;
 
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
if (cap->pad)
return -EINVAL;
 
-   cap->pad = vin->sink_pad_idx;
+   cap->pad = rent->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
 
@@ -630,12 +645,17 @@ static int rvin_g_edid(struct file *file, void *fh, 
struct v4l2_edid *edid)
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
+   struct rvin_graph_entity *rent;
int ret;
 
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
if (edid->pad)
return -EINVAL;
 
-   edid->pad = vin->sink_pad_idx;
+   edid->pad = rent->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, get_edid, edid);
 
@@ -648,12 +668,17 @@ static int rvin_s_edid(struct file *file, void *fh, 
struct v4l2_edid *edid)
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
+   struct rvin_graph_entity *rent;
int ret;
 
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
if (edid->pad)
return -EINVAL;
 
-   edid->pad = vin->sink_pad_idx;
+   edid->pad = rent->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, set_edid, edid);
 
@@ -926,19 +951,19 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE;
 
-   vin->src_pad_idx = 0;
+   vin->digital.source_pad_idx = 0;
for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SOURCE)
break;
if (pad_idx >= sd->entity.num_pads)
return -EINVAL;
 
-   vin->src_pad_idx = pad_idx;
+   vin->digital.source_pad_idx = pad_idx;
 
-   vin->sink_pad_idx = 0;
+   vin->digital.sink_pad_idx = 0;
for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SINK) {
-   vin->sink_pad_idx = pad_idx;
+   vin->digital.sink_pad_idx = pad_idx;
break;
}
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index daec26a..d31212a 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -70,10 

[PATCHv2 00/32] rcar-vin: Add Gen3 with media controller support

2016-11-12 Thread Niklas Söderlund
Hi All,

This series enable Gen3 VIN support in rcar-vin driver for Renesas
r8a7795 and r8a7796. It is based on top of v4.9-rc1.

Parts of this series was previously part of an different series from me
which enabled Gen3 support in a different way (using s_input instead of
a media controller) but after feedback during ELCE the Gen3 enablement
is now almost completely rewritten.

 Patch 1-2: pick-up media entity features from Laurent which the driver
 depends on.

 Patch 3-5: fix small issues in the driver.

 Patch 6-13: changes the driver from attaching to a video source
 subdevice at probe time to when the video device node (/dev/videoX) are
 opened. It also allows for the subdevice which is attached is not the
 same as last time it was opened, but only at the time the first user
 opens, i.e. when v4l2_fh_is_singular_file() is true.

 Patch 14-15: prepare the internal data structures for Gen3.

 Patch 16-17: small refactoring preparing for Gen3 additions.

 Patch 18-19: add logic to work with the Gen3 hardware registers

 Patch 20-24: add media control support, link setup and link notify
 handlers.

 Patch 25-29: add logic to the driver to work together with the media
 controller.

 Patch 30-32: document the new Gen3 DT bindings, add r8a7795 and r8a7796
 definitions and device info structures.

The driver is tested on both Renesas H3 (r8a7795) and M3-W (r8a7796)
together with the new rcar-csi2 driver (posted separately) and a
prototype driver of the ADV7482 (not ready for upstream but publicly
available). It is possible to capture both CVBS and HDMI video streams,
v4l2-compliance passes with no errors (there is one warning due the
ADV7482 driver) and media-ctl can be used to change the routing from the
different CSI-2 sources to the different VIN consumers.

Gen2 compatibility is verified on Koelsch and no problems where found,
video can be captured just like before and v4l2-compliance passes
without errors or warnings.

I have started on a very basic test suite for the VIN driver at:

  https://git.ragnatech.se/vin-tests

And as before the state of the driver and information about how to test it can 
be found on the elinux wiki:

  http://elinux.org/R-Car/Tests:rcar-vin

* Changes since v1
- Remove unneeded casts as pointed out by Geert.
- Fix spelling and DT documentation as pointed out by Geert and Sergei, thanks!
- Refresh patch 2/32 with an updated version, thanks Sakari for pointing this 
  out.
- Add Sakaris Ack to patch 1/32.
- Rebase on top of v4.9-rc1 instead of v4.9-rc3 to ease integration testing 
  together with renesas-drivers tree.

Laurent Pinchart (2):
  media: entity: Add has_route entity operation
  media: entity: Add media_entity_has_route() function

Niklas Söderlund (30):
  media: rcar-vin: reset bytesperline and sizeimage when resetting
format
  media: rcar-vin: use rvin_reset_format() in S_DV_TIMINGS
  media: rcar-vin: fix how pads are handled for v4l2 subdeivce
operations
  media: rcar-vin: fix standard in input enumeration
  media: rcar-vin: add wrapper to get rvin_graph_entity
  media: rcar-vin: move subdev source and sink pad index to
rvin_graph_entity
  media: rcar-vin: move pad number discovery to async complete handler
  media: rcar-vin: use pad information when verifying media bus format
  media: rcar-vin: refactor pad lookup code
  media: rcar-vin: split rvin_s_fmt_vid_cap()
  media: rcar-vin: register the video device early
  media: rcar-vin: move chip information to own struct
  media: rcar-vin: move max width and height information to chip
information
  media: rcar-vin: change name of video device
  media: rcar-vin: clarify error message from the digital notifier
  media: rcar-vin: enable Gen3 hardware configuration
  media: rcar-vin: add functions to manipulate Gen3 CHSEL value
  media: rcar-vin: expose a sink pad if we are on Gen3
  media: rcar-vin: add group allocator functions
  media: rcar-vin: add chsel information to rvin_info
  media: rcar-vin: parse Gen3 OF and setup media graph
  media: rcar-vin: add link notify for Gen3
  media: rcar-vin: enable CSI2 group subdevices in lookup helpers
  media: rcar-vin: add helpers for bridge
  media: rcar-vin: start/stop the CSI2 bridge stream
  media: rcar-vin: propagate format to bridge
  media: rcar-vin: attach to CSI2 group when the video device is opened
  media: rcar-vin: add Gen3 devicetree bindings documentation
  media: rcar-vin: enable support for r8a7795
  media: rcar-vin: enable support for r8a7796

 .../devicetree/bindings/media/rcar_vin.txt |  117 +-
 drivers/media/media-entity.c   |   16 +
 drivers/media/platform/rcar-vin/Kconfig|2 +-
 drivers/media/platform/rcar-vin/rcar-core.c| 1138 +++-
 drivers/media/platform/rcar-vin/rcar-dma.c |  240 -
 drivers/media/platform/rcar-vin/rcar-v4l2.c|  394 ---
 drivers/media/platform/rcar-vin/rcar-vin.h |  112 +-
 include/media/media-entity.h   

[PATCHv2 06/32] media: rcar-vin: fix standard in input enumeration

2016-11-12 Thread Niklas Söderlund
If the subdevice supports dv_timings_cap the driver should not fill in
the standard. Also don't use the standard from probe time ask the
subdevice each time, this is done in preparation for Gen3 support where
the source subdevice might change during runtime.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 610f59e..f9218f2 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -483,10 +483,16 @@ static int rvin_enum_input(struct file *file, void *priv,
return ret;
 
i->type = V4L2_INPUT_TYPE_CAMERA;
-   i->std = vin->vdev.tvnorms;
 
-   if (v4l2_subdev_has_op(sd, pad, dv_timings_cap))
+   if (v4l2_subdev_has_op(sd, pad, dv_timings_cap)) {
i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
+   i->std = 0;
+   } else {
+   i->capabilities = V4L2_IN_CAP_STD;
+   ret = v4l2_subdev_call(sd, video, g_tvnorms, >std);
+   if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+   return ret;
+   }
 
strlcpy(i->name, "Camera", sizeof(i->name));
 
-- 
2.10.2

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


[PATCHv2 02/32] media: entity: Add media_entity_has_route() function

2016-11-12 Thread Niklas Söderlund
From: Laurent Pinchart 

This is a wrapper around the media entity has_route operation.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Michal Simek 
Signed-off-by: Sakari Ailus 
Signed-off-by: Niklas Söderlund 
---
 drivers/media/media-entity.c | 16 
 include/media/media-entity.h | 17 +
 2 files changed, 33 insertions(+)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index c68239e..58d9fa6 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -242,6 +242,22 @@ EXPORT_SYMBOL_GPL(media_entity_pads_init);
  * Graph traversal
  */
 
+bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
+   unsigned int pad1)
+{
+   if (pad0 >= entity->num_pads || pad1 >= entity->num_pads)
+   return false;
+
+   if (pad0 == pad1)
+   return true;
+
+   if (!entity->ops || !entity->ops->has_route)
+   return true;
+
+   return entity->ops->has_route(entity, pad0, pad1);
+}
+EXPORT_SYMBOL_GPL(media_entity_has_route);
+
 static struct media_entity *
 media_entity_other(struct media_entity *entity, struct media_link *link)
 {
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8f9fc85..01e2876 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -834,6 +834,23 @@ __must_check int media_entity_graph_walk_init(
struct media_entity_graph *graph, struct media_device *mdev);
 
 /**
+ * media_entity_has_route - Check if two entity pads are connected internally
+ *
+ * @entity: The entity
+ * @pad0: The first pad index
+ * @pad1: The second pad index
+ *
+ * This function can be used to check whether two pads of an entity are
+ * connected internally in the entity.
+ *
+ * The caller must hold entity->graph_obj.mdev->mutex.
+ *
+ * Return: true if the pads are connected internally and false otherwise.
+ */
+bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
+   unsigned int pad1);
+
+/**
  * media_entity_graph_walk_cleanup - Release resources used by graph walk.
  *
  * @graph: Media graph structure that will be used to walk the graph
-- 
2.10.2

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


[PATCHv2 07/32] media: rcar-vin: add wrapper to get rvin_graph_entity

2016-11-12 Thread Niklas Söderlund
Update the driver to retrieve the code and mbus_cfg values from a
rvin_graph_entity retrieved from a wrapper function instead of directly
accessing the entity for the digital port. This is done to prepare for
Gen3 support where the subdeivce might change during runtime, so to
directly accesses a specific rvin_graph_entity is bad.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c |  9 +
 drivers/media/platform/rcar-vin/rcar-dma.c  | 15 ++-
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  6 +-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  1 +
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 098a0b1..89a9280 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -26,6 +26,15 @@
 #include "rcar-vin.h"
 
 /* 
-
+ * Subdevice helpers
+ */
+
+struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin)
+{
+   return >digital;
+}
+
+/* 
-
  * Async notifier
  */
 
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 9ccd5ff..eac5c19 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -131,10 +131,15 @@ static u32 rvin_read(struct rvin_dev *vin, u32 offset)
 
 static int rvin_setup(struct rvin_dev *vin)
 {
+   struct rvin_graph_entity *rent;
u32 vnmc, dmr, dmr2, interrupts;
v4l2_std_id std;
bool progressive = false, output_is_yuv = false, input_is_yuv = false;
 
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
switch (vin->format.field) {
case V4L2_FIELD_TOP:
vnmc = VNMC_IM_ODD;
@@ -174,7 +179,7 @@ static int rvin_setup(struct rvin_dev *vin)
/*
 * Input interface
 */
-   switch (vin->digital.code) {
+   switch (rent->code) {
case MEDIA_BUS_FMT_YUYV8_1X16:
/* BT.601/BT.1358 16bit YCbCr422 */
vnmc |= VNMC_INF_YUV16;
@@ -182,7 +187,7 @@ static int rvin_setup(struct rvin_dev *vin)
break;
case MEDIA_BUS_FMT_UYVY8_2X8:
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
-   vnmc |= vin->digital.mbus_cfg.type == V4L2_MBUS_BT656 ?
+   vnmc |= rent->mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
input_is_yuv = true;
break;
@@ -191,7 +196,7 @@ static int rvin_setup(struct rvin_dev *vin)
break;
case MEDIA_BUS_FMT_UYVY10_2X10:
/* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
-   vnmc |= vin->digital.mbus_cfg.type == V4L2_MBUS_BT656 ?
+   vnmc |= rent->mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
input_is_yuv = true;
break;
@@ -203,11 +208,11 @@ static int rvin_setup(struct rvin_dev *vin)
dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
/* Hsync Signal Polarity Select */
-   if (!(vin->digital.mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
+   if (!(rent->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
dmr2 |= VNDMR2_HPS;
 
/* Vsync Signal Polarity Select */
-   if (!(vin->digital.mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
+   if (!(rent->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
dmr2 |= VNDMR2_VPS;
 
/*
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index f9218f2..370bb18 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -164,6 +164,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 {
struct v4l2_subdev *sd;
struct v4l2_subdev_pad_config *pad_cfg;
+   struct rvin_graph_entity *rent;
struct v4l2_subdev_format format = {
.which = which,
};
@@ -171,8 +172,11 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
int ret;
 
sd = vin_to_source(vin);
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
 
-   v4l2_fill_mbus_format(, pix, vin->digital.code);
+   v4l2_fill_mbus_format(, pix, rent->code);
 
pad_cfg = v4l2_subdev_alloc_pad_config(sd);
if (pad_cfg == NULL)
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 727e215..daec26a 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -144,6 +144,7 

[PATCHv2 12/32] media: rcar-vin: split rvin_s_fmt_vid_cap()

2016-11-12 Thread Niklas Söderlund
The functionality provided by rvin_s_fmt_vid_cap() will be needed in
other places to add Gen3 support. Split it up in a function which do the
work and one which interface with the v4l2 API.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 51324c6..929f58b 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -313,10 +313,8 @@ static int rvin_try_fmt_vid_cap(struct file *file, void 
*priv,
 );
 }
 
-static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
- struct v4l2_format *f)
+static int __rvin_s_fmt_vid_cap(struct rvin_dev *vin, struct v4l2_format *f)
 {
-   struct rvin_dev *vin = video_drvdata(file);
struct rvin_source_fmt source;
int ret;
 
@@ -338,6 +336,14 @@ static int rvin_s_fmt_vid_cap(struct file *file, void 
*priv,
return 0;
 }
 
+static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
+ struct v4l2_format *f)
+{
+   struct rvin_dev *vin = video_drvdata(file);
+
+   return __rvin_s_fmt_vid_cap(vin, f);
+}
+
 static int rvin_g_fmt_vid_cap(struct file *file, void *priv,
  struct v4l2_format *f)
 {
-- 
2.10.2

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


[PATCHv2 19/32] media: rcar-vin: add functions to manipulate Gen3 CHSEL value

2016-11-12 Thread Niklas Söderlund
On Gen3 the CSI routing is controlled by the VnCSI_IFMD register. One
feature of this register is that it's only present in the VIN0 and VIN4
instances. The register in VIN0 controls the routing for VIN0-3 and the
register in VIN4 controls routing for VIN4-7.

To be able to control routing from a media device these functions need
to control runtime PM for the subgroup master (VIN0 and VIN4). The
subgroup master must be switched on before the register is manipulated,
once the operation is complete it's safe to switch the master off and
the new routing will still be in effect.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 43 ++
 drivers/media/platform/rcar-vin/rcar-vin.h |  3 +++
 2 files changed, 46 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 80958e6..322e4c1 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -16,6 +16,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1247,3 +1248,45 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq)
 
return ret;
 }
+
+/* 
-
+ * Gen3 CHSEL manipulation
+ */
+
+int rvin_set_chsel(struct rvin_dev *vin, u8 chsel)
+{
+   u32 ifmd;
+
+   pm_runtime_get_sync(vin->dev);
+
+   /*
+* Undocumented feature: Writing to VNCSI_IFMD_REG will go
+* through and on read back look correct but won't have
+* any effect if VNMC_REG is not first set to 0.
+*/
+   rvin_write(vin, 0, VNMC_REG);
+
+   ifmd = VNCSI_IFMD_DES2 | VNCSI_IFMD_DES1 | VNCSI_IFMD_DES0 |
+   VNCSI_IFMD_CSI_CHSEL(chsel);
+
+   rvin_write(vin, ifmd, VNCSI_IFMD_REG);
+
+   vin_dbg(vin, "Set IFMD 0x%x\n", ifmd);
+
+   pm_runtime_put(vin->dev);
+
+   return 0;
+}
+
+int rvin_get_chsel(struct rvin_dev *vin)
+{
+   int chsel;
+
+   pm_runtime_get_sync(vin->dev);
+
+   chsel = rvin_read(vin, VNCSI_IFMD_REG) & VNCSI_IFMD_CSI_CHSEL_MASK;
+
+   pm_runtime_put(vin->dev);
+
+   return chsel;
+}
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index b8f5634..a6a49a96 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -184,4 +184,7 @@ void rvin_scale_try(struct rvin_dev *vin, struct 
v4l2_pix_format *pix,
u32 width, u32 height);
 void rvin_crop_scale_comp(struct rvin_dev *vin);
 
+int rvin_set_chsel(struct rvin_dev *vin, u8 chsel);
+int rvin_get_chsel(struct rvin_dev *vin);
+
 #endif
-- 
2.10.2

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


[PATCHv2 15/32] media: rcar-vin: move max width and height information to chip information

2016-11-12 Thread Niklas Söderlund
On Gen3 the max supported width and height will be different from Gen2.
Move the limits to the struct chip_info to prepare for Gen3 support.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 6 ++
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++
 drivers/media/platform/rcar-vin/rcar-vin.h  | 6 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index c80bbbc..def240b1 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -255,14 +255,20 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
 
 static const struct rvin_info rcar_info_h1 = {
.chip = RCAR_H1,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_m1 = {
.chip = RCAR_M1,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_gen2 = {
.chip = RCAR_GEN2,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct of_device_id rvin_of_id_table[] = {
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 05b0181..f5fbe9f 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -23,8 +23,6 @@
 #include "rcar-vin.h"
 
 #define RVIN_DEFAULT_FORMATV4L2_PIX_FMT_YUYV
-#define RVIN_MAX_WIDTH 2048
-#define RVIN_MAX_HEIGHT2048
 
 /* 
-
  * Format Conversions
@@ -271,8 +269,8 @@ static int __rvin_try_format(struct rvin_dev *vin,
walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
 
/* Limit to VIN capabilities */
-   v4l_bound_align_image(>width, 2, RVIN_MAX_WIDTH, walign,
- >height, 4, RVIN_MAX_HEIGHT, 2, 0);
+   v4l_bound_align_image(>width, 2, vin->info->max_width, walign,
+ >height, 4, vin->info->max_height, 2, 0);
 
pix->bytesperline = max_t(u32, pix->bytesperline,
  rvin_format_bytesperline(pix));
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 17a5fce..ddeca9f 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -91,9 +91,15 @@ struct rvin_graph_entity {
 /**
  * struct rvin_info- Information about the particular VIN implementation
  * @chip:  type of VIN chip
+ *
+ * max_width:  max input with the VIN supports
+ * max_height: max input height the VIN supports
  */
 struct rvin_info {
enum chip_id chip;
+
+   unsigned int max_width;
+   unsigned int max_height;
 };
 
 /**
-- 
2.10.2

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


[PATCHv2 22/32] media: rcar-vin: add chsel information to rvin_info

2016-11-12 Thread Niklas Söderlund
Each Gen3 SoC have a limited set of predefined routing possibilities for
which CSI2 device and virtual channel can be routed to which VIN
instance.  Prepare to store this information in the struct rvin_info.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-vin.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 90c28a7..cd7d959 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -35,6 +35,9 @@
 /* Max number on VIN instances that can be in a system */
 #define RCAR_VIN_NUM 8
 
+/* Max number of CHSEL values for any Gen3 SoC */
+#define RCAR_CHSEL_MAX 6
+
 enum chip_id {
RCAR_H1,
RCAR_M1,
@@ -111,6 +114,16 @@ struct rvin_graph_entity {
 
 struct rvin_group;
 
+
+/** struct rvin_group_chsel - Map a CSI2 device and channel for a CHSEL value
+ * @csi:   VIN internal number for CSI2 device
+ * @chan:  CSI2 VC number on remote
+ */
+struct rvin_group_chsel {
+   enum rvin_csi_id csi;
+   int chan;
+};
+
 /**
  * struct rvin_info- Information about the particular VIN implementation
  * @chip:  type of VIN chip
@@ -123,6 +136,9 @@ struct rvin_info {
 
unsigned int max_width;
unsigned int max_height;
+
+   unsigned int num_chsels;
+   struct rvin_group_chsel chsels[RCAR_VIN_NUM][RCAR_CHSEL_MAX];
 };
 
 /**
-- 
2.10.2

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


[PATCHv2 04/32] media: rcar-vin: use rvin_reset_format() in S_DV_TIMINGS

2016-11-12 Thread Niklas Söderlund
Use rvin_reset_format() in rvin_s_dv_timings() instead if just resetting
a few fields. This fixes an issue where the field format was not
properly set after S_DV_TIMINGS.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 69bc4cf..7ca2759 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -573,12 +573,8 @@ static int rvin_s_dv_timings(struct file *file, void 
*priv_fh,
if (ret)
return ret;
 
-   vin->source.width = timings->bt.width;
-   vin->source.height = timings->bt.height;
-   vin->format.width = timings->bt.width;
-   vin->format.height = timings->bt.height;
-
-   return 0;
+   /* Changing the timings will change the width/height */
+   return rvin_reset_format(vin);
 }
 
 static int rvin_g_dv_timings(struct file *file, void *priv_fh,
-- 
2.10.2

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


[PATCHv2 05/32] media: rcar-vin: fix how pads are handled for v4l2 subdeivce operations

2016-11-12 Thread Niklas Söderlund
The rcar-vin driver only uses one pad, pad number 0.

 All v4l2 operations which did not check that the requested operation
 was for pad 0 have been updated with a check to enforce this.

 All v4l2 operations that stored (and later restore) the requested pad
 before substituting it for the subdeivce pad number have been update
 not store the incoming pad and simply restore it to 0 after the
 subdevice operation is complete.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 7ca2759..610f59e 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -550,14 +550,16 @@ static int rvin_enum_dv_timings(struct file *file, void 
*priv_fh,
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
-   int pad, ret;
+   int ret;
+
+   if (timings->pad)
+   return -EINVAL;
 
-   pad = timings->pad;
timings->pad = vin->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
 
-   timings->pad = pad;
+   timings->pad = 0;
 
return ret;
 }
@@ -600,14 +602,16 @@ static int rvin_dv_timings_cap(struct file *file, void 
*priv_fh,
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
-   int pad, ret;
+   int ret;
+
+   if (cap->pad)
+   return -EINVAL;
 
-   pad = cap->pad;
cap->pad = vin->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
 
-   cap->pad = pad;
+   cap->pad = 0;
 
return ret;
 }
@@ -616,17 +620,16 @@ static int rvin_g_edid(struct file *file, void *fh, 
struct v4l2_edid *edid)
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
-   int input, ret;
+   int ret;
 
if (edid->pad)
return -EINVAL;
 
-   input = edid->pad;
edid->pad = vin->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, get_edid, edid);
 
-   edid->pad = input;
+   edid->pad = 0;
 
return ret;
 }
@@ -635,17 +638,16 @@ static int rvin_s_edid(struct file *file, void *fh, 
struct v4l2_edid *edid)
 {
struct rvin_dev *vin = video_drvdata(file);
struct v4l2_subdev *sd = vin_to_source(vin);
-   int input, ret;
+   int ret;
 
if (edid->pad)
return -EINVAL;
 
-   input = edid->pad;
edid->pad = vin->sink_pad_idx;
 
ret = v4l2_subdev_call(sd, pad, set_edid, edid);
 
-   edid->pad = input;
+   edid->pad = 0;
 
return ret;
 }
-- 
2.10.2

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


[PATCHv2 09/32] media: rcar-vin: move pad number discovery to async complete handler

2016-11-12 Thread Niklas Söderlund
The rvin_v4l2_probe() handler will with Gen3 support need to handle more
then one subdevice. To prepare for this move the digital subdev pad
number discover to the digital specific async notification complete
function.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 23 +++
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 18 +-
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 89a9280..2c40b6a 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -68,6 +68,8 @@ static bool rvin_mbus_supported(struct rvin_graph_entity 
*entity)
 static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
+   struct v4l2_subdev *sd = vin->digital.subdev;
+   unsigned int pad_idx;
int ret;
 
/* Verify subdevices mbus format */
@@ -80,6 +82,27 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
vin_dbg(vin, "Found media bus format for %s: %d\n",
vin->digital.subdev->name, vin->digital.code);
 
+   /* Figure out source and sink pad ids */
+   vin->digital.source_pad_idx = 0;
+   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
+   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SOURCE)
+   break;
+   if (pad_idx >= sd->entity.num_pads)
+   return -EINVAL;
+
+   vin->digital.source_pad_idx = pad_idx;
+
+   vin->digital.sink_pad_idx = 0;
+   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
+   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SINK) {
+   vin->digital.sink_pad_idx = pad_idx;
+   break;
+   }
+
+   vin_dbg(vin, "Found media pads for %s source: %d sink %d\n",
+   vin->digital.subdev->name, vin->digital.source_pad_idx,
+   vin->digital.sink_pad_idx);
+
ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
if (ret < 0) {
vin_err(vin, "Failed to register subdev nodes\n");
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index f8ff7c4..51324c6 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -905,7 +905,7 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
 {
struct video_device *vdev = >vdev;
struct v4l2_subdev *sd = vin_to_source(vin);
-   int pad_idx, ret;
+   int ret;
 
v4l2_set_subdev_hostdata(sd, vin);
 
@@ -951,22 +951,6 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE;
 
-   vin->digital.source_pad_idx = 0;
-   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
-   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SOURCE)
-   break;
-   if (pad_idx >= sd->entity.num_pads)
-   return -EINVAL;
-
-   vin->digital.source_pad_idx = pad_idx;
-
-   vin->digital.sink_pad_idx = 0;
-   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
-   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SINK) {
-   vin->digital.sink_pad_idx = pad_idx;
-   break;
-   }
-
vin->format.pixelformat = RVIN_DEFAULT_FORMAT;
rvin_reset_format(vin);
 
-- 
2.10.2

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


[PATCHv2 11/32] media: rcar-vin: refactor pad lookup code

2016-11-12 Thread Niklas Söderlund
The code to lookup which pad is source and sink can be broken out to a
helper function.

A bad check is also dropped in this refactoring. If the subdeivce don't
supply pad information the driver would not be able to use it if the
check is kept.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index fb6368c..50058fe 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -66,11 +66,21 @@ static bool rvin_mbus_supported(struct rvin_graph_entity 
*entity)
return false;
 }
 
+static unsigned int rvin_pad_idx(struct v4l2_subdev *sd, int direction)
+{
+   unsigned int pad_idx;
+
+   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
+   if (sd->entity.pads[pad_idx].flags == direction)
+   return pad_idx;
+
+   return 0;
+}
+
 static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
struct v4l2_subdev *sd = vin->digital.subdev;
-   unsigned int pad_idx;
int ret;
 
/* Verify subdevices mbus format */
@@ -84,21 +94,8 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
vin->digital.subdev->name, vin->digital.code);
 
/* Figure out source and sink pad ids */
-   vin->digital.source_pad_idx = 0;
-   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
-   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SOURCE)
-   break;
-   if (pad_idx >= sd->entity.num_pads)
-   return -EINVAL;
-
-   vin->digital.source_pad_idx = pad_idx;
-
-   vin->digital.sink_pad_idx = 0;
-   for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
-   if (sd->entity.pads[pad_idx].flags == MEDIA_PAD_FL_SINK) {
-   vin->digital.sink_pad_idx = pad_idx;
-   break;
-   }
+   vin->digital.source_pad_idx = rvin_pad_idx(sd, MEDIA_PAD_FL_SOURCE);
+   vin->digital.sink_pad_idx = rvin_pad_idx(sd, MEDIA_PAD_FL_SINK);
 
vin_dbg(vin, "Found media pads for %s source: %d sink %d\n",
vin->digital.subdev->name, vin->digital.source_pad_idx,
-- 
2.10.2

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


[PATCHv2 13/32] media: rcar-vin: register the video device early

2016-11-12 Thread Niklas Söderlund
This is done to prepare for Gen3 support where there can be more then
one video pipeline which can terminate in a particular VIN instance.
Each pipeline have its own set of subdevices so to attach to a specific
subdevice at probe time is not possible. The pipelines will be
configured using the media controller API.

This patch changes the rcar-vin behavior so that the video device is
registered at probe time but attaching to a subdeivce is only once the
video device node is opened. If at that time there is no video source
subdevice for the VIN to use the open will fail with -EBUSY.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c |  10 +-
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 226 ++--
 drivers/media/platform/rcar-vin/rcar-vin.h  |   2 +
 3 files changed, 121 insertions(+), 117 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 50058fe..5807d8d 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -107,7 +107,7 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
return ret;
}
 
-   return rvin_v4l2_probe(vin);
+   return 0;
 }
 
 static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier,
@@ -118,7 +118,6 @@ static void rvin_digital_notify_unbind(struct 
v4l2_async_notifier *notifier,
 
if (vin->digital.subdev == subdev) {
vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
-   rvin_v4l2_remove(vin);
vin->digital.subdev = NULL;
return;
}
@@ -283,6 +282,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
 
vin->dev = >dev;
vin->chip = (enum chip_id)match->data;
+   vin->last_input = NULL;
 
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (mem == NULL)
@@ -304,6 +304,10 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (ret < 0)
goto error;
 
+   ret = rvin_v4l2_probe(vin);
+   if (ret)
+   goto error;
+
pm_suspend_ignore_children(>dev, true);
pm_runtime_enable(>dev);
 
@@ -322,6 +326,8 @@ static int rcar_vin_remove(struct platform_device *pdev)
 
pm_runtime_disable(>dev);
 
+   rvin_v4l2_remove(vin);
+
v4l2_async_notifier_unregister(>notifier);
 
rvin_dma_remove(vin);
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 929f58b..47137d7 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -483,6 +483,94 @@ static int rvin_cropcap(struct file *file, void *priv,
return v4l2_subdev_call(sd, video, g_pixelaspect, >pixelaspect);
 }
 
+static int rvin_attach_subdevices(struct rvin_dev *vin)
+{
+   struct v4l2_subdev_format fmt = {
+   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+   };
+   struct v4l2_mbus_framefmt *mf = 
+   struct v4l2_subdev *sd = vin_to_source(vin);
+   struct rvin_graph_entity *rent;
+   struct v4l2_format f;
+   int ret;
+
+   rent = vin_to_entity(vin);
+   if (!rent)
+   return -ENODEV;
+
+   ret = v4l2_subdev_call(sd, core, s_power, 1);
+   if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+   return ret;
+
+   if (rent != vin->last_input) {
+   /* Input source have changed, reset our format */
+
+   vin->vdev.tvnorms = 0;
+   ret = v4l2_subdev_call(sd, video, g_tvnorms,
+  >vdev.tvnorms);
+   if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+   goto error;
+
+   /* Free old controls (safe even if there where none) */
+   v4l2_ctrl_handler_free(>ctrl_handler);
+
+   ret = v4l2_ctrl_handler_init(>ctrl_handler, 16);
+   if (ret < 0)
+   goto error;
+
+   /* Add new controls */
+   ret = v4l2_ctrl_add_handler(>ctrl_handler,
+   sd->ctrl_handler, NULL);
+   if (ret < 0)
+   goto error;
+
+   v4l2_ctrl_handler_setup(>ctrl_handler);
+
+   fmt.pad = rent->source_pad_idx;
+
+   /* Try to improve our guess of a reasonable window format */
+   ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, );
+   if (ret)
+   goto error;
+
+   /* Set default format */
+   vin->format.width   = mf->width;
+   vin->format.height  = mf->height;
+   vin->format.colorspace  = mf->colorspace;
+   vin->format.field   = mf->field;
+   vin->format.pixelformat 

[PATCHv2 28/32] media: rcar-vin: propagate format to bridge

2016-11-12 Thread Niklas Söderlund
The CSI2 bridge needs to know the video format, propagate it after the
video source have had its say on the format.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index e99815f..d363531 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -193,6 +193,21 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
if (ret < 0 && ret != -ENOIOCTLCMD)
goto done;
 
+   /* If we are part of a CSI2 group update bridge */
+   if (vin_have_bridge(vin)) {
+   struct v4l2_subdev *bridge = vin_to_bridge(vin);
+
+   if (!bridge) {
+   ret = -EINVAL;
+   goto done;
+   }
+
+   format.pad = 0;
+   ret = v4l2_subdev_call(bridge, pad, set_fmt, pad_cfg, );
+   if (ret < 0 && ret != -ENOIOCTLCMD)
+   goto done;
+   }
+
v4l2_fill_pix_format(pix, );
 
pix->field = field;
-- 
2.10.2

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


[PATCHv2 01/32] media: entity: Add has_route entity operation

2016-11-12 Thread Niklas Söderlund
From: Laurent Pinchart 

The optional operation can be used by entities to report whether two
pads are internally connected.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Michal Simek 
Signed-off-by: Niklas Söderlund 
Acked-by: Sakari Ailus 
---
 include/media/media-entity.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index b2203ee..8f9fc85 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -181,6 +181,9 @@ struct media_pad {
  * @link_validate: Return whether a link is valid from the entity point of
  * view. The media_entity_pipeline_start() function
  * validates all links by calling this operation. Optional.
+ * @has_route: Return whether a route exists inside the entity between
+ * two given pads. Optional. If the operation isn't
+ * implemented all pads will be considered as connected.
  *
  * .. note::
  *
@@ -192,6 +195,8 @@ struct media_entity_operations {
  const struct media_pad *local,
  const struct media_pad *remote, u32 flags);
int (*link_validate)(struct media_link *link);
+   bool (*has_route)(struct media_entity *entity, unsigned int pad0,
+ unsigned int pad1);
 };
 
 /**
-- 
2.10.2

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


[PATCHv2 24/32] media: rcar-vin: add link notify for Gen3

2016-11-12 Thread Niklas Söderlund
Add the ability to process media device link change request. Link
enablement are a bit complicated on Gen3, if it's possible to enable a
link depends on what other links already are enabled. On Gen3 the 8 VIN
are split into two subgroups (VIN0-3 and VIN4-7) and from a routing
perspective these two groups are independent of each other. Each
subgroups routing is controlled by the subgroup VIN master instance
(VIN0 and VIN4).

There are a limited number of possible route setups available for each
subgroup and the configuration of each setup is dictated by the
hardware. On H3 for example there are 6 possible route setups for each
subgroup to choose from.

This leads to the media device link notification code being rather large
since it will find the best routing configuration to try and accommodate
as many links as possible. When it's not possible to enable a new link
due to hardware constrains the link_notifier callback will return
-EBUSY.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 205 
 1 file changed, 205 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index de75ca8..0092ab4 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -26,6 +26,209 @@
 #include "rcar-vin.h"
 
 /* 
-
+ * Media Controller link notification
+ */
+
+static unsigned int rvin_group_csi_pad_to_chan(unsigned int pad)
+{
+   /*
+* The CSI2 driver is rcar-csi2 and we know it's pad layout are
+* 0: Source 1-4: Sinks so if we remove one from the pad we
+* get the rcar-vin internal CSI2 channel number
+*/
+   return pad - 1;
+}
+
+/* group lock should be held when calling this function */
+static int rvin_group_entity_to_vin_num(struct rvin_group *group,
+   struct media_entity *entity)
+{
+   struct video_device *vdev;
+   int i;
+
+   if (!is_media_entity_v4l2_video_device(entity))
+   return -ENODEV;
+
+   vdev = media_entity_to_video_device(entity);
+
+   for (i = 0; i < RCAR_VIN_NUM; i++) {
+   if (!group->vin[i])
+   continue;
+
+   if (>vin[i]->vdev == vdev)
+   return i;
+   }
+
+   return -ENODEV;
+}
+
+/* group lock should be held when calling this function */
+static int rvin_group_entity_to_csi_num(struct rvin_group *group,
+   struct media_entity *entity)
+{
+   struct v4l2_subdev *sd;
+   int i;
+
+   if (!is_media_entity_v4l2_subdev(entity))
+   return -ENODEV;
+
+   sd = media_entity_to_v4l2_subdev(entity);
+
+   for (i = 0; i < RVIN_CSI_MAX; i++)
+   if (group->bridge[i].subdev == sd)
+   return i;
+
+   return -ENODEV;
+}
+
+/* group lock should be held when calling this function */
+static void __rvin_group_build_link_list(struct rvin_group *group,
+struct rvin_group_chsel *map,
+int start, int len)
+{
+   struct media_pad *vin_pad, *remote_pad;
+   unsigned int n;
+
+   for (n = 0; n < len; n++) {
+   map[n].csi = -1;
+   map[n].chan = -1;
+
+   if (!group->vin[start + n])
+   continue;
+
+   vin_pad = >vin[start + n]->vdev.entity.pads[RVIN_SINK];
+
+   remote_pad = media_entity_remote_pad(vin_pad);
+   if (!remote_pad)
+   continue;
+
+   map[n].csi =
+   rvin_group_entity_to_csi_num(group, remote_pad->entity);
+   map[n].chan = rvin_group_csi_pad_to_chan(remote_pad->index);
+   }
+}
+
+/* group lock should be held when calling this function */
+static int __rvin_group_try_get_chsel(struct rvin_group *group,
+ struct rvin_group_chsel *map,
+ int start, int len)
+{
+   const struct rvin_group_chsel *sel;
+   unsigned int i, n;
+   int chsel;
+
+   for (i = 0; i < group->vin[start]->info->num_chsels; i++) {
+   chsel = i;
+   for (n = 0; n < len; n++) {
+
+   /* If the link is not active it's OK */
+   if (map[n].csi == -1)
+   continue;
+
+   /* Check if chsel match requested link */
+   sel = >vin[start]->info->chsels[start + n][i];
+   if (map[n].csi != sel->csi ||
+   map[n].chan != sel->chan) {
+   chsel = -1;
+   break;
+   }
+   }
+
+   

[PATCHv2 21/32] media: rcar-vin: add group allocator functions

2016-11-12 Thread Niklas Söderlund
On Gen3 all VIN instances which wish to interact with with the shared
CSI2 resource needs to be part of the same media device and share other
information, such as subdevices and be able to call routing operations
on other VIN instances.

This patch adds a group allocator which joins all VIN instances in one
group. Inspiration for this patch is taken from Shuah Khans patch series
'Media Device Allocator API' which do a similar thing but allows a media
device to be shared across different drivers. The use case here is to
share group information between multiple instances of the same driver.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 103 
 drivers/media/platform/rcar-vin/rcar-vin.h  |  41 +++
 2 files changed, 144 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 6554141..c21f029 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -26,6 +26,102 @@
 #include "rcar-vin.h"
 
 /* 
-
+ * Gen3 CSI2 Group Allocator
+ */
+
+static DEFINE_MUTEX(rvin_group_lock);
+static struct rvin_group *rvin_group_data;
+
+static void rvin_group_release(struct kref *kref)
+{
+   struct rvin_group *group =
+   container_of(kref, struct rvin_group, refcount);
+
+   mutex_lock(_group_lock);
+
+   media_device_unregister(>mdev);
+   media_device_cleanup(>mdev);
+
+   rvin_group_data = NULL;
+
+   mutex_unlock(_group_lock);
+
+   kfree(group);
+}
+
+static struct rvin_group *__rvin_group_allocate(struct rvin_dev *vin)
+{
+   struct rvin_group *group;
+
+   if (rvin_group_data) {
+   group = rvin_group_data;
+   kref_get(>refcount);
+   vin_dbg(vin, "%s: get group=%p\n", __func__, group);
+   return group;
+   }
+
+   group = kzalloc(sizeof(*group), GFP_KERNEL);
+   if (!group)
+   return NULL;
+
+   kref_init(>refcount);
+   rvin_group_data = group;
+
+   vin_dbg(vin, "%s: alloc group=%p\n", __func__, group);
+   return group;
+}
+
+static struct rvin_group *rvin_group_allocate(struct rvin_dev *vin)
+{
+   struct rvin_group *group;
+   struct media_device *mdev;
+   int ret;
+
+   mutex_lock(_group_lock);
+
+   group = __rvin_group_allocate(vin);
+   if (!group) {
+   mutex_unlock(_group_lock);
+   return ERR_PTR(-ENOMEM);
+   }
+
+   /* Init group data if its not already initialized */
+   mdev = >mdev;
+   if (!mdev->dev) {
+   mutex_init(>lock);
+   mdev->dev = vin->dev;
+
+   strlcpy(mdev->driver_name, "Renesas VIN",
+   sizeof(mdev->driver_name));
+   strlcpy(mdev->model, vin->dev->of_node->name,
+   sizeof(mdev->model));
+   strlcpy(mdev->bus_info, of_node_full_name(vin->dev->of_node),
+   sizeof(mdev->bus_info));
+   mdev->driver_version = LINUX_VERSION_CODE;
+   media_device_init(mdev);
+
+   ret = media_device_register(mdev);
+   if (ret) {
+   vin_err(vin, "Failed to register media device\n");
+   mutex_unlock(_group_lock);
+   return ERR_PTR(ret);
+   }
+   }
+
+   vin->v4l2_dev.mdev = mdev;
+
+   mutex_unlock(_group_lock);
+
+   return group;
+}
+
+static void rvin_group_delete(struct rvin_dev *vin)
+{
+   vin_dbg(vin, "%s: group=%p\n", __func__, >group);
+   kref_put(>group->refcount, rvin_group_release);
+}
+
+/* 
-
  * Subdevice helpers
  */
 
@@ -322,6 +418,10 @@ static int rvin_graph_init(struct rvin_dev *vin)
ret = media_entity_pads_init(>vdev.entity, 1, vin->pads);
if (ret)
return ret;
+
+   vin->group = rvin_group_allocate(vin);
+   if (IS_ERR(vin->group))
+   return PTR_ERR(vin->group);
}
 
return ret;
@@ -390,6 +490,9 @@ static int rcar_vin_remove(struct platform_device *pdev)
 
rvin_v4l2_remove(vin);
 
+   if (vin->group)
+   rvin_group_delete(vin);
+
v4l2_async_notifier_unregister(>notifier);
 
rvin_dma_remove(vin);
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 8ed43be..90c28a7 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -17,10 +17,13 @@
 #ifndef __RCAR_VIN__
 #define __RCAR_VIN__
 
+#include 
+
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* Number of HW buffers 

[PATCHv2 29/32] media: rcar-vin: attach to CSI2 group when the video device is opened

2016-11-12 Thread Niklas Söderlund
Attempt to attach to the subdevices pointed out by the routing from the
CSI2 group when the video device is opened. This is the last piece
missing to enable CSI2 groups on Gen3.

If the current CSI2 routing for the group points ta a set of subdevices
which are not present (not all routings are available on all boards) the
open fall will fail with a -EBUSY error. The VIN instance will be
unavailable with this error until the group routing is changed to one
which provides it with a available set of subdevices.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index d363531..1801c6e 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -846,6 +846,7 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
 static int rvin_open(struct file *file)
 {
struct rvin_dev *vin = video_drvdata(file);
+   struct v4l2_subdev *source, *bridge;
int ret;
 
mutex_lock(>lock);
@@ -857,12 +858,28 @@ static int rvin_open(struct file *file)
goto err_out;
 
/* If there is no subdevice there is not much we can do */
-   if (!vin_to_source(vin)) {
+   source = vin_to_source(vin);
+   if (!source) {
ret = -EBUSY;
goto err_open;
}
 
if (v4l2_fh_is_singular_file(file)) {
+   if (vin_have_bridge(vin)) {
+
+   /* If there are no bridge not much we can do */
+   bridge = vin_to_bridge(vin);
+   if (!bridge) {
+   ret = -EBUSY;
+   goto err_open;
+   }
+
+   v4l2_pipeline_pm_use(>vdev.entity, 1);
+
+   vin_dbg(vin, "Group source: %s bridge: %s\n",
+   source->name,
+   bridge->name);
+   }
pm_runtime_get_sync(vin->dev);
ret = rvin_attach_subdevices(vin);
if (ret) {
@@ -876,6 +893,8 @@ static int rvin_open(struct file *file)
return 0;
 err_power:
pm_runtime_put(vin->dev);
+   if (vin_have_bridge(vin))
+   v4l2_pipeline_pm_use(>vdev.entity, 0);
 err_open:
v4l2_fh_release(file);
 err_out:
@@ -904,6 +923,8 @@ static int rvin_release(struct file *file)
if (fh_singular) {
rvin_detach_subdevices(vin);
pm_runtime_put(vin->dev);
+   if (vin_have_bridge(vin))
+   v4l2_pipeline_pm_use(>vdev.entity, 0);
}
 
mutex_unlock(>lock);
-- 
2.10.2

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


[PATCHv2 32/32] media: rcar-vin: enable support for r8a7796

2016-11-12 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a7796.

Signed-off-by: Niklas Söderlund 
---
 .../devicetree/bindings/media/rcar_vin.txt |  1 +
 drivers/media/platform/rcar-vin/rcar-core.c| 63 ++
 2 files changed, 64 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index 64b03f1..e3a82dc 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -10,6 +10,7 @@ always slaves and support multiple input channels which can 
be either RGB,
 YUVU, BT656 or CSI-2.
 
  - compatible: Must be one or more of the following
+   - "renesas,vin-r8a7796" for the R8A7796 device
- "renesas,vin-r8a7795" for the R8A7795 device
- "renesas,vin-r8a7794" for the R8A7794 device
- "renesas,vin-r8a7793" for the R8A7793 device
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 1a86c72..bb31af8 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -1201,6 +1201,65 @@ static const struct rvin_info rcar_info_r8a7795 = {
},
 };
 
+static const struct rvin_info rcar_info_r8a7796 = {
+   .chip = RCAR_GEN3,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 5,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_NOOPE, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_NOOPE, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_NOOPE, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   },
+   },
+};
+
 static const struct rvin_info rcar_info_gen2 = {
.chip = RCAR_GEN2,
.max_width = 2048,
@@ -1213,6 +1272,10 @@ static const struct of_device_id rvin_of_id_table[] = {
.data = _info_r8a7795,
},
{
+   .compatible = "renesas,vin-r8a7796",
+   .data = _info_r8a7796,
+   },
+   {
.compatible = "renesas,vin-r8a7794",
.data = _info_gen2,
},
-- 
2.10.2

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


[PATCHv2 18/32] media: rcar-vin: enable Gen3 hardware configuration

2016-11-12 Thread Niklas Söderlund
Add the register needed to work with Gen3 hardware. This patch adds
the logic for how to work with the Gen3 hardware. More work is required
to enable the subdevice structure needed to configure capturing.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 98 --
 drivers/media/platform/rcar-vin/rcar-vin.h |  1 +
 2 files changed, 68 insertions(+), 31 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index eac5c19..80958e6 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -33,21 +33,23 @@
 #define VNELPRC_REG0x10/* Video n End Line Pre-Clip Register */
 #define VNSPPRC_REG0x14/* Video n Start Pixel Pre-Clip Register */
 #define VNEPPRC_REG0x18/* Video n End Pixel Pre-Clip Register */
-#define VNSLPOC_REG0x1C/* Video n Start Line Post-Clip Register */
-#define VNELPOC_REG0x20/* Video n End Line Post-Clip Register */
-#define VNSPPOC_REG0x24/* Video n Start Pixel Post-Clip Register */
-#define VNEPPOC_REG0x28/* Video n End Pixel Post-Clip Register */
 #define VNIS_REG   0x2C/* Video n Image Stride Register */
 #define VNMB_REG(m)(0x30 + ((m) << 2)) /* Video n Memory Base m Register */
 #define VNIE_REG   0x40/* Video n Interrupt Enable Register */
 #define VNINTS_REG 0x44/* Video n Interrupt Status Register */
 #define VNSI_REG   0x48/* Video n Scanline Interrupt Register */
 #define VNMTC_REG  0x4C/* Video n Memory Transfer Control Register */
-#define VNYS_REG   0x50/* Video n Y Scale Register */
-#define VNXS_REG   0x54/* Video n X Scale Register */
 #define VNDMR_REG  0x58/* Video n Data Mode Register */
 #define VNDMR2_REG 0x5C/* Video n Data Mode Register 2 */
 #define VNUVAOF_REG0x60/* Video n UV Address Offset Register */
+
+/* Register offsets specific for Gen2 */
+#define VNSLPOC_REG0x1C/* Video n Start Line Post-Clip Register */
+#define VNELPOC_REG0x20/* Video n End Line Post-Clip Register */
+#define VNSPPOC_REG0x24/* Video n Start Pixel Post-Clip Register */
+#define VNEPPOC_REG0x28/* Video n End Pixel Post-Clip Register */
+#define VNYS_REG   0x50/* Video n Y Scale Register */
+#define VNXS_REG   0x54/* Video n X Scale Register */
 #define VNC1A_REG  0x80/* Video n Coefficient Set C1A Register */
 #define VNC1B_REG  0x84/* Video n Coefficient Set C1B Register */
 #define VNC1C_REG  0x88/* Video n Coefficient Set C1C Register */
@@ -73,9 +75,13 @@
 #define VNC8B_REG  0xF4/* Video n Coefficient Set C8B Register */
 #define VNC8C_REG  0xF8/* Video n Coefficient Set C8C Register */
 
+/* Register offsets specific for Gen3 */
+#define VNCSI_IFMD_REG 0x20 /* Video n CSI2 Interface Mode Register */
 
 /* Register bit fields for R-Car VIN */
 /* Video n Main Control Register bits */
+#define VNMC_DPINE (1 << 27) /* Gen3 specific */
+#define VNMC_SCLE  (1 << 26) /* Gen3 specific */
 #define VNMC_FOC   (1 << 21)
 #define VNMC_YCAL  (1 << 19)
 #define VNMC_INF_YUV8_BT656(0 << 16)
@@ -119,6 +125,13 @@
 #define VNDMR2_FTEV(1 << 17)
 #define VNDMR2_VLV(n)  ((n & 0xf) << 12)
 
+/* Video n CSI2 Interface Mode Register (Gen3) */
+#define VNCSI_IFMD_DES2(1 << 27)
+#define VNCSI_IFMD_DES1(1 << 26)
+#define VNCSI_IFMD_DES0(1 << 25)
+#define VNCSI_IFMD_CSI_CHSEL(n) ((n & 0xf) << 0)
+#define VNCSI_IFMD_CSI_CHSEL_MASK 0xf
+
 static void rvin_write(struct rvin_dev *vin, u32 value, u32 offset)
 {
iowrite32(value, vin->base + offset);
@@ -205,7 +218,10 @@ static int rvin_setup(struct rvin_dev *vin)
}
 
/* Enable VSYNC Field Toogle mode after one VSYNC input */
-   dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
+   if (vin->info->chip == RCAR_GEN3)
+   dmr2 = VNDMR2_FTEV;
+   else
+   dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
/* Hsync Signal Polarity Select */
if (!(rent->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
@@ -257,6 +273,14 @@ static int rvin_setup(struct rvin_dev *vin)
if (input_is_yuv == output_is_yuv)
vnmc |= VNMC_BPS;
 
+   if (vin->info->chip == RCAR_GEN3) {
+   /* Select between CSI-2 and Digital input */
+   if (rent->mbus_cfg.type == V4L2_MBUS_CSI2)
+   vnmc &= ~VNMC_DPINE;
+   else
+   vnmc |= VNMC_DPINE;
+   }
+
/* Progressive or interlaced mode */
interrupts = progressive ? VNIE_FIE : VNIE_EFE;
 
@@ -758,28 +782,10 @@ static void rvin_set_coeff(struct rvin_dev *vin, unsigned 
short xs)
rvin_write(vin, p_set->coeff_set[23], VNC8C_REG);
 }
 

[PATCHv2 25/32] media: rcar-vin: enable CSI2 group subdevices in lookup helpers

2016-11-12 Thread Niklas Söderlund
Make the subdevice helpers look not only at the local digital subdevice
but also for the CSI2 group subdevices which can be present on Gen3.

Which CSI2 group subdevices are found depends on the CSI2 subgroup
routing which is stored in the CHSEL register of the subgroup master
(VIN0 for VIN0-3 and VIN4 for VIN4-7). The lookup functions look at this
value and returns the correct information or NULL if there is no
attached subdevices for the current routing for this device.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 70 -
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 +-
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 0092ab4..0b3882a 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -330,9 +330,77 @@ static void rvin_group_delete(struct rvin_dev *vin)
  * Subdevice helpers
  */
 
+static int rvin_group_vin_to_csi(struct rvin_dev *vin)
+{
+   int i, vin_num, vin_master, chsel, csi;
+
+   /* Only valid on Gen3 */
+   if (vin->info->chip != RCAR_GEN3)
+   return -1;
+
+   /*
+* Only try to translate to a CSI2 number if there is a enabled
+* link from the VIN sink pad. However if there are no links at
+* all we are at probe time so ignore the need for enabled links
+* to be able to make a better guess of initial format
+*/
+   if (vin->pads[RVIN_SINK].entity->num_links &&
+   !media_entity_remote_pad(>pads[RVIN_SINK]))
+   return -1;
+
+   /* Find which VIN we are */
+   vin_num = -1;
+   for (i = 0; i < RCAR_VIN_NUM; i++)
+   if (vin == vin->group->vin[i])
+   vin_num = i;
+
+   if (vin_num == -1)
+   return -1;
+
+   vin_master = vin_num < 4 ? 0 : 4;
+   if (!vin->group->vin[vin_master])
+   return -1;
+
+   chsel = rvin_get_chsel(vin->group->vin[vin_master]);
+
+   csi = vin->info->chsels[vin_num][chsel].csi;
+   if (csi >= RVIN_CSI_MAX)
+   return -1;
+
+   if (!vin->group->source[csi].subdev || !vin->group->bridge[csi].subdev)
+   return -1;
+
+   return csi;
+}
+
 struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin)
 {
-   return >digital;
+   int csi;
+
+   /* If there is a digital subdev use it */
+   if (vin->digital.subdev)
+   return >digital;
+
+   csi = rvin_group_vin_to_csi(vin);
+   if (csi < 0)
+   return NULL;
+
+   return >group->source[csi];
+}
+
+struct v4l2_subdev *vin_to_source(struct rvin_dev *vin)
+{
+   int csi;
+
+   /* If there is a digital subdev use it */
+   if (vin->digital.subdev)
+   return vin->digital.subdev;
+
+   csi = rvin_group_vin_to_csi(vin);
+   if (csi < 0)
+   return NULL;
+
+   return vin->group->source[csi].subdev;
 }
 
 /* 
-
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index cd7d959..2f1e087 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -207,7 +207,7 @@ struct rvin_dev {
 };
 
 struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin);
-#define vin_to_source(vin) vin->digital.subdev
+struct v4l2_subdev *vin_to_source(struct rvin_dev *vin);
 
 /* Debug */
 #define vin_dbg(d, fmt, arg...)dev_dbg(d->dev, fmt, ##arg)
-- 
2.10.2

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


[PATCHv2 31/32] media: rcar-vin: enable support for r8a7795

2016-11-12 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a7795.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/Kconfig |  2 +-
 drivers/media/platform/rcar-vin/rcar-core.c | 71 +
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/Kconfig 
b/drivers/media/platform/rcar-vin/Kconfig
index 111d2a1..e0e981c 100644
--- a/drivers/media/platform/rcar-vin/Kconfig
+++ b/drivers/media/platform/rcar-vin/Kconfig
@@ -5,7 +5,7 @@ config VIDEO_RCAR_VIN
select VIDEOBUF2_DMA_CONTIG
---help---
  Support for Renesas R-Car Video Input (VIN) driver.
- Supports R-Car Gen2 SoCs.
+ Supports R-Car Gen2 and Gen3 SoCs.
 
  To compile this driver as a module, choose M here: the
  module will be called rcar-vin.
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 1efbb0a..1a86c72 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -1134,6 +1134,73 @@ static const struct rvin_info rcar_info_m1 = {
.max_height = 2048,
 };
 
+static const struct rvin_info rcar_info_r8a7795 = {
+   .chip = RCAR_GEN3,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 6,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI21, .chan = 1 },
+   }, {
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   { .csi = RVIN_CSI21, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI21, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   { .csi = RVIN_CSI21, .chan = 3 },
+   }, {
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI21, .chan = 1 },
+   }, {
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   { .csi = RVIN_CSI21, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI21, .chan = 1 },
+   { .csi = RVIN_CSI41, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   { .csi = RVIN_CSI21, .chan = 3 },
+   },
+   },
+};
+
 static const struct rvin_info rcar_info_gen2 = {
.chip = RCAR_GEN2,
.max_width = 2048,
@@ -1142,6 +1209,10 @@ static const struct rvin_info rcar_info_gen2 = {
 
 static const struct of_device_id rvin_of_id_table[] = {
{
+   .compatible = "renesas,vin-r8a7795",
+   .data = _info_r8a7795,
+   },
+   {
.compatible = "renesas,vin-r8a7794",
.data = _info_gen2,
},
-- 
2.10.2

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

[PATCHv2 03/32] media: rcar-vin: reset bytesperline and sizeimage when resetting format

2016-11-12 Thread Niklas Söderlund
These two fields where forgotten when refactoring the format reset code
path. If they are not also reset at the same time as width and hight the
format read using G_FMT will not match reality.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 2bbe6d4..69bc4cf 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -151,6 +151,9 @@ static int rvin_reset_format(struct rvin_dev *vin)
 
rvin_reset_crop_compose(vin);
 
+   vin->format.bytesperline = rvin_format_bytesperline(>format);
+   vin->format.sizeimage = rvin_format_sizeimage(>format);
+
return 0;
 }
 
-- 
2.10.2

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


[PATCHv2 14/32] media: rcar-vin: move chip information to own struct

2016-11-12 Thread Niklas Söderlund
When Gen3 support is added to the driver more then chip id will be
different for the different Soc. To avoid a lot of if statements in the
code create a struct chip_info to contain this information.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 49 -
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  3 +-
 drivers/media/platform/rcar-vin/rcar-vin.h  | 12 +--
 3 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 5807d8d..c80bbbc 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -253,14 +253,47 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
  * Platform Device Driver
  */
 
+static const struct rvin_info rcar_info_h1 = {
+   .chip = RCAR_H1,
+};
+
+static const struct rvin_info rcar_info_m1 = {
+   .chip = RCAR_M1,
+};
+
+static const struct rvin_info rcar_info_gen2 = {
+   .chip = RCAR_GEN2,
+};
+
 static const struct of_device_id rvin_of_id_table[] = {
-   { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
-   { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
-   { .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },
+   {
+   .compatible = "renesas,vin-r8a7794",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7793",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7791",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7790",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7779",
+   .data = _info_h1,
+   },
+   {
+   .compatible = "renesas,vin-r8a7778",
+   .data = _info_m1,
+   },
+   {
+   .compatible = "renesas,rcar-gen2-vin",
+   .data = _info_gen2,
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
@@ -281,7 +314,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
return -ENODEV;
 
vin->dev = >dev;
-   vin->chip = (enum chip_id)match->data;
+   vin->info = match->data;
vin->last_input = NULL;
 
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 47137d7..05b0181 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -279,7 +279,8 @@ static int __rvin_try_format(struct rvin_dev *vin,
pix->sizeimage = max_t(u32, pix->sizeimage,
   rvin_format_sizeimage(pix));
 
-   if (vin->chip == RCAR_M1 && pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
+   if (vin->info->chip == RCAR_M1 &&
+   pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
vin_err(vin, "pixel format XBGR32 not supported on M1\n");
return -EINVAL;
}
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 2a1b190..17a5fce 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -89,10 +89,18 @@ struct rvin_graph_entity {
 };
 
 /**
+ * struct rvin_info- Information about the particular VIN implementation
+ * @chip:  type of VIN chip
+ */
+struct rvin_info {
+   enum chip_id chip;
+};
+
+/**
  * struct rvin_dev - Renesas VIN device structure
  * @dev:   (OF) device
  * @base:  device I/O register space remapped to virtual memory
- * @chip:  type of VIN chip
+ * @info   info about VIN instance
  *
  * @vdev:  V4L2 video device associated with VIN
  * @v4l2_dev:  V4L2 device
@@ -121,7 +129,7 @@ struct rvin_graph_entity {
 struct rvin_dev {
struct device *dev;
void __iomem *base;
-   enum chip_id chip;
+   const struct rvin_info *info;
 
struct video_device vdev;
struct v4l2_device v4l2_dev;
-- 
2.10.2

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


[PATCHv2 23/32] media: rcar-vin: parse Gen3 OF and setup media graph

2016-11-12 Thread Niklas Söderlund
Parse the VIN Gen3 OF graph and register all devices in the CSI2 group
common media device. Once a subdevice is added to the common media
device list as many links as possible are added and if possible enabled.

The links between the video source device and the CSI2 bridge are
enabled as immutable since they can't change during runtime. While the
link between the CSI2 bridge and the VIN video device are enabled
according the CHSEL routing table suitable for the SoC.

The parsing and registering subdevices is a collaborative effort shared
between all rcar-vin instances which are part of the CSI2 group. Which
ever rcar-vin instance which fist sees a new subdevice in the graph adds
it to its private v4l2 async notifier and once it's bound it will be
available for the whole CSI2 group.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 485 
 1 file changed, 485 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index c21f029..de75ca8 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -350,6 +350,483 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
 }
 
 /* 
-
+ * CSI async notifier
+ */
+
+/* group lock should be held when calling this function */
+static void rvin_group_update_pads(struct rvin_graph_entity *entity)
+{
+   struct media_entity *ent = >subdev->entity;
+   unsigned int i;
+
+   /* Make sure source pad idx are sane */
+   if (entity->source_pad_idx >= ent->num_pads ||
+   ent->pads[entity->source_pad_idx].flags != MEDIA_PAD_FL_SOURCE) {
+   entity->source_pad_idx =
+   rvin_pad_idx(entity->subdev, MEDIA_PAD_FL_SOURCE);
+   }
+
+   /* Try to find sink for source, fall back 0 which always is sink */
+   entity->sink_pad_idx = 0;
+   for (i = 0; i < ent->num_pads; ++i) {
+   struct media_pad *sink = >pads[i];
+
+   if (!(sink->flags & MEDIA_PAD_FL_SINK))
+   continue;
+
+   if (sink->index == entity->source_pad_idx)
+   continue;
+
+   if (media_entity_has_route(ent, sink->index,
+  entity->source_pad_idx))
+   entity->sink_pad_idx = sink->index;
+   }
+}
+
+/* group lock should be held when calling this function */
+static int rvin_group_add_link(struct rvin_dev *vin,
+  struct media_entity *source,
+  unsigned int source_pad_idx,
+  struct media_entity *sink,
+  unsigned int sink_idx,
+  u32 flags)
+{
+   struct media_pad *source_pad, *sink_pad;
+   int ret = 0;
+
+   source_pad = >pads[source_pad_idx];
+   sink_pad = >pads[sink_idx];
+
+   if (!media_entity_find_link(source_pad, sink_pad))
+   ret = media_create_pad_link(source, source_pad_idx,
+   sink, sink_idx, flags);
+
+   if (ret)
+   vin_err(vin, "Error adding link from %s to %s\n",
+   source->name, sink->name);
+
+   return ret;
+}
+
+static int rvin_group_update_links(struct rvin_dev *vin)
+{
+   struct media_entity *source, *sink;
+   struct rvin_dev *master;
+   unsigned int i, n, idx, chsel, csi;
+   u32 flags;
+   int ret;
+
+   mutex_lock(>group->lock);
+
+   /* Update Source -> Bridge */
+   for (i = 0; i < RVIN_CSI_MAX; i++) {
+   if (!vin->group->source[i].subdev)
+   continue;
+
+   if (!vin->group->bridge[i].subdev)
+   continue;
+
+   source = >group->source[i].subdev->entity;
+   sink = >group->bridge[i].subdev->entity;
+   idx = vin->group->source[i].source_pad_idx;
+   flags = MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE;
+
+   ret = rvin_group_add_link(vin, source, idx, sink, 0, flags);
+   if (ret)
+   goto out;
+   }
+
+   /* Update Bridge -> VIN */
+   for (n = 0; n < RCAR_VIN_NUM; n++) {
+
+   /* Check that VIN is part of the group */
+   if (!vin->group->vin[n])
+   continue;
+
+   /* Check that subgroup master is part of the group */
+   master = vin->group->vin[n < 4 ? 0 : 4];
+   if (!master)
+   continue;
+
+   chsel = rvin_get_chsel(master);
+
+   for (i = 0; i < vin->info->num_chsels; i++) {
+   csi = vin->info->chsels[n][i].csi;
+
+   /* If the CSI is out of bounds it's a no 

[PATCHv2 17/32] media: rcar-vin: clarify error message from the digital notifier

2016-11-12 Thread Niklas Söderlund
Some of the parser functions previously only used by the digital
subdevice OF/V4L2 async code will be shared with the CSI2 group
notifiers. Clarify which notifier register error message and mark which
functions are generic helpers.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index def240b1..26e438a 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -35,7 +35,7 @@ struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin)
 }
 
 /* 
-
- * Async notifier
+ * Async notifier helpers
  */
 
 #define notifier_to_vin(n) container_of(n, struct rvin_dev, notifier)
@@ -77,6 +77,10 @@ static unsigned int rvin_pad_idx(struct v4l2_subdev *sd, int 
direction)
return 0;
 }
 
+/* 
-
+ * Digital async notifier
+ */
+
 static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
@@ -242,7 +246,7 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
 
ret = v4l2_async_notifier_register(>v4l2_dev, >notifier);
if (ret < 0) {
-   vin_err(vin, "Notifier registration failed\n");
+   vin_err(vin, "Digital notifier registration failed\n");
return ret;
}
 
-- 
2.10.2

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


[PATCHv2 30/32] media: rcar-vin: add Gen3 devicetree bindings documentation

2016-11-12 Thread Niklas Söderlund
Document the Gen3 devicetree bindings. The new bindings are all handled
in the port@1 node, if an endpoint is described as on Gen2 in port@0 the
driver will work in Gen2 mode and this is supported on Gen3. The new
CSI-2 video sources are only supported on Gen3.

Signed-off-by: Niklas Söderlund 
---
 .../devicetree/bindings/media/rcar_vin.txt | 116 +++--
 1 file changed, 106 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index 6a4e61c..64b03f1 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -2,8 +2,12 @@ Renesas RCar Video Input driver (rcar_vin)
 --
 
 The rcar_vin device provides video input capabilities for the Renesas R-Car
-family of devices. The current blocks are always slaves and suppot one input
-channel which can be either RGB, YUYV or BT656.
+family of devices.
+
+On Gen2 the current blocks are always slaves and support one input channel
+which can be either RGB, YUYV or BT656. On Gen3 the current blocks are
+always slaves and support multiple input channels which can be either RGB,
+YUVU, BT656 or CSI-2.
 
  - compatible: Must be one or more of the following
- "renesas,vin-r8a7795" for the R8A7795 device
@@ -28,7 +32,7 @@ channel which can be either RGB, YUYV or BT656.
 Additionally, an alias named vinX will need to be created to specify
 which video input device this is.
 
-The per-board settings:
+The per-board settings Gen2:
  - port sub-node describing a single endpoint connected to the vin
as described in video-interfaces.txt[1]. Only the first one will
be considered as each vin interface has one input port.
@@ -36,13 +40,22 @@ The per-board settings:
These settings are used to work out video input format and widths
into the system.
 
+The per-board settings Gen3:
+
+- ports
+- port@0 - Digital video source (same as port node on Gen2)
+- port@1 - CSI-2 video sources
+-reg 0 - sub-node describing the endpoint which is CSI20
+-reg 1 - sub-node describing the endpoint which is CSI21
+-reg 2 - sub-node describing the endpoint which is CSI40
+-reg 3 - sub-node describing the endpoint which is CSI41
 
-Device node example

+Device node example Gen2
+
 
-   aliases {
-  vin0 = 
-   };
+aliases {
+vin0 = 
+};
 
 vin0: vin@0xe6ef {
 compatible = "renesas,vin-r8a7790", "renesas,rcar-gen2-vin";
@@ -52,8 +65,8 @@ Device node example
 status = "disabled";
 };
 
-Board setup example (vin1 composite video input)
-
+Board setup example Gen2 (vin1 composite video input)
+-
 
{
 status = "ok";
@@ -92,6 +105,89 @@ Board setup example (vin1 composite video input)
 };
 };
 
+Device node example Gen3
+
+
+aliases {
+vin0 = 
+};
+
+vin1: video@e6ef1000 {
+compatible = "renesas,vin-r8a7796";
+reg =  <0 0xe6ef1000 0 0x1000>;
+interrupts = <0 189 IRQ_TYPE_LEVEL_HIGH>;
+clocks = < CPG_MOD 810>;
+   power-domains = < R8A7796_PD_ALWAYS_ON>;
+status = "disabled";
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@1 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+reg = <1>;
+
+vin1csi20: endpoint@0 {
+reg = <0>;
+remote-endpoint= <>;
+};
+};
+};
+};
+
+csi20: csi2@fea8 {
+compatible = "renesas,r8a7796-csi2";
+reg = <0 0xfea8 0 0x1>;
+interrupts = <0 184 IRQ_TYPE_LEVEL_HIGH>;
+clocks = < CPG_MOD 714>;
+   power-domains = < R8A7796_PD_ALWAYS_ON>;
+status = "disabled";
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@1 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+reg = <1>;
+
+csi20vin1: endpoint@1 {
+reg = <1>;
+remote-endpoint 

[PATCHv2 20/32] media: rcar-vin: expose a sink pad if we are on Gen3

2016-11-12 Thread Niklas Söderlund
Refactor the probe code path to look for the digital subdevice, if one
is found use it just like the driver did before (Gen2 mode) but if it's
not found prepare for a Gen3 mode by registering a pad for the media
controller API to use.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 21 -
 drivers/media/platform/rcar-vin/rcar-vin.h  |  9 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 26e438a..6554141 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -308,6 +308,25 @@ static const struct of_device_id rvin_of_id_table[] = {
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
 
+static int rvin_graph_init(struct rvin_dev *vin)
+{
+   int ret;
+
+   /* Try to get digital video pipe */
+   ret = rvin_digital_graph_init(vin);
+
+   /* No digital pipe and we are on Gen3 try to joint CSI2 group */
+   if (ret == -ENODEV && vin->info->chip == RCAR_GEN3) {
+
+   vin->pads[RVIN_SINK].flags = MEDIA_PAD_FL_SINK;
+   ret = media_entity_pads_init(>vdev.entity, 1, vin->pads);
+   if (ret)
+   return ret;
+   }
+
+   return ret;
+}
+
 static int rcar_vin_probe(struct platform_device *pdev)
 {
const struct of_device_id *match;
@@ -343,7 +362,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (ret)
return ret;
 
-   ret = rvin_digital_graph_init(vin);
+   ret = rvin_graph_init(vin);
if (ret < 0)
goto error;
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index a6a49a96..8ed43be 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -36,6 +36,11 @@ enum chip_id {
RCAR_GEN3,
 };
 
+enum rvin_pads {
+   RVIN_SINK,
+   RVIN_PAD_MAX,
+};
+
 /**
  * STOPPED  - No operation in progress
  * RUNNING  - Operation in progress have buffers
@@ -115,6 +120,8 @@ struct rvin_info {
  * @notifier:  V4L2 asynchronous subdevs notifier
  * @digital:   entity in the DT for local digital subdevice
  *
+ * @pads:  pads for media controller
+ *
  * @lock:  protects @queue
  * @queue: vb2 buffers queue
  *
@@ -144,6 +151,8 @@ struct rvin_dev {
struct v4l2_async_notifier notifier;
struct rvin_graph_entity digital;
 
+   struct media_pad pads[RVIN_PAD_MAX];
+
struct mutex lock;
struct vb2_queue queue;
 
-- 
2.10.2

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


[PATCHv2 16/32] media: rcar-vin: change name of video device

2016-11-12 Thread Niklas Söderlund
The rcar-vin driver needs to be part of a media controller to support
Gen3. Give each VIN instance a unique name so it can be referenced from
userspace.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index f5fbe9f..e99815f 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -944,7 +944,8 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
vdev->fops = _fops;
vdev->v4l2_dev = >v4l2_dev;
vdev->queue = >queue;
-   strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name));
+   snprintf(vdev->name, sizeof(vdev->name), "%s.%s", KBUILD_MODNAME,
+dev_name(vin->dev));
vdev->release = video_device_release_empty;
vdev->ioctl_ops = _ioctl_ops;
vdev->lock = >lock;
-- 
2.10.2

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


[PATCHv2 26/32] media: rcar-vin: add helpers for bridge

2016-11-12 Thread Niklas Söderlund
On Gen3 there might be a CSI2 bridge between the video source and the
VIN. Add helpers to check for this and to fetch the bridge subdevice.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 19 +++
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 0b3882a..1efbb0a 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -373,6 +373,11 @@ static int rvin_group_vin_to_csi(struct rvin_dev *vin)
return csi;
 }
 
+bool vin_have_bridge(struct rvin_dev *vin)
+{
+   return vin->digital.subdev == NULL;
+}
+
 struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin)
 {
int csi;
@@ -403,6 +408,20 @@ struct v4l2_subdev *vin_to_source(struct rvin_dev *vin)
return vin->group->source[csi].subdev;
 }
 
+struct v4l2_subdev *vin_to_bridge(struct rvin_dev *vin)
+{
+   int csi;
+
+   if (vin->digital.subdev)
+   return NULL;
+
+   csi = rvin_group_vin_to_csi(vin);
+   if (csi < 0)
+   return NULL;
+
+   return vin->group->bridge[csi].subdev;
+}
+
 /* 
-
  * Async notifier helpers
  */
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 2f1e087..acaed2b 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -206,8 +206,10 @@ struct rvin_dev {
struct v4l2_rect compose;
 };
 
+bool vin_have_bridge(struct rvin_dev *vin);
 struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin);
 struct v4l2_subdev *vin_to_source(struct rvin_dev *vin);
+struct v4l2_subdev *vin_to_bridge(struct rvin_dev *vin);
 
 /* Debug */
 #define vin_dbg(d, fmt, arg...)dev_dbg(d->dev, fmt, ##arg)
-- 
2.10.2

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


[PATCHv2 27/32] media: rcar-vin: start/stop the CSI2 bridge stream

2016-11-12 Thread Niklas Söderlund
On Gen3 the CSI2 bridge stream needs to be start/stop in conjunction
with the video source. Create helpers to deal with both the Gen2 single
subdevice case and the Gen3 CSI2 group case.

In the Gen3 case there might be other simultaneous users of the bridge
and source devices so examine each entity stream_count before acting on
any particular device.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 84 +++---
 1 file changed, 77 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 322e4c1..872f138 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1089,15 +1089,87 @@ static void rvin_buffer_queue(struct vb2_buffer *vb)
spin_unlock_irqrestore(>qlock, flags);
 }
 
+static int __rvin_start_streaming(struct rvin_dev *vin)
+{
+   struct v4l2_subdev *source, *bridge = NULL;
+   struct media_pipeline *pipe;
+   int ret;
+
+   source = vin_to_source(vin);
+   if (!source)
+   return -EINVAL;
+
+   if (vin_have_bridge(vin)) {
+   bridge = vin_to_bridge(vin);
+
+   if (!bridge)
+   return -EINVAL;
+
+   mutex_lock(>group->lock);
+
+   pipe = bridge->entity.pipe ? bridge->entity.pipe :
+   >vdev.pipe;
+   ret = media_entity_pipeline_start(>vdev.entity, pipe);
+   if (ret) {
+   mutex_unlock(>group->lock);
+   return ret;
+   }
+
+   /* Only need to start stream if it's not running */
+   if (bridge->entity.stream_count <= 1)
+   v4l2_subdev_call(bridge, video, s_stream, 1);
+   if (source->entity.stream_count <= 1)
+   v4l2_subdev_call(source, video, s_stream, 1);
+
+   mutex_unlock(>group->lock);
+   } else {
+   v4l2_subdev_call(source, video, s_stream, 1);
+   }
+
+   return 0;
+}
+
+static int __rvin_stop_streaming(struct rvin_dev *vin)
+{
+   struct v4l2_subdev *source, *bridge = NULL;
+
+   source = vin_to_source(vin);
+   if (!source)
+   return -EINVAL;
+
+   if (vin_have_bridge(vin)) {
+   bridge = vin_to_bridge(vin);
+
+   if (!bridge)
+   return -EINVAL;
+
+   mutex_lock(>group->lock);
+
+   media_entity_pipeline_stop(>vdev.entity);
+
+   /* Only need to stop stream if there are no other users */
+   if (bridge->entity.stream_count <= 0)
+   v4l2_subdev_call(bridge, video, s_stream, 0);
+   if (source->entity.stream_count <= 0)
+   v4l2_subdev_call(source, video, s_stream, 0);
+
+   mutex_unlock(>group->lock);
+   } else {
+   v4l2_subdev_call(source, video, s_stream, 0);
+   }
+
+   return 0;
+}
+
 static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
struct rvin_dev *vin = vb2_get_drv_priv(vq);
-   struct v4l2_subdev *sd;
unsigned long flags;
int ret;
 
-   sd = vin_to_source(vin);
-   v4l2_subdev_call(sd, video, s_stream, 1);
+   ret = __rvin_start_streaming(vin);
+   if (ret)
+   return ret;
 
spin_lock_irqsave(>qlock, flags);
 
@@ -1122,7 +1194,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, 
unsigned int count)
/* Return all buffers if something went wrong */
if (ret) {
return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
-   v4l2_subdev_call(sd, video, s_stream, 0);
+   __rvin_stop_streaming(vin);
}
 
spin_unlock_irqrestore(>qlock, flags);
@@ -1133,7 +1205,6 @@ static int rvin_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 static void rvin_stop_streaming(struct vb2_queue *vq)
 {
struct rvin_dev *vin = vb2_get_drv_priv(vq);
-   struct v4l2_subdev *sd;
unsigned long flags;
int retries = 0;
 
@@ -1172,8 +1243,7 @@ static void rvin_stop_streaming(struct vb2_queue *vq)
 
spin_unlock_irqrestore(>qlock, flags);
 
-   sd = vin_to_source(vin);
-   v4l2_subdev_call(sd, video, s_stream, 0);
+   __rvin_stop_streaming(vin);
 
/* disable interrupts */
rvin_disable_interrupts(vin);
-- 
2.10.2

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


[PATCHv2 10/32] media: rcar-vin: use pad information when verifying media bus format

2016-11-12 Thread Niklas Söderlund
Now that the pad information is present in struct rvin_graph_entity use
it when verifying the media bus format.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 2c40b6a..fb6368c 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -48,6 +48,7 @@ static bool rvin_mbus_supported(struct rvin_graph_entity 
*entity)
};
 
code.index = 0;
+   code.pad = entity->source_pad_idx;
while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, )) {
code.index++;
switch (code.code) {
-- 
2.10.2

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


[PATCHv4] media: rcar-csi2: add Renesas R-Car MIPI CSI-2 driver

2016-11-12 Thread Niklas Söderlund
A V4L2 driver for Renesas R-Car MIPI CSI-2 interface. The driver
supports the rcar-vin driver on R-Car Gen3 SoCs where a separate driver
is needed to receive CSI-2.

Driver is based on a prototype by Koji Matsuoka in the Renesas BSP.

Signed-off-by: Niklas Söderlund 
---

Changes since v3:
- Update DT binding documentation with input from Geert Uytterhoeven, 
  thanks!

Changes since v2:
- Added media control pads as this is needed by the new rcar-vin driver.
- Update DT bindings after review comments and to add r8a7796 support.
- Add get_fmt handler.
- Fix media bus format error s/YUYV8/UYVY8/

Changes since v1:
- Drop dependency on a pad aware s_stream operation.
- Use the DT bindings format "renesas,-", thanks Geert
  for pointing this out.

 .../devicetree/bindings/media/rcar-csi2.txt| 116 
 drivers/media/platform/rcar-vin/Kconfig|  11 +
 drivers/media/platform/rcar-vin/Makefile   |   2 +
 drivers/media/platform/rcar-vin/rcar-csi2.c| 586 +
 4 files changed, 715 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rcar-csi2.txt
 create mode 100644 drivers/media/platform/rcar-vin/rcar-csi2.c

diff --git a/Documentation/devicetree/bindings/media/rcar-csi2.txt 
b/Documentation/devicetree/bindings/media/rcar-csi2.txt
new file mode 100644
index 000..a9788e3
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rcar-csi2.txt
@@ -0,0 +1,116 @@
+Renesas R-Car MIPI CSI-2
+
+
+The rcar-csi2 device provides MIPI CSI-2 capabilities for the Renesas R-Car
+family of devices. It is to be used in conjunction with the R-Car VIN module,
+which provides the video capture capabilities.
+
+ - compatible: Must be one or more of the following
+   - "renesas,r8a7795-csi2" for the R8A7795 device.
+   - "renesas,r8a7796-csi2" for the R8A7796 device.
+   - "renesas,rcar-gen3-csi2" for a generic R-Car Gen3 compatible device.
+
+   When compatible with a generic version nodes must list the
+   SoC-specific version corresponding to the platform first
+   followed by the generic version.
+
+ - reg: the register base and size for the device registers
+ - interrupts: the interrupt for the device
+ - clocks: Reference to the parent clock
+
+The device node should contain two 'port' child nodes according to the
+bindings defined in Documentation/devicetree/bindings/media/
+video-interfaces.txt. Port 0 should connect the node that is the video
+source for to the CSI-2. Port 1 should connect all the R-Car VIN 
+modules, which can make use of the CSI-2 module.
+
+- Port 0 - Video source
+   - Reg 0 - sub-node describing the endpoint that is the video source
+
+- Port 1 - VIN instances
+   - Reg 0 - sub-node describing the endpoint that is VIN0
+   - Reg 1 - sub-node describing the endpoint that is VIN1
+   - Reg 2 - sub-node describing the endpoint that is VIN2
+   - Reg 3 - sub-node describing the endpoint that is VIN3
+   - Reg 4 - sub-node describing the endpoint that is VIN4
+   - Reg 5 - sub-node describing the endpoint that is VIN5
+   - Reg 6 - sub-node describing the endpoint that is VIN6
+   - Reg 7 - sub-node describing the endpoint that is VIN7
+
+Example:
+
+/* SoC properties */
+
+csi20: csi2@fea8 {
+compatible = "renesas,r8a7795-csi2";
+reg = <0 0xfea8 0 0x1>;
+interrupts = <0 184 IRQ_TYPE_LEVEL_HIGH>;
+clocks = < CPG_MOD 714>;
+power-domains = < R8A7796_PD_ALWAYS_ON>;
+status = "disabled";
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@1 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+reg = <1>;
+
+csi20vin0: endpoint@0 {
+reg = <0>;
+remote-endpoint = <>;
+};
+csi20vin1: endpoint@1 {
+reg = <1>;
+remote-endpoint = <>;
+};
+csi20vin2: endpoint@2 {
+reg = <2>;
+remote-endpoint = <>;
+};
+csi20vin3: endpoint@3 {
+reg = <3>;
+remote-endpoint = <>;
+};
+csi20vin4: endpoint@4 {
+reg = <4>;
+remote-endpoint = <>;
+};
+

[PATCH 6/9] it913x: change driver model from i2c to platform

2016-11-12 Thread Antti Palosaari
That tuner is integrated to demodulator and communicates via
demodulators address space. We cannot register both demodulator
and tuner having same address to same I2C bus, so better to change
it platform driver in order to implement I2C adapter correctly.

Signed-off-by: Antti Palosaari 
---
 drivers/media/tuners/it913x.c | 89 +--
 drivers/media/tuners/it913x.h | 29 ++
 2 files changed, 48 insertions(+), 70 deletions(-)

diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c
index 6c3ef21..085e33c 100644
--- a/drivers/media/tuners/it913x.c
+++ b/drivers/media/tuners/it913x.c
@@ -21,10 +21,11 @@
  */
 
 #include "it913x.h"
+#include 
 #include 
 
 struct it913x_dev {
-   struct i2c_client *client;
+   struct platform_device *pdev;
struct regmap *regmap;
struct dvb_frontend *fe;
u8 chip_ver:2;
@@ -39,13 +40,14 @@ struct it913x_dev {
 static int it913x_init(struct dvb_frontend *fe)
 {
struct it913x_dev *dev = fe->tuner_priv;
+   struct platform_device *pdev = dev->pdev;
int ret;
unsigned int utmp;
u8 iqik_m_cal, nv_val, buf[2];
static const u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
unsigned long timeout;
 
-   dev_dbg(>client->dev, "role %u\n", dev->role);
+   dev_dbg(>dev, "role %u\n", dev->role);
 
ret = regmap_write(dev->regmap, 0x80ec4c, 0x68);
if (ret)
@@ -73,7 +75,7 @@ static int it913x_init(struct dvb_frontend *fe)
iqik_m_cal = 6;
break;
default:
-   dev_err(>client->dev, "unknown clock identifier %d\n", 
utmp);
+   dev_err(>dev, "unknown clock identifier %d\n", utmp);
goto err;
}
 
@@ -98,14 +100,14 @@ static int it913x_init(struct dvb_frontend *fe)
break;
}
 
-   dev_dbg(>client->dev, "r_fbc_m_bdry took %u ms, val %u\n",
+   dev_dbg(>dev, "r_fbc_m_bdry took %u ms, val %u\n",
jiffies_to_msecs(jiffies) -
(jiffies_to_msecs(timeout) - TIMEOUT), utmp);
 
dev->fn_min = dev->xtal * utmp;
dev->fn_min /= (dev->fdiv * nv_val);
dev->fn_min *= 1000;
-   dev_dbg(>client->dev, "fn_min %u\n", dev->fn_min);
+   dev_dbg(>dev, "fn_min %u\n", dev->fn_min);
 
/*
 * Chip version BX never sets that flag so we just wait 50ms in that
@@ -125,7 +127,7 @@ static int it913x_init(struct dvb_frontend *fe)
break;
}
 
-   dev_dbg(>client->dev, "p_tsm_init_mode took %u ms, val 
%u\n",
+   dev_dbg(>dev, "p_tsm_init_mode took %u ms, val %u\n",
jiffies_to_msecs(jiffies) -
(jiffies_to_msecs(timeout) - TIMEOUT), utmp);
} else {
@@ -152,16 +154,17 @@ static int it913x_init(struct dvb_frontend *fe)
 
return 0;
 err:
-   dev_dbg(>client->dev, "failed %d\n", ret);
+   dev_dbg(>dev, "failed %d\n", ret);
return ret;
 }
 
 static int it913x_sleep(struct dvb_frontend *fe)
 {
struct it913x_dev *dev = fe->tuner_priv;
+   struct platform_device *pdev = dev->pdev;
int ret, len;
 
-   dev_dbg(>client->dev, "role %u\n", dev->role);
+   dev_dbg(>dev, "role %u\n", dev->role);
 
dev->active = false;
 
@@ -178,7 +181,7 @@ static int it913x_sleep(struct dvb_frontend *fe)
else
len = 15;
 
-   dev_dbg(>client->dev, "role %u, len %d\n", dev->role, len);
+   dev_dbg(>dev, "role %u, len %d\n", dev->role, len);
 
ret = regmap_bulk_write(dev->regmap, 0x80ec02,

"\x3f\x1f\x3f\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
@@ -210,13 +213,14 @@ static int it913x_sleep(struct dvb_frontend *fe)
 
return 0;
 err:
-   dev_dbg(>client->dev, "failed %d\n", ret);
+   dev_dbg(>dev, "failed %d\n", ret);
return ret;
 }
 
 static int it913x_set_params(struct dvb_frontend *fe)
 {
struct it913x_dev *dev = fe->tuner_priv;
+   struct platform_device *pdev = dev->pdev;
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
unsigned int utmp;
@@ -224,7 +228,7 @@ static int it913x_set_params(struct dvb_frontend *fe)
u16 iqik_m_cal, n_div;
u8 u8tmp, n, l_band, lna_band;
 
-   dev_dbg(>client->dev, "role=%u, frequency %u, bandwidth_hz %u\n",
+   dev_dbg(>dev, "role=%u, frequency %u, bandwidth_hz %u\n",
dev->role, c->frequency, c->bandwidth_hz);
 
if (!dev->active) {
@@ -290,7 +294,7 @@ static int it913x_set_params(struct dvb_frontend *fe)
pre_lo_freq += (u32) n << 13;
/* Frequency OMEGA_IQIK_M_CAL_MID*/
t_cal_freq = pre_lo_freq + (u32)iqik_m_cal;
-   dev_dbg(>client->dev, "t_cal_freq %u, pre_lo_freq %u\n",
+   dev_dbg(>dev, "t_cal_freq %u, 

[PATCH 1/9] af9035: read and store whole eeprom

2016-11-12 Thread Antti Palosaari
Read eeprom content to chip state and read values there when needed.
Also debug dump eeprom content.

Signed-off-by: Antti Palosaari 
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 126 +++---
 drivers/media/usb/dvb-usb-v2/af9035.h |   5 +-
 2 files changed, 60 insertions(+), 71 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index c673726..61dac6a 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -496,7 +496,8 @@ static int af9035_identify_state(struct dvb_usb_device *d, 
const char **name)
 {
struct state *state = d_to_priv(d);
struct usb_interface *intf = d->intf;
-   int ret, ts_mode_invalid;
+   int ret, i, ts_mode_invalid;
+   unsigned int utmp, eeprom_addr;
u8 tmp;
u8 wbuf[1] = { 1 };
u8 rbuf[4];
@@ -518,25 +519,48 @@ static int af9035_identify_state(struct dvb_usb_device 
*d, const char **name)
 state->prechip_version, state->chip_version, state->chip_type);
 
if (state->chip_type == 0x9135) {
-   if (state->chip_version == 0x02)
+   if (state->chip_version == 0x02) {
*name = AF9035_FIRMWARE_IT9135_V2;
-   else
+   utmp = 0x00461d;
+   } else {
*name = AF9035_FIRMWARE_IT9135_V1;
-   state->eeprom_addr = EEPROM_BASE_IT9135;
+   utmp = 0x00461b;
+   }
+
+   /* Check if eeprom exists */
+   ret = af9035_rd_reg(d, utmp, );
+   if (ret < 0)
+   goto err;
+
+   if (tmp == 0x00) {
+   dev_dbg(>dev, "no eeprom\n");
+   state->no_eeprom = true;
+   goto check_firmware_status;
+   }
+
+   eeprom_addr = EEPROM_BASE_IT9135;
} else if (state->chip_type == 0x9306) {
*name = AF9035_FIRMWARE_IT9303;
-   state->eeprom_addr = EEPROM_BASE_IT9135;
+   state->no_eeprom = true;
+   goto check_firmware_status;
} else {
*name = AF9035_FIRMWARE_AF9035;
-   state->eeprom_addr = EEPROM_BASE_AF9035;
+   eeprom_addr = EEPROM_BASE_AF9035;
+   }
+
+   /* Read and store eeprom */
+   for (i = 0; i < 256; i += 32) {
+   ret = af9035_rd_regs(d, eeprom_addr + i, >eeprom[i], 32);
+   if (ret < 0)
+   goto err;
}
 
+   dev_dbg(>dev, "eeprom dump:\n");
+   for (i = 0; i < 256; i += 16)
+   dev_dbg(>dev, "%*ph\n", 16, >eeprom[i]);
 
/* check for dual tuner mode */
-   ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, );
-   if (ret < 0)
-   goto err;
-
+   tmp = state->eeprom[EEPROM_TS_MODE];
ts_mode_invalid = 0;
switch (tmp) {
case 0:
@@ -560,7 +584,7 @@ static int af9035_identify_state(struct dvb_usb_device *d, 
const char **name)
if (ts_mode_invalid)
dev_info(>dev, "ts mode=%d not supported, defaulting to 
single tuner mode!", tmp);
 
-
+check_firmware_status:
ret = af9035_ctrl_msg(d, );
if (ret < 0)
goto err;
@@ -750,11 +774,7 @@ static int af9035_download_firmware(struct dvb_usb_device 
*d,
goto err;
 
/* tell the slave I2C address */
-   ret = af9035_rd_reg(d,
-   state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR,
-   );
-   if (ret < 0)
-   goto err;
+   tmp = state->eeprom[EEPROM_2ND_DEMOD_ADDR];
 
/* use default I2C address if eeprom has no address set */
if (!tmp)
@@ -819,7 +839,7 @@ static int af9035_read_config(struct dvb_usb_device *d)
struct state *state = d_to_priv(d);
int ret, i;
u8 tmp;
-   u16 tmp16, addr;
+   u16 tmp16;
 
/* demod I2C "address" */
state->af9033_i2c_addr[0] = 0x38;
@@ -837,20 +857,16 @@ static int af9035_read_config(struct dvb_usb_device *d)
if (state->chip_version == 0x02) {
state->af9033_config[0].tuner = AF9033_TUNER_IT9135_60;
state->af9033_config[1].tuner = AF9033_TUNER_IT9135_60;
-   tmp16 = 0x00461d; /* eeprom memory mapped location */
} else {
state->af9033_config[0].tuner = AF9033_TUNER_IT9135_38;
state->af9033_config[1].tuner = AF9033_TUNER_IT9135_38;
-   tmp16 = 0x00461b; /* eeprom memory mapped location */
}
 
-   /* check if eeprom exists */
-   ret = af9035_rd_reg(d, tmp16, );
-   if (ret < 0)
-   

[PATCH 2/9] af9033: convert to regmap api

2016-11-12 Thread Antti Palosaari
Use regmap to cover I2C register operations.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/Kconfig   |   1 +
 drivers/media/dvb-frontends/af9033.c  | 420 ++
 drivers/media/dvb-frontends/af9033_priv.h |   1 +
 3 files changed, 145 insertions(+), 277 deletions(-)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 0122255..51244e6 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -847,6 +847,7 @@ config DVB_M88RS2000
 config DVB_AF9033
tristate "Afatech AF9033 DVB-T demodulator"
depends on DVB_CORE && I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
 
 config DVB_HORUS3A
diff --git a/drivers/media/dvb-frontends/af9033.c 
b/drivers/media/dvb-frontends/af9033.c
index 9a8157a..5b806e8 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -21,11 +21,9 @@
 
 #include "af9033_priv.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  64
-
 struct af9033_dev {
struct i2c_client *client;
+   struct regmap *regmap;
struct dvb_frontend fe;
struct af9033_config cfg;
bool is_af9035;
@@ -43,134 +41,6 @@ struct af9033_dev {
u64 total_block_count;
 };
 
-/* write multiple registers */
-static int af9033_wr_regs(struct af9033_dev *dev, u32 reg, const u8 *val,
-   int len)
-{
-   int ret;
-   u8 buf[MAX_XFER_SIZE];
-   struct i2c_msg msg[1] = {
-   {
-   .addr = dev->client->addr,
-   .flags = 0,
-   .len = 3 + len,
-   .buf = buf,
-   }
-   };
-
-   if (3 + len > sizeof(buf)) {
-   dev_warn(>client->dev,
-   "i2c wr reg=%04x: len=%d is too big!\n",
-   reg, len);
-   return -EINVAL;
-   }
-
-   buf[0] = (reg >> 16) & 0xff;
-   buf[1] = (reg >>  8) & 0xff;
-   buf[2] = (reg >>  0) & 0xff;
-   memcpy([3], val, len);
-
-   ret = i2c_transfer(dev->client->adapter, msg, 1);
-   if (ret == 1) {
-   ret = 0;
-   } else {
-   dev_warn(>client->dev, "i2c wr failed=%d reg=%06x 
len=%d\n",
-   ret, reg, len);
-   ret = -EREMOTEIO;
-   }
-
-   return ret;
-}
-
-/* read multiple registers */
-static int af9033_rd_regs(struct af9033_dev *dev, u32 reg, u8 *val, int len)
-{
-   int ret;
-   u8 buf[3] = { (reg >> 16) & 0xff, (reg >> 8) & 0xff,
-   (reg >> 0) & 0xff };
-   struct i2c_msg msg[2] = {
-   {
-   .addr = dev->client->addr,
-   .flags = 0,
-   .len = sizeof(buf),
-   .buf = buf
-   }, {
-   .addr = dev->client->addr,
-   .flags = I2C_M_RD,
-   .len = len,
-   .buf = val
-   }
-   };
-
-   ret = i2c_transfer(dev->client->adapter, msg, 2);
-   if (ret == 2) {
-   ret = 0;
-   } else {
-   dev_warn(>client->dev, "i2c rd failed=%d reg=%06x 
len=%d\n",
-   ret, reg, len);
-   ret = -EREMOTEIO;
-   }
-
-   return ret;
-}
-
-
-/* write single register */
-static int af9033_wr_reg(struct af9033_dev *dev, u32 reg, u8 val)
-{
-   return af9033_wr_regs(dev, reg, , 1);
-}
-
-/* read single register */
-static int af9033_rd_reg(struct af9033_dev *dev, u32 reg, u8 *val)
-{
-   return af9033_rd_regs(dev, reg, val, 1);
-}
-
-/* write single register with mask */
-static int af9033_wr_reg_mask(struct af9033_dev *dev, u32 reg, u8 val,
-   u8 mask)
-{
-   int ret;
-   u8 tmp;
-
-   /* no need for read if whole reg is written */
-   if (mask != 0xff) {
-   ret = af9033_rd_regs(dev, reg, , 1);
-   if (ret)
-   return ret;
-
-   val &= mask;
-   tmp &= ~mask;
-   val |= tmp;
-   }
-
-   return af9033_wr_regs(dev, reg, , 1);
-}
-
-/* read single register with mask */
-static int af9033_rd_reg_mask(struct af9033_dev *dev, u32 reg, u8 *val,
-   u8 mask)
-{
-   int ret, i;
-   u8 tmp;
-
-   ret = af9033_rd_regs(dev, reg, , 1);
-   if (ret)
-   return ret;
-
-   tmp &= mask;
-
-   /* find position of the first bit */
-   for (i = 0; i < 8; i++) {
-   if ((mask >> i) & 0x01)
-   break;
-   }
-   *val = tmp >> i;
-
-   return 0;
-}
-
 /* write reg val table using reg addr auto increment */
 static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
const struct reg_val *tab, int tab_len)
@@ 

[PATCH 3/9] af9033: use 64-bit div macro where possible

2016-11-12 Thread Antti Palosaari
Replace Booth's binary division algo with 64-bit multiply and division.
Fix related IF calculations.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/af9033.c  | 103 +-
 drivers/media/dvb-frontends/af9033_priv.h |   1 +
 2 files changed, 32 insertions(+), 72 deletions(-)

diff --git a/drivers/media/dvb-frontends/af9033.c 
b/drivers/media/dvb-frontends/af9033.c
index 5b806e8..e9ff0f6 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -79,40 +79,14 @@ static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
return ret;
 }
 
-static u32 af9033_div(struct af9033_dev *dev, u32 a, u32 b, u32 x)
-{
-   u32 r = 0, c = 0, i;
-
-   dev_dbg(>client->dev, "a=%d b=%d x=%d\n", a, b, x);
-
-   if (a > b) {
-   c = a / b;
-   a = a - c * b;
-   }
-
-   for (i = 0; i < x; i++) {
-   if (a >= b) {
-   r += 1;
-   a -= b;
-   }
-   a <<= 1;
-   r <<= 1;
-   }
-   r = (c << (u32)x) + r;
-
-   dev_dbg(>client->dev, "a=%d b=%d x=%d r=%d r=%x\n", a, b, x, r, r);
-
-   return r;
-}
-
 static int af9033_init(struct dvb_frontend *fe)
 {
struct af9033_dev *dev = fe->demodulator_priv;
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret, i, len;
+   unsigned int utmp;
const struct reg_val *init;
u8 buf[4];
-   u32 adc_cw, clock_cw;
struct reg_val_mask tab[] = {
{ 0x80fb24, 0x00, 0x08 },
{ 0x80004c, 0x00, 0xff },
@@ -143,19 +117,18 @@ static int af9033_init(struct dvb_frontend *fe)
};
 
/* program clock control */
-   clock_cw = af9033_div(dev, dev->cfg.clock, 100ul, 19ul);
-   buf[0] = (clock_cw >>  0) & 0xff;
-   buf[1] = (clock_cw >>  8) & 0xff;
-   buf[2] = (clock_cw >> 16) & 0xff;
-   buf[3] = (clock_cw >> 24) & 0xff;
-
-   dev_dbg(>client->dev, "clock=%d clock_cw=%08x\n",
-   dev->cfg.clock, clock_cw);
-
+   utmp = div_u64((u64)dev->cfg.clock * 0x8, 100);
+   buf[0] = (utmp >>  0) & 0xff;
+   buf[1] = (utmp >>  8) & 0xff;
+   buf[2] = (utmp >> 16) & 0xff;
+   buf[3] = (utmp >> 24) & 0xff;
ret = regmap_bulk_write(dev->regmap, 0x800025, buf, 4);
if (ret)
goto err;
 
+   dev_dbg(>client->dev, "clk=%u clk_cw=%08x\n",
+   dev->cfg.clock, utmp);
+
/* program ADC control */
for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) {
if (clock_adc_lut[i].clock == dev->cfg.clock)
@@ -168,18 +141,17 @@ static int af9033_init(struct dvb_frontend *fe)
goto err;
}
 
-   adc_cw = af9033_div(dev, clock_adc_lut[i].adc, 100ul, 19ul);
-   buf[0] = (adc_cw >>  0) & 0xff;
-   buf[1] = (adc_cw >>  8) & 0xff;
-   buf[2] = (adc_cw >> 16) & 0xff;
-
-   dev_dbg(>client->dev, "adc=%d adc_cw=%06x\n",
-   clock_adc_lut[i].adc, adc_cw);
-
+   utmp = div_u64((u64)clock_adc_lut[i].adc * 0x8, 100);
+   buf[0] = (utmp >>  0) & 0xff;
+   buf[1] = (utmp >>  8) & 0xff;
+   buf[2] = (utmp >> 16) & 0xff;
ret = regmap_bulk_write(dev->regmap, 0x80f1cd, buf, 3);
if (ret)
goto err;
 
+   dev_dbg(>client->dev, "adc=%u adc_cw=%06x\n",
+   clock_adc_lut[i].adc, utmp);
+
/* program register table */
for (i = 0; i < ARRAY_SIZE(tab); i++) {
ret = regmap_update_bits(dev->regmap, tab[i].reg, tab[i].mask,
@@ -397,9 +369,10 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
 {
struct af9033_dev *dev = fe->demodulator_priv;
struct dtv_frontend_properties *c = >dtv_property_cache;
-   int ret, i, spec_inv, sampling_freq;
+   int ret, i;
+   unsigned int utmp, adc_freq;
u8 tmp, buf[3], bandwidth_reg_val;
-   u32 if_frequency, freq_cw, adc_freq;
+   u32 if_frequency;
 
dev_dbg(>client->dev, "frequency=%d bandwidth_hz=%d\n",
c->frequency, c->bandwidth_hz);
@@ -449,8 +422,6 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
 
/* program frequency control */
if (c->bandwidth_hz != dev->bandwidth_hz) {
-   spec_inv = dev->cfg.spec_inv ? -1 : 1;
-
for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) {
if (clock_adc_lut[i].clock == dev->cfg.clock)
break;
@@ -464,42 +435,30 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
}
adc_freq = clock_adc_lut[i].adc;
 
+   if (dev->cfg.adc_multiplier == AF9033_ADC_MULTIPLIER_2X)
+   adc_freq = 2 * adc_freq;
+
/* get used IF frequency */
if (fe->ops.tuner_ops.get_if_frequency)
   

[PATCH 7/9] af9035: register it9133 tuner using platform binding

2016-11-12 Thread Antti Palosaari
it913x tuner driver is changed to platform model so we need bind it
using platform_device_register_data().

Also remove hacks from I2C adapter where fake tuner driver address
(addr >> 1) were used as those are no longer needed.

Signed-off-by: Antti Palosaari 
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 121 --
 drivers/media/usb/dvb-usb-v2/af9035.h |   2 +
 2 files changed, 59 insertions(+), 64 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 61dac6a..d89d0d6 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -335,14 +335,12 @@ static int af9035_i2c_master_xfer(struct i2c_adapter 
*adap,
/* TODO: correct limits > 40 */
ret = -EOPNOTSUPP;
} else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
-  (msg[0].addr == state->af9033_i2c_addr[1]) ||
-  (state->chip_type == 0x9135)) {
+  (msg[0].addr == state->af9033_i2c_addr[1])) {
/* demod access via firmware interface */
u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
msg[0].buf[2];
 
-   if (msg[0].addr == state->af9033_i2c_addr[1] ||
-   msg[0].addr == (state->af9033_i2c_addr[1] >> 1))
+   if (msg[0].addr == state->af9033_i2c_addr[1])
reg |= 0x10;
 
ret = af9035_rd_regs(d, reg, [1].buf[0],
@@ -396,14 +394,12 @@ static int af9035_i2c_master_xfer(struct i2c_adapter 
*adap,
/* TODO: correct limits > 40 */
ret = -EOPNOTSUPP;
} else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
-  (msg[0].addr == state->af9033_i2c_addr[1]) ||
-  (state->chip_type == 0x9135)) {
+  (msg[0].addr == state->af9033_i2c_addr[1])) {
/* demod access via firmware interface */
u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
msg[0].buf[2];
 
-   if (msg[0].addr == state->af9033_i2c_addr[1] ||
-   msg[0].addr == (state->af9033_i2c_addr[1] >> 1))
+   if (msg[0].addr == state->af9033_i2c_addr[1])
reg |= 0x10;
 
ret = af9035_wr_regs(d, reg, [0].buf[3],
@@ -1250,30 +1246,11 @@ static int af9035_frontend_detach(struct 
dvb_usb_adapter *adap)
struct state *state = adap_to_priv(adap);
struct dvb_usb_device *d = adap_to_d(adap);
struct usb_interface *intf = d->intf;
-   int demod2;
 
dev_dbg(>dev, "adap->id=%d\n", adap->id);
 
-   /*
-* For dual tuner devices we have to resolve 2nd demod client, as there
-* is two different kind of tuner drivers; one is using I2C binding
-* and the other is using DVB attach/detach binding.
-*/
-   switch (state->af9033_config[adap->id].tuner) {
-   case AF9033_TUNER_IT9135_38:
-   case AF9033_TUNER_IT9135_51:
-   case AF9033_TUNER_IT9135_52:
-   case AF9033_TUNER_IT9135_60:
-   case AF9033_TUNER_IT9135_61:
-   case AF9033_TUNER_IT9135_62:
-   demod2 = 2;
-   break;
-   default:
-   demod2 = 1;
-   }
-
if (adap->id == 1) {
-   if (state->i2c_client[demod2])
+   if (state->i2c_client[1])
af9035_del_i2c_dev(d);
} else if (adap->id == 0) {
if (state->i2c_client[0])
@@ -1513,50 +1490,55 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
-   {
-   struct it913x_config it913x_config = {
-   .fe = adap->fe[0],
-   .chip_ver = 1,
-   };
-
-   if (state->dual_mode) {
-   if (adap->id == 0)
-   it913x_config.role = IT913X_ROLE_DUAL_MASTER;
-   else
-   it913x_config.role = IT913X_ROLE_DUAL_SLAVE;
-   }
-
-   ret = af9035_add_i2c_dev(d, "it913x",
-   state->af9033_i2c_addr[adap->id] >> 1,
-   _config, >i2c_adap);
-   if (ret)
-   goto err;
-
-   fe = adap->fe[0];
-   break;
-   }
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
{
-   struct it913x_config it913x_config = {
+   struct 

[PATCH 9/9] af9035: correct demod i2c addresses

2016-11-12 Thread Antti Palosaari
Chip uses so called 8-bit i2c addresses, but on bus there is of
course correct 7-bit addresses with rw bit as lsb - verified
with oscilloscope.

Lets still use correct addresses in driver.

Signed-off-by: Antti Palosaari 
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index da29b6f..166ce09 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -772,9 +772,9 @@ static int af9035_download_firmware(struct dvb_usb_device 
*d,
/* tell the slave I2C address */
tmp = state->eeprom[EEPROM_2ND_DEMOD_ADDR];
 
-   /* use default I2C address if eeprom has no address set */
+   /* Use default I2C address if eeprom has no address set */
if (!tmp)
-   tmp = 0x3a;
+   tmp = 0x1d << 1; /* 8-bit format used by chip */
 
if ((state->chip_type == 0x9135) ||
(state->chip_type == 0x9306)) {
@@ -837,9 +837,9 @@ static int af9035_read_config(struct dvb_usb_device *d)
u8 tmp;
u16 tmp16;
 
-   /* demod I2C "address" */
-   state->af9033_i2c_addr[0] = 0x38;
-   state->af9033_i2c_addr[1] = 0x3a;
+   /* Demod I2C address */
+   state->af9033_i2c_addr[0] = 0x1c;
+   state->af9033_i2c_addr[1] = 0x1d;
state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
@@ -878,12 +878,13 @@ static int af9035_read_config(struct dvb_usb_device *d)
state->ir_type = state->eeprom[EEPROM_IR_TYPE];
 
if (state->dual_mode) {
-   /* read 2nd demodulator I2C address */
+   /* Read 2nd demodulator I2C address. 8-bit format on eeprom */
tmp = state->eeprom[EEPROM_2ND_DEMOD_ADDR];
if (tmp)
-   state->af9033_i2c_addr[1] = tmp;
+   state->af9033_i2c_addr[1] = tmp >> 1;
 
-   dev_dbg(>dev, "2nd demod I2C addr=%02x\n", tmp);
+   dev_dbg(>dev, "2nd demod I2C addr=%02x\n",
+   state->af9033_i2c_addr[1]);
}
 
for (i = 0; i < state->dual_mode + 1; i++) {
-- 
http://palosaari.fi/

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


[PATCH 4/9] af9033: style related and minor changes

2016-11-12 Thread Antti Palosaari
Fix coding style and other small issues.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/af9033.c  | 313 +++---
 drivers/media/dvb-frontends/af9033.h  |   3 +-
 drivers/media/dvb-frontends/af9033_priv.h |  82 +---
 3 files changed, 211 insertions(+), 187 deletions(-)

diff --git a/drivers/media/dvb-frontends/af9033.c 
b/drivers/media/dvb-frontends/af9033.c
index e9ff0f6..b86a01e 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -41,18 +41,19 @@ struct af9033_dev {
u64 total_block_count;
 };
 
-/* write reg val table using reg addr auto increment */
+/* Write reg val table using reg addr auto increment */
 static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
-   const struct reg_val *tab, int tab_len)
+const struct reg_val *tab, int tab_len)
 {
+   struct i2c_client *client = dev->client;
 #define MAX_TAB_LEN 212
int ret, i, j;
u8 buf[1 + MAX_TAB_LEN];
 
-   dev_dbg(>client->dev, "tab_len=%d\n", tab_len);
+   dev_dbg(>dev, "tab_len=%d\n", tab_len);
 
if (tab_len > sizeof(buf)) {
-   dev_warn(>client->dev, "tab len %d is too big\n", tab_len);
+   dev_warn(>dev, "tab len %d is too big\n", tab_len);
return -EINVAL;
}
 
@@ -72,51 +73,52 @@ static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
}
 
return 0;
-
 err:
-   dev_dbg(>client->dev, "failed=%d\n", ret);
-
+   dev_dbg(>dev, "failed=%d\n", ret);
return ret;
 }
 
 static int af9033_init(struct dvb_frontend *fe)
 {
struct af9033_dev *dev = fe->demodulator_priv;
+   struct i2c_client *client = dev->client;
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret, i, len;
unsigned int utmp;
const struct reg_val *init;
u8 buf[4];
struct reg_val_mask tab[] = {
-   { 0x80fb24, 0x00, 0x08 },
-   { 0x80004c, 0x00, 0xff },
-   { 0x00f641, dev->cfg.tuner, 0xff },
-   { 0x80f5ca, 0x01, 0x01 },
-   { 0x80f715, 0x01, 0x01 },
-   { 0x00f41f, 0x04, 0x04 },
-   { 0x00f41a, 0x01, 0x01 },
-   { 0x80f731, 0x00, 0x01 },
-   { 0x00d91e, 0x00, 0x01 },
-   { 0x00d919, 0x00, 0x01 },
-   { 0x80f732, 0x00, 0x01 },
-   { 0x00d91f, 0x00, 0x01 },
-   { 0x00d91a, 0x00, 0x01 },
-   { 0x80f730, 0x00, 0x01 },
-   { 0x80f778, 0x00, 0xff },
-   { 0x80f73c, 0x01, 0x01 },
-   { 0x80f776, 0x00, 0x01 },
-   { 0x00d8fd, 0x01, 0xff },
-   { 0x00d830, 0x01, 0xff },
-   { 0x00d831, 0x00, 0xff },
-   { 0x00d832, 0x00, 0xff },
-   { 0x80f985, dev->ts_mode_serial, 0x01 },
-   { 0x80f986, dev->ts_mode_parallel, 0x01 },
-   { 0x00d827, 0x00, 0xff },
-   { 0x00d829, 0x00, 0xff },
-   { 0x800045, dev->cfg.adc_multiplier, 0xff },
+   {0x80fb24, 0x00, 0x08},
+   {0x80004c, 0x00, 0xff},
+   {0x00f641, dev->cfg.tuner, 0xff},
+   {0x80f5ca, 0x01, 0x01},
+   {0x80f715, 0x01, 0x01},
+   {0x00f41f, 0x04, 0x04},
+   {0x00f41a, 0x01, 0x01},
+   {0x80f731, 0x00, 0x01},
+   {0x00d91e, 0x00, 0x01},
+   {0x00d919, 0x00, 0x01},
+   {0x80f732, 0x00, 0x01},
+   {0x00d91f, 0x00, 0x01},
+   {0x00d91a, 0x00, 0x01},
+   {0x80f730, 0x00, 0x01},
+   {0x80f778, 0x00, 0xff},
+   {0x80f73c, 0x01, 0x01},
+   {0x80f776, 0x00, 0x01},
+   {0x00d8fd, 0x01, 0xff},
+   {0x00d830, 0x01, 0xff},
+   {0x00d831, 0x00, 0xff},
+   {0x00d832, 0x00, 0xff},
+   {0x80f985, dev->ts_mode_serial, 0x01},
+   {0x80f986, dev->ts_mode_parallel, 0x01},
+   {0x00d827, 0x00, 0xff},
+   {0x00d829, 0x00, 0xff},
+   {0x800045, dev->cfg.adc_multiplier, 0xff},
};
 
-   /* program clock control */
+   dev_dbg(>dev, "\n");
+
+   /* Main clk control */
utmp = div_u64((u64)dev->cfg.clock * 0x8, 100);
buf[0] = (utmp >>  0) & 0xff;
buf[1] = (utmp >>  8) & 0xff;
@@ -126,17 +128,15 @@ static int af9033_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   dev_dbg(>client->dev, "clk=%u clk_cw=%08x\n",
-   dev->cfg.clock, utmp);
+   dev_dbg(>dev, "clk=%u clk_cw=%08x\n", dev->cfg.clock, utmp);
 
-   /* program ADC control */
+   /* ADC clk control */
for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) {
if (clock_adc_lut[i].clock == dev->cfg.clock)
break;
}
 

[PATCH 5/9] af9033: return regmap for integrated IT913x tuner driver

2016-11-12 Thread Antti Palosaari
IT9130 series contains integrated tuner driver, which uses that
demodulator address space. Return regmap in order to allow it913x
driver communication.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/af9033.c | 1 +
 drivers/media/dvb-frontends/af9033.h | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/drivers/media/dvb-frontends/af9033.c 
b/drivers/media/dvb-frontends/af9033.c
index b86a01e..2b86436 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -1154,6 +1154,7 @@ static int af9033_probe(struct i2c_client *client,
cfg->ops->pid_filter = af9033_pid_filter;
cfg->ops->pid_filter_ctrl = af9033_pid_filter_ctrl;
}
+   cfg->regmap = dev->regmap;
i2c_set_clientdata(client, dev);
 
dev_info(>dev, "Afatech AF9033 successfully attached\n");
diff --git a/drivers/media/dvb-frontends/af9033.h 
b/drivers/media/dvb-frontends/af9033.h
index c87367f..1a23c64 100644
--- a/drivers/media/dvb-frontends/af9033.h
+++ b/drivers/media/dvb-frontends/af9033.h
@@ -87,6 +87,12 @@ struct af9033_config {
 * returned by that driver
 */
struct dvb_frontend **fe;
+
+   /*
+* regmap for IT913x integrated tuner driver
+* returned by that driver
+*/
+   struct regmap *regmap;
 };
 
 struct af9033_ops {
-- 
http://palosaari.fi/

--
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 8/9] it913x: add chip device ids for binding

2016-11-12 Thread Antti Palosaari
Driver supports 2 different device versions, AX and BX. Use device
IDs to pass chip version information to driver.

Signed-off-by: Antti Palosaari 
---
 drivers/media/tuners/it913x.c | 11 ++-
 drivers/media/tuners/it913x.h |  5 -
 drivers/media/usb/dvb-usb-v2/af9035.c |  8 
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c
index 085e33c..66d77df 100644
--- a/drivers/media/tuners/it913x.c
+++ b/drivers/media/tuners/it913x.c
@@ -394,6 +394,7 @@ static int it913x_probe(struct platform_device *pdev)
struct it913x_platform_data *pdata = pdev->dev.platform_data;
struct dvb_frontend *fe = pdata->fe;
struct it913x_dev *dev;
+   const struct platform_device_id *id = platform_get_device_id(pdev);
int ret;
char *chip_ver_str;
 
@@ -407,7 +408,7 @@ static int it913x_probe(struct platform_device *pdev)
dev->pdev = pdev;
dev->regmap = pdata->regmap;
dev->fe = pdata->fe;
-   dev->chip_ver = pdata->chip_ver;
+   dev->chip_ver = id->driver_data;
dev->role = pdata->role;
 
fe->tuner_priv = dev;
@@ -445,6 +446,13 @@ static int it913x_remove(struct platform_device *pdev)
return 0;
 }
 
+static const struct platform_device_id it913x_id_table[] = {
+   {"it9133ax-tuner", 1},
+   {"it9133bx-tuner", 2},
+   {},
+};
+MODULE_DEVICE_TABLE(platform, it913x_id_table);
+
 static struct platform_driver it913x_driver = {
.driver = {
.name   = "it913x",
@@ -452,6 +460,7 @@ static struct platform_driver it913x_driver = {
},
.probe  = it913x_probe,
.remove = it913x_remove,
+   .id_table   = it913x_id_table,
 };
 
 module_platform_driver(it913x_driver);
diff --git a/drivers/media/tuners/it913x.h b/drivers/media/tuners/it913x.h
index aa18862..5df7653 100644
--- a/drivers/media/tuners/it913x.h
+++ b/drivers/media/tuners/it913x.h
@@ -29,21 +29,16 @@
  * struct it913x_platform_data - Platform data for the it913x driver
  * @regmap: af9033 demod driver regmap.
  * @dvb_frontend: af9033 demod driver DVB frontend.
- * @chip_ver: Used chip version. 1=IT9133 AX, 2=IT9133 BX.
  * @role: Chip role, single or dual configuration.
  */
 
 struct it913x_platform_data {
struct regmap *regmap;
struct dvb_frontend *fe;
-   unsigned int chip_ver:2;
 #define IT913X_ROLE_SINGLE 0
 #define IT913X_ROLE_DUAL_MASTER1
 #define IT913X_ROLE_DUAL_SLAVE 2
unsigned int role:2;
 };
 
-/* Backwards compatibility */
-#define it913x_config it913x_platform_data
-
 #endif
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index d89d0d6..da29b6f 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1495,6 +1495,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
case AF9033_TUNER_IT9135_62:
{
struct platform_device *pdev;
+   const char *name;
struct it913x_platform_data it913x_pdata = {
.regmap = state->af9033_config[adap->id].regmap,
.fe = adap->fe[0],
@@ -1504,12 +1505,12 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
-   it913x_pdata.chip_ver = 1;
+   name = "it9133ax-tuner";
break;
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
-   it913x_pdata.chip_ver = 2;
+   name = "it9133bx-tuner";
break;
}
 
@@ -1523,8 +1524,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
}
 
request_module("%s", "it913x");
-   pdev = platform_device_register_data(>intf->dev,
-"it913x",
+   pdev = platform_device_register_data(>intf->dev, name,
 PLATFORM_DEVID_AUTO,
 _pdata,
 sizeof(it913x_pdata));
-- 
http://palosaari.fi/

--
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: Question about 2 gp8psk patches I noticed, and possible bug.

2016-11-12 Thread VDR User
Ok, I think I had too much patching going on (I switched from 4.8.4
kernel drivers to media_build) so I started from scratch with a fresh
update to kernel 4.8.7. First I applied the dma stuff in this order:

(from https://patchwork.linuxtv.org/patch/37395/raw/)
v2-18-31-gp8psk-don-t-do-DMA-on-stack.patch
(from https://patchwork.linuxtv.org/patch/37386/raw/)
v2-19-31-gp8psk-don-t-go-past-the-buffer-size.patch
(from https://patchwork.linuxtv.org/patch/37929/raw/)
media-gp8psk-fix-gp8psk_usb_in_op-logic.patch

It works fine at this point but we still have the attach bug. Then I applied:

(from https://patchwork.linuxtv.org/patch/38040/raw/)
Question-about-2-gp8psk-patches-I-noticed-and-possible-bug..patch

Attach bug is fixed, tuning works, module unloads without crashing.
Everything seems ok! I think the gp8psk issues are resolved with the
above 4 patches. As you know, there are some other drivers which
attach the same way as gp8psk was.

Thanks for your help & patience!

One quick question.. Shouldn't gp8psk_fe be listed in the "used by"
column of dvb_usb_gp8psk or the other dvb_* modules?:

Module  Size  Used by
gp8psk_fe   3803  1
dvb_usb_gp8psk  7344  19
dvb_usb17495  1 dvb_usb_gp8psk
dvb_core   62327  1 dvb_usb
--
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: Question about 2 gp8psk patches I noticed, and possible bug.

2016-11-12 Thread Mauro Carvalho Chehab
Em Fri, 11 Nov 2016 20:45:31 -0800
VDR User  escreveu:

> > Sorry, forgot to add one file to the patch.
> >
> > The right fix is this one.  
> 
> This patch seems to fix the unload crash but unfortunately now all I
> get is "frontend 0/0 timed out while tuning".

I don't see any reason why it should cause any regressions.

> Forgot to mention that I didn't see the gp8psk-fe entry in menuconfig
> customize frontends even though the gp8psk module was enabled and set
> to . When I exited and saved .config, DVB_GP8PSK_FE was set though.
> Maybe something at `config DVB_USB_GP8PSK` in
> drivers/media/usb/dvb-usb/Kconfig needs adjusting too?

I used the same approach taken on as102: the frontend driver is auto-selected
when the gsp8psk driver is selected, and its entry is invisible on normal
make config/gconfig/xconfig, as the drivers can only be used together.

You can still see it at the graphical options if you enable it to show
the hidden symbols.

> And I noticed something different in dmesg when loading the module.
> The prior to the patch it logged:
> 
> [   92.041222] dvb-usb: found a 'Genpix SkyWalker-2 DVB-S receiver' in
> warm state.
> [   93.104244] gp8psk: FW Version = 2.14.6 (0x20e06)  Build 2010/10/10
> [   93.104991] gp8psk: FPGA Version = 1
> [   93.105367] dvb-usb: will pass the complete MPEG2 transport stream
> to the software demuxer.
> [   93.105549] DVB: registering new adapter (Genpix SkyWalker-2 DVB-S 
> receiver)
> [   93.106614] usb 1-2: DVB: registering adapter 0 frontend 0 (Genpix 
> DVB-S)...
> [   93.107620] dvb-usb: Genpix SkyWalker-2 DVB-S receiver successfully
> initialized and connected.
> [   93.107627] gp8psk: found Genpix USB device pID = 206 (hex)
> [   93.107674] usbcore: registered new interface driver dvb_usb_gp8psk
> 
> After the patch:
> 
> [  542.926237] dvb-usb: found a 'Genpix SkyWalker-2 DVB-S receiver' in
> warm state.
> [  543.989074] gp8psk: FW Version = 208.00.0 (0xd0)  Build 2193/15/159
> [  543.989945] gp8psk: FPGA Version = 2
> [  543.990071] dvb-usb: will pass the complete MPEG2 transport stream
> to the software demuxer.
> [  543.990257] dvbdev: DVB: registering new adapter (Genpix
> SkyWalker-2 DVB-S receiver)
> [  543.994589] usb 1-2: DVB: registering adapter 0 frontend 0 (Genpix 
> DVB-S)...
> [  543.995575] dvb-usb: Genpix SkyWalker-2 DVB-S receiver successfully
> initialized and connected.
> [  543.995581] gp8psk: found Genpix USB device pID = 206 (hex)
> [  543.995628] usbcore: registered new interface driver dvb_usb_gp8psk
> 
> The FW Version and FPGA Version is messed up. Is it possible that
> could cause the tuner timeout?

The version itself is just an information retrieved from the device.
It is not the cause of the trouble. It could be another  symptom, though.
Perhaps some failure happened during device probe, causing the device
to be unstable.

Time to enable the debug messages from the driver and see what changed.

I generated a new version of the patch that should allow enabling all
debug messages from the frontend at once. It also fixes checkpatch
issues.

Please create new file: /etc/modprobe.d/gp8psk.conf with the following 
contents:

options dvb-usb-gp8psk debug=15
options gp8psk-fe debug=1

This should allow getting debug messages with and without the patch.
I added a new debug message inside the patch, to indicate if the frontend
driver asks for firmware reload, and another one to indicate that the
firmware driver was properly loaded. Except for that, the other messages
weren't touched.

Could you please apply the patch and pastebin the messages? Please
also pastebin the messages without the patch.

Thanks!
Mauro

[PATCH] [media] gp8psk: Fix DVB frontend attach

The DVB binding schema at the DVB core assumes that the
frontend is a separate driver. Faling to do that causes
OOPS when the module is removed, as it tries to do a
symbol_put_addr on an internal symbol, causing craches like:

 WARNING: CPU: 1 PID: 28102 at kernel/module.c:1108 module_put+0x57/0x70
 Modules linked in: dvb_usb_gp8psk(-) dvb_usb dvb_core nvidia_drm(PO) 
nvidia_modeset(PO) snd_hda_codec_hdmi snd_hda_intel snd_hda_codec snd_hwdep 
snd_hda_core snd_pcm snd_timer snd soundcore nvidia(PO) [last unloaded: rc_core]
 CPU: 1 PID: 28102 Comm: rmmod Tainted: PWC O 4.8.4-build.1 #1
 Hardware name: MSI MS-7309/MS-7309, BIOS V1.12 02/23/2009
  c12ba080   c103ed6a c1616014 0001 6dc6
 c1615862 0454 c109e8a7 c109e8a7 0009   f13f6a10
 f5f5a600 c103ee33 0009   c109e8a7 f80ca4d0 c109f617
 Call Trace:
  [] ? dump_stack+0x44/0x64
  [] ? __warn+0xfa/0x120
  [] ? module_put+0x57/0x70
  [] ? module_put+0x57/0x70
  [] ? warn_slowpath_null+0x23/0x30
  [] ? module_put+0x57/0x70
  [] ? gp8psk_fe_set_frontend+0x460/0x460 [dvb_usb_gp8psk]
  [] ? symbol_put_addr+0x27/0x50
  [] ? dvb_usb_adapter_frontend_exit+0x3a/0x70 [dvb_usb]

Signed-off-by: Mauro Carvalho Chehab