cron job: media_tree daily build: WARNINGS

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

Results of the daily build of media_tree:

date:   Sun Feb 25 05:00:11 CET 2018
media-tree git hash:a7bc5773cd166032e35e343dfb6067a93d8402d1
media_build git hash:   a9ea3d056e5ce50d37dd6129126f776c3a8ec2d7
v4l-utils git hash: ef45319c1686088a46325db4dbfaffcdbcacf862
gcc version:i686-linux-gcc (GCC) 7.3.0
sparse version: v0.5.0-3994-g45eb2282
smatch version: v0.5.0-3994-g45eb2282
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-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: WARNINGS
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.98-i686: WARNINGS
linux-3.2.98-x86_64: WARNINGS
linux-3.3.8-i686: WARNINGS
linux-3.3.8-x86_64: WARNINGS
linux-3.4.27-i686: WARNINGS
linux-3.4.27-x86_64: WARNINGS
linux-3.5.7-i686: WARNINGS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.67-i686: WARNINGS
linux-3.12.67-x86_64: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.53-i686: WARNINGS
linux-3.16.53-x86_64: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.93-i686: WARNINGS
linux-3.18.93-x86_64: WARNINGS
linux-3.19-i686: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.49-i686: WARNINGS
linux-4.1.49-x86_64: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.115-i686: OK
linux-4.4.115-x86_64: OK
linux-4.5.7-i686: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-i686: OK
linux-4.7.5-x86_64: WARNINGS
linux-4.8-i686: OK
linux-4.8-x86_64: WARNINGS
linux-4.9.80-i686: OK
linux-4.9.80-x86_64: OK
linux-4.10.14-i686: OK
linux-4.10.14-x86_64: WARNINGS
linux-4.11-i686: OK
linux-4.11-x86_64: WARNINGS
linux-4.12.1-i686: OK
linux-4.12.1-x86_64: WARNINGS
linux-4.13-i686: OK
linux-4.13-x86_64: OK
linux-4.14.17-i686: OK
linux-4.14.17-x86_64: OK
linux-4.15.2-i686: OK
linux-4.15.2-x86_64: OK
linux-4.16-rc1-i686: OK
linux-4.16-rc1-x86_64: OK
apps: WARNINGS
spec-git: OK
sparse: WARNINGS
smatch: OK

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


Re: [PATCH] media: radio: Critical interrupt bugfix for si470x over i2c

2018-02-24 Thread Douglas Fischer
Hans,

Sorry for the delay and thanks for getting back to me. Please see
below. Sorry for the mangles, I'll fix my email setup before I submit a
v2 for all three patches, this is the only one I have questions for you
on.

On Thu, 15 Feb 2018 15:38:55 +0100
Hans Verkuil  wrote:

> On 27/01/18 00:42, Douglas Fischer wrote:
> > Fixed si470x_start() disabling the interrupt signal, causing tune
> > operations to never complete. This does not affect USB radios
> > because they poll the registers instead of using the IRQ line.
> > 
> > Signed-off-by: Douglas Fischer 
> > ---
> > 
> > diff -uprN
> > linux.orig/drivers/media/radio/si470x/radio-si470x-common.c
> > linux/drivers/media/radio/si470x/radio-si470x-common.c ---
> > linux.orig/drivers/media/radio/si470x/radio-si470x-common.c
> > 2018-01-15 21:58:10.675620432 -0500 +++
> > linux/drivers/media/radio/si470x/radio-si470x-common.c 2018-01-16
> > 16:54:23.699770645 -0500 @@ -377,8 +377,13 @@ int
> > si470x_start(struct si470x_device *r goto done; /* sysconfig 1 */
> > -   radio->registers[SYSCONFIG1] =
> > -   (de << 11) & SYSCONFIG1_DE; /* DE*/
> > +   radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDSIEN;
> > +   radio->registers[SYSCONFIG1] |= SYSCONFIG1_STCIEN;
> > +   radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;  
> 
> Just do:
> 
>   radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDSIEN |
> SYSCONFIG1_STCIEN | SYSCONFIG1_RDS;
> 
> > +   radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_GPIO2;  
> 
> Why is this cleared?
> 
> > +   radio->registers[SYSCONFIG1] |= 0x1 << 2;  
> 
> What's this? It doesn't use a define, so either add one or add a
> comment.
I need to set SYSCONFIG1_GPIO2 to 0x01, so clear both bits and
then set just bit 2. Is there a more elegant way to do that?
Should I just add "/* GPIO2 */" at the end of the line?
> 
> > +   if (de)
> > +   radio->registers[SYSCONFIG1] |= SYSCONFIG1_DE;
> > retval = si470x_set_register(radio, SYSCONFIG1);
> > if (retval < 0)
> > goto done;
> >   
> 
> Also, this is now set in si470x_start, so the same code can now be
> removed in si470x_fops_open for i2c.
> 
> In general I would feel happier if you just add a 'bool is_i2c'
> argument to si470x_start and only change SYSCONFIG1 for the i2c case.
> 
I can redo it that way if you would like, but to me it seems
better to write code that just works for both instead of
maintaining two different start sequences? The only difference
is that the i2c version needs GPIO2 set as an interrupt while
the USB version doesn't use GPIO2 at all. So it doesn't affect
the USB version to enable the interrupt on GPIO2.
> Regards,
> 
>   Hans

Thanks,
Doug


Re: [PATCH v3 01/10] pwm: extend PWM framework with PWM modes

2018-02-24 Thread kbuild test robot
Hi Claudiu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on pwm/for-next]
[also build test WARNING on v4.16-rc2 next-20180223]
[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/Claudiu-Beznea/extend-PWM-framework-to-support-PWM-modes/20180225-024011
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git 
for-next
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa 

All warnings (new ones prefixed by >>):

>> drivers//pwm/pwm-sun4i.c:36:0: warning: "PWM_MODE" redefined
#define PWM_MODE  BIT(7)

   In file included from drivers//pwm/pwm-sun4i.c:19:0:
   include/linux/pwm.h:40:0: note: this is the location of the previous 
definition
#define PWM_MODE(name)  BIT(PWM_MODE_##name##_BIT)


vim +/PWM_MODE +36 drivers//pwm/pwm-sun4i.c

09853ce7 Alexandre Belloni 2014-12-17  29  
09853ce7 Alexandre Belloni 2014-12-17  30  #define PWMCH_OFFSET 15
09853ce7 Alexandre Belloni 2014-12-17  31  #define PWM_PRESCAL_MASK 
GENMASK(3, 0)
09853ce7 Alexandre Belloni 2014-12-17  32  #define PWM_PRESCAL_OFF  0
09853ce7 Alexandre Belloni 2014-12-17  33  #define PWM_EN   
BIT(4)
09853ce7 Alexandre Belloni 2014-12-17  34  #define PWM_ACT_STATE
BIT(5)
09853ce7 Alexandre Belloni 2014-12-17  35  #define PWM_CLK_GATING   
BIT(6)
09853ce7 Alexandre Belloni 2014-12-17 @36  #define PWM_MODE BIT(7)
09853ce7 Alexandre Belloni 2014-12-17  37  #define PWM_PULSEBIT(8)
09853ce7 Alexandre Belloni 2014-12-17  38  #define PWM_BYPASS   BIT(9)
09853ce7 Alexandre Belloni 2014-12-17  39  

:: The code at line 36 was first introduced by commit
:: 09853ce7bc1003a490c7ee74a5705d7a7cf16b7d pwm: Add Allwinner SoC support

:: TO: Alexandre Belloni 
:: CC: Thierry Reding 

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


.config.gz
Description: application/gzip


[PATCH 07/12] [media] ngene: add support for DuoFlex S2 V4 addon modules

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Add support for the STV0910/STV6111/LNBH25 based DuoFlex S2 V4 DVB-S2
addon modules by recognizing them from their XO2 type value and using
the auxiliary stv0910, stv6111 and lnbh25 driver to form a complete
DVB frontend.

This also adds autoselection (if MEDIA_SUBDRV_AUTOSELECT) of the STV0910,
STV6111 and LNBH25 demod/tuner/LNB-IC drivers to Kconfig.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/Kconfig   |  3 ++
 drivers/media/pci/ngene/ngene-cards.c | 83 +++
 2 files changed, 86 insertions(+)

diff --git a/drivers/media/pci/ngene/Kconfig b/drivers/media/pci/ngene/Kconfig
index f717567f54a5..e06d019996f3 100644
--- a/drivers/media/pci/ngene/Kconfig
+++ b/drivers/media/pci/ngene/Kconfig
@@ -11,6 +11,9 @@ config DVB_NGENE
select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2841ER if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_STV0910 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_STV6111 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_LNBH25 if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2099 if MEDIA_SUBDRV_AUTOSELECT
---help---
  Support for Micronas PCI express cards with nGene bridge.
diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index cdc8db14c606..00b100660784 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -46,6 +46,9 @@
 #include "stv0367_priv.h"
 #include "tda18212.h"
 #include "cxd2841er.h"
+#include "stv0910.h"
+#include "stv6111.h"
+#include "lnbh25.h"
 
 //
 /* I2C transfer functions used for demod/tuner probing***/
@@ -152,6 +155,30 @@ static int tuner_attach_stv6110(struct ngene_channel *chan)
return 0;
 }
 
+static int tuner_attach_stv6111(struct ngene_channel *chan)
+{
+   struct device *pdev = &chan->dev->pci_dev->dev;
+   struct i2c_adapter *i2c;
+   struct dvb_frontend *fe;
+   u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60);
+
+   /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
+   if (chan->number < 2)
+   i2c = &chan->dev->channel[0].i2c_adapter;
+   else
+   i2c = &chan->dev->channel[1].i2c_adapter;
+
+   fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
+   if (!fe) {
+   fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
+   if (!fe) {
+   dev_err(pdev, "stv6111_attach() failed!\n");
+   return -ENODEV;
+   }
+   }
+   return 0;
+}
+
 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
struct ngene_channel *chan = fe->sec_priv;
@@ -283,6 +310,8 @@ static int tuner_attach_probe(struct ngene_channel *chan)
case DEMOD_TYPE_SONY_C2T2:
case DEMOD_TYPE_SONY_C2T2I:
return tuner_attach_tda18212(chan, chan->demod_type);
+   case DEMOD_TYPE_STV0910:
+   return tuner_attach_stv6111(chan);
}
 
return -EINVAL;
@@ -326,6 +355,54 @@ static int demod_attach_stv0900(struct ngene_channel *chan)
return 0;
 }
 
+static struct stv0910_cfg stv0910_p = {
+   .adr  = 0x68,
+   .parallel = 1,
+   .rptlvl   = 4,
+   .clk  = 3000,
+};
+
+static struct lnbh25_config lnbh25_cfg = {
+   .i2c_address = 0x0c << 1,
+   .data2_config = LNBH25_TEN
+};
+
+static int demod_attach_stv0910(struct ngene_channel *chan,
+   struct i2c_adapter *i2c)
+{
+   struct device *pdev = &chan->dev->pci_dev->dev;
+   struct stv0910_cfg cfg = stv0910_p;
+   struct lnbh25_config lnbcfg = lnbh25_cfg;
+
+   chan->fe = dvb_attach(stv0910_attach, i2c, &cfg, (chan->number & 1));
+   if (!chan->fe) {
+   cfg.adr = 0x6c;
+   chan->fe = dvb_attach(stv0910_attach, i2c,
+ &cfg, (chan->number & 1));
+   }
+   if (!chan->fe) {
+   dev_err(pdev, "stv0910_attach() failed!\n");
+   return -ENODEV;
+   }
+
+   /*
+* attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
+* i2c addresses
+*/
+   lnbcfg.i2c_address = (((chan->number & 1) ? 0x0d : 0x0c) << 1);
+   if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
+   lnbcfg.i2c_address = (((chan->number & 1) ? 0x09 : 0x08) << 1);
+   if (!dvb_attach(lnbh25_attach, chan->fe, &lnbcfg, i2c)) {
+   dev_err(pdev, "lnbh25_attach() failed!\n");
+   dvb_frontend_detach(chan->fe);
+   chan->fe = NULL;
+   return -ENODEV;
+   }
+   }
+
+   return 0;
+}
+
 static struct stv0367_config ddb_stv0367_config[] = {
{
.

[PATCH 06/12] [media] ngene: add support for Sony CXD28xx-based DuoFlex modules

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Recognize (probe) and support (attach) all Sony CXD28xx based DuoFlex
addon modules/cards, namely the DuoFlex CT2 (CXD2837), ISDB-T (CXD2838),
C2T2 (CXD2843) and C2T2I (CXD2854). Since all these modules are equipped
with a MachXO2 interface, that support is required for the hardware to
work. This functionality utilises the auxiliary cxd2841er and tda18212
drivers.

This also adds autoselection (if MEDIA_SUBDRV_AUTOSELECT) of the CXD2841ER
demod driver to Kconfig. The __maybe_unused annotation can now be removed
from the xo2names array.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/Kconfig   |  1 +
 drivers/media/pci/ngene/ngene-cards.c | 63 ---
 2 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/ngene/Kconfig b/drivers/media/pci/ngene/Kconfig
index c3254f9dc8ad..f717567f54a5 100644
--- a/drivers/media/pci/ngene/Kconfig
+++ b/drivers/media/pci/ngene/Kconfig
@@ -9,6 +9,7 @@ config DVB_NGENE
select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MT2131 if MEDIA_SUBDRV_AUTOSELECT
select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_CXD2841ER if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2099 if MEDIA_SUBDRV_AUTOSELECT
---help---
diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 05b8e56999ec..cdc8db14c606 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -45,6 +45,7 @@
 #include "stv0367.h"
 #include "stv0367_priv.h"
 #include "tda18212.h"
+#include "cxd2841er.h"
 
 //
 /* I2C transfer functions used for demod/tuner probing***/
@@ -277,6 +278,10 @@ static int tuner_attach_probe(struct ngene_channel *chan)
case DEMOD_TYPE_DRXK:
return tuner_attach_tda18271(chan);
case DEMOD_TYPE_STV0367:
+   case DEMOD_TYPE_SONY_CT2:
+   case DEMOD_TYPE_SONY_ISDBT:
+   case DEMOD_TYPE_SONY_C2T2:
+   case DEMOD_TYPE_SONY_C2T2I:
return tuner_attach_tda18212(chan, chan->demod_type);
}
 
@@ -358,6 +363,34 @@ static int demod_attach_stv0367(struct ngene_channel *chan,
return 0;
 }
 
+static int demod_attach_cxd28xx(struct ngene_channel *chan,
+   struct i2c_adapter *i2c, int osc24)
+{
+   struct device *pdev = &chan->dev->pci_dev->dev;
+   struct cxd2841er_config cfg;
+
+   /* the cxd2841er driver expects 8bit/shifted I2C addresses */
+   cfg.i2c_addr = ((chan->number & 1) ? 0x6d : 0x6c) << 1;
+
+   cfg.xtal = osc24 ? SONY_XTAL_24000 : SONY_XTAL_20500;
+   cfg.flags = CXD2841ER_AUTO_IFHZ | CXD2841ER_EARLY_TUNE |
+   CXD2841ER_NO_WAIT_LOCK | CXD2841ER_NO_AGCNEG |
+   CXD2841ER_TSBITS | CXD2841ER_TS_SERIAL;
+
+   /* attach frontend */
+   chan->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
+
+   if (!chan->fe) {
+   dev_err(pdev, "CXD28XX attach failed!\n");
+   return -ENODEV;
+   }
+
+   chan->fe->sec_priv = chan;
+   chan->gate_ctrl = chan->fe->ops.i2c_gate_ctrl;
+   chan->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
+   return 0;
+}
+
 static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
 {
struct ngene_channel *chan = fe->analog_demod_priv;
@@ -426,7 +459,7 @@ static int demod_attach_drxk(struct ngene_channel *chan,
 /* XO2 related lists and functions **/
 //
 
-static char __maybe_unused *xo2names[] = {
+static char *xo2names[] = {
"DUAL DVB-S2",
"DUAL DVB-C/T/T2",
"DUAL DVB-ISDBT",
@@ -513,7 +546,8 @@ static int cineS2_probe(struct ngene_channel *chan)
struct i2c_adapter *i2c;
struct stv090x_config *fe_conf;
u8 buf[3];
-   u8 xo2_type, xo2_id;
+   u8 xo2_type, xo2_id, xo2_demodtype;
+   u8 sony_osc24 = 0;
struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
int rc;
 
@@ -537,9 +571,28 @@ static int cineS2_probe(struct ngene_channel *chan)
else
init_xo2(chan, i2c);
 
-   /* TODO: implement support for XO2 module types */
-   dev_warn(pdev, "XO2 not supported\n");
-   return -ENODEV;
+   xo2_demodtype = DEMOD_TYPE_XO2 + xo2_id;
+
+   switch (xo2_demodtype) {
+   case DEMOD_TYPE_SONY_CT2:
+   case DEMOD_TYPE_SONY_ISDBT:
+   case DEMOD_TYPE_SONY_C2T2:
+   case DEMOD_TYPE_SONY_C2T2I:
+   dev_info(pdev, "%s (XO2) on channel %d\n",
+ 

[PATCH 11/12] [media] ngene: move the tsin_exchange() stripcopy block into a function

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Move the copy logic that will skip previously inserted TS NULL frames when
moving data to the DVB ring buffers into an own function. This is done to
not duplicate code all over the place with the following TS offset shift
fixup patch.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-dvb.c | 48 +
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-dvb.c 
b/drivers/media/pci/ngene/ngene-dvb.c
index f71fd41c762c..6d72b9f69418 100644
--- a/drivers/media/pci/ngene/ngene-dvb.c
+++ b/drivers/media/pci/ngene/ngene-dvb.c
@@ -123,6 +123,32 @@ static u32 overflow;
 static u32 stripped;
 #endif
 
+static inline void tsin_copy_stripped(struct ngene *dev, void *buf)
+{
+   if (memcmp(buf, fill_ts, sizeof(fill_ts)) != 0) {
+   if (dvb_ringbuffer_free(&dev->tsin_rbuf) >= 188) {
+   dvb_ringbuffer_write(&dev->tsin_rbuf, buf, 188);
+   wake_up(&dev->tsin_rbuf.queue);
+#ifdef DEBUG_CI_XFER
+   ok++;
+#endif
+   }
+#ifdef DEBUG_CI_XFER
+   else
+   overflow++;
+#endif
+   }
+#ifdef DEBUG_CI_XFER
+   else
+   stripped++;
+
+   if (ok % 100 == 0 && overflow)
+   dev_warn(&dev->pci_dev->dev,
+"%s: ok %u overflow %u dropped %u\n",
+__func__, ok, overflow, stripped);
+#endif
+}
+
 void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
 {
struct ngene_channel *chan = priv;
@@ -134,28 +160,8 @@ void *tsin_exchange(void *priv, void *buf, u32 len, u32 
clock, u32 flags)
 
if (dev->ci.en && chan->number == 2) {
while (len >= 188) {
-   if (memcmp(buf, fill_ts, sizeof fill_ts) != 0) {
-   if (dvb_ringbuffer_free(&dev->tsin_rbuf) >= 
188) {
-   dvb_ringbuffer_write(&dev->tsin_rbuf, 
buf, 188);
-   wake_up(&dev->tsin_rbuf.queue);
-#ifdef DEBUG_CI_XFER
-   ok++;
-#endif
-   }
-#ifdef DEBUG_CI_XFER
-   else
-   overflow++;
-#endif
-   }
-#ifdef DEBUG_CI_XFER
-   else
-   stripped++;
+   tsin_copy_stripped(dev, buf);
 
-   if (ok % 100 == 0 && overflow)
-   dev_warn(&dev->pci_dev->dev,
-"%s: ok %u overflow %u dropped %u\n",
-__func__, ok, overflow, stripped);
-#endif
buf += 188;
len -= 188;
}
-- 
2.16.1



[PATCH 12/12] [media] ngene: compensate for TS buffer offset shifts

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

A possible hardware bug was discovered when using CA addon hardware
attached to the ngene hardware, in that the TS input buffer much likely
will shift and thus become unaligned to 188 byte blocks (a full TS frame)
when things like CA module initialisation (which happens via differing
communication paths) takes place. This causes the TS NULL removal in
tsin_exchange() to fail to detect this previously inserted data and thus
causes userspace applications to receive data they didn't sent beforehand
and ultimately can cause troubles.

On driver load with an inserted CAM, buffers are fine at first (note that
the driver has to keep the communication running from/to the card by
inserting TS NULL frames, this is done in tsout_exchange() via
FillTSBuffer() - that data is simply sent back by the hardware):

  offset | 01   2   3   4   5  188 189 190 191 192 193  376
  data   | 47  1f  ff  10  6f  6f   47  1f  ff  10  6f  6f   47

After a few seconds, the CA module is recognised and initialised, which is
signalled by

  dvb_ca_en50221: dvb_ca adapter X: DVB CAM detected and initialised 
successfully

This is where the first shift happens (this is always four bytes), buffer
becomes like this:

  offset | 01   2   3   4   5  188 189 190 191 192 193  376
  data   | 6f  6f  6f  6f  47  1f   6f  6f  6f  6f  47  1f   6f

Next, VDR, TVHeadend or any other CI aware application is started, buffers
will shift by even more bytes. It is believed this is due to the hardware
not handling control and data bytes properly distinct, and control data
having an influence on the actual data stream, which we cannot properly
detect at the driver level.

Workaround this hardware quirk by adding a detection for the TS sync byte
0x47 before each TS frame copy, scan for a new SYNC byte and a TS NULL
packet if buffers become unaligned, take note of that offset and apply
that when copying data to the DVB ring buffers. The last <188 bytes from
the hardware buffers are stored in a temp buffer (tsin_buffer), for which
the remainder will be in the beginning of the next hardware buffer (next
iteration if tsin_exchange()). That remainder will be appended to the
temp buffer and finally sent to the DVB ring buffer. The resulting TS
stream is perfectly fine, and the TS NULL packets inserted by the driver
which are sent back are properly removed. The resulting offset is being
clamped to 188 byte segments (one TS packet). Though this can result in
a repeated TS packet if the overall offset grows beyond this (and it
will grow only on CA initialisation), this is still way better than
unaligned TS frames and data sent to userspace that just isn't supposed
to be there.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-dvb.c | 80 -
 drivers/media/pci/ngene/ngene.h |  3 ++
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ngene/ngene-dvb.c 
b/drivers/media/pci/ngene/ngene-dvb.c
index 6d72b9f69418..5abf69f6bc4b 100644
--- a/drivers/media/pci/ngene/ngene-dvb.c
+++ b/drivers/media/pci/ngene/ngene-dvb.c
@@ -38,6 +38,9 @@
 
 #include "ngene.h"
 
+static int ci_tsfix = 1;
+module_param(ci_tsfix, int, 0444);
+MODULE_PARM_DESC(ci_tsfix, "Detect and fix TS buffer offset shifs in 
conjunction with CI expansions (default: 1/enabled)");
 
 //
 /* COMMAND API interface /
@@ -123,6 +126,24 @@ static u32 overflow;
 static u32 stripped;
 #endif
 
+static int tsin_find_offset(void *buf, u32 len)
+{
+   int i, l;
+
+   l = len - sizeof(fill_ts);
+   if (l <= 0)
+   return -1;
+
+   for (i = 0; i < l; i++) {
+   if (((char *)buf)[i] == 0x47) {
+   if (!memcmp(buf + i, fill_ts, sizeof(fill_ts)))
+   return i;
+   }
+   }
+
+   return -1;
+}
+
 static inline void tsin_copy_stripped(struct ngene *dev, void *buf)
 {
if (memcmp(buf, fill_ts, sizeof(fill_ts)) != 0) {
@@ -153,18 +174,75 @@ void *tsin_exchange(void *priv, void *buf, u32 len, u32 
clock, u32 flags)
 {
struct ngene_channel *chan = priv;
struct ngene *dev = chan->dev;
-
+   int tsoff;
 
if (flags & DF_SWAP32)
swap_buffer(buf, len);
 
if (dev->ci.en && chan->number == 2) {
+   /* blindly copy buffers if ci_tsfix is disabled */
+   if (!ci_tsfix) {
+   while (len >= 188) {
+   tsin_copy_stripped(dev, buf);
+
+   buf += 188;
+   len -= 188;
+   }
+   return NULL;
+   }
+
+   /* ci_tsfix = 1 */
+
+   /*
+* since the remainder of the TS packet which got cut off
+  

[PATCH 05/12] [media] ngene: add XO2 module support

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Detect and initialise modules equipped with XO2 interfaces (Lattice
MachXO2). This requires a few more I2C transfer functions which this adds
aswell. Defines for the different possible (available) module types are
added to ngene.h. The support for the actual tuners contained on these
addon modules is kept separate from this commit and is being added with
the next commits.

The xo2names array is temporarily marked __maybe_unused to silence a
corresponding compiler warning at this stage.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 144 +-
 drivers/media/pci/ngene/ngene.h   |  12 +++
 2 files changed, 155 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 7ec5f68b1ec7..05b8e56999ec 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -50,6 +50,32 @@
 /* I2C transfer functions used for demod/tuner probing***/
 //
 
+static int i2c_io(struct i2c_adapter *adapter, u8 adr,
+ u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
+{
+   struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
+  .buf  = wbuf, .len   = wlen },
+ {.addr = adr,  .flags = I2C_M_RD,
+  .buf  = rbuf,  .len   = rlen } };
+   return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
+}
+
+static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
+{
+   struct i2c_msg msg = {.addr = adr, .flags = 0,
+ .buf = data, .len = len};
+
+   return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
+}
+
+static int i2c_write_reg(struct i2c_adapter *adap, u8 adr,
+u8 reg, u8 val)
+{
+   u8 msg[2] = {reg, val};
+
+   return i2c_write(adap, adr, msg, 2);
+}
+
 static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
 {
struct i2c_msg msgs[1] = {{.addr = adr,  .flags = I2C_M_RD,
@@ -78,6 +104,12 @@ static int i2c_read_regs(struct i2c_adapter *adapter,
 
return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
 }
+
+static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val)
+{
+   return i2c_read_regs(adapter, adr, reg, val, 1);
+}
+
 //
 /* Demod/tuner attachment ***/
 //
@@ -390,12 +422,98 @@ static int demod_attach_drxk(struct ngene_channel *chan,
return 0;
 }
 
+//
+/* XO2 related lists and functions **/
+//
+
+static char __maybe_unused *xo2names[] = {
+   "DUAL DVB-S2",
+   "DUAL DVB-C/T/T2",
+   "DUAL DVB-ISDBT",
+   "DUAL DVB-C/C2/T/T2",
+   "DUAL ATSC",
+   "DUAL DVB-C/C2/T/T2/I",
+};
+
+static int init_xo2(struct ngene_channel *chan, struct i2c_adapter *i2c)
+{
+   struct device *pdev = &chan->dev->pci_dev->dev;
+   u8 addr = 0x10;
+   u8 val, data[2];
+   int res;
+
+   res = i2c_read_regs(i2c, addr, 0x04, data, 2);
+   if (res < 0)
+   return res;
+
+   if (data[0] != 0x01)  {
+   dev_info(pdev, "Invalid XO2 on channel %d\n", chan->number);
+   return -1;
+   }
+
+   i2c_read_reg(i2c, addr, 0x08, &val);
+   if (val != 0) {
+   i2c_write_reg(i2c, addr, 0x08, 0x00);
+   msleep(100);
+   }
+   /* Enable tuner power, disable pll, reset demods */
+   i2c_write_reg(i2c, addr, 0x08, 0x04);
+   usleep_range(2000, 3000);
+   /* Release demod resets */
+   i2c_write_reg(i2c, addr, 0x08, 0x07);
+
+   /*
+* speed: 0=55,1=75,2=90,3=104 MBit/s
+* Note: The ngene hardware must be run at 75 MBit/s compared
+* to more modern ddbridge hardware which runs at 90 MBit/s,
+* else there will be issues with the data transport and non-
+* working secondary/slave demods/tuners.
+*/
+   i2c_write_reg(i2c, addr, 0x09, 1);
+
+   i2c_write_reg(i2c, addr, 0x0a, 0x01);
+   i2c_write_reg(i2c, addr, 0x0b, 0x01);
+
+   usleep_range(2000, 3000);
+   /* Start XO2 PLL */
+   i2c_write_reg(i2c, addr, 0x08, 0x87);
+
+   return 0;
+}
+
+static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id)
+{
+   u8 probe[1] = { 0x00 }, data[4];
+   u8 addr = 0x10;
+
+   *type = NGENE_XO2_TYPE_NONE;
+
+   if (i2c_io(i2c, addr, probe, 1, data, 4))
+   return 0;
+   if (data[0] == 'D' && data[1] == 'F') {
+   

[PATCH 10/12] [media] ngene: don't treat non-existing demods as error

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

When probing the I2C busses in cineS2_probe(), it's no error when there's
no hardware connected to the probed expansion connector, so print this
informal message with info severity.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index d603d0af703e..37e9f0eb6d20 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -728,7 +728,7 @@ static int cineS2_probe(struct ngene_channel *chan)
dev_info(pdev, "STV0367 on channel %d\n", chan->number);
demod_attach_stv0367(chan, i2c);
} else {
-   dev_err(pdev, "No demod found on chan %d\n", chan->number);
+   dev_info(pdev, "No demod found on chan %d\n", chan->number);
return -ENODEV;
}
return 0;
-- 
2.16.1



[PATCH 09/12] [media] ngene: check for CXD2099AR presence before attaching

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Currently, if there's no CXD2099AR attached to any expansion connector of
the ngene hardware, it will complain with this on every module load:

cxd2099 1-0040: No CXD2099AR detected at 0x40
cxd2099: probe of 1-0040 failed with error -5
ngene :02:00.0: CXD2099AR attach failed

This happens due to the logic assuming such hardware is always there and
blindly tries to attach the cxd2099 I2C driver. Rather add a probe
function (in ngene-cards.c with a prototype in ngene.h) to check for
the existence of such hardware before probing, and don't try further if
no CXD2099 was found.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 19 +++
 drivers/media/pci/ngene/ngene-core.c  | 14 ++
 drivers/media/pci/ngene/ngene.h   |  3 +++
 3 files changed, 36 insertions(+)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index dff55c7c9f86..d603d0af703e 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -505,6 +505,25 @@ static int port_has_stv0367(struct i2c_adapter *i2c)
return 1;
 }
 
+int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type)
+{
+   u8 val;
+   u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4];
+   struct i2c_msg msgs[2] = {{ .addr = 0x40,  .flags = 0,
+   .buf  = probe, .len   = 4 },
+ { .addr = 0x40,  .flags = I2C_M_RD,
+   .buf  = data,  .len   = 4 } };
+   val = i2c_transfer(i2c, msgs, 2);
+   if (val != 2)
+   return 0;
+
+   if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43)
+   *type = 2;
+   else
+   *type = 1;
+   return 1;
+}
+
 static int demod_attach_drxk(struct ngene_channel *chan,
 struct i2c_adapter *i2c)
 {
diff --git a/drivers/media/pci/ngene/ngene-core.c 
b/drivers/media/pci/ngene/ngene-core.c
index 526d0adfa427..f69a8fc1ec2a 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1589,6 +1589,20 @@ static void cxd_attach(struct ngene *dev)
.addr = 0x40,
.platform_data = &cxd_cfg,
};
+   int ret;
+   u8 type;
+
+   /* check for CXD2099AR presence before attaching */
+   ret = ngene_port_has_cxd2099(&dev->channel[0].i2c_adapter, &type);
+   if (!ret) {
+   dev_dbg(pdev, "No CXD2099AR found\n");
+   return;
+   }
+
+   if (type != 1) {
+   dev_warn(pdev, "CXD2099AR is uninitialized!\n");
+   return;
+   }
 
cxd_cfg.en = &ci->en;
 
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index 72195f6552b3..66d8eaa28549 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -909,6 +909,9 @@ int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 
level);
 void set_transfer(struct ngene_channel *chan, int state);
 void FillTSBuffer(void *Buffer, int Length, u32 Flags);
 
+/* Provided by ngene-cards.c */
+int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type);
+
 /* Provided by ngene-i2c.c */
 int ngene_i2c_init(struct ngene *dev, int dev_nr);
 
-- 
2.16.1



[PATCH 03/12] [media] ngene: use defines to identify the demod_type

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Make it more clear which demod_type is used for which hardware by having
defines for the possible demod_type values. With that, change the
demod_type evaluation in tuner_attach_probe() to a switch-case instead
of an if() for each possible value.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 11 +++
 drivers/media/pci/ngene/ngene.h   |  3 +++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 1de8cbee..065b83ee569b 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -123,10 +123,13 @@ static int tuner_attach_tda18271(struct ngene_channel 
*chan)
 
 static int tuner_attach_probe(struct ngene_channel *chan)
 {
-   if (chan->demod_type == 0)
+   switch (chan->demod_type) {
+   case DEMOD_TYPE_STV090X:
return tuner_attach_stv6110(chan);
-   if (chan->demod_type == 1)
+   case DEMOD_TYPE_DRXK:
return tuner_attach_tda18271(chan);
+   }
+
return -EINVAL;
 }
 
@@ -251,7 +254,7 @@ static int cineS2_probe(struct ngene_channel *chan)
i2c = &chan->dev->channel[1].i2c_adapter;
 
if (port_has_stv0900(i2c, chan->number)) {
-   chan->demod_type = 0;
+   chan->demod_type = DEMOD_TYPE_STV090X;
fe_conf = chan->dev->card_info->fe_config[chan->number];
/* demod found, attach it */
rc = demod_attach_stv0900(chan);
@@ -280,7 +283,7 @@ static int cineS2_probe(struct ngene_channel *chan)
return -EIO;
}
} else if (port_has_drxk(i2c, chan->number^2)) {
-   chan->demod_type = 1;
+   chan->demod_type = DEMOD_TYPE_DRXK;
demod_attach_drxk(chan, i2c);
} else {
dev_err(pdev, "No demod found on chan %d\n", chan->number);
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index caf8602c7459..9724701a3274 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -51,6 +51,9 @@
 #define VIDEO_CAP_MPEG4 512
 #endif
 
+#define DEMOD_TYPE_STV090X 0
+#define DEMOD_TYPE_DRXK1
+
 enum STREAM {
STREAM_VIDEOIN1 = 0,/* ITU656 or TS Input */
STREAM_VIDEOIN2,
-- 
2.16.1



[PATCH 00/12] ngene-updates: Hardware support, TS buffer shift fix

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Some love for the ngene driver, which runs the older Micronas nGene
based cards from Digital Devices like the cineS2 v5.5.

This series changes:

- Two more PCI IDs for more supported PCIe bridge hardware
- Conversion of all printk() to more proper dev_*() based logging (the
  module_init rather uses pr_*() logging since there's no *dev available
  yet).
- Support for all available DuoFlex addon modules from that vendor. All
  addon modules are electrically compatible and use the same interface,
  and the addons work very well on the aging ngene hardware.
- Check for CXD2099AR addon modules before blindly trying to attach them,
  removing unnecessary and maybe irritating error logging if such module
  isn't present.
- Workaround a hardware quirk in conjunction with the CXD2099AR module,
  CA modules and CAM control communication, causing the TS input buffer
  to shift albeit different communication paths are ought to be in use.

This series is based on the CXD2099 regmap conversion series, see [1].
Especially [2] is required for the STV0367 enablement patch (and the
following ones) since the use of the TDA18212 I2C tuner client relies
on the i2c_client variable to be present, which is added in the
forementioned CXD2099 series.

Please pick this up and merge.

[1] https://www.spinics.net/lists/linux-media/msg129183.html
[2] https://www.spinics.net/lists/linux-media/msg129187.html

Daniel Scheller (12):
  [media] ngene: add two additional PCI IDs
  [media] ngene: convert kernellog printing from printk() to dev_*()
macros
  [media] ngene: use defines to identify the demod_type
  [media] ngene: support STV0367 DVB-C/T DuoFlex addons
  [media] ngene: add XO2 module support
  [media] ngene: add support for Sony CXD28xx-based DuoFlex modules
  [media] ngene: add support for DuoFlex S2 V4 addon modules
  [media] ngene: deduplicate I2C adapter evaluation
  [media] ngene: check for CXD2099AR presence before attaching
  [media] ngene: don't treat non-existing demods as error
  [media] ngene: move the tsin_exchange() stripcopy block into a
function
  [media] ngene: compensate for TS buffer offset shifts

 drivers/media/pci/ngene/Kconfig   |   6 +
 drivers/media/pci/ngene/ngene-cards.c | 590 ++
 drivers/media/pci/ngene/ngene-core.c  | 101 +++---
 drivers/media/pci/ngene/ngene-dvb.c   | 122 +--
 drivers/media/pci/ngene/ngene.h   |  23 ++
 5 files changed, 721 insertions(+), 121 deletions(-)

-- 
2.16.1



[PATCH 02/12] [media] ngene: convert kernellog printing from printk() to dev_*() macros

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Convert all printk() and pr_*() kernel log printing to rather use the
dev_*() macros. Not only is it discouraged to use printk() (checkpatch
even complains about that), but also this helps identifying the exact PCI
device for any printed event, and it makes almost all printing shorter
in terms of code style since there's no need to use KERN_* DEVICE_NAME
any more (dev_*() will take care of this).

Since the dprintk macro define isn't used anymore, remove it.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 75 ---
 drivers/media/pci/ngene/ngene-core.c  | 75 +--
 drivers/media/pci/ngene/ngene-dvb.c   |  4 +-
 3 files changed, 84 insertions(+), 70 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 49f78bb31537..1de8cbee 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -23,6 +23,8 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -48,6 +50,7 @@
 
 static int tuner_attach_stv6110(struct ngene_channel *chan)
 {
+   struct device *pdev = &chan->dev->pci_dev->dev;
struct i2c_adapter *i2c;
struct stv090x_config *feconf = (struct stv090x_config *)
chan->dev->card_info->fe_config[chan->number];
@@ -63,7 +66,7 @@ static int tuner_attach_stv6110(struct ngene_channel *chan)
 
ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
if (ctl == NULL) {
-   printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
+   dev_err(pdev, "No STV6110X found!\n");
return -ENODEV;
}
 
@@ -100,6 +103,7 @@ static int drxk_gate_ctrl(struct dvb_frontend *fe, int 
enable)
 
 static int tuner_attach_tda18271(struct ngene_channel *chan)
 {
+   struct device *pdev = &chan->dev->pci_dev->dev;
struct i2c_adapter *i2c;
struct dvb_frontend *fe;
 
@@ -110,7 +114,7 @@ static int tuner_attach_tda18271(struct ngene_channel *chan)
if (chan->fe->ops.i2c_gate_ctrl)
chan->fe->ops.i2c_gate_ctrl(chan->fe, 0);
if (!fe) {
-   printk(KERN_ERR "No TDA18271 found!\n");
+   dev_err(pdev, "No TDA18271 found!\n");
return -ENODEV;
}
 
@@ -128,6 +132,7 @@ static int tuner_attach_probe(struct ngene_channel *chan)
 
 static int demod_attach_stv0900(struct ngene_channel *chan)
 {
+   struct device *pdev = &chan->dev->pci_dev->dev;
struct i2c_adapter *i2c;
struct stv090x_config *feconf = (struct stv090x_config *)
chan->dev->card_info->fe_config[chan->number];
@@ -144,7 +149,7 @@ static int demod_attach_stv0900(struct ngene_channel *chan)
(chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
: STV090x_DEMODULATOR_1);
if (chan->fe == NULL) {
-   printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
+   dev_err(pdev, "No STV0900 found!\n");
return -ENODEV;
}
 
@@ -154,7 +159,7 @@ static int demod_attach_stv0900(struct ngene_channel *chan)
 
if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
0, chan->dev->card_info->lnb[chan->number])) {
-   printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
+   dev_err(pdev, "No LNBH24 found!\n");
dvb_frontend_detach(chan->fe);
chan->fe = NULL;
return -ENODEV;
@@ -211,6 +216,7 @@ static int port_has_drxk(struct i2c_adapter *i2c, int port)
 static int demod_attach_drxk(struct ngene_channel *chan,
 struct i2c_adapter *i2c)
 {
+   struct device *pdev = &chan->dev->pci_dev->dev;
struct drxk_config config;
 
memset(&config, 0, sizeof(config));
@@ -220,7 +226,7 @@ static int demod_attach_drxk(struct ngene_channel *chan,
 
chan->fe = dvb_attach(drxk_attach, &config, i2c);
if (!chan->fe) {
-   printk(KERN_ERR "No DRXK found!\n");
+   dev_err(pdev, "No DRXK found!\n");
return -ENODEV;
}
chan->fe->sec_priv = chan;
@@ -231,6 +237,7 @@ static int demod_attach_drxk(struct ngene_channel *chan,
 
 static int cineS2_probe(struct ngene_channel *chan)
 {
+   struct device *pdev = &chan->dev->pci_dev->dev;
struct i2c_adapter *i2c;
struct stv090x_config *fe_conf;
u8 buf[3];
@@ -269,14 +276,14 @@ static int cineS2_probe(struct ngene_channel *chan)
}
rc = i2c_transfer(i2c, &i2c_msg, 1);
if (rc != 1) {
-   printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
+   dev_err(pdev, "Could not setup DPNx\n");
return -EIO;
}

[PATCH 01/12] [media] ngene: add two additional PCI IDs

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Add two more device IDs for cards supported by the ngene driver.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index bb49620540c5..49f78bb31537 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -749,6 +749,8 @@ static const struct ngene_info ngene_info_terratec = {
 //
 
 static const struct pci_device_id ngene_id_tbl[] = {
+   NGENE_ID(0x18c3, 0xab04, ngene_info_cineS2),
+   NGENE_ID(0x18c3, 0xab05, ngene_info_cineS2v5),
NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
-- 
2.16.1



[PATCH 08/12] [media] ngene: deduplicate I2C adapter evaluation

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

The I2C adapter evaluation (based on chan->number) is duplicated at
several places (tuner_attach_() functions, demod_attach_stv0900() and
cineS2_probe()). Clean this up by wrapping that construct in a separate
function which all users of that can pass the ngene_channel pointer and
get the correct I2C adapter from.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ngene/ngene-cards.c | 41 +--
 1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 00b100660784..dff55c7c9f86 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -118,17 +118,25 @@ static int i2c_read_reg(struct i2c_adapter *adapter, u8 
adr, u8 reg, u8 *val)
 /* Demod/tuner attachment ***/
 //
 
+static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan)
+{
+   /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
+   if (chan->number < 2)
+   return &chan->dev->channel[0].i2c_adapter;
+
+   return &chan->dev->channel[1].i2c_adapter;
+}
+
 static int tuner_attach_stv6110(struct ngene_channel *chan)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
struct stv090x_config *feconf = (struct stv090x_config *)
chan->dev->card_info->fe_config[chan->number];
struct stv6110x_config *tunerconf = (struct stv6110x_config *)
chan->dev->card_info->tuner_config[chan->number];
const struct stv6110x_devctl *ctl;
 
-   /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
if (chan->number < 2)
i2c = &chan->dev->channel[0].i2c_adapter;
else
@@ -158,16 +166,10 @@ static int tuner_attach_stv6110(struct ngene_channel 
*chan)
 static int tuner_attach_stv6111(struct ngene_channel *chan)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
struct dvb_frontend *fe;
u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60);
 
-   /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
-   if (chan->number < 2)
-   i2c = &chan->dev->channel[0].i2c_adapter;
-   else
-   i2c = &chan->dev->channel[1].i2c_adapter;
-
fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr);
if (!fe) {
fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4);
@@ -197,10 +199,9 @@ static int drxk_gate_ctrl(struct dvb_frontend *fe, int 
enable)
 static int tuner_attach_tda18271(struct ngene_channel *chan)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
struct dvb_frontend *fe;
 
-   i2c = &chan->dev->channel[0].i2c_adapter;
if (chan->fe->ops.i2c_gate_ctrl)
chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60);
@@ -240,7 +241,7 @@ static int tuner_tda18212_ping(struct ngene_channel *chan,
 static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
struct i2c_client *client;
struct tda18212_config config = {
.fe = chan->fe,
@@ -262,12 +263,6 @@ static int tuner_attach_tda18212(struct ngene_channel 
*chan, u32 dmdtype)
else
board_info.addr = 0x60;
 
-   /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
-   if (chan->number < 2)
-   i2c = &chan->dev->channel[0].i2c_adapter;
-   else
-   i2c = &chan->dev->channel[1].i2c_adapter;
-
/*
 * due to a hardware quirk with the I2C gate on the stv0367+tda18212
 * combo, the tda18212 must be probed by reading it's id _twice_ when
@@ -320,7 +315,7 @@ static int tuner_attach_probe(struct ngene_channel *chan)
 static int demod_attach_stv0900(struct ngene_channel *chan)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
struct stv090x_config *feconf = (struct stv090x_config *)
chan->dev->card_info->fe_config[chan->number];
 
@@ -620,7 +615,7 @@ static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, 
u8 *id)
 static int cineS2_probe(struct ngene_channel *chan)
 {
struct device *pdev = &chan->dev->pci_dev->dev;
-   struct i2c_adapter *i2c;
+   struct i2c_adapter *i2c = i2c_adapter_from_chan(chan);
   

[PATCH 04/12] [media] ngene: support STV0367 DVB-C/T DuoFlex addons

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

Add support for STV0367+TDA18212 based DuoFlex CT addon modules. For this,
add a demod probe function and all necessary demod/tuner attach functions
which use existing auxiliary drivers (stv0367 and tda18212) to support
this hardware. As tda18212 is an I2C client driver, proper cleanup code
is added to the deregistration sequence in ngene-core. To not cause use-
after-free situations when there's a CXD2099 I2C client connected, which
is rather freed in ngene-core.c:cxd_detach(), add i2c_client_fe to struct
ngene_channel to keep track if the i2c_client was allocated by a frontend
driver, rather than the CI code paths. Also move the I2C access functions
to the top of the file and add the required read_regs() function for the
tda18212 ping to work.

This adds autoselection (if MEDIA_SUBDRV_AUTOSELECT) of the STV0367 demod
driver and TDA18212 tuner driver to Kconfig aswell.

Signed-off-by: Daniel Scheller 
---
This and the following patches require the i2c_client variable that is
added by https://www.spinics.net/lists/linux-media/msg129187.html so
that makes it a somewhat hard-dependency.

 drivers/media/pci/ngene/Kconfig   |   2 +
 drivers/media/pci/ngene/ngene-cards.c | 194 ++
 drivers/media/pci/ngene/ngene-core.c  |  12 +++
 drivers/media/pci/ngene/ngene.h   |   2 +
 4 files changed, 191 insertions(+), 19 deletions(-)

diff --git a/drivers/media/pci/ngene/Kconfig b/drivers/media/pci/ngene/Kconfig
index 390ed75fe438..c3254f9dc8ad 100644
--- a/drivers/media/pci/ngene/Kconfig
+++ b/drivers/media/pci/ngene/Kconfig
@@ -8,6 +8,8 @@ config DVB_NGENE
select DVB_DRXK if MEDIA_SUBDRV_AUTOSELECT
select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MT2131 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2099 if MEDIA_SUBDRV_AUTOSELECT
---help---
  Support for Micronas PCI express cards with nGene bridge.
diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 065b83ee569b..7ec5f68b1ec7 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -42,8 +42,42 @@
 #include "drxk.h"
 #include "drxd.h"
 #include "dvb-pll.h"
+#include "stv0367.h"
+#include "stv0367_priv.h"
+#include "tda18212.h"
 
+//
+/* I2C transfer functions used for demod/tuner probing***/
+//
+
+static int i2c_read(struct i2c_adapter *adapter, u8 adr, u8 *val)
+{
+   struct i2c_msg msgs[1] = {{.addr = adr,  .flags = I2C_M_RD,
+  .buf  = val,  .len   = 1 } };
+   return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
+}
+
+static int i2c_read_reg16(struct i2c_adapter *adapter, u8 adr,
+ u16 reg, u8 *val)
+{
+   u8 msg[2] = {reg >> 8, reg & 0xff};
+   struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0,
+  .buf  = msg, .len   = 2},
+ {.addr = adr, .flags = I2C_M_RD,
+  .buf  = val, .len   = 1} };
+   return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
+}
 
+static int i2c_read_regs(struct i2c_adapter *adapter,
+u8 adr, u8 reg, u8 *val, u8 len)
+{
+   struct i2c_msg msgs[2] = {{.addr = adr,  .flags = 0,
+  .buf  = ®, .len   = 1},
+ {.addr = adr,  .flags = I2C_M_RD,
+  .buf  = val,  .len   = len} };
+
+   return (i2c_transfer(adapter, msgs, 2) == 2) ? 0 : -1;
+}
 //
 /* Demod/tuner attachment ***/
 //
@@ -85,7 +119,6 @@ static int tuner_attach_stv6110(struct ngene_channel *chan)
return 0;
 }
 
-
 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
struct ngene_channel *chan = fe->sec_priv;
@@ -121,6 +154,89 @@ static int tuner_attach_tda18271(struct ngene_channel 
*chan)
return 0;
 }
 
+static int tuner_tda18212_ping(struct ngene_channel *chan,
+  struct i2c_adapter *i2c,
+  unsigned short adr)
+{
+   struct device *pdev = &chan->dev->pci_dev->dev;
+   u8 tda_id[2];
+   u8 subaddr = 0x00;
+
+   dev_dbg(pdev, "stv0367-tda18212 tuner ping\n");
+   if (chan->fe->ops.i2c_gate_ctrl)
+   chan->fe->ops.i2c_gate_ctrl(chan->fe, 1);
+
+   if (i2c_read_regs(i2c, adr, subaddr, tda_id, sizeof(tda_id)) < 0)
+   dev_dbg(pdev, "tda18212 ping 1 fail\n");
+  

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

2018-02-24 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 | 26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 3668a04359e8..52d06b30fabb 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -124,15 +124,26 @@ 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.
+* They are copied from the Settings\DecoderDefaults registry keys
+* present in the Windows driver .INF file for each norm.
+*/
static const u16 pal[][2] = {
+   { 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 },
@@ -143,14 +154,20 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
};
 
static const u16 ntsc[][2] = {
+   { 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 },
@@ -236,15 +253,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.16.2



[PATCH 2/2] usbtv: Add SECAM support

2018-02-24 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 | 34 +-
 drivers/media/usb/usbtv/usbtv.h   |  2 +-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c 
b/drivers/media/usb/usbtv/usbtv-video.c
index 52d06b30fabb..7dd4f25203db 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,
}
 };
 
@@ -177,6 +182,30 @@ static int usbtv_select_norm(struct usbtv *usbtv, 
v4l2_std_id norm)
{ USBTV_BASE + 0x0267, 0x0005 }
};
 
+   static const u16 secam[][2] = {
+   { 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 }
+   };
+
ret = usbtv_configure_for_norm(usbtv, norm);
 
if (!ret) {
@@ -184,6 +213,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;
@@ -595,7 +626,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.16.2



[PATCH 0/2] usbtv: Add SECAM support

2018-02-24 Thread Hugo Grostabussiat
This patch series adds support for the SECAM standard to the USBTV
video grabber driver.

The first patch prepares for the inclusion of further decoder
configuration sequences by making them follow the same order and length
as the sequences which can be found inside the Windows driver's .INF
file.

The second patch adds the SECAM decoder configuration sequence found in
the .INF file, and exposes SECAM support to userspace.

Hugo Grostabussiat (2):
  usbtv: Use same decoder sequence as Windows driver
  usbtv: Add SECAM support

 drivers/media/usb/usbtv/usbtv-video.c | 60 +--
 drivers/media/usb/usbtv/usbtv.h   |  2 +-
 2 files changed, 51 insertions(+), 11 deletions(-)

-- 
2.16.2



[no subject]

2018-02-24 Thread Alfred Chow




Good Day,

This is the second time i am sending you this mail.

I am Mr. Alfred Cheuk Yu Chow, the Director for Credit & Marketing Chong
Hing Bank, Hong Kong, need your assistance in a deal that will be of
mutual benefit.

Email me back for more details.

Regards.








Re: [PATCH] [media] dvb_ca_en50221: fix severity of successful CAM init log message

2018-02-24 Thread Jasmin J.
Hi!

Is OK for me, so:
  Acked-by: Jasmin Jessich 

BR,
   Jasmin


[linuxtv-media:fixes 3/11] ERROR: "vb2_core_streamoff" [drivers/media/dvb-core/dvb-core.ko] undefined!

2018-02-24 Thread kbuild test robot
tree:   git://linuxtv.org/media_tree.git fixes
head:   3dd6b560dc5d59e7cb6dbda6e85dc9af7925fcf8
commit: ec5b100462543aee1f3e139e168699fd3b05cdc6 [3/11] media: dvb: fix 
DVB_MMAP symbol name
config: i386-randconfig-c0-02241943 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
git checkout ec5b100462543aee1f3e139e168699fd3b05cdc6
# save the attached .config to linux build tree
make ARCH=i386 

Note: the linuxtv-media/fixes HEAD 3dd6b560dc5d59e7cb6dbda6e85dc9af7925fcf8 
builds fine.
  It only hurts bisectibility.

All errors (new ones prefixed by >>):

>> ERROR: "vb2_core_streamoff" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_dqbuf" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_mmap" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_qbuf" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_querybuf" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_streamon" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_poll" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_vmalloc_memops" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_plane_vaddr" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_buffer_done" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_queue_release" [drivers/media/dvb-core/dvb-core.ko] 
>> undefined!
>> ERROR: "vb2_core_expbuf" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_reqbufs" [drivers/media/dvb-core/dvb-core.ko] undefined!
>> ERROR: "vb2_core_queue_init" [drivers/media/dvb-core/dvb-core.ko] undefined!

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


.config.gz
Description: application/gzip


[PATCH] [media] dvb_ca_en50221: fix severity of successful CAM init log message

2018-02-24 Thread Daniel Scheller
From: Daniel Scheller 

A successful CA module initialisation isn't an error. Change the log print
to info severity accordingly.

Cc: Jasmin Jessich 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-core/dvb_ca_en50221.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c 
b/drivers/media/dvb-core/dvb_ca_en50221.c
index 204d0f6c678d..97365a863519 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1254,8 +1254,8 @@ static void dvb_ca_en50221_thread_state_machine(struct 
dvb_ca_private *ca,
ca->pub->slot_ts_enable(ca->pub, slot);
sl->slot_state = DVB_CA_SLOTSTATE_RUNNING;
dvb_ca_en50221_thread_update_delay(ca);
-   pr_err("dvb_ca adapter %d: DVB CAM detected and initialised 
successfully\n",
-  ca->dvbdev->adapter->num);
+   pr_info("dvb_ca adapter %d: DVB CAM detected and initialised 
successfully\n",
+   ca->dvbdev->adapter->num);
break;
 
case DVB_CA_SLOTSTATE_RUNNING:
-- 
2.16.1



[PATCH v3] media: video-i2c: add video-i2c driver

2018-02-24 Thread Matt Ranostay
There are several thermal sensors that only have a low-speed bus
interface but output valid video data. This patchset enables support
for the AMG88xx "Grid-Eye" sensor family.

Cc: Luca Barbato 
Cc: Laurent Pinchart 
Signed-off-by: Matt Ranostay 
---
Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 547 ++
 3 files changed, 557 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 8fdd673d449f..53aede720e0f 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -917,6 +917,15 @@ config VIDEO_M52790
 
 To compile this driver as a module, choose M here: the
 module will be called m52790.
+
+config VIDEO_I2C
+   tristate "I2C transport video support"
+   depends on VIDEO_V4L2 && I2C
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enable the I2C transport video support which supports the
+ following:
+  * Panasonic AMG88xx Grid-Eye Sensors
 endmenu
 
 menu "Sensors used on soc_camera driver"
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 26b19a2e9d04..5d4c06cb3f6f 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -91,6 +91,7 @@ obj-$(CONFIG_VIDEO_LM3646)+= lm3646.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
+obj-$(CONFIG_VIDEO_I2C)+= video-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)  += ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
new file mode 100644
index ..ea8ab2fcd580
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,547 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay 
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VIDEO_I2C_DRIVER   "video-i2c"
+#define MAX_BUFFER_SIZE128
+
+struct video_i2c_chip;
+
+struct video_i2c_buffer {
+   struct vb2_v4l2_buffer vb;
+   struct list_head list;
+};
+
+struct video_i2c_data {
+   struct i2c_client *client;
+   const struct video_i2c_chip *chip;
+   struct mutex lock;
+   spinlock_t slock;
+   struct mutex queue_lock;
+
+   struct v4l2_device v4l2_dev;
+   struct video_device vdev;
+   struct vb2_queue vb_vidq;
+
+   struct task_struct *kthread_vid_cap;
+   struct list_head vid_cap_active;
+};
+
+static struct v4l2_fmtdesc amg88xx_format = {
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct video_i2c_chip {
+   /* video dimensions */
+   const struct v4l2_fmtdesc *format;
+   const struct v4l2_frmsize_discrete *size;
+
+   /* max frames per second */
+   unsigned int max_fps;
+
+   /* pixel buffer size */
+   unsigned int buffer_size;
+
+   /* pixel size in bits */
+   unsigned int bpp;
+
+   /* xfer function */
+   int (*xfer)(struct video_i2c_data *data, char *buf);
+};
+
+static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
+{
+   struct i2c_client *client = data->client;
+   struct i2c_msg msg[2];
+   u8 reg = 0x80;
+   int ret;
+
+   msg[0].addr = client->addr;
+   msg[0].flags = 0;
+   msg[0].len = 1;
+   msg[0].buf  = (char *) ®
+
+   msg[1].addr = client->addr;
+   msg[1].flags = I2C_M_RD;
+   msg[1].len = data->chip->buffer_size;
+   msg[1].buf = (char *) buf;
+
+   ret = i2c_transfer(client->adapter, msg, 2);
+
+   return (ret == 2) ? 0 : -EIO;
+}
+
+static const struct video_i2c_chip video_i2c_chip = {
+   .size   = &amg88xx_size,
+   .format = &amg88xx_format,
+   .max_fps= 10,
+   .buffer_size= 128,
+   .bpp= 16,
+   .xfer   = &amg88xx_xfer,
+};
+
+static const struct v4l2_file_operations video_i2c_fops = {
+   .owner  = THIS_MODULE,
+   .open   = v4l2_fh_open,
+   .release= vb2_fop_release,
+   .poll   = vb2_fop_poll,
+   .read   = vb2_fop_read,
+   .mmap   = vb2_fop_mmap,
+   .unlocked_ioctl = 

Re: [PATCH v2] media: video-i2c: add video-i2c driver

2018-02-24 Thread kbuild test robot
Hi Matt,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.16-rc2 next-20180223]
[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/Matt-Ranostay/media-video-i2c-add-video-i2c-driver/20180218-181041
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-n0-02241505 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

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

   drivers/media/i2c/video-i2c.c: In function 'video_i2c_thread_vid_cap':
>> drivers/media/i2c/video-i2c.c:205:12: error: implicit declaration of 
>> function 'kthread_should_stop'; did you mean 'freezer_should_skip'? 
>> [-Werror=implicit-function-declaration]
 } while (!kthread_should_stop());
   ^~~
   freezer_should_skip
   drivers/media/i2c/video-i2c.c: In function 'start_streaming':
>> drivers/media/i2c/video-i2c.c:218:26: error: implicit declaration of 
>> function 'kthread_run'; did you mean 'it_real_fn'? 
>> [-Werror=implicit-function-declaration]
 data->kthread_vid_cap = kthread_run(video_i2c_thread_vid_cap, data,
 ^~~
 it_real_fn
>> drivers/media/i2c/video-i2c.c:218:24: warning: assignment makes pointer from 
>> integer without a cast [-Wint-conversion]
 data->kthread_vid_cap = kthread_run(video_i2c_thread_vid_cap, data,
   ^
   drivers/media/i2c/video-i2c.c: In function 'stop_streaming':
>> drivers/media/i2c/video-i2c.c:243:2: error: implicit declaration of function 
>> 'kthread_stop'; did you mean 'vb2_thread_stop'? 
>> [-Werror=implicit-function-declaration]
 kthread_stop(data->kthread_vid_cap);
 ^~~~
 vb2_thread_stop
   cc1: some warnings being treated as errors

vim +205 drivers/media/i2c/video-i2c.c

   164  
   165  static int video_i2c_thread_vid_cap(void *priv)
   166  {
   167  struct video_i2c_data *data = priv;
   168  
   169  set_freezable();
   170  
   171  do {
   172  unsigned long start_jiffies = jiffies;
   173  unsigned int delay = msecs_to_jiffies(1000 / 
data->chip->max_fps);
   174  struct video_i2c_buffer *vid_cap_buf = NULL;
   175  int schedule_delay;
   176  
   177  try_to_freeze();
   178  
   179  spin_lock(&data->slock);
   180  
   181  if (!list_empty(&data->vid_cap_active)) {
   182  vid_cap_buf = 
list_entry(data->vid_cap_active.next,
   183   struct 
video_i2c_buffer, list);
   184  list_del(&vid_cap_buf->list);
   185  }
   186  
   187  spin_unlock(&data->slock);
   188  
   189  if (vid_cap_buf) {
   190  struct vb2_buffer *vb2_buf = 
&vid_cap_buf->vb.vb2_buf;
   191  void *vbuf = vb2_plane_vaddr(vb2_buf, 0);
   192  int ret = data->chip->xfer(data, vbuf);
   193  
   194  vb2_buf->timestamp = ktime_get_ns();
   195  vb2_buffer_done(vb2_buf, ret ?
   196  VB2_BUF_STATE_ERROR : 
VB2_BUF_STATE_DONE);
   197  }
   198  
   199  schedule_delay = delay - (jiffies - start_jiffies);
   200  
   201  if (time_after(jiffies, start_jiffies + delay))
   202  schedule_delay = delay;
   203  
   204  schedule_timeout_interruptible(schedule_delay);
 > 205  } while (!kthread_should_stop());
   206  
   207  return 0;
   208  }
   209  
   210  static int start_streaming(struct vb2_queue *vq, unsigned int count)
   211  {
   212  struct video_i2c_data *data = vb2_get_drv_priv(vq);
   213  struct video_i2c_buffer *buf, *tmp;
   214  
   215  if (data->kthread_vid_cap)
   216  return 0;
   217  
 > 218  data->kthread_vid_cap = kthread_run(video_i2c_thread_vid_cap, 
 > data,
   219  "%s-vid-cap", 
data->v4l2_dev.name);
   220  if (!IS_ERR(data->kthread_vid_cap))
   221  return 0;
   222  
   223  spin_lock(&data->slock);
   224  
   225  list_for_each_entry_safe(buf, tmp, &data->vid_cap_active, list) 
{
   226  list_del(&buf->list);
   227  vb2_buffer_done(&buf->vb.vb2_buf,
   228  VB2_BUF_STATE_QUEUED);
   229  }
   230  
   231  spin_unlock(&data->slock);
   232  
   233  return PTR_ERR(data->kthread_vid_cap);
  

[GIT PULL FOR v4.17] R-Car VSP changes

2018-02-24 Thread Laurent Pinchart
Hi Mauro,

The following changes since commit 29422737017b866d4a51014cc7522fa3a99e8852:

  media: rc: get start time just before calling driver tx (2018-02-14 14:17:21 
-0500)

are available in the Git repository at:

  git://linuxtv.org/pinchartl/media.git v4l2/vsp1/next

for you to fetch changes up to 3ce28e6d5808d2f805018c7903366d306f483ee8:

  v4l: vsp1: Fix video output on R8A77970 (2018-02-23 15:03:17 +0200)


Kieran Bingham (1):
  v4l: vsp1: Fix header display list status check in continuous mode

Laurent Pinchart (2):
  v4l: vsp1: Fix display stalls when requesting too many inputs
  v4l: vsp1: Print the correct blending unit name in debug messages

Sergei Shtylyov (1):
  v4l: vsp1: Fix video output on R8A77970   

  


  
Wolfram Sang (1):   

  
  v4l: vsp1: Fix mask creation for MULT_ALPHA_RATIO 

  


  
 drivers/media/platform/vsp1/vsp1_dl.c   |  3 ++-   

  
 drivers/media/platform/vsp1/vsp1_drm.c  | 30 +-

  
 drivers/media/platform/vsp1/vsp1_lif.c  | 12   

  
 drivers/media/platform/vsp1/vsp1_regs.h |  8 +++-  

  
 4 files changed, 38 insertions(+), 15 deletions(-)

-- 
Regards,

Laurent Pinchart