Re: [PATCH v2 5/6] usbtv: Enforce standard for color decoding

2018-04-08 Thread kbuild test robot
Hi Hugo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.16 next-20180406]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Hugo-Grostabussiat/usbtv-Add-SECAM-support-and-fix-color-encoding-selection/20180409-054206
base:   git://linuxtv.org/media_tree.git master
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/media/usb/usbtv/usbtv-video.c:261:45: sparse: incorrect type in 
>> argument 2 (different modifiers) @@expected unsigned short const 
>> [usertype] ( *regs )[2] @@got ed short const [usertype] ( *regs )[2] @@
   drivers/media/usb/usbtv/usbtv-video.c:261:45:expected unsigned short 
const [usertype] ( *regs )[2]
   drivers/media/usb/usbtv/usbtv-video.c:261:45:got unsigned short 
[usertype] ( * )[2]

vim +261 drivers/media/usb/usbtv/usbtv-video.c

   142  
   143  static int usbtv_select_norm(struct usbtv *usbtv, v4l2_std_id norm)
   144  {
   145  int ret;
   146  /* These are the series of register values used to configure the
   147   * decoder for a specific standard.
   148   * The first 21 register writes are copied from the
   149   * Settings\DecoderDefaults registry keys present in the 
Windows driver
   150   * .INF file, and control various image tuning parameters (color
   151   * correction, sharpness, ...).
   152   */
   153  static const u16 pal[][2] = {
   154  /* "AVPAL" tuning sequence from .INF file */
   155  { USBTV_BASE + 0x0003, 0x0004 },
   156  { USBTV_BASE + 0x001a, 0x0068 },
   157  { USBTV_BASE + 0x0100, 0x00d3 },
   158  { USBTV_BASE + 0x010e, 0x0072 },
   159  { USBTV_BASE + 0x010f, 0x00a2 },
   160  { USBTV_BASE + 0x0112, 0x00b0 },
   161  { USBTV_BASE + 0x0115, 0x0015 },
   162  { USBTV_BASE + 0x0117, 0x0001 },
   163  { USBTV_BASE + 0x0118, 0x002c },
   164  { USBTV_BASE + 0x012d, 0x0010 },
   165  { USBTV_BASE + 0x012f, 0x0020 },
   166  { USBTV_BASE + 0x0220, 0x002e },
   167  { USBTV_BASE + 0x0225, 0x0008 },
   168  { USBTV_BASE + 0x024e, 0x0002 },
   169  { USBTV_BASE + 0x024f, 0x0002 },
   170  { USBTV_BASE + 0x0254, 0x0059 },
   171  { USBTV_BASE + 0x025a, 0x0016 },
   172  { USBTV_BASE + 0x025b, 0x0035 },
   173  { USBTV_BASE + 0x0263, 0x0017 },
   174  { USBTV_BASE + 0x0266, 0x0016 },
   175  { USBTV_BASE + 0x0267, 0x0036 },
   176  /* End image tuning */
   177  { USBTV_BASE + 0x024e, 0x0002 },
   178  { USBTV_BASE + 0x024f, 0x0002 },
   179  };
   180  
   181  static const u16 ntsc[][2] = {
   182  /* "AVNTSC" tuning sequence from .INF file */
   183  { USBTV_BASE + 0x0003, 0x0004 },
   184  { USBTV_BASE + 0x001a, 0x0079 },
   185  { USBTV_BASE + 0x0100, 0x00d3 },
   186  { USBTV_BASE + 0x010e, 0x0068 },
   187  { USBTV_BASE + 0x010f, 0x009c },
   188  { USBTV_BASE + 0x0112, 0x00f0 },
   189  { USBTV_BASE + 0x0115, 0x0015 },
   190  { USBTV_BASE + 0x0117, 0x },
   191  { USBTV_BASE + 0x0118, 0x00fc },
   192  { USBTV_BASE + 0x012d, 0x0004 },
   193  { USBTV_BASE + 0x012f, 0x0008 },
   194  { USBTV_BASE + 0x0220, 0x002e },
   195  { USBTV_BASE + 0x0225, 0x0008 },
   196  { USBTV_BASE + 0x024e, 0x0002 },
   197  { USBTV_BASE + 0x024f, 0x0001 },
   198  { USBTV_BASE + 0x0254, 0x005f },
   199  { USBTV_BASE + 0x025a, 0x0012 },
   200  { USBTV_BASE + 0x025b, 0x0001 },
   201  { USBTV_BASE + 0x0263, 0x001c },
   202  { USBTV_BASE + 0x0266, 0x0011 },
   203  { USBTV_BASE + 0x0267, 0x0005 },
   204  /* End image tuning */
   205  { USBTV_BASE + 0x024e, 0x0002 },
   206  { USBTV_BASE + 0x024f, 0x0002 },
   207  };
   208  
   209  static const u16 secam[][2] = {
   210  /* "AVSECAM" tuning sequence from .INF file */
   211  { USBTV_BASE + 0x0003, 0x0004 },
   212  { USBTV_BASE + 0x001a, 0x0073 },
   213  { USBTV_BASE + 0x0100, 0x00dc },
   214  { USBTV_BASE + 0x010e, 

cron job: media_tree daily build: OK

2018-04-08 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:   Mon Apr  9 05:00:11 CEST 2018
media-tree git hash:17dec0a949153d9ac00760ba2f5b78cb583e995f
media_build git hash:   541653bb52fcf7c34b8b83a4c8cc66b09c68ac37
v4l-utils git hash: 47d43b130dc6e9e0edc900759fb37649208371e4
gcc version:i686-linux-gcc (GCC) 7.3.0
sparse version: v0.5.2-rc1
smatch version: v0.5.0-4419-g3b5bf5c9
host hardware:  x86_64
host os:4.14.0-3-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-arm64: OK
linux-git-i686: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-i686: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-i686: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-i686: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.101-i686: OK
linux-3.0.101-x86_64: OK
linux-3.1.10-i686: OK
linux-3.1.10-x86_64: OK
linux-3.2.101-i686: OK
linux-3.2.101-x86_64: OK
linux-3.3.8-i686: OK
linux-3.3.8-x86_64: OK
linux-3.4.113-i686: OK
linux-3.4.113-x86_64: OK
linux-3.5.7-i686: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-i686: OK
linux-3.6.11-x86_64: OK
linux-3.7.10-i686: OK
linux-3.7.10-x86_64: OK
linux-3.8.13-i686: OK
linux-3.8.13-x86_64: OK
linux-3.9.11-i686: OK
linux-3.9.11-x86_64: OK
linux-3.10.108-i686: OK
linux-3.10.108-x86_64: OK
linux-3.11.10-i686: OK
linux-3.11.10-x86_64: OK
linux-3.12.74-i686: OK
linux-3.12.74-x86_64: OK
linux-3.13.11-i686: OK
linux-3.13.11-x86_64: OK
linux-3.14.79-i686: OK
linux-3.14.79-x86_64: OK
linux-3.15.10-i686: OK
linux-3.15.10-x86_64: OK
linux-3.16.56-i686: OK
linux-3.16.56-x86_64: OK
linux-3.17.8-i686: OK
linux-3.17.8-x86_64: OK
linux-3.18.102-i686: OK
linux-3.18.102-x86_64: OK
linux-3.19.8-i686: OK
linux-3.19.8-x86_64: OK
linux-4.0.9-i686: OK
linux-4.0.9-x86_64: OK
linux-4.1.51-i686: OK
linux-4.1.51-x86_64: OK
linux-4.2.8-i686: OK
linux-4.2.8-x86_64: OK
linux-4.3.6-i686: OK
linux-4.3.6-x86_64: OK
linux-4.4.109-i686: OK
linux-4.4.109-x86_64: OK
linux-4.5.7-i686: OK
linux-4.5.7-x86_64: OK
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: OK
linux-4.7.10-i686: OK
linux-4.7.10-x86_64: OK
linux-4.8.17-i686: OK
linux-4.8.17-x86_64: OK
linux-4.9.91-i686: OK
linux-4.9.91-x86_64: OK
linux-4.14.31-i686: OK
linux-4.14.31-x86_64: OK
linux-4.15.14-i686: OK
linux-4.15.14-x86_64: OK
linux-4.16-i686: OK
linux-4.16-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[PATCH v2 4/6] usbtv: Keep norm parameter specific

2018-04-08 Thread Hugo Grostabussiat
The user-supplied norm value gets overwritten by the generic .norm
member from the norm_params. That way, we lose the specific norm the
user may want to set.

For instance, if the user specifies V4L2_STD_PAL_60, the value actually
used will be V4L2_STD_525_60, which in the end will be as if the user
had specified V4L2_STD_NTSC, since this is always the first bitfield we
match the norm value against before configuring the hardware.

The norm_params array is only there to match a norm with an output
resolution. The norm value itself should not be changed.

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 29e245083247..6cad50d1e5f8 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -77,7 +77,7 @@ static int usbtv_configure_for_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
usbtv->height = params->cap_height;
usbtv->n_chunks = usbtv->width * usbtv->height
/ 4 / USBTV_CHUNK;
-   usbtv->norm = params->norm;
+   usbtv->norm = norm;
} else
ret = -EINVAL;
 
-- 
2.17.0



[PATCH v2 5/6] usbtv: Enforce standard for color decoding

2018-04-08 Thread Hugo Grostabussiat
Depending on the chosen standard, configure the decoder to use the
appropriate color encoding standard (PAL-like, NTSC-like or SECAM).

Until now, the decoder was not configured for a specific color standard,
making it autodetect the color encoding.

While this may sound fine, it potentially causes the wrong image tuning
parameters to be applied (e.g. tuning parameters for NTSC are applied to
a PAL source), and may confuse users about what the actual standard is
in use.

This commit explicitly configures the color standard the decoder will
use, making it visually obvious if a wrong standard was chosen.

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 45 ---
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 6cad50d1e5f8..d0bf5eb217b1 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -121,6 +121,25 @@ static int usbtv_select_input(struct usbtv *usbtv, int 
input)
return ret;
 }
 
+static uint16_t usbtv_norm_to_16f_reg(v4l2_std_id norm)
+{
+   /* NTSC M/M-JP/M-KR */
+   if (norm & V4L2_STD_NTSC)
+   return 0x00b8;
+   /* PAL BG/DK/H/I */
+   if (norm & V4L2_STD_PAL)
+   return 0x00ee;
+   /* SECAM B/D/G/H/K/K1/L/Lc */
+   if (norm & V4L2_STD_SECAM)
+   return 0x00ff;
+   if (norm & V4L2_STD_NTSC_443)
+   return 0x00a8;
+   if (norm & (V4L2_STD_PAL_M | V4L2_STD_PAL_60))
+   return 0x00bc;
+   /* Fallback to automatic detection for other standards */
+   return 0x;
+}
+
 static int usbtv_select_norm(struct usbtv *usbtv, v4l2_std_id norm)
 {
int ret;
@@ -154,7 +173,7 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
{ USBTV_BASE + 0x0263, 0x0017 },
{ USBTV_BASE + 0x0266, 0x0016 },
{ USBTV_BASE + 0x0267, 0x0036 },
-   /* Epilog */
+   /* End image tuning */
{ USBTV_BASE + 0x024e, 0x0002 },
{ USBTV_BASE + 0x024f, 0x0002 },
};
@@ -182,7 +201,7 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
{ USBTV_BASE + 0x0263, 0x001c },
{ USBTV_BASE + 0x0266, 0x0011 },
{ USBTV_BASE + 0x0267, 0x0005 },
-   /* Epilog */
+   /* End image tuning */
{ USBTV_BASE + 0x024e, 0x0002 },
{ USBTV_BASE + 0x024f, 0x0002 },
};
@@ -210,7 +229,7 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
{ USBTV_BASE + 0x0263, 0x0021 },
{ USBTV_BASE + 0x0266, 0x0016 },
{ USBTV_BASE + 0x0267, 0x0036 },
-   /* Epilog */
+   /* End image tuning */
{ USBTV_BASE + 0x024e, 0x0002 },
{ USBTV_BASE + 0x024f, 0x0002 },
};
@@ -218,12 +237,28 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
ret = usbtv_configure_for_norm(usbtv, norm);
 
if (!ret) {
-   if (norm & V4L2_STD_525_60)
+   /* Masks for norms using a NTSC or PAL color encoding. */
+   static const v4l2_std_id ntsc_mask =
+   V4L2_STD_NTSC | V4L2_STD_NTSC_443;
+   static const v4l2_std_id pal_mask =
+   V4L2_STD_PAL | V4L2_STD_PAL_60 | V4L2_STD_PAL_M;
+
+   if (norm & ntsc_mask)
ret = usbtv_set_regs(usbtv, ntsc, ARRAY_SIZE(ntsc));
-   else if (norm & V4L2_STD_PAL)
+   else if (norm & pal_mask)
ret = usbtv_set_regs(usbtv, pal, ARRAY_SIZE(pal));
else if (norm & V4L2_STD_SECAM)
ret = usbtv_set_regs(usbtv, secam, ARRAY_SIZE(secam));
+   else
+   ret = -EINVAL;
+   }
+
+   if (!ret) {
+   /* Configure the decoder for the color standard */
+   u16 cfg[][2] = {
+   { USBTV_BASE + 0x016f, usbtv_norm_to_16f_reg(norm) }
+   };
+   ret = usbtv_set_regs(usbtv, cfg, ARRAY_SIZE(cfg));
}
 
return ret;
-- 
2.17.0



[PATCH v2 2/6] usbtv: Add SECAM support

2018-04-08 Thread Hugo Grostabussiat
Add support for the SECAM norm, using the "AVSECAM" decoder configuration
sequence found in Windows driver's .INF file.

For reference, the "AVSECAM" sequence in the .INF file is:
0x04,0x73,0xDC,0x72,0xA2,0x90,0x35,0x01,0x30,0x04,0x08,0x2D,0x28,0x08,
0x02,0x69,0x16,0x35,0x21,0x16,0x36

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 38 ++-
 drivers/media/usb/usbtv/usbtv.h   |  2 +-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 97f9790954f9..6b0a10173388 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -57,6 +57,11 @@ static struct usbtv_norm_params norm_params[] = {
.norm = V4L2_STD_PAL,
.cap_width = 720,
.cap_height = 576,
+   },
+   {
+   .norm = V4L2_STD_SECAM,
+   .cap_width = 720,
+   .cap_height = 576,
}
 };
 
@@ -187,6 +192,34 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
{ USBTV_BASE + 0x024f, 0x0002 },
};
 
+   static const u16 secam[][2] = {
+   /* "AVSECAM" tuning sequence from .INF file */
+   { USBTV_BASE + 0x0003, 0x0004 },
+   { USBTV_BASE + 0x001a, 0x0073 },
+   { USBTV_BASE + 0x0100, 0x00dc },
+   { USBTV_BASE + 0x010e, 0x0072 },
+   { USBTV_BASE + 0x010f, 0x00a2 },
+   { USBTV_BASE + 0x0112, 0x0090 },
+   { USBTV_BASE + 0x0115, 0x0035 },
+   { USBTV_BASE + 0x0117, 0x0001 },
+   { USBTV_BASE + 0x0118, 0x0030 },
+   { USBTV_BASE + 0x012d, 0x0004 },
+   { USBTV_BASE + 0x012f, 0x0008 },
+   { USBTV_BASE + 0x0220, 0x002d },
+   { USBTV_BASE + 0x0225, 0x0028 },
+   { USBTV_BASE + 0x024e, 0x0008 },
+   { USBTV_BASE + 0x024f, 0x0002 },
+   { USBTV_BASE + 0x0254, 0x0069 },
+   { USBTV_BASE + 0x025a, 0x0016 },
+   { USBTV_BASE + 0x025b, 0x0035 },
+   { USBTV_BASE + 0x0263, 0x0021 },
+   { USBTV_BASE + 0x0266, 0x0016 },
+   { USBTV_BASE + 0x0267, 0x0036 },
+   /* Epilog */
+   { USBTV_BASE + 0x024e, 0x0002 },
+   { USBTV_BASE + 0x024f, 0x0002 },
+   };
+
ret = usbtv_configure_for_norm(usbtv, norm);
 
if (!ret) {
@@ -194,6 +227,8 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
ret = usbtv_set_regs(usbtv, ntsc, ARRAY_SIZE(ntsc));
else if (norm & V4L2_STD_PAL)
ret = usbtv_set_regs(usbtv, pal, ARRAY_SIZE(pal));
+   else if (norm & V4L2_STD_SECAM)
+   ret = usbtv_set_regs(usbtv, secam, ARRAY_SIZE(secam));
}
 
return ret;
@@ -605,7 +640,8 @@ static int usbtv_s_std(struct file *file, void *priv, 
v4l2_std_id norm)
int ret = -EINVAL;
struct usbtv *usbtv = video_drvdata(file);
 
-   if ((norm & V4L2_STD_525_60) || (norm & V4L2_STD_PAL))
+   if ((norm & V4L2_STD_525_60) || (norm & V4L2_STD_PAL) ||
+   (norm & V4L2_STD_SECAM))
ret = usbtv_select_norm(usbtv, norm);
 
return ret;
diff --git a/drivers/media/usb/usbtv/usbtv.h b/drivers/media/usb/usbtv/usbtv.h
index 0231e449877e..77a368e90fd0 100644
--- a/drivers/media/usb/usbtv/usbtv.h
+++ b/drivers/media/usb/usbtv/usbtv.h
@@ -68,7 +68,7 @@
 #define USBTV_ODD(chunk)   ((be32_to_cpu(chunk[0]) & 0xf000) >> 15)
 #define USBTV_CHUNK_NO(chunk)  (be32_to_cpu(chunk[0]) & 0x0fff)
 
-#define USBTV_TV_STD  (V4L2_STD_525_60 | V4L2_STD_PAL)
+#define USBTV_TV_STD  (V4L2_STD_525_60 | V4L2_STD_PAL | V4L2_STD_SECAM)
 
 /* parameters for supported TV norms */
 struct usbtv_norm_params {
-- 
2.17.0



[PATCH v2 1/6] usbtv: Use same decoder sequence as Windows driver

2018-04-08 Thread Hugo Grostabussiat
Re-format the register {address, value} pairs so they follow the same
order as the decoder configuration sequences in the Windows driver's .INF
file.

For instance, for PAL, the "AVPAL" sequence in the .INF file is:
0x04,0x68,0xD3,0x72,0xA2,0xB0,0x15,0x01,0x2C,0x10,0x20,0x2e,0x08,0x02,
0x02,0x59,0x16,0x35,0x17,0x16,0x36

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 40 +++
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 3668a04359e8..97f9790954f9 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -124,40 +124,67 @@ static int usbtv_select_input(struct usbtv *usbtv, int 
input)
 static int usbtv_select_norm(struct usbtv *usbtv, v4l2_std_id norm)
 {
int ret;
+   /* These are the series of register values used to configure the
+* decoder for a specific standard.
+* The first 21 register writes are copied from the
+* Settings\DecoderDefaults registry keys present in the Windows driver
+* .INF file, and control various image tuning parameters (color
+* correction, sharpness, ...).
+*/
static const u16 pal[][2] = {
+   /* "AVPAL" tuning sequence from .INF file */
+   { USBTV_BASE + 0x0003, 0x0004 },
{ USBTV_BASE + 0x001a, 0x0068 },
+   { USBTV_BASE + 0x0100, 0x00d3 },
{ USBTV_BASE + 0x010e, 0x0072 },
{ USBTV_BASE + 0x010f, 0x00a2 },
{ USBTV_BASE + 0x0112, 0x00b0 },
+   { USBTV_BASE + 0x0115, 0x0015 },
{ USBTV_BASE + 0x0117, 0x0001 },
{ USBTV_BASE + 0x0118, 0x002c },
{ USBTV_BASE + 0x012d, 0x0010 },
{ USBTV_BASE + 0x012f, 0x0020 },
+   { USBTV_BASE + 0x0220, 0x002e },
+   { USBTV_BASE + 0x0225, 0x0008 },
+   { USBTV_BASE + 0x024e, 0x0002 },
{ USBTV_BASE + 0x024f, 0x0002 },
{ USBTV_BASE + 0x0254, 0x0059 },
{ USBTV_BASE + 0x025a, 0x0016 },
{ USBTV_BASE + 0x025b, 0x0035 },
{ USBTV_BASE + 0x0263, 0x0017 },
{ USBTV_BASE + 0x0266, 0x0016 },
-   { USBTV_BASE + 0x0267, 0x0036 }
+   { USBTV_BASE + 0x0267, 0x0036 },
+   /* Epilog */
+   { USBTV_BASE + 0x024e, 0x0002 },
+   { USBTV_BASE + 0x024f, 0x0002 },
};
 
static const u16 ntsc[][2] = {
+   /* "AVNTSC" tuning sequence from .INF file */
+   { USBTV_BASE + 0x0003, 0x0004 },
{ USBTV_BASE + 0x001a, 0x0079 },
+   { USBTV_BASE + 0x0100, 0x00d3 },
{ USBTV_BASE + 0x010e, 0x0068 },
{ USBTV_BASE + 0x010f, 0x009c },
{ USBTV_BASE + 0x0112, 0x00f0 },
+   { USBTV_BASE + 0x0115, 0x0015 },
{ USBTV_BASE + 0x0117, 0x },
{ USBTV_BASE + 0x0118, 0x00fc },
{ USBTV_BASE + 0x012d, 0x0004 },
{ USBTV_BASE + 0x012f, 0x0008 },
+   { USBTV_BASE + 0x0220, 0x002e },
+   { USBTV_BASE + 0x0225, 0x0008 },
+   { USBTV_BASE + 0x024e, 0x0002 },
{ USBTV_BASE + 0x024f, 0x0001 },
{ USBTV_BASE + 0x0254, 0x005f },
{ USBTV_BASE + 0x025a, 0x0012 },
{ USBTV_BASE + 0x025b, 0x0001 },
{ USBTV_BASE + 0x0263, 0x001c },
{ USBTV_BASE + 0x0266, 0x0011 },
-   { USBTV_BASE + 0x0267, 0x0005 }
+   { USBTV_BASE + 0x0267, 0x0005 },
+   /* Epilog */
+   { USBTV_BASE + 0x024e, 0x0002 },
+   { USBTV_BASE + 0x024f, 0x0002 },
};
 
ret = usbtv_configure_for_norm(usbtv, norm);
@@ -236,15 +263,6 @@ static int usbtv_setup_capture(struct usbtv *usbtv)
{ USBTV_BASE + 0x0158, 0x001f },
{ USBTV_BASE + 0x0159, 0x0006 },
{ USBTV_BASE + 0x015d, 0x },
-
-   { USBTV_BASE + 0x0003, 0x0004 },
-   { USBTV_BASE + 0x0100, 0x00d3 },
-   { USBTV_BASE + 0x0115, 0x0015 },
-   { USBTV_BASE + 0x0220, 0x002e },
-   { USBTV_BASE + 0x0225, 0x0008 },
-   { USBTV_BASE + 0x024e, 0x0002 },
-   { USBTV_BASE + 0x024e, 0x0002 },
-   { USBTV_BASE + 0x024f, 0x0002 },
};
 
ret = usbtv_set_regs(usbtv, setup, ARRAY_SIZE(setup));
-- 
2.17.0



[PATCH v2 6/6] usbtv: Use the constant for supported standards

2018-04-08 Thread Hugo Grostabussiat
Use the USBTV_TV_STD define instead of repeating ourselves.

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index d0bf5eb217b1..eda51dbf063b 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -670,8 +670,7 @@ static int usbtv_s_std(struct file *file, void *priv, 
v4l2_std_id norm)
int ret = -EINVAL;
struct usbtv *usbtv = video_drvdata(file);
 
-   if ((norm & V4L2_STD_525_60) || (norm & V4L2_STD_PAL) ||
-   (norm & V4L2_STD_SECAM))
+   if (norm & USBTV_TV_STD)
ret = usbtv_select_norm(usbtv, norm);
 
return ret;
-- 
2.17.0



[PATCH v2 0/6] usbtv: Add SECAM support and fix color encoding selection

2018-04-08 Thread Hugo Grostabussiat
This series adds SECAM support to the usbtv driver, while
also attempting to mimic the Windows driver's behavior
regarding color encoding selection.

I made USB captures of the device as it is set up by the Windows driver,
for all the supported video standards. The analog source used is the
composite output of a video card, which is configured to output a signal
using the same standard as the one configured for the capture, when that
is possible. This enabled me to find new values for the 0x016f register
that I had missed in the v1, as well as test my patches.
Unfortunately, I did not have a SECAM source for the tests, so they were
limited to setting the standard to SECAM for a PAL source, and making
sure the output was the same between the Windows and the Linux driver.

The capture adapter used for the tests is a QSonic VG-310, with USB ID
1b71:3002. The Windows driver used as reference is EasyCap driver
version 2.1.1.2 (2011-06-08).

The changes since the v1 are:
- the output resolution is selected independently of the color encoding.
  For instance, PAL-M, while using a PAL-like color encoding, has the
  same resolution as NTSC-M, so the NTSC resolution will be used in that
  case
- conversely, the color encoding is configured independently of the
  resolution
- PAL and NTSC variants have a different value for register 0x016f
- the norm value set by the user is no longer overwritten by the driver
  with a generic value when selecting the output resolution, so specific
  standards (e.g. NTSC-443) can actually be selected
- minor cosmetic changes

Hugo Grostabussiat (6):
  usbtv: Use same decoder sequence as Windows driver
  usbtv: Add SECAM support
  usbtv: Use V4L2 defines to select capture resolution
  usbtv: Keep norm parameter specific
  usbtv: Enforce standard for color decoding
  usbtv: Use the constant for supported standards

 drivers/media/usb/usbtv/usbtv-video.c | 115 ++
 drivers/media/usb/usbtv/usbtv.h   |   2 +-
 2 files changed, 100 insertions(+), 17 deletions(-)

-- 
2.17.0



[PATCH v2 3/6] usbtv: Use V4L2 defines to select capture resolution

2018-04-08 Thread Hugo Grostabussiat
Make use of the V4L2_STD_525_60 and V4L2_STD_625_50 defines to
determine the vertical resolution to use when capturing.

V4L2_STD_525_60 (resp. V4L2_STD_625_50) is the set of standards using
525 (resp. 625) lines per frame, independently of the color encoding.

Signed-off-by: Hugo Grostabussiat 
---
 drivers/media/usb/usbtv/usbtv-video.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 6b0a10173388..29e245083247 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -54,12 +54,7 @@ static struct usbtv_norm_params norm_params[] = {
.cap_height = 480,
},
{
-   .norm = V4L2_STD_PAL,
-   .cap_width = 720,
-   .cap_height = 576,
-   },
-   {
-   .norm = V4L2_STD_SECAM,
+   .norm = V4L2_STD_625_50,
.cap_width = 720,
.cap_height = 576,
}
-- 
2.17.0



[PATCH v2 4/7] media: rc: mce_kbd decoder: low timeout values cause double keydowns

2018-04-08 Thread Sean Young
The mce keyboard repeats pressed keys every 100ms. If the IR timeout
is set to less than that, we send key up events before the repeat
arrives, so we have key up/key down for each IR repeat.

The keyboard ends any sequence with a 0 scancode, in which case all keys
are cleared so there is no need to run the timeout timer: it only exists
for the case that the final 0 was not received.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-mce_kbd-decoder.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index ae4b980c4a16..230b9397aa11 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -322,11 +322,13 @@ static int ir_mce_kbd_decode(struct rc_dev *dev, struct 
ir_raw_event ev)
scancode = data->body & 0x;
dev_dbg(>dev, "keyboard data 0x%08x\n",
data->body);
-   if (dev->timeout)
-   delay = usecs_to_jiffies(dev->timeout / 1000);
-   else
-   delay = msecs_to_jiffies(100);
-   mod_timer(>rx_timeout, jiffies + delay);
+   if (scancode) {
+   delay = nsecs_to_jiffies(dev->timeout) +
+   msecs_to_jiffies(100);
+   mod_timer(>rx_timeout, jiffies + delay);
+   } else {
+   del_timer(>rx_timeout);
+   }
/* Pass data to keyboard buffer parser */
ir_mce_kbd_process_keyboard_data(dev, scancode);
lsc.rc_proto = RC_PROTO_MCIR2_KBD;
-- 
2.14.3



[PATCH v2 7/7] media: rc: mceusb: allow the timeout to be configurable

2018-04-08 Thread Sean Young
mceusb devices have a default timeout of 100ms, but this can be changed.

Signed-off-by: Sean Young 
---
 drivers/media/rc/mceusb.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 69ba57372c05..c97cb2eb1c5f 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -982,6 +982,25 @@ static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 
carrier)
return 0;
 }
 
+static int mceusb_set_timeout(struct rc_dev *dev, unsigned int timeout)
+{
+   u8 cmdbuf[4] = { MCE_CMD_PORT_IR, MCE_CMD_SETIRTIMEOUT, 0, 0 };
+   struct mceusb_dev *ir = dev->priv;
+   unsigned int units;
+
+   units = DIV_ROUND_CLOSEST(timeout, US_TO_NS(MCE_TIME_UNIT));
+
+   cmdbuf[2] = units >> 8;
+   cmdbuf[3] = units;
+
+   mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
+
+   /* get receiver timeout value */
+   mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT));
+
+   return 0;
+}
+
 /*
  * Select or deselect the 2nd receiver port.
  * Second receiver is learning mode, wide-band, short-range receiver.
@@ -1415,7 +1434,10 @@ static struct rc_dev *mceusb_init_rc_dev(struct 
mceusb_dev *ir)
rc->dev.parent = dev;
rc->priv = ir;
rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
+   rc->min_timeout = US_TO_NS(MCE_TIME_UNIT);
rc->timeout = MS_TO_NS(100);
+   rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
+   rc->s_timeout = mceusb_set_timeout;
if (!ir->flags.no_tx) {
rc->s_tx_mask = mceusb_set_tx_mask;
rc->s_tx_carrier = mceusb_set_tx_carrier;
-- 
2.14.3



[PATCH v2 2/7] media: rc: add ioctl to get the current timeout

2018-04-08 Thread Sean Young
Since the kernel now modifies the timeout, make it possible to retrieve
the current value.

Signed-off-by: Sean Young 
---
 Documentation/media/uapi/rc/lirc-func.rst|  1 +
 Documentation/media/uapi/rc/lirc-set-rec-timeout.rst | 14 +-
 drivers/media/rc/lirc_dev.c  |  7 +++
 include/uapi/linux/lirc.h|  6 ++
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/Documentation/media/uapi/rc/lirc-func.rst 
b/Documentation/media/uapi/rc/lirc-func.rst
index ddb4620de294..9656423a3f28 100644
--- a/Documentation/media/uapi/rc/lirc-func.rst
+++ b/Documentation/media/uapi/rc/lirc-func.rst
@@ -17,6 +17,7 @@ LIRC Function Reference
 lirc-get-rec-resolution
 lirc-set-send-duty-cycle
 lirc-get-timeout
+lirc-get-rec-timeout
 lirc-set-rec-timeout
 lirc-set-rec-carrier
 lirc-set-rec-carrier-range
diff --git a/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst 
b/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst
index b3e16bbdbc90..a833a6a4c25a 100644
--- a/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst
+++ b/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst
@@ -1,19 +1,23 @@
 .. -*- coding: utf-8; mode: rst -*-
 
 .. _lirc_set_rec_timeout:
+.. _lirc_get_rec_timeout:
 
-**
-ioctl LIRC_SET_REC_TIMEOUT
-**
+***
+ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT
+***
 
 Name
 
 
-LIRC_SET_REC_TIMEOUT - sets the integer value for IR inactivity timeout.
+LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR 
inactivity timeout.
 
 Synopsis
 
 
+.. c:function:: int ioctl( int fd, LIRC_GET_REC_TIMEOUT, __u32 *timeout )
+:name: LIRC_GET_REC_TIMEOUT
+
 .. c:function:: int ioctl( int fd, LIRC_SET_REC_TIMEOUT, __u32 *timeout )
 :name: LIRC_SET_REC_TIMEOUT
 
@@ -30,7 +34,7 @@ Arguments
 Description
 ===
 
-Sets the integer value for IR inactivity timeout.
+Get and set the integer value for IR inactivity timeout.
 
 If supported by the hardware, setting it to 0  disables all hardware timeouts
 and data should be reported as soon as possible. If the exact value
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 247e6fc3dc0c..6b4755e9fa25 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -575,6 +575,13 @@ static long ir_lirc_ioctl(struct file *file, unsigned int 
cmd,
}
break;
 
+   case LIRC_GET_REC_TIMEOUT:
+   if (!dev->timeout)
+   ret = -ENOTTY;
+   else
+   val = DIV_ROUND_UP(dev->timeout, 1000);
+   break;
+
case LIRC_SET_REC_TIMEOUT_REPORTS:
if (!dev->timeout)
ret = -ENOTTY;
diff --git a/include/uapi/linux/lirc.h b/include/uapi/linux/lirc.h
index f189931042a7..6b319581882f 100644
--- a/include/uapi/linux/lirc.h
+++ b/include/uapi/linux/lirc.h
@@ -133,6 +133,12 @@
 
 #define LIRC_SET_WIDEBAND_RECEIVER _IOW('i', 0x0023, __u32)
 
+/*
+ * Return the recording timeout, which is either set by
+ * the ioctl LIRC_SET_REC_TIMEOUT or by the kernel after setting the protocols.
+ */
+#define LIRC_GET_REC_TIMEOUT  _IOR('i', 0x0024, __u32)
+
 /*
  * struct lirc_scancode - decoded scancode with protocol for use with
  * LIRC_MODE_SCANCODE
-- 
2.14.3



[PATCH v2 5/7] media: rc: mce_kbd protocol encodes two scancodes

2018-04-08 Thread Sean Young
If two keys are pressed, then both keys are encoded in the scancode. This
makes the mce keyboard more responsive.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-mce_kbd-decoder.c | 21 -
 drivers/media/rc/rc-main.c|  2 +-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index 230b9397aa11..dcdba83290d2 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -147,13 +147,14 @@ static enum mce_kbd_mode mce_kbd_mode(struct mce_kbd_dec 
*data)
 static void ir_mce_kbd_process_keyboard_data(struct rc_dev *dev, u32 scancode)
 {
struct mce_kbd_dec *data = >raw->mce_kbd;
-   u8 keydata   = (scancode >> 8) & 0xff;
+   u8 keydata1  = (scancode >> 8) & 0xff;
+   u8 keydata2  = (scancode >> 16) & 0xff;
u8 shiftmask = scancode & 0xff;
-   unsigned char keycode, maskcode;
+   unsigned char maskcode;
int i, keystate;
 
-   dev_dbg(>dev, "keyboard: keydata = 0x%02x, shiftmask = 0x%02x\n",
-   keydata, shiftmask);
+   dev_dbg(>dev, "keyboard: keydata2 = 0x%02x, keydata1 = 0x%02x, 
shiftmask = 0x%02x\n",
+   keydata2, keydata1, shiftmask);
 
for (i = 0; i < 7; i++) {
maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START + i];
@@ -164,10 +165,12 @@ static void ir_mce_kbd_process_keyboard_data(struct 
rc_dev *dev, u32 scancode)
input_report_key(data->idev, maskcode, keystate);
}
 
-   if (keydata) {
-   keycode = kbd_keycodes[keydata];
-   input_report_key(data->idev, keycode, 1);
-   } else {
+   if (keydata1)
+   input_report_key(data->idev, kbd_keycodes[keydata1], 1);
+   if (keydata2)
+   input_report_key(data->idev, kbd_keycodes[keydata2], 1);
+
+   if (!keydata1 && !keydata2) {
for (i = 0; i < MCIR2_MASK_KEYS_START; i++)
input_report_key(data->idev, kbd_keycodes[i], 0);
}
@@ -319,7 +322,7 @@ static int ir_mce_kbd_decode(struct rc_dev *dev, struct 
ir_raw_event ev)
 
switch (data->wanted_bits) {
case MCIR2_KEYBOARD_NBITS:
-   scancode = data->body & 0x;
+   scancode = data->body & 0xff;
dev_dbg(>dev, "keyboard data 0x%08x\n",
data->body);
if (scancode) {
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 9f4df60f62e1..b7071bde670a 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -51,7 +51,7 @@ static const struct {
[RC_PROTO_SANYO] = { .name = "sanyo",
.scancode_bits = 0x1f, .repeat_period = 125 },
[RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd",
-   .scancode_bits = 0x, .repeat_period = 100 },
+   .scancode_bits = 0xff, .repeat_period = 100 },
[RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse",
.scancode_bits = 0x1f, .repeat_period = 100 },
[RC_PROTO_RC6_0] = { .name = "rc-6-0",
-- 
2.14.3



[PATCH v2 6/7] media: rc: mce_kbd decoder: fix stuck keys

2018-04-08 Thread Sean Young
The MCE Remote sends a 0 scancode when keys are released. If this is not
received or decoded, then keys can get "stuck"; the keyup event is not
sent since the input_sync() is missing from the timeout handler.

Cc: sta...@vger.kernel.org
Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-mce_kbd-decoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index dcdba83290d2..a6adf54461e9 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -130,6 +130,8 @@ static void mce_kbd_rx_timeout(struct timer_list *t)
 
for (i = 0; i < MCIR2_MASK_KEYS_START; i++)
input_report_key(raw->mce_kbd.idev, kbd_keycodes[i], 0);
+
+   input_sync(raw->mce_kbd.idev);
 }
 
 static enum mce_kbd_mode mce_kbd_mode(struct mce_kbd_dec *data)
-- 
2.14.3



[PATCH v2 1/7] media: rc: set timeout to smallest value required by enabled protocols

2018-04-08 Thread Sean Young
The longer the IR timeout, the longer the rc device waits until delivering
the trailing space. So, by reducing this timeout, we reduce the delay for
the last scancode to be delivered.

Note that the lirc daemon disables all protocols, in which case we revert
back to the default value.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-imon-decoder.c|  1 +
 drivers/media/rc/ir-jvc-decoder.c |  1 +
 drivers/media/rc/ir-mce_kbd-decoder.c |  1 +
 drivers/media/rc/ir-nec-decoder.c |  1 +
 drivers/media/rc/ir-rc5-decoder.c |  1 +
 drivers/media/rc/ir-rc6-decoder.c |  1 +
 drivers/media/rc/ir-sanyo-decoder.c   |  1 +
 drivers/media/rc/ir-sharp-decoder.c   |  1 +
 drivers/media/rc/ir-sony-decoder.c|  1 +
 drivers/media/rc/ir-xmp-decoder.c |  1 +
 drivers/media/rc/rc-core-priv.h   |  1 +
 drivers/media/rc/rc-ir-raw.c  | 31 ++-
 drivers/media/rc/rc-main.c| 12 ++--
 13 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/drivers/media/rc/ir-imon-decoder.c 
b/drivers/media/rc/ir-imon-decoder.c
index a1ff06a26542..9024b359e5ee 100644
--- a/drivers/media/rc/ir-imon-decoder.c
+++ b/drivers/media/rc/ir-imon-decoder.c
@@ -170,6 +170,7 @@ static struct ir_raw_handler imon_handler = {
.decode = ir_imon_decode,
.encode = ir_imon_encode,
.carrier= 38000,
+   .max_space  = IMON_UNIT * IMON_BITS * 2,
 };
 
 static int __init ir_imon_decode_init(void)
diff --git a/drivers/media/rc/ir-jvc-decoder.c 
b/drivers/media/rc/ir-jvc-decoder.c
index 8cb68ae43282..190c690b14f8 100644
--- a/drivers/media/rc/ir-jvc-decoder.c
+++ b/drivers/media/rc/ir-jvc-decoder.c
@@ -213,6 +213,7 @@ static struct ir_raw_handler jvc_handler = {
.decode = ir_jvc_decode,
.encode = ir_jvc_encode,
.carrier= 38000,
+   .max_space  = JVC_TRAILER_SPACE,
 };
 
 static int __init ir_jvc_decode_init(void)
diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index c110984ca671..ae4b980c4a16 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -475,6 +475,7 @@ static struct ir_raw_handler mce_kbd_handler = {
.raw_register   = ir_mce_kbd_register,
.raw_unregister = ir_mce_kbd_unregister,
.carrier= 36000,
+   .max_space  = MCIR2_MAX_LEN,
 };
 
 static int __init ir_mce_kbd_decode_init(void)
diff --git a/drivers/media/rc/ir-nec-decoder.c 
b/drivers/media/rc/ir-nec-decoder.c
index 21647b809e6f..fac12f867a81 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -253,6 +253,7 @@ static struct ir_raw_handler nec_handler = {
.decode = ir_nec_decode,
.encode = ir_nec_encode,
.carrier= 38000,
+   .max_space  = NEC_TRAILER_SPACE,
 };
 
 static int __init ir_nec_decode_init(void)
diff --git a/drivers/media/rc/ir-rc5-decoder.c 
b/drivers/media/rc/ir-rc5-decoder.c
index 74d3b859c3a2..711068c8de90 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -274,6 +274,7 @@ static struct ir_raw_handler rc5_handler = {
.decode = ir_rc5_decode,
.encode = ir_rc5_encode,
.carrier= 36000,
+   .max_space  = RC5_TRAILER,
 };
 
 static int __init ir_rc5_decode_init(void)
diff --git a/drivers/media/rc/ir-rc6-decoder.c 
b/drivers/media/rc/ir-rc6-decoder.c
index 8314da32453f..9cc4820878c7 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -394,6 +394,7 @@ static struct ir_raw_handler rc6_handler = {
.decode = ir_rc6_decode,
.encode = ir_rc6_encode,
.carrier= 36000,
+   .max_space  = RC6_SUFFIX_SPACE,
 };
 
 static int __init ir_rc6_decode_init(void)
diff --git a/drivers/media/rc/ir-sanyo-decoder.c 
b/drivers/media/rc/ir-sanyo-decoder.c
index 4efe6db5376a..e72787b446c9 100644
--- a/drivers/media/rc/ir-sanyo-decoder.c
+++ b/drivers/media/rc/ir-sanyo-decoder.c
@@ -210,6 +210,7 @@ static struct ir_raw_handler sanyo_handler = {
.decode = ir_sanyo_decode,
.encode = ir_sanyo_encode,
.carrier= 38000,
+   .max_space  = SANYO_TRAILER_SPACE,
 };
 
 static int __init ir_sanyo_decode_init(void)
diff --git a/drivers/media/rc/ir-sharp-decoder.c 
b/drivers/media/rc/ir-sharp-decoder.c
index 6a38c50566a4..e7e3841a6eb0 100644
--- a/drivers/media/rc/ir-sharp-decoder.c
+++ b/drivers/media/rc/ir-sharp-decoder.c
@@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = {
.decode = ir_sharp_decode,
.encode = ir_sharp_encode,
.carrier= 38000,
+   .max_space  = SHARP_ECHO_SPACE,
 };
 
 static int __init ir_sharp_decode_init(void)
diff --git a/drivers/media/rc/ir-sony-decoder.c 

[PATCH v2 3/7] media: rc: per-protocol repeat period and minimum keyup timer

2018-04-08 Thread Sean Young
Each IR protocol has its own repeat period. We can minimise the keyup
timer to be the protocol period + IR timeout. This makes keys less
"sticky" and makes IR more reactive and nicer to use.

This feature was previously attempted in commit d57ea877af38 ("media: rc:
per-protocol repeat period"), but that did not take the IR timeout into
account, and had to be reverted.

Signed-off-by: Sean Young 
---
 drivers/media/cec/cec-core.c |  2 +-
 drivers/media/rc/lirc_dev.c  |  2 +-
 drivers/media/rc/rc-main.c   | 56 +++-
 3 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index b0c87f9ea08f..b278ab90b387 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -322,7 +322,7 @@ struct cec_adapter *cec_allocate_adapter(const struct 
cec_adap_ops *ops,
adap->rc->allowed_protocols = RC_PROTO_BIT_CEC;
adap->rc->priv = adap;
adap->rc->map_name = RC_MAP_CEC;
-   adap->rc->timeout = MS_TO_NS(100);
+   adap->rc->timeout = MS_TO_NS(550);
 #endif
return adap;
 }
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 6b4755e9fa25..cc58ed78462f 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -583,7 +583,7 @@ static long ir_lirc_ioctl(struct file *file, unsigned int 
cmd,
break;
 
case LIRC_SET_REC_TIMEOUT_REPORTS:
-   if (!dev->timeout)
+   if (dev->driver_type != RC_DRIVER_IR_RAW)
ret = -ENOTTY;
else
fh->send_timeout_reports = !!val;
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 6a720e9c7aa8..9f4df60f62e1 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -26,50 +26,50 @@ static const struct {
unsigned int repeat_period;
unsigned int scancode_bits;
 } protocols[] = {
-   [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 250 },
-   [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 250 },
+   [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 125 },
+   [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 125 },
[RC_PROTO_RC5] = { .name = "rc-5",
-   .scancode_bits = 0x1f7f, .repeat_period = 250 },
+   .scancode_bits = 0x1f7f, .repeat_period = 114 },
[RC_PROTO_RC5X_20] = { .name = "rc-5x-20",
-   .scancode_bits = 0x1f7f3f, .repeat_period = 250 },
+   .scancode_bits = 0x1f7f3f, .repeat_period = 114 },
[RC_PROTO_RC5_SZ] = { .name = "rc-5-sz",
-   .scancode_bits = 0x2fff, .repeat_period = 250 },
+   .scancode_bits = 0x2fff, .repeat_period = 114 },
[RC_PROTO_JVC] = { .name = "jvc",
-   .scancode_bits = 0x, .repeat_period = 250 },
+   .scancode_bits = 0x, .repeat_period = 125 },
[RC_PROTO_SONY12] = { .name = "sony-12",
-   .scancode_bits = 0x1f007f, .repeat_period = 250 },
+   .scancode_bits = 0x1f007f, .repeat_period = 100 },
[RC_PROTO_SONY15] = { .name = "sony-15",
-   .scancode_bits = 0xff007f, .repeat_period = 250 },
+   .scancode_bits = 0xff007f, .repeat_period = 100 },
[RC_PROTO_SONY20] = { .name = "sony-20",
-   .scancode_bits = 0x1fff7f, .repeat_period = 250 },
+   .scancode_bits = 0x1fff7f, .repeat_period = 100 },
[RC_PROTO_NEC] = { .name = "nec",
-   .scancode_bits = 0x, .repeat_period = 250 },
+   .scancode_bits = 0x, .repeat_period = 110 },
[RC_PROTO_NECX] = { .name = "nec-x",
-   .scancode_bits = 0xff, .repeat_period = 250 },
+   .scancode_bits = 0xff, .repeat_period = 110 },
[RC_PROTO_NEC32] = { .name = "nec-32",
-   .scancode_bits = 0x, .repeat_period = 250 },
+   .scancode_bits = 0x, .repeat_period = 110 },
[RC_PROTO_SANYO] = { .name = "sanyo",
-   .scancode_bits = 0x1f, .repeat_period = 250 },
+   .scancode_bits = 0x1f, .repeat_period = 125 },
[RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd",
-   .scancode_bits = 0x, .repeat_period = 250 },
+   .scancode_bits = 0x, .repeat_period = 100 },
[RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse",
-   .scancode_bits = 0x1f, .repeat_period = 250 },
+   .scancode_bits = 0x1f, .repeat_period = 100 },
[RC_PROTO_RC6_0] = { .name = "rc-6-0",
-   .scancode_bits = 0x, .repeat_period = 250 },
+   .scancode_bits = 0x, .repeat_period = 114 },
[RC_PROTO_RC6_6A_20] = { .name = "rc-6-6a-20",
-   .scancode_bits = 0xf, .repeat_period = 250 },
+   .scancode_bits = 0xf, .repeat_period = 114 },
 

[PATCH v2 0/7] Improve latency of IR decoding

2018-04-08 Thread Sean Young
The current IR decoding is much too slow. Many IR protocols rely on
a trailing space for decoding (e.g. rc-6 needs to know when the bits
end). The trailing space is generated by the IR timeout, and if this
is longer than required, buttons can feel slow to respond.

The other issue is the keyup timer. IR has no concept of a keyup message,
this is implied by the absence of IR. So, minimising the timeout for
this makes buttons less "sticky"; the are released much quicker.

With these patches in place, using IR with the builtin decoders is much
improved and feels very snappy.

Changes since v1:
 - lost more testing
 - fixed various issues with mce decoder
 - fixed mceusb so it can use better timeout too

Sean Young (7):
  media: rc: set timeout to smallest value required by enabled protocols
  media: rc: add ioctl to get the current timeout
  media: rc: per-protocol repeat period and minimum keyup timer
  media: rc: mce_kbd decoder: low timeout values cause double keydowns
  media: rc: mce_kbd protocol encodes two scancodes
  media: rc: mce_kbd decoder: fix stuck keys
  media: rc: mceusb: allow the timeout to be configurable

 Documentation/media/uapi/rc/lirc-func.rst  |  1 +
 .../media/uapi/rc/lirc-set-rec-timeout.rst | 14 +++--
 drivers/media/cec/cec-core.c   |  2 +-
 drivers/media/rc/ir-imon-decoder.c |  1 +
 drivers/media/rc/ir-jvc-decoder.c  |  1 +
 drivers/media/rc/ir-mce_kbd-decoder.c  | 36 +++-
 drivers/media/rc/ir-nec-decoder.c  |  1 +
 drivers/media/rc/ir-rc5-decoder.c  |  1 +
 drivers/media/rc/ir-rc6-decoder.c  |  1 +
 drivers/media/rc/ir-sanyo-decoder.c|  1 +
 drivers/media/rc/ir-sharp-decoder.c|  1 +
 drivers/media/rc/ir-sony-decoder.c |  1 +
 drivers/media/rc/ir-xmp-decoder.c  |  1 +
 drivers/media/rc/lirc_dev.c|  9 ++-
 drivers/media/rc/mceusb.c  | 22 +++
 drivers/media/rc/rc-core-priv.h|  1 +
 drivers/media/rc/rc-ir-raw.c   | 31 +-
 drivers/media/rc/rc-main.c | 68 +++---
 include/uapi/linux/lirc.h  |  6 ++
 19 files changed, 144 insertions(+), 55 deletions(-)

-- 
2.14.3



Re: Regression: DVBSky S960 USB tuner doesn't work in 4.10 or newer

2018-04-08 Thread Olli Salonen
I created a report of the issue in Bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=199323

I'd be grateful for any tips on how to debug this further.

Cheers,
-olli

On 4 April 2018 at 14:41, Olli Salonen  wrote:
> Hello Peter and Max,
>
> I noticed that when using kernel 4.10 or newer my DVBSky S960 and
> S960CI satellite USB TV tuners stopped working properly. Basically,
> they will fail at one point when tuning to a channel. This typically
> takes less than 100 tuning attempts. For perspective, when performing
> a full channel scan on my system, the tuner tunes at least 500 times.
> After the tuner fails, I need to reboot the PC (probably unloading the
> driver and loading it again would do).
>
> 2018-04-04 10:17:36.756 [   INFO] mpegts: 12149H in 4.8E - tuning on
> Montage Technology M88DS3103 : DVB-S #0
> 2018-04-04 10:17:37.159 [  ERROR] diseqc: failed to send diseqc cmd
> (e=Connection timed out)
> 2018-04-04 10:17:37.160 [   INFO] mpegts: 12265H in 4.8E - tuning on
> Montage Technology M88DS3103 : DVB-S #0
> 2018-04-04 10:17:37.535 [  ERROR] diseqc: failed to send diseqc cmd
> (e=Connection timed out)
>
> I did a kernel bisect between 4.9 and 4.10. It seems the commit that
> breaks my tuner is the following one:
>
> 9d659ae14b545c4296e812c70493bfdc999b5c1c is the first bad commit
> commit 9d659ae14b545c4296e812c70493bfdc999b5c1c
> Author: Peter Zijlstra 
> Date:   Tue Aug 23 14:40:16 2016 +0200
>
> locking/mutex: Add lock handoff to avoid starvation
>
> I couldn't easily revert that commit only. I can see that the
> drivers/media/usb/dvb-usb-v2/dvbsky.c driver does use mutex_lock() and
> mutex_lock_interruptible() in a few places.
>
> Do you guys see anything that's obviously wrong in the way the mutexes
> are used in dvbsky.c or anything in that particular patch that could
> cause this issue?
>
> Thanks and best regards,
> -olli


[PATCH v3 2/5] tuners: add new i2c driver for Sharp qm1d1b0004 ISDB-S tuner

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

The tuner is used in Earthsoft PT1/PT2 DVB boards,
and  the driver was extraced from (the former) va1j5jf8007s.c of PT1.
it might contain PT1 specific configs.

Signed-off-by: Akihiro Tsukada 
---
Changes since v2:
- none

Changes since v1:
- none

 drivers/media/tuners/Kconfig  |   7 +
 drivers/media/tuners/Makefile |   1 +
 drivers/media/tuners/qm1d1b0004.c | 264 ++
 drivers/media/tuners/qm1d1b0004.h |  24 +++
 4 files changed, 296 insertions(+)
 create mode 100644 drivers/media/tuners/qm1d1b0004.c
 create mode 100644 drivers/media/tuners/qm1d1b0004.h

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 6687514df97..147f3cd0bb9 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -284,4 +284,11 @@ config MEDIA_TUNER_QM1D1C0042
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Sharp QM1D1C0042 trellis coded 8PSK tuner driver.
+
+config MEDIA_TUNER_QM1D1B0004
+   tristate "Sharp QM1D1B0004 tuner"
+   depends on MEDIA_SUPPORT && I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Sharp QM1D1B0004 ISDB-S tuner driver.
 endmenu
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile
index 0ff21f1c7ee..7b4f8423501 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_MEDIA_TUNER_IT913X) += it913x.o
 obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o
 obj-$(CONFIG_MEDIA_TUNER_MXL301RF) += mxl301rf.o
 obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o
+obj-$(CONFIG_MEDIA_TUNER_QM1D1B0004) += qm1d1b0004.o
 obj-$(CONFIG_MEDIA_TUNER_M88RS6000T) += m88rs6000t.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18250) += tda18250.o
 
diff --git a/drivers/media/tuners/qm1d1b0004.c 
b/drivers/media/tuners/qm1d1b0004.c
new file mode 100644
index 000..9dac1b875c1
--- /dev/null
+++ b/drivers/media/tuners/qm1d1b0004.c
@@ -0,0 +1,264 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sharp QM1D1B0004 satellite tuner
+ *
+ * Copyright (C) 2014 Akihiro Tsukada 
+ *
+ * based on (former) drivers/media/pci/pt1/va1j5jf8007s.c.
+ */
+
+/*
+ * Note:
+ * Since the data-sheet of this tuner chip is not available,
+ * this driver lacks some tuner_ops and config options.
+ * In addition, the implementation might be dependent on the specific use
+ * in the FE module: VA1J5JF8007S and/or in the product: Earthsoft PT1/PT2.
+ */
+
+#include 
+#include 
+#include 
+#include "qm1d1b0004.h"
+
+/*
+ * Tuner I/F (copied from the former va1j5jf8007s.c)
+ * b[0] I2C addr
+ * b[1] "0":1, BG:2, divider_quotient[7:3]:5
+ * b[2] divider_quotient[2:0]:3, divider_remainder:5
+ * b[3] "111":3, LPF[3:2]:2, TM:1, "0":1, REF:1
+ * b[4] BANDX, PSC:1, LPF[1:0]:2, DIV:1, "0":1
+ *
+ * PLL frequency step :=
+ *REF == 0 -> PLL XTL frequency(4MHz) / 8
+ *REF == 1 -> PLL XTL frequency(4MHz) / 4
+ *
+ * PreScaler :=
+ *PSC == 0 -> x32
+ *PSC == 1 -> x16
+ *
+ * divider_quotient := (frequency / PLL frequency step) / PreScaler
+ * divider_remainder := (frequency / PLL frequency step) % PreScaler
+ *
+ * LPF := LPF Frequency / 1000 / 2 - 2
+ * LPF Frequency @ baudrate=28.86Mbps = 3
+ *
+ * band (1..9)
+ *   band 1 (freq <  986000) -> DIV:1, BANDX:5, PSC:1
+ *   band 2 (freq < 1072000) -> DIV:1, BANDX:6, PSC:1
+ *   band 3 (freq < 1154000) -> DIV:1, BANDX:7, PSC:0
+ *   band 4 (freq < 1291000) -> DIV:0, BANDX:1, PSC:0
+ *   band 5 (freq < 1447000) -> DIV:0, BANDX:2, PSC:0
+ *   band 6 (freq < 1615000) -> DIV:0, BANDX:3, PSC:0
+ *   band 7 (freq < 1791000) -> DIV:0, BANDX:4, PSC:0
+ *   band 8 (freq < 1972000) -> DIV:0, BANDX:5, PSC:0
+ *   band 9 (freq < 215) -> DIV:0, BANDX:6, PSC:0
+ */
+
+#define QM1D1B0004_PSC_MASK (1 << 4)
+
+#define QM1D1B0004_XTL_FREQ 4000
+#define QM1D1B0004_LPF_FALLBACK 3
+
+static const struct qm1d1b0004_config default_cfg = {
+   .lpf_freq = QM1D1B0004_CFG_LPF_DFLT,
+   .half_step = false,
+};
+
+struct qm1d1b0004_state {
+   struct qm1d1b0004_config cfg;
+   struct i2c_client *i2c;
+};
+
+
+struct qm1d1b0004_cb_map {
+   u32 frequency;
+   u8 cb;
+};
+
+static const struct qm1d1b0004_cb_map cb_maps[] = {
+   {  986000, 0xb2 },
+   { 1072000, 0xd2 },
+   { 1154000, 0xe2 },
+   { 1291000, 0x20 },
+   { 1447000, 0x40 },
+   { 1615000, 0x60 },
+   { 1791000, 0x80 },
+   { 1972000, 0xa0 },
+};
+
+static u8 lookup_cb(u32 frequency)
+{
+   int i;
+   const struct qm1d1b0004_cb_map *map;
+
+   for (i = 0; i < ARRAY_SIZE(cb_maps); i++) {
+   map = _maps[i];
+   if (frequency < map->frequency)
+   return map->cb;
+   }
+   return 0xc0;
+}
+
+static int qm1d1b0004_set_params(struct dvb_frontend *fe)
+{
+   struct qm1d1b0004_state *state;
+   u32 frequency, pll, lpf_freq;
+   u16 word;
+   u8 buf[4], cb, lpf;
+   int ret;

[PATCH v3 1/5] dvb-frontends/dvb-pll: add tda6651 ISDB-T pll_desc

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

This patch adds a PLL "description" of Philips TDA6651 for ISDB-T.
It was extracted from (the former) va1j5jf8007t.c of EarthSoft PT1,
thus the desc might include PT1 specific configs.

Signed-off-by: Akihiro Tsukada 
---
Changes since v2:
- do not #define chip name constant

Changes since v1:
- use new style of specifying pll_desc of the tuner

 drivers/media/dvb-frontends/dvb-pll.c | 24 
 drivers/media/dvb-frontends/dvb-pll.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/media/dvb-frontends/dvb-pll.c 
b/drivers/media/dvb-frontends/dvb-pll.c
index f7d444d09cf..e3894ff403d 100644
--- a/drivers/media/dvb-frontends/dvb-pll.c
+++ b/drivers/media/dvb-frontends/dvb-pll.c
@@ -550,6 +550,28 @@ static const struct dvb_pll_desc dvb_pll_tua6034_friio = {
}
 };
 
+/* Philips TDA6651 ISDB-T, used in Earthsoft PT1 */
+static const struct dvb_pll_desc dvb_pll_tda665x_earth_pt1 = {
+   .name   = "Philips TDA6651 ISDB-T (EarthSoft PT1)",
+   .min=  9000,
+   .max= 77000,
+   .iffreq =  5700,
+   .initdata = (u8[]){ 5, 0x0e, 0x7f, 0xc1, 0x80, 0x80 },
+   .count = 10,
+   .entries = {
+   { 14000, 142857, 0xc1, 0x81 },
+   { 17000, 142857, 0xc1, 0xa1 },
+   { 22000, 142857, 0xc1, 0x62 },
+   { 33000, 142857, 0xc1, 0xa2 },
+   { 40200, 142857, 0xc1, 0xe2 },
+   { 45000, 142857, 0xc1, 0x64 },
+   { 55000, 142857, 0xc1, 0x84 },
+   { 6, 142857, 0xc1, 0xa4 },
+   { 7, 142857, 0xc1, 0xc4 },
+   { 77000, 142857, 0xc1, 0xe4 },
+   }
+};
+
 /* --- */
 
 static const struct dvb_pll_desc *pll_list[] = {
@@ -574,6 +596,7 @@ static const struct dvb_pll_desc *pll_list[] = {
[DVB_PLL_SAMSUNG_TBDU18132]  = _pll_samsung_tbdu18132,
[DVB_PLL_SAMSUNG_TBMU24112]  = _pll_samsung_tbmu24112,
[DVB_PLL_TUA6034_FRIIO]  = _pll_tua6034_friio,
+   [DVB_PLL_TDA665X_EARTH_PT1]  = _pll_tda665x_earth_pt1,
 };
 
 /* --- */
@@ -896,6 +919,7 @@ static const struct i2c_device_id dvb_pll_id[] = {
{"tdee4",   DVB_PLL_TDEE4},
{"dtt7520x",DVB_PLL_THOMSON_DTT7520X},
{"tua6034_friio",   DVB_PLL_TUA6034_FRIIO},
+   {"tda665x_earthpt1",DVB_PLL_TDA665X_EARTH_PT1},
{}
 };
 
diff --git a/drivers/media/dvb-frontends/dvb-pll.h 
b/drivers/media/dvb-frontends/dvb-pll.h
index 7555407c2cc..973a66a82e2 100644
--- a/drivers/media/dvb-frontends/dvb-pll.h
+++ b/drivers/media/dvb-frontends/dvb-pll.h
@@ -30,6 +30,7 @@
 #define DVB_PLL_TDEE4 18
 #define DVB_PLL_THOMSON_DTT7520X   19
 #define DVB_PLL_TUA6034_FRIIO  20
+#define DVB_PLL_TDA665X_EARTH_PT1  21
 
 struct dvb_pll_config {
struct dvb_frontend *fe;
-- 
2.17.0



[PATCH v3 3/5] dvb: earth-pt1: decompose pt1 driver into sub drivers

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

earth-pt1 was a monolithic module and included demod/tuner drivers.
This patch removes those FE parts and  attach demod/tuner i2c drivers.

Signed-off-by: Akihiro Tsukada 
---
Changes since v2:
- specify tuner chip name literally

Changes since v1:
- use i2c_board_info.name to specify pll_desc id.

 drivers/media/pci/pt1/Kconfig|   3 +
 drivers/media/pci/pt1/Makefile   |   3 +-
 drivers/media/pci/pt1/pt1.c  | 329 
 drivers/media/pci/pt1/va1j5jf8007s.c | 732 ---
 drivers/media/pci/pt1/va1j5jf8007s.h |  42 --
 drivers/media/pci/pt1/va1j5jf8007t.c | 532 ---
 drivers/media/pci/pt1/va1j5jf8007t.h |  42 --
 7 files changed, 227 insertions(+), 1456 deletions(-)
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007s.c
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007s.h
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007t.c
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007t.h

diff --git a/drivers/media/pci/pt1/Kconfig b/drivers/media/pci/pt1/Kconfig
index 24501d5bf70..2718b4c6b7c 100644
--- a/drivers/media/pci/pt1/Kconfig
+++ b/drivers/media/pci/pt1/Kconfig
@@ -1,6 +1,9 @@
 config DVB_PT1
tristate "PT1 cards"
depends on DVB_CORE && PCI && I2C
+   select DVB_TC90522 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_QM1D1B0004 if MEDIA_SUBDRV_AUTOSELECT
help
  Support for Earthsoft PT1 PCI cards.
 
diff --git a/drivers/media/pci/pt1/Makefile b/drivers/media/pci/pt1/Makefile
index ab873ae088a..bc491e08dd6 100644
--- a/drivers/media/pci/pt1/Makefile
+++ b/drivers/media/pci/pt1/Makefile
@@ -1,5 +1,6 @@
-earth-pt1-objs := pt1.o va1j5jf8007s.o va1j5jf8007t.o
+earth-pt1-objs := pt1.o
 
 obj-$(CONFIG_DVB_PT1) += earth-pt1.o
 
 ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/tuners
diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index 4f6867af831..40b6c0ac342 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -33,8 +35,9 @@
 #include 
 #include 
 
-#include "va1j5jf8007t.h"
-#include "va1j5jf8007s.h"
+#include "tc90522.h"
+#include "qm1d1b0004.h"
+#include "dvb-pll.h"
 
 #define DRIVER_NAME "earth-pt1"
 
@@ -63,6 +66,11 @@ struct pt1_table {
struct pt1_buffer bufs[PT1_NR_BUFS];
 };
 
+enum pt1_fe_clk {
+   PT1_FE_CLK_20MHZ,   /* PT1 */
+   PT1_FE_CLK_25MHZ,   /* PT2 */
+};
+
 #define PT1_NR_ADAPS 4
 
 struct pt1_adapter;
@@ -81,6 +89,8 @@ struct pt1 {
struct mutex lock;
int power;
int reset;
+
+   enum pt1_fe_clk fe_clk;
 };
 
 struct pt1_adapter {
@@ -97,6 +107,8 @@ struct pt1_adapter {
int users;
struct dmxdev dmxdev;
struct dvb_frontend *fe;
+   struct i2c_client *demod_i2c_client;
+   struct i2c_client *tuner_i2c_client;
int (*orig_set_voltage)(struct dvb_frontend *fe,
enum fe_sec_voltage voltage);
int (*orig_sleep)(struct dvb_frontend *fe);
@@ -106,6 +118,144 @@ struct pt1_adapter {
int sleep;
 };
 
+union pt1_tuner_config {
+   struct qm1d1b0004_config qm1d1b0004;
+   struct dvb_pll_config tda6651;
+};
+
+struct pt1_config {
+   struct i2c_board_info demod_info;
+   struct tc90522_config demod_cfg;
+
+   struct i2c_board_info tuner_info;
+   union pt1_tuner_config tuner_cfg;
+};
+
+static const struct pt1_config pt1_configs[PT1_NR_ADAPS] = {
+   {
+   .demod_info = {
+   I2C_BOARD_INFO(TC90522_I2C_DEV_SAT, 0x1b),
+   },
+   .tuner_info = {
+   I2C_BOARD_INFO("qm1d1b0004", 0x60),
+   },
+   },
+   {
+   .demod_info = {
+   I2C_BOARD_INFO(TC90522_I2C_DEV_TER, 0x1a),
+   },
+   .tuner_info = {
+   I2C_BOARD_INFO("tda665x_earthpt1", 0x61),
+   },
+   },
+   {
+   .demod_info = {
+   I2C_BOARD_INFO(TC90522_I2C_DEV_SAT, 0x19),
+   },
+   .tuner_info = {
+   I2C_BOARD_INFO("qm1d1b0004", 0x60),
+   },
+   },
+   {
+   .demod_info = {
+   I2C_BOARD_INFO(TC90522_I2C_DEV_TER, 0x18),
+   },
+   .tuner_info = {
+   I2C_BOARD_INFO("tda665x_earthpt1", 0x61),
+   },
+   },
+};
+
+static const u8 va1j5jf8007s_20mhz_configs[][2] = {
+   {0x04, 0x02}, {0x0d, 0x55}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01},
+   {0x1c, 0x0a}, {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0},
+   {0x52, 0x89}, {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69},
+   {0x87, 0x04}, {0x8e, 0x02}, 

[PATCH v3 4/5] dvb: earth-pt1: add support for suspend/resume

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

Without this patch, re-loading of the module was required after resume.

Signed-off-by: Akihiro Tsukada 
---
Changes since v2:
- none

Changes since v1:
- none

 drivers/media/pci/pt1/pt1.c | 107 +++-
 1 file changed, 105 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index 40b6c0ac342..b169175d85e 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -461,12 +461,18 @@ static int pt1_thread(void *data)
 {
struct pt1 *pt1;
struct pt1_buffer_page *page;
+   bool was_frozen;
 
pt1 = data;
set_freezable();
 
-   while (!kthread_should_stop()) {
-   try_to_freeze();
+   while (!kthread_freezable_should_stop(_frozen)) {
+   if (was_frozen) {
+   int i;
+
+   for (i = 0; i < PT1_NR_ADAPS; i++)
+   pt1_set_stream(pt1, i, !!pt1->adaps[i]->users);
+   }
 
page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page;
if (!pt1_filter(pt1, page)) {
@@ -1165,6 +1171,98 @@ static void pt1_i2c_init(struct pt1 *pt1)
pt1_i2c_emit(pt1, i, 0, 0, 1, 1, 0);
 }
 
+#ifdef CONFIG_PM_SLEEP
+
+static int pt1_suspend(struct device *dev)
+{
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct pt1 *pt1 = pci_get_drvdata(pdev);
+
+   pt1_init_streams(pt1);
+   pt1_disable_ram(pt1);
+   pt1->power = 0;
+   pt1->reset = 1;
+   pt1_update_power(pt1);
+   return 0;
+}
+
+static int pt1_resume(struct device *dev)
+{
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct pt1 *pt1 = pci_get_drvdata(pdev);
+   int ret;
+   int i;
+
+   pt1->power = 0;
+   pt1->reset = 1;
+   pt1_update_power(pt1);
+
+   pt1_i2c_init(pt1);
+   pt1_i2c_wait(pt1);
+
+   ret = pt1_sync(pt1);
+   if (ret < 0)
+   goto resume_err;
+
+   pt1_identify(pt1);
+
+   ret = pt1_unlock(pt1);
+   if (ret < 0)
+   goto resume_err;
+
+   ret = pt1_reset_pci(pt1);
+   if (ret < 0)
+   goto resume_err;
+
+   ret = pt1_reset_ram(pt1);
+   if (ret < 0)
+   goto resume_err;
+
+   ret = pt1_enable_ram(pt1);
+   if (ret < 0)
+   goto resume_err;
+
+   pt1_init_streams(pt1);
+
+   pt1->power = 1;
+   pt1_update_power(pt1);
+   msleep(20);
+
+   pt1->reset = 0;
+   pt1_update_power(pt1);
+   usleep_range(1000, 2000);
+
+   for (i = 0; i < PT1_NR_ADAPS; i++)
+   dvb_frontend_reinitialise(pt1->adaps[i]->fe);
+
+   pt1_init_table_count(pt1);
+   for (i = 0; i < pt1_nr_tables; i++) {
+   int j;
+
+   for (j = 0; j < PT1_NR_BUFS; j++)
+   pt1->tables[i].bufs[j].page->upackets[PT1_NR_UPACKETS-1]
+   = 0;
+   pt1_increment_table_count(pt1);
+   }
+   pt1_register_tables(pt1, pt1->tables[0].addr >> PT1_PAGE_SHIFT);
+
+   pt1->table_index = 0;
+   pt1->buf_index = 0;
+   for (i = 0; i < PT1_NR_ADAPS; i++) {
+   pt1->adaps[i]->upacket_count = 0;
+   pt1->adaps[i]->packet_count = 0;
+   pt1->adaps[i]->st_count = -1;
+   }
+
+   return 0;
+
+resume_err:
+   dev_info(>pdev->dev, "failed to resume PT1/PT2.");
+   return 0;   /* resume anyway */
+}
+
+#endif /* CONFIG_PM_SLEEP */
+
 static void pt1_remove(struct pci_dev *pdev)
 {
struct pt1 *pt1;
@@ -1325,11 +1423,16 @@ static const struct pci_device_id pt1_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, pt1_id_table);
 
+static SIMPLE_DEV_PM_OPS(pt1_pm_ops, pt1_suspend, pt1_resume);
+
 static struct pci_driver pt1_driver = {
.name   = DRIVER_NAME,
.probe  = pt1_probe,
.remove = pt1_remove,
.id_table   = pt1_id_table,
+#if CONFIG_PM_SLEEP
+   .driver.pm  = _pm_ops,
+#endif
 };
 
 module_pci_driver(pt1_driver);
-- 
2.17.0



[PATCH v3 5/5] dvb: earth-pt1: replace schedule_timeout with usleep_range

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

As described in Document/timers/timers-howto.txt,
hrtimer-based delay should be used for small sleeps.

Signed-off-by: Akihiro Tsukada 
---
Changes since v2:
- none

Changes since v1:
- none

 drivers/media/pci/pt1/pt1.c | 34 +++---
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index b169175d85e..a3126d7caac 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -18,7 +18,10 @@
  */
 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -321,7 +324,7 @@ static int pt1_unlock(struct pt1 *pt1)
for (i = 0; i < 3; i++) {
if (pt1_read_reg(pt1, 0) & 0x8000)
return 0;
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
}
dev_err(>pdev->dev, "could not unlock\n");
return -EIO;
@@ -335,7 +338,7 @@ static int pt1_reset_pci(struct pt1 *pt1)
for (i = 0; i < 10; i++) {
if (pt1_read_reg(pt1, 0) & 0x0001)
return 0;
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
}
dev_err(>pdev->dev, "could not reset PCI\n");
return -EIO;
@@ -349,7 +352,7 @@ static int pt1_reset_ram(struct pt1 *pt1)
for (i = 0; i < 10; i++) {
if (pt1_read_reg(pt1, 0) & 0x0002)
return 0;
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
}
dev_err(>pdev->dev, "could not reset RAM\n");
return -EIO;
@@ -366,7 +369,7 @@ static int pt1_do_enable_ram(struct pt1 *pt1)
if ((pt1_read_reg(pt1, 0) & 0x0004) != status)
return 0;
}
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
}
dev_err(>pdev->dev, "could not enable RAM\n");
return -EIO;
@@ -376,7 +379,7 @@ static int pt1_enable_ram(struct pt1 *pt1)
 {
int i, ret;
int phase;
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
phase = pt1->pdev->device == 0x211a ? 128 : 166;
for (i = 0; i < phase; i++) {
ret = pt1_do_enable_ram(pt1);
@@ -463,6 +466,9 @@ static int pt1_thread(void *data)
struct pt1_buffer_page *page;
bool was_frozen;
 
+#define PT1_FETCH_DELAY 10
+#define PT1_FETCH_DELAY_DELTA 2
+
pt1 = data;
set_freezable();
 
@@ -476,7 +482,13 @@ static int pt1_thread(void *data)
 
page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page;
if (!pt1_filter(pt1, page)) {
-   schedule_timeout_interruptible((HZ + 999) / 1000);
+   ktime_t delay;
+
+   delay = PT1_FETCH_DELAY * NSEC_PER_MSEC;
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_hrtimeout_range(,
+   PT1_FETCH_DELAY_DELTA * NSEC_PER_MSEC,
+   HRTIMER_MODE_REL);
continue;
}
 
@@ -712,7 +724,7 @@ pt1_update_power(struct pt1 *pt1)
adap = pt1->adaps[i];
switch (adap->voltage) {
case SEC_VOLTAGE_13: /* actually 11V */
-   bits |= 1 << 1;
+   bits |= 1 << 2;
break;
case SEC_VOLTAGE_18: /* actually 15V */
bits |= 1 << 1 | 1 << 2;
@@ -766,7 +778,7 @@ static int pt1_wakeup(struct dvb_frontend *fe)
adap = container_of(fe->dvb, struct pt1_adapter, adap);
adap->sleep = 0;
pt1_update_power(adap->pt1);
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
 
ret = config_demod(adap->demod_i2c_client, adap->pt1->fe_clk);
if (ret == 0 && adap->orig_init)
@@ -1073,7 +1085,7 @@ static int pt1_i2c_end(struct pt1 *pt1, int addr)
do {
if (signal_pending(current))
return -EINTR;
-   schedule_timeout_interruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
} while (pt1_read_reg(pt1, 0) & 0x0080);
return 0;
 }
@@ -1376,11 +1388,11 @@ static int pt1_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
pt1->power = 1;
pt1_update_power(pt1);
-   schedule_timeout_uninterruptible((HZ + 49) / 50);
+   msleep(20);
 
pt1->reset = 0;
pt1_update_power(pt1);
-   schedule_timeout_uninterruptible((HZ + 999) / 1000);
+   usleep_range(1000, 2000);
 

[PATCH v3 0/5] dvb/pci/pt1: decompose earth-pt1 into sub drivers

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

Changes since v2:
- dvb-pll,pt1: do not #define chip name constants and use string literals

Changes since v1:
- use new style of specifying pll_desc of the terrestrial tuner

Akihiro Tsukada (5):
  dvb-frontends/dvb-pll: add tda6651 ISDB-T pll_desc
  tuners: add new i2c driver for  Sharp qm1d1b0004 ISDB-S tuner
  dvb: earth-pt1: decompose pt1 driver into sub drivers
  dvb: earth-pt1: add support for suspend/resume
  dvb: earth-pt1:  replace schedule_timeout with usleep_range

 drivers/media/dvb-frontends/dvb-pll.c |  24 +
 drivers/media/dvb-frontends/dvb-pll.h |   1 +
 drivers/media/pci/pt1/Kconfig |   3 +
 drivers/media/pci/pt1/Makefile|   3 +-
 drivers/media/pci/pt1/pt1.c   | 470 -
 drivers/media/pci/pt1/va1j5jf8007s.c  | 732 --
 drivers/media/pci/pt1/va1j5jf8007s.h  |  42 --
 drivers/media/pci/pt1/va1j5jf8007t.c  | 532 ---
 drivers/media/pci/pt1/va1j5jf8007t.h  |  42 --
 drivers/media/tuners/Kconfig  |   7 +
 drivers/media/tuners/Makefile |   1 +
 drivers/media/tuners/qm1d1b0004.c | 264 ++
 drivers/media/tuners/qm1d1b0004.h |  24 +
 13 files changed, 676 insertions(+), 1469 deletions(-)
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007s.c
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007s.h
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007t.c
 delete mode 100644 drivers/media/pci/pt1/va1j5jf8007t.h
 create mode 100644 drivers/media/tuners/qm1d1b0004.c
 create mode 100644 drivers/media/tuners/qm1d1b0004.h

-- 
2.17.0



[PATCH v5 4/5] dvb-usb-v2/gl861: use usleep_range() for short delay

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

As the kernel doc "timers-howto.txt" reads,
short delay with msleep() can take much longer.
In a case of raspbery-pi platform where CONFIG_HZ_100 was set,
it actually affected the init of Friio devices
since it issues lots of i2c transactions with short delay.

Signed-off-by: Akihiro Tsukada 
---
Changes since v4:
- none

 drivers/media/usb/dvb-usb-v2/gl861.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb-v2/gl861.c 
b/drivers/media/usb/dvb-usb-v2/gl861.c
index ecff0062bfb..cdd7bfcb883 100644
--- a/drivers/media/usb/dvb-usb-v2/gl861.c
+++ b/drivers/media/usb/dvb-usb-v2/gl861.c
@@ -45,7 +45,7 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
return -EINVAL;
}
 
-   msleep(1); /* avoid I2C errors */
+   usleep_range(1000, 2000); /* avoid I2C errors */
 
return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
   value, index, rbuf, rlen, 2000);
-- 
2.17.0



[PATCH v5 1/5] dvb-frontends/dvb-pll: add i2c driver support

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

registers the module as an i2c driver,
but keeps dvb_pll_attach() untouched for compatibility.

Signed-off-by: Akihiro Tsukada 
---
Changes since v4:
- do not #define chip name constants

Changes since v3:
- use standard i2c_device_id instead of dvb_pll_config

 drivers/media/dvb-frontends/dvb-pll.c | 67 +++
 drivers/media/dvb-frontends/dvb-pll.h |  4 ++
 2 files changed, 71 insertions(+)

diff --git a/drivers/media/dvb-frontends/dvb-pll.c 
b/drivers/media/dvb-frontends/dvb-pll.c
index 5553b89b804..ff0f477276a 100644
--- a/drivers/media/dvb-frontends/dvb-pll.c
+++ b/drivers/media/dvb-frontends/dvb-pll.c
@@ -827,6 +827,73 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend 
*fe, int pll_addr,
 }
 EXPORT_SYMBOL(dvb_pll_attach);
 
+
+static int
+dvb_pll_probe(struct i2c_client *client, const struct i2c_device_id *id)
+{
+   struct dvb_pll_config *cfg;
+   struct dvb_frontend *fe;
+   unsigned int desc_id;
+
+   cfg = client->dev.platform_data;
+   fe = cfg->fe;
+   i2c_set_clientdata(client, fe);
+   desc_id = (unsigned int) id->driver_data;
+
+   if (!dvb_pll_attach(fe, client->addr, client->adapter, desc_id))
+   return -ENOMEM;
+
+   dev_info(>dev, "DVB Simple Tuner attached.\n");
+   return 0;
+}
+
+static int dvb_pll_remove(struct i2c_client *client)
+{
+   struct dvb_frontend *fe;
+
+   fe = i2c_get_clientdata(client);
+   dvb_pll_release(fe);
+   return 0;
+}
+
+
+static const struct i2c_device_id dvb_pll_id[] = {
+   {"dtt7579", DVB_PLL_THOMSON_DTT7579},
+   {"dtt759x", DVB_PLL_THOMSON_DTT759X},
+   {"z201",DVB_PLL_LG_Z201},
+   {"unknown_1",   DVB_PLL_UNKNOWN_1},
+   {"tua6010xs",   DVB_PLL_TUA6010XS},
+   {"env57h1xd5",  DVB_PLL_ENV57H1XD5},
+   {"tua6034", DVB_PLL_TUA6034},
+   {"tda665x", DVB_PLL_TDA665X},
+   {"tded4",   DVB_PLL_TDED4},
+   {"tdhu2",   DVB_PLL_TDHU2},
+   {"tbmv",DVB_PLL_SAMSUNG_TBMV},
+   {"sd1878_tda8261",  DVB_PLL_PHILIPS_SD1878_TDA8261},
+   {"opera1",  DVB_PLL_OPERA1},
+   {"dtos403ih102a",   DVB_PLL_SAMSUNG_DTOS403IH102A},
+   {"tdtc9251dh0", DVB_PLL_SAMSUNG_TDTC9251DH0},
+   {"tbdu18132",   DVB_PLL_SAMSUNG_TBDU18132},
+   {"tbmu24112",   DVB_PLL_SAMSUNG_TBMU24112},
+   {"tdee4",   DVB_PLL_TDEE4},
+   {"dtt7520x",DVB_PLL_THOMSON_DTT7520X},
+   {}
+};
+
+
+MODULE_DEVICE_TABLE(i2c, dvb_pll_id);
+
+static struct i2c_driver dvb_pll_driver = {
+   .driver = {
+   .name = "dvb_pll",
+   },
+   .probe= dvb_pll_probe,
+   .remove   = dvb_pll_remove,
+   .id_table = dvb_pll_id,
+};
+
+module_i2c_driver(dvb_pll_driver);
+
 MODULE_DESCRIPTION("dvb pll library");
 MODULE_AUTHOR("Gerd Knorr");
 MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/dvb-pll.h 
b/drivers/media/dvb-frontends/dvb-pll.h
index ca885e71d2f..101537ae4ef 100644
--- a/drivers/media/dvb-frontends/dvb-pll.h
+++ b/drivers/media/dvb-frontends/dvb-pll.h
@@ -30,6 +30,10 @@
 #define DVB_PLL_TDEE4 18
 #define DVB_PLL_THOMSON_DTT7520X   19
 
+struct dvb_pll_config {
+   struct dvb_frontend *fe;
+};
+
 #if IS_REACHABLE(CONFIG_DVB_PLL)
 /**
  * Attach a dvb-pll to the supplied frontend structure.
-- 
2.17.0



[PATCH v5 5/5] dvb-usb-v2/gl861: ensure USB message buffers DMA'able

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

i2c message buf might be on stack.

Signed-off-by: Akihiro Tsukada 
---
Changes since v4:
- none

 drivers/media/usb/dvb-usb-v2/gl861.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/gl861.c 
b/drivers/media/usb/dvb-usb-v2/gl861.c
index cdd7bfcb883..47b614da807 100644
--- a/drivers/media/usb/dvb-usb-v2/gl861.c
+++ b/drivers/media/usb/dvb-usb-v2/gl861.c
@@ -22,6 +22,8 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
u16 value = addr << (8 + 1);
int wo = (rbuf == NULL || rlen == 0); /* write-only */
u8 req, type;
+   u8 *buf;
+   int ret;
 
if (wo) {
req = GL861_REQ_I2C_WRITE;
@@ -44,11 +46,23 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
KBUILD_MODNAME, wlen);
return -EINVAL;
}
-
+   buf = NULL;
+   if (rlen > 0) {
+   buf = kmalloc(rlen, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+   }
usleep_range(1000, 2000); /* avoid I2C errors */
 
-   return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
-  value, index, rbuf, rlen, 2000);
+   ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
+ value, index, buf, rlen, 2000);
+   if (rlen > 0) {
+   if (ret > 0)
+   memcpy(rbuf, buf, rlen);
+   kfree(buf);
+   }
+
+   return ret;
 }
 
 /* Friio specific I2C read/write */
-- 
2.17.0



[PATCH v6 3/5] dvb-usb/friio, dvb-usb-v2/gl861: decompose friio and merge with gl861

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

Friio device contains "gl861" bridge and "tc90522" demod,
for which the separate drivers are already in the kernel.
But friio driver was monolithic and did not use them,
practically copying those features.
This patch decomposes friio driver into sub drivers and
re-uses existing ones, thus reduces some code.

It adds some features to gl861,
to support the friio-specific init/config of the devices
and implement i2c communications to the tuner via demod
with USB vendor requests.

Signed-off-by: Akihiro Tsukada 
---
Changes since v5:
- specify chip name literally
- i2c algo of gl861 is not (yet?) changed as proposed by Antti,
  (which is to move the special case handling to demod driver),
  since I do not yet understand
  whether it should/can be really moved or not.

Changes since v4:
- use new style of specifying pll_desc id of the tuner driver

Changes since v3:
- make dvb_usb_device_properties static

Changes since v2:
(patch #27928, dvb-usb-friio: split and merge into dvb-usbv2-gl861)
 - used the new i2c binding helpers instead of my own one
 - merged gl861-friio.c with gl861.c

 drivers/media/usb/dvb-usb-v2/Kconfig |   5 +-
 drivers/media/usb/dvb-usb-v2/gl861.c | 465 +++-
 drivers/media/usb/dvb-usb-v2/gl861.h |   1 +
 drivers/media/usb/dvb-usb/Kconfig|   6 -
 drivers/media/usb/dvb-usb/Makefile   |   3 -
 drivers/media/usb/dvb-usb/friio-fe.c | 441 --
 drivers/media/usb/dvb-usb/friio.c| 522 ---
 drivers/media/usb/dvb-usb/friio.h|  99 -
 8 files changed, 462 insertions(+), 1080 deletions(-)
 delete mode 100644 drivers/media/usb/dvb-usb/friio-fe.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.h

diff --git a/drivers/media/usb/dvb-usb-v2/Kconfig 
b/drivers/media/usb/dvb-usb-v2/Kconfig
index 0e4944b2b0f..e0a1f377295 100644
--- a/drivers/media/usb/dvb-usb-v2/Kconfig
+++ b/drivers/media/usb/dvb-usb-v2/Kconfig
@@ -95,10 +95,13 @@ config DVB_USB_GL861
tristate "Genesys Logic GL861 USB2.0 support"
depends on DVB_USB_V2
select DVB_ZL10353 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_TC90522 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_QT1010 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT
help
  Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0
- receiver with USB ID 0db0:5581.
+ receiver with USB ID 0db0:5581, Friio White ISDB-T receiver
+ with USB ID 0x7a69:0001.
 
 config DVB_USB_LME2510
tristate "LME DM04/QQBOX DVB-S USB2.0 support"
diff --git a/drivers/media/usb/dvb-usb-v2/gl861.c 
b/drivers/media/usb/dvb-usb-v2/gl861.c
index b1b09c54786..ecff0062bfb 100644
--- a/drivers/media/usb/dvb-usb-v2/gl861.c
+++ b/drivers/media/usb/dvb-usb-v2/gl861.c
@@ -10,6 +10,8 @@
 
 #include "zl10353.h"
 #include "qt1010.h"
+#include "tc90522.h"
+#include "dvb-pll.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
@@ -49,6 +51,80 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
   value, index, rbuf, rlen, 2000);
 }
 
+/* Friio specific I2C read/write */
+/* special USB request is used in Friio's init/config */
+static int
+gl861_i2c_rawwrite(struct dvb_usb_device *d, u8 addr, u8 *wbuf, u16 wlen)
+{
+   u8 *buf;
+   int ret;
+
+   buf = kmalloc(wlen, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   usleep_range(1000, 2000); /* avoid I2C errors */
+   memcpy(buf, wbuf, wlen);
+   ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
+GL861_REQ_I2C_RAW, GL861_WRITE,
+addr << (8 + 1), 0x0100, buf, wlen, 2000);
+   kfree(buf);
+   return ret;
+}
+
+/*
+ * In Friio,
+ * I2C commnucations to the tuner are relay'ed via the demod (via the bridge),
+ * so its encapsulation to USB message is different from the one to the demod.
+ */
+static int
+gl861_i2c_rawread(struct dvb_usb_device *d, u8 addr, u8 *rbuf, u16 rlen)
+{
+   u8 *buf;
+   int ret;
+
+   buf = kmalloc(rlen, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   usleep_range(1000, 2000); /* avoid I2C errors */
+
+   ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
+GL861_REQ_I2C_READ, GL861_READ,
+addr << (8 + 1), 0x0100, buf, rlen, 2000);
+   if (ret > 0 && rbuf)
+   memcpy(rbuf, buf, rlen);
+   kfree(buf);
+
+   return ret;
+}
+
+static int
+gl861_i2c_relay_write(struct dvb_usb_device *d, struct i2c_msg *msg)
+{
+   u8 *buf;
+   int ret;
+
+   if (msg->flags & I2C_M_RD)
+   return -EINVAL;
+   if (msg->len < 2)
+   return -EINVAL;
+
+   buf = kmalloc(msg->len - 1, GFP_KERNEL);
+   if (!buf)
+   return 

[PATCH v5 2/5] dvb-frontends/dvb-pll: add tua6034 ISDB-T tuner used in Friio

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

This driver already contains tua6034-based device settings,
but they are not for ISDB-T and have different parameters.

Signed-off-by: Akihiro Tsukada 
---
Changes since v4:
- do not #define chip name constant

Changes since v3:
- rebase on the new style of specifying pll_desc

Changes since v2:
(patch #27927 dvb: tua6034: add a new driver for Infineon tua6034 tuner)
- extends dvb-pll instead of creating a new driver

 drivers/media/dvb-frontends/dvb-pll.c | 19 +++
 drivers/media/dvb-frontends/dvb-pll.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/drivers/media/dvb-frontends/dvb-pll.c 
b/drivers/media/dvb-frontends/dvb-pll.c
index ff0f477276a..f7d444d09cf 100644
--- a/drivers/media/dvb-frontends/dvb-pll.c
+++ b/drivers/media/dvb-frontends/dvb-pll.c
@@ -533,6 +533,23 @@ static const struct dvb_pll_desc dvb_pll_alps_tdee4 = {
}
 };
 
+/* Infineon TUA6034 ISDB-T, used in Friio */
+/* CP cur. 50uA, AGC takeover: 103dBuV, PORT3 on */
+static const struct dvb_pll_desc dvb_pll_tua6034_friio = {
+   .name   = "Infineon TUA6034 ISDB-T (Friio)",
+   .min=  9000,
+   .max= 77000,
+   .iffreq =  5700,
+   .initdata = (u8[]){ 4, 0x9a, 0x50, 0xb2, 0x08 },
+   .sleepdata = (u8[]){ 4, 0x9a, 0x70, 0xb3, 0x0b },
+   .count = 3,
+   .entries = {
+   { 17000, 142857, 0xba, 0x09 },
+   { 47000, 142857, 0xba, 0x0a },
+   { 77000, 142857, 0xb2, 0x08 },
+   }
+};
+
 /* --- */
 
 static const struct dvb_pll_desc *pll_list[] = {
@@ -556,6 +573,7 @@ static const struct dvb_pll_desc *pll_list[] = {
[DVB_PLL_SAMSUNG_TDTC9251DH0]= _pll_samsung_tdtc9251dh0,
[DVB_PLL_SAMSUNG_TBDU18132]  = _pll_samsung_tbdu18132,
[DVB_PLL_SAMSUNG_TBMU24112]  = _pll_samsung_tbmu24112,
+   [DVB_PLL_TUA6034_FRIIO]  = _pll_tua6034_friio,
 };
 
 /* --- */
@@ -877,6 +895,7 @@ static const struct i2c_device_id dvb_pll_id[] = {
{"tbmu24112",   DVB_PLL_SAMSUNG_TBMU24112},
{"tdee4",   DVB_PLL_TDEE4},
{"dtt7520x",DVB_PLL_THOMSON_DTT7520X},
+   {"tua6034_friio",   DVB_PLL_TUA6034_FRIIO},
{}
 };
 
diff --git a/drivers/media/dvb-frontends/dvb-pll.h 
b/drivers/media/dvb-frontends/dvb-pll.h
index 101537ae4ef..7555407c2cc 100644
--- a/drivers/media/dvb-frontends/dvb-pll.h
+++ b/drivers/media/dvb-frontends/dvb-pll.h
@@ -29,6 +29,7 @@
 #define DVB_PLL_SAMSUNG_TBMU24112  17
 #define DVB_PLL_TDEE4 18
 #define DVB_PLL_THOMSON_DTT7520X   19
+#define DVB_PLL_TUA6034_FRIIO  20
 
 struct dvb_pll_config {
struct dvb_frontend *fe;
-- 
2.17.0



[PATCH v5 0/5] dvb-usb-friio: decompose friio and merge with gl861

2018-04-08 Thread tskd08
From: Akihiro Tsukada 

This series decomposes dvb-usb-friio into sub drivers
and merge the bridge driver with dvb-usb-gl861.
As to the demod & tuner drivers, existing drivers are re-used.

Changes since v4:
- dvb-pll,gl861: do not #define chip name constants
- i2c algo of gl861 is not (yet?) changed as proposed by Antti,
  (which is to move the special case handling to demod driver),
  since I do not yet understand
  whether it should/can be really moved or not.

Changes since v3:
- dvb-pll,gl681: use i2c_device_id/i2c_board_info to specify pll_desc

Changes since v2:
- used the new i2c binding helpers instead of my own one
- extends dvb-pll instead of creating a new tuner driver
- merged gl861-friio.c with gl861.c
- improved module counting
- made i2c communications on USB robust (regarding DMA)

Replaces:
patch #27927, dvb: tua6034: add a new driver for Infineon tua6034 tuner
patch #27928, dvb-usb-friio: split and merge into dvb-usbv2-gl861

Akihiro Tsukada (5):
  dvb-frontends/dvb-pll: add i2c driver support
  dvb-frontends/dvb-pll: add tua6034 ISDB-T tuner used in Friio
  dvb-usb/friio, dvb-usb-v2/gl861: decompose friio and merge with gl861
  dvb-usb-v2/gl861: use usleep_range() for short delay
  dvb-usb-v2/gl861: ensure  USB message buffers DMA'able

 drivers/media/dvb-frontends/dvb-pll.c |  86 +
 drivers/media/dvb-frontends/dvb-pll.h |   5 +
 drivers/media/usb/dvb-usb-v2/Kconfig  |   5 +-
 drivers/media/usb/dvb-usb-v2/gl861.c  | 485 +++-
 drivers/media/usb/dvb-usb-v2/gl861.h  |   1 +
 drivers/media/usb/dvb-usb/Kconfig |   6 -
 drivers/media/usb/dvb-usb/Makefile|   3 -
 drivers/media/usb/dvb-usb/friio-fe.c  | 441 --
 drivers/media/usb/dvb-usb/friio.c | 522 --
 drivers/media/usb/dvb-usb/friio.h |  99 -
 10 files changed, 570 insertions(+), 1083 deletions(-)
 delete mode 100644 drivers/media/usb/dvb-usb/friio-fe.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.h

-- 
2.17.0



[PATCH] media: entity: fix spelling for media_entity_get_fwnode_pad()

2018-04-08 Thread Niklas Söderlund
From: Niklas Söderlund 

s/dose/does/

Fixes: d295c6a460cd2ac6 ("[media] media: entity: Add 
media_entity_get_fwnode_pad() function")
Signed-off-by: Niklas Söderlund 
---
 include/media/media-entity.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a732af1dbba099d4..3aa3d58d1d586dc2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -842,7 +842,7 @@ struct media_entity *media_entity_get(struct media_entity 
*entity);
  * a fwnode. This is useful for devices which use more complex
  * mappings of media pads.
  *
- * If the entity dose not implement the get_fwnode_pad() operation
+ * If the entity does not implement the get_fwnode_pad() operation
  * then this function searches the entity for the first pad that
  * matches the @direction_flags.
  *
-- 
2.16.3



Re: [PATCH 1/3] media: si2165: Remove owner assignment from i2c_driver

2018-04-08 Thread Matthias Schwarzott
Thank you for sending this patch.

Am 24.03.2018 um 15:01 schrieb Fabio Estevam:
> From: Fabio Estevam 
> 
> Structure i2c_driver does not need to set the owner field, as this will
> be populated by the driver core.
> 
> Generated by scripts/coccinelle/api/platform_no_drv_owner.cocci.
> 
> Cc: Matthias Schwarzott 
> Signed-off-by: Fabio Estevam 
> ---
>  drivers/media/dvb-frontends/si2165.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/media/dvb-frontends/si2165.c 
> b/drivers/media/dvb-frontends/si2165.c
> index 2dd336f..d132e3c 100644
> --- a/drivers/media/dvb-frontends/si2165.c
> +++ b/drivers/media/dvb-frontends/si2165.c
> @@ -1299,7 +1299,6 @@ MODULE_DEVICE_TABLE(i2c, si2165_id_table);
>  
>  static struct i2c_driver si2165_driver = {
>   .driver = {
> - .owner  = THIS_MODULE,
>   .name   = "si2165",
>   },
>   .probe  = si2165_probe,
> 

The change is fine.

Reviewed-by: Matthias Schwarzott 


Re: [PATCH 01/16] omap: omap-iommu.h: allow building drivers with COMPILE_TEST

2018-04-08 Thread Matthias Schwarzott
Am 05.04.2018 um 19:54 schrieb Mauro Carvalho Chehab:
> Drivers that depend on omap-iommu.h (currently, just omap3isp)
> need a stub implementation in order to be built with COMPILE_TEST.
> 
> Signed-off-by: Mauro Carvalho Chehab 
> ---
>  include/linux/omap-iommu.h | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/linux/omap-iommu.h b/include/linux/omap-iommu.h
> index c1aede46718b..0c21fc5b002e 100644
> --- a/include/linux/omap-iommu.h
> +++ b/include/linux/omap-iommu.h
> @@ -13,7 +13,12 @@
>  #ifndef _OMAP_IOMMU_H_
>  #define _OMAP_IOMMU_H_
>  
> +#ifdef CONFIG_OMAP_IOMMU
>  extern void omap_iommu_save_ctx(struct device *dev);
>  extern void omap_iommu_restore_ctx(struct device *dev);
> +#else
> +static inline void omap_iommu_save_ctx(struct device *dev) {};
> +static inline void omap_iommu_restore_ctx(struct device *dev) {};

The semicolons at end of line are unnecessary.

> +#endif
>  
>  #endif
> 

Regards
Matthias