Re: [PATCH 2/4] Test for ioctl() function signature

2015-05-05 Thread Mauro Carvalho Chehab
Em Sun, 25 Jan 2015 21:36:25 +0100
Felix Janda felix.ja...@posteo.de escreveu:

 On glibc, ioctl has the signature ioctl(int, unsigned long int, ...).
 On musl, libc and according to POSIX it is ioctl(int, int, ...).
 Add a configure test adapted from gnulib's ioctl.m4 to make the
 DL_PRELOAD libraries work for both signatures.


This patch breaks compilation on Fedora:

v4l2convert.c:130:45: error: conflicting types for 'ioctl'
 LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
 ^
In file included from v4l2convert.c:37:0:
/usr/include/sys/ioctl.h:41:12: note: previous declaration of 'ioctl' was here
 extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
^

 
 Signed-off-by: Felix Janda felix.ja...@posteo.de
 ---
  configure.ac  | 12 
  lib/libv4l1/v4l1compat.c  |  4 
  lib/libv4l2/v4l2convert.c |  4 
  3 files changed, 20 insertions(+)
 
 diff --git a/configure.ac b/configure.ac
 index 4156559..00136d7 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -116,6 +116,18 @@ gl_VISIBILITY
  AC_CHECK_HEADERS([sys/klog.h])
  AC_CHECK_FUNCS([klogctl])
  
 +AC_CACHE_CHECK([for ioctl with POSIX signature],
 +  [gl_cv_func_ioctl_posix_signature],
 +  [AC_COMPILE_IFELSE(
 + [AC_LANG_PROGRAM(
 +[[#include sys/ioctl.h]],
 +[[int ioctl (int, int, ...);]])
 + ],
 + [gl_cv_func_ioctl_posix_signature=yes],
 + [gl_cv_func_ioctl_posix_signature=no])
 +  ])
 +AC_DEFINE([HAVE_POSIX_IOCTL], [1], [test x$gl_cv_func_ioctl_posix_signature 
 = xyes])
 +
  AC_CHECK_FUNCS([__secure_getenv secure_getenv])
  
  # Check host os
 diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
 index 07240c1..282173b 100644
 --- a/lib/libv4l1/v4l1compat.c
 +++ b/lib/libv4l1/v4l1compat.c
 @@ -93,7 +93,11 @@ LIBV4L_PUBLIC int dup(int fd)
   return v4l1_dup(fd);
  }
  
 +#ifdef HAVE_POSIX_IOCTL
 +LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
 +#else
  LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...)
 +#endif
  {
   void *arg;
   va_list ap;
 diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
 index b65da5e..c79f9da 100644
 --- a/lib/libv4l2/v4l2convert.c
 +++ b/lib/libv4l2/v4l2convert.c
 @@ -121,7 +121,11 @@ LIBV4L_PUBLIC int dup(int fd)
   return v4l2_dup(fd);
  }
  
 +#ifdef HAVE_POSIX_IOCTL
 +LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
 +#else
  LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...)
 +#endif
  {
   void *arg;
   va_list ap;
--
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 3/4] Wrap LFS64 functions only if __GLIBC__

2015-05-05 Thread Mauro Carvalho Chehab
Em Sun, 25 Jan 2015 21:36:36 +0100
Felix Janda felix.ja...@posteo.de escreveu:

 The functions open64 and mmap64 are glibc specific.
 
 Signed-off-by: Felix Janda felix.ja...@posteo.de
 ---
  lib/libv4l1/v4l1compat.c  | 4 ++--
  lib/libv4l2/v4l2convert.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
 
 diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
 index 282173b..c78adb4 100644
 --- a/lib/libv4l1/v4l1compat.c
 +++ b/lib/libv4l1/v4l1compat.c
 @@ -61,7 +61,7 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
   return fd;
  }
  
 -#ifdef linux
 +#ifdef __GLIBC__

Hmm... linux was added here to avoid breaking on FreeBSD, on this
changeset:

commit 9026d3cc277e9211a89345846dea95af7208383c
Author: hans@rhel5-devel.localdomain hans@rhel5-devel.localdomain
Date:   Tue Jun 2 15:34:34 2009 +0200

libv4l: initial support for compiling on FreeBSD

From: Hans Petter Selasky hsela...@freebsd.org

I'm afraid that removing the above would break for FreeBSD, as I think
it also uses glibc, but not 100% sure.

So, either we should get an ack from Hans Peter, or you should
change the tests to:

#if linux  __GLIBC__

Regards,
Mauro



  LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
  {
   int fd;
 @@ -120,7 +120,7 @@ LIBV4L_PUBLIC void *mmap(void *start, size_t length, int 
 prot, int flags, int fd
   return v4l1_mmap(start, length, prot, flags, fd, offset);
  }
  
 -#ifdef linux
 +#ifdef __GLIBC__
  LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
 int fd,
   off64_t offset)
  {
 diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
 index c79f9da..9345641 100644
 --- a/lib/libv4l2/v4l2convert.c
 +++ b/lib/libv4l2/v4l2convert.c
 @@ -86,7 +86,7 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
   return fd;
  }
  
 -#ifdef linux
 +#ifdef __GLIBC__
  LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
  {
   int fd;
 @@ -148,7 +148,7 @@ LIBV4L_PUBLIC void *mmap(void *start, size_t length, int 
 prot, int flags, int fd
   return v4l2_mmap(start, length, prot, flags, fd, offset);
  }
  
 -#ifdef linux
 +#ifdef __GLIBC__
  LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
 int fd,
   off64_t offset)
  {
--
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 v2] v4l2-dv-timings: fix overflow in gtf timings calculation

2015-05-05 Thread Prashant Laddha
Please find version v2 for the overflow fix in gtf timing calculation.
v2 incorporates comments from Hans on version 1 of this patch.

Regards,
Prashant

Prashant Laddha (1):
  v4l2-dv-timings: fix overflow in gtf timings calculation

 drivers/media/v4l2-core/v4l2-dv-timings.c | 30 --
 1 file changed, 20 insertions(+), 10 deletions(-)

Changes compared to v1:
1. Use div_u64() for 64 bit division
2. Use u64 instead 
-- 
1.9.1

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


[PATCH v2] v4l2-dv-timings: fix overflow in gtf timings calculation

2015-05-05 Thread Prashant Laddha
The intermediate calculation in the expression for hblank can exceed
32 bit signed range. This overflow can lead to negative values for
hblank. Typecasting intermediate variable to higher precision.

Cc: Hans Verkuil hans.verk...@cisco.com
Cc: Martin Bugge marbu...@cisco.com
Signed-off-by: Prashant Laddha prlad...@cisco.com
---
 drivers/media/v4l2-core/v4l2-dv-timings.c | 30 --
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 86e11d1..3e14dc4 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -25,6 +25,7 @@
 #include linux/videodev2.h
 #include linux/v4l2-dv-timings.h
 #include media/v4l2-dv-timings.h
+#include linux/math64.h
 
 MODULE_AUTHOR(Hans Verkuil);
 MODULE_DESCRIPTION(V4L2 DV Timings Helper Functions);
@@ -572,16 +573,25 @@ bool v4l2_detect_gtf(unsigned frame_height,
image_width = (image_width + GTF_CELL_GRAN/2)  ~(GTF_CELL_GRAN - 1);
 
/* Horizontal */
-   if (default_gtf)
-   h_blank = ((image_width * GTF_D_C_PRIME * hfreq) -
-   (image_width * GTF_D_M_PRIME * 1000) +
-   (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) 
/ 2) /
-   (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000);
-   else
-   h_blank = ((image_width * GTF_S_C_PRIME * hfreq) -
-   (image_width * GTF_S_M_PRIME * 1000) +
-   (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) 
/ 2) /
-   (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000);
+   if (default_gtf) {
+   u64 num;
+   u64 den;
+
+   num = ((image_width * GTF_D_C_PRIME * (u64)hfreq) -
+ ((u64)image_width * GTF_D_M_PRIME * 1000));
+   den = ((u64)hfreq * (100 - GTF_D_C_PRIME) +
+ GTF_D_M_PRIME * 1000);
+   h_blank = div_u64((num + (den  1)), den);
+   } else {
+   u64 num;
+   u64 den;
+
+   num = ((image_width * GTF_S_C_PRIME * (u64)hfreq) -
+ ((u64)image_width * GTF_S_M_PRIME * 1000));
+   den = ((u64)hfreq * (100 - GTF_S_C_PRIME) +
+ GTF_S_M_PRIME * 1000);
+   h_blank = div_u64((num + (den  1)), den);
+   }
 
h_blank = ((h_blank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN)) *
  (2 * GTF_CELL_GRAN);
-- 
1.9.1

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


Re: [PATCH 1/4] Use off_t and off64_t instead of __off_t and __off64_t

2015-05-05 Thread Mauro Carvalho Chehab
Em Sun, 25 Jan 2015 21:36:15 +0100
Felix Janda felix.ja...@posteo.de escreveu:

 Since _LARGEFILE64_SOURCE is 1, these types coincide if defined.

The __off_t macro was also added by the FreeBSD patchset. Removing this
will likely break for FreeBSD.

So, provided that this is not causing any issues, better to keep it
as-is.

Regards,
Mauro



 
 Signed-off-by: Felix Janda felix.ja...@posteo.de
 ---
  lib/libv4l1/v4l1compat.c   | 5 ++---
  lib/libv4l2/v4l2convert.c  | 4 ++--
  lib/libv4lconvert/libv4lsyscall-priv.h | 7 +++
  3 files changed, 7 insertions(+), 9 deletions(-)
 
 diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
 index e328288..07240c1 100644
 --- a/lib/libv4l1/v4l1compat.c
 +++ b/lib/libv4l1/v4l1compat.c
 @@ -26,7 +26,6 @@
  #include stdarg.h
  #include fcntl.h
  #include libv4l1.h
 -#include ../libv4lconvert/libv4lsyscall-priv.h /* for __off_t */
  
  #include sys/ioctl.h
  #include sys/mman.h
 @@ -112,14 +111,14 @@ LIBV4L_PUBLIC ssize_t read(int fd, void *buffer, size_t 
 n)
  }
  
  LIBV4L_PUBLIC void *mmap(void *start, size_t length, int prot, int flags, 
 int fd,
 - __off_t offset)
 + off_t offset)
  {
   return v4l1_mmap(start, length, prot, flags, fd, offset);
  }
  
  #ifdef linux
  LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
 int fd,
 - __off64_t offset)
 + off64_t offset)
  {
   return v4l1_mmap(start, length, prot, flags, fd, offset);
  }
 diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
 index 9b46ab8..b65da5e 100644
 --- a/lib/libv4l2/v4l2convert.c
 +++ b/lib/libv4l2/v4l2convert.c
 @@ -139,14 +139,14 @@ LIBV4L_PUBLIC ssize_t read(int fd, void *buffer, size_t 
 n)
  }
  
  LIBV4L_PUBLIC void *mmap(void *start, size_t length, int prot, int flags, 
 int fd,
 - __off_t offset)
 + off_t offset)
  {
   return v4l2_mmap(start, length, prot, flags, fd, offset);
  }
  
  #ifdef linux
  LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
 int fd,
 - __off64_t offset)
 + off64_t offset)
  {
   return v4l2_mmap(start, length, prot, flags, fd, offset);
  }
 diff --git a/lib/libv4lconvert/libv4lsyscall-priv.h 
 b/lib/libv4lconvert/libv4lsyscall-priv.h
 index cdd38bc..ce89073 100644
 --- a/lib/libv4lconvert/libv4lsyscall-priv.h
 +++ b/lib/libv4lconvert/libv4lsyscall-priv.h
 @@ -59,7 +59,6 @@
  #define  _IOC_SIZE(cmd) IOCPARM_LEN(cmd)
  #define  MAP_ANONYMOUS MAP_ANON
  #define  MMAP2_PAGE_SHIFT 0
 -typedef off_t __off_t;
  #endif
  
  #undef SYS_OPEN
 @@ -91,15 +90,15 @@ typedef off_t __off_t;
  #if defined(__FreeBSD__)
  #define SYS_MMAP(addr, len, prot, flags, fd, off) \
   __syscall(SYS_mmap, (void *)(addr), (size_t)(len), \
 - (int)(prot), (int)(flags), (int)(fd), (__off_t)(off))
 + (int)(prot), (int)(flags), (int)(fd), (off_t)(off))
  #elif defined(__FreeBSD_kernel__)
  #define SYS_MMAP(addr, len, prot, flags, fd, off) \
   syscall(SYS_mmap, (void *)(addr), (size_t)(len), \
 - (int)(prot), (int)(flags), (int)(fd), (__off_t)(off))
 + (int)(prot), (int)(flags), (int)(fd), (off_t)(off))
  #else
  #define SYS_MMAP(addr, len, prot, flags, fd, off) \
   syscall(SYS_mmap2, (void *)(addr), (size_t)(len), \
 - (int)(prot), (int)(flags), (int)(fd), (__off_t)((off) 
  MMAP2_PAGE_SHIFT))
 + (int)(prot), (int)(flags), (int)(fd), (off_t)((off)  
 MMAP2_PAGE_SHIFT))
  #endif
  
  #define SYS_MUNMAP(addr, len) \
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC] How implement Secure Data Path ?

2015-05-05 Thread Laurent Pinchart
On Tuesday 05 May 2015 09:27:52 Christoph Hellwig wrote:
 On Tue, May 05, 2015 at 05:39:57PM +0200, Benjamin Gaignard wrote:
  Since few months I'm looking for Linaro to how do Secure Data Path (SPD).
  I have tried and implemented multiple thinks but I always facing
  architecture issues so I would like to get your help to solve the
  problem.
  
  First what is Secure Data Path ? SDP is a set of hardware features to
  garanty that some memories regions could only be read and/or write by
  specific hardware IPs. You can imagine it as a kind of memory firewall
  which grant/revoke accesses to memory per devices. Firewall configuration
  must be done in a trusted environment: for ARM architecture we plan to
  use OP-TEE + a trusted application to do that.
  
  One typical use case for SDP in a video playback which involve those
  elements: decrypt - video decoder - transform - display
 
 Sounds like a good enough reason not to implement it ever.

The irony of it is to post an RFC on they day before 
http://www.defectivebydesign.org/dayagainstdrm/ :-)

-- 
Regards,

Laurent Pinchart

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


cron job: media_tree daily build: ERRORS

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

Results of the daily build of media_tree:

date:   Wed May  6 04:00:16 CEST 2015
git branch: test
git hash:   1555f3bf5cc172e7d23c2b8db10d656d15bec13e
gcc version:i686-linux-gcc (GCC) 5.1.0
sparse version: v0.5.0-44-g40791b9
smatch version: 0.4.1-3153-g7d56ab3
host hardware:  x86_64
host os:4.0.0-0.slh.3-amd64

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

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


Re: Time for a v4l-utils 1.8.0 release

2015-05-05 Thread Laurent Pinchart
Hi Mauro,

On Tuesday 05 May 2015 17:22:35 Mauro Carvalho Chehab wrote:
 Em Tue, 05 May 2015 21:08:49 +0200 Gregor Jasny escreveu:
  Hello,
  
  It's already more than half a year since the last v4l-utils release. Do
  you have any pending commits or objections? If no one vetos I'd like to
  release this weekend.
 
 There is are a additions I'd like to add to v4l-utils:
 
 1) on DVB, ioctls may fail with -EAGAIN. Some parts of the libdvbv5 don't
 handle it well. I made one quick hack for it, but didn't have time to
 add a timeout to avoid an endless loop. The patch is simple. I just need
 some time to do that;
 
 2) The Media Controller control util (media-ctl) doesn't support DVB.
 
 The patchset adding DVB support on media-ctl is ready, and I'm merging
 right now, and matches what's there at Kernel version 4.1-rc1 and upper.
 
 Yet, Laurent and Sakari want to do some changes at the Kernel API, before
 setting it into a stone at Kernel v 4.1 release.

I think Hans wants changes too.

 This has to happen on the next 4 weeks.

We'll try to, but depending on how review goes this might take more time.

In the meantime I suggest moving the media-ctl changes to a separate branch 
and go with the v1.8.0 release as planned.

 So, I suggest to postpone the release of 1.8.0 until the end of this month.

-- 
Regards,

Laurent Pinchart

--
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: Time for a v4l-utils 1.8.0 release

2015-05-05 Thread Hans Petter Selasky

On 05/06/15 04:07, Laurent Pinchart wrote:

Hi Mauro,

On Tuesday 05 May 2015 17:22:35 Mauro Carvalho Chehab wrote:

Em Tue, 05 May 2015 21:08:49 +0200 Gregor Jasny escreveu:

Hello,

It's already more than half a year since the last v4l-utils release. Do
you have any pending commits or objections? If no one vetos I'd like to
release this weekend.


There is are a additions I'd like to add to v4l-utils:

1) on DVB, ioctls may fail with -EAGAIN. Some parts of the libdvbv5 don't
handle it well. I made one quick hack for it, but didn't have time to
add a timeout to avoid an endless loop. The patch is simple. I just need
some time to do that;

2) The Media Controller control util (media-ctl) doesn't support DVB.

The patchset adding DVB support on media-ctl is ready, and I'm merging
right now, and matches what's there at Kernel version 4.1-rc1 and upper.

Yet, Laurent and Sakari want to do some changes at the Kernel API, before
setting it into a stone at Kernel v 4.1 release.


I think Hans wants changes too.


This has to happen on the next 4 weeks.


We'll try to, but depending on how review goes this might take more time.

In the meantime I suggest moving the media-ctl changes to a separate branch
and go with the v1.8.0 release as planned.


So, I suggest to postpone the release of 1.8.0 until the end of this month.




Hi,

Maybe someone would like to give the v4l-utils a spin on FreeBSD before 
release? Or is this the latest code in the .git ?


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


Re: [PATCH v3 1/1] V4L2: platform: Renesas R-Car JPEG codec driver

2015-05-05 Thread Mikhail Ulianov
On Mon, 04 May 2015 02:32:05 +0300
Laurent Pinchart laurent.pinch...@ideasonboard.com wrote:

 Hi Mikhail,
 
 Thank you for the patch. Please see below for a (partial) review.
 
 On Thursday 30 April 2015 00:53:29 Mikhail Ulyanov wrote:
  Here's the the driver for the Renesas R-Car JPEG processing unit
  driver.
  
  The driver is implemented within the V4L2 framework as a mem-to-mem
  device. It presents two video nodes to userspace, one for the
  encoding part, and one for the decoding part.
  
  It was found that the only working mode for encoding is no markers
  output, so we generate it with software. In current version of
  driver we also use software JPEG header parsing because with
  hardware parsing performance is lower then desired.
 
 Just out of curiosity, what is the performance impact of hardware
 parsing ?
Looks like feature of IP core. Header parsing complete/continue
sequence make it work 1.5-2 times longer, so as i remember maximum
performance with 1Mp YUV420 JPEG decoding was ~60 FPS. 
--
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] v4l: of: Correct pclk-sample for BT656 bus

2015-05-05 Thread Nikhil Devshatwar
Current v4l2_of_parse_parallel_bus function attempts to parse the
DT properties for the parallel bus as well as BT656 bus.
If the pclk-sample property is defined for the BT656 bus, it is still
marked as a parallel bus.
Fix this by parsing the pclk after the bus_type is selected.
Only when hsync or vsync properties are specified, the bus_type should
be set to V4L2_MBUS_PARALLEL.

Signed-off-by: Nikhil Devshatwar nikhil...@ti.com
---
 drivers/media/v4l2-core/v4l2-of.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-of.c 
b/drivers/media/v4l2-core/v4l2-of.c
index c52fb96..b27cbb1 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -93,10 +93,6 @@ static void v4l2_of_parse_parallel_bus(const struct 
device_node *node,
flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
V4L2_MBUS_VSYNC_ACTIVE_LOW;
 
-   if (!of_property_read_u32(node, pclk-sample, v))
-   flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
-   V4L2_MBUS_PCLK_SAMPLE_FALLING;
-
if (!of_property_read_u32(node, field-even-active, v))
flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
V4L2_MBUS_FIELD_EVEN_LOW;
@@ -105,6 +101,10 @@ static void v4l2_of_parse_parallel_bus(const struct 
device_node *node,
else
endpoint-bus_type = V4L2_MBUS_BT656;
 
+   if (!of_property_read_u32(node, pclk-sample, v))
+   flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
+   V4L2_MBUS_PCLK_SAMPLE_FALLING;
+
if (!of_property_read_u32(node, data-active, v))
flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
V4L2_MBUS_DATA_ACTIVE_LOW;
-- 
1.7.9.5

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


[PATCH 04/21] fc2580: remove obsolete media attach

2015-05-05 Thread Antti Palosaari
All users are using driver via I2C client binding so lets remove
unneeded media binding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c | 72 ---
 drivers/media/tuners/fc2580.h | 26 
 2 files changed, 98 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index d01fba8..48e4dae 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -466,17 +466,6 @@ static int fc2580_get_if_frequency(struct dvb_frontend 
*fe, u32 *frequency)
return 0;
 }
 
-static int fc2580_release(struct dvb_frontend *fe)
-{
-   struct fc2580_priv *priv = fe-tuner_priv;
-
-   dev_dbg(priv-i2c-dev, %s:\n, __func__);
-
-   kfree(fe-tuner_priv);
-
-   return 0;
-}
-
 static const struct dvb_tuner_ops fc2580_tuner_ops = {
.info = {
.name   = FCI FC2580,
@@ -484,8 +473,6 @@ static const struct dvb_tuner_ops fc2580_tuner_ops = {
.frequency_max  = 86200,
},
 
-   .release = fc2580_release,
-
.init = fc2580_init,
.sleep = fc2580_sleep,
.set_params = fc2580_set_params,
@@ -493,64 +480,6 @@ static const struct dvb_tuner_ops fc2580_tuner_ops = {
.get_if_frequency = fc2580_get_if_frequency,
 };
 
-struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct fc2580_config *cfg)
-{
-   struct fc2580_priv *priv;
-   int ret;
-   u8 chip_id;
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1);
-
-   priv = kzalloc(sizeof(struct fc2580_priv), GFP_KERNEL);
-   if (!priv) {
-   ret = -ENOMEM;
-   dev_err(i2c-dev, %s: kzalloc() failed\n, KBUILD_MODNAME);
-   goto err;
-   }
-
-   priv-clk = cfg-clock;
-   priv-i2c = i2c;
-   priv-i2c_addr = cfg-i2c_addr;
-
-   /* check if the tuner is there */
-   ret = fc2580_rd_reg(priv, 0x01, chip_id);
-   if (ret  0)
-   goto err;
-
-   dev_dbg(priv-i2c-dev, %s: chip_id=%02x\n, __func__, chip_id);
-
-   switch (chip_id) {
-   case 0x56:
-   case 0x5a:
-   break;
-   default:
-   goto err;
-   }
-
-   dev_info(priv-i2c-dev,
-   %s: FCI FC2580 successfully identified\n,
-   KBUILD_MODNAME);
-
-   fe-tuner_priv = priv;
-   memcpy(fe-ops.tuner_ops, fc2580_tuner_ops,
-   sizeof(struct dvb_tuner_ops));
-
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   return fe;
-err:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0);
-
-   dev_dbg(i2c-dev, %s: failed=%d\n, __func__, ret);
-   kfree(priv);
-   return NULL;
-}
-EXPORT_SYMBOL(fc2580_attach);
-
 static int fc2580_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
@@ -592,7 +521,6 @@ static int fc2580_probe(struct i2c_client *client,
fe-tuner_priv = dev;
memcpy(fe-ops.tuner_ops, fc2580_tuner_ops,
sizeof(struct dvb_tuner_ops));
-   fe-ops.tuner_ops.release = NULL;
i2c_set_clientdata(client, dev);
 
dev_info(client-dev, FCI FC2580 successfully identified\n);
diff --git a/drivers/media/tuners/fc2580.h b/drivers/media/tuners/fc2580.h
index 5679e44..61ee0e8 100644
--- a/drivers/media/tuners/fc2580.h
+++ b/drivers/media/tuners/fc2580.h
@@ -21,7 +21,6 @@
 #ifndef FC2580_H
 #define FC2580_H
 
-#include linux/kconfig.h
 #include dvb_frontend.h
 
 /*
@@ -39,29 +38,4 @@ struct fc2580_platform_data {
struct dvb_frontend *dvb_frontend;
 };
 
-struct fc2580_config {
-   /*
-* I2C address
-* 0x56, ...
-*/
-   u8 i2c_addr;
-
-   /*
-* clock
-*/
-   u32 clock;
-};
-
-#if IS_REACHABLE(CONFIG_MEDIA_TUNER_FC2580)
-extern struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct fc2580_config *cfg);
-#else
-static inline struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, const struct fc2580_config *cfg)
-{
-   pr_warn(%s: driver disabled by Kconfig\n, __func__);
-   return NULL;
-}
-#endif
-
 #endif
-- 
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 02/21] rtl28xxu: bind fc2580 using I2C binding

2015-05-05 Thread Antti Palosaari
Change fc2580 driver from media binding to I2C client binding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 895441f..d5b1808 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -1018,11 +1018,6 @@ err:
return ret;
 }
 
-static const struct fc2580_config rtl2832u_fc2580_config = {
-   .i2c_addr = 0x56,
-   .clock = 16384000,
-};
-
 static struct tua9001_config rtl2832u_tua9001_config = {
.i2c_addr = 0x60,
 };
@@ -1105,10 +1100,26 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
subdev = i2c_get_clientdata(client);
}
break;
-   case TUNER_RTL2832_FC2580:
-   fe = dvb_attach(fc2580_attach, adap-fe[0],
-   dev-demod_i2c_adapter,
-   rtl2832u_fc2580_config);
+   case TUNER_RTL2832_FC2580: {
+   struct fc2580_platform_data fc2580_pdata = {
+   .dvb_frontend = adap-fe[0],
+   };
+   struct i2c_board_info board_info = {};
+
+   strlcpy(board_info.type, fc2580, I2C_NAME_SIZE);
+   board_info.addr = 0x56;
+   board_info.platform_data = fc2580_pdata;
+   request_module(fc2580);
+   client = i2c_new_device(dev-demod_i2c_adapter,
+   board_info);
+   if (client == NULL || client-dev.driver == NULL)
+   break;
+   if (!try_module_get(client-dev.driver-owner)) {
+   i2c_unregister_device(client);
+   break;
+   }
+   dev-i2c_client_tuner = client;
+   }
break;
case TUNER_RTL2832_TUA9001:
/* enable GPIO1 and GPIO4 as output */
-- 
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 21/21] rtl28xxu: load SDR module for fc2580 based devices

2015-05-05 Thread Antti Palosaari
Load rtl2832_sdr driver for devices having fc2580 tuner.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 41f8808..d8866af 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -1119,6 +1119,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
break;
}
dev-i2c_client_tuner = client;
+   subdev = fc2580_pdata.get_v4l2_subdev(client);
}
break;
case TUNER_RTL2832_TUA9001: {
@@ -1184,6 +1185,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
 
/* register SDR */
switch (dev-tuner) {
+   case TUNER_RTL2832_FC2580:
case TUNER_RTL2832_FC0012:
case TUNER_RTL2832_FC0013:
case TUNER_RTL2832_E4000:
-- 
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 08/21] af9035: fix device order in ID list

2015-05-05 Thread Antti Palosaari
Driver supports multiple chipset versions. Devices are ordered to
ID table per used chipset type. ITE 9303 Generic device uses IT9303
chipset and was added mistakenly between IT9135 IDs.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 558166d..ae72357 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -2026,6 +2026,7 @@ static const struct usb_device_id af9035_id_table[] = {
af9035_props, Asus U3100Mini Plus, NULL) },
{ DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
af9035_props, TerraTec Cinergy T Stick (rev. 2), NULL) },
+
/* IT9135 devices */
{ DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135,
af9035_props, ITE 9135 Generic, RC_MAP_IT913X_V1) },
@@ -2051,9 +2052,6 @@ static const struct usb_device_id af9035_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2,
af9035_props, Digital Dual TV Receiver CTVDIGDUAL_V2,
RC_MAP_IT913X_V1) },
-   /* IT930x devices */
-   { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303,
-   it930x_props, ITE 9303 Generic, NULL) },
/* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
{ DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099,
af9035_props, TerraTec Cinergy T Stick Dual RC (rev. 2),
@@ -2066,6 +2064,10 @@ static const struct usb_device_id af9035_id_table[] = {
af9035_props, PCTV AndroiDTV (78e), RC_MAP_IT913X_V1) },
{ DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_79E,
af9035_props, PCTV microStick (79e), RC_MAP_IT913X_V2) },
+
+   /* IT930x devices */
+   { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303,
+   it930x_props, ITE 9303 Generic, NULL) },
{ }
 };
 MODULE_DEVICE_TABLE(usb, af9035_id_table);
-- 
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 18/21] fc2580: calculate filter control word dynamically

2015-05-05 Thread Antti Palosaari
Calculate low-pass filter control word dynamically from given radio
channel bandwidth.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c  | 8 
 drivers/media/tuners/fc2580_priv.h | 9 -
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index 08838b4..30cee76 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -46,7 +46,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
int ret, i;
unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
u64 f_vco;
-   u8 u8tmp, synth_config;
+   u8 synth_config;
unsigned long timeout;
 
dev_dbg(client-dev,
@@ -249,9 +249,9 @@ static int fc2580_set_params(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   u8tmp = div_u64((u64) dev-clk * fc2580_if_filter_lut[i].mul,
-   10);
-   ret = regmap_write(dev-regmap, 0x37, u8tmp);
+   uitmp = (unsigned int) 8058000 - (c-bandwidth_hz * 122 / 100 / 2);
+   uitmp = div64_u64((u64) dev-clk * uitmp, 1ULL);
+   ret = regmap_write(dev-regmap, 0x37, uitmp);
if (ret)
goto err;
 
diff --git a/drivers/media/tuners/fc2580_priv.h 
b/drivers/media/tuners/fc2580_priv.h
index 60f8f6c..bd88b01 100644
--- a/drivers/media/tuners/fc2580_priv.h
+++ b/drivers/media/tuners/fc2580_priv.h
@@ -64,16 +64,15 @@ static const struct fc2580_pll fc2580_pll_lut[] = {
 
 struct fc2580_if_filter {
u32 freq;
-   u16 mul;
u8 r36_val;
u8 r39_val;
 };
 
 static const struct fc2580_if_filter fc2580_if_filter_lut[] = {
-   {   600, 4400, 0x18, 0x00},
-   {   700, 3910, 0x18, 0x80},
-   {   800, 3300, 0x18, 0x80},
-   {0x, 3300, 0x18, 0x80},
+   {   600, 0x18, 0x00},
+   {   700, 0x18, 0x80},
+   {   800, 0x18, 0x80},
+   {0x, 0x18, 0x80},
 };
 
 struct fc2580_freq_regs {
-- 
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 06/21] fc2580: cleanups and variable renames

2015-05-05 Thread Antti Palosaari
Rename driver state from priv to dev.
Remove legacy i2c-gate control.
Use I2C client for proper dev_() logging.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c  | 172 -
 drivers/media/tuners/fc2580_priv.h |   2 +-
 2 files changed, 76 insertions(+), 98 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index 9324855..f4b31db5 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -36,13 +36,14 @@
  */
 
 /* write multiple registers */
-static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+static int fc2580_wr_regs(struct fc2580_dev *dev, u8 reg, u8 *val, int len)
 {
+   struct i2c_client *client = dev-client;
int ret;
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
-   .addr = priv-i2c_addr,
+   .addr = dev-i2c_addr,
.flags = 0,
.len = 1 + len,
.buf = buf,
@@ -50,7 +51,7 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, 
u8 *val, int len)
};
 
if (1 + len  sizeof(buf)) {
-   dev_warn(priv-i2c-dev,
+   dev_warn(client-dev,
 %s: i2c wr reg=%04x: len=%d is too big!\n,
 KBUILD_MODNAME, reg, len);
return -EINVAL;
@@ -59,30 +60,31 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, 
u8 *val, int len)
buf[0] = reg;
memcpy(buf[1], val, len);
 
-   ret = i2c_transfer(priv-i2c, msg, 1);
+   ret = i2c_transfer(dev-i2c, msg, 1);
if (ret == 1) {
ret = 0;
} else {
-   dev_warn(priv-i2c-dev, %s: i2c wr failed=%d reg=%02x  \
-   len=%d\n, KBUILD_MODNAME, ret, reg, len);
+   dev_warn(dev-i2c-dev, %s: i2c wr failed=%d reg=%02x 
len=%d\n,
+KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
}
return ret;
 }
 
 /* read multiple registers */
-static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
+static int fc2580_rd_regs(struct fc2580_dev *dev, u8 reg, u8 *val, int len)
 {
+   struct i2c_client *client = dev-client;
int ret;
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[2] = {
{
-   .addr = priv-i2c_addr,
+   .addr = dev-i2c_addr,
.flags = 0,
.len = 1,
.buf = reg,
}, {
-   .addr = priv-i2c_addr,
+   .addr = dev-i2c_addr,
.flags = I2C_M_RD,
.len = len,
.buf = buf,
@@ -90,19 +92,19 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, 
u8 *val, int len)
};
 
if (len  sizeof(buf)) {
-   dev_warn(priv-i2c-dev,
+   dev_warn(client-dev,
 %s: i2c rd reg=%04x: len=%d is too big!\n,
 KBUILD_MODNAME, reg, len);
return -EINVAL;
}
 
-   ret = i2c_transfer(priv-i2c, msg, 2);
+   ret = i2c_transfer(dev-i2c, msg, 2);
if (ret == 2) {
memcpy(val, buf, len);
ret = 0;
} else {
-   dev_warn(priv-i2c-dev, %s: i2c rd failed=%d reg=%02x  \
-   len=%d\n, KBUILD_MODNAME, ret, reg, len);
+   dev_warn(client-dev, %s: i2c rd failed=%d reg=%02x len=%d\n,
+KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO;
}
 
@@ -110,33 +112,33 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 
reg, u8 *val, int len)
 }
 
 /* write single register */
-static int fc2580_wr_reg(struct fc2580_priv *priv, u8 reg, u8 val)
+static int fc2580_wr_reg(struct fc2580_dev *dev, u8 reg, u8 val)
 {
-   return fc2580_wr_regs(priv, reg, val, 1);
+   return fc2580_wr_regs(dev, reg, val, 1);
 }
 
 /* read single register */
-static int fc2580_rd_reg(struct fc2580_priv *priv, u8 reg, u8 *val)
+static int fc2580_rd_reg(struct fc2580_dev *dev, u8 reg, u8 *val)
 {
-   return fc2580_rd_regs(priv, reg, val, 1);
+   return fc2580_rd_regs(dev, reg, val, 1);
 }
 
 /* write single register conditionally only when value differs from 0xff
  * XXX: This is special routine meant only for writing fc2580_freq_regs_lut[]
  * values. Do not use for the other purposes. */
-static int fc2580_wr_reg_ff(struct fc2580_priv *priv, u8 reg, u8 val)
+static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, u8 val)
 {
if (val == 0xff)
return 0;
else
-   return fc2580_wr_regs(priv, reg, val, 1);
+   return fc2580_wr_regs(dev, reg, val, 1);
 }
 
 
 static int 

[PATCH 07/21] fc2580: use regmap for register I2C access

2015-05-05 Thread Antti Palosaari
Replace home made register access routines with regmap.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/Kconfig   |   1 +
 drivers/media/tuners/fc2580.c  | 216 +++--
 drivers/media/tuners/fc2580_priv.h |   4 +-
 3 files changed, 66 insertions(+), 155 deletions(-)

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 983510d..e826453 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -220,6 +220,7 @@ config MEDIA_TUNER_E4000
 config MEDIA_TUNER_FC2580
tristate FCI FC2580 silicon tuner
depends on MEDIA_SUPPORT  I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  FCI FC2580 silicon tuner driver.
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index f4b31db5..08838b4 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -20,109 +20,13 @@
 
 #include fc2580_priv.h
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  64
-
 /*
  * TODO:
  * I2C write and read works only for one single register. Multiple registers
  * could not be accessed using normal register address auto-increment.
  * There could be (very likely) register to change that behavior
- *
- * Due to that limitation functions:
- *   fc2580_wr_regs()
- *   fc2580_rd_regs()
- * could not be used for accessing more than one register at once.
  */
 
-/* write multiple registers */
-static int fc2580_wr_regs(struct fc2580_dev *dev, u8 reg, u8 *val, int len)
-{
-   struct i2c_client *client = dev-client;
-   int ret;
-   u8 buf[MAX_XFER_SIZE];
-   struct i2c_msg msg[1] = {
-   {
-   .addr = dev-i2c_addr,
-   .flags = 0,
-   .len = 1 + len,
-   .buf = buf,
-   }
-   };
-
-   if (1 + len  sizeof(buf)) {
-   dev_warn(client-dev,
-%s: i2c wr reg=%04x: len=%d is too big!\n,
-KBUILD_MODNAME, reg, len);
-   return -EINVAL;
-   }
-
-   buf[0] = reg;
-   memcpy(buf[1], val, len);
-
-   ret = i2c_transfer(dev-i2c, msg, 1);
-   if (ret == 1) {
-   ret = 0;
-   } else {
-   dev_warn(dev-i2c-dev, %s: i2c wr failed=%d reg=%02x 
len=%d\n,
-KBUILD_MODNAME, ret, reg, len);
-   ret = -EREMOTEIO;
-   }
-   return ret;
-}
-
-/* read multiple registers */
-static int fc2580_rd_regs(struct fc2580_dev *dev, u8 reg, u8 *val, int len)
-{
-   struct i2c_client *client = dev-client;
-   int ret;
-   u8 buf[MAX_XFER_SIZE];
-   struct i2c_msg msg[2] = {
-   {
-   .addr = dev-i2c_addr,
-   .flags = 0,
-   .len = 1,
-   .buf = reg,
-   }, {
-   .addr = dev-i2c_addr,
-   .flags = I2C_M_RD,
-   .len = len,
-   .buf = buf,
-   }
-   };
-
-   if (len  sizeof(buf)) {
-   dev_warn(client-dev,
-%s: i2c rd reg=%04x: len=%d is too big!\n,
-KBUILD_MODNAME, reg, len);
-   return -EINVAL;
-   }
-
-   ret = i2c_transfer(dev-i2c, msg, 2);
-   if (ret == 2) {
-   memcpy(val, buf, len);
-   ret = 0;
-   } else {
-   dev_warn(client-dev, %s: i2c rd failed=%d reg=%02x len=%d\n,
-KBUILD_MODNAME, ret, reg, len);
-   ret = -EREMOTEIO;
-   }
-
-   return ret;
-}
-
-/* write single register */
-static int fc2580_wr_reg(struct fc2580_dev *dev, u8 reg, u8 val)
-{
-   return fc2580_wr_regs(dev, reg, val, 1);
-}
-
-/* read single register */
-static int fc2580_rd_reg(struct fc2580_dev *dev, u8 reg, u8 *val)
-{
-   return fc2580_rd_regs(dev, reg, val, 1);
-}
-
 /* write single register conditionally only when value differs from 0xff
  * XXX: This is special routine meant only for writing fc2580_freq_regs_lut[]
  * values. Do not use for the other purposes. */
@@ -131,10 +35,9 @@ static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, 
u8 val)
if (val == 0xff)
return 0;
else
-   return fc2580_wr_regs(dev, reg, val, 1);
+   return regmap_write(dev-regmap, reg, val);
 }
 
-
 static int fc2580_set_params(struct dvb_frontend *fe)
 {
struct fc2580_dev *dev = fe-tuner_priv;
@@ -206,24 +109,24 @@ static int fc2580_set_params(struct dvb_frontend *fe)
frequency=%u f_vco=%llu F_REF=%u div_ref=%u div_n=%u k=%u 
div_out=%u k_cw=%0x\n,
c-frequency, f_vco, F_REF, div_ref, div_n, k, div_out, k_cw);
 
-   ret = fc2580_wr_reg(dev, 0x02, synth_config);
-   if (ret  0)
+   ret = 

[PATCH 05/21] fc2580: improve set params logic

2015-05-05 Thread Antti Palosaari
Calculate PLL dividers slightly differently, most likely it is now
correct. Move some register values to innitab. Use jiffies to poll
filter lock. Fix logging.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c  | 179 +
 drivers/media/tuners/fc2580_priv.h |   8 +-
 2 files changed, 88 insertions(+), 99 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index 48e4dae..9324855 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -33,11 +33,6 @@
  *   fc2580_wr_regs()
  *   fc2580_rd_regs()
  * could not be used for accessing more than one register at once.
- *
- * TODO:
- * Currently it blind writes bunch of static registers from the
- * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
- * logic to reduce unneeded register writes.
  */
 
 /* write multiple registers */
@@ -137,107 +132,110 @@ static int fc2580_wr_reg_ff(struct fc2580_priv *priv, 
u8 reg, u8 val)
return fc2580_wr_regs(priv, reg, val, 1);
 }
 
+
 static int fc2580_set_params(struct dvb_frontend *fe)
 {
struct fc2580_priv *priv = fe-tuner_priv;
+   struct i2c_client *client = priv-client;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
-   int ret = 0, i;
-   unsigned int r_val, n_val, k_val, k_val_reg, f_ref;
-   u8 tmp_val, r18_val;
+   int ret, i;
+   unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
u64 f_vco;
+   u8 u8tmp, synth_config;
+   unsigned long timeout;
 
-   /*
-* Fractional-N synthesizer/PLL.
-* Most likely all those PLL calculations are not correct. I am not
-* sure, but it looks like it is divider based Fractional-N synthesizer.
-* There is divider for reference clock too?
-* Anyhow, synthesizer calculation results seems to be quite correct.
-*/
-
-   dev_dbg(priv-i2c-dev, %s: delivery_system=%d frequency=%d  \
-   bandwidth_hz=%d\n, __func__,
-   c-delivery_system, c-frequency, c-bandwidth_hz);
+   dev_dbg(client-dev,
+   delivery_system=%u frequency=%u bandwidth_hz=%u\n,
+   c-delivery_system, c-frequency, c-bandwidth_hz);
 
if (fe-ops.i2c_gate_ctrl)
fe-ops.i2c_gate_ctrl(fe, 1);
 
-   /* PLL */
+   /*
+* Fractional-N synthesizer
+*
+*  +---+
+*  v   |
+*  Fref   ++ ++ +---+ ++ +--+  
   +---+
+* -- | /R | -- | PD | -- |  VCO  | -- | /2 | -- | /N.F | 
-- | K |
+* ++ ++ +---+ ++ +--+  
   +---+
+* |
+* |
+* v
+*   +---+  Fout
+*   | /Rout | --
+*   +---+
+*/
for (i = 0; i  ARRAY_SIZE(fc2580_pll_lut); i++) {
if (c-frequency = fc2580_pll_lut[i].freq)
break;
}
-
-   if (i == ARRAY_SIZE(fc2580_pll_lut))
+   if (i == ARRAY_SIZE(fc2580_pll_lut)) {
+   ret = -EINVAL;
goto err;
+   }
 
-   f_vco = c-frequency;
-   f_vco *= fc2580_pll_lut[i].div;
-
-   if (f_vco = 26UL)
-   tmp_val = 0x0e | fc2580_pll_lut[i].band;
+   #define DIV_PRE_N 2
+   #define F_REF priv-clk
+   div_out = fc2580_pll_lut[i].div_out;
+   f_vco = (u64) c-frequency * div_out;
+   synth_config = fc2580_pll_lut[i].band;
+   if (f_vco  26ULL)
+   synth_config |= 0x06;
else
-   tmp_val = 0x06 | fc2580_pll_lut[i].band;
-
-   ret = fc2580_wr_reg(priv, 0x02, tmp_val);
-   if (ret  0)
-   goto err;
-
-   if (f_vco = 2UL * 76 * priv-clk) {
-   r_val = 1;
-   r18_val = 0x00;
-   } else if (f_vco = 1UL * 76 * priv-clk) {
-   r_val = 2;
-   r18_val = 0x10;
+   synth_config |= 0x0e;
+
+   /* select reference divider R (keep PLL div N in valid range) */
+   #define DIV_N_MIN 76
+   if (f_vco = div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 1)) {
+   div_ref = 1;
+   div_ref_val = 0x00;
+   } else if (f_vco = div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 2)) {
+   div_ref = 2;
+   div_ref_val = 0x10;
} else {
-   r_val = 4;
-   r18_val = 0x20;
+   div_ref = 4;
+   div_ref_val = 0x20;
}
 
-   f_ref = 2UL * priv-clk / r_val;
-   n_val = div_u64_rem(f_vco, f_ref, k_val);
- 

[PATCH 01/21] fc2580: implement I2C client bindings

2015-05-05 Thread Antti Palosaari
Add I2C client bindings to driver.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c  | 101 +
 drivers/media/tuners/fc2580.h  |  15 ++
 drivers/media/tuners/fc2580_priv.h |   4 +-
 3 files changed, 110 insertions(+), 10 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index f0c9c42..d01fba8 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -47,7 +47,7 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, 
u8 *val, int len)
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-i2c_addr,
.flags = 0,
.len = 1 + len,
.buf = buf,
@@ -82,12 +82,12 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, 
u8 *val, int len)
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[2] = {
{
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-i2c_addr,
.flags = 0,
.len = 1,
.buf = reg,
}, {
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-i2c_addr,
.flags = I2C_M_RD,
.len = len,
.buf = buf,
@@ -182,10 +182,10 @@ static int fc2580_set_params(struct dvb_frontend *fe)
if (ret  0)
goto err;
 
-   if (f_vco = 2UL * 76 * priv-cfg-clock) {
+   if (f_vco = 2UL * 76 * priv-clk) {
r_val = 1;
r18_val = 0x00;
-   } else if (f_vco = 1UL * 76 * priv-cfg-clock) {
+   } else if (f_vco = 1UL * 76 * priv-clk) {
r_val = 2;
r18_val = 0x10;
} else {
@@ -193,7 +193,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
r18_val = 0x20;
}
 
-   f_ref = 2UL * priv-cfg-clock / r_val;
+   f_ref = 2UL * priv-clk / r_val;
n_val = div_u64_rem(f_vco, f_ref, k_val);
k_val_reg = div_u64(1ULL * k_val * (1  20), f_ref);
 
@@ -213,7 +213,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
if (ret  0)
goto err;
 
-   if (priv-cfg-clock = 2800) {
+   if (priv-clk = 2800) {
ret = fc2580_wr_reg(priv, 0x4b, 0x22);
if (ret  0)
goto err;
@@ -348,7 +348,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
if (ret  0)
goto err;
 
-   ret = fc2580_wr_reg(priv, 0x37, div_u64(1ULL * priv-cfg-clock *
+   ret = fc2580_wr_reg(priv, 0x37, div_u64(1ULL * priv-clk *
fc2580_if_filter_lut[i].mul, 10));
if (ret  0)
goto err;
@@ -510,8 +510,9 @@ struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
goto err;
}
 
-   priv-cfg = cfg;
+   priv-clk = cfg-clock;
priv-i2c = i2c;
+   priv-i2c_addr = cfg-i2c_addr;
 
/* check if the tuner is there */
ret = fc2580_rd_reg(priv, 0x01, chip_id);
@@ -550,6 +551,88 @@ err:
 }
 EXPORT_SYMBOL(fc2580_attach);
 
+static int fc2580_probe(struct i2c_client *client,
+   const struct i2c_device_id *id)
+{
+   struct fc2580_priv *dev;
+   struct fc2580_platform_data *pdata = client-dev.platform_data;
+   struct dvb_frontend *fe = pdata-dvb_frontend;
+   int ret;
+   u8 chip_id;
+
+   dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+   if (!dev) {
+   ret = -ENOMEM;
+   goto err;
+   }
+
+   if (pdata-clk)
+   dev-clk = pdata-clk;
+   else
+   dev-clk = 16384000; /* internal clock */
+   dev-client = client;
+   dev-i2c = client-adapter;
+   dev-i2c_addr = client-addr;
+
+   /* check if the tuner is there */
+   ret = fc2580_rd_reg(dev, 0x01, chip_id);
+   if (ret  0)
+   goto err_kfree;
+
+   dev_dbg(client-dev, chip_id=%02x\n, chip_id);
+
+   switch (chip_id) {
+   case 0x56:
+   case 0x5a:
+   break;
+   default:
+   goto err_kfree;
+   }
+
+   fe-tuner_priv = dev;
+   memcpy(fe-ops.tuner_ops, fc2580_tuner_ops,
+   sizeof(struct dvb_tuner_ops));
+   fe-ops.tuner_ops.release = NULL;
+   i2c_set_clientdata(client, dev);
+
+   dev_info(client-dev, FCI FC2580 successfully identified\n);
+   return 0;
+err_kfree:
+   kfree(dev);
+err:
+   dev_dbg(client-dev, failed=%d\n, ret);
+   return ret;
+}
+
+static int fc2580_remove(struct i2c_client *client)
+{
+   struct fc2580_priv *dev = i2c_get_clientdata(client);
+
+   dev_dbg(client-dev, \n);
+
+   kfree(dev);
+   return 0;
+}
+
+static 

[PATCH 19/21] fc2580: implement V4L2 subdevice for SDR control

2015-05-05 Thread Antti Palosaari
Implement V4L2 subdevice for bandwidth and frequency controls of
SDR usage. That driver now implements both DVB frontend and V4L2
subdevice. Driver itself is I2C driver. Lets see how it works.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/fc2580.c  | 262 +
 drivers/media/tuners/fc2580.h  |   5 +
 drivers/media/tuners/fc2580_priv.h |  11 ++
 3 files changed, 249 insertions(+), 29 deletions(-)

diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index 30cee76..db21902 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -38,20 +38,19 @@ static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, 
u8 val)
return regmap_write(dev-regmap, reg, val);
 }
 
-static int fc2580_set_params(struct dvb_frontend *fe)
+static int fc2580_set_params(struct fc2580_dev *dev)
 {
-   struct fc2580_dev *dev = fe-tuner_priv;
struct i2c_client *client = dev-client;
-   struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret, i;
unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
u64 f_vco;
u8 synth_config;
unsigned long timeout;
 
-   dev_dbg(client-dev,
-   delivery_system=%u frequency=%u bandwidth_hz=%u\n,
-   c-delivery_system, c-frequency, c-bandwidth_hz);
+   if (!dev-active) {
+   dev_dbg(client-dev, tuner is sleeping\n);
+   return 0;
+   }
 
/*
 * Fractional-N synthesizer
@@ -69,7 +68,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
 *   +---+
 */
for (i = 0; i  ARRAY_SIZE(fc2580_pll_lut); i++) {
-   if (c-frequency = fc2580_pll_lut[i].freq)
+   if (dev-f_frequency = fc2580_pll_lut[i].freq)
break;
}
if (i == ARRAY_SIZE(fc2580_pll_lut)) {
@@ -80,7 +79,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
#define DIV_PRE_N 2
#define F_REF dev-clk
div_out = fc2580_pll_lut[i].div_out;
-   f_vco = (u64) c-frequency * div_out;
+   f_vco = (u64) dev-f_frequency * div_out;
synth_config = fc2580_pll_lut[i].band;
if (f_vco  26ULL)
synth_config |= 0x06;
@@ -106,8 +105,9 @@ static int fc2580_set_params(struct dvb_frontend *fe)
k_cw = div_u64((u64) k * 0x10, uitmp);
 
dev_dbg(client-dev,
-   frequency=%u f_vco=%llu F_REF=%u div_ref=%u div_n=%u k=%u 
div_out=%u k_cw=%0x\n,
-   c-frequency, f_vco, F_REF, div_ref, div_n, k, div_out, k_cw);
+   frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_ref=%u 
div_n=%u k=%u div_out=%u k_cw=%0x\n,
+   dev-f_frequency, dev-f_bandwidth, f_vco, F_REF, div_ref,
+   div_n, k, div_out, k_cw);
 
ret = regmap_write(dev-regmap, 0x02, synth_config);
if (ret)
@@ -131,7 +131,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
 
/* registers */
for (i = 0; i  ARRAY_SIZE(fc2580_freq_regs_lut); i++) {
-   if (c-frequency = fc2580_freq_regs_lut[i].freq)
+   if (dev-f_frequency = fc2580_freq_regs_lut[i].freq)
break;
}
if (i == ARRAY_SIZE(fc2580_freq_regs_lut)) {
@@ -237,7 +237,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
 
/* IF filters */
for (i = 0; i  ARRAY_SIZE(fc2580_if_filter_lut); i++) {
-   if (c-bandwidth_hz = fc2580_if_filter_lut[i].freq)
+   if (dev-f_bandwidth = fc2580_if_filter_lut[i].freq)
break;
}
if (i == ARRAY_SIZE(fc2580_if_filter_lut)) {
@@ -249,7 +249,7 @@ static int fc2580_set_params(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   uitmp = (unsigned int) 8058000 - (c-bandwidth_hz * 122 / 100 / 2);
+   uitmp = (unsigned int) 8058000 - (dev-f_bandwidth * 122 / 100 / 2);
uitmp = div64_u64((u64) dev-clk * uitmp, 1ULL);
ret = regmap_write(dev-regmap, 0x37, uitmp);
if (ret)
@@ -285,9 +285,8 @@ err:
return ret;
 }
 
-static int fc2580_init(struct dvb_frontend *fe)
+static int fc2580_init(struct fc2580_dev *dev)
 {
-   struct fc2580_dev *dev = fe-tuner_priv;
struct i2c_client *client = dev-client;
int ret, i;
 
@@ -300,56 +299,236 @@ static int fc2580_init(struct dvb_frontend *fe)
goto err;
}
 
+   dev-active = true;
return 0;
 err:
dev_dbg(client-dev, failed=%d\n, ret);
return ret;
 }
 
-static int fc2580_sleep(struct dvb_frontend *fe)
+static int fc2580_sleep(struct fc2580_dev *dev)
 {
-   struct fc2580_dev *dev = fe-tuner_priv;
struct i2c_client *client = dev-client;
int ret;
 
dev_dbg(client-dev, \n);
 
+   dev-active = false;
+
ret = 

[PATCH 09/21] tua9001: add I2C bindings

2015-05-05 Thread Antti Palosaari
Add I2C bindings.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/tua9001.c  | 100 +++-
 drivers/media/tuners/tua9001.h  |  13 +
 drivers/media/tuners/tua9001_priv.h |   4 +-
 3 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index 83a6240..55cac20 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -28,7 +28,7 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, 
u16 val)
u8 buf[3] = { reg, (val  8)  0xff, (val  0)  0xff };
struct i2c_msg msg[1] = {
{
-   .addr = priv-cfg-i2c_addr,
+   .addr = priv-i2c_addr,
.flags = 0,
.len = sizeof(buf),
.buf = buf,
@@ -253,7 +253,7 @@ struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
if (priv == NULL)
return NULL;
 
-   priv-cfg = cfg;
+   priv-i2c_addr = cfg-i2c_addr;
priv-i2c = i2c;
 
if (fe-callback) {
@@ -289,6 +289,102 @@ err:
 }
 EXPORT_SYMBOL(tua9001_attach);
 
+static int tua9001_probe(struct i2c_client *client,
+   const struct i2c_device_id *id)
+{
+   struct tua9001_priv *dev;
+   struct tua9001_platform_data *pdata = client-dev.platform_data;
+   struct dvb_frontend *fe = pdata-dvb_frontend;
+   int ret;
+
+   dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+   if (!dev) {
+   ret = -ENOMEM;
+   goto err;
+   }
+
+   dev-client = client;
+   dev-i2c_addr = client-addr;
+   dev-i2c = client-adapter;
+   dev-fe = pdata-dvb_frontend;
+
+   if (fe-callback) {
+   ret = fe-callback(client-adapter,
+  DVB_FRONTEND_COMPONENT_TUNER,
+  TUA9001_CMD_CEN, 1);
+   if (ret)
+   goto err_kfree;
+
+   ret = fe-callback(client-adapter,
+  DVB_FRONTEND_COMPONENT_TUNER,
+  TUA9001_CMD_RXEN, 0);
+   if (ret)
+   goto err_kfree;
+
+   ret = fe-callback(client-adapter,
+  DVB_FRONTEND_COMPONENT_TUNER,
+  TUA9001_CMD_RESETN, 1);
+   if (ret)
+   goto err_kfree;
+   }
+
+   fe-tuner_priv = dev;
+   memcpy(fe-ops.tuner_ops, tua9001_tuner_ops,
+   sizeof(struct dvb_tuner_ops));
+   fe-ops.tuner_ops.release = NULL;
+   i2c_set_clientdata(client, dev);
+
+   dev_info(client-dev, Infineon TUA 9001 successfully attached\n);
+   return 0;
+err_kfree:
+   kfree(dev);
+err:
+   dev_dbg(client-dev, failed=%d\n, ret);
+   return ret;
+}
+
+static int tua9001_remove(struct i2c_client *client)
+{
+   struct tua9001_priv *dev = i2c_get_clientdata(client);
+   struct dvb_frontend *fe = dev-fe;
+   int ret;
+
+   dev_dbg(client-dev, \n);
+
+   if (fe-callback) {
+   ret = fe-callback(client-adapter,
+  DVB_FRONTEND_COMPONENT_TUNER,
+  TUA9001_CMD_CEN, 0);
+   if (ret)
+   goto err_kfree;
+   }
+   kfree(dev);
+   return 0;
+err_kfree:
+   kfree(dev);
+   dev_dbg(client-dev, failed=%d\n, ret);
+   return ret;
+}
+
+static const struct i2c_device_id tua9001_id_table[] = {
+   {tua9001, 0},
+   {}
+};
+MODULE_DEVICE_TABLE(i2c, tua9001_id_table);
+
+static struct i2c_driver tua9001_driver = {
+   .driver = {
+   .owner  = THIS_MODULE,
+   .name   = tua9001,
+   .suppress_bind_attrs = true,
+   },
+   .probe  = tua9001_probe,
+   .remove = tua9001_remove,
+   .id_table   = tua9001_id_table,
+};
+
+module_i2c_driver(tua9001_driver);
+
 MODULE_DESCRIPTION(Infineon TUA 9001 silicon tuner driver);
 MODULE_AUTHOR(Antti Palosaari cr...@iki.fi);
 MODULE_LICENSE(GPL);
diff --git a/drivers/media/tuners/tua9001.h b/drivers/media/tuners/tua9001.h
index 2c3375c..0b4fc8d 100644
--- a/drivers/media/tuners/tua9001.h
+++ b/drivers/media/tuners/tua9001.h
@@ -24,6 +24,19 @@
 #include linux/kconfig.h
 #include dvb_frontend.h
 
+/*
+ * I2C address
+ * 0x60,
+ */
+
+/**
+ * struct tua9001_platform_data - Platform data for the tua9001 driver
+ * @dvb_frontend: DVB frontend.
+ */
+struct tua9001_platform_data {
+   struct dvb_frontend *dvb_frontend;
+};
+
 struct tua9001_config {
/*
 * I2C address
diff --git a/drivers/media/tuners/tua9001_priv.h 
b/drivers/media/tuners/tua9001_priv.h
index 73cc1ce..3282a1a 100644
--- a/drivers/media/tuners/tua9001_priv.h
+++ b/drivers/media/tuners/tua9001_priv.h
@@ -27,8 +27,10 @@ struct 

[PATCH 17/21] rtl28xxu: set correct FC2580 tuner for RTL2832 demod

2015-05-05 Thread Antti Palosaari
rtl2832 demod driver has support for FC2580 tuner config, no need to
abuse FC0012 settings anymore.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 9a65291..41f8808 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -643,6 +643,11 @@ err:
return ret;
 }
 
+static const struct rtl2832_platform_data rtl2832_fc2580_platform_data = {
+   .clk = 2880,
+   .tuner = TUNER_RTL2832_FC2580,
+};
+
 static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = {
.clk = 2880,
.tuner = TUNER_RTL2832_FC0012
@@ -804,8 +809,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter 
*adap)
*pdata = rtl2832_fc0013_platform_data;
break;
case TUNER_RTL2832_FC2580:
-   /* FIXME: do not abuse fc0012 settings */
-   *pdata = rtl2832_fc0012_platform_data;
+   *pdata = rtl2832_fc2580_platform_data;
break;
case TUNER_RTL2832_TUA9001:
*pdata = rtl2832_tua9001_platform_data;
-- 
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 12/21] tua9001: remove media attach

2015-05-05 Thread Antti Palosaari
We are using I2C client binding now, so remove old media attach.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/tua9001.c | 88 ++
 drivers/media/tuners/tua9001.h | 20 --
 2 files changed, 4 insertions(+), 104 deletions(-)

diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index 55cac20..87e8518 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -47,23 +47,6 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, 
u16 val)
return ret;
 }
 
-static int tua9001_release(struct dvb_frontend *fe)
-{
-   struct tua9001_priv *priv = fe-tuner_priv;
-   int ret = 0;
-
-   dev_dbg(priv-i2c-dev, %s:\n, __func__);
-
-   if (fe-callback)
-   ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
-   TUA9001_CMD_CEN, 0);
-
-   kfree(fe-tuner_priv);
-   fe-tuner_priv = NULL;
-
-   return ret;
-}
-
 static int tua9001_init(struct dvb_frontend *fe)
 {
struct tua9001_priv *priv = fe-tuner_priv;
@@ -96,18 +79,11 @@ static int tua9001_init(struct dvb_frontend *fe)
goto err;
}
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
-
for (i = 0; i  ARRAY_SIZE(data); i++) {
ret = tua9001_wr_reg(priv, data[i].reg, data[i].val);
if (ret  0)
-   goto err_i2c_gate_ctrl;
+   goto err;
}
-
-err_i2c_gate_ctrl:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
 err:
if (ret  0)
dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
@@ -181,32 +157,25 @@ static int tua9001_set_params(struct dvb_frontend *fe)
data[1].reg = 0x1f;
data[1].val = frequency;
 
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
-
if (fe-callback) {
ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
TUA9001_CMD_RXEN, 0);
if (ret  0)
-   goto err_i2c_gate_ctrl;
+   goto err;
}
 
for (i = 0; i  ARRAY_SIZE(data); i++) {
ret = tua9001_wr_reg(priv, data[i].reg, data[i].val);
if (ret  0)
-   goto err_i2c_gate_ctrl;
+   goto err;
}
 
if (fe-callback) {
ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
TUA9001_CMD_RXEN, 1);
if (ret  0)
-   goto err_i2c_gate_ctrl;
+   goto err;
}
-
-err_i2c_gate_ctrl:
-   if (fe-ops.i2c_gate_ctrl)
-   fe-ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
 err:
if (ret  0)
dev_dbg(priv-i2c-dev, %s: failed=%d\n, __func__, ret);
@@ -234,8 +203,6 @@ static const struct dvb_tuner_ops tua9001_tuner_ops = {
.frequency_step = 0,
},
 
-   .release = tua9001_release,
-
.init = tua9001_init,
.sleep = tua9001_sleep,
.set_params = tua9001_set_params,
@@ -243,52 +210,6 @@ static const struct dvb_tuner_ops tua9001_tuner_ops = {
.get_if_frequency = tua9001_get_if_frequency,
 };
 
-struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
-   struct i2c_adapter *i2c, struct tua9001_config *cfg)
-{
-   struct tua9001_priv *priv = NULL;
-   int ret;
-
-   priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL);
-   if (priv == NULL)
-   return NULL;
-
-   priv-i2c_addr = cfg-i2c_addr;
-   priv-i2c = i2c;
-
-   if (fe-callback) {
-   ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
-   TUA9001_CMD_CEN, 1);
-   if (ret  0)
-   goto err;
-
-   ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
-   TUA9001_CMD_RXEN, 0);
-   if (ret  0)
-   goto err;
-
-   ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
-   TUA9001_CMD_RESETN, 1);
-   if (ret  0)
-   goto err;
-   }
-
-   dev_info(priv-i2c-dev,
-   %s: Infineon TUA 9001 successfully attached\n,
-   KBUILD_MODNAME);
-
-   memcpy(fe-ops.tuner_ops, tua9001_tuner_ops,
-   sizeof(struct dvb_tuner_ops));
-
-   fe-tuner_priv = priv;
-   return fe;
-err:
-   dev_dbg(i2c-dev, %s: failed=%d\n, __func__, ret);
-   kfree(priv);
-   return NULL;
-}
-EXPORT_SYMBOL(tua9001_attach);
-
 static int tua9001_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {

[PATCH 10/21] af9035: bind tua9001 using I2C binding

2015-05-05 Thread Antti Palosaari
Change tua9001 driver from media binding to I2C client binding.

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

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index ae72357..cd88597 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1234,10 +1234,6 @@ static int af9035_frontend_detach(struct dvb_usb_adapter 
*adap)
return 0;
 }
 
-static struct tua9001_config af9035_tua9001_config = {
-   .i2c_addr = 0x60,
-};
-
 static const struct fc0011_config af9035_fc0011_config = {
.i2c_address = 0x60,
 };
@@ -1296,9 +1292,15 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
 */
 
switch (state-af9033_config[adap-id].tuner) {
-   case AF9033_TUNER_TUA9001:
-   /* AF9035 gpiot3 = TUA9001 RESETN
-  AF9035 gpiot2 = TUA9001 RXEN */
+   case AF9033_TUNER_TUA9001: {
+   struct tua9001_platform_data tua9001_pdata = {
+   .dvb_frontend = adap-fe[0],
+   };
+
+   /*
+* AF9035 gpiot3 = TUA9001 RESETN
+* AF9035 gpiot2 = TUA9001 RXEN
+*/
 
/* configure gpiot2 and gpiot2 as output */
ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01);
@@ -1318,9 +1320,14 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
goto err;
 
/* attach tuner */
-   fe = dvb_attach(tua9001_attach, adap-fe[0],
-   d-i2c_adap, af9035_tua9001_config);
+   ret = af9035_add_i2c_dev(d, tua9001, 0x60, tua9001_pdata,
+d-i2c_adap);
+   if (ret)
+   goto err;
+
+   fe = adap-fe[0];
break;
+   }
case AF9033_TUNER_FC0011:
fe = dvb_attach(fc0011_attach, adap-fe[0],
d-i2c_adap, af9035_fc0011_config);
@@ -1615,6 +1622,7 @@ static int af9035_tuner_detach(struct dvb_usb_adapter 
*adap)
dev_dbg(d-udev-dev, %s: adap-id=%d\n, __func__, adap-id);
 
switch (state-af9033_config[adap-id].tuner) {
+   case AF9033_TUNER_TUA9001:
case AF9033_TUNER_FC2580:
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
-- 
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 13/21] tua9001: various minor changes

2015-05-05 Thread Antti Palosaari
Fix logging. Style issues. Rename things.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/Kconfig|   2 +-
 drivers/media/tuners/tua9001.c  | 153 ++--
 drivers/media/tuners/tua9001.h  |   6 +-
 drivers/media/tuners/tua9001_priv.h |  16 ++--
 4 files changed, 83 insertions(+), 94 deletions(-)

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index e826453..74973f4 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -234,7 +234,7 @@ config MEDIA_TUNER_M88RS6000T
  Montage M88RS6000 internal tuner.
 
 config MEDIA_TUNER_TUA9001
-   tristate Infineon TUA 9001 silicon tuner
+   tristate Infineon TUA9001 silicon tuner
depends on MEDIA_SUPPORT  I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index 87e8518..fe778cd 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -1,5 +1,5 @@
 /*
- * Infineon TUA 9001 silicon tuner driver
+ * Infineon TUA9001 silicon tuner driver
  *
  * Copyright (C) 2009 Antti Palosaari cr...@iki.fi
  *
@@ -12,35 +12,30 @@
  *but WITHOUT ANY WARRANTY; without even the implied warranty of
  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License along
- *with this program; if not, write to the Free Software Foundation, Inc.,
- *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include tua9001.h
 #include tua9001_priv.h
 
 /* write register */
-static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val)
+static int tua9001_wr_reg(struct tua9001_dev *dev, u8 reg, u16 val)
 {
+   struct i2c_client *client = dev-client;
int ret;
u8 buf[3] = { reg, (val  8)  0xff, (val  0)  0xff };
struct i2c_msg msg[1] = {
{
-   .addr = priv-i2c_addr,
+   .addr = client-addr,
.flags = 0,
.len = sizeof(buf),
.buf = buf,
}
};
 
-   ret = i2c_transfer(priv-i2c, msg, 1);
+   ret = i2c_transfer(client-adapter, msg, 1);
if (ret == 1) {
ret = 0;
} else {
-   dev_warn(priv-i2c-dev, %s: i2c wr failed=%d reg=%02x\n,
-   KBUILD_MODNAME, ret, reg);
+   dev_warn(client-dev, i2c wr failed=%d reg=%02x\n, ret, reg);
ret = -EREMOTEIO;
}
 
@@ -49,77 +44,82 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 
reg, u16 val)
 
 static int tua9001_init(struct dvb_frontend *fe)
 {
-   struct tua9001_priv *priv = fe-tuner_priv;
-   int ret = 0;
-   u8 i;
-   struct reg_val data[] = {
-   { 0x1e, 0x6512 },
-   { 0x25, 0xb888 },
-   { 0x39, 0x5460 },
-   { 0x3b, 0x00c0 },
-   { 0x3a, 0xf000 },
-   { 0x08, 0x },
-   { 0x32, 0x0030 },
-   { 0x41, 0x703a },
-   { 0x40, 0x1c78 },
-   { 0x2c, 0x1c00 },
-   { 0x36, 0xc013 },
-   { 0x37, 0x6f18 },
-   { 0x27, 0x0008 },
-   { 0x2a, 0x0001 },
-   { 0x34, 0x0a40 },
+   struct tua9001_dev *dev = fe-tuner_priv;
+   struct i2c_client *client = dev-client;
+   int ret, i;
+   static const struct tua9001_reg_val data[] = {
+   {0x1e, 0x6512},
+   {0x25, 0xb888},
+   {0x39, 0x5460},
+   {0x3b, 0x00c0},
+   {0x3a, 0xf000},
+   {0x08, 0x},
+   {0x32, 0x0030},
+   {0x41, 0x703a},
+   {0x40, 0x1c78},
+   {0x2c, 0x1c00},
+   {0x36, 0xc013},
+   {0x37, 0x6f18},
+   {0x27, 0x0008},
+   {0x2a, 0x0001},
+   {0x34, 0x0a40},
};
 
-   dev_dbg(priv-i2c-dev, %s:\n, __func__);
+   dev_dbg(client-dev, \n);
 
if (fe-callback) {
-   ret = fe-callback(priv-i2c, DVB_FRONTEND_COMPONENT_TUNER,
-   TUA9001_CMD_RESETN, 0);
-   if (ret  0)
+   ret = fe-callback(client-adapter,
+  DVB_FRONTEND_COMPONENT_TUNER,
+  TUA9001_CMD_RESETN, 0);
+   if (ret)
goto err;
}
 
for (i = 0; i  ARRAY_SIZE(data); i++) {
-   ret = tua9001_wr_reg(priv, data[i].reg, data[i].val);
-   if (ret  0)
+   ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+   if (ret)
goto err;
}
+   return 0;
 err:
-   if (ret  0)
-   

[PATCH 03/21] af9035: bind fc2580 using I2C binding

2015-05-05 Thread Antti Palosaari
Change fc2580 driver from media binding to I2C client binding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 80a29f5..558166d 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1265,11 +1265,6 @@ static struct tda18218_config af9035_tda18218_config = {
.i2c_wr_max = 21,
 };
 
-static const struct fc2580_config af9035_fc2580_config = {
-   .i2c_addr = 0x56,
-   .clock = 16384000,
-};
-
 static const struct fc0012_config af9035_fc0012_config[] = {
{
.i2c_address = 0x63,
@@ -1390,7 +1385,11 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
fe = dvb_attach(tda18218_attach, adap-fe[0],
d-i2c_adap, af9035_tda18218_config);
break;
-   case AF9033_TUNER_FC2580:
+   case AF9033_TUNER_FC2580: {
+   struct fc2580_platform_data fc2580_pdata = {
+   .dvb_frontend = adap-fe[0],
+   };
+
/* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on  */
ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
if (ret  0)
@@ -1406,9 +1405,14 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
 
usleep_range(1, 5);
/* attach tuner */
-   fe = dvb_attach(fc2580_attach, adap-fe[0],
-   d-i2c_adap, af9035_fc2580_config);
+   ret = af9035_add_i2c_dev(d, fc2580, 0x56, fc2580_pdata,
+d-i2c_adap);
+   if (ret)
+   goto err;
+
+   fe = adap-fe[0];
break;
+   }
case AF9033_TUNER_FC0012:
/*
 * AF9035 gpiot2 = FC0012 enable
@@ -1611,6 +1615,7 @@ static int af9035_tuner_detach(struct dvb_usb_adapter 
*adap)
dev_dbg(d-udev-dev, %s: adap-id=%d\n, __func__, adap-id);
 
switch (state-af9033_config[adap-id].tuner) {
+   case AF9033_TUNER_FC2580:
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
-- 
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 11/21] rtl28xxu: bind tua9001 using I2C binding

2015-05-05 Thread Antti Palosaari
Change tua9001 driver from media binding to I2C client binding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index d5b1808..9a65291 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -1018,10 +1018,6 @@ err:
return ret;
 }
 
-static struct tua9001_config rtl2832u_tua9001_config = {
-   .i2c_addr = 0x60,
-};
-
 static const struct fc0012_config rtl2832u_fc0012_config = {
.i2c_address = 0x63, /* 0xc6  1 */
.xtal_freq = FC_XTAL_28_8_MHZ,
@@ -1121,7 +1117,12 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
dev-i2c_client_tuner = client;
}
break;
-   case TUNER_RTL2832_TUA9001:
+   case TUNER_RTL2832_TUA9001: {
+   struct tua9001_platform_data tua9001_pdata = {
+   .dvb_frontend = adap-fe[0],
+   };
+   struct i2c_board_info board_info = {};
+
/* enable GPIO1 and GPIO4 as output */
ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
if (ret)
@@ -1131,10 +1132,20 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter 
*adap)
if (ret)
goto err;
 
-   fe = dvb_attach(tua9001_attach, adap-fe[0],
-   dev-demod_i2c_adapter,
-   rtl2832u_tua9001_config);
+   strlcpy(board_info.type, tua9001, I2C_NAME_SIZE);
+   board_info.addr = 0x60;
+   board_info.platform_data = tua9001_pdata;
+   request_module(tua9001);
+   client = i2c_new_device(dev-demod_i2c_adapter, board_info);
+   if (client == NULL || client-dev.driver == NULL)
+   break;
+   if (!try_module_get(client-dev.driver-owner)) {
+   i2c_unregister_device(client);
+   break;
+   }
+   dev-i2c_client_tuner = client;
break;
+   }
case TUNER_RTL2832_R820T:
fe = dvb_attach(r820t_attach, adap-fe[0],
dev-demod_i2c_adapter,
-- 
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 14/21] tua9001: use regmap for I2C register access

2015-05-05 Thread Antti Palosaari
Use regmap for I2C register access.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/Kconfig|  1 +
 drivers/media/tuners/tua9001.c  | 41 +++--
 drivers/media/tuners/tua9001_priv.h |  2 ++
 3 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 74973f4..bd302ff 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -236,6 +236,7 @@ config MEDIA_TUNER_M88RS6000T
 config MEDIA_TUNER_TUA9001
tristate Infineon TUA9001 silicon tuner
depends on MEDIA_SUPPORT  I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Infineon TUA 9001 silicon tuner driver.
diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index fe778cd..09a1034 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -16,32 +16,6 @@
 
 #include tua9001_priv.h
 
-/* write register */
-static int tua9001_wr_reg(struct tua9001_dev *dev, u8 reg, u16 val)
-{
-   struct i2c_client *client = dev-client;
-   int ret;
-   u8 buf[3] = { reg, (val  8)  0xff, (val  0)  0xff };
-   struct i2c_msg msg[1] = {
-   {
-   .addr = client-addr,
-   .flags = 0,
-   .len = sizeof(buf),
-   .buf = buf,
-   }
-   };
-
-   ret = i2c_transfer(client-adapter, msg, 1);
-   if (ret == 1) {
-   ret = 0;
-   } else {
-   dev_warn(client-dev, i2c wr failed=%d reg=%02x\n, ret, reg);
-   ret = -EREMOTEIO;
-   }
-
-   return ret;
-}
-
 static int tua9001_init(struct dvb_frontend *fe)
 {
struct tua9001_dev *dev = fe-tuner_priv;
@@ -76,7 +50,7 @@ static int tua9001_init(struct dvb_frontend *fe)
}
 
for (i = 0; i  ARRAY_SIZE(data); i++) {
-   ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+   ret = regmap_write(dev-regmap, data[i].reg, data[i].val);
if (ret)
goto err;
}
@@ -166,7 +140,7 @@ static int tua9001_set_params(struct dvb_frontend *fe)
}
 
for (i = 0; i  ARRAY_SIZE(data); i++) {
-   ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+   ret = regmap_write(dev-regmap, data[i].reg, data[i].val);
if (ret)
goto err;
}
@@ -216,6 +190,10 @@ static int tua9001_probe(struct i2c_client *client,
struct tua9001_platform_data *pdata = client-dev.platform_data;
struct dvb_frontend *fe = pdata-dvb_frontend;
int ret;
+   static const struct regmap_config regmap_config = {
+   .reg_bits =  8,
+   .val_bits = 16,
+   };
 
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
@@ -223,8 +201,13 @@ static int tua9001_probe(struct i2c_client *client,
goto err;
}
 
-   dev-client = client;
dev-fe = pdata-dvb_frontend;
+   dev-client = client;
+   dev-regmap = devm_regmap_init_i2c(client, regmap_config);
+   if (IS_ERR(dev-regmap)) {
+   ret = PTR_ERR(dev-regmap);
+   goto err_kfree;
+   }
 
if (fe-callback) {
ret = fe-callback(client-adapter,
diff --git a/drivers/media/tuners/tua9001_priv.h 
b/drivers/media/tuners/tua9001_priv.h
index e24d843..327ead9 100644
--- a/drivers/media/tuners/tua9001_priv.h
+++ b/drivers/media/tuners/tua9001_priv.h
@@ -18,6 +18,7 @@
 #define TUA9001_PRIV_H
 
 #include tua9001.h
+#include linux/regmap.h
 
 struct tua9001_reg_val {
u8 reg;
@@ -27,6 +28,7 @@ struct tua9001_reg_val {
 struct tua9001_dev {
struct dvb_frontend *fe;
struct i2c_client *client;
+   struct regmap *regmap;
 };
 
 #endif
-- 
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 16/21] rtl2832: add inittab for FC2580 tuner

2015-05-05 Thread Antti Palosaari
Add reg/val inittab for FC2580 tuner.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c  |  4 
 drivers/media/dvb-frontends/rtl2832.h  |  1 +
 drivers/media/dvb-frontends/rtl2832_priv.h | 24 
 3 files changed, 29 insertions(+)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index b400f7b..753496c 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -358,6 +358,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
dev_dbg(client-dev, load settings for tuner=%02x\n,
dev-pdata-tuner);
switch (dev-pdata-tuner) {
+   case RTL2832_TUNER_FC2580:
+   len = ARRAY_SIZE(rtl2832_tuner_init_fc2580);
+   init = rtl2832_tuner_init_fc2580;
+   break;
case RTL2832_TUNER_FC0012:
case RTL2832_TUNER_FC0013:
len = ARRAY_SIZE(rtl2832_tuner_init_fc0012);
diff --git a/drivers/media/dvb-frontends/rtl2832.h 
b/drivers/media/dvb-frontends/rtl2832.h
index a8e912e..c1df881 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -41,6 +41,7 @@ struct rtl2832_platform_data {
/*
 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver.
 */
+#define RTL2832_TUNER_FC25800x21
 #define RTL2832_TUNER_TUA9001   0x24
 #define RTL2832_TUNER_FC00120x26
 #define RTL2832_TUNER_E4000 0x27
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h 
b/drivers/media/dvb-frontends/rtl2832_priv.h
index c3a922c..635556d 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -252,6 +252,30 @@ enum DVBT_REG_BIT_NAME {
DVBT_REG_BIT_NAME_ITEM_TERMINATOR,
 };
 
+static const struct rtl2832_reg_value rtl2832_tuner_init_fc2580[] = {
+   {DVBT_DAGC_TRG_VAL, 0x39},
+   {DVBT_AGC_TARG_VAL_0,0x0},
+   {DVBT_AGC_TARG_VAL_8_1, 0x5a},
+   {DVBT_AAGC_LOOP_GAIN,   0x16},
+   {DVBT_LOOP_GAIN2_3_0,0x6},
+   {DVBT_LOOP_GAIN2_4,  0x1},
+   {DVBT_LOOP_GAIN3,   0x16},
+   {DVBT_VTOP1,0x35},
+   {DVBT_VTOP2,0x21},
+   {DVBT_VTOP3,0x21},
+   {DVBT_KRF1,  0x0},
+   {DVBT_KRF2, 0x40},
+   {DVBT_KRF3, 0x10},
+   {DVBT_KRF4, 0x10},
+   {DVBT_IF_AGC_MIN,   0x80},
+   {DVBT_IF_AGC_MAX,   0x7f},
+   {DVBT_RF_AGC_MIN,   0x9c},
+   {DVBT_RF_AGC_MAX,   0x7f},
+   {DVBT_POLAR_RF_AGC,  0x0},
+   {DVBT_POLAR_IF_AGC,  0x0},
+   {DVBT_AD7_SETTING,0xe9f4},
+};
+
 static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = {
{DVBT_DAGC_TRG_VAL, 0x39},
{DVBT_AGC_TARG_VAL_0,0x0},
-- 
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 20/21] rtl2832_sdr: add support for fc2580 tuner

2015-05-05 Thread Antti Palosaari
Add initial support for fc2580 tuner based devices.
Tuner is controlled via V4L2 subdevice API.
Passes v4l2-compliance tests.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832_sdr.c | 110 --
 drivers/media/dvb-frontends/rtl2832_sdr.h |   1 +
 2 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c 
b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 3ff8806..c501bcd 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -39,6 +39,10 @@ static bool rtl2832_sdr_emulated_fmt;
 module_param_named(emulated_formats, rtl2832_sdr_emulated_fmt, bool, 0644);
 MODULE_PARM_DESC(emulated_formats, enable emulated formats (disappears in 
future));
 
+/* Original macro does not contain enough null pointer checks for our need */
+#define V4L2_SUBDEV_HAS_OP(sd, o, f) \
+   ((sd)  (sd)-ops  (sd)-ops-o  (sd)-ops-o-f)
+
 #define MAX_BULK_BUFS(10)
 #define BULK_BUFFER_SIZE (128 * 512)
 
@@ -116,6 +120,7 @@ struct rtl2832_sdr_dev {
 
struct video_device vdev;
struct v4l2_device v4l2_dev;
+   struct v4l2_subdev *v4l2_subdev;
 
/* videobuf2 queue and queued buffers list */
struct vb2_queue vb_queue;
@@ -742,6 +747,29 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_dev *dev)
ret = rtl2832_sdr_wr_regs(dev, 0x00e, \xfc, 1);
ret = rtl2832_sdr_wr_regs(dev, 0x011, \xf4, 1);
break;
+   case RTL2832_SDR_TUNER_FC2580:
+   ret = rtl2832_sdr_wr_regs(dev, 0x112, \x39, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x102, \x40, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x103, \x5a, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1c7, \x2c, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x104, \xcc, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x105, \xbe, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1c8, \x16, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x106, \x35, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1c9, \x21, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1ca, \x21, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1cb, \x00, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x107, \x40, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1cd, \x10, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x1ce, \x10, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x108, \x80, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x109, \x7f, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x10a, \x9c, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x10b, \x7f, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x00e, \xfc, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x00e, \xfc, 1);
+   ret = rtl2832_sdr_wr_regs(dev, 0x011, \xe9\xf4, 2);
+   break;
default:
dev_notice(pdev-dev, Unsupported tuner\n);
}
@@ -832,8 +860,10 @@ static int rtl2832_sdr_set_tuner_freq(struct 
rtl2832_sdr_dev *dev)
if (!test_bit(POWER_ON, dev-flags))
return 0;
 
-   if (fe-ops.tuner_ops.set_params)
-   fe-ops.tuner_ops.set_params(fe);
+   if (!V4L2_SUBDEV_HAS_OP(dev-v4l2_subdev, tuner, s_frequency)) {
+   if (fe-ops.tuner_ops.set_params)
+   fe-ops.tuner_ops.set_params(fe);
+   }
 
return 0;
 };
@@ -891,7 +921,11 @@ static int rtl2832_sdr_start_streaming(struct vb2_queue 
*vq, unsigned int count)
 
set_bit(POWER_ON, dev-flags);
 
-   ret = rtl2832_sdr_set_tuner(dev);
+   /* wake-up tuner */
+   if (V4L2_SUBDEV_HAS_OP(dev-v4l2_subdev, core, s_power))
+   ret = v4l2_subdev_call(dev-v4l2_subdev, core, s_power, 1);
+   else
+   ret = rtl2832_sdr_set_tuner(dev);
if (ret)
goto err;
 
@@ -939,7 +973,12 @@ static void rtl2832_sdr_stop_streaming(struct vb2_queue 
*vq)
rtl2832_sdr_free_stream_bufs(dev);
rtl2832_sdr_cleanup_queued_bufs(dev);
rtl2832_sdr_unset_adc(dev);
-   rtl2832_sdr_unset_tuner(dev);
+
+   /* sleep tuner */
+   if (V4L2_SUBDEV_HAS_OP(dev-v4l2_subdev, core, s_power))
+   v4l2_subdev_call(dev-v4l2_subdev, core, s_power, 0);
+   else
+   rtl2832_sdr_unset_tuner(dev);
 
clear_bit(POWER_ON, dev-flags);
 
@@ -968,6 +1007,7 @@ static int rtl2832_sdr_g_tuner(struct file *file, void 
*priv,
 {
struct rtl2832_sdr_dev *dev = video_drvdata(file);
struct platform_device *pdev = dev-pdev;
+   int ret;
 
dev_dbg(pdev-dev, index=%d type=%d\n, v-index, v-type);
 
@@ -977,17 +1017,21 @@ static int rtl2832_sdr_g_tuner(struct file *file, void 
*priv,
v-capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
v-rangelow =   30;
v-rangehigh = 

[PATCH 15/21] tua9001: use div_u64() for frequency calculation

2015-05-05 Thread Antti Palosaari
Use div_u64() to simplify and remove home made divides.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/tua9001.c  | 9 +
 drivers/media/tuners/tua9001_priv.h | 1 +
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index 09a1034..d4f6ca0 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -88,7 +88,6 @@ static int tua9001_set_params(struct dvb_frontend *fe)
struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret, i;
u16 val;
-   u32 frequency;
struct tua9001_reg_val data[2];
 
dev_dbg(client-dev,
@@ -122,14 +121,8 @@ static int tua9001_set_params(struct dvb_frontend *fe)
 
data[0].reg = 0x04;
data[0].val = val;
-
-   frequency = (c-frequency - 15000);
-   frequency /= 100;
-   frequency *= 48;
-   frequency /= 1;
-
data[1].reg = 0x1f;
-   data[1].val = frequency;
+   data[1].val = div_u64((u64) (c-frequency - 15000) * 48, 100);
 
if (fe-callback) {
ret = fe-callback(client-adapter,
diff --git a/drivers/media/tuners/tua9001_priv.h 
b/drivers/media/tuners/tua9001_priv.h
index 327ead9..bc406c5 100644
--- a/drivers/media/tuners/tua9001_priv.h
+++ b/drivers/media/tuners/tua9001_priv.h
@@ -18,6 +18,7 @@
 #define TUA9001_PRIV_H
 
 #include tua9001.h
+#include linux/math64.h
 #include linux/regmap.h
 
 struct tua9001_reg_val {
-- 
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 3/4] e4000: cosmetic changes for PLL

2015-05-05 Thread Antti Palosaari
Add schematic drawing of used Fractional-N PLL. Rename and add some
new PLL variables for better understanding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c  | 44 +++
 drivers/media/tuners/e4000_priv.h |  4 ++--
 2 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index a5d51d7..d27d2e7 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -112,8 +112,8 @@ static int e4000_set_params(struct dvb_frontend *fe)
 {
struct e4000 *s = fe-tuner_priv;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
-   int ret, i, sigma_delta;
-   unsigned int pll_n, pll_f;
+   int ret, i;
+   unsigned int div_n, k, k_cw, div_out;
u64 f_vco;
u8 buf[5], i_data[4], q_data[4];
 
@@ -126,7 +126,21 @@ static int e4000_set_params(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   /* PLL */
+   /*
+* Fractional-N synthesizer
+*
+*   ++
+*   v|
+*  Fref   ++ +---+ +--+ +---+
+* -- | PD | -- |  VCO  | -- | /N.F | -- | K |
+* ++ +---+ +--+ +---+
+*  |
+*  |
+*  v
+*+---+  Fout
+*| /Rout | --
+*+---+
+*/
for (i = 0; i  ARRAY_SIZE(e4000_pll_lut); i++) {
if (c-frequency = e4000_pll_lut[i].freq)
break;
@@ -137,18 +151,22 @@ static int e4000_set_params(struct dvb_frontend *fe)
goto err;
}
 
-   f_vco = 1ull * c-frequency * e4000_pll_lut[i].mul;
-   pll_n = div_u64_rem(f_vco, s-clock, pll_f);
-   sigma_delta = div_u64(0x1ULL * pll_f, s-clock);
-   buf[0] = pll_n;
-   buf[1] = (sigma_delta  0)  0xff;
-   buf[2] = (sigma_delta  8)  0xff;
-   buf[3] = 0x00;
-   buf[4] = e4000_pll_lut[i].div;
+   #define F_REF s-clock
+   div_out = e4000_pll_lut[i].div_out;
+   f_vco = (u64) c-frequency * div_out;
+   /* calculate PLL integer and fractional control word */
+   div_n = div_u64_rem(f_vco, F_REF, k);
+   k_cw = div_u64((u64) k * 0x1, F_REF);
 
-   dev_dbg(s-client-dev, f_vco=%llu pll div=%d sigma_delta=%04x\n,
-   f_vco, buf[0], sigma_delta);
+   dev_dbg(s-client-dev,
+   frequency=%u f_vco=%llu F_REF=%u div_n=%u k=%u k_cw=%04x 
div_out=%u\n,
+   c-frequency, f_vco, F_REF, div_n, k, k_cw, div_out);
 
+   buf[0] = div_n;
+   buf[1] = (k_cw  0)  0xff;
+   buf[2] = (k_cw  8)  0xff;
+   buf[3] = 0x00;
+   buf[4] = e4000_pll_lut[i].div_out_reg;
ret = regmap_bulk_write(s-regmap, 0x09, buf, 5);
if (ret)
goto err;
diff --git a/drivers/media/tuners/e4000_priv.h 
b/drivers/media/tuners/e4000_priv.h
index cb00704..6214fc0 100644
--- a/drivers/media/tuners/e4000_priv.h
+++ b/drivers/media/tuners/e4000_priv.h
@@ -49,8 +49,8 @@ struct e4000 {
 
 struct e4000_pll {
u32 freq;
-   u8 div;
-   u8 mul;
+   u8 div_out_reg;
+   u8 div_out;
 };
 
 static const struct e4000_pll e4000_pll_lut[] = {
-- 
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 2/4] e4000: remove dummy register write

2015-05-05 Thread Antti Palosaari
Chip is already probed, which means I2C bus is alive and working
unless something strange happens during sleep.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 59190cb..a5d51d7 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -28,9 +28,6 @@ static int e4000_init(struct dvb_frontend *fe)
 
dev_dbg(s-client-dev, \n);
 
-   /* dummy I2C to ensure I2C wakes up */
-   ret = regmap_write(s-regmap, 0x02, 0x40);
-
/* reset */
ret = regmap_write(s-regmap, 0x00, 0x01);
if (ret)
-- 
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 1/4] e4000: disable sysfs device bind / unbind

2015-05-05 Thread Antti Palosaari
We are not allowed manually bind / unbind device from the driver
currently.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 510239f..59190cb 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -601,6 +601,7 @@ static struct i2c_driver e4000_driver = {
.driver = {
.owner  = THIS_MODULE,
.name   = e4000,
+   .suppress_bind_attrs = true,
},
.probe  = e4000_probe,
.remove = e4000_remove,
-- 
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/4] e4000: various small changes

2015-05-05 Thread Antti Palosaari
Rename device state from 's' to 'dev'.
Move single include to driver private header.
Change error handling type of each function to one I tend use nowadays.
Define I2C client pointer for each function and use it.
Do not clean tuner ops during driver remove - not needed.
Rename some other variables.

All are rather cosmetic changes.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/e4000.c  | 350 +++---
 drivers/media/tuners/e4000.h  |   1 -
 drivers/media/tuners/e4000_priv.h |   5 +-
 3 files changed, 177 insertions(+), 179 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index d27d2e7..6e2c025 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -19,110 +19,112 @@
  */
 
 #include e4000_priv.h
-#include linux/math64.h
 
 static int e4000_init(struct dvb_frontend *fe)
 {
-   struct e4000 *s = fe-tuner_priv;
+   struct e4000_dev *dev = fe-tuner_priv;
+   struct i2c_client *client = dev-client;
int ret;
 
-   dev_dbg(s-client-dev, \n);
+   dev_dbg(client-dev, \n);
 
/* reset */
-   ret = regmap_write(s-regmap, 0x00, 0x01);
+   ret = regmap_write(dev-regmap, 0x00, 0x01);
if (ret)
goto err;
 
/* disable output clock */
-   ret = regmap_write(s-regmap, 0x06, 0x00);
+   ret = regmap_write(dev-regmap, 0x06, 0x00);
if (ret)
goto err;
 
-   ret = regmap_write(s-regmap, 0x7a, 0x96);
+   ret = regmap_write(dev-regmap, 0x7a, 0x96);
if (ret)
goto err;
 
/* configure gains */
-   ret = regmap_bulk_write(s-regmap, 0x7e, \x01\xfe, 2);
+   ret = regmap_bulk_write(dev-regmap, 0x7e, \x01\xfe, 2);
if (ret)
goto err;
 
-   ret = regmap_write(s-regmap, 0x82, 0x00);
+   ret = regmap_write(dev-regmap, 0x82, 0x00);
if (ret)
goto err;
 
-   ret = regmap_write(s-regmap, 0x24, 0x05);
+   ret = regmap_write(dev-regmap, 0x24, 0x05);
if (ret)
goto err;
 
-   ret = regmap_bulk_write(s-regmap, 0x87, \x20\x01, 2);
+   ret = regmap_bulk_write(dev-regmap, 0x87, \x20\x01, 2);
if (ret)
goto err;
 
-   ret = regmap_bulk_write(s-regmap, 0x9f, \x7f\x07, 2);
+   ret = regmap_bulk_write(dev-regmap, 0x9f, \x7f\x07, 2);
if (ret)
goto err;
 
/* DC offset control */
-   ret = regmap_write(s-regmap, 0x2d, 0x1f);
+   ret = regmap_write(dev-regmap, 0x2d, 0x1f);
if (ret)
goto err;
 
-   ret = regmap_bulk_write(s-regmap, 0x70, \x01\x01, 2);
+   ret = regmap_bulk_write(dev-regmap, 0x70, \x01\x01, 2);
if (ret)
goto err;
 
/* gain control */
-   ret = regmap_write(s-regmap, 0x1a, 0x17);
+   ret = regmap_write(dev-regmap, 0x1a, 0x17);
if (ret)
goto err;
 
-   ret = regmap_write(s-regmap, 0x1f, 0x1a);
+   ret = regmap_write(dev-regmap, 0x1f, 0x1a);
if (ret)
goto err;
 
-   s-active = true;
-err:
-   if (ret)
-   dev_dbg(s-client-dev, failed=%d\n, ret);
+   dev-active = true;
 
+   return 0;
+err:
+   dev_dbg(client-dev, failed=%d\n, ret);
return ret;
 }
 
 static int e4000_sleep(struct dvb_frontend *fe)
 {
-   struct e4000 *s = fe-tuner_priv;
+   struct e4000_dev *dev = fe-tuner_priv;
+   struct i2c_client *client = dev-client;
int ret;
 
-   dev_dbg(s-client-dev, \n);
+   dev_dbg(client-dev, \n);
 
-   s-active = false;
+   dev-active = false;
 
-   ret = regmap_write(s-regmap, 0x00, 0x00);
+   ret = regmap_write(dev-regmap, 0x00, 0x00);
if (ret)
goto err;
-err:
-   if (ret)
-   dev_dbg(s-client-dev, failed=%d\n, ret);
 
+   return 0;
+err:
+   dev_dbg(client-dev, failed=%d\n, ret);
return ret;
 }
 
 static int e4000_set_params(struct dvb_frontend *fe)
 {
-   struct e4000 *s = fe-tuner_priv;
+   struct e4000_dev *dev = fe-tuner_priv;
+   struct i2c_client *client = dev-client;
struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret, i;
unsigned int div_n, k, k_cw, div_out;
u64 f_vco;
u8 buf[5], i_data[4], q_data[4];
 
-   dev_dbg(s-client-dev,
-   delivery_system=%d frequency=%u bandwidth_hz=%u\n,
-   c-delivery_system, c-frequency, c-bandwidth_hz);
+   dev_dbg(client-dev,
+   delivery_system=%d frequency=%u bandwidth_hz=%u\n,
+   c-delivery_system, c-frequency, c-bandwidth_hz);
 
/* gain control manual */
-   ret = regmap_write(s-regmap, 0x1a, 0x00);
+   ret = regmap_write(dev-regmap, 0x1a, 0x00);
if (ret)
goto err;
 
@@ -151,14 +153,14 @@ static int e4000_set_params(struct 

Re: [PATCH v3 1/1] V4L2: platform: Renesas R-Car JPEG codec driver

2015-05-05 Thread Mikhail Ulianov
Hello Laurent,
Thanks for your comments.

On Mon, 04 May 2015 02:32:05 +0300
Laurent Pinchart laurent.pinch...@ideasonboard.com wrote:
  +/*
  + *
  
  + * video ioctl operations
  + *
  
  + */
  +static void put_qtbl(u8 *p, const unsigned int *qtbl)
  +{
  +   unsigned int i;
  +
  +   for (i = 0; i  ARRAY_SIZE(zigzag); i++)
  +   *(p + i) = *((const u8 *)qtbl + zigzag[i]);
  +}
  +
  +static void put_htbl(u8 *p, const u8 *htbl, unsigned int len)
  +{
  +   unsigned int i, j;
  +
  +   for (i = 0; i  len; i += 4)
  +   for (j = 0; j  4  (i + j)  len; ++j)
  +   p[i + j] = htbl[i + 3 - j];
 
 Instead of converting the tables to big endian for every frame, how
 about generating them in big endian directly and then using a simple
 memcpy() ?
I think you got it wrong. It's done only *once* on driver
initialization. And i implemented it this way because size of table(for
regs initialization) is not equal with one we want to put in header (164
bytes vs 162 bytes)

[snip]
 
  +/*
  + *
  
  + * Queue operations
  + *
  --==
  + */
  +static int jpu_queue_setup(struct vb2_queue *vq,
  +  const struct v4l2_format *fmt,
  +  unsigned int *nbuffers, unsigned int
  *nplanes,
  +  unsigned int sizes[], void
  *alloc_ctxs[]) +{
  +   struct jpu_ctx *ctx = vb2_get_drv_priv(vq);
  +   struct jpu_q_data *q_data;
  +   unsigned int count = *nbuffers;
  +   unsigned int i;
  +
  +   q_data = jpu_get_q_data(ctx, vq-type);
  +
  +   *nplanes = q_data-format.num_planes;
  +
  +   /*
  +* Header is parsed during decoding and parsed information
  stored
  +* in the context so we do not allow another buffer to
  overwrite it.
  +* For now it works this way, but planned for alternation.
 
 It shouldn't be difficult to create a jpu_buffer structure that
 inherits from vb2_buffer and store the information there instead of
 in the context.
You are absolutely right. But for this version i want to keep it
simple and also at this moment not everything clear for me with this
format autodetection feature we want to have e.g. for decoder if user
requested 2 output buffers and then queue first with some valid JPEG
with format -1-(so we setup queues format here), after that
another one with format -2-... should we discard second one or just
change format of queues? what about same situation if user already
requested capture buffers. I mean relations with buf_prepare and 
queue_setup. AFAIU format should remain the same for all requested
buffers. I see only one solid solution here - get rid of
autodetection feature and rely only on format setted by user, so in
this case we can just discard queued buffers with inappropriate
format(kind of format validation in kernel). This solution will also
work well with NV61, NV21, and semiplanar formats we want to add in next
version. *But* with this solution header parsing must be done twice(in
user and kernel spaces). 
I'm a little bit frustrated here :)

[snip]
 
  +   src_buf = v4l2_m2m_next_src_buf(ctx-fh.m2m_ctx);
  +   dst_buf = v4l2_m2m_next_dst_buf(ctx-fh.m2m_ctx);
  +
  +   if (ctx-encoder) {
  +   unsigned long src_1_addr, src_2_addr, dst_addr;
  +   unsigned int redu, inft, w, h;
  +   u8 *dst_vaddr;
  +   struct jpu_q_data *q_data = ctx-out_q;
  +   unsigned char subsampling =
  q_data-fmtinfo-subsampling; +
  +   src_1_addr =
  vb2_dma_contig_plane_dma_addr(src_buf, 0);
  +   src_2_addr =
  vb2_dma_contig_plane_dma_addr(src_buf, 1); +
  +   dst_addr = vb2_dma_contig_plane_dma_addr(dst_buf,
  0);
  +   dst_vaddr = vb2_plane_vaddr(dst_buf, 0);
  +
  +   w = q_data-format.width;
  +   h = q_data-format.height;
  +   bpl = q_data-format.plane_fmt[0].bytesperline;
  +
  +   memcpy(dst_vaddr, jpeg_hdrs[ctx-compr_quality],
  +   JPU_JPEG_HDR_SIZE);
  +   *(u16 *)(dst_vaddr + JPU_JPEG_HEIGHT_OFFSET) =
  cpu_to_be16(h);
  +   *(u16 *)(dst_vaddr + JPU_JPEG_WIDTH_OFFSET) =
  cpu_to_be16(w);
  +   *(dst_vaddr + JPU_JPEG_SUBS_OFFSET) = subsampling;
 
 At this point I think the buffer belongs to the device. Have you
 considered possible caching issues ? Would it make sense to write the
 header when the buffer is prepared ?
AFAIU if header will be aligned to cache line there shouldn't be any
problems and v4l2_m2m_buf_done - vb2_dc_finish will do rest of work.
Not sure what when the buffer is prepared mean. You mean after
v4l2_m2m_buf_done?

{snip]
 
  +#ifdef CONFIG_PM_SLEEP
  +static int jpu_suspend(struct device *dev)
  +{
  +   struct jpu *jpu = dev_get_drvdata(dev);
  +
  +   if 

Re: [RFCv3 2/2] dma-buf: add helpers for sharing attacher constraints with dma-parms

2015-05-05 Thread Sumit Semwal
Hi Russell, everyone,

First up, sincere apologies for being awol for sometime; had some
personal / medical things to take care of, and then I thought I'd wait
for the merge window to get over before beginning to discuss this
again.

On 11 February 2015 at 21:53, Russell King - ARM Linux
li...@arm.linux.org.uk wrote:
 On Wed, Feb 11, 2015 at 01:20:24PM +0100, Marek Szyprowski wrote:
 Hello,

 On 2015-02-11 12:12, Russell King - ARM Linux wrote:
 Which is a damn good reason to NAK it - by that admission, it's a half-baked
 idea.
 
 If all we want to know is whether the importer can accept only contiguous
 memory or not, make a flag to do that, and allow the exporter to test this
 flag.  Don't over-engineer this to make it _seem_ like it can do something
 that it actually totally fails with.
 
 As I've already pointed out, there's a major problem if you have already
 had a less restrictive attachment which has an active mapping, and a new
 more restrictive attachment comes along later.
 
 It seems from Rob's descriptions that we also need another flag in the
 importer to indicate whether it wants to have a valid struct page in the
 scatter list, or whether it (correctly) uses the DMA accessors on the
 scatter list - so that exporters can reject importers which are buggy.

 Okay, but flag-based approach also have limitations.

 Yes, the flag-based approach doesn't let you describe in detail what
 the importer can accept - which, given the issues that I've raised
 is a *good* thing.  We won't be misleading anyone into thinking that
 we can do something that's really half-baked, and which we have no
 present requirement for.

 This is precisely what Linus talks about when he says don't over-
 engineer - if we over-engineer this, we end up with something that
 sort-of works, and that's a bad thing.

 The Keep It Simple approach here makes total sense - what are our
 current requirements - to be able to say that an importer can only accept:
   - contiguous memory rather than a scatterlist
   - scatterlists with struct page pointers

 Does solving that need us to compare all the constraints of each and
 every importer, possibly ending up with constraints which can't be
 satisfied?  No.  Does the flag approach satisfy the requirements?  Yes.


So, for basic constraint-sharing, we'll just go with the flag based
approach, with a flag (best place for it is still dev-dma_params I
suppose) for denoting contiguous or scatterlist. Is that agreed, then?
Also, with this idea, of course, there won't be any helpers for trying
to calculate constraints; it would be totally the exporter's
responsibility to handle it via the attach() dma_buf_op if it wishes
to.

 Frankly, if we want to make it really portable and sharable between devices,
 then IMO we should get rid of struct scatterlist and replace it with simple
 array of pfns in dma_buf. This way at least the problem of missing struct
 page will be solved and the buffer representation will be also a bit more
 compact.

 ... and move the mapping and unmapping of the PFNs to the importer,
 which IMHO is where it should already be (so the importer can decide
 when it should map the buffer itself independently of getting the
 details of the buffer.)

 Such solution however also requires extending dma-mapping API to handle
 mapping and unmapping of such pfn arrays. The advantage of this approach
 is the fact that it will be completely new API, so it can be designed
 well from the beginning.

 As far as I'm aware, there was no big discussion of the dma_buf API -
 it's something that just appeared one day (I don't remember seeing it
 discussed.)  So, that may well be a good thing if it means we can get
 these kinds of details better hammered out.

 However, I don't share your view of completely new API - that would
 be far too disruptive.  I think we can modify the existing API, to
 achieve our goals.

 I don't think changing the dma-mapping API just for this case is really
 on though - if we're passed a list of PFNs, they either must be all
 associated with a struct page - iow, pfn_valid(pfn) returns true for
 all of them or none of them.  If none of them, then we need to be able
 to convert those PFNs to a dma_addr_t for the target device (yes, that
 may need the dma-mapping API augmenting.)

 However, if they are associated with a struct page, then we should use
 the established APIs and use a scatterlist, otherwise we're looking
 at rewriting all IOMMUs and all DMA mapping implementations to handle
 what would become a special case for dma_buf.

 I'd rather... Keep It Simple.

+1 for Keep it simple, and the idea overall. Though I suspect more
dma-buf users (dri / v4l friends?) should comment if this doesn't help
solve things on some platforms / subsystems that they care about.

 So, maybe, as a first step, let's augment dma_buf with a pair of
 functions which get the raw unmapped scatterlist:

 struct sg_table *dma_buf_get_scatterlist(struct dma_buf_attachment *attach)
 {
   

DVBv5 qos/stats driver implementation

2015-05-05 Thread Jemma Denson

Mauro/Antti,

Myself and Patrick are currently in the process of bringing an old out 
of tree frontend driver into shape for inclusion, and one of the issues 
raised by Mauro was the requirement for the new DVBv5 stats method. I've 
noticed there seems to be two different ways of going around this - one 
is to run through the collection and cache filling process during the 
calls to read_status (as in dib7000p/dib8000p), and the other is to poll 
independently every couple of seconds via schedule_delayed_work (as in 
af9033, rtl2830/2832).


Is there any reason for the two different ways - is it just a coding 
preference or is there some specifics to how these frontends need to be 
implemented?


Thanks,

Jemma.


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


[PATCH 10/27] [media] wl128x: Allow compile test of GPIO consumers if !GPIOLIB

2015-05-05 Thread Geert Uytterhoeven
The GPIO subsystem provides dummy GPIO consumer functions if GPIOLIB is
not enabled. Hence drivers that depend on GPIOLIB, but use GPIO consumer
functionality only, can still be compiled if GPIOLIB is not enabled.

Relax the dependency on GPIOLIB if COMPILE_TEST is enabled, where
appropriate.

Signed-off-by: Geert Uytterhoeven ge...@linux-m68k.org
Cc: Mauro Carvalho Chehab mche...@osg.samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/radio/wl128x/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/radio/wl128x/Kconfig 
b/drivers/media/radio/wl128x/Kconfig
index 9d6574bebf78b4f6..c9e349b169c44c07 100644
--- a/drivers/media/radio/wl128x/Kconfig
+++ b/drivers/media/radio/wl128x/Kconfig
@@ -4,8 +4,8 @@
 menu Texas Instruments WL128x FM driver (ST based)
 config RADIO_WL128X
tristate Texas Instruments WL128x FM Radio
-   depends on VIDEO_V4L2  RFKILL  GPIOLIB  TTY
-   depends on TI_ST
+   depends on VIDEO_V4L2  RFKILL  TTY  TI_ST
+   depends on GPIOLIB || COMPILE_TEST
help
Choose Y here if you have this FM radio chip.
 
-- 
1.9.1

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


[PATCH 1/4] dw2102: remove unnecessary printing of MAC address

2015-05-05 Thread Olli Salonen
While reading the MAC address for SU3000-based devices the system was
printing excessive debug information in the logs:

Output before the patch:

[ 1515.780692] bc 00 00 00 00 00
[ 1515.781440] bc ea 00 00 00 00
[ 1515.782251] bc ea 2b 00 00 00
[ 1515.783094] bc ea 2b 46 00 00
[ 1515.783816] bc ea 2b 46 12 00
[ 1515.784565] bc ea 2b 46 12 92
[ 1515.784571] dvb-usb: MAC address: bc:ea:2b:46:12:92

Output after the patch:

[ 3803.495706] dvb-usb: MAC address: bc:ea:2b:46:12:92

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/dw2102.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 28fd6ba..4ad6bb2 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -928,8 +928,6 @@ static int su3000_read_mac_address(struct dvb_usb_device 
*d, u8 mac[6])
break;
else
mac[i] = ibuf[0];
-
-   debug_dump(mac, 6, printk);
}
 
return 0;
-- 
1.9.1

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


[PATCH 2/4] dw2102: remove unnecessary newline from log printouts

2015-05-05 Thread Olli Salonen
The info and warn functions already add a newline to the end of the
log printouts, so remove the extra newline from the printouts.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/dw2102.c | 60 +++---
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 4ad6bb2..b1f8a3f 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -307,7 +307,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
*adap, struct i2c_msg ms
u8 ibuf[MAX_XFER_SIZE], obuf[3];
 
if (2 + msg[1].len  sizeof(ibuf)) {
-   warn(i2c rd: len=%d is too big!\n,
+   warn(i2c rd: len=%d is too big!,
 msg[1].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -332,7 +332,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
*adap, struct i2c_msg ms
u8 obuf[MAX_XFER_SIZE];
 
if (2 + msg[0].len  sizeof(obuf)) {
-   warn(i2c wr: len=%d is too big!\n,
+   warn(i2c wr: len=%d is too big!,
 msg[1].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -350,7 +350,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
*adap, struct i2c_msg ms
u8 obuf[MAX_XFER_SIZE];
 
if (2 + msg[0].len  sizeof(obuf)) {
-   warn(i2c wr: len=%d is too big!\n,
+   warn(i2c wr: len=%d is too big!,
 msg[1].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -426,7 +426,7 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[], i
u8  ibuf[MAX_XFER_SIZE];
 
if (2 + msg[j].len  sizeof(ibuf)) {
-   warn(i2c rd: len=%d is too big!\n,
+   warn(i2c rd: len=%d is too big!,
 msg[j].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -463,7 +463,7 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[], i
u8 obuf[MAX_XFER_SIZE];
 
if (2 + msg[j].len  sizeof(obuf)) {
-   warn(i2c wr: len=%d is too big!\n,
+   warn(i2c wr: len=%d is too big!,
 msg[j].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -507,7 +507,7 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
u8 ibuf[MAX_XFER_SIZE], obuf[3];
 
if (2 + msg[1].len  sizeof(ibuf)) {
-   warn(i2c rd: len=%d is too big!\n,
+   warn(i2c rd: len=%d is too big!,
 msg[1].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -532,7 +532,7 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
u8 obuf[MAX_XFER_SIZE];
 
if (2 + msg[0].len  sizeof(obuf)) {
-   warn(i2c wr: len=%d is too big!\n,
+   warn(i2c wr: len=%d is too big!,
 msg[0].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -623,7 +623,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
u8 ibuf[MAX_XFER_SIZE];
 
if (msg[j].len  sizeof(ibuf)) {
-   warn(i2c rd: len=%d is too big!\n,
+   warn(i2c rd: len=%d is too big!,
 msg[j].len);
ret = -EOPNOTSUPP;
goto unlock;
@@ -658,7 +658,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
u8 obuf[MAX_XFER_SIZE];
 
if (2 + msg[j].len  sizeof(obuf)) {
-   warn(i2c wr: len=%d is too big!\n,
+   warn(i2c wr: len=%d is too big!,
 msg[j].len);
ret = -EOPNOTSUPP;
 

[PATCH 4/4] dw2102: resync fifo when demod locks

2015-05-05 Thread Olli Salonen
If the streaming_ctrl is called to enable TS before demod has locked
the TS will be empty. Copied the solution from the dvbsky driver for the
TechnoTrend S2-4600 device: when the state changes from unlock to
lock, call su3000_streaming_ctrl again.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/dw2102.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 7552521..f9ad57f 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -117,8 +117,13 @@
 
 struct dw2102_state {
u8 initialized;
+   u8 last_lock;
struct i2c_client *i2c_client_tuner;
+
+   /* fe hook functions*/
int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
+   int (*fe_read_status)(struct dvb_frontend *fe,
+   fe_status_t *status);
 };
 
 /* debug */
@@ -1001,6 +1006,23 @@ static void dw210x_led_ctrl(struct dvb_frontend *fe, int 
offon)
i2c_transfer(udev_adap-dev-i2c_adap, msg, 1);
 }
 
+static int tt_s2_4600_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+   struct dvb_usb_adapter *d =
+   (struct dvb_usb_adapter *)(fe-dvb-priv);
+   struct dw2102_state *st = (struct dw2102_state *)d-dev-priv;
+   int ret;
+
+   ret = st-fe_read_status(fe, status);
+
+   /* resync slave fifo when signal change from unlock to lock */
+   if ((*status  FE_HAS_LOCK)  (!st-last_lock))
+   su3000_streaming_ctrl(d, 1);
+
+   st-last_lock = (*status  FE_HAS_LOCK) ? 1 : 0;
+   return ret;
+}
+
 static struct stv0299_config sharp_z0194a_config = {
.demod_address = 0x68,
.inittab = sharp_z0194a_inittab,
@@ -1553,6 +1575,12 @@ static int tt_s2_4600_frontend_attach(struct 
dvb_usb_adapter *adap)
 
state-i2c_client_tuner = client;
 
+   /* hook fe: need to resync the slave fifo when signal locks */
+   state-fe_read_status = adap-fe_adap[0].fe-ops.read_status;
+   adap-fe_adap[0].fe-ops.read_status = tt_s2_4600_read_status;
+
+   state-last_lock = 0;
+
return 0;
 }
 
-- 
1.9.1

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


[PATCH 3/4] dw2102: debugging improvements

2015-05-05 Thread Olli Salonen
Move some info printouts to be debugging printouts that are only shown
if debugging for the module is enabled. The module already implemented
deb_rc and deb_xfer, but not deb_info.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/dw2102.c | 6 --
 drivers/media/usb/dvb-usb/dw2102.h | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index b1f8a3f..7552521 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -881,6 +881,8 @@ static int su3000_streaming_ctrl(struct dvb_usb_adapter 
*adap, int onoff)
.len = 1
};
 
+   deb_info(%s: onoff: %d\n, __func__, onoff);
+
i2c_transfer(adap-dev-i2c_adap, msg, 1);
 
return 0;
@@ -891,7 +893,7 @@ static int su3000_power_ctrl(struct dvb_usb_device *d, int 
i)
struct dw2102_state *state = (struct dw2102_state *)d-priv;
u8 obuf[] = {0xde, 0};
 
-   info(%s: %d, initialized %d, __func__, i, state-initialized);
+   deb_info(%s: %d, initialized %d\n, __func__, i, state-initialized);
 
if (i  !state-initialized) {
state-initialized = 1;
@@ -938,7 +940,7 @@ static int su3000_identify_state(struct usb_device *udev,
 struct dvb_usb_device_description **desc,
 int *cold)
 {
-   info(%s, __func__);
+   deb_info(%s\n, __func__);
 
*cold = 0;
return 0;
diff --git a/drivers/media/usb/dvb-usb/dw2102.h 
b/drivers/media/usb/dvb-usb/dw2102.h
index 5cd0b0e..1602368 100644
--- a/drivers/media/usb/dvb-usb/dw2102.h
+++ b/drivers/media/usb/dvb-usb/dw2102.h
@@ -4,6 +4,7 @@
 #define DVB_USB_LOG_PREFIX dw2102
 #include dvb-usb.h
 
+#define deb_info(args...) dprintk(dvb_usb_dw2102_debug, 0x01, args)
 #define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args)
 #define deb_rc(args...)   dprintk(dvb_usb_dw2102_debug, 0x04, args)
 #endif
-- 
1.9.1

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


Re: [RFC] How implement Secure Data Path ?

2015-05-05 Thread Christoph Hellwig
On Tue, May 05, 2015 at 05:39:57PM +0200, Benjamin Gaignard wrote:
 Since few months I'm looking for Linaro to how do Secure Data Path (SPD).
 I have tried and implemented multiple thinks but I always facing architecture
 issues so I would like to get your help to solve the problem.
 
 First what is Secure Data Path ? SDP is a set of hardware features to garanty
 that some memories regions could only be read and/or write by specific 
 hardware
 IPs. You can imagine it as a kind of memory firewall which grant/revoke
 accesses to memory per devices. Firewall configuration must be done in a 
 trusted
 environment: for ARM architecture we plan to use OP-TEE + a trusted
 application to do that.
 
 One typical use case for SDP in a video playback which involve those elements:
 decrypt - video decoder - transform - display

Sounds like a good enough reason not to implement it ever.
--
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 0/6] GoTView MasterHD 3 USB tuner

2015-05-05 Thread Olli Salonen
Fourth version of this patch series as there had been new si2157 devices 
that were added to the media_tree since the last submission. The 
si2157-patch in this series now takes care of those devices as well.

Olli Salonen (6):
  si2168: add support for gapped clock
  dvbsky: use si2168 config option ts_clock_gapped
  si2168: add I2C error handling
  si2157: support selection of IF interface
  rtl28xxu: add I2C read without write
  rtl2832: add support for GoTView MasterHD 3 USB tuner

 drivers/media/dvb-frontends/rtl2832.c  |   4 +
 drivers/media/dvb-frontends/rtl2832.h  |   1 +
 drivers/media/dvb-frontends/rtl2832_priv.h |  25 ++
 drivers/media/dvb-frontends/si2168.c   |   9 +++
 drivers/media/dvb-frontends/si2168.h   |   3 +
 drivers/media/dvb-frontends/si2168_priv.h  |   1 +
 drivers/media/pci/cx23885/cx23885-dvb.c|   4 +
 drivers/media/pci/saa7164/saa7164-dvb.c|   3 +
 drivers/media/pci/smipcie/smipcie.c|   1 +
 drivers/media/tuners/si2157.c  |   4 +-
 drivers/media/tuners/si2157.h  |   6 ++
 drivers/media/tuners/si2157_priv.h |   1 +
 drivers/media/usb/cx231xx/cx231xx-dvb.c|   2 +
 drivers/media/usb/dvb-usb-v2/af9035.c  |   1 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c  |   5 +-
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c| 125 -
 drivers/media/usb/dvb-usb-v2/rtl28xxu.h|   5 ++
 drivers/media/usb/dvb-usb/cxusb.c  |   1 +
 drivers/media/usb/em28xx/em28xx-dvb.c  |   2 +
 19 files changed, 197 insertions(+), 6 deletions(-)

-- 
1.9.1

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


[PATCH v4 1/6] si2168: add support for gapped clock

2015-05-05 Thread Olli Salonen
Add a parameter in si2168_config to support gapped clock. This might be 
necessary on some devices with higher bitrates.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c  | 3 +++
 drivers/media/dvb-frontends/si2168.h  | 3 +++
 drivers/media/dvb-frontends/si2168_priv.h | 1 +
 3 files changed, 7 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 5db588e..29a5936 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -508,6 +508,8 @@ static int si2168_init(struct dvb_frontend *fe)
/* set ts mode */
memcpy(cmd.args, \x14\x00\x01\x10\x10\x00, 6);
cmd.args[4] |= dev-ts_mode;
+   if (dev-ts_clock_gapped)
+   cmd.args[4] |= 0x40;
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2168_cmd_execute(client, cmd);
@@ -688,6 +690,7 @@ static int si2168_probe(struct i2c_client *client,
*config-fe = dev-fe;
dev-ts_mode = config-ts_mode;
dev-ts_clock_inv = config-ts_clock_inv;
+   dev-ts_clock_gapped = config-ts_clock_gapped;
dev-fw_loaded = false;
 
i2c_set_clientdata(client, dev);
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index 70d702a..3225d0c 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -42,6 +42,9 @@ struct si2168_config {
 
/* TS clock inverted */
bool ts_clock_inv;
+
+   /* TS clock gapped */
+   bool ts_clock_gapped;
 };
 
 #endif
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index d7efce8..d2589e3 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -38,6 +38,7 @@ struct si2168_dev {
bool fw_loaded;
u8 ts_mode;
bool ts_clock_inv;
+   bool ts_clock_gapped;
 };
 
 /* firmware command struct */
-- 
1.9.1

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


[PATCH v4 2/6] dvbsky: use si2168 config option ts_clock_gapped

2015-05-05 Thread Olli Salonen
Change the dvbsky driver to support gapped clock instead of the current
hack.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index cdf59bc..0f73b1d 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -615,7 +615,8 @@ static int dvbsky_t330_attach(struct dvb_usb_adapter *adap)
memset(si2168_config, 0, sizeof(si2168_config));
si2168_config.i2c_adapter = i2c_adapter;
si2168_config.fe = adap-fe[0];
-   si2168_config.ts_mode = SI2168_TS_PARALLEL | 0x40;
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
+   si2168_config.ts_clock_gapped = true;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2168, I2C_NAME_SIZE);
info.addr = 0x64;
-- 
1.9.1

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


[PATCH v4 4/6] si2157: support selection of IF interface

2015-05-05 Thread Olli Salonen
The chips supported by the si2157 driver have two IF outputs (either
pins 12+13 or pins 9+11). Instead of hardcoding the output to be used
add an option to choose which output shall be used.

As this patch changes the default behaviour, the IF interface is
specified in each driver currently using si2157 driver. This is to
keep bisectability.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 4 
 drivers/media/pci/saa7164/saa7164-dvb.c | 3 +++
 drivers/media/pci/smipcie/smipcie.c | 1 +
 drivers/media/tuners/si2157.c   | 4 +++-
 drivers/media/tuners/si2157.h   | 6 ++
 drivers/media/tuners/si2157_priv.h  | 1 +
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 2 ++
 drivers/media/usb/dvb-usb-v2/af9035.c   | 1 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c   | 2 ++
 drivers/media/usb/dvb-usb/cxusb.c   | 1 +
 drivers/media/usb/em28xx/em28xx-dvb.c   | 2 ++
 11 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index 745caab..37fd013 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -1912,6 +1912,7 @@ static int dvb_register(struct cx23885_tsport *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = fe0-dvb.frontend;
+   si2157_config.if_port = 1;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
info.addr = 0x60;
@@ -1957,6 +1958,7 @@ static int dvb_register(struct cx23885_tsport *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = fe0-dvb.frontend;
+   si2157_config.if_port = 1;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
info.addr = 0x60;
@@ -2093,6 +2095,7 @@ static int dvb_register(struct cx23885_tsport *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = fe0-dvb.frontend;
+   si2157_config.if_port = 1;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
info.addr = 0x60;
@@ -2172,6 +2175,7 @@ static int dvb_register(struct cx23885_tsport *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = fe0-dvb.frontend;
+   si2157_config.if_port = 1;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
info.addr = 0x60;
diff --git a/drivers/media/pci/saa7164/saa7164-dvb.c 
b/drivers/media/pci/saa7164/saa7164-dvb.c
index 9969800..e9a783b 100644
--- a/drivers/media/pci/saa7164/saa7164-dvb.c
+++ b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -111,6 +111,7 @@ static struct lgdt3306a_config hauppauge_hvr2255b_config = {
 
 static struct si2157_config hauppauge_hvr2255_tuner_config = {
.inversion = 1,
+   .if_port = 1,
 };
 
 static int si2157_attach(struct saa7164_port *port, struct i2c_adapter 
*adapter,
@@ -665,6 +666,7 @@ int saa7164_dvb_register(struct saa7164_port *port)
 
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
+   si2157_config.if_port = 1;
si2157_config.fe = port-dvb.frontend;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
@@ -710,6 +712,7 @@ int saa7164_dvb_register(struct saa7164_port *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = port-dvb.frontend;
+   si2157_config.if_port = 1;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2157, I2C_NAME_SIZE);
info.addr = 0xc0  1;
diff --git a/drivers/media/pci/smipcie/smipcie.c 
b/drivers/media/pci/smipcie/smipcie.c
index 4115925..143fd78 100644
--- a/drivers/media/pci/smipcie/smipcie.c
+++ b/drivers/media/pci/smipcie/smipcie.c
@@ -657,6 +657,7 @@ static int smi_dvbsky_sit2_fe_attach(struct smi_port *port)
/* attach tuner */
memset(si2157_config, 0, sizeof(si2157_config));
si2157_config.fe = port-fe;
+   si2157_config.if_port = 1;
 
memset(client_info, 0, sizeof(struct i2c_board_info));
strlcpy(client_info.type, si2157, 

[PATCH v4 5/6] rtl28xxu: add I2C read without write

2015-05-05 Thread Olli Salonen
Add support for I2C read operation without a preceeding write.

While here, change the error code to EOPNOTSUPP in case an
unsupported I2C operation is attempted.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 895441f..54cb109 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -232,8 +232,14 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
req.data = msg[0].buf;
ret = rtl28xxu_ctrl_msg(d, req);
}
+   } else if (num == 1  (msg[0].flags  I2C_M_RD)) {
+   req.value = (msg[0].addr  1);
+   req.index = CMD_I2C_DA_RD;
+   req.size = msg[0].len;
+   req.data = msg[0].buf;
+   ret = rtl28xxu_ctrl_msg(d, req);
} else {
-   ret = -EINVAL;
+   ret = -EOPNOTSUPP;
}
 
 err_mutex_unlock:
-- 
1.9.1

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


[PATCH v4 6/6] rtl2832: add support for GoTView MasterHD 3 USB tuner

2015-05-05 Thread Olli Salonen
GoTView MasterHD 3 is a DVB-T2/C USB 2.0 tuner.

It's based on the following components:
- USB bridge: RTL2832P (contains also DVB-T demodulator)
- Demodulator: Si2168-A30
- Tuner: Si2148-A20

The demodulator and the tuner will need firmwares. The Si2148 uses Si2158
firmware. Antti has the firmwares available for download:
http://palosaari.fi/linux/v4l-dvb/firmware/

Do note that for DVB-T either of the demodulators can be used. DVB-C and
DVB-T2 are only supported by the Si2168 demodulator. The driver will
register 2 frontends for the same adapter. Frontend 0 will be the RTL2832
demodulator and frontend 1 will be the Si2168 demodulator. The same
tuner is used for both.

As a consequence of the above, it's recommended to use application that
does implement proper DVBv5 support.

For some reason, the old I2C write method sporadically fails. Thus the
need for an option to only use the new I2C write method supported by the
RTL2832.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/rtl2832.c  |   4 +
 drivers/media/dvb-frontends/rtl2832.h  |   1 +
 drivers/media/dvb-frontends/rtl2832_priv.h |  25 ++
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c| 117 -
 drivers/media/usb/dvb-usb-v2/rtl28xxu.h|   5 ++
 5 files changed, 149 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c 
b/drivers/media/dvb-frontends/rtl2832.c
index b400f7b..55a8b1f 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -376,6 +376,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
len = ARRAY_SIZE(rtl2832_tuner_init_r820t);
init = rtl2832_tuner_init_r820t;
break;
+   case RTL2832_TUNER_SI2157:
+   len = ARRAY_SIZE(rtl2832_tuner_init_si2157);
+   init = rtl2832_tuner_init_si2157;
+   break;
default:
ret = -EINVAL;
goto err;
diff --git a/drivers/media/dvb-frontends/rtl2832.h 
b/drivers/media/dvb-frontends/rtl2832.h
index a8e912e..c6cdcc4 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -47,6 +47,7 @@ struct rtl2832_platform_data {
 #define RTL2832_TUNER_FC00130x29
 #define RTL2832_TUNER_R820T 0x2a
 #define RTL2832_TUNER_R828D 0x2b
+#define RTL2832_TUNER_SI21570x2c
u8 tuner;
 
struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h 
b/drivers/media/dvb-frontends/rtl2832_priv.h
index c3a922c..a973b8a 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -377,4 +377,29 @@ static const struct rtl2832_reg_value 
rtl2832_tuner_init_r820t[] = {
{DVBT_SPEC_INV,  0x1},
 };
 
+static const struct rtl2832_reg_value rtl2832_tuner_init_si2157[] = {
+   {DVBT_DAGC_TRG_VAL, 0x39},
+   {DVBT_AGC_TARG_VAL_0,0x0},
+   {DVBT_AGC_TARG_VAL_8_1, 0x40},
+   {DVBT_AAGC_LOOP_GAIN,   0x16},
+   {DVBT_LOOP_GAIN2_3_0,0x8},
+   {DVBT_LOOP_GAIN2_4,  0x1},
+   {DVBT_LOOP_GAIN3,   0x18},
+   {DVBT_VTOP1,0x35},
+   {DVBT_VTOP2,0x21},
+   {DVBT_VTOP3,0x21},
+   {DVBT_KRF1,  0x0},
+   {DVBT_KRF2, 0x40},
+   {DVBT_KRF3, 0x10},
+   {DVBT_KRF4, 0x10},
+   {DVBT_IF_AGC_MIN,   0x80},
+   {DVBT_IF_AGC_MAX,   0x7f},
+   {DVBT_RF_AGC_MIN,   0x80},
+   {DVBT_RF_AGC_MAX,   0x7f},
+   {DVBT_POLAR_RF_AGC,  0x0},
+   {DVBT_POLAR_IF_AGC,  0x0},
+   {DVBT_AD7_SETTING,0xe9f4},
+   {DVBT_SPEC_INV,  0x0},
+};
+
 #endif /* RTL2832_PRIV_H */
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 54cb109..616be99 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -217,7 +217,7 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, 
struct i2c_msg msg[],
req.data = msg[0].buf[1];
ret = rtl28xxu_ctrl_msg(d, req);
}
-   } else if (msg[0].len  23) {
+   } else if ((msg[0].len  23)  (!dev-new_i2c_write)) {
/* method 2 - old I2C */
req.value = (msg[0].buf[0]  8) | (msg[0].addr  1);
req.index = CMD_I2C_WR;
@@ -363,6 +363,8 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
struct 

Re: [RFC] How implement Secure Data Path ?

2015-05-05 Thread One Thousand Gnomes
 First what is Secure Data Path ? SDP is a set of hardware features to garanty
 that some memories regions could only be read and/or write by specific 
 hardware
 IPs. You can imagine it as a kind of memory firewall which grant/revoke
 accesses to memory per devices. Firewall configuration must be done in a 
 trusted
 environment: for ARM architecture we plan to use OP-TEE + a trusted
 application to do that.

It's not just an ARM feature so any basis for this in the core code
should be generic, whether its being enforced by ARM SDP, various Intel
feature sets or even via a hypervisor.

 I have try 2 hacky approachs with dma_buf:
 - add a secure field in dma_buf structure and configure firewall in
   dma_buf_{map/unmap}_attachment() functions.

How is SDP not just another IOMMU. The only oddity here is that it
happens to configure buffers the CPU can't touch and it has a control
mechanism that is designed to cover big media corp type uses where the
threat model is that the system owner is the enemy. Why does anything care
about it being SDP, there are also generic cases this might be a useful
optimisation (eg knowing the buffer isn't CPU touched so you can optimise
cache flushing).

The control mechanism is a device/platform detail as with any IOMMU. It
doesn't matter who configures it or how, providing it happens.

We do presumably need some small core DMA changes - anyone trying to map
such a buffer into CPU space needs to get a warning or error but what
else ?

 From buffer allocation point of view I also facing a problem because when 
 v4l2
 or drm/kms are exporting buffers by using dma_buf they don't attaching
 themself on it and never call dma_buf_{map/unmap}_attachment(). This is not
 an issue in those framework while it is how dma_buf exporters are
 supposed to work.

Which could be addressed if need be.

So if SDP is just another IOMMU feature, just as stuff like IMR is on
some x86 devices, and hypervisor enforced protection is on assorted
platforms why do we need a special way to do it ? Is there anything
actually needed beyond being able to tell the existing DMA code that this
buffer won't be CPU touched and wiring it into the DMA operations for the
platform ?

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


[PATCH v4 3/6] si2168: add I2C error handling

2015-05-05 Thread Olli Salonen
Return error from si2168_cmd_execute in case the demodulator returns an 
error.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 29a5936..b68ab34 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -60,6 +60,12 @@ static int si2168_cmd_execute(struct i2c_client *client, 
struct si2168_cmd *cmd)
jiffies_to_msecs(jiffies) -
(jiffies_to_msecs(timeout) - TIMEOUT));
 
+   /* error bit set? */
+   if ((cmd-args[0]  6)  0x01) {
+   ret = -EREMOTEIO;
+   goto err_mutex_unlock;
+   }
+
if (!((cmd-args[0]  7)  0x01)) {
ret = -ETIMEDOUT;
goto err_mutex_unlock;
-- 
1.9.1

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


Re: [PATCH 3/4] Wrap LFS64 functions only if __GLIBC__

2015-05-05 Thread Gregor Jasny
On 05/05/15 14:34, Mauro Carvalho Chehab wrote:
 Em Sun, 25 Jan 2015 21:36:36 +0100
 Felix Janda felix.ja...@posteo.de escreveu:
 -#ifdef linux
 +#ifdef __GLIBC__
 
 Hmm... linux was added here to avoid breaking on FreeBSD, on this
 changeset:
 
 So, either we should get an ack from Hans Peter, or you should
 change the tests to:
 
   #if linux  __GLIBC__

That would be needed to not break Debian/kFreeBSD which is a FreeBSD
Kernel with GNU C library.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv2 1/4] Use off_t and off64_t instead of __off_t and __off64_t

2015-05-05 Thread Felix Janda
Since _LARGEFILE64_SOURCE is 1, these types coincide if defined.

Signed-off-by: Felix Janda felix.ja...@posteo.de
---
v2: rebased

Mauro Carvalho Chehab wrote:

Thanks for the review.

 Em Sun, 25 Jan 2015 21:36:15 +0100
 Felix Janda felix.ja...@posteo.de escreveu:
 
  Since _LARGEFILE64_SOURCE is 1, these types coincide if defined.
 
 The __off_t macro was also added by the FreeBSD patchset. Removing this
 will likely break for FreeBSD.

No. The patchset added a typedef of __off_t to off_t. Why? Because
FreeBSD does not have off_t. By now for a similar reason there is a
similar typedef for android. Generally, names starting with one or two
underscores are implementation specific and not portable. If the source
code did not use __off_t, there would be no need to introduce these
typedefs.

This patch removes all occurences of __off_t and __off64_t in the
source code. 

 So, provided that this is not causing any issues, better to keep it
 as-is.

It produces error: unknown type name '__off_t' on musl based linux
systems.

---
 lib/libv4l1/v4l1compat.c   |  5 ++---
 lib/libv4l2/v4l2convert.c  |  5 ++---
 lib/libv4lconvert/libv4lsyscall-priv.h | 11 +++
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
index c641c17..282173b 100644
--- a/lib/libv4l1/v4l1compat.c
+++ b/lib/libv4l1/v4l1compat.c
@@ -116,14 +116,14 @@ LIBV4L_PUBLIC ssize_t read(int fd, void *buffer, size_t n)
 }
 
 LIBV4L_PUBLIC void *mmap(void *start, size_t length, int prot, int flags, int 
fd,
-   __off_t offset)
+   off_t offset)
 {
return v4l1_mmap(start, length, prot, flags, fd, offset);
 }
 
 #ifdef linux
 LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
int fd,
-   __off64_t offset)
+   off64_t offset)
 {
return v4l1_mmap(start, length, prot, flags, fd, offset);
 }
diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
index 008408e..2c2f12a 100644
@@ -148,14 +148,14 @@ LIBV4L_PUBLIC ssize_t read(int fd, void *buffer, size_t n)
 }
 
 LIBV4L_PUBLIC void *mmap(void *start, size_t length, int prot, int flags, int 
fd,
-   __off_t offset)
+   off_t offset)
 {
return v4l2_mmap(start, length, prot, flags, fd, offset);
 }
 
 #ifdef linux
 LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
int fd,
-   __off64_t offset)
+   off64_t offset)
 {
return v4l2_mmap(start, length, prot, flags, fd, offset);
 }
diff --git a/lib/libv4lconvert/libv4lsyscall-priv.h 
b/lib/libv4lconvert/libv4lsyscall-priv.h
index f548fb2..f87eff4 100644
--- a/lib/libv4lconvert/libv4lsyscall-priv.h
+++ b/lib/libv4lconvert/libv4lsyscall-priv.h
@@ -59,11 +59,6 @@
 #define_IOC_SIZE(cmd) IOCPARM_LEN(cmd)
 #defineMAP_ANONYMOUS MAP_ANON
 #defineMMAP2_PAGE_SHIFT 0
-typedef off_t __off_t;
-#endif
-
-#if defined(ANDROID)
-typedef off_t __off_t;
 #endif
 
 #undef SYS_OPEN
@@ -95,15 +90,15 @@ typedef off_t __off_t;
 #if defined(__FreeBSD__)
 #define SYS_MMAP(addr, len, prot, flags, fd, off) \
__syscall(SYS_mmap, (void *)(addr), (size_t)(len), \
-   (int)(prot), (int)(flags), (int)(fd), (__off_t)(off))
+   (int)(prot), (int)(flags), (int)(fd), (off_t)(off))
 #elif defined(__FreeBSD_kernel__)
 #define SYS_MMAP(addr, len, prot, flags, fd, off) \
syscall(SYS_mmap, (void *)(addr), (size_t)(len), \
-   (int)(prot), (int)(flags), (int)(fd), (__off_t)(off))
+   (int)(prot), (int)(flags), (int)(fd), (off_t)(off))
 #else
 #define SYS_MMAP(addr, len, prot, flags, fd, off) \
syscall(SYS_mmap2, (void *)(addr), (size_t)(len), \
-   (int)(prot), (int)(flags), (int)(fd), (__off_t)((off) 
 MMAP2_PAGE_SHIFT))
+   (int)(prot), (int)(flags), (int)(fd), (off_t)((off)  
MMAP2_PAGE_SHIFT))
 #endif
 
 #define SYS_MUNMAP(addr, len) \
-- 
2.3.6
--
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 2/4] Test for ioctl() function signature

2015-05-05 Thread Felix Janda
On glibc, ioctl has the signature ioctl(int, unsigned long int, ...).
On musl, libc and according to POSIX it is ioctl(int, int, ...).
Add a configure test adapted from gnulib's ioctl.m4 to make the
DL_PRELOAD libraries work for both signatures.

Signed-off-by: Felix Janda felix.ja...@posteo.de
---
v2: Fix declaration of HAVE_POSIX_IOCTL

Mauro Carvalho Chehab wrote:
 Em Sun, 25 Jan 2015 21:36:25 +0100
 Felix Janda felix.ja...@posteo.de escreveu:
 
  On glibc, ioctl has the signature ioctl(int, unsigned long int, ...).
  On musl, libc and according to POSIX it is ioctl(int, int, ...).
  Add a configure test adapted from gnulib's ioctl.m4 to make the
  DL_PRELOAD libraries work for both signatures.
 
 
 This patch breaks compilation on Fedora:
 
 v4l2convert.c:130:45: error: conflicting types for 'ioctl'
  LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
  ^
 In file included from v4l2convert.c:37:0:
 /usr/include/sys/ioctl.h:41:12: note: previous declaration of 'ioctl' was here
  extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
 ^

Sorry for the bad patch.
./configure will have correctly identified in your case that ioctl does
not have the POSIX signature, but by my mistake it still put

#define HAVE_POSIX_IOCTL 1

into config.h. Should be fixed with this patch.

---
 configure.ac  | 14 ++
 lib/libv4l1/v4l1compat.c  |  4 
 lib/libv4l2/v4l2convert.c |  4 
 3 files changed, 22 insertions(+)

diff --git a/configure.ac b/configure.ac
index 330479c..79c1cfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,6 +118,20 @@ gl_VISIBILITY
 AC_CHECK_HEADERS([sys/klog.h])
 AC_CHECK_FUNCS([klogctl])
 
+AC_CACHE_CHECK([for ioctl with POSIX signature],
+  [gl_cv_func_ioctl_posix_signature],
+  [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+[[#include sys/ioctl.h]],
+[[int ioctl (int, int, ...);]])
+ ],
+ [gl_cv_func_ioctl_posix_signature=yes],
+ [gl_cv_func_ioctl_posix_signature=no])
+  ])
+if test x$gl_cv_func_ioctl_posix_signature = xyes; then
+  AC_DEFINE([HAVE_POSIX_IOCTL], [1], [Have ioctl with POSIX signature])
+fi
+
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
 
 # Check host os
diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
index e328288..c641c17 100644
--- a/lib/libv4l1/v4l1compat.c
+++ b/lib/libv4l1/v4l1compat.c
@@ -94,7 +94,11 @@ LIBV4L_PUBLIC int dup(int fd)
return v4l1_dup(fd);
 }
 
+#ifdef HAVE_POSIX_IOCTL
+LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
+#else
 LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...)
+#endif
 {
void *arg;
va_list ap;
diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
index d046834..008408e 100644
--- a/lib/libv4l2/v4l2convert.c
+++ b/lib/libv4l2/v4l2convert.c
@@ -126,7 +126,11 @@ LIBV4L_PUBLIC int dup(int fd)
return v4l2_dup(fd);
 }
 
+#ifdef HAVE_POSIX_IOCTL
+LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
+#else
 LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...)
+#endif
 {
void *arg;
va_list ap;
-- 
2.3.6
--
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 3/4] Wrap LFS64 functions only if linux __GLIBC__

2015-05-05 Thread Felix Janda
For musl libc, open64 is #define'd to open. Therefore we should not try
to wrap both open and open64.

Signed-off-by: Felix Janda felix.ja...@posteo.de
---
v2: Test for linux as well

Mauro Carvalho Chehab wrote:
[..]
 Hmm... linux was added here to avoid breaking on FreeBSD, on this
 changeset:
 
 commit 9026d3cc277e9211a89345846dea95af7208383c
 Author: hans@rhel5-devel.localdomain hans@rhel5-devel.localdomain
 Date:   Tue Jun 2 15:34:34 2009 +0200
 
 libv4l: initial support for compiling on FreeBSD
 
 From: Hans Petter Selasky hsela...@freebsd.org
 
 I'm afraid that removing the above would break for FreeBSD, as I think
 it also uses glibc, but not 100% sure.

Usually FreeBSD has its own libc (which does not define __GLIBC__).
However (as I've didn't know at the time) there is also kFreeBSD, which
has a FreeBSD kernel but still uses glibc.

 So, either we should get an ack from Hans Peter, or you should
 change the tests to:
 
   #if linux  __GLIBC__

I've changed them to

#if defined(linux)  defined(__GLIBC__)

Thanks for the review!

---
 lib/libv4l1/v4l1compat.c  | 4 ++--
 lib/libv4l2/v4l2convert.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/libv4l1/v4l1compat.c b/lib/libv4l1/v4l1compat.c
index 282173b..0d433c6 100644
--- a/lib/libv4l1/v4l1compat.c
+++ b/lib/libv4l1/v4l1compat.c
@@ -61,7 +61,7 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
return fd;
 }
 
-#ifdef linux
+#if defined(linux)  defined(__GLIBC__)
 LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
 {
int fd;
@@ -120,7 +120,7 @@ LIBV4L_PUBLIC void *mmap(void *start, size_t length, int 
prot, int flags, int fd
return v4l1_mmap(start, length, prot, flags, fd, offset);
 }
 
-#ifdef linux
+#if defined(linux)  defined(__GLIBC__)
 LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
int fd,
off64_t offset)
 {
diff --git a/lib/libv4l2/v4l2convert.c b/lib/libv4l2/v4l2convert.c
index 2c2f12a..6abccbf 100644
--- a/lib/libv4l2/v4l2convert.c
+++ b/lib/libv4l2/v4l2convert.c
@@ -89,7 +89,7 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
return fd;
 }
 
-#ifdef linux
+#if defined(linux)  defined(__GLIBC__)
 LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
 {
int fd;
@@ -152,7 +152,7 @@ LIBV4L_PUBLIC void *mmap(void *start, size_t length, int 
prot, int flags, int fd
return v4l2_mmap(start, length, prot, flags, fd, offset);
 }
 
-#ifdef linux
+#if defined(linux)  defined(__GLIBC__)
 LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, 
int fd,
off64_t offset)
 {
-- 
2.3.6

















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


Time for a v4l-utils 1.8.0 release

2015-05-05 Thread Gregor Jasny
Hello,

It's already more than half a year since the last v4l-utils release. Do
you have any pending commits or objections? If no one vetos I'd like to
release this weekend.

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


[GIT PULL for v4.1-rc3] media fixes

2015-05-05 Thread Mauro Carvalho Chehab
Hi Linus,

Please pull from:
  git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 
tags/media/v4.1-3


For 3 driver fixes:

- one fix for omap4, fixing a regression due to a subsystem API that
  got removed for 4.1 (commit efde234674d9);
- one fix for one of the formats supported by Marvel ccic driver;
- one fix on rcar_vin driver that, when stopping abnormally, the driver
  can't return from wait_for_completion.

Thanks!
Mauro

-

The following changes since commit 64131a87f2aae2ed9e05d8227c5b009ca6c50d98:

  Merge branch 'drm-next-merged' of git://people.freedesktop.org/~airlied/linux 
into v4l_for_linus (2015-04-21 09:44:55 -0300)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 
tags/media/v4.1-3

for you to fetch changes up to fefad2d54beb8aad6bf4ac6daeb74f86f52565de:

  [media] v4l: omap4iss: Replace outdated OMAP4 control pad API with syscon 
(2015-04-28 08:38:23 -0300)


media fixes for v4.1-rc3


Hans Verkuil (1):
  [media] marvell-ccic: fix Y'CbCr ordering

Koji Matsuoka (1):
  [media] media: soc_camera: rcar_vin: Fix wait_for_completion

Laurent Pinchart (1):
  [media] v4l: omap4iss: Replace outdated OMAP4 control pad API with syscon

 drivers/media/platform/marvell-ccic/mcam-core.c | 14 +++---
 drivers/media/platform/marvell-ccic/mcam-core.h |  8 
 drivers/media/platform/soc_camera/rcar_vin.c|  7 ++-
 drivers/staging/media/omap4iss/Kconfig  |  1 +
 drivers/staging/media/omap4iss/iss.c| 11 +++
 drivers/staging/media/omap4iss/iss.h|  4 
 drivers/staging/media/omap4iss/iss_csiphy.c | 12 +++-
 7 files changed, 40 insertions(+), 17 deletions(-)

--
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: Time for a v4l-utils 1.8.0 release

2015-05-05 Thread Mauro Carvalho Chehab
Em Tue, 05 May 2015 21:08:49 +0200
Gregor Jasny gja...@googlemail.com escreveu:

 Hello,
 
 It's already more than half a year since the last v4l-utils release. Do
 you have any pending commits or objections? If no one vetos I'd like to
 release this weekend.

There is are a additions I'd like to add to v4l-utils: 

1) on DVB, ioctls may fail with -EAGAIN. Some parts of the libdvbv5 don't
handle it well. I made one quick hack for it, but didn't have time to
add a timeout to avoid an endless loop. The patch is simple. I just need
some time to do that;

2) The Media Controller control util (media-ctl) doesn't support DVB.

The patchset adding DVB support on media-ctl is ready, and I'm merging
right now, and matches what's there at Kernel version 4.1-rc1 and upper.

Yet, Laurent and Sakari want to do some changes at the Kernel API, before
setting it into a stone at Kernel v 4.1 release.

This has to happen on the next 4 weeks.

So, I suggest to postpone the release of 1.8.0 until the end of this month.

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


[PATCH 9/9] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames()

2015-05-05 Thread Jan Kara
Convert g2d_userptr_get_dma_addr() to pin pages using get_vaddr_frames().
This removes the knowledge about vmas and mmap_sem locking from exynos
driver. Also it fixes a problem that the function has been mapping user
provided address without holding mmap_sem.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 91 ++-
 drivers/gpu/drm/exynos/exynos_drm_gem.c | 97 -
 2 files changed, 30 insertions(+), 158 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c 
b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 81a250830808..65eb38797fd3 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -190,10 +190,8 @@ struct g2d_cmdlist_userptr {
dma_addr_t  dma_addr;
unsigned long   userptr;
unsigned long   size;
-   struct page **pages;
-   unsigned intnpages;
+   struct frame_vector *vec;
struct sg_table *sgt;
-   struct vm_area_struct   *vma;
atomic_trefcount;
boolin_pool;
boolout_of_list;
@@ -363,6 +361,7 @@ static void g2d_userptr_put_dma_addr(struct drm_device 
*drm_dev,
 {
struct g2d_cmdlist_userptr *g2d_userptr =
(struct g2d_cmdlist_userptr *)obj;
+   struct page **pages;
 
if (!obj)
return;
@@ -382,19 +381,21 @@ out:
exynos_gem_unmap_sgt_from_dma(drm_dev, g2d_userptr-sgt,
DMA_BIDIRECTIONAL);
 
-   exynos_gem_put_pages_to_userptr(g2d_userptr-pages,
-   g2d_userptr-npages,
-   g2d_userptr-vma);
+   pages = frame_vector_pages(g2d_userptr-vec);
+   if (!IS_ERR(pages)) {
+   int i;
 
-   exynos_gem_put_vma(g2d_userptr-vma);
+   for (i = 0; i  frame_vector_count(g2d_userptr-vec); i++)
+   set_page_dirty_lock(pages[i]);
+   }
+   put_vaddr_frames(g2d_userptr-vec);
+   frame_vector_destroy(g2d_userptr-vec);
 
if (!g2d_userptr-out_of_list)
list_del_init(g2d_userptr-list);
 
sg_free_table(g2d_userptr-sgt);
kfree(g2d_userptr-sgt);
-
-   drm_free_large(g2d_userptr-pages);
kfree(g2d_userptr);
 }
 
@@ -413,6 +414,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
drm_device *drm_dev,
struct vm_area_struct *vma;
unsigned long start, end;
unsigned int npages, offset;
+   struct frame_vector *vec;
int ret;
 
if (!size) {
@@ -456,65 +458,37 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
drm_device *drm_dev,
return ERR_PTR(-ENOMEM);
 
atomic_set(g2d_userptr-refcount, 1);
+   g2d_userptr-size = size;
 
start = userptr  PAGE_MASK;
offset = userptr  ~PAGE_MASK;
end = PAGE_ALIGN(userptr + size);
npages = (end - start)  PAGE_SHIFT;
-   g2d_userptr-npages = npages;
+   vec = g2d_userptr-vec = frame_vector_create(npages);
+   if (!vec)
+   goto out_free;
 
-   pages = drm_calloc_large(npages, sizeof(struct page *));
-   if (!pages) {
-   DRM_ERROR(failed to allocate pages.\n);
-   ret = -ENOMEM;
-   goto err_free;
-   }
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, userptr);
-   if (!vma) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to get vm region.\n);
+   ret = get_vaddr_frames(start, npages, 1, 1, vec);
+   if (ret != npages) {
+   DRM_ERROR(failed to get user pages from userptr.\n);
+   if (ret  0)
+   goto err_destroy_framevec;
ret = -EFAULT;
-   goto err_free_pages;
+   goto err_put_framevec;
}
-
-   if (vma-vm_end  userptr + size) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(vma is too small.\n);
+   if (frame_vector_to_pages(vec)  0) {
ret = -EFAULT;
-   goto err_free_pages;
+   goto err_put_framevec;
}
 
-   g2d_userptr-vma = exynos_gem_get_vma(vma);
-   if (!g2d_userptr-vma) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to copy vma.\n);
-   ret = -ENOMEM;
-   goto err_free_pages;
-   }
-
-   g2d_userptr-size = size;
-
-   ret = exynos_gem_get_pages_from_userptr(start  PAGE_MASK,
-   npages, pages, vma);
-   if (ret  0) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to get user pages from userptr.\n);
-   goto err_put_vma;
-   }
-
-   

[PATCH 8/9] media: vb2: Remove unused functions

2015-05-05 Thread Jan Kara
Conversion to the use of pinned pfns made some functions unused. Remove
them. Also there's no need to lock mmap_sem in __buf_prepare() anymore.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-memops.c | 114 -
 include/media/videobuf2-memops.h   |   6 --
 2 files changed, 120 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
b/drivers/media/v4l2-core/videobuf2-memops.c
index 0ec186d41b9b..48c6a49c4928 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -23,120 +23,6 @@
 #include media/videobuf2-memops.h
 
 /**
- * vb2_get_vma() - acquire and lock the virtual memory area
- * @vma:   given virtual memory area
- *
- * This function attempts to acquire an area mapped in the userspace for
- * the duration of a hardware operation. The area is locked by performing
- * the same set of operation that are done when process calls fork() and
- * memory areas are duplicated.
- *
- * Returns a copy of a virtual memory region on success or NULL.
- */
-struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma)
-{
-   struct vm_area_struct *vma_copy;
-
-   vma_copy = kmalloc(sizeof(*vma_copy), GFP_KERNEL);
-   if (vma_copy == NULL)
-   return NULL;
-
-   if (vma-vm_ops  vma-vm_ops-open)
-   vma-vm_ops-open(vma);
-
-   if (vma-vm_file)
-   get_file(vma-vm_file);
-
-   memcpy(vma_copy, vma, sizeof(*vma));
-
-   vma_copy-vm_mm = NULL;
-   vma_copy-vm_next = NULL;
-   vma_copy-vm_prev = NULL;
-
-   return vma_copy;
-}
-EXPORT_SYMBOL_GPL(vb2_get_vma);
-
-/**
- * vb2_put_userptr() - release a userspace virtual memory area
- * @vma:   virtual memory region associated with the area to be released
- *
- * This function releases the previously acquired memory area after a hardware
- * operation.
- */
-void vb2_put_vma(struct vm_area_struct *vma)
-{
-   if (!vma)
-   return;
-
-   if (vma-vm_ops  vma-vm_ops-close)
-   vma-vm_ops-close(vma);
-
-   if (vma-vm_file)
-   fput(vma-vm_file);
-
-   kfree(vma);
-}
-EXPORT_SYMBOL_GPL(vb2_put_vma);
-
-/**
- * vb2_get_contig_userptr() - lock physically contiguous userspace mapped 
memory
- * @vaddr: starting virtual address of the area to be verified
- * @size:  size of the area
- * @res_paddr: will return physical address for the given vaddr
- * @res_vma:   will return locked copy of struct vm_area for the given area
- *
- * This function will go through memory area of size @size mapped at @vaddr and
- * verify that the underlying physical pages are contiguous. If they are
- * contiguous the virtual memory area is locked and a @res_vma is filled with
- * the copy and @res_pa set to the physical address of the buffer.
- *
- * Returns 0 on success.
- */
-int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
-  struct vm_area_struct **res_vma, dma_addr_t *res_pa)
-{
-   struct mm_struct *mm = current-mm;
-   struct vm_area_struct *vma;
-   unsigned long offset, start, end;
-   unsigned long this_pfn, prev_pfn;
-   dma_addr_t pa = 0;
-
-   start = vaddr;
-   offset = start  ~PAGE_MASK;
-   end = start + size;
-
-   vma = find_vma(mm, start);
-
-   if (vma == NULL || vma-vm_end  end)
-   return -EFAULT;
-
-   for (prev_pfn = 0; start  end; start += PAGE_SIZE) {
-   int ret = follow_pfn(vma, start, this_pfn);
-   if (ret)
-   return ret;
-
-   if (prev_pfn == 0)
-   pa = this_pfn  PAGE_SHIFT;
-   else if (this_pfn != prev_pfn + 1)
-   return -EFAULT;
-
-   prev_pfn = this_pfn;
-   }
-
-   /*
-* Memory is contigous, lock vma and return to the caller
-*/
-   *res_vma = vb2_get_vma(vma);
-   if (*res_vma == NULL)
-   return -ENOMEM;
-
-   *res_pa = pa + offset;
-   return 0;
-}
-EXPORT_SYMBOL_GPL(vb2_get_contig_userptr);
-
-/**
  * vb2_create_framevec() - map virtual addresses to pfns
  * @start: Virtual user address where we start mapping
  * @length:Length of a range to map
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index 2f0564ff5f31..830b5239fd8b 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -31,12 +31,6 @@ struct vb2_vmarea_handler {
 
 extern const struct vm_operations_struct vb2_common_vm_ops;
 
-int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
-  struct vm_area_struct **res_vma, dma_addr_t *res_pa);
-
-struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
-void vb2_put_vma(struct vm_area_struct *vma);
-
 

[PATCH 2/9] mm: Provide new get_vaddr_frames() helper

2015-05-05 Thread Jan Kara
Provide new function get_vaddr_frames().  This function maps virtual
addresses from given start and fills given array with page frame numbers of
the corresponding pages. If given start belongs to a normal vma, the function
grabs reference to each of the pages to pin them in memory. If start
belongs to VM_IO | VM_PFNMAP vma, we don't touch page structures. Caller
must make sure pfns aren't reused for anything else while he is using
them.

This function is created for various drivers to simplify handling of
their buffers.

Signed-off-by: Jan Kara j...@suse.cz
---
 include/linux/mm.h |  44 +++
 mm/gup.c   | 213 +
 2 files changed, 257 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 0755b9fd03a7..dcd1f02a78e9 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -20,6 +20,7 @@
 #include linux/shrinker.h
 #include linux/resource.h
 #include linux/page_ext.h
+#include linux/err.h
 
 struct mempolicy;
 struct anon_vma;
@@ -1197,6 +1198,49 @@ long get_user_pages_unlocked(struct task_struct *tsk, 
struct mm_struct *mm,
int write, int force, struct page **pages);
 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
struct page **pages);
+
+/* Container for pinned pfns / pages */
+struct frame_vector {
+   unsigned int nr_allocated;  /* Number of frames we have space for */
+   unsigned int nr_frames; /* Number of frames stored in ptrs array */
+   bool got_ref;   /* Did we pin pages by getting page ref? */
+   bool is_pfns;   /* Does array contain pages or pfns? */
+   void *ptrs[0];  /* Array of pinned pfns / pages. Use
+* pfns_vector_pages() or pfns_vector_pfns()
+* for access */
+};
+
+struct frame_vector *frame_vector_create(unsigned int nr_frames);
+void frame_vector_destroy(struct frame_vector *vec);
+int get_vaddr_frames(unsigned long start, unsigned int nr_pfns,
+bool write, bool force, struct frame_vector *vec);
+void put_vaddr_frames(struct frame_vector *vec);
+int frame_vector_to_pages(struct frame_vector *vec);
+void frame_vector_to_pfns(struct frame_vector *vec);
+
+static inline unsigned int frame_vector_count(struct frame_vector *vec)
+{
+   return vec-nr_frames;
+}
+
+static inline struct page **frame_vector_pages(struct frame_vector *vec)
+{
+   if (vec-is_pfns) {
+   int err = frame_vector_to_pages(vec);
+
+   if (err)
+   return ERR_PTR(err);
+   }
+   return (struct page **)(vec-ptrs);
+}
+
+static inline unsigned long *frame_vector_pfns(struct frame_vector *vec)
+{
+   if (!vec-is_pfns)
+   frame_vector_to_pfns(vec);
+   return (unsigned long *)(vec-ptrs);
+}
+
 struct kvec;
 int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
struct page **pages);
diff --git a/mm/gup.c b/mm/gup.c
index 6297f6bccfb1..e99ff3e7f142 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -936,6 +936,219 @@ int __mm_populate(unsigned long start, unsigned long len, 
int ignore_errors)
return ret; /* 0 or negative error code */
 }
 
+/*
+ * get_vaddr_frames() - map virtual addresses to pfns
+ * @start: starting user address
+ * @nr_frames: number of pages / pfns from start to map
+ * @write: whether pages will be written to by the caller
+ * @force: whether to force write access even if user mapping is
+ * readonly. This will result in the page being COWed even
+ * in MAP_SHARED mappings. You do not want this.
+ * @vec:   structure which receives pages / pfns of the addresses mapped.
+ * It should have space for at least nr_frames entries.
+ *
+ * This function maps virtual addresses from @start and fills @vec structure
+ * with page frame numbers or page pointers to corresponding pages (choice
+ * depends on the type of the vma underlying the virtual address). If @start
+ * belongs to a normal vma, the function grabs reference to each of the pages
+ * to pin them in memory. If @start belongs to VM_IO | VM_PFNMAP vma, we don't
+ * touch page structures and the caller must make sure pfns aren't reused for
+ * anything else while he is using them.
+ *
+ * The function returns number of pages mapped which may be less than
+ * @nr_frames. In particular we stop mapping if there are more vmas of
+ * different type underlying the specified range of virtual addresses.
+ *
+ * This function takes care of grabbing mmap_sem as necessary.
+ */
+int get_vaddr_frames(unsigned long start, unsigned int nr_frames,
+bool write, bool force, struct frame_vector *vec)
+{
+   struct mm_struct *mm = current-mm;
+   struct vm_area_struct *vma;
+   int ret = 0;
+   int err;
+   int locked = 1;
+
+   if (nr_frames == 0)
+   return 

[PATCH 6/9] media: vb2: Convert vb2_vmalloc_get_userptr() to use frame vector

2015-05-05 Thread Jan Kara
Convert vb2_vmalloc_get_userptr() to use frame vector infrastructure.
When we are doing that there's no need to allocate page array and some
code can be simplified.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-vmalloc.c | 94 +++--
 1 file changed, 36 insertions(+), 58 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c 
b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 0ba40be21ebd..d2ce81fa2cdf 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -23,11 +23,9 @@
 
 struct vb2_vmalloc_buf {
void*vaddr;
-   struct page **pages;
-   struct vm_area_struct   *vma;
+   struct frame_vector *vec;
enum dma_data_direction dma_dir;
unsigned long   size;
-   unsigned intn_pages;
atomic_trefcount;
struct vb2_vmarea_handler   handler;
struct dma_buf  *dbuf;
@@ -76,10 +74,8 @@ static void *vb2_vmalloc_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
 enum dma_data_direction dma_dir)
 {
struct vb2_vmalloc_buf *buf;
-   unsigned long first, last;
-   int n_pages, offset;
-   struct vm_area_struct *vma;
-   dma_addr_t physp;
+   struct frame_vector *vec;
+   int n_pages, offset, i;
 
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
@@ -88,53 +84,36 @@ static void *vb2_vmalloc_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
buf-dma_dir = dma_dir;
offset = vaddr  ~PAGE_MASK;
buf-size = size;
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, vaddr);
-   if (vma  (vma-vm_flags  VM_PFNMAP)  (vma-vm_pgoff)) {
-   if (vb2_get_contig_userptr(vaddr, size, vma, physp))
-   goto fail_pages_array_alloc;
-   buf-vma = vma;
-   buf-vaddr = (__force void *)ioremap_nocache(physp, size);
-   if (!buf-vaddr)
-   goto fail_pages_array_alloc;
+   vec = vb2_create_framevec(vaddr, size, dma_dir == DMA_FROM_DEVICE);
+   if (IS_ERR(vec))
+   goto fail_pfnvec_create;
+   buf-vec = vec;
+   n_pages = frame_vector_count(vec);
+   if (frame_vector_to_pages(vec)  0) {
+   unsigned long *nums = frame_vector_pfns(vec);
+
+   /*
+* We cannot get page pointers for these pfns. Check memory is
+* physically contiguous and use direct mapping.
+*/
+   for (i = 1; i  n_pages; i++)
+   if (nums[i-1] + 1 != nums[i])
+   goto fail_map;
+   buf-vaddr = (__force void *)
+   ioremap_nocache(nums[0]  PAGE_SHIFT, size);
} else {
-   first = vaddr  PAGE_SHIFT;
-   last  = (vaddr + size - 1)  PAGE_SHIFT;
-   buf-n_pages = last - first + 1;
-   buf-pages = kzalloc(buf-n_pages * sizeof(struct page *),
-GFP_KERNEL);
-   if (!buf-pages)
-   goto fail_pages_array_alloc;
-
-   /* current-mm-mmap_sem is taken by videobuf2 core */
-   n_pages = get_user_pages(current, current-mm,
-vaddr  PAGE_MASK, buf-n_pages,
-dma_dir == DMA_FROM_DEVICE,
-1, /* force */
-buf-pages, NULL);
-   if (n_pages != buf-n_pages)
-   goto fail_get_user_pages;
-
-   buf-vaddr = vm_map_ram(buf-pages, buf-n_pages, -1,
+   buf-vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
PAGE_KERNEL);
-   if (!buf-vaddr)
-   goto fail_get_user_pages;
}
-   up_read(current-mm-mmap_sem);
 
+   if (!buf-vaddr)
+   goto fail_map;
buf-vaddr += offset;
return buf;
 
-fail_get_user_pages:
-   pr_debug(get_user_pages requested/got: %d/%d]\n, n_pages,
-buf-n_pages);
-   while (--n_pages = 0)
-   put_page(buf-pages[n_pages]);
-   kfree(buf-pages);
-
-fail_pages_array_alloc:
-   up_read(current-mm-mmap_sem);
+fail_map:
+   vb2_destroy_framevec(vec);
+fail_pfnvec_create:
kfree(buf);
 
return NULL;
@@ -145,22 +124,21 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
struct vb2_vmalloc_buf *buf = buf_priv;
unsigned long vaddr = (unsigned long)buf-vaddr  PAGE_MASK;
unsigned int i;
+  

[PATCH 1/9] [media] vb2: Push mmap_sem down to memops

2015-05-05 Thread Jan Kara
Currently vb2 core acquires mmap_sem just around call to
__qbuf_userptr(). However since commit f035eb4e976ef5 (videobuf2: fix
lockdep warning) it isn't necessary to acquire it so early as we no
longer have to drop queue mutex before acquiring mmap_sem. So push
acquisition of mmap_sem down into .get_userptr and .put_userptr memops
so that the semaphore is acquired for a shorter time and it is clearer
what it is needed for.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-core.c   | 2 --
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 7 +++
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 6 ++
 drivers/media/v4l2-core/videobuf2-vmalloc.c| 6 +-
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 66ada01c796c..20cdbc0900ea 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1657,9 +1657,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
ret = __qbuf_mmap(vb, b);
break;
case V4L2_MEMORY_USERPTR:
-   down_read(current-mm-mmap_sem);
ret = __qbuf_userptr(vb, b);
-   up_read(current-mm-mmap_sem);
break;
case V4L2_MEMORY_DMABUF:
ret = __qbuf_dmabuf(vb, b);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 644dec73d220..620c4aa78881 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -532,7 +532,9 @@ static void vb2_dc_put_userptr(void *buf_priv)
sg_free_table(sgt);
kfree(sgt);
}
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
+   up_read(current-mm-mmap_sem);
kfree(buf);
 }
 
@@ -616,6 +618,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
goto fail_buf;
}
 
+   down_read(current-mm-mmap_sem);
/* current-mm-mmap_sem is taken by videobuf2 core */
vma = find_vma(current-mm, vaddr);
if (!vma) {
@@ -642,6 +645,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
if (ret) {
unsigned long pfn;
if (vb2_dc_get_user_pfn(start, n_pages, vma, pfn) == 0) {
+   up_read(current-mm-mmap_sem);
buf-dma_addr = vb2_dc_pfn_to_dma(buf-dev, pfn);
buf-size = size;
kfree(pages);
@@ -651,6 +655,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
pr_err(failed to get user pages\n);
goto fail_vma;
}
+   up_read(current-mm-mmap_sem);
 
sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
if (!sgt) {
@@ -713,10 +718,12 @@ fail_get_user_pages:
while (n_pages)
put_page(pages[--n_pages]);
 
+   down_read(current-mm-mmap_sem);
 fail_vma:
vb2_put_vma(buf-vma);
 
 fail_pages:
+   up_read(current-mm-mmap_sem);
kfree(pages); /* kfree is NULL-proof */
 
 fail_buf:
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 45c708e463b9..afd4b514affc 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -263,6 +263,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
if (!buf-pages)
goto userptr_fail_alloc_pages;
 
+   down_read(current-mm-mmap_sem);
vma = find_vma(current-mm, vaddr);
if (!vma) {
dprintk(1, no vma for address %lu\n, vaddr);
@@ -301,6 +302,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
 1, /* force */
 buf-pages,
 NULL);
+   up_read(current-mm-mmap_sem);
 
if (num_pages_from_user != buf-num_pages)
goto userptr_fail_get_user_pages;
@@ -328,8 +330,10 @@ userptr_fail_get_user_pages:
if (!vma_is_io(buf-vma))
while (--num_pages_from_user = 0)
put_page(buf-pages[num_pages_from_user]);
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
 userptr_fail_find_vma:
+   up_read(current-mm-mmap_sem);
kfree(buf-pages);
 userptr_fail_alloc_pages:
kfree(buf);
@@ -362,7 +366,9 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
put_page(buf-pages[i]);
}
kfree(buf-pages);
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
+   up_read(current-mm-mmap_sem);
kfree(buf);
 }
 
diff --git 

[RFC] How implement Secure Data Path ?

2015-05-05 Thread Benjamin Gaignard
Hello,

Since few months I'm looking for Linaro to how do Secure Data Path (SPD).
I have tried and implemented multiple thinks but I always facing architecture
issues so I would like to get your help to solve the problem.

First what is Secure Data Path ? SDP is a set of hardware features to garanty
that some memories regions could only be read and/or write by specific hardware
IPs. You can imagine it as a kind of memory firewall which grant/revoke
accesses to memory per devices. Firewall configuration must be done in a trusted
environment: for ARM architecture we plan to use OP-TEE + a trusted
application to do that.

One typical use case for SDP in a video playback which involve those elements:
decrypt - video decoder - transform - display

decrypt output contains encoded data that need to be secure: only hardware video
decoder should be able to read them.
Hardware decoder output (decoded frame) can only be read by hardware
transform and
only hardware display can read transform output.
Video decoder and transform are v4l2 devices and display is a drm/kms device.

To be able to configure the firewall SDP need to know when each device need to
have access to memory (physical address and size) and in which direction (read
or write).
SDP also need a way to transfert information that memory is secure between
different frameworks and devices.
Obviously I also want to limit the impact of SDP in userland and kernel:
For example not change the way of how buffers are allocating or how
graph/pipeline
are setup.

When looking to all those constraints I have try to use dma_buf: it is a cross
frameworks and processes way to share buffers and, with
dma_buf_map_attachment() and dma_buf_unmap_attachment() functions, have an API
that provide the informations (device, memory, direction) to configure
the firewall.

I have try 2 hacky approachs with dma_buf:
- add a secure field in dma_buf structure and configure firewall in
  dma_buf_{map/unmap}_attachment() functions.
- overwrite dma_buf exporter ops to have a kind of nested calls which allow to
  configure firewall without impacting the exporter code.

The both solutions have architecture issues, the first one add a metadata
into dma_buf structure and calls to a specific SDP environment (OP-TEE +
trusted application) and second obvious break dma_buf coding rules
when overwriting
exporter ops.

From buffer allocation point of view I also facing a problem because when v4l2
or drm/kms are exporting buffers by using dma_buf they don't attaching
themself on it and never call dma_buf_{map/unmap}_attachment(). This is not
an issue in those framework while it is how dma_buf exporters are
supposed to work.

Using an external allocator (like ION) solve this problem but I think in
this case we will have the same problem than for the constraint aware
allocator which has never been accepted.

The goal of this RFC is to share/test ideas to solve this problem which at
least impact v4l2 and drm/kms.
Any suggestions/inputs are welcome !

Regards,
Benjamin
--
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] libgencec: Add userspace library for the generic CEC kernel interface

2015-05-05 Thread Emil Velikov
Hi Kamil,

It seems that you've only incorporated the libgencec.pc suggestion.
Did you change your mind about the others, found out something funny
with them (if so can you let me know what) or simply forgot about them
?

On 30 April 2015 at 11:25, Kamil Debski k.deb...@samsung.com wrote:
 Hi Emil,

 From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
 ow...@vger.kernel.org] On Behalf Of Emil Velikov
 Sent: Wednesday, April 29, 2015 5:00 PM

 Hi Kamil,

 Allow me to put a few suggestions:

 On 29 April 2015 at 11:02, Kamil Debski k.deb...@samsung.com wrote:

  diff --git a/m4/.gitkeep b/m4/.gitkeep new file mode 100644 index
  000..e69de29
 Haven't seen any projects doing this. Curious what the benefits of
 keeping and empty folder might be ?

 When I run autoreconf -i it complained about missing m4 folder, hence I added
 this filler file such that the folder is created. Any suggestion on how to do
 this better?

Ahh yes - that lovely message. It turns out that older versions of
automake will even error out [1], rather than just printing out a
warning. A handy workaround would be to add a .gitignore (and a second
one in the top folder) list. Plus it will slim down the untracked
files list and let you clearly see when git add was missed :-)

Cheers
Emil

[1] https://bugzilla.redhat.com/show_bug.cgi?id=901333
--
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: DVBv5 qos/stats driver implementation

2015-05-05 Thread Mauro Carvalho Chehab
Em Tue, 05 May 2015 15:26:07 +0100
Jemma Denson jden...@gmail.com escreveu:

 Mauro/Antti,
 
 Myself and Patrick are currently in the process of bringing an old out 
 of tree frontend driver into shape for inclusion, and one of the issues 
 raised by Mauro was the requirement for the new DVBv5 stats method. I've 
 noticed there seems to be two different ways of going around this - one 
 is to run through the collection and cache filling process during the 
 calls to read_status (as in dib7000p/dib8000p), and the other is to poll 
 independently every couple of seconds via schedule_delayed_work (as in 
 af9033, rtl2830/2832).
 
 Is there any reason for the two different ways - is it just a coding 
 preference or is there some specifics to how these frontends need to be 
 implemented?

Hi Jemma,

It is basically coding preference. 

The DVB has already a thread that calls the frontend driver on every
3 seconds, at most (or when an event occurs). So, I don't see any need
for the drivers to start another thread to update status, as 3 seconds
is generally good enough for status update, then the frontend is
already locked, and the events can make status to update earlier during
device lock phase. Also, if needed, it won't be hard to add core support
to adjust the kthread delay time.

The driver may also skip an update if needed. So, I don't see much
gain on having a per-driver thread.

Having a per-driver thread should work too, although it is an overkill
for me to have two status kthreads running (one provided by the core,
and another by the driver).

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


[PATCH 0/9 v3] Helper to abstract vma handling in media layer

2015-05-05 Thread Jan Kara
  Hello,

  I'm sending the third version of my patch series to abstract vma handling
from the various media drivers. After this patch set drivers have to know much
less details about vmas, their types, and locking. Also quite some code is
removed from them. As a bonus drivers get automatically VM_FAULT_RETRY
handling. The primary motivation for this series is to remove knowledge about
mmap_sem locking from as many places a possible so that we can change it with
reasonable effort.

The core of the series is the new helper get_vaddr_frames() which is given a
virtual address and it fills in PFNs / struct page pointers (depending on VMA
type) into the provided array. If PFNs correspond to normal pages it also grabs
references to these pages. The difference from get_user_pages() is that this
function can also deal with pfnmap, and io mappings which is what the media
drivers need.

I have tested the patches with vivid driver so at least vb2 code got some
exposure. Conversion of other drivers was just compile-tested so I'd like to
ask respective maintainers if they could have a look.  Also I'd like to ask mm
folks to check patch 2/9 implementing the helper. Thanks!

Honza

Changes since v2:
* Renamed functions and structures as Mel suggested
* Other minor changes suggested by Mel
* Rebased on top of 4.1-rc2
* Changed functions to get pointer to array of pages / pfns to perform
  conversion if necessary. This fixes possible issue in the omap I may have
  introduced in v2 and generally makes the API less errorprone.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/9] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns()

2015-05-05 Thread Jan Kara
Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() instead of
hand made mapping of virtual address to physical address. Also the
function leaked page reference from get_user_pages() so fix that by
properly release the reference when omap_vout_buffer_release() is
called.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/platform/omap/omap_vout.c | 67 +++--
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/drivers/media/platform/omap/omap_vout.c 
b/drivers/media/platform/omap/omap_vout.c
index 17b189a81ec5..d3f6d82ccbc1 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -195,46 +195,34 @@ static int omap_vout_try_format(struct v4l2_pix_format 
*pix)
 }
 
 /*
- * omap_vout_uservirt_to_phys: This inline function is used to convert user
- * space virtual address to physical address.
+ * omap_vout_get_userptr: Convert user space virtual address to physical
+ * address.
  */
-static unsigned long omap_vout_uservirt_to_phys(unsigned long virtp)
+static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp,
+u32 *physp)
 {
-   unsigned long physp = 0;
-   struct vm_area_struct *vma;
-   struct mm_struct *mm = current-mm;
+   struct frame_vector *vec;
+   int ret;
 
/* For kernel direct-mapped memory, take the easy way */
-   if (virtp = PAGE_OFFSET)
-   return virt_to_phys((void *) virtp);
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(mm, virtp);
-   if (vma  (vma-vm_flags  VM_IO)  vma-vm_pgoff) {
-   /* this will catch, kernel-allocated, mmaped-to-usermode
-  addresses */
-   physp = (vma-vm_pgoff  PAGE_SHIFT) + (virtp - vma-vm_start);
-   up_read(current-mm-mmap_sem);
-   } else {
-   /* otherwise, use get_user_pages() for general userland pages */
-   int res, nr_pages = 1;
-   struct page *pages;
+   if (virtp = PAGE_OFFSET) {
+   *physp = virt_to_phys((void *)virtp);
+   return 0;
+   }
 
-   res = get_user_pages(current, current-mm, virtp, nr_pages, 1,
-   0, pages, NULL);
-   up_read(current-mm-mmap_sem);
+   vec = frame_vector_create(1);
+   if (!vec)
+   return -ENOMEM;
 
-   if (res == nr_pages) {
-   physp =  __pa(page_address(pages[0]) +
-   (virtp  ~PAGE_MASK));
-   } else {
-   printk(KERN_WARNING VOUT_NAME
-   get_user_pages failed\n);
-   return 0;
-   }
+   ret = get_vaddr_frames(virtp, 1, 1, 0, vec);
+   if (ret != 1) {
+   frame_vector_destroy(vec);
+   return -EINVAL;
}
+   *physp = __pfn_to_phys(frame_vector_pfns(vec)[0]);
+   vb-priv = vec;
 
-   return physp;
+   return 0;
 }
 
 /*
@@ -788,11 +776,15 @@ static int omap_vout_buffer_prepare(struct videobuf_queue 
*q,
 * address of the buffer
 */
if (V4L2_MEMORY_USERPTR == vb-memory) {
+   int ret;
+
if (0 == vb-baddr)
return -EINVAL;
/* Physical address */
-   vout-queued_buf_addr[vb-i] = (u8 *)
-   omap_vout_uservirt_to_phys(vb-baddr);
+   ret = omap_vout_get_userptr(vb, vb-baddr,
+   (u32 *)vout-queued_buf_addr[vb-i]);
+   if (ret  0)
+   return ret;
} else {
unsigned long addr, dma_addr;
unsigned long size;
@@ -841,9 +833,12 @@ static void omap_vout_buffer_release(struct videobuf_queue 
*q,
struct omap_vout_device *vout = q-priv_data;
 
vb-state = VIDEOBUF_NEEDS_INIT;
+   if (vb-memory == V4L2_MEMORY_USERPTR  vb-priv) {
+   struct frame_vector *vec = vb-priv;
 
-   if (V4L2_MEMORY_MMAP != vout-memory)
-   return;
+   put_vaddr_frames(vec);
+   frame_vector_destroy(vec);
+   }
 }
 
 /*
-- 
2.1.4

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


[PATCH 4/9] vb2: Provide helpers for mapping virtual addresses

2015-05-05 Thread Jan Kara
Provide simple helper functions to map virtual address range into an
array of pfns / pages.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-memops.c | 58 ++
 include/media/videobuf2-memops.h   |  5 +++
 2 files changed, 63 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
b/drivers/media/v4l2-core/videobuf2-memops.c
index 81c1ad8b2cf1..0ec186d41b9b 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -137,6 +137,64 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned 
long size,
 EXPORT_SYMBOL_GPL(vb2_get_contig_userptr);
 
 /**
+ * vb2_create_framevec() - map virtual addresses to pfns
+ * @start: Virtual user address where we start mapping
+ * @length:Length of a range to map
+ * @write: Should we map for writing into the area
+ *
+ * This function allocates and fills in a vector with pfns corresponding to
+ * virtual address range passed in arguments. If pfns have corresponding pages,
+ * page references are also grabbed to pin pages in memory. The function
+ * returns pointer to the vector on success and error pointer in case of
+ * failure. Returned vector needs to be freed via vb2_destroy_pfnvec().
+ */
+struct frame_vector *vb2_create_framevec(unsigned long start,
+unsigned long length,
+bool write)
+{
+   int ret;
+   unsigned long first, last;
+   unsigned long nr;
+   struct frame_vector *vec;
+
+   first = start  PAGE_SHIFT;
+   last = (start + length - 1)  PAGE_SHIFT;
+   nr = last - first + 1;
+   vec = frame_vector_create(nr);
+   if (!vec)
+   return ERR_PTR(-ENOMEM);
+   ret = get_vaddr_frames(start, nr, write, 1, vec);
+   if (ret  0)
+   goto out_destroy;
+   /* We accept only complete set of PFNs */
+   if (ret != nr) {
+   ret = -EFAULT;
+   goto out_release;
+   }
+   return vec;
+out_release:
+   put_vaddr_frames(vec);
+out_destroy:
+   frame_vector_destroy(vec);
+   return ERR_PTR(ret);
+}
+EXPORT_SYMBOL(vb2_create_framevec);
+
+/**
+ * vb2_destroy_framevec() - release vector of mapped pfns
+ * @vec:   vector of pfns / pages to release
+ *
+ * This releases references to all pages in the vector @vec (if corresponding
+ * pfns are backed by pages) and frees the passed vector.
+ */
+void vb2_destroy_framevec(struct frame_vector *vec)
+{
+   put_vaddr_frames(vec);
+   frame_vector_destroy(vec);
+}
+EXPORT_SYMBOL(vb2_destroy_framevec);
+
+/**
  * vb2_common_vm_open() - increase refcount of the vma
  * @vma:   virtual memory region for the mapping
  *
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index f05444ca8c0c..2f0564ff5f31 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -15,6 +15,7 @@
 #define _MEDIA_VIDEOBUF2_MEMOPS_H
 
 #include media/videobuf2-core.h
+#include linux/mm.h
 
 /**
  * vb2_vmarea_handler - common vma refcount tracking handler
@@ -36,5 +37,9 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned long 
size,
 struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
 void vb2_put_vma(struct vm_area_struct *vma);
 
+struct frame_vector *vb2_create_framevec(unsigned long start,
+unsigned long length,
+bool write);
+void vb2_destroy_framevec(struct frame_vector *vec);
 
 #endif
-- 
2.1.4

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


[PATCH 5/9] media: vb2: Convert vb2_dma_sg_get_userptr() to use frame vector

2015-05-05 Thread Jan Kara
Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 97 +-
 1 file changed, 15 insertions(+), 82 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index afd4b514affc..4ee1b3fbfe2a 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -38,6 +38,7 @@ struct vb2_dma_sg_buf {
struct device   *dev;
void*vaddr;
struct page **pages;
+   struct frame_vector *vec;
int offset;
enum dma_data_direction dma_dir;
struct sg_table sg_table;
@@ -51,7 +52,6 @@ struct vb2_dma_sg_buf {
unsigned intnum_pages;
atomic_trefcount;
struct vb2_vmarea_handler   handler;
-   struct vm_area_struct   *vma;
 
struct dma_buf_attachment   *db_attach;
 };
@@ -224,25 +224,17 @@ static void vb2_dma_sg_finish(void *buf_priv)
dma_sync_sg_for_cpu(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
 }
 
-static inline int vma_is_io(struct vm_area_struct *vma)
-{
-   return !!(vma-vm_flags  (VM_IO | VM_PFNMAP));
-}
-
 static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
unsigned long size,
enum dma_data_direction dma_dir)
 {
struct vb2_dma_sg_conf *conf = alloc_ctx;
struct vb2_dma_sg_buf *buf;
-   unsigned long first, last;
-   int num_pages_from_user;
-   struct vm_area_struct *vma;
struct sg_table *sgt;
DEFINE_DMA_ATTRS(attrs);
+   struct frame_vector *vec;
 
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs);
-
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return NULL;
@@ -253,63 +245,19 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
buf-offset = vaddr  ~PAGE_MASK;
buf-size = size;
buf-dma_sgt = buf-sg_table;
+   vec = vb2_create_framevec(vaddr, size, buf-dma_dir == DMA_FROM_DEVICE);
+   if (IS_ERR(vec))
+   goto userptr_fail_pfnvec;
+   buf-vec = vec;
 
-   first = (vaddrPAGE_MASK)  PAGE_SHIFT;
-   last  = ((vaddr + size - 1)  PAGE_MASK)  PAGE_SHIFT;
-   buf-num_pages = last - first + 1;
-
-   buf-pages = kzalloc(buf-num_pages * sizeof(struct page *),
-GFP_KERNEL);
-   if (!buf-pages)
-   goto userptr_fail_alloc_pages;
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, vaddr);
-   if (!vma) {
-   dprintk(1, no vma for address %lu\n, vaddr);
-   goto userptr_fail_find_vma;
-   }
-
-   if (vma-vm_end  vaddr + size) {
-   dprintk(1, vma at %lu is too small for %lu bytes\n,
-   vaddr, size);
-   goto userptr_fail_find_vma;
-   }
-
-   buf-vma = vb2_get_vma(vma);
-   if (!buf-vma) {
-   dprintk(1, failed to copy vma\n);
-   goto userptr_fail_find_vma;
-   }
-
-   if (vma_is_io(buf-vma)) {
-   for (num_pages_from_user = 0;
-num_pages_from_user  buf-num_pages;
-++num_pages_from_user, vaddr += PAGE_SIZE) {
-   unsigned long pfn;
-
-   if (follow_pfn(vma, vaddr, pfn)) {
-   dprintk(1, no page for address %lu\n, vaddr);
-   break;
-   }
-   buf-pages[num_pages_from_user] = pfn_to_page(pfn);
-   }
-   } else
-   num_pages_from_user = get_user_pages(current, current-mm,
-vaddr  PAGE_MASK,
-buf-num_pages,
-buf-dma_dir == DMA_FROM_DEVICE,
-1, /* force */
-buf-pages,
-NULL);
-   up_read(current-mm-mmap_sem);
-
-   if (num_pages_from_user != buf-num_pages)
-   goto userptr_fail_get_user_pages;
+   buf-pages = frame_vector_pages(vec);
+   if (IS_ERR(buf-pages))
+   goto userptr_fail_sgtable;
+   buf-num_pages = frame_vector_count(vec);
 
if (sg_alloc_table_from_pages(buf-dma_sgt, buf-pages,
buf-num_pages, buf-offset, size, 0))
-   goto userptr_fail_alloc_table_from_pages;
+   goto userptr_fail_sgtable;
 
sgt = buf-sg_table;
/*
@@ -323,19 +271,9 @@ 

[PATCH 7/9] media: vb2: Convert vb2_dc_get_userptr() to use frame vector

2015-05-05 Thread Jan Kara
Convert vb2_dc_get_userptr() to use frame vector infrastructure. When we
are doing that there's no need to allocate page array and some code can
be simplified.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 214 -
 1 file changed, 34 insertions(+), 180 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 620c4aa78881..e6cea452302b 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -32,15 +32,13 @@ struct vb2_dc_buf {
dma_addr_t  dma_addr;
enum dma_data_direction dma_dir;
struct sg_table *dma_sgt;
+   struct frame_vector *vec;
 
/* MMAP related */
struct vb2_vmarea_handler   handler;
atomic_trefcount;
struct sg_table *sgt_base;
 
-   /* USERPTR related */
-   struct vm_area_struct   *vma;
-
/* DMABUF related */
struct dma_buf_attachment   *db_attach;
 };
@@ -49,24 +47,6 @@ struct vb2_dc_buf {
 /*scatterlist table functions*/
 /*/
 
-
-static void vb2_dc_sgt_foreach_page(struct sg_table *sgt,
-   void (*cb)(struct page *pg))
-{
-   struct scatterlist *s;
-   unsigned int i;
-
-   for_each_sg(sgt-sgl, s, sgt-orig_nents, i) {
-   struct page *page = sg_page(s);
-   unsigned int n_pages = PAGE_ALIGN(s-offset + s-length)
-PAGE_SHIFT;
-   unsigned int j;
-
-   for (j = 0; j  n_pages; ++j, ++page)
-   cb(page);
-   }
-}
-
 static unsigned long vb2_dc_get_contiguous_size(struct sg_table *sgt)
 {
struct scatterlist *s;
@@ -429,92 +409,12 @@ static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv, 
unsigned long flags)
 /*   callbacks for USERPTR buffers   */
 /*/
 
-static inline int vma_is_io(struct vm_area_struct *vma)
-{
-   return !!(vma-vm_flags  (VM_IO | VM_PFNMAP));
-}
-
-static int vb2_dc_get_user_pfn(unsigned long start, int n_pages,
-   struct vm_area_struct *vma, unsigned long *res)
-{
-   unsigned long pfn, start_pfn, prev_pfn;
-   unsigned int i;
-   int ret;
-
-   if (!vma_is_io(vma))
-   return -EFAULT;
-
-   ret = follow_pfn(vma, start, pfn);
-   if (ret)
-   return ret;
-
-   start_pfn = pfn;
-   start += PAGE_SIZE;
-
-   for (i = 1; i  n_pages; ++i, start += PAGE_SIZE) {
-   prev_pfn = pfn;
-   ret = follow_pfn(vma, start, pfn);
-
-   if (ret) {
-   pr_err(no page for address %lu\n, start);
-   return ret;
-   }
-   if (pfn != prev_pfn + 1)
-   return -EINVAL;
-   }
-
-   *res = start_pfn;
-   return 0;
-}
-
-static int vb2_dc_get_user_pages(unsigned long start, struct page **pages,
-   int n_pages, struct vm_area_struct *vma,
-   enum dma_data_direction dma_dir)
-{
-   if (vma_is_io(vma)) {
-   unsigned int i;
-
-   for (i = 0; i  n_pages; ++i, start += PAGE_SIZE) {
-   unsigned long pfn;
-   int ret = follow_pfn(vma, start, pfn);
-
-   if (!pfn_valid(pfn))
-   return -EINVAL;
-
-   if (ret) {
-   pr_err(no page for address %lu\n, start);
-   return ret;
-   }
-   pages[i] = pfn_to_page(pfn);
-   }
-   } else {
-   int n;
-
-   n = get_user_pages(current, current-mm, start  PAGE_MASK,
-   n_pages, dma_dir == DMA_FROM_DEVICE, 1, pages, NULL);
-   /* negative error means that no page was pinned */
-   n = max(n, 0);
-   if (n != n_pages) {
-   pr_err(got only %d of %d user pages\n, n, n_pages);
-   while (n)
-   put_page(pages[--n]);
-   return -EFAULT;
-   }
-   }
-
-   return 0;
-}
-
-static void vb2_dc_put_dirty_page(struct page *page)
-{
-   set_page_dirty_lock(page);
-   put_page(page);
-}
-
 static void vb2_dc_put_userptr(void *buf_priv)
 {
struct vb2_dc_buf *buf = buf_priv;
struct sg_table *sgt = buf-dma_sgt;
+   int i;
+   struct page **pages;
 
if (sgt) {
DEFINE_DMA_ATTRS(attrs);
@@ -526,15 +426,15 @@ static void vb2_dc_put_userptr(void *buf_priv)
 */

Re: [PATCH] v4l: of: Correct pclk-sample for BT656 bus

2015-05-05 Thread Sylwester Nawrocki
On 05/05/15 15:49, Nikhil Devshatwar wrote:
 Current v4l2_of_parse_parallel_bus function attempts to parse the
 DT properties for the parallel bus as well as BT656 bus.
 If the pclk-sample property is defined for the BT656 bus, it is still
 marked as a parallel bus.
 Fix this by parsing the pclk after the bus_type is selected.
 Only when hsync or vsync properties are specified, the bus_type should
 be set to V4L2_MBUS_PARALLEL.
 
 Signed-off-by: Nikhil Devshatwar nikhil...@ti.com

Thanks for the patch.

Acked-by: Sylwester Nawrocki s.nawro...@samsung.com

I'd say this should be backported to stable.
 ---
  drivers/media/v4l2-core/v4l2-of.c |8 
  1 file changed, 4 insertions(+), 4 deletions(-)
 
 diff --git a/drivers/media/v4l2-core/v4l2-of.c 
 b/drivers/media/v4l2-core/v4l2-of.c
 index c52fb96..b27cbb1 100644
 --- a/drivers/media/v4l2-core/v4l2-of.c
 +++ b/drivers/media/v4l2-core/v4l2-of.c
 @@ -93,10 +93,6 @@ static void v4l2_of_parse_parallel_bus(const struct 
 device_node *node,
   flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
   V4L2_MBUS_VSYNC_ACTIVE_LOW;
  
 - if (!of_property_read_u32(node, pclk-sample, v))
 - flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
 - V4L2_MBUS_PCLK_SAMPLE_FALLING;
 -
   if (!of_property_read_u32(node, field-even-active, v))
   flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
   V4L2_MBUS_FIELD_EVEN_LOW;
 @@ -105,6 +101,10 @@ static void v4l2_of_parse_parallel_bus(const struct 
 device_node *node,
   else
   endpoint-bus_type = V4L2_MBUS_BT656;
  
 + if (!of_property_read_u32(node, pclk-sample, v))
 + flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
 + V4L2_MBUS_PCLK_SAMPLE_FALLING;
 +
   if (!of_property_read_u32(node, data-active, v))
   flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
   V4L2_MBUS_DATA_ACTIVE_LOW;

--
Regards,
Sylwester
--
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


Von Dr. Christopher Harrison (Bitte antworten)

2015-05-05 Thread Dr. Christopher Harrison

Lieber Freund,


Wie geht es dir heute? Ich hoffe, in Ordnung, ich bin Dr. Christopher Harrison 
von NothWest London, England. Ich arbeite für Zweig Lloyds Bank London. Ich 
schreibe Ihnen aus meinem Büro, das aus einem großen immense Vorteil für uns 
beide sein wird. In meiner Abteilung, dass die Co-Trainer (Großregion London), 
entdeckte ich eine verlassene Summe von £ 16,5 Millionen Pfund (Sechzehn 
Millionen fünfhunderttausend Pfund und Pfund Sterling) in einem Konto, das Sie 
mit einem unserer ausländischen Kunden Späte Herr Ron Bramlage gehört , ein 
Amerikaner, der in Kansas Staaten lebt, die ein Opfer von einem 
Hubschrauberabsturz im vergangenen Jahr 8. Juni 2012, in Florida Sumpf ihn und 
Familienmitglieder zu töten war. Ron war 45 Jahre alt. Auch in der Chopper zum 
Zeitpunkt des Absturzes war seine Frau Rebecca, 43, und die Kinder des Paares - 
Brandon, 15; Boston, 13; Beau, 11; und 8-jährige Roxanne - wurden getötet. Der 
Pilot war auch tot.


Ich suche Ihre Partnerschaft und Zusammenarbeit zur Durchführung dieser 
Transaktion zusammen, weil der Lloyds Bank schließt einige ihrer Zweigstellen 
und den Zweig, wo dieser Fonds hinterlegt ist unter denen geschlossen werden, 
so dass ich möchte, dass wir diesen Fonds zu bekommen, bevor ihre Verschluss. 
Ich habe Sie kontaktiert, weil ich glaube, Sie werden nicht weglaufen mit 
eigenen Aktien dieses Fonds, wenn es Ihrem Konto eingeht, und die gemeinsame 
Nutzung Quote von 60% für mich und 40% für Ihre Zusammenarbeit. Für Sie die 
Lloyds Bank, um sicherzustellen, Schließen Niederlassungen besuchen Sie diese 
Seite:


https://uk.news.yahoo.com/lloyds-bank-more-200-branches-close-181000783--finance.html#4KVKdTh


Aufgrund der Sensibilität der Transaktion und die Vertraulichkeit hier, jetzt 
unsere Bank hat für keine der Verwandten warten zu kommen-up für die 
Behauptung, aber niemand hat in der Suche die Verwandten für eine lange Zeit 
jetzt getan, dass ich persönlich nicht erfolgreich waren . Mein lieber Freund, 
ich suche Ihre Zustimmung an Sie als nächsten Angehörigen / Will Begünstigter 
des Verstorbenen zu präsentieren, so dass die Erlöse aus diesem Konto bei £ 
16,5 Millionen Pfund an Sie gezahlt werden bewertet.


Das wird für mich ausgezahlt oder geteilt in diese Prozentsätze, 60% und 40% zu 
Ihnen, ich habe alle notwendigen rechtlichen Dokumente, die wir verwendet 
werden, um diese Behauptung wir machen gesichert. Alles was ich brauche ist es, 
in Ihrem Namen zu den Dokumenten füllen und legalisiert es in den Hof und die 
Lloyds Bank hier, um Ihnen zu beweisen, als berechtigten Empfänger, ist Alles, 
was ich jetzt brauche Ihre ehrliche Zusammenarbeit, Verschwiegenheit und 
Vertrauen, damit wir sehen, diese Transaktion durch. Ich garantiere Ihnen, dass 
dies unter einer legitimen Anordnung, die Sie von einem Verstoß gegen das 
Gesetz hier in England und in Ihrem Land zu schützen wird ausgeführt.


Bitte, bitte senden Sie mir die folgenden: wir haben 7 Tage, um es zu 
durchlaufen, das ist sehr, sehr URGENT PLEASE.


1. Vollständiger Name: ..
2. Ihre Telefonnummer: .
3. Ihre Kontaktadresse: ..
4. Alter / Geschlecht: ...
5. Kern Job / Beruf: ..


Bitte beantworten Sie meine E-Mail hier: harrisondr.christoph_off...@yahoo.co.uk


Ich habe euch in Kontakt gebracht, zu glauben, dass Sie nicht weglaufen mit 
eigenen Aktien dieses Fonds, wenn es Ihrem Konto kommt, hoffe ich, können Sie 
auf diese vertrauen? Wie Sie wissen, diese Transaktion beinhalten sehr viel 
Geld. Bitte Standard freundlich zeigen Sie Ihr Interesse, indem sie mich mit 
Ihren Angaben wie oben, so kann ich Ihnen mehr Informationen darüber, wie die 
Bank gehen, um diesen Fonds zu Ihnen innerhalb von 5 Bankarbeitstagen 
übertragen bekommen zu erbringen. Endeavour zu antworten, dass sie nicht länger 
auf mich gewartet. Ok, mein lieber Freund?


Freundliche Grüße,
Dr. Christopher Harrison
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 00/17] media: blackfin: bfin_capture enhancements

2015-05-05 Thread Scott Jiang
2015-04-24 18:04 GMT+08:00 Hans Verkuil hverk...@xs4all.nl:
 On 04/10/2015 12:42 PM, Scott Jiang wrote:
 Hi Hans,


 Hans, I tried to use v4l2-compliance but it failed to compile. Sorry
 for telling you it have passed compilation because I forgot to use
 blackfin toolchain.
 ./configure --without-jpeg  --host=bfin-linux-uclibc --disable-libv4l

 The main problem is there is no argp.h in uClibc, how to disable checking 
 this?

 checking for argp.h... no
 configure: error: Cannot continue: argp.h not found

 Scott


 Hi Scott,

 Can you try this patch for v4l-utils? It makes argp optional, and it should
 allow v4l2-compliance to compile with uclibc (unless there are more 
 problems).

 I'm no autoconf guru, so I'm not certain if everything is correct, but it
 seemed to do its job when I remove argp.h from my system.


 Yes, I can pass configure now. But there is another error when make

 make[3]: Entering directory
 `/home/scott/projects/git-kernel/v4l-utils/lib/libdvbv5'
   CC libdvbv5_la-parse_string.lo
 parse_string.c:26:19: error: iconv.h: No such file or directory
 parse_string.c: In function 'dvb_iconv_to_charset':
 parse_string.c:316: error: 'iconv_t' undeclared (first use in this function)

 I tried to pass this library, while --without-libdvbv5 is not supported.


 If you can pass the configure step, then you should be able to run this:

 cd utils/v4l2-compliance
 cat *.cpp x.cpp
 g++ -o v4l2-compliance x.cpp -I . -I ../../include/ -DNO_LIBV4L2

 (you need to use the right toolchain here, of course)

 If this compiles OK, then you have a v4l2-compliance tool that you can
 use.

Yes, this method works. The test results of v4l2-compliance are below,
I'm sorry the kernel has not upgraded to 4.0.
root:/ ./v4l2-compliance -d 0
Driver Info:bfin_capture bfin_capture.0: =  START
STATUS  =

Driver name   : bfin_capture
Card type :bfin_capture bfin_capture.0: ==
 END STATUS  ==
 BF609
Bus info  : Blackfin Platform
Driver version: 3.17.0
Capabilities  : 0x0421
Video Capture
Streaming
Extended Pix Format

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

Required ioctls:
fail: x.cpp(306): missing bus_info prefix ('Blackfin Platform')
test VIDIOC_QUERYCAP: FAIL

Allow for multiple opens:
test second video open: OK
fail: x.cpp(306): missing bus_info prefix ('Blackfin Platform')
test VIDIOC_QUERYCAP: FAIL
test VIDIOC_G/S_PRIORITY: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Test input 0:

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
fail: x.cpp(2944): subscribe event for control 'User
Controls' failed
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 3 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported)
fail: x.cpp(3405): pixelformat != V4L2_PIX_FMT_JPEG 
colorspace == V4L2_COLORSPACE_JPEG
fail: x.cpp(3508): testColorspace(pix.pixelformat,
pix.colorspace, pix.ycbcr_enc, pix.quantization)
test VIDIOC_G_FMT: FAIL
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK

Codec ioctls:
test 

Re: [PATCH v4 00/17] media: blackfin: bfin_capture enhancements

2015-05-05 Thread Lad, Prabhakar
Hi Scott,

On Tue, May 5, 2015 at 10:58 AM, Scott Jiang
scott.jiang.li...@gmail.com wrote:
 2015-04-24 18:04 GMT+08:00 Hans Verkuil hverk...@xs4all.nl:
 On 04/10/2015 12:42 PM, Scott Jiang wrote:
 Hi Hans,


 Hans, I tried to use v4l2-compliance but it failed to compile. Sorry
 for telling you it have passed compilation because I forgot to use
 blackfin toolchain.
 ./configure --without-jpeg  --host=bfin-linux-uclibc --disable-libv4l

 The main problem is there is no argp.h in uClibc, how to disable checking 
 this?

 checking for argp.h... no
 configure: error: Cannot continue: argp.h not found

 Scott


 Hi Scott,

 Can you try this patch for v4l-utils? It makes argp optional, and it should
 allow v4l2-compliance to compile with uclibc (unless there are more 
 problems).

 I'm no autoconf guru, so I'm not certain if everything is correct, but it
 seemed to do its job when I remove argp.h from my system.


 Yes, I can pass configure now. But there is another error when make

 make[3]: Entering directory
 `/home/scott/projects/git-kernel/v4l-utils/lib/libdvbv5'
   CC libdvbv5_la-parse_string.lo
 parse_string.c:26:19: error: iconv.h: No such file or directory
 parse_string.c: In function 'dvb_iconv_to_charset':
 parse_string.c:316: error: 'iconv_t' undeclared (first use in this function)

 I tried to pass this library, while --without-libdvbv5 is not supported.


 If you can pass the configure step, then you should be able to run this:

 cd utils/v4l2-compliance
 cat *.cpp x.cpp
 g++ -o v4l2-compliance x.cpp -I . -I ../../include/ -DNO_LIBV4L2

 (you need to use the right toolchain here, of course)

 If this compiles OK, then you have a v4l2-compliance tool that you can
 use.

 Yes, this method works. The test results of v4l2-compliance are below,
 I'm sorry the kernel has not upgraded to 4.0.
 root:/ ./v4l2-compliance -d 0

v4l2-compliance with -s option would interesting to watch.

Cheers,
--Prabhakar Lad
--
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] [media] usb: as102: as10x_cmd_cfg: Remove unused function

2015-05-05 Thread Mauro Carvalho Chehab
Em Mon, 12 Jan 2015 00:05:10 +0100
Rickard Strandqvist rickard_strandqv...@spectrumdigital.se escreveu:

 Remove the function as10x_cmd_eLNA_change_mode() that is not used anywhere.
 
 This was partially found by using a static code analysis program called 
 cppcheck.

The fix here should add support for it, as the DVB core now supports
changing the LNA settings via DTV_LNA property, as described at:

http://linuxtv.org/downloads/v4l-dvb-apis/FE_GET_SET_PROPERTY.html#DTV-LNA

Regards,
Mauro

 
 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/media/usb/as102/as10x_cmd.h |1 -
  drivers/media/usb/as102/as10x_cmd_cfg.c |   49 
 ---
  2 files changed, 50 deletions(-)
 
 diff --git a/drivers/media/usb/as102/as10x_cmd.h 
 b/drivers/media/usb/as102/as10x_cmd.h
 index e06b84e..d87fc2f 100644
 --- a/drivers/media/usb/as102/as10x_cmd.h
 +++ b/drivers/media/usb/as102/as10x_cmd.h
 @@ -518,6 +518,5 @@ int as10x_cmd_get_context(struct as10x_bus_adapter_t 
 *adap,
 uint16_t tag,
 uint32_t *pvalue);
  
 -int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t 
 mode);
  int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id);
  #endif
 diff --git a/drivers/media/usb/as102/as10x_cmd_cfg.c 
 b/drivers/media/usb/as102/as10x_cmd_cfg.c
 index c87f2ca..74def1f 100644
 --- a/drivers/media/usb/as102/as10x_cmd_cfg.c
 +++ b/drivers/media/usb/as102/as10x_cmd_cfg.c
 @@ -130,55 +130,6 @@ out:
  }
  
  /**
 - * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
 - * @adap:  pointer to AS10x bus adapter
 - * @mode:  mode selected:
 - *   - ON: 0x0 = eLNA always ON
 - *   - OFF   : 0x1 = eLNA always OFF
 - *   - AUTO  : 0x2 = eLNA follow hysteresis parameters
 - *to be ON or OFF
 - *
 - * Return 0 on success or negative value in case of error.
 - */
 -int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t 
 mode)
 -{
 - int error;
 - struct as10x_cmd_t *pcmd, *prsp;
 -
 - pcmd = adap-cmd;
 - prsp = adap-rsp;
 -
 - /* prepare command */
 - as10x_cmd_build(pcmd, (++adap-cmd_xid),
 - sizeof(pcmd-body.cfg_change_mode.req));
 -
 - /* fill command */
 - pcmd-body.cfg_change_mode.req.proc_id =
 - cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
 - pcmd-body.cfg_change_mode.req.mode = mode;
 -
 - /* send command */
 - if (adap-ops-xfer_cmd) {
 - error  = adap-ops-xfer_cmd(adap, (uint8_t *) pcmd,
 - sizeof(pcmd-body.cfg_change_mode.req)
 - + HEADER_SIZE, (uint8_t *) prsp,
 - sizeof(prsp-body.cfg_change_mode.rsp)
 - + HEADER_SIZE);
 - } else {
 - error = AS10X_CMD_ERROR;
 - }
 -
 - if (error  0)
 - goto out;
 -
 - /* parse response */
 - error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
 -
 -out:
 - return error;
 -}
 -
 -/**
   * as10x_context_rsp_parse - Parse context command response
   * @prsp:   pointer to AS10x command response buffer
   * @proc_id:id of the command
--
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/4] msi001: cleanups / renames

2015-05-05 Thread Antti Palosaari
Rename state from s to dev. Rename some other things. Fix indentations.
Disable driver unbind via sysfs.

Signed-off-by: Antti Palosaari cr...@iki.fi

indentation prevent unload

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/msi001.c | 195 ++
 1 file changed, 101 insertions(+), 94 deletions(-)

diff --git a/drivers/media/tuners/msi001.c b/drivers/media/tuners/msi001.c
index d0ec4e3..b533240 100644
--- a/drivers/media/tuners/msi001.c
+++ b/drivers/media/tuners/msi001.c
@@ -36,7 +36,7 @@ static const struct v4l2_frequency_band bands[] = {
},
 };
 
-struct msi001 {
+struct msi001_dev {
struct spi_device *spi;
struct v4l2_subdev sd;
 
@@ -51,25 +51,26 @@ struct msi001 {
unsigned int f_tuner;
 };
 
-static inline struct msi001 *sd_to_msi001(struct v4l2_subdev *sd)
+static inline struct msi001_dev *sd_to_msi001_dev(struct v4l2_subdev *sd)
 {
-   return container_of(sd, struct msi001, sd);
+   return container_of(sd, struct msi001_dev, sd);
 }
 
-static int msi001_wreg(struct msi001 *s, u32 data)
+static int msi001_wreg(struct msi001_dev *dev, u32 data)
 {
/* Register format: 4 bits addr + 20 bits value */
-   return spi_write(s-spi, data, 3);
+   return spi_write(dev-spi, data, 3);
 };
 
-static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain,
-   int if_gain)
+static int msi001_set_gain(struct msi001_dev *dev, int lna_gain, int 
mixer_gain,
+  int if_gain)
 {
+   struct spi_device *spi = dev-spi;
int ret;
u32 reg;
 
-   dev_dbg(s-spi-dev, lna=%d mixer=%d if=%d\n,
-   lna_gain, mixer_gain, if_gain);
+   dev_dbg(spi-dev, lna=%d mixer=%d if=%d\n,
+   lna_gain, mixer_gain, if_gain);
 
reg = 1  0;
reg |= (59 - if_gain)  4;
@@ -78,18 +79,19 @@ static int msi001_set_gain(struct msi001 *s, int lna_gain, 
int mixer_gain,
reg |= (1 - lna_gain)  13;
reg |= 4  14;
reg |= 0  17;
-   ret = msi001_wreg(s, reg);
+   ret = msi001_wreg(dev, reg);
if (ret)
goto err;
 
return 0;
 err:
-   dev_dbg(s-spi-dev, failed %d\n, ret);
+   dev_dbg(spi-dev, failed %d\n, ret);
return ret;
 };
 
-static int msi001_set_tuner(struct msi001 *s)
+static int msi001_set_tuner(struct msi001_dev *dev)
 {
+   struct spi_device *spi = dev-spi;
int ret, i;
unsigned int uitmp, div_n, k, k_thresh, k_frac, div_lo, f_if1;
u32 reg;
@@ -130,7 +132,7 @@ static int msi001_set_tuner(struct msi001 *s)
{800, 0x07}, /* 8 MHz */
};
 
-   unsigned int f_rf = s-f_tuner;
+   unsigned int f_rf = dev-f_tuner;
 
/*
 * bandwidth (Hz)
@@ -147,7 +149,7 @@ static int msi001_set_tuner(struct msi001 *s)
#define DIV_PRE_N 4
#define F_VCO_STEP div_lo
 
-   dev_dbg(s-spi-dev, f_rf=%d f_if=%d\n, f_rf, f_if);
+   dev_dbg(spi-dev, f_rf=%d f_if=%d\n, f_rf, f_if);
 
for (i = 0; i  ARRAY_SIZE(band_lut); i++) {
if (f_rf = band_lut[i].rf) {
@@ -156,7 +158,6 @@ static int msi001_set_tuner(struct msi001 *s)
break;
}
}
-
if (i == ARRAY_SIZE(band_lut)) {
ret = -EINVAL;
goto err;
@@ -174,14 +175,13 @@ static int msi001_set_tuner(struct msi001 *s)
break;
}
}
-
if (i == ARRAY_SIZE(if_freq_lut)) {
ret = -EINVAL;
goto err;
}
 
/* filters */
-   bandwidth = s-bandwidth-val;
+   bandwidth = dev-bandwidth-val;
bandwidth = clamp(bandwidth, 20U, 800U);
 
for (i = 0; i  ARRAY_SIZE(bandwidth_lut); i++) {
@@ -190,15 +190,14 @@ static int msi001_set_tuner(struct msi001 *s)
break;
}
}
-
if (i == ARRAY_SIZE(bandwidth_lut)) {
ret = -EINVAL;
goto err;
}
 
-   s-bandwidth-val = bandwidth_lut[i].freq;
+   dev-bandwidth-val = bandwidth_lut[i].freq;
 
-   dev_dbg(s-spi-dev, bandwidth selected=%d\n, bandwidth_lut[i].freq);
+   dev_dbg(spi-dev, bandwidth selected=%d\n, bandwidth_lut[i].freq);
 
/*
 * Fractional-N synthesizer
@@ -237,15 +236,15 @@ static int msi001_set_tuner(struct msi001 *s)
uitmp += (unsigned int) F_REF * DIV_PRE_N * k_frac / k_thresh;
uitmp /= div_lo;
 
-   dev_dbg(s-spi-dev,
+   dev_dbg(spi-dev,
f_rf=%u:%u f_vco=%llu div_n=%u k_thresh=%u k_frac=%u 
div_lo=%u\n,
f_rf, uitmp, f_vco, div_n, k_thresh, k_frac, div_lo);
 
-   ret = msi001_wreg(s, 0x0e);
+   ret = msi001_wreg(dev, 0x0e);
if (ret)
goto err;
 
-   ret = msi001_wreg(s, 0x03);
+   ret = msi001_wreg(dev, 0x03);
if (ret)
 

[PATCH 4/4] msi2500: cleanups

2015-05-05 Thread Antti Palosaari
Rename state to dev.
Correct some indentations.
Remove FSF address.
Fix some style issues reported by checkpatch.pl.
Correct some style issues I liked.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/msi2500/msi2500.c | 610 ++--
 1 file changed, 306 insertions(+), 304 deletions(-)

diff --git a/drivers/media/usb/msi2500/msi2500.c 
b/drivers/media/usb/msi2500/msi2500.c
index 8605b96..3f276d9 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -1,4 +1,5 @@
 /*
+ * Mirics MSi2500 driver
  * Mirics MSi3101 SDR Dongle driver
  *
  * Copyright (C) 2013 Antti Palosaari cr...@iki.fi
@@ -13,10 +14,6 @@
  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *GNU General Public License for more details.
  *
- *You should have received a copy of the GNU General Public License along
- *with this program; if not, write to the Free Software Foundation, Inc.,
- *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  * That driver is somehow based of pwc driver:
  *  (C) 1999-2004 Nemosoft Unv.
  *  (C) 2004-2006 Luc Saillard (l...@saillard.org)
@@ -119,7 +116,7 @@ struct msi2500_frame_buf {
struct list_head list;
 };
 
-struct msi2500_state {
+struct msi2500_dev {
struct device *dev;
struct video_device vdev;
struct v4l2_device v4l2_dev;
@@ -158,19 +155,19 @@ struct msi2500_state {
 
 /* Private functions */
 static struct msi2500_frame_buf *msi2500_get_next_fill_buf(
-   struct msi2500_state *s)
+   struct msi2500_dev *dev)
 {
unsigned long flags;
struct msi2500_frame_buf *buf = NULL;
 
-   spin_lock_irqsave(s-queued_bufs_lock, flags);
-   if (list_empty(s-queued_bufs))
+   spin_lock_irqsave(dev-queued_bufs_lock, flags);
+   if (list_empty(dev-queued_bufs))
goto leave;
 
-   buf = list_entry(s-queued_bufs.next, struct msi2500_frame_buf, list);
+   buf = list_entry(dev-queued_bufs.next, struct msi2500_frame_buf, list);
list_del(buf-list);
 leave:
-   spin_unlock_irqrestore(s-queued_bufs_lock, flags);
+   spin_unlock_irqrestore(dev-queued_bufs_lock, flags);
return buf;
 }
 
@@ -256,8 +253,8 @@ leave:
  * signed 14-bit sample
  */
 
-static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
-   unsigned int src_len)
+static int msi2500_convert_stream(struct msi2500_dev *dev, u8 *dst, u8 *src,
+ unsigned int src_len)
 {
unsigned int i, j, transactions, dst_len = 0;
u32 sample[3];
@@ -268,26 +265,27 @@ static int msi2500_convert_stream(struct msi2500_state 
*s, u8 *dst, u8 *src,
for (i = 0; i  transactions; i++) {
sample[i] = src[3]  24 | src[2]  16 | src[1]  8 |
src[0]  0;
-   if (i == 0  s-next_sample != sample[0]) {
-   dev_dbg_ratelimited(s-dev,
-   %d samples lost, %d %08x:%08x\n,
-   sample[0] - s-next_sample,
-   src_len, s-next_sample, sample[0]);
+   if (i == 0  dev-next_sample != sample[0]) {
+   dev_dbg_ratelimited(dev-dev,
+   %d samples lost, %d %08x:%08x\n,
+   sample[0] - dev-next_sample,
+   src_len, dev-next_sample,
+   sample[0]);
}
 
/*
 * Dump all unknown 'garbage' data - maybe we will discover
 * someday if there is something rational...
 */
-   dev_dbg_ratelimited(s-dev, %*ph\n, 12, src[4]);
+   dev_dbg_ratelimited(dev-dev, %*ph\n, 12, src[4]);
 
src += 16; /* skip header */
 
-   switch (s-pixelformat) {
+   switch (dev-pixelformat) {
case V4L2_SDR_FMT_CU8: /* 504 x IQ samples */
{
-   s8 *s8src = (s8 *) src;
-   u8 *u8dst = (u8 *) dst;
+   s8 *s8src = (s8 *)src;
+   u8 *u8dst = (u8 *)dst;
 
for (j = 0; j  1008; j++)
*u8dst++ = *s8src++ + 128;
@@ -295,13 +293,13 @@ static int msi2500_convert_stream(struct msi2500_state 
*s, u8 *dst, u8 *src,
src += 1008;
dst += 1008;
dst_len += 1008;
-   s-next_sample = sample[i] + 504;
+   dev-next_sample = sample[i] + 504;
break;
}
case  V4L2_SDR_FMT_CU16LE: /* 252 x IQ samples */
{
-   s16 

[PATCH 3/4] msi2500: revise synthesizer calculation

2015-05-05 Thread Antti Palosaari
Update synthesizer calculation to model I prefer nowadays. It is mostly
just renaming some variables, but also minor functionality change how
integer and fractional part are divided (using div_u64_rem()). Also, add
'schematic' of synthesizer following my current understanding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/msi2500/msi2500.c | 49 +
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/drivers/media/usb/msi2500/msi2500.c 
b/drivers/media/usb/msi2500/msi2500.c
index efc761c..8605b96 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -682,11 +682,10 @@ static int msi2500_ctrl_msg(struct msi2500_state *s, u8 
cmd, u32 data)
return ret;
 }
 
-#define F_REF 2400
-#define DIV_R_IN 2
 static int msi2500_set_usb_adc(struct msi2500_state *s)
 {
-   int ret, div_n, div_m, div_r_out, f_sr, f_vco, fract;
+   int ret;
+   unsigned int f_vco, f_sr, div_n, k, k_cw, div_out;
u32 reg3, reg4, reg7;
struct v4l2_ctrl *bandwidth_auto;
struct v4l2_ctrl *bandwidth;
@@ -728,6 +727,21 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
}
 
/*
+* Fractional-N synthesizer
+*
+*   ++
+*   v|
+*  Fref   ++ +---+ +-+ +--+ +---+
+* -- | PD | -- |  VCO  | -- | /2  | -- | /N.F | -- | K |
+* ++ +---+ +-+ +--+ +---+
+*  |
+*  |
+*  v
+*+---+ +-+  Fout
+*| /Rout | -- | /12 | --
+*+---+ +-+
+*/
+   /*
 * Synthesizer config is just a educated guess...
 *
 * [7:0]   0x03, register address
@@ -754,10 +768,14 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
 *
 * VCO 20200 - 72000++
 */
+
+   #define F_REF 2400
+   #define DIV_PRE_N 2
+   #define DIV_LO_OUT 12
reg3 = 0x01000303;
reg4 = 0x0004;
 
-   /* XXX: Filters? AGC? */
+   /* XXX: Filters? AGC? VCO band? */
if (f_sr  600)
reg3 |= 0x1  20;
else if (f_sr  700)
@@ -767,24 +785,25 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
else
reg3 |= 0xd  20;
 
-   for (div_r_out = 4; div_r_out  16; div_r_out += 2) {
-   f_vco = f_sr * div_r_out * 12;
-   dev_dbg(s-dev, div_r_out=%d f_vco=%d\n, div_r_out, f_vco);
+   for (div_out = 4; div_out  16; div_out += 2) {
+   f_vco = f_sr * div_out * DIV_LO_OUT;
+   dev_dbg(s-dev, div_out=%d f_vco=%d\n, div_out, f_vco);
if (f_vco = 20200)
break;
}
 
-   div_n = f_vco / (F_REF * DIV_R_IN);
-   div_m = f_vco % (F_REF * DIV_R_IN);
-   fract = 0x20ul * div_m / (F_REF * DIV_R_IN);
+   /* Calculate PLL integer and fractional control word. */
+   div_n = div_u64_rem(f_vco, DIV_PRE_N * F_REF, k);
+   k_cw = div_u64((u64) k * 0x20, DIV_PRE_N * F_REF);
 
reg3 |= div_n  16;
-   reg3 |= (div_r_out / 2 - 1)  10;
-   reg3 |= ((fract  20)  0x01)  15; /* [20] */
-   reg4 |= ((fract   0)  0x0f)   8; /* [19:0] */
+   reg3 |= (div_out / 2 - 1)  10;
+   reg3 |= ((k_cw  20)  0x01)  15; /* [20] */
+   reg4 |= ((k_cw   0)  0x0f)   8; /* [19:0] */
 
-   dev_dbg(s-dev, f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d 
reg3=%08x reg4=%08x\n,
-   f_sr, f_vco, div_n, div_m, div_r_out, reg3, reg4);
+   dev_dbg(s-dev,
+   f_sr=%u f_vco=%u div_n=%u k=%u div_out=%u reg3=%08x 
reg4=%08x\n,
+   f_sr, f_vco, div_n, k, div_out, reg3, reg4);
 
ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008);
if (ret)
-- 
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 1/4] msi001: revise synthesizer calculation

2015-05-05 Thread Antti Palosaari
Update synthesizer calculation to model I prefer nowadays. It is mostly
just renaming some variables, but also minor functionality change how
integer and fractional part are divided (using div_u64_rem()). Also, add
'schematic' of synthesizer following my current understanding.

Signed-off-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/tuners/msi001.c | 74 +--
 1 file changed, 44 insertions(+), 30 deletions(-)

diff --git a/drivers/media/tuners/msi001.c b/drivers/media/tuners/msi001.c
index 74cfc3c..d0ec4e3 100644
--- a/drivers/media/tuners/msi001.c
+++ b/drivers/media/tuners/msi001.c
@@ -91,15 +91,15 @@ err:
 static int msi001_set_tuner(struct msi001 *s)
 {
int ret, i;
-   unsigned int n, m, thresh, frac, vco_step, tmp, f_if1;
+   unsigned int uitmp, div_n, k, k_thresh, k_frac, div_lo, f_if1;
u32 reg;
-   u64 f_vco, tmp64;
-   u8 mode, filter_mode, lo_div;
+   u64 f_vco;
+   u8 mode, filter_mode;
 
static const struct {
u32 rf;
u8 mode;
-   u8 lo_div;
+   u8 div_lo;
} band_lut[] = {
{ 5000, 0xe1, 16}, /* AM_MODE2, antenna 2 */
{10800, 0x42, 32}, /* VHF_MODE */
@@ -144,15 +144,15 @@ static int msi001_set_tuner(struct msi001 *s)
 */
unsigned int f_if = 0;
#define F_REF 2400
-   #define R_REF 4
-   #define F_OUT_STEP 1
+   #define DIV_PRE_N 4
+   #define F_VCO_STEP div_lo
 
dev_dbg(s-spi-dev, f_rf=%d f_if=%d\n, f_rf, f_if);
 
for (i = 0; i  ARRAY_SIZE(band_lut); i++) {
if (f_rf = band_lut[i].rf) {
mode = band_lut[i].mode;
-   lo_div = band_lut[i].lo_div;
+   div_lo = band_lut[i].div_lo;
break;
}
}
@@ -200,32 +200,46 @@ static int msi001_set_tuner(struct msi001 *s)
 
dev_dbg(s-spi-dev, bandwidth selected=%d\n, bandwidth_lut[i].freq);
 
-   f_vco = (u64) (f_rf + f_if + f_if1) * lo_div;
-   tmp64 = f_vco;
-   m = do_div(tmp64, F_REF * R_REF);
-   n = (unsigned int) tmp64;
+   /*
+* Fractional-N synthesizer
+*
+*   +---+
+*   v   |
+*  Fref   ++ +---+ ++ +--+ +---+
+* -- | PD | -- |  VCO  | -- | /4 | -- | /N.F | -- | K |
+* ++ +---+ ++ +--+ +---+
+*  |
+*  |
+*  v
+*+---+  Fout
+*| /Rout | --
+*+---+
+*/
 
-   vco_step = F_OUT_STEP * lo_div;
-   thresh = (F_REF * R_REF) / vco_step;
-   frac = 1ul * thresh * m / (F_REF * R_REF);
+   /* Calculate PLL integer and fractional control word. */
+   f_vco = (u64) (f_rf + f_if + f_if1) * div_lo;
+   div_n = div_u64_rem(f_vco, DIV_PRE_N * F_REF, k);
+   k_thresh = (DIV_PRE_N * F_REF) / F_VCO_STEP;
+   k_frac = div_u64((u64) k * k_thresh, (DIV_PRE_N * F_REF));
 
/* Find out greatest common divisor and divide to smaller. */
-   tmp = gcd(thresh, frac);
-   thresh /= tmp;
-   frac /= tmp;
+   uitmp = gcd(k_thresh, k_frac);
+   k_thresh /= uitmp;
+   k_frac /= uitmp;
 
/* Force divide to reg max. Resolution will be reduced. */
-   tmp = DIV_ROUND_UP(thresh, 4095);
-   thresh = DIV_ROUND_CLOSEST(thresh, tmp);
-   frac = DIV_ROUND_CLOSEST(frac, tmp);
+   uitmp = DIV_ROUND_UP(k_thresh, 4095);
+   k_thresh = DIV_ROUND_CLOSEST(k_thresh, uitmp);
+   k_frac = DIV_ROUND_CLOSEST(k_frac, uitmp);
 
-   /* calc real RF set */
-   tmp = 1ul * F_REF * R_REF * n;
-   tmp += 1ul * F_REF * R_REF * frac / thresh;
-   tmp /= lo_div;
+   /* Calculate real RF set. */
+   uitmp = (unsigned int) F_REF * DIV_PRE_N * div_n;
+   uitmp += (unsigned int) F_REF * DIV_PRE_N * k_frac / k_thresh;
+   uitmp /= div_lo;
 
-   dev_dbg(s-spi-dev, rf=%u:%u n=%d thresh=%d frac=%d\n,
-   f_rf, tmp, n, thresh, frac);
+   dev_dbg(s-spi-dev,
+   f_rf=%u:%u f_vco=%llu div_n=%u k_thresh=%u k_frac=%u 
div_lo=%u\n,
+   f_rf, uitmp, f_vco, div_n, k_thresh, k_frac, div_lo);
 
ret = msi001_wreg(s, 0x0e);
if (ret)
@@ -246,7 +260,7 @@ static int msi001_set_tuner(struct msi001 *s)
goto err;
 
reg = 5  0;
-   reg |= thresh  4;
+   reg |= k_thresh  4;
reg |= 1  19;
reg |= 1  21;
ret = msi001_wreg(s, reg);
@@ -254,8 +268,8 @@ static int msi001_set_tuner(struct msi001 *s)
goto err;
 
reg = 2  0;
-   reg |= frac  4;
-   reg