RE: Are media drivers abusing of GFP_DMA? - was: Re: [LSF/MM TOPIC NOTES] x86 ZONE_DMA love

2018-05-09 Thread Yasunari.Takiguchi
Dear Mauro

> -Original Message-
> 
> There was a recent discussion about the use/abuse of GFP_DMA flag when
> allocating memories at LSF/MM 2018 (see Luis notes enclosed).
> 
> The idea seems to be to remove it, using CMA instead. Before doing that,
> better to check if what we have on media is are valid use cases for it,
> or
> if it is there just due to some misunderstanding (or because it was
> copied from some other code).
> 
> Hans de Goede sent us today a patch stopping abuse at gspca, and I'm
> also posting today two other patches meant to stop abuse of it on USB
> drivers. Still, there are 4 platform drivers using it:
> 
>   $ git grep -l -E "GFP_DMA\\b" drivers/media/
>   drivers/media/platform/omap3isp/ispstat.c
>   drivers/media/platform/sti/bdisp/bdisp-hw.c
>   drivers/media/platform/sti/hva/hva-mem.c
>   drivers/media/spi/cxd2880-spi.c
> 
> Could you please check if GFP_DMA is really needed there, or if it is
> just because of some cut-and-paste from some other place?
About drivers/media/spi/cxd2880-spi.c,
we referred to kmalloc of driver/spi/spi.c spi_write_then_read() function and 
made this code. 

Regards,
Takiguchi


[PATCH 3/3] [media] cxd2880: Changed version information

2018-04-26 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the version update for this cxd2880 driver changing. 

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
   -updated version information

 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
index fab55038b37b..c6d6c8dd16a1 100644
--- a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
@@ -7,6 +7,6 @@
  * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  */
 
-#define CXD2880_TNRDMD_DRIVER_VERSION "1.4.1 - 1.0.4"
+#define CXD2880_TNRDMD_DRIVER_VERSION "1.4.1 - 1.0.5"
 
-#define CXD2880_TNRDMD_DRIVER_RELEASE_DATE "2018-01-17"
+#define CXD2880_TNRDMD_DRIVER_RELEASE_DATE "2018-04-25"
-- 
2.15.1



[PATCH 2/3] [media] cxd2880:Optimized spi drive current and BER/PER set/get condition

2018-04-26 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the optimization for SPI drive current and 
signal lock condition check part for BER/PER measure
to ensure BER/PER are stable

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -reduced the SPI output drive current
  -optimized signal lock condition check part for BER/PER measure
   to ensure BER/PER are stable

 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
index d474dc1b05da..bd9101e246d5 100644
--- a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -520,6 +520,15 @@ static int cxd2880_init(struct dvb_frontend *fe)
pr_err("cxd2880 integ init failed %d\n", ret);
return ret;
}
+
+   ret = cxd2880_tnrdmd_set_cfg(>tnrdmd,
+CXD2880_TNRDMD_CFG_TSPIN_CURRENT,
+0x00);
+   if (ret) {
+   mutex_unlock(priv->spi_mutex);
+   pr_err("cxd2880 set config failed %d\n", ret);
+   return ret;
+   }
mutex_unlock(priv->spi_mutex);
 
pr_debug("OK.\n");
@@ -1126,7 +1135,7 @@ static int cxd2880_get_stats(struct dvb_frontend *fe,
priv = fe->demodulator_priv;
c = >dtv_property_cache;
 
-   if (!(status & FE_HAS_LOCK)) {
+   if (!(status & FE_HAS_LOCK) || !(status & FE_HAS_CARRIER)) {
c->pre_bit_error.len = 1;
c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
c->pre_bit_count.len = 1;
@@ -1345,7 +1354,8 @@ static int cxd2880_read_status(struct dvb_frontend *fe,
 
pr_debug("status %d\n", *status);
 
-   if (priv->s == 0 && (*status & FE_HAS_LOCK)) {
+   if (priv->s == 0 && (*status & FE_HAS_LOCK) &&
+   (*status & FE_HAS_CARRIER)) {
mutex_lock(priv->spi_mutex);
if (c->delivery_system == SYS_DVBT) {
ret = cxd2880_set_ber_per_period_t(fe);
-- 
2.15.1



[PATCH 1/3] [media] cxd2880-spi: Modified how to declare structure

2018-04-26 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the modification of structure declaration for spi_transfer. 

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
[Change list]
   drivers/media/spi/cxd2880-spi.c
  -modified how to declare spi_transfer structure

 drivers/media/spi/cxd2880-spi.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
index 4df3bd312f48..754940f7e964 100644
--- a/drivers/media/spi/cxd2880-spi.c
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -60,14 +60,13 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
 {
struct spi_message msg;
-   struct spi_transfer tx;
+   struct spi_transfer tx = {};
 
if (!spi || !data) {
pr_err("invalid arg\n");
return -EINVAL;
}
 
-   memset(, 0, sizeof(tx));
tx.tx_buf = data;
tx.len = size;
 
@@ -130,7 +129,7 @@ static int cxd2880_spi_read_ts(struct spi_device *spi,
int ret;
u8 data[3];
struct spi_message message;
-   struct spi_transfer transfer[2];
+   struct spi_transfer transfer[2] = {};
 
if (!spi || !read_data || !packet_num) {
pr_err("invalid arg\n");
@@ -146,7 +145,6 @@ static int cxd2880_spi_read_ts(struct spi_device *spi,
data[2] = packet_num;
 
spi_message_init();
-   memset(transfer, 0, sizeof(transfer));
 
transfer[0].len = 3;
transfer[0].tx_buf = data;
@@ -383,7 +381,7 @@ static int cxd2880_start_feed(struct dvb_demux_feed *feed)
}
}
if (i == CXD2880_MAX_FILTER_SIZE) {
-   pr_err("PID filter is full. Assumed bug.\n");
+   pr_err("PID filter is full.\n");
return -EINVAL;
}
if (!dvb_spi->all_pid_feed_count)
-- 
2.15.1



[PATCH 0/3] [media] cxd2880: modified structure declaration and optimized the driver

2018-04-26 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the update patch for patch Sony CXD2880 DVB-T2/T tuner + 
demodulator driver.

We modified how to declare structure and
optimized spi drive current and 
signal lock condition check part for BER/PER measure
to ensure BER/PER are stable.

The change history of this patch series is as below.

[Change list]
(1)The detail change items of each files are as below.
[PATCH 1/3]
   drivers/media/spi/cxd2880-spi.c
 -modified how to declare spi_transfer structure

[PATCH 2/3]
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
 -reduced the SPI output drive current
 -optimized signal lock condition check part for BER/PER measure
  to ensure BER/PER are stable

[PATCH 3/3]
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

Thanks,
Takiguchi
---
 drivers/media/spi/cxd2880-spi.c | 8 
+++-
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c   | 14 
--
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h | 4 ++--

 3 files changed, 17 insertions(+), 9 deletions(-)

2.15.1



RE: [PATCH v5 02/12] [media] cxd2880-spi: Add support for CXD2880 SPI interface

2018-04-05 Thread Yasunari.Takiguchi
Hi, Mauro

> > +   u8 send_data[BURST_WRITE_MAX + 4];
> > +   const u8 *write_data_top = NULL;
> > +   int ret = 0;
> > +
> > +   if (!spi || !data) {
> > +   pr_err("invalid arg\n");
> > +   return -EINVAL;
> > +   }
> > +   if (size > BURST_WRITE_MAX) {
> > +   pr_err("data size > WRITE_MAX\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   if (sub_address + size > 0x100) {
> > +   pr_err("out of range\n");
> > +   return -EINVAL;
> > +   }
> 
> It is better to use dev_err(spi->dev, ...) instead of pr_err().

I got comment for this previous version patch as below
--
The best would be to se dev_err() & friends for printing messages, as they 
print the device's name as filled at struct device.
If you don't use, please add a define that will print the name at the logs, 
like:

  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

either at the begining of the driver or at some header file.

Btw, I'm noticing that you're also using dev_err() on other places of the code. 
Please standardize. OK, on a few places, you may still need to use pr_err(), if 
you need to print a message before initializing struct device, but I suspect 
that you can init
--

You pointed out here before. Because dev_foo () and pr_foo () were mixed.
We standardize with pr_foo() because the logs is outputted before getting the 
device structure.
Is it better to use dev_foo() where we can use it?

Takiguchi


RE: [PATCH] media: cxd2880-spi: avoid out-of-bounds access warning

2018-03-19 Thread Yasunari.Takiguchi
Hi.

We check the patch. 

> -Original Message-
> From: Arnd Bergmann [mailto:a...@arndb.de]
> Sent: Tuesday, March 13, 2018 9:09 PM
> To: Takiguchi, Yasunari (SSS); Mauro Carvalho Chehab
> Cc: Arnd Bergmann; Martin Sebor; Matsumoto, Toshihiko (SSS); Yonezawa,
> Kota (SSS); Watanabe, Satoshi (SSS); Yamamoto, Masayuki (SSS);
> linux-media@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] media: cxd2880-spi: avoid out-of-bounds access warning
> 
> The -Warray-bounds warning in gcc-8 triggers for a newly added file:
> 
> drivers/media/spi/cxd2880-spi.c: In function 'cxd2880_write_reg':
> drivers/media/spi/cxd2880-spi.c:111:3: error: 'memcpy' forming offset
> [133, 258] is out of the bounds [0, 132] of object 'send_data' with type
> 'u8[132]' {aka 'unsigned char[132]'} [-Werror=array-bounds]
> 
> The problem appears to be that we have two range checks in this function,
> first comparing against BURST_WRITE_MAX (128) and then comparing against
> a literal '255'. The logic checking the buffer size looks at the second
> one and decides that this might be the actual maximum data length.
> 
> This is understandable behavior from the compiler, but the code is
> actually safe. Since the first check is already shorter, we can remove
> the loop and only leave that. To be on the safe side in case BURST_WRITE_MAX
> might be increased, I'm leaving the check against U8_MAX.
> 
> Fixes: bd24fcddf6b8 ("media: cxd2880-spi: Add support for CXD2880 SPI
> interface")
> Cc: Martin Sebor 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/spi/cxd2880-spi.c | 24 +++-
>  1 file changed, 7 insertions(+), 17 deletions(-)

Reviewed-by: Yasunari Takiguchi 




RE: [PATCH v5 02/12] [media] cxd2880-spi: Add support for CXD2880 SPI interface

2018-03-07 Thread Yasunari.Takiguchi
Dear Mauro

I am very glad to hear your message.

Being busy, thank you for taking care of fixing patches as well also.
And we will improve about your below comments continuously.

Regards & Thanks
Takiguchi

> -Original Message-
> From: Mauro Carvalho Chehab [mailto:mche...@s-opensource.com]
> Sent: Wednesday, March 7, 2018 7:15 PM
> To: Takiguchi, Yasunari (SSS)
> Cc: linux-ker...@vger.kernel.org; devicet...@vger.kernel.org;
> linux-media@vger.kernel.org; tbird...@gmail.com;
> frowand.l...@gmail.com; Yamamoto, Masayuki (SSS); Nozawa, Hideki (STWN);
> Yonezawa, Kota (SSS); Matsumoto, Toshihiko (SSS); Watanabe, Satoshi (SSS)
> Subject: Re: [PATCH v5 02/12] [media] cxd2880-spi: Add support for CXD2880
> SPI interface
> 
> Em Thu, 18 Jan 2018 17:46:10 +0900
>  escreveu:
> 
> > From: Yasunari Takiguchi 
> >
> > This is the SPI adapter part of the driver for the Sony CXD2880
> > DVB-T2/T tuner + demodulator.
> 
> Thanks for the patches!
> 
> The patch series look ok. Just a few nitpicks that could be solved later.
> 
> I had to apply a few patches to make it build and remove some warnings
> with W=1. Patches sent.
> 
> With that, I'm applying this series.
> 
> Regards,
> Mauro
> 
> >
> > Signed-off-by: Yasunari Takiguchi 
> > Signed-off-by: Masayuki Yamamoto 
> > Signed-off-by: Hideki Nozawa 
> > Signed-off-by: Kota Yonezawa 
> > Signed-off-by: Toshihiko Matsumoto 
> > Signed-off-by: Satoshi Watanabe 
> > ---
> >
> > [Change list]
> > Changes in V5
> >Using SPDX-License-Identifier
> >drivers/media/spi/cxd2880-spi.c
> >   -modified typo about "ivnalid" -> "invalid"
> >   -modified typo about "drvier" -> "driver"
> >   -removed unnecessary if()
> >   -modified return error code
> >   -reduction of valiable names
> >   -removed unnecessary parentheses
> >   -changed members of struct cxd2880_ts_buf_info
> >
> > Changes in V4
> >drivers/media/spi/cxd2880-spi.c
> >   -removed Camel case
> >   -removed unnecessary initialization at variable declaration
> >   -removed unnecessary brace {}
> >
> > Changes in V3
> >drivers/media/spi/cxd2880-spi.c
> >   -adjusted of indent spaces
> >   -removed unnecessary cast
> >   -changed debugging code
> >   -changed timeout method
> >   -modified coding style of if()
> >   -changed hexadecimal code to lower case.
> >
> > Changes in V2
> >drivers/media/spi/cxd2880-spi.c
> >   -Modified PID filter setting.
> >
> >  drivers/media/spi/cxd2880-spi.c | 670
> > 
> >  1 file changed, 670 insertions(+)
> >  create mode 100644 drivers/media/spi/cxd2880-spi.c
> >
> > diff --git a/drivers/media/spi/cxd2880-spi.c
> > b/drivers/media/spi/cxd2880-spi.c new file mode 100644 index
> > ..857e4c0d7a92
> > --- /dev/null
> > +++ b/drivers/media/spi/cxd2880-spi.c
> > @@ -0,0 +1,670 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * cxd2880-spi.c
> > + * Sony CXD2880 DVB-T2/T tuner + demodulator driver
> > + * SPI adapter
> > + *
> > + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions
> > +Corporation  */
> > +
> > +#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
> > +
> > +#include 
> > +#include 
> > +
> > +#include "dvb_demux.h"
> > +#include "dmxdev.h"
> > +#include "dvb_frontend.h"
> > +#include "cxd2880.h"
> > +
> > +#define CXD2880_MAX_FILTER_SIZE 32
> > +#define BURST_WRITE_MAX 128
> > +#define MAX_TRANS_PKT 300
> > +
> > +struct cxd2880_ts_buf_info {
> > +   u8 read_ready:1;
> > +   u8 almost_full:1;
> > +   u8 almost_empty:1;
> > +   u8 overflow:1;
> > +   u8 underflow:1;
> > +   u16 pkt_num;
> > +};
> > +
> > +struct cxd2880_pid_config {
> > +   u8 is_enable;
> > +   u16 pid;
> > +};
> > +
> > +struct cxd2880_pid_filter_config {
> > +   u8 is_negative;
> > +   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
> > +};
> > +
> > +struct cxd2880_dvb_spi {
> > +   struct dvb_frontend dvb_fe;
> > +   struct dvb_adapter adapter;
> > +   struct dvb_demux demux;
> > +   struct dmxdev dmxdev;
> > +   struct dmx_frontend dmx_fe;
> > +   struct task_struct *cxd2880_ts_read_thread;
> > +   struct spi_device *spi;
> > +   struct mutex spi_mutex; /* For SPI access exclusive control */
> > +   int feed_count;
> > +   int all_pid_feed_count;
> > +   u8 *ts_buf;
> > +   struct cxd2880_pid_filter_config filter_config; };
> > +
> > +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
> > +
> > +static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32
> > +size) {
> > +   struct spi_message msg;
> > +   struct spi_transfer tx;
> > +
> > +   if (!spi || !data) {
> > +   pr_err("invalid arg\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   memset(, 0, sizeof(tx));
> 
> Nitpick:
> 
>  

RE: [PATCH v5 00/12] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator

2018-02-25 Thread Yasunari.Takiguchi
Hi, all

I sent the patch series of Sony CXD2880 DVB-T2/T tuner + demodulator driver 
version 5 on 18th/Jan.
I'd like to get better understanding of current review status for our drivers.

Are there any comments, advices and review results for them?

Thanks,
Takiguchi


[PATCH v5 12/12] [media] cxd2880: Add all Makefile, Kconfig files and Update MAINTAINERS file for the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Makefile, Kconfig files of driver 
and MAINTAINERS file update about the driver 
for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   drivers/media/dvb-frontends/cxd2880/Makefile
   -Using SPDX-License-Identifier
   -removed cxd2880_stopwatch_port.o
   drivers/media/dvb-frontends/cxd2880/Kconfig
   -Using SPDX-License-Identifier

Changes in V4
   We put [PATCH v3 12/14], [PATCH v3 13/14] and [PATCH v3 14/14]
   in [PATCH v4 12/12].
   
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_integ_dvbt2.o and cxd2880_integ_dvbt.o 

Changes in V3
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_math.o 

 MAINTAINERS  |  9 +
 drivers/media/dvb-frontends/Kconfig  |  2 ++
 drivers/media/dvb-frontends/Makefile |  1 +
 drivers/media/dvb-frontends/cxd2880/Kconfig  |  8 
 drivers/media/dvb-frontends/cxd2880/Makefile | 19 +++
 drivers/media/spi/Kconfig| 14 ++
 drivers/media/spi/Makefile   |  5 +
 7 files changed, 58 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 18994806e441..fcdbd7874ffb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8549,6 +8549,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR DIGITAL DEVICES PCIE DEVICES
 M: Daniel Scheller 
 L: linux-media@vger.kernel.org
diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index d17722eb4456..7fb626c00a39 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -546,6 +546,8 @@ config DVB_GP8PSK_FE
depends on DVB_CORE
default DVB_USB_GP8PSK
 
+source "drivers/media/dvb-frontends/cxd2880/Kconfig"
+
 comment "DVB-C (cable) frontends"
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index d025eb373842..7c7aca05678a 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -130,3 +130,4 @@ obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
 obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
 obj-$(CONFIG_DVB_HELENE) += helene.o
 obj-$(CONFIG_DVB_ZD1301_DEMOD) += zd1301_demod.o
+obj-$(CONFIG_DVB_CXD2880) += cxd2880/
diff --git a/drivers/media/dvb-frontends/cxd2880/Kconfig 
b/drivers/media/dvb-frontends/cxd2880/Kconfig
new file mode 100644
index ..9d989676e800
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Kconfig
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DVB_CXD2880
+   tristate "Sony CXD2880 DVB-T2/T tuner + demodulator"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Say Y when you want to support this frontend.
\ No newline at end of file
diff --git a/drivers/media/dvb-frontends/cxd2880/Makefile 
b/drivers/media/dvb-frontends/cxd2880/Makefile
new file mode 100644
index ..65a5d37f28cc
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Makefile
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+
+cxd2880-objs := cxd2880_common.o \
+   cxd2880_devio_spi.o \
+   cxd2880_integ.o \
+   cxd2880_io.o \
+   cxd2880_spi_device.o \
+   cxd2880_tnrdmd.o \
+   cxd2880_tnrdmd_dvbt2.o \
+   cxd2880_tnrdmd_dvbt2_mon.o \
+   cxd2880_tnrdmd_dvbt.o \
+   cxd2880_tnrdmd_dvbt_mon.o\
+   cxd2880_tnrdmd_mon.o\
+   cxd2880_top.o
+
+obj-$(CONFIG_DVB_CXD2880) += cxd2880.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a39a440..b07ac86fc53c 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+

[PATCH v5 11/12] [media] cxd2880: Add DVB-T2 monitor functions

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor functions (DVB-T2)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary if()
  -modified return error code
  -removed unnecessary parentheses 
  -modified for "Lines should not end with a '(' "
  -removed unnecessary functions
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h
  -removed unnecessary functions

Changes in V4
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -cxd2880_integ_dvbt2.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -cxd2880_integ_dvbt2.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -changed CXD2880_SLEEP to usleep_range
  -replaced cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()  
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h
  -modified return code

 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.c | 1878 
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.h |  135 ++
 2 files changed, 2013 insertions(+)
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
new file mode 100644
index ..5296cbbca8bd
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
@@ -0,0 +1,1878 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_tnrdmd_dvbt2_mon.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 monitor functions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+
+#include "dvb_math.h"
+
+static const int ref_dbm_1000[4][8] = {
+   {-96000, -95000, -94000, -93000, -92000, -92000, -98000, -97000},
+   {-91000, -89000, -88000, -87000, -86000, -86000, -93000, -92000},
+   {-86000, -85000, -83000, -82000, -81000, -8, -89000, -88000},
+   {-82000, -8, -78000, -76000, -75000, -74000, -86000, -84000},
+};
+
+int cxd2880_tnrdmd_dvbt2_mon_sync_stat(struct cxd2880_tnrdmd
+  *tnr_dmd, u8 *sync_stat,
+  u8 *ts_lock_stat,
+  u8 *unlock_detected)
+{
+   u8 data;
+   int ret;
+
+   if (!tnr_dmd || !sync_stat || !ts_lock_stat || !unlock_detected)
+   return -EINVAL;
+
+   if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return -EINVAL;
+
+   if (tnr_dmd->sys != CXD2880_DTV_SYS_DVBT2)
+   return -EINVAL;
+
+   ret = tnr_dmd->io->write_reg(tnr_dmd->io,
+CXD2880_IO_TGT_DMD,
+0x00, 0x0b);
+   if (ret)
+   return ret;
+
+   ret = tnr_dmd->io->read_regs(tnr_dmd->io,
+CXD2880_IO_TGT_DMD,
+0x10, , sizeof(data));
+   if (ret)
+   return ret;
+
+   *sync_stat = data & 0x07;
+   *ts_lock_stat = ((data & 0x20) ? 1 : 0);
+   *unlock_detected = ((data & 0x10) ? 1 : 0);
+
+   if (*sync_stat == 0x07)
+   return -EAGAIN;
+
+   return 0;
+}
+
+int cxd2880_tnrdmd_dvbt2_mon_sync_stat_sub(struct cxd2880_tnrdmd
+  *tnr_dmd,
+  u8 *sync_stat,
+  u8 *unlock_detected)
+{
+   u8 

[PATCH v5 10/12] [media] cxd2880: Add DVB-T2 control functions for the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T2
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -removed unnecessary if()
  -modified return error code
  -removed unnecessary parentheses 

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h
  -modified return code

 .../media/dvb-frontends/cxd2880/cxd2880_dvbt2.h|  385 +++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c   | 1217 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h   |   65 ++
 3 files changed, 1667 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
new file mode 100644
index ..191047b158fe
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
@@ -0,0 +1,385 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * cxd2880_dvbt2.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 related definitions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#ifndef CXD2880_DVBT2_H
+#define CXD2880_DVBT2_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt2_profile {
+   CXD2880_DVBT2_PROFILE_BASE,
+   CXD2880_DVBT2_PROFILE_LITE,
+   CXD2880_DVBT2_PROFILE_ANY
+};
+
+enum cxd2880_dvbt2_version {
+   CXD2880_DVBT2_V111,
+   CXD2880_DVBT2_V121,
+   CXD2880_DVBT2_V131
+};
+
+enum cxd2880_dvbt2_s1 {
+   CXD2880_DVBT2_S1_BASE_SISO = 0x00,
+   CXD2880_DVBT2_S1_BASE_MISO = 0x01,
+   CXD2880_DVBT2_S1_NON_DVBT2 = 0x02,
+   CXD2880_DVBT2_S1_LITE_SISO = 0x03,
+   CXD2880_DVBT2_S1_LITE_MISO = 0x04,
+   CXD2880_DVBT2_S1_RSVD3 = 0x05,
+   CXD2880_DVBT2_S1_RSVD4 = 0x06,
+   CXD2880_DVBT2_S1_RSVD5 = 0x07,
+   CXD2880_DVBT2_S1_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_base_s2 {
+   CXD2880_DVBT2_BASE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_BASE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_BASE_S2_M1K_G_ANY = 0x03,
+   CXD2880_DVBT2_BASE_S2_M16K_G_ANY = 0x04,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT = 0x05,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT2 = 0x07,
+   CXD2880_DVBT2_BASE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_lite_s2 {
+   CXD2880_DVBT2_LITE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_LITE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT2 = 0x03,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT = 0x04,
+   CXD2880_DVBT2_LITE_S2_RSVD1 = 0x05,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_LITE_S2_RSVD2 = 0x07,
+   CXD2880_DVBT2_LITE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_guard {
+   CXD2880_DVBT2_G1_32 = 0x00,
+   CXD2880_DVBT2_G1_16 = 0x01,
+   CXD2880_DVBT2_G1_8 = 0x02,
+   CXD2880_DVBT2_G1_4 = 0x03,
+   CXD2880_DVBT2_G1_128 = 0x04,
+   CXD2880_DVBT2_G19_128 = 0x05,
+   CXD2880_DVBT2_G19_256 = 0x06,
+   CXD2880_DVBT2_G_RSVD1 = 0x07,
+   CXD2880_DVBT2_G_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_mode {
+   CXD2880_DVBT2_M2K = 0x00,
+   CXD2880_DVBT2_M8K = 0x01,
+   CXD2880_DVBT2_M4K = 0x02,
+   CXD2880_DVBT2_M1K = 0x03,
+   CXD2880_DVBT2_M16K = 0x04,
+   CXD2880_DVBT2_M32K = 0x05,
+   CXD2880_DVBT2_M_RSVD1 = 0x06,
+   CXD2880_DVBT2_M_RSVD2 = 0x07
+};
+
+enum cxd2880_dvbt2_bw {
+   CXD2880_DVBT2_BW_8 = 0x00,
+   CXD2880_DVBT2_BW_7 = 0x01,
+   CXD2880_DVBT2_BW_6 = 0x02,
+   CXD2880_DVBT2_BW_5 = 0x03,
+   CXD2880_DVBT2_BW_10 = 0x04,
+   CXD2880_DVBT2_BW_1_7 = 0x05,
+   

[PATCH v5 09/12] [media] cxd2880: Add DVB-T monitor functions

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor functions (DVB-T)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary if()
  -modified return error code
  -removed unnecessary parentheses 
  -modified for "Lines should not end with a '(' "
  -removed unnecessary functions
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
  -removed unnecessary functions

Changes in V4
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -cxd2880_integ_dvbt.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -cxd2880_integ_dvbt.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -changed CXD2880_SLEEP to usleep_range
  -chnaged cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
  -modified return code

 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 775 +
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  77 ++
 2 files changed, 852 insertions(+)
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
new file mode 100644
index ..78214a99a5df
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
@@ -0,0 +1,775 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_tnrdmd_dvbt_mon.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T monitor functions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+
+#include "dvb_math.h"
+
+static const int ref_dbm_1000[3][5] = {
+   {-93000, -91000, -9, -89000, -88000},
+   {-87000, -85000, -84000, -83000, -82000},
+   {-82000, -8, -78000, -77000, -76000},
+};
+
+static int is_tps_locked(struct cxd2880_tnrdmd *tnr_dmd);
+
+int cxd2880_tnrdmd_dvbt_mon_sync_stat(struct cxd2880_tnrdmd
+ *tnr_dmd, u8 *sync_stat,
+ u8 *ts_lock_stat,
+ u8 *unlock_detected)
+{
+   u8 rdata = 0x00;
+   int ret;
+
+   if (!tnr_dmd || !sync_stat || !ts_lock_stat || !unlock_detected)
+   return -EINVAL;
+
+   if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return -EINVAL;
+   if (tnr_dmd->sys != CXD2880_DTV_SYS_DVBT)
+   return -EINVAL;
+
+   ret = tnr_dmd->io->write_reg(tnr_dmd->io,
+CXD2880_IO_TGT_DMD,
+0x00, 0x0d);
+   if (ret)
+   return ret;
+
+   ret = tnr_dmd->io->read_regs(tnr_dmd->io,
+CXD2880_IO_TGT_DMD,
+0x10, , 1);
+   if (ret)
+   return ret;
+
+   *unlock_detected = (rdata & 0x10) ? 1 : 0;
+   *sync_stat = rdata & 0x07;
+   *ts_lock_stat = (rdata & 0x20) ? 1 : 0;
+
+   if (*sync_stat == 0x07)
+   return -EAGAIN;
+
+   return ret;
+}
+
+int cxd2880_tnrdmd_dvbt_mon_sync_stat_sub(struct cxd2880_tnrdmd
+ *tnr_dmd, u8 *sync_stat,
+ u8 *unlock_detected)
+{
+   u8 ts_lock_stat = 0;
+
+   if (!tnr_dmd || !sync_stat || !unlock_detected)
+   return -EINVAL;
+
+   if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
+   return -EINVAL;
+
+   return cxd2880_tnrdmd_dvbt_mon_sync_stat(tnr_dmd->diver_sub,
+

[PATCH v5 08/12] [media] cxd2880: Add DVB-T control functions the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -removed unnecessary if()
  -modified return error code
  -removed unnecessary parentheses 

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h
  -modified return code

 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h |  74 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c| 919 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h|  45 +
 3 files changed, 1038 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
new file mode 100644
index ..76a1acc346ef
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * cxd2880_dvbt.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T related definitions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#ifndef CXD2880_DVBT_H
+#define CXD2880_DVBT_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt_constellation {
+   CXD2880_DVBT_CONSTELLATION_QPSK,
+   CXD2880_DVBT_CONSTELLATION_16QAM,
+   CXD2880_DVBT_CONSTELLATION_64QAM,
+   CXD2880_DVBT_CONSTELLATION_RESERVED_3
+};
+
+enum cxd2880_dvbt_hierarchy {
+   CXD2880_DVBT_HIERARCHY_NON,
+   CXD2880_DVBT_HIERARCHY_1,
+   CXD2880_DVBT_HIERARCHY_2,
+   CXD2880_DVBT_HIERARCHY_4
+};
+
+enum cxd2880_dvbt_coderate {
+   CXD2880_DVBT_CODERATE_1_2,
+   CXD2880_DVBT_CODERATE_2_3,
+   CXD2880_DVBT_CODERATE_3_4,
+   CXD2880_DVBT_CODERATE_5_6,
+   CXD2880_DVBT_CODERATE_7_8,
+   CXD2880_DVBT_CODERATE_RESERVED_5,
+   CXD2880_DVBT_CODERATE_RESERVED_6,
+   CXD2880_DVBT_CODERATE_RESERVED_7
+};
+
+enum cxd2880_dvbt_guard {
+   CXD2880_DVBT_GUARD_1_32,
+   CXD2880_DVBT_GUARD_1_16,
+   CXD2880_DVBT_GUARD_1_8,
+   CXD2880_DVBT_GUARD_1_4
+};
+
+enum cxd2880_dvbt_mode {
+   CXD2880_DVBT_MODE_2K,
+   CXD2880_DVBT_MODE_8K,
+   CXD2880_DVBT_MODE_RESERVED_2,
+   CXD2880_DVBT_MODE_RESERVED_3
+};
+
+enum cxd2880_dvbt_profile {
+   CXD2880_DVBT_PROFILE_HP = 0,
+   CXD2880_DVBT_PROFILE_LP
+};
+
+struct cxd2880_dvbt_tpsinfo {
+   enum cxd2880_dvbt_constellation constellation;
+   enum cxd2880_dvbt_hierarchy hierarchy;
+   enum cxd2880_dvbt_coderate rate_hp;
+   enum cxd2880_dvbt_coderate rate_lp;
+   enum cxd2880_dvbt_guard guard;
+   enum cxd2880_dvbt_mode mode;
+   u8 fnum;
+   u8 length_indicator;
+   u16 cell_id;
+   u8 cell_id_ok;
+   u8 reserved_even;
+   u8 reserved_odd;
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
new file mode 100644
index ..e1ad5187ad8f
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
@@ -0,0 +1,919 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_tnrdmd_dvbt.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * control functions for DVB-T
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include "dvb_frontend.h"
+
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+
+static const struct cxd2880_reg_value tune_dmd_setting_seq1[] = {
+   {0x00, 0x00}, {0x31, 0x01},
+};
+
+static const struct cxd2880_reg_value tune_dmd_setting_seq2[] = {
+   {0x00, 0x04}, {0x5c, 0xfb}, {0x00, 0x10}, {0xa4, 0x03},
+   {0x00, 0x14}, {0xb0, 0x00}, {0x00, 0x25},
+};
+
+static 

[PATCH v5 07/12] [media] cxd2880: Add top level of the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This provides the main dvb frontend operation functions
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -changed define position of cxd2880_dvbt_t2_ops
  -modified typo about "drvier" -> "driver"
  -removed unnecessary cast
  -removed unnecessary if() 
  -modified return error code
  -removed unnecessary parentheses 
  -modified for "Lines should not end with a '(' "
  -modified to return constant 0 from read_ber function

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -modified typo "inavlid" to "invalid" at pr_err
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed to use cxd2880_dvbt_tune and cxd2880_dvbt2_tune 
   instead of cxd2880_integ_dvbt_tune and cxd2880_integ_dvbt2_tune
   (because we changed it so that demodulator does not 
 wait for locking the signal.) 

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -adjusted indent spaces
  -modified debugging code
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -modified about measurement period of PER/BER.
  -changed hexadecimal code to lower case. 

 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 1954 +
 1 file changed, 1954 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
new file mode 100644
index ..f109e9d98cc0
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -0,0 +1,1954 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_top.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+
+#include "dvb_frontend.h"
+#include "dvb_math.h"
+
+#include "cxd2880.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+#include "cxd2880_integ.h"
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_devio_spi.h"
+#include "cxd2880_spi_device.h"
+#include "cxd2880_tnrdmd_driver_version.h"
+
+struct cxd2880_priv {
+   struct cxd2880_tnrdmd tnrdmd;
+   struct spi_device *spi;
+   struct cxd2880_io regio;
+   struct cxd2880_spi_device spi_device;
+   struct cxd2880_spi cxd2880_spi;
+   struct cxd2880_dvbt_tune_param dvbt_tune_param;
+   struct cxd2880_dvbt2_tune_param dvbt2_tune_param;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+   unsigned long pre_ber_update;
+   unsigned long pre_ber_interval;
+   unsigned long post_ber_update;
+   unsigned long post_ber_interval;
+   unsigned long ucblock_update;
+   unsigned long ucblock_interval;
+   enum fe_status s;
+};
+
+static int cxd2880_pre_bit_err_t(struct cxd2880_tnrdmd *tnrdmd,
+u32 *pre_bit_err, u32 *pre_bit_count)
+{
+   u8 rdata[2];
+   int ret;
+
+   if (!tnrdmd || !pre_bit_err || !pre_bit_count)
+   return -EINVAL;
+
+   if (tnrdmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return -EINVAL;
+
+   if (tnrdmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return -EINVAL;
+
+   if (tnrdmd->sys != CXD2880_DTV_SYS_DVBT)
+   return -EINVAL;
+
+   ret = slvt_freeze_reg(tnrdmd);
+   if (ret)
+   return ret;
+
+   ret = tnrdmd->io->write_reg(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x00, 0x10);
+   if (ret) {
+   slvt_unfreeze_reg(tnrdmd);
+   return ret;
+   }
+
+   ret = tnrdmd->io->read_regs(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x39, rdata, 1);
+   if (ret) {
+   slvt_unfreeze_reg(tnrdmd);
+   return ret;
+   }
+
+   if ((rdata[0] & 0x01) == 0) {
+   slvt_unfreeze_reg(tnrdmd);
+   return -EAGAIN;
+   }
+
+   ret = tnrdmd->io->read_regs(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x22, rdata, 2);
+  

[PATCH v5 06/12] [media] cxd2880: Add integration layer for the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These functions monitor the driver and watch for task completion.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -removed unnecessary if() 
  -changed timer function from stop_watch to ktime

Changes in V4   
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -removed unnecessary initialization at variable declaration

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -changed cxd2880_atomic_read to atomic_read
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
  -modified return code

 .../media/dvb-frontends/cxd2880/cxd2880_integ.c| 72 ++
 .../media/dvb-frontends/cxd2880/cxd2880_integ.h| 27 
 2 files changed, 99 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
new file mode 100644
index ..5302ab0964c1
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_integ.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common functions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include 
+#include 
+
+#include "cxd2880_tnrdmd.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_integ.h"
+
+int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   int ret;
+   ktime_t start;
+   u8 cpu_task_completed = 0;
+
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   ret = cxd2880_tnrdmd_init1(tnr_dmd);
+   if (ret)
+   return ret;
+
+   start = ktime_get();
+
+   while (1) {
+   ret =
+   cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
+_task_completed);
+   if (ret)
+   return ret;
+
+   if (cpu_task_completed)
+   break;
+
+   if (ktime_to_ms(ktime_sub(ktime_get(), start)) >
+   CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
+   return -ETIMEDOUT;
+
+   usleep_range(CXD2880_TNRDMD_WAIT_INIT_INTVL,
+CXD2880_TNRDMD_WAIT_INIT_INTVL + 1000);
+   }
+
+   return cxd2880_tnrdmd_init2(tnr_dmd);
+}
+
+int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   atomic_set(_dmd->cancel, 1);
+
+   return 0;
+}
+
+int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   if (atomic_read(_dmd->cancel) != 0)
+   return -ECANCELED;
+
+   return 0;
+}
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
new file mode 100644
index ..7160225db8b9
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * cxd2880_integ.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common interface
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#ifndef CXD2880_INTEG_H
+#define CXD2880_INTEG_H
+
+#include "cxd2880_tnrdmd.h"
+
+#define CXD2880_TNRDMD_WAIT_INIT_TIMEOUT   500
+#define CXD2880_TNRDMD_WAIT_INIT_INTVL 10
+
+#define CXD2880_TNRDMD_WAIT_AGC_STABLE 100
+
+int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd);
+
+int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd);
+
+int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd
+*tnr_dmd);
+
+#endif
-- 
2.15.1



[PATCH v5 05/12] [media] cxd2880: Add tuner part of the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This part of the driver has the main routines to handle
the tuner and demodulator functionality.  The tnrdmd_mon.* files
have monitor functions for the driver.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -removed unnecessary if()
  -modified if (ret) return ret;
  -modified return error code
  -removed unnecessary parentheses
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -removed struct cxd2880_tnrdmd_ts_buf_info
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -removed unnecessary if()
  -modified return error code
  -removed unnecessary parentheses
  -removed cxd2880_tnrdmd_mon_ts_buf_info() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
  -removed cxd2880_tnrdmd_mon_ts_buf_info()  
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers
  -removed unnecessary brace {}
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -adjusted of indent spaces of macro
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -removed unnecessary brace {}

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
  -removed code relevant to ISDB-T
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -removed unnecessary cast
  -removed code relevant to ISDB-T
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_memset to memset 
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()
  -changed to use const values at writing a lot of registers 
   with a command. 
  -changed hexadecimal code to lower case. 
  -adjusted of indent spaces
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -removed code relevant to ISDB-T
  -changed cxd2880_atomic struct to atomic_t
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -changed CXD2880_SLEEP to usleep_range
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
  -modified return code

Changes in V2
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h  |   29 +
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c   | 3519 
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h   |  365 ++
 .../cxd2880/cxd2880_tnrdmd_driver_version.h|   12 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c |  150 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h |   29 +
 6 files changed, 4104 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
new file mode 100644
index ..820f4757a520
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * cxd2880_dtv.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DTV related definitions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#ifndef CXD2880_DTV_H
+#define CXD2880_DTV_H
+
+enum cxd2880_dtv_sys {
+   CXD2880_DTV_SYS_UNKNOWN,
+   CXD2880_DTV_SYS_DVBT,
+   CXD2880_DTV_SYS_DVBT2,
+   CXD2880_DTV_SYS_ANY

[PATCH v5 04/12] [media] cxd2880: Add spi device IO routines

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Add functions for initializing, reading and writing to the SPI
device for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -modified return error code
  -removed unnecessary parentheses 
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
  -removed unnecessary parentheses

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary initialization at variable declaration

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary cast
  -changed cxd2880_memcpy to memcpy
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
  -removed unnecessary cast
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h
  -modified return code

 .../dvb-frontends/cxd2880/cxd2880_devio_spi.c  | 129 +
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.h  |  23 
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h  |  34 ++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.c | 113 ++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.h |  26 +
 5 files changed, 325 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
new file mode 100644
index ..d2e37c95d748
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_devio_spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * I/O interface via SPI
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include "cxd2880_devio_spi.h"
+
+#define BURST_WRITE_MAX 128
+
+static int cxd2880_io_spi_read_reg(struct cxd2880_io *io,
+  enum cxd2880_io_tgt tgt,
+  u8 sub_address, u8 *data,
+  u32 size)
+{
+   int ret;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[6];
+   u8 *read_data_top = data;
+
+   if (!io || !io->if_object || !data)
+   return -EINVAL;
+
+   if (sub_address + size > 0x100)
+   return -EINVAL;
+
+   spi = io->if_object;
+
+   if (tgt == CXD2880_IO_TGT_SYS)
+   send_data[0] = 0x0b;
+   else
+   send_data[0] = 0x0a;
+
+   send_data[3] = 0;
+   send_data[4] = 0;
+   send_data[5] = 0;
+
+   while (size > 0) {
+   send_data[1] = sub_address;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = size;
+
+   ret =
+   spi->write_read(spi, send_data, sizeof(send_data),
+   read_data_top, send_data[2]);
+   if (ret)
+   return ret;
+
+   sub_address += send_data[2];
+   read_data_top += send_data[2];
+   size -= send_data[2];
+   }
+
+   return ret;
+}
+
+static int cxd2880_io_spi_write_reg(struct cxd2880_io *io,
+   enum cxd2880_io_tgt tgt,
+   u8 sub_address,
+   const u8 *data, u32 size)
+{
+   int ret;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = data;
+
+   if (!io || !io->if_object || !data)
+   return -EINVAL;
+
+   if (size > BURST_WRITE_MAX)
+   return -EINVAL;
+
+   if (sub_address + size > 0x100)
+   return -EINVAL;
+
+   spi = io->if_object;
+
+   if (tgt == CXD2880_IO_TGT_SYS)
+   send_data[0] = 0x0f;
+   else
+   

[PATCH v5 03/12] [media] cxd2880: Add common files for the driver

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These are common files for the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.
These contains helper functions for the driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -modified return not to use ret parameter. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
  -removed unnecessary parentheses
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
  -removed function proto type about cxd2880_stopwatch
  -removed CXD2880_ARG_UNUSED
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -cxd2880_stopwatch_port.c file was removed from V5.

Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
  -changed MASKUPPER/MASKLOWER with GENMASK 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
  -removed definition NULL and SONY_SLEEP
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_atomic_set to atomic_set
  -removed cxd2880_atomic struct and cxd2880_atomic_read
  -changed stop-watch function
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary cast
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
  -modified return code 
   drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -changed CXD2880_SLEEP to usleep_range
  -changed stop-watch function
  -modified return code
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
  -cxd2880_stdlib.h file was removed from V3.

 drivers/media/dvb-frontends/cxd2880/cxd2880.h  | 29 ++
 .../media/dvb-frontends/cxd2880/cxd2880_common.c   | 21 +++
 .../media/dvb-frontends/cxd2880/cxd2880_common.h   | 19 +++
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c   | 66 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h   | 54 ++
 5 files changed, 189 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
new file mode 100644
index ..4ea3510aab66
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * cxd2880.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#ifndef CXD2880_H
+#define CXD2880_H
+
+struct cxd2880_config {
+   struct spi_device *spi;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+};
+
+#if IS_REACHABLE(CONFIG_DVB_CXD2880)
+extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg);
+#else
+static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg)
+{
+   pr_warn("%s: driver disabled by Kconfig\n", __func__);
+   return NULL;
+}
+#endif /* CONFIG_DVB_CXD2880 */
+
+#endif /* CXD2880_H */
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
new file mode 100644
index ..d6f5af6609c1
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880_common.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * common functions
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#include "cxd2880_common.h"
+
+int cxd2880_convert2s_complement(u32 value, u32 bitlen)
+{
+   if (!bitlen || bitlen >= 32)
+   return (int)value;
+
+   if (value & (u32)(1 << (bitlen - 1)))
+   return (int)(GENMASK(31, bitlen) | value);
+   else
+   return (int)(GENMASK(bitlen - 1, 0) & value);
+}
diff 

[PATCH v5 02/12] [media] cxd2880-spi: Add support for CXD2880 SPI interface

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the SPI adapter part of the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V5
   Using SPDX-License-Identifier
   drivers/media/spi/cxd2880-spi.c
  -modified typo about "ivnalid" -> "invalid"
  -modified typo about "drvier" -> "driver"
  -removed unnecessary if() 
  -modified return error code
  -reduction of valiable names
  -removed unnecessary parentheses 
  -changed members of struct cxd2880_ts_buf_info

Changes in V4
   drivers/media/spi/cxd2880-spi.c
  -removed Camel case
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}

Changes in V3
   drivers/media/spi/cxd2880-spi.c
  -adjusted of indent spaces
  -removed unnecessary cast
  -changed debugging code
  -changed timeout method
  -modified coding style of if()
  -changed hexadecimal code to lower case. 

Changes in V2
   drivers/media/spi/cxd2880-spi.c
  -Modified PID filter setting.

 drivers/media/spi/cxd2880-spi.c | 670 
 1 file changed, 670 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index ..857e4c0d7a92
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,670 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PKT 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready:1;
+   u8 almost_full:1;
+   u8 almost_empty:1;
+   u8 overflow:1;
+   u8 underflow:1;
+   u16 pkt_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex; /* For SPI access exclusive control */
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+
+   if (!spi || !data) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+
+   return spi_sync(spi, );
+}
+
+static int cxd2880_write_reg(struct spi_device *spi,
+u8 sub_address, const u8 *data, u32 size)
+{
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = NULL;
+   int ret = 0;
+
+   if (!spi || !data) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+   if (size > BURST_WRITE_MAX) {
+   pr_err("data size > WRITE_MAX\n");
+   return -EINVAL;
+   }
+
+   if (sub_address + size > 0x100) {
+   pr_err("out of range\n");
+   return -EINVAL;
+   }
+
+   send_data[0] = 0x0e;
+   write_data_top = data;
+
+   while (size > 0) {
+   send_data[1] = sub_address;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = (u8)size;
+
+   memcpy(_data[3], write_data_top, send_data[2]);
+
+   ret = cxd2880_write_spi(spi, send_data, send_data[2] + 3);
+   if (ret) {
+   pr_err("write spi failed %d\n", ret);
+   break;
+   }
+   sub_address += send_data[2];
+   write_data_top += send_data[2];
+   size -= send_data[2];
+   }
+
+   return ret;
+}
+

[PATCH v5 01/12] [dt-bindings] [media] Add document file for CXD2880 SPI I/F

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the document file for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the description of the SPI adapter binding.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
Acked-by: Rob Herring 
---

No change since version 1.

 .../devicetree/bindings/media/spi/sony-cxd2880.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index ..fc5aa263abe5
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,14 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+};
-- 
2.15.1



[PATCH v5 00/12] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator

2018-01-18 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the patch series (version 5) of Sony CXD2880 DVB-T2/T tuner + 
demodulator driver.The driver supports DVB-API and interfaces through 
SPI.

We have tested the driver on Raspberry Pi 3 and got picture and sound 
from a media player.

The change history of this patch series is as below.

[Change list]
Changes in V5
(1)Using SPDX-License-Identifier instead of 
   repeating the copyright notes.

(2)Removed a file.
This below file is removed because we changed stop_watch 
   function to ktime.

   [PATCH v5 03/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -removed

(3)The detail change items of each files are as below.
[PATCH v5 02/12]
   Using SPDX-License-Identifier
   drivers/media/spi/cxd2880-spi.c
 -modified typo about "ivnalid" -> "invalid"
 -modified typo about "drvier" -> "driver"
 -removed unnecessary if() 
 -modified return error code
 -reduction of valiable names
 -removed unnecessary parentheses 
 -changed members of struct cxd2880_ts_buf_info

[PATCH v5 03/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 -modified return not to use ret parameter. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 -removed unnecessary parentheses
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 -removed function proto type about cxd2880_stopwatch
 -removed CXD2880_ARG_UNUSED
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
 -cxd2880_stopwatch_port.c file was removed from V5.

[PATCH v5 04/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 -modified return error code
 -removed unnecessary parentheses 
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
 -removed unnecessary parentheses

[PATCH v5 05/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
 -removed unnecessary if()
 -modified if (ret) return ret;
 -modified return error code
 -removed unnecessary parentheses
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
 -removed struct cxd2880_tnrdmd_ts_buf_info
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
 -removed unnecessary if()
 -modified return error code
 -removed unnecessary parentheses
 -removed cxd2880_tnrdmd_mon_ts_buf_info() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
 -removed cxd2880_tnrdmd_mon_ts_buf_info()  
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

[PATCH v5 06/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 -removed unnecessary if() 
 -changed timer function from stop_watch to ktime
   
[PATCH v5 07/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
 -changed define position of cxd2880_dvbt_t2_ops
 -modified typo about "drvier" -> "driver"
 -removed unnecessary cast
 -removed unnecessary if() 
 -modified return error code
 -removed unnecessary parentheses 
 -modified for "Lines should not end with a '(' "
 -modified to return constant 0 from read_ber function

[PATCH v5 08/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
 -removed unnecessary if()
 -modified return error code
 -removed unnecessary parentheses 

[PATCH v5 09/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
 -removed unnecessary if()
 -modified return error code
 -removed unnecessary parentheses 
 -modified for "Lines should not end with a '(' "
 -removed unnecessary functions
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
 -removed unnecessary functions

[PATCH v5 10/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
 -removed unnecessary if()
 -modified return error code
 -removed unnecessary parentheses 

[PATCH v5 11/12]
   Using SPDX-License-Identifier
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
 -removed unnecessary if()
 -modified return error code
 -removed unnecessary parentheses 
 -modified for "Lines should not end with a '(' "
 -removed unnecessary functions
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h
 -removed unnecessary functions

[PATCH 

[PATCH v4 12/12] [media] cxd2880: Add all Makefile, Kconfig files and Update MAINTAINERS file for the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Makefile, Kconfig files of driver 
and MAINTAINERS file update about the driver 
for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   We put [PATCH v3 12/14], [PATCH v3 13/14] and [PATCH v3 14/14]
   in [PATCH v4 12/12].
   
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_integ_dvbt2.o and cxd2880_integ_dvbt.o 

Changes in V3
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_math.o  

 MAINTAINERS  |  9 +
 drivers/media/dvb-frontends/Kconfig  |  2 ++
 drivers/media/dvb-frontends/Makefile |  1 +
 drivers/media/dvb-frontends/cxd2880/Kconfig  |  6 ++
 drivers/media/dvb-frontends/cxd2880/Makefile | 18 ++
 drivers/media/spi/Kconfig| 14 ++
 drivers/media/spi/Makefile   |  5 +
 7 files changed, 55 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index a74227ad082e..9451def42ebe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8447,6 +8447,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR DIGITAL DEVICES PCIE DEVICES
 M: Daniel Scheller 
 L: linux-media@vger.kernel.org
diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 2631d0e0a024..f29100832639 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -546,6 +546,8 @@ config DVB_GP8PSK_FE
depends on DVB_CORE
default DVB_USB_GP8PSK
 
+source "drivers/media/dvb-frontends/cxd2880/Kconfig"
+
 comment "DVB-C (cable) frontends"
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index f45f6a4a4371..e6b387284f6f 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -129,3 +129,4 @@ obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
 obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
 obj-$(CONFIG_DVB_HELENE) += helene.o
 obj-$(CONFIG_DVB_ZD1301_DEMOD) += zd1301_demod.o
+obj-$(CONFIG_DVB_CXD2880) += cxd2880/
diff --git a/drivers/media/dvb-frontends/cxd2880/Kconfig 
b/drivers/media/dvb-frontends/cxd2880/Kconfig
new file mode 100644
index ..36b8b6f7c4f7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Kconfig
@@ -0,0 +1,6 @@
+config DVB_CXD2880
+   tristate "Sony CXD2880 DVB-T2/T tuner + demodulator"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Say Y when you want to support this frontend.
\ No newline at end of file
diff --git a/drivers/media/dvb-frontends/cxd2880/Makefile 
b/drivers/media/dvb-frontends/cxd2880/Makefile
new file mode 100644
index ..dddedd178cf7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Makefile
@@ -0,0 +1,18 @@
+cxd2880-objs := cxd2880_common.o \
+   cxd2880_devio_spi.o \
+   cxd2880_integ.o \
+   cxd2880_io.o \
+   cxd2880_spi_device.o \
+   cxd2880_stopwatch_port.o \
+   cxd2880_tnrdmd.o \
+   cxd2880_tnrdmd_dvbt2.o \
+   cxd2880_tnrdmd_dvbt2_mon.o \
+   cxd2880_tnrdmd_dvbt.o \
+   cxd2880_tnrdmd_dvbt_mon.o\
+   cxd2880_tnrdmd_mon.o\
+   cxd2880_top.o
+
+obj-$(CONFIG_DVB_CXD2880) += cxd2880.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a39a440..b07ac86fc53c 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Choose if you would like to have SPI interface support for Sony 
CXD2880.
+
+endmenu
+
+endif
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile

[PATCH v4 11/12] [media] cxd2880: Add DVB-T2 monitor functions

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor functions (DVB-T2)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -cxd2880_integ_dvbt2.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -cxd2880_integ_dvbt2.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -changed CXD2880_SLEEP to usleep_range
  -replaced cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()  
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h
  -modified return code

 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.c | 2535 
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.h |  170 ++
 2 files changed, 2705 insertions(+)
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
new file mode 100644
index ..dac92243e907
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
@@ -0,0 +1,2535 @@
+/*
+ * cxd2880_tnrdmd_dvbt2_mon.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 monitor functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+
+#include "dvb_math.h"
+
+static const u16 n_bch_bits_lookup[2][8] = {
+   {7200, 9720, 10800, 11880, 12600, 13320, 5400, 6480},
+   {32400, 38880, 43200, 48600, 51840, 54000, 21600, 25920}
+};
+
+static const int snr_nordig_p1_db_1000[4][8] = {
+   {3500, 4700, 5600, 6600, 7200, 7700, 1300, 2200},
+   {8700, 10100, 11400, 12500, 13300, 13800, 6000, 7200},
+   {13000, 14800, 16200, 17700, 18700, 19400, 9800, 11100},
+   {17000, 19400, 20800, 22900, 24300, 25100, 13200, 14800},
+};
+
+static const int ref_dbm_1000[4][8] = {
+   {-96000, -95000, -94000, -93000, -92000, -92000, -98000, -97000},
+   {-91000, -89000, -88000, -87000, -86000, -86000, -93000, -92000},
+   {-86000, -85000, -83000, -82000, -81000, -8, -89000, -88000},
+   {-82000, -8, -78000, -76000, -75000, -74000, -86000, -84000},
+};
+
+int cxd2880_tnrdmd_dvbt2_mon_sync_stat(struct cxd2880_tnrdmd
+  *tnr_dmd, u8 *sync_stat,
+  u8 *ts_lock_stat,
+  u8 *unlock_detected)
+{
+   u8 data;
+   int ret;
+
+   if ((!tnr_dmd) || (!sync_stat) || (!ts_lock_stat) || 

[PATCH v4 10/12] [media] cxd2880: Add DVB-T2 control functions for the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T2
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h
  -modified return code

 .../media/dvb-frontends/cxd2880/cxd2880_dvbt2.h|  402 +++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c   | 1260 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h   |   82 ++
 3 files changed, 1744 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
new file mode 100644
index ..674ed17deef5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
@@ -0,0 +1,402 @@
+/*
+ * cxd2880_dvbt2.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT2_H
+#define CXD2880_DVBT2_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt2_profile {
+   CXD2880_DVBT2_PROFILE_BASE,
+   CXD2880_DVBT2_PROFILE_LITE,
+   CXD2880_DVBT2_PROFILE_ANY
+};
+
+enum cxd2880_dvbt2_version {
+   CXD2880_DVBT2_V111,
+   CXD2880_DVBT2_V121,
+   CXD2880_DVBT2_V131
+};
+
+enum cxd2880_dvbt2_s1 {
+   CXD2880_DVBT2_S1_BASE_SISO = 0x00,
+   CXD2880_DVBT2_S1_BASE_MISO = 0x01,
+   CXD2880_DVBT2_S1_NON_DVBT2 = 0x02,
+   CXD2880_DVBT2_S1_LITE_SISO = 0x03,
+   CXD2880_DVBT2_S1_LITE_MISO = 0x04,
+   CXD2880_DVBT2_S1_RSVD3 = 0x05,
+   CXD2880_DVBT2_S1_RSVD4 = 0x06,
+   CXD2880_DVBT2_S1_RSVD5 = 0x07,
+   CXD2880_DVBT2_S1_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_base_s2 {
+   CXD2880_DVBT2_BASE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_BASE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_BASE_S2_M1K_G_ANY = 0x03,
+   CXD2880_DVBT2_BASE_S2_M16K_G_ANY = 0x04,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT = 0x05,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT2 = 0x07,
+   CXD2880_DVBT2_BASE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_lite_s2 {
+   CXD2880_DVBT2_LITE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_LITE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT2 = 0x03,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT = 0x04,
+   CXD2880_DVBT2_LITE_S2_RSVD1 = 0x05,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_LITE_S2_RSVD2 = 0x07,
+   CXD2880_DVBT2_LITE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_guard {
+   CXD2880_DVBT2_G1_32 = 0x00,
+   CXD2880_DVBT2_G1_16 = 0x01,
+   

[PATCH v4 09/12] [media] cxd2880: Add DVB-T monitor functions

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor functions (DVB-T)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -cxd2880_integ_dvbt.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -cxd2880_integ_dvbt.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -changed CXD2880_SLEEP to usleep_range
  -chnaged cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
  -modified return code

 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 1201 
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  106 ++
 2 files changed, 1307 insertions(+)
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
new file mode 100644
index ..b00f1ac088bb
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
@@ -0,0 +1,1201 @@
+/*
+ * cxd2880_tnrdmd_dvbt_mon.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T monitor functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+
+#include "dvb_math.h"
+
+static const int nordig_non_hdvbt_db_1000[3][5] = {
+   {5100, 6900, 7900, 8900, 9700},
+   {10800, 13100, 14600, 15600, 16000},
+   {16500, 18700, 20200, 21600, 22500}
+};
+
+static const int nordig_hier_hp_dvbt_db_1000[3][2][5] = {
+   {
+   {9100, 12000, 13600, 15000, 16600},
+   {10900, 14100, 15700, 19400, 20600}
+   }, {
+   {6800, 9100, 10400, 11900, 12700},
+   {8500, 11000, 12800, 15000, 16000}
+   }, {
+   {5800, 7900, 9100, 10300, 12100},
+   {8000, 9300, 11600, 13000, 12900}
+   }
+};
+
+static const int nordig_hier_lp_dvbt_db_1000[3][2][5] = {
+   {
+   {12500, 14300, 15300, 16300, 16900},
+   {16700, 19100, 20900, 22500, 23700}
+   }, {
+   {15000, 17200, 18400, 19100, 20100},
+   {18500, 21200, 23600, 24700, 25900}
+   }, {
+   {19500, 21400, 22500, 23700, 24700},
+   {21900, 24200, 25600, 26900, 27800}
+   }
+};
+
+static const int ref_dbm_1000[3][5] = {
+   {-93000, -91000, -9, -89000, -88000},
+   {-87000, -85000, -84000, -83000, -82000},
+   {-82000, -8, -78000, -77000, -76000},
+};
+
+static int is_tps_locked(struct cxd2880_tnrdmd *tnr_dmd);
+
+int 

[PATCH v4 08/12] [media] cxd2880: Add DVB-T control functions the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h
  -modified return code

 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h |  91 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c| 954 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h|  62 ++
 3 files changed, 1107 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
new file mode 100644
index ..345c094760d2
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
@@ -0,0 +1,91 @@
+/*
+ * cxd2880_dvbt.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT_H
+#define CXD2880_DVBT_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt_constellation {
+   CXD2880_DVBT_CONSTELLATION_QPSK,
+   CXD2880_DVBT_CONSTELLATION_16QAM,
+   CXD2880_DVBT_CONSTELLATION_64QAM,
+   CXD2880_DVBT_CONSTELLATION_RESERVED_3
+};
+
+enum cxd2880_dvbt_hierarchy {
+   CXD2880_DVBT_HIERARCHY_NON,
+   CXD2880_DVBT_HIERARCHY_1,
+   CXD2880_DVBT_HIERARCHY_2,
+   CXD2880_DVBT_HIERARCHY_4
+};
+
+enum cxd2880_dvbt_coderate {
+   CXD2880_DVBT_CODERATE_1_2,
+   CXD2880_DVBT_CODERATE_2_3,
+   CXD2880_DVBT_CODERATE_3_4,
+   CXD2880_DVBT_CODERATE_5_6,
+   CXD2880_DVBT_CODERATE_7_8,
+   CXD2880_DVBT_CODERATE_RESERVED_5,
+   CXD2880_DVBT_CODERATE_RESERVED_6,
+   CXD2880_DVBT_CODERATE_RESERVED_7
+};
+
+enum cxd2880_dvbt_guard {
+   CXD2880_DVBT_GUARD_1_32,
+   CXD2880_DVBT_GUARD_1_16,
+   CXD2880_DVBT_GUARD_1_8,
+   CXD2880_DVBT_GUARD_1_4
+};
+
+enum cxd2880_dvbt_mode {
+   CXD2880_DVBT_MODE_2K,
+   CXD2880_DVBT_MODE_8K,
+   CXD2880_DVBT_MODE_RESERVED_2,
+   CXD2880_DVBT_MODE_RESERVED_3
+};
+
+enum cxd2880_dvbt_profile {
+   CXD2880_DVBT_PROFILE_HP = 0,
+   CXD2880_DVBT_PROFILE_LP
+};
+
+struct cxd2880_dvbt_tpsinfo {
+   enum cxd2880_dvbt_constellation constellation;
+   enum cxd2880_dvbt_hierarchy hierarchy;
+   enum cxd2880_dvbt_coderate rate_hp;
+   enum cxd2880_dvbt_coderate rate_lp;
+   enum cxd2880_dvbt_guard guard;
+   enum cxd2880_dvbt_mode mode;
+   u8 fnum;
+   u8 length_indicator;
+   u16 cell_id;
+   u8 cell_id_ok;
+   u8 reserved_even;
+   u8 reserved_odd;
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c 

[PATCH v4 07/12] [media] cxd2880: Add top level of the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This provides the main dvb frontend operation functions
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -modified typo "inavlid" to "invalid" at pr_err
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed to use cxd2880_dvbt_tune and cxd2880_dvbt2_tune 
   instead of cxd2880_integ_dvbt_tune and cxd2880_integ_dvbt2_tune
   (because we changed it so that demodulator does not 
 wait for locking the signal.) 

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -adjusted indent spaces
  -modified debugging code
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -modified about measurement period of PER/BER.
  -changed hexadecimal code to lower case. 

 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 2019 +
 1 file changed, 2019 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
new file mode 100644
index ..c82aaf0c1597
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -0,0 +1,2019 @@
+/*
+ * cxd2880_top.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+
+#include "dvb_frontend.h"
+#include "dvb_math.h"
+
+#include "cxd2880.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+#include "cxd2880_integ.h"
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_devio_spi.h"
+#include "cxd2880_spi_device.h"
+#include "cxd2880_tnrdmd_driver_version.h"
+
+struct cxd2880_priv {
+   struct cxd2880_tnrdmd tnrdmd;
+   struct spi_device *spi;
+   struct cxd2880_io regio;
+   struct cxd2880_spi_device spi_device;
+   struct cxd2880_spi cxd2880_spi;
+   struct cxd2880_dvbt_tune_param dvbt_tune_param;
+   struct cxd2880_dvbt2_tune_param dvbt2_tune_param;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+   unsigned long pre_ber_update;
+   unsigned long pre_ber_interval;
+   unsigned long post_ber_update;
+   unsigned long post_ber_interval;
+   unsigned long ucblock_update;
+   unsigned long ucblock_interval;
+   enum fe_status s;
+};
+
+static int cxd2880_pre_bit_err_t(
+   struct cxd2880_tnrdmd *tnrdmd, u32 *pre_bit_err,
+   u32 *pre_bit_count)
+{
+   u8 rdata[2];
+   int ret;
+
+   if ((!tnrdmd) || (!pre_bit_err) || (!pre_bit_count))
+   return -EINVAL;
+
+   if (tnrdmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return -EINVAL;
+
+   if (tnrdmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return -EPERM;
+
+   if (tnrdmd->sys != CXD2880_DTV_SYS_DVBT)
+   return -EPERM;
+
+   ret = slvt_freeze_reg(tnrdmd);
+   if (ret)
+   return ret;
+
+   ret = tnrdmd->io->write_reg(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x00, 0x10);
+   if (ret) {
+   

[PATCH v4 06/12] [media] cxd2880: Add integration layer for the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These functions monitor the driver and watch for task completion.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4   
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -removed unnecessary initialization at variable declaration

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -changed cxd2880_atomic_read to atomic_read
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
  -modified return code

 .../media/dvb-frontends/cxd2880/cxd2880_integ.c| 98 ++
 .../media/dvb-frontends/cxd2880/cxd2880_integ.h| 44 ++
 2 files changed, 142 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
new file mode 100644
index ..7264fc355d6b
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
@@ -0,0 +1,98 @@
+/*
+ * cxd2880_integ.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_integ.h"
+
+int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   int ret;
+   struct cxd2880_stopwatch timer;
+   unsigned int elapsed_time = 0;
+   u8 cpu_task_completed = 0;
+
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   ret = cxd2880_tnrdmd_init1(tnr_dmd);
+   if (ret)
+   return ret;
+
+   ret = cxd2880_stopwatch_start();
+   if (ret)
+   return ret;
+
+   while (1) {
+   ret = cxd2880_stopwatch_elapsed(, _time);
+   if (ret)
+   return ret;
+
+   ret =
+   cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
+_task_completed);
+   if (ret)
+   return ret;
+
+   if (cpu_task_completed)
+   break;
+
+   if (elapsed_time > CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
+   return -ETIME;
+   ret =
+   cxd2880_stopwatch_sleep(,
+   CXD2880_TNRDMD_WAIT_INIT_INTVL);
+   if (ret)
+   return ret;
+   }
+
+   ret = cxd2880_tnrdmd_init2(tnr_dmd);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   atomic_set(_dmd->cancel, 1);
+
+   return 0;
+}
+
+int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   if (atomic_read(_dmd->cancel) != 0)
+   return -ECANCELED;
+
+   return 0;
+}
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
new file mode 100644
index ..2b4fe5c3743b
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
@@ -0,0 +1,44 @@
+/*
+ * 

[PATCH v4 05/12] [media] cxd2880: Add tuner part of the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This part of the driver has the main routines to handle
the tuner and demodulator functionality.  The tnrdmd_mon.* files
have monitor functions for the driver.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers
  -removed unnecessary brace {}
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -adjusted of indent spaces of macro
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -removed unnecessary brace {}

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
  -removed code relevant to ISDB-T
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -removed unnecessary cast
  -removed code relevant to ISDB-T
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_memset to memset 
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()
  -changed to use const values at writing a lot of registers 
   with a command. 
  -changed hexadecimal code to lower case. 
  -adjusted of indent spaces
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -removed code relevant to ISDB-T
  -changed cxd2880_atomic struct to atomic_t
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -changed CXD2880_SLEEP to usleep_range
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
  -modified return code

Changes in V2
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h  |   46 +
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c   | 3687 
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h   |  391 +++
 .../cxd2880/cxd2880_tnrdmd_driver_version.h|   29 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c |  218 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h |   52 +
 6 files changed, 4423 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
new file mode 100644
index ..2d35d3990060
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
@@ -0,0 +1,46 @@
+/*
+ * cxd2880_dtv.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DTV related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with 

[PATCH v4 04/12] [media] cxd2880: Add spi device IO routines

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Add functions for initializing, reading and writing to the SPI
device for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary initialization at variable declaration

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary cast
  -changed cxd2880_memcpy to memcpy
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
  -removed unnecessary cast
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h
  -modified return code

 .../dvb-frontends/cxd2880/cxd2880_devio_spi.c  | 146 +
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.h  |  40 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h  |  51 +++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.c | 130 ++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.h |  43 ++
 5 files changed, 410 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
new file mode 100644
index ..e6226a00fc8c
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
@@ -0,0 +1,146 @@
+/*
+ * cxd2880_devio_spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * I/O interface via SPI
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_devio_spi.h"
+
+#define BURST_WRITE_MAX 128
+
+static int cxd2880_io_spi_read_reg(struct cxd2880_io *io,
+  enum cxd2880_io_tgt tgt,
+  u8 sub_address, u8 *data,
+  u32 size)
+{
+   int ret;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[6];
+   u8 *read_data_top = data;
+
+   if ((!io) || (!io->if_object) || (!data))
+   return -EINVAL;
+
+   if (sub_address + size > 0x100)
+   return -ERANGE;
+
+   spi = io->if_object;
+
+   if (tgt == CXD2880_IO_TGT_SYS)
+   send_data[0] = 0x0b;
+   else
+   send_data[0] = 0x0a;
+
+   send_data[3] = 0;
+   send_data[4] = 0;
+   send_data[5] = 0;
+
+   while (size > 0) {
+   send_data[1] = sub_address;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = size;
+
+   ret =
+   spi->write_read(spi, send_data, sizeof(send_data),
+   read_data_top, send_data[2]);
+   if (ret)
+   return ret;
+
+   sub_address += send_data[2];
+   read_data_top += send_data[2];
+   size -= send_data[2];
+ 

[PATCH v4 03/12] [media] cxd2880: Add common files for the driver

2017-10-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These are common files for the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.
These contains helper functions for the driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers

Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
  -changed MASKUPPER/MASKLOWER with GENMASK 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
  -removed definition NULL and SONY_SLEEP
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_atomic_set to atomic_set
  -removed cxd2880_atomic struct and cxd2880_atomic_read
  -changed stop-watch function
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary cast
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
  -modified return code 
   drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -changed CXD2880_SLEEP to usleep_range
  -changed stop-watch function
  -modified return code
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
  -cxd2880_stdlib.h file was removed from V3.

 drivers/media/dvb-frontends/cxd2880/cxd2880.h  | 46 +++
 .../media/dvb-frontends/cxd2880/cxd2880_common.c   | 38 +
 .../media/dvb-frontends/cxd2880/cxd2880_common.h   | 50 
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c   | 89 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h   | 71 +
 .../dvb-frontends/cxd2880/cxd2880_stopwatch_port.c | 60 +++
 6 files changed, 354 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
new file mode 100644
index ..281f9a784eb5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
@@ -0,0 +1,46 @@
+/*
+ * cxd2880.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_H
+#define CXD2880_H
+
+struct cxd2880_config {
+   struct spi_device *spi;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+};
+
+#if IS_REACHABLE(CONFIG_DVB_CXD2880)
+extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg);
+#else
+static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg)
+{
+   pr_warn("%s: driver disabled by Kconfig\n", __func__);
+   return NULL;
+}
+#endif /* CONFIG_DVB_CXD2880 */
+
+#endif /* CXD2880_H */
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
new file mode 100644
index 

[PATCH v4 02/12] [media] cxd2880-spi: Add support for CXD2880 SPI interface

2017-10-12 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the SPI adapter part of the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---

[Change list]
Changes in V4
   drivers/media/spi/cxd2880-spi.c
  -removed Camel case
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}

Changes in V3
   drivers/media/spi/cxd2880-spi.c
  -adjusted of indent spaces
  -removed unnecessary cast
  -changed debugging code
  -changed timeout method
  -modified coding style of if()
  -changed hexadecimal code to lower case. 

Changes in V2
   drivers/media/spi/cxd2880-spi.c
  -Modified PID filter setting.

 drivers/media/spi/cxd2880-spi.c | 695 
 1 file changed, 695 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index ..387cb32f90b8
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,695 @@
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PACKET 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready;
+   u8 almost_full;
+   u8 almost_empty;
+   u8 overflow;
+   u8 underflow;
+   u16 packet_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex; /* For SPI access exclusive control */
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+   int ret;
+
+   if ((!spi) || (!data)) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+   ret = spi_sync(spi, );
+
+   return ret;
+}
+
+static int cxd2880_write_reg(struct spi_device *spi,
+u8 sub_address, const u8 *data, u32 size)
+{
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = NULL;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+   if (size > BURST_WRITE_MAX) {
+   pr_err("data size > WRITE_MAX\n");
+   return -EINVAL;
+   }
+
+   if (sub_address + size > 0x100) {
+   pr_err("out of range\n");
+   return -EINVAL;
+   }
+
+   

[PATCH v4 01/12] [dt-bindings] [media] Add document file for CXD2880 SPI I/F

2017-10-12 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the document file for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the description of the SPI adapter binding.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
Acked-by: Rob Herring 
---

No change since version 1.

 .../devicetree/bindings/media/spi/sony-cxd2880.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index ..fc5aa263abe5
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,14 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+};
-- 
2.13.0



[PATCH v4 00/12] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-10-12 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the patch series (version 4) of Sony CXD2880 DVB-T2/T tuner + 
demodulator driver.The driver supports DVB-API and interfaces through 
SPI.

We have tested the driver on Raspberry Pi 3 and got picture and sound 
from a media player.

The change history of this patch series is as below.

[Change list]
Changes in V4
(1)Total patch number was changed from 14 to 12.
 We put [PATCH v3 12/14], [PATCH v3 13/14] and [PATCH v3 14/14]
   in [PATCH v4 12/12].

(2)Removed another file.
 These below files were removed because we changed it so that
   demodulator does not wait for locking the signal.

[PATCH v4 09/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -removed
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -removed
[PATCH v4 11/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -removed
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -removed

(3)The detail change items of each files are as below.
[PATCH v4 02/12]
   drivers/media/spi/cxd2880-spi.c
  -removed Camel case
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}

[PATCH v4 03/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers

[PATCH v4 04/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary initialization at variable declaration

[PATCH v4 05/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -modified how to write consecutive registers
  -removed unnecessary brace {}
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -adjusted of indent spaces of macro
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -removed unnecessary brace {}

[PATCH v4 06/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -removed unnecessary initialization at variable declaration

[PATCH v4 07/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -modified typo "inavlid" to "invalid" at pr_err
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed to use cxd2880_dvbt_tune and cxd2880_dvbt2_tune 
   instead of cxd2880_integ_dvbt_tune and cxd2880_integ_dvbt2_tune
(because we changed it so that demodulator does not 
 wait for locking the signal.) 

[PATCH v4 08/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -used over 80 columns limit, it makes fine to read codes
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

[PATCH v4 09/12]
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -cxd2880_integ_dvbt.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -cxd2880_integ_dvbt.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

[PATCH v4 10/12]
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -modified how to write consecutive registers

[PATCH v4 11/12]
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -cxd2880_integ_dvbt2.c file was removed from V4.
   #drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -cxd2880_integ_dvbt2.h file was removed from V4.
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary initialization at variable declaration
  -removed unnecessary brace {}
  -changed position of static const (to top part of the file)

[PATCH v4 12/12]
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_integ_dvbt2.o and cxd2880_integ_dvbt.o 

Changes in V3
(1)Total patch number was changed from 15 to 14,
   due to the all files of [PATCH v2 04/15] were removed.
   drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
  -Removed
   drivers/media/dvb-frontends/cxd2880/cxd2880_math.h
  -Removed

(2)Removed another 

[PATCH v3 14/14] [media] cxd2880 : Update MAINTAINERS file for CXD2880 driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is MAINTAINERS file update about the driver for
the Sony CXD2880 DVB-T2/T tuner + demodulator.

[Change list]
Changes in V3
   MAINTAINERS
  -no change

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6f7721d1634c..12a80c33c194 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8302,6 +8302,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR FREESCALE IMX
 M: Steve Longerbeam 
 M: Philipp Zabel 
-- 
2.13.0



[PATCH v3 13/14] [media] cxd2880: Add all Kconfig files for the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Kconfig files of driver for
the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/Kconfig
  -no change
   drivers/media/dvb-frontends/cxd2880/Kconfig
  -no change
   drivers/media/spi/Kconfig
  -no change

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/Kconfig |  2 ++
 drivers/media/dvb-frontends/cxd2880/Kconfig |  6 ++
 drivers/media/spi/Kconfig   | 14 ++
 3 files changed, 22 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 3a260b82b3e8..6831f4a49c18 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -519,6 +519,8 @@ config DVB_GP8PSK_FE
depends on DVB_CORE
default DVB_USB_GP8PSK
 
+source "drivers/media/dvb-frontends/cxd2880/Kconfig"
+
 comment "DVB-C (cable) frontends"
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/cxd2880/Kconfig 
b/drivers/media/dvb-frontends/cxd2880/Kconfig
new file mode 100644
index ..36b8b6f7c4f7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Kconfig
@@ -0,0 +1,6 @@
+config DVB_CXD2880
+   tristate "Sony CXD2880 DVB-T2/T tuner + demodulator"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Say Y when you want to support this frontend.
\ No newline at end of file
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a39a440..b07ac86fc53c 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Choose if you would like to have SPI interface support for Sony 
CXD2880.
+
+endmenu
+
+endif
-- 
2.13.0



[PATCH v3 12/14] [media] cxd2880: Add all Makefile files for the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Makefile files of driver
for the Sony CXD2880 DVB-T2/T tuner + demodulator.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/Makefile
  -no change
   drivers/media/dvb-frontends/cxd2880/Makefile
  -removed cxd2880_math.o \ 
   drivers/media/spi/Makefile
  -no change

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/Makefile |  1 +
 drivers/media/dvb-frontends/cxd2880/Makefile | 20 
 drivers/media/spi/Makefile   |  5 +
 3 files changed, 26 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile

diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index 3fccaf34ef52..d298c7954699 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -126,3 +126,4 @@ obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
 obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
 obj-$(CONFIG_DVB_HELENE) += helene.o
 obj-$(CONFIG_DVB_ZD1301_DEMOD) += zd1301_demod.o
+obj-$(CONFIG_DVB_CXD2880) += cxd2880/
diff --git a/drivers/media/dvb-frontends/cxd2880/Makefile 
b/drivers/media/dvb-frontends/cxd2880/Makefile
new file mode 100644
index ..ee7758b28a05
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Makefile
@@ -0,0 +1,20 @@
+cxd2880-objs := cxd2880_common.o \
+   cxd2880_devio_spi.o \
+   cxd2880_integ.o \
+   cxd2880_integ_dvbt2.o \
+   cxd2880_integ_dvbt.o \
+   cxd2880_io.o \
+   cxd2880_spi_device.o \
+   cxd2880_stopwatch_port.o \
+   cxd2880_tnrdmd.o \
+   cxd2880_tnrdmd_dvbt2.o \
+   cxd2880_tnrdmd_dvbt2_mon.o \
+   cxd2880_tnrdmd_dvbt.o \
+   cxd2880_tnrdmd_dvbt_mon.o\
+   cxd2880_tnrdmd_mon.o\
+   cxd2880_top.o
+
+obj-$(CONFIG_DVB_CXD2880) += cxd2880.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
index ea64013d16cc..40e0f88d9f6c 100644
--- a/drivers/media/spi/Makefile
+++ b/drivers/media/spi/Makefile
@@ -1 +1,6 @@
 obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
+obj-$(CONFIG_CXD2880_SPI_DRV) += cxd2880-spi.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/dvb-frontends/cxd2880
\ No newline at end of file
-- 
2.13.0



[PATCH v3 11/14] [media] cxd2880: Add DVB-T2 monitor and integration layer functions

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor and integration layer functions (DVB-T2)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
  -changed CXD2880_SLEEP to usleep_range
  -replaced cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()  
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c|  312 +++
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h|   64 +
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.c | 2622 
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.h |  170 ++
 4 files changed, 3168 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
new file mode 100644
index ..ac049820d797
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
@@ -0,0 +1,312 @@
+/*
+ * cxd2880_integ_dvbt2.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer functions for DVB-T2
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_integ_dvbt2.h"
+
+static int dvbt2_wait_demod_lock(struct cxd2880_tnrdmd *tnr_dmd,
+enum cxd2880_dvbt2_profile
+profile);
+
+static int dvbt2_wait_l1_post_lock(struct cxd2880_tnrdmd *tnr_dmd);
+
+int cxd2880_integ_dvbt2_tune(struct cxd2880_tnrdmd *tnr_dmd,
+struct cxd2880_dvbt2_tune_param
+*tune_param)
+{
+   int ret = 0;
+
+   if ((!tnr_dmd) || (!tune_param))
+   return -EINVAL;
+
+   if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return -EINVAL;
+
+   if ((tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP) &&
+   (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE))
+   return -EPERM;
+
+   atomic_set(_dmd->cancel, 0);
+
+   if ((tune_param->bandwidth != CXD2880_DTV_BW_1_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_5_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_6_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_8_MHZ)) {
+   return -EOPNOTSUPP;
+   }
+
+   if ((tune_param->profile != CXD2880_DVBT2_PROFILE_BASE) &&
+   (tune_param->profile != CXD2880_DVBT2_PROFILE_LITE))
+   return -EINVAL;
+
+   ret = cxd2880_tnrdmd_dvbt2_tune1(tnr_dmd, tune_param);
+   

[PATCH v3 10/14] [media] cxd2880: Add DVB-T2 control functions for the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T2
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../media/dvb-frontends/cxd2880/cxd2880_dvbt2.h|  402 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c   | 1359 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h   |   82 ++
 3 files changed, 1843 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
new file mode 100644
index ..674ed17deef5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
@@ -0,0 +1,402 @@
+/*
+ * cxd2880_dvbt2.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT2_H
+#define CXD2880_DVBT2_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt2_profile {
+   CXD2880_DVBT2_PROFILE_BASE,
+   CXD2880_DVBT2_PROFILE_LITE,
+   CXD2880_DVBT2_PROFILE_ANY
+};
+
+enum cxd2880_dvbt2_version {
+   CXD2880_DVBT2_V111,
+   CXD2880_DVBT2_V121,
+   CXD2880_DVBT2_V131
+};
+
+enum cxd2880_dvbt2_s1 {
+   CXD2880_DVBT2_S1_BASE_SISO = 0x00,
+   CXD2880_DVBT2_S1_BASE_MISO = 0x01,
+   CXD2880_DVBT2_S1_NON_DVBT2 = 0x02,
+   CXD2880_DVBT2_S1_LITE_SISO = 0x03,
+   CXD2880_DVBT2_S1_LITE_MISO = 0x04,
+   CXD2880_DVBT2_S1_RSVD3 = 0x05,
+   CXD2880_DVBT2_S1_RSVD4 = 0x06,
+   CXD2880_DVBT2_S1_RSVD5 = 0x07,
+   CXD2880_DVBT2_S1_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_base_s2 {
+   CXD2880_DVBT2_BASE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_BASE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_BASE_S2_M1K_G_ANY = 0x03,
+   CXD2880_DVBT2_BASE_S2_M16K_G_ANY = 0x04,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT = 0x05,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT2 = 0x07,
+   CXD2880_DVBT2_BASE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_lite_s2 {
+   CXD2880_DVBT2_LITE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_LITE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT2 = 0x03,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT = 0x04,
+   CXD2880_DVBT2_LITE_S2_RSVD1 = 0x05,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_LITE_S2_RSVD2 = 0x07,
+   CXD2880_DVBT2_LITE_S2_UNKNOWN = 0xff
+};
+
+enum cxd2880_dvbt2_guard {
+   CXD2880_DVBT2_G1_32 = 0x00,
+   CXD2880_DVBT2_G1_16 = 0x01,
+   CXD2880_DVBT2_G1_8 = 0x02,
+   CXD2880_DVBT2_G1_4 = 0x03,
+   CXD2880_DVBT2_G1_128 = 0x04,
+   CXD2880_DVBT2_G19_128 = 0x05,
+   CXD2880_DVBT2_G19_256 = 0x06,
+   CXD2880_DVBT2_G_RSVD1 = 0x07,
+   

[PATCH v3 09/14] [media] cxd2880: Add DVB-T monitor and integration layer functions

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor and integration layer functions (DVB-T)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
  -changed CXD2880_SLEEP to usleep_range
  -chnaged cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
  -removed unnecessary cast
  -changed cxd2880_math_log to intlog10
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.c |  198 
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.h |   58 +
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 1227 
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  106 ++
 4 files changed, 1589 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
new file mode 100644
index ..729cb0939203
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
@@ -0,0 +1,198 @@
+/*
+ * cxd2880_integ_dvbt.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer functions for DVB-T
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_integ_dvbt.h"
+
+static int dvbt_wait_demod_lock(struct cxd2880_tnrdmd *tnr_dmd);
+
+int cxd2880_integ_dvbt_tune(struct cxd2880_tnrdmd *tnr_dmd,
+   struct cxd2880_dvbt_tune_param
+   *tune_param)
+{
+   int ret = 0;
+
+   if ((!tnr_dmd) || (!tune_param))
+   return -EINVAL;
+
+   if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return -EINVAL;
+
+   if ((tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP) &&
+   (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE))
+   return -EPERM;
+
+   atomic_set(_dmd->cancel, 0);
+
+   if ((tune_param->bandwidth != CXD2880_DTV_BW_5_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_6_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_8_MHZ)) {
+   return -EOPNOTSUPP;
+   }
+
+   ret = cxd2880_tnrdmd_dvbt_tune1(tnr_dmd, tune_param);
+   if (ret)
+   return ret;
+
+   usleep_range(CXD2880_TNRDMD_WAIT_AGC_STABLE * 1,
+CXD2880_TNRDMD_WAIT_AGC_STABLE * 1 + 1000);
+
+   ret = cxd2880_tnrdmd_dvbt_tune2(tnr_dmd, tune_param);
+   if (ret)
+   return ret;
+
+   ret = dvbt_wait_demod_lock(tnr_dmd);
+   if (ret)
+   return ret;
+
+   return ret;
+}
+
+int cxd2880_integ_dvbt_wait_ts_lock(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   int ret = 0;
+   enum cxd2880_tnrdmd_lock_result lock =
+   

[PATCH v3 08/14] [media] cxd2880: Add DVB-T control functions the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h |   91 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c| 1115 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h|   62 ++
 3 files changed, 1268 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
new file mode 100644
index ..345c094760d2
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
@@ -0,0 +1,91 @@
+/*
+ * cxd2880_dvbt.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT_H
+#define CXD2880_DVBT_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt_constellation {
+   CXD2880_DVBT_CONSTELLATION_QPSK,
+   CXD2880_DVBT_CONSTELLATION_16QAM,
+   CXD2880_DVBT_CONSTELLATION_64QAM,
+   CXD2880_DVBT_CONSTELLATION_RESERVED_3
+};
+
+enum cxd2880_dvbt_hierarchy {
+   CXD2880_DVBT_HIERARCHY_NON,
+   CXD2880_DVBT_HIERARCHY_1,
+   CXD2880_DVBT_HIERARCHY_2,
+   CXD2880_DVBT_HIERARCHY_4
+};
+
+enum cxd2880_dvbt_coderate {
+   CXD2880_DVBT_CODERATE_1_2,
+   CXD2880_DVBT_CODERATE_2_3,
+   CXD2880_DVBT_CODERATE_3_4,
+   CXD2880_DVBT_CODERATE_5_6,
+   CXD2880_DVBT_CODERATE_7_8,
+   CXD2880_DVBT_CODERATE_RESERVED_5,
+   CXD2880_DVBT_CODERATE_RESERVED_6,
+   CXD2880_DVBT_CODERATE_RESERVED_7
+};
+
+enum cxd2880_dvbt_guard {
+   CXD2880_DVBT_GUARD_1_32,
+   CXD2880_DVBT_GUARD_1_16,
+   CXD2880_DVBT_GUARD_1_8,
+   CXD2880_DVBT_GUARD_1_4
+};
+
+enum cxd2880_dvbt_mode {
+   CXD2880_DVBT_MODE_2K,
+   CXD2880_DVBT_MODE_8K,
+   CXD2880_DVBT_MODE_RESERVED_2,
+   CXD2880_DVBT_MODE_RESERVED_3
+};
+
+enum cxd2880_dvbt_profile {
+   CXD2880_DVBT_PROFILE_HP = 0,
+   CXD2880_DVBT_PROFILE_LP
+};
+
+struct cxd2880_dvbt_tpsinfo {
+   enum cxd2880_dvbt_constellation constellation;
+   enum cxd2880_dvbt_hierarchy hierarchy;
+   enum cxd2880_dvbt_coderate rate_hp;
+   enum cxd2880_dvbt_coderate rate_lp;
+   enum cxd2880_dvbt_guard guard;
+   enum cxd2880_dvbt_mode mode;
+   u8 fnum;
+   u8 length_indicator;
+   u16 cell_id;
+   u8 cell_id_ok;
+   u8 reserved_even;
+   u8 reserved_odd;
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
new file mode 100644
index ..8a16cb359171
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
@@ -0,0 +1,1115 @@
+/*
+ * cxd2880_tnrdmd_dvbt.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * control functions for 

[PATCH v3 07/14] [media] cxd2880: Add top level of the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This provides the main dvb frontend operation functions
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -adjusted indent spaces
  -modified debugging code
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -modified about measurement period of PER/BER.
  -changed hexadecimal code to lower case. 

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 1879 +
 1 file changed, 1879 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
new file mode 100644
index ..306966dd186b
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -0,0 +1,1879 @@
+/*
+ * cxd2880_top.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+
+#include "dvb_frontend.h"
+#include "dvb_math.h"
+
+#include "cxd2880.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+#include "cxd2880_integ_dvbt2.h"
+#include "cxd2880_integ_dvbt.h"
+#include "cxd2880_devio_spi.h"
+#include "cxd2880_spi_device.h"
+#include "cxd2880_tnrdmd_driver_version.h"
+
+struct cxd2880_priv {
+   struct cxd2880_tnrdmd tnrdmd;
+   struct spi_device *spi;
+   struct cxd2880_io regio;
+   struct cxd2880_spi_device spi_device;
+   struct cxd2880_spi cxd2880_spi;
+   struct cxd2880_dvbt_tune_param dvbt_tune_param;
+   struct cxd2880_dvbt2_tune_param dvbt2_tune_param;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+   unsigned long pre_ber_update;
+   unsigned long pre_ber_interval;
+   unsigned long post_ber_update;
+   unsigned long post_ber_interval;
+   unsigned long ucblock_update;
+   unsigned long ucblock_interval;
+};
+
+static int cxd2880_pre_bit_err_t(
+   struct cxd2880_tnrdmd *tnrdmd, u32 *pre_bit_err,
+   u32 *pre_bit_count)
+{
+   u8 rdata[2];
+   int ret = 0;
+
+   if ((!tnrdmd) || (!pre_bit_err) || (!pre_bit_count))
+   return -EINVAL;
+
+   if (tnrdmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return -EINVAL;
+
+   if (tnrdmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return -EPERM;
+
+   if (tnrdmd->sys != CXD2880_DTV_SYS_DVBT)
+   return -EPERM;
+
+   ret = slvt_freeze_reg(tnrdmd);
+   if (ret)
+   return ret;
+
+   ret = tnrdmd->io->write_reg(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x00, 0x10);
+   if (ret) {
+   slvt_unfreeze_reg(tnrdmd);
+   return ret;
+   }
+
+   ret = tnrdmd->io->read_regs(tnrdmd->io,
+   CXD2880_IO_TGT_DMD,
+   0x39, rdata, 1);
+   if (ret) {
+   slvt_unfreeze_reg(tnrdmd);
+   return ret;
+   }
+
+   if ((rdata[0] & 0x01) == 0) {
+   slvt_unfreeze_reg(tnrdmd);
+   return -EBUSY;
+   }
+
+   ret = tnrdmd->io->read_regs(tnrdmd->io,
+ 

[PATCH v3 06/14] [media] cxd2880: Add integration layer for the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These functions monitor the driver and watch for task completion.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -changed cxd2880_atomic_read to atomic_read
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../media/dvb-frontends/cxd2880/cxd2880_integ.c| 98 ++
 .../media/dvb-frontends/cxd2880/cxd2880_integ.h| 44 ++
 2 files changed, 142 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
new file mode 100644
index ..d4516df49210
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
@@ -0,0 +1,98 @@
+/*
+ * cxd2880_integ.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_integ.h"
+
+int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   int ret = 0;
+   struct cxd2880_stopwatch timer;
+   unsigned int elapsed_time = 0;
+   u8 cpu_task_completed = 0;
+
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   ret = cxd2880_tnrdmd_init1(tnr_dmd);
+   if (ret)
+   return ret;
+
+   ret = cxd2880_stopwatch_start();
+   if (ret)
+   return ret;
+
+   while (1) {
+   ret = cxd2880_stopwatch_elapsed(, _time);
+   if (ret)
+   return ret;
+
+   ret =
+   cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
+_task_completed);
+   if (ret)
+   return ret;
+
+   if (cpu_task_completed)
+   break;
+
+   if (elapsed_time > CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
+   return -ETIME;
+   ret =
+   cxd2880_stopwatch_sleep(,
+   CXD2880_TNRDMD_WAIT_INIT_INTVL);
+   if (ret)
+   return ret;
+   }
+
+   ret = cxd2880_tnrdmd_init2(tnr_dmd);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   atomic_set(_dmd->cancel, 1);
+
+   return 0;
+}
+
+int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   if (atomic_read(_dmd->cancel) != 0)
+   return -ECANCELED;
+
+   return 0;
+}
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
new file mode 100644
index ..2b4fe5c3743b
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
@@ -0,0 +1,44 @@
+/*
+ * cxd2880_integ.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common interface
+ *
+ * Copyright (C) 2016, 2017 

[PATCH v3 05/14] [media] cxd2880: Add tuner part of the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This part of the driver has the main routines to handle
the tuner and demodulator functionality.  The tnrdmd_mon.* files
have monitor functions for the driver.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
  -removed code relevant to ISDB-T
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -removed unnecessary cast
  -removed code relevant to ISDB-T
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_memset to memset 
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()
  -changed to use const values at writing a lot of registers 
   with a command. 
  -changed hexadecimal code to lower case. 
  -adjusted of indent spaces
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -removed code relevant to ISDB-T
  -changed cxd2880_atomic struct to atomic_t
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -changed CXD2880_SLEEP to usleep_range
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
  -modified return code

Changes in V2
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h  |   46 +
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c   | 4030 
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h   |  391 ++
 .../cxd2880/cxd2880_tnrdmd_driver_version.h|   29 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c |  221 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h |   52 +
 6 files changed, 4769 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
new file mode 100644
index ..2d35d3990060
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
@@ -0,0 +1,46 @@
+/*
+ * cxd2880_dtv.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DTV related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DTV_H
+#define CXD2880_DTV_H
+
+enum cxd2880_dtv_sys {
+   CXD2880_DTV_SYS_UNKNOWN,
+   CXD2880_DTV_SYS_DVBT,
+   CXD2880_DTV_SYS_DVBT2,
+   CXD2880_DTV_SYS_ANY
+};
+
+enum cxd2880_dtv_bandwidth {
+   CXD2880_DTV_BW_UNKNOWN = 0,
+   CXD2880_DTV_BW_1_7_MHZ = 1,
+   CXD2880_DTV_BW_5_MHZ = 5,
+   CXD2880_DTV_BW_6_MHZ = 6,
+   CXD2880_DTV_BW_7_MHZ = 7,
+   CXD2880_DTV_BW_8_MHZ = 8
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c 

[PATCH v3 04/14] [media] cxd2880: Add spi device IO routines

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Add functions for initializing, reading and writing to the SPI
device for the Sony CXD2880 DVB-T2/T tuner + demodulator.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary cast
  -changed cxd2880_memcpy to memcpy
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
  -removed unnecessary cast
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h
  -modified return code

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.c  | 146 +
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.h  |  40 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h  |  51 +++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.c | 130 ++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.h |  43 ++
 5 files changed, 410 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
new file mode 100644
index ..2cf4fb0e4610
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
@@ -0,0 +1,146 @@
+/*
+ * cxd2880_devio_spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * I/O interface via SPI
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_devio_spi.h"
+
+#define BURST_WRITE_MAX 128
+
+static int cxd2880_io_spi_read_reg(struct cxd2880_io *io,
+  enum cxd2880_io_tgt tgt,
+  u8 sub_address, u8 *data,
+  u32 size)
+{
+   int ret = 0;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[6];
+   u8 *read_data_top = data;
+
+   if ((!io) || (!io->if_object) || (!data))
+   return -EINVAL;
+
+   if (sub_address + size > 0x100)
+   return -ERANGE;
+
+   spi = io->if_object;
+
+   if (tgt == CXD2880_IO_TGT_SYS)
+   send_data[0] = 0x0b;
+   else
+   send_data[0] = 0x0a;
+
+   send_data[3] = 0;
+   send_data[4] = 0;
+   send_data[5] = 0;
+
+   while (size > 0) {
+   send_data[1] = sub_address;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = size;
+
+   ret =
+   spi->write_read(spi, send_data, sizeof(send_data),
+   read_data_top, send_data[2]);
+   if (ret)
+   return ret;
+
+   sub_address += send_data[2];
+   read_data_top += send_data[2];
+   size -= send_data[2];
+   }
+
+   return ret;
+}
+
+static int cxd2880_io_spi_write_reg(struct cxd2880_io *io,
+   enum 

[PATCH v3 03/14] [media] cxd2880: Add common files for the driver

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These are common files for the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.
These contains helper functions for the driver.

[Change list]
Changes in V3
   drivers/media/dvb-frontends/cxd2880/cxd2880.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
  -changed MASKUPPER/MASKLOWER with GENMASK 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
  -removed definition NULL and SONY_SLEEP
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_atomic_set to atomic_set
  -removed cxd2880_atomic struct and cxd2880_atomic_read
  -changed stop-watch function
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary cast
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
  -modified return code 
   drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -changed CXD2880_SLEEP to usleep_range
  -changed stop-watch function
  -modified return code
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
  -cxd2880_stdlib.h file was removed from V3.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880.h  | 46 +++
 .../media/dvb-frontends/cxd2880/cxd2880_common.c   | 38 
 .../media/dvb-frontends/cxd2880/cxd2880_common.h   | 50 
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c   | 68 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h   | 62 
 .../dvb-frontends/cxd2880/cxd2880_stopwatch_port.c | 60 +++
 6 files changed, 324 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
new file mode 100644
index ..281f9a784eb5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
@@ -0,0 +1,46 @@
+/*
+ * cxd2880.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_H
+#define CXD2880_H
+
+struct cxd2880_config {
+   struct spi_device *spi;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+};
+
+#if IS_REACHABLE(CONFIG_DVB_CXD2880)
+extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg);
+#else
+static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg)
+{
+   pr_warn("%s: driver disabled by Kconfig\n", __func__);
+   return NULL;
+}
+#endif /* CONFIG_DVB_CXD2880 */
+
+#endif /* CXD2880_H */
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
new file mode 100644
index ..ffaa140bb8cb
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
@@ -0,0 +1,38 @@
+/*
+ * cxd2880_common.c
+ * Sony CXD2880 DVB-T2/T 

[PATCH v3 02/14] [media] cxd2880-spi: Add support for CXD2880 SPI interface

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the SPI adapter part of the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.

[Change list]
Changes in V3
   drivers/media/spi/cxd2880-spi.c
  -adjusted of indent spaces
  -removed unnecessary cast
  -changed debugging code
  -changed timeout method
  -modified coding style of if()
  -changed hexadecimal code to lower case. 

Changes in V2
   drivers/media/spi/cxd2880-spi.c
  -Modified PID filter setting.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/spi/cxd2880-spi.c | 697 
 1 file changed, 697 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index ..961b94daab38
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,697 @@
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
+
+#include 
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PACKET 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready;
+   u8 almost_full;
+   u8 almost_empty;
+   u8 overflow;
+   u8 underflow;
+   u16 packet_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex; /* For SPI access exclusive control */
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+   ret = spi_sync(spi, );
+
+   return ret;
+}
+
+static int cxd2880_write_reg(struct spi_device *spi,
+u8 subAddress, const u8 *data, u32 size)
+{
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = NULL;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("invalid arg\n");
+   return -EINVAL;
+   }
+   if (size > BURST_WRITE_MAX) {
+   pr_err("data size > WRITE_MAX\n");
+   return -EINVAL;
+   }
+
+   if (subAddress + size > 0x100) {
+   pr_err("out of range\n");
+   return -EINVAL;
+   }
+
+   send_data[0] = 0x0e;
+   write_data_top = data;
+
+   while (size > 0) {
+   send_data[1] = subAddress;
+   if (size > 255)
+   

[PATCH v3 01/14] [dt-bindings] [media] Add document file for CXD2880 SPI I/F

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the document file for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the description of the SPI adapter binding.

No change since version 1. I should have carried the ack forward:
Acked-by: Rob Herring 

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../devicetree/bindings/media/spi/sony-cxd2880.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index ..fc5aa263abe5
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,14 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+};
-- 
2.13.0



[PATCH v3 00/14] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-08-15 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the patch series (version 3) of Sony CXD2880 DVB-T2/T tuner + 
demodulator driver.
The driver supports DVB-API and interfaces through SPI.

We have tested the driver on Raspberry Pi 3 and got picture and sound from a 
media player.

The change history of this patch series is as below.

[Change list]
Changes in V3
(1)Total patch number was changed from 15 to 14,
   due to the all files of [PATCH v2 04/15] were removed.
   drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
  -Removed
   drivers/media/dvb-frontends/cxd2880/cxd2880_math.h
  -Removed

(2)Removed another file.
   drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
  -Removed 

(3)The detail change items of each files are as below.
[PATCH v3 01/14]
   Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
  -no change
[PATCH v3 02/14]
   drivers/media/spi/cxd2880-spi.c
  -adjusted of indent spaces
  -removed unnecessary cast
  -changed debugging code
  -changed timeout method
  -modified coding style of if()
  -changed hexadecimal code to lower case. 
[PATCH v3 03/14]
   drivers/media/dvb-frontends/cxd2880/cxd2880.h
  -no change
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
  -changed MASKUPPER/MASKLOWER with GENMASK 
   drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
  -removed definition NULL and SONY_SLEEP
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_atomic_set to atomic_set
  -removed cxd2880_atomic struct and cxd2880_atomic_read
  -changed stop-watch function
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
  -removed unnecessary cast
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
  -modified return code 
   drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
  -changed CXD2880_SLEEP to usleep_range
  -changed stop-watch function
  -modified return code
   #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
  -cxd2880_stdlib.h file was removed from V3.
[PATCH v3 04/14]
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
  -removed unnecessary cast
  -changed cxd2880_memcpy to memcpy
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
  -removed unnecessary cast
  -modified return code
   drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h
  -modified return code
[PATCH v3 05/14]
   drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
  -removed code relevant to ISDB-T
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
  -removed unnecessary cast
  -removed code relevant to ISDB-T
  -changed CXD2880_SLEEP to usleep_range
  -changed cxd2880_memset to memset 
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if()
  -changed to use const values at writing a lot of registers 
   with a command. 
  -changed hexadecimal code to lower case. 
  -adjusted of indent spaces
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
  -removed code relevant to ISDB-T
  -changed cxd2880_atomic struct to atomic_t
  -modified return code
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
  -updated version information
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
  -changed CXD2880_SLEEP to usleep_range
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  -changed hexadecimal code to lower case. 
   drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h
  -modified return code
[PATCH v3 06/14]
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
  -changed cxd2880_atomic_read to atomic_read
  -changed cxd2880_atomic_set to atomic_set
  -modified return code
  -modified coding style of if() 
   drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
  -modified return code
[PATCH v3 07/14]
   drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
  -adjusted indent spaces
  -modified debugging code
  -removed unnecessary cast
  -modified return code
  -modified coding style of if() 
  

[PATCH v2 15/15] [media] cxd2880 : Update MAINTAINERS file for CXD2880 driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is MAINTAINERS file update about the driver for
the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fdd5350fe261..62543a76d6bf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8042,6 +8042,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR HORUS3A
 M: Sergey Kozlov 
 M: Abylay Ospan 
-- 
2.11.0



[PATCH v2 14/15] [media] cxd2880: Add all Kconfig files for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Kconfig files of driver for
the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/Kconfig |  2 ++
 drivers/media/dvb-frontends/cxd2880/Kconfig |  6 ++
 drivers/media/spi/Kconfig   | 14 ++
 3 files changed, 22 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index e8c6554a47aa..3a3a7129a150 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -518,6 +518,8 @@ config DVB_GP8PSK_FE
depends on DVB_CORE
default DVB_USB_GP8PSK
 
+source "drivers/media/dvb-frontends/cxd2880/Kconfig"
+
 comment "DVB-C (cable) frontends"
depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/cxd2880/Kconfig 
b/drivers/media/dvb-frontends/cxd2880/Kconfig
new file mode 100644
index ..36b8b6f7c4f7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Kconfig
@@ -0,0 +1,6 @@
+config DVB_CXD2880
+   tristate "Sony CXD2880 DVB-T2/T tuner + demodulator"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Say Y when you want to support this frontend.
\ No newline at end of file
diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a39a440..b07ac86fc53c 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Choose if you would like to have SPI interface support for Sony 
CXD2880.
+
+endmenu
+
+endif
-- 
2.11.0



[PATCH v2 13/15] [media] cxd2880: Add all Makefile files for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the Makefile files of driver
for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/Makefile |  1 +
 drivers/media/dvb-frontends/cxd2880/Makefile | 21 +
 drivers/media/spi/Makefile   |  5 +
 3 files changed, 27 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile

diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index 3fccaf34ef52..d298c7954699 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -126,3 +126,4 @@ obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
 obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
 obj-$(CONFIG_DVB_HELENE) += helene.o
 obj-$(CONFIG_DVB_ZD1301_DEMOD) += zd1301_demod.o
+obj-$(CONFIG_DVB_CXD2880) += cxd2880/
diff --git a/drivers/media/dvb-frontends/cxd2880/Makefile 
b/drivers/media/dvb-frontends/cxd2880/Makefile
new file mode 100644
index ..2672c4a3d65c
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/Makefile
@@ -0,0 +1,21 @@
+cxd2880-objs := cxd2880_common.o \
+   cxd2880_devio_spi.o \
+   cxd2880_integ.o \
+   cxd2880_integ_dvbt2.o \
+   cxd2880_integ_dvbt.o \
+   cxd2880_io.o \
+   cxd2880_spi_device.o \
+   cxd2880_stopwatch_port.o \
+   cxd2880_tnrdmd.o \
+   cxd2880_tnrdmd_dvbt2.o \
+   cxd2880_tnrdmd_dvbt2_mon.o \
+   cxd2880_tnrdmd_dvbt.o \
+   cxd2880_tnrdmd_dvbt_mon.o\
+   cxd2880_tnrdmd_mon.o\
+   cxd2880_math.o \
+   cxd2880_top.o
+
+obj-$(CONFIG_DVB_CXD2880) += cxd2880.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
index ea64013d16cc..40e0f88d9f6c 100644
--- a/drivers/media/spi/Makefile
+++ b/drivers/media/spi/Makefile
@@ -1 +1,6 @@
 obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
+obj-$(CONFIG_CXD2880_SPI_DRV) += cxd2880-spi.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/dvb-frontends/cxd2880
\ No newline at end of file
-- 
2.11.0



[PATCH v2 12/15] [media] cxd2880: Add DVB-T2 monitor and integration layer functions

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor and integration layer functions (DVB-T2)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c|  311 +++
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h|   64 +
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.c | 2523 
 .../cxd2880/cxd2880_tnrdmd_dvbt2_mon.h |  170 ++
 4 files changed, 3068 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
new file mode 100644
index ..1d60b9c236d8
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c
@@ -0,0 +1,311 @@
+/*
+ * cxd2880_integ_dvbt2.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer functions for DVB-T2
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_dvbt2.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_integ_dvbt2.h"
+
+static enum cxd2880_ret dvbt2_wait_demod_lock(struct cxd2880_tnrdmd *tnr_dmd,
+ enum cxd2880_dvbt2_profile
+ profile);
+
+static enum cxd2880_ret dvbt2_wait_l1_post_lock(struct cxd2880_tnrdmd 
*tnr_dmd);
+
+enum cxd2880_ret cxd2880_integ_dvbt2_tune(struct cxd2880_tnrdmd *tnr_dmd,
+ struct cxd2880_dvbt2_tune_param
+ *tune_param)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+
+   if ((!tnr_dmd) || (!tune_param))
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if ((tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP) &&
+   (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE))
+   return CXD2880_RESULT_ERROR_SW_STATE;
+
+   cxd2880_atomic_set(_dmd->cancel, 0);
+
+   if ((tune_param->bandwidth != CXD2880_DTV_BW_1_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_5_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_6_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_8_MHZ)) {
+   return CXD2880_RESULT_ERROR_NOSUPPORT;
+   }
+
+   if ((tune_param->profile != CXD2880_DVBT2_PROFILE_BASE) &&
+   (tune_param->profile != CXD2880_DVBT2_PROFILE_LITE))
+   return CXD2880_RESULT_ERROR_ARG;
+
+   ret = cxd2880_tnrdmd_dvbt2_tune1(tnr_dmd, tune_param);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   CXD2880_SLEEP(CXD2880_TNRDMD_WAIT_AGC_STABLE);
+
+   ret = cxd2880_tnrdmd_dvbt2_tune2(tnr_dmd, tune_param);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   ret = dvbt2_wait_demod_lock(tnr_dmd, tune_param->profile);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   ret = cxd2880_tnrdmd_dvbt2_diver_fef_setting(tnr_dmd);
+   if (ret == CXD2880_RESULT_ERROR_HW_STATE)
+   

[PATCH v2 11/15] [media] cxd2880: Add DVB-T2 control functions for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T2
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../media/dvb-frontends/cxd2880/cxd2880_dvbt2.h|  402 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c   | 1309 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h   |   82 ++
 3 files changed, 1793 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
new file mode 100644
index ..1870398cba9d
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h
@@ -0,0 +1,402 @@
+/*
+ * cxd2880_dvbt2.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T2 related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT2_H
+#define CXD2880_DVBT2_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt2_profile {
+   CXD2880_DVBT2_PROFILE_BASE,
+   CXD2880_DVBT2_PROFILE_LITE,
+   CXD2880_DVBT2_PROFILE_ANY
+};
+
+enum cxd2880_dvbt2_version {
+   CXD2880_DVBT2_V111,
+   CXD2880_DVBT2_V121,
+   CXD2880_DVBT2_V131
+};
+
+enum cxd2880_dvbt2_s1 {
+   CXD2880_DVBT2_S1_BASE_SISO = 0x00,
+   CXD2880_DVBT2_S1_BASE_MISO = 0x01,
+   CXD2880_DVBT2_S1_NON_DVBT2 = 0x02,
+   CXD2880_DVBT2_S1_LITE_SISO = 0x03,
+   CXD2880_DVBT2_S1_LITE_MISO = 0x04,
+   CXD2880_DVBT2_S1_RSVD3 = 0x05,
+   CXD2880_DVBT2_S1_RSVD4 = 0x06,
+   CXD2880_DVBT2_S1_RSVD5 = 0x07,
+   CXD2880_DVBT2_S1_UNKNOWN = 0xFF
+};
+
+enum cxd2880_dvbt2_base_s2 {
+   CXD2880_DVBT2_BASE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_BASE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_BASE_S2_M1K_G_ANY = 0x03,
+   CXD2880_DVBT2_BASE_S2_M16K_G_ANY = 0x04,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT = 0x05,
+   CXD2880_DVBT2_BASE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_BASE_S2_M32K_G_DVBT2 = 0x07,
+   CXD2880_DVBT2_BASE_S2_UNKNOWN = 0xFF
+};
+
+enum cxd2880_dvbt2_lite_s2 {
+   CXD2880_DVBT2_LITE_S2_M2K_G_ANY = 0x00,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT = 0x01,
+   CXD2880_DVBT2_LITE_S2_M4K_G_ANY = 0x02,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT2 = 0x03,
+   CXD2880_DVBT2_LITE_S2_M16K_G_DVBT = 0x04,
+   CXD2880_DVBT2_LITE_S2_RSVD1 = 0x05,
+   CXD2880_DVBT2_LITE_S2_M8K_G_DVBT2 = 0x06,
+   CXD2880_DVBT2_LITE_S2_RSVD2 = 0x07,
+   CXD2880_DVBT2_LITE_S2_UNKNOWN = 0xFF
+};
+
+enum cxd2880_dvbt2_guard {
+   CXD2880_DVBT2_G1_32 = 0x00,
+   CXD2880_DVBT2_G1_16 = 0x01,
+   CXD2880_DVBT2_G1_8 = 0x02,
+   CXD2880_DVBT2_G1_4 = 0x03,
+   CXD2880_DVBT2_G1_128 = 0x04,
+   CXD2880_DVBT2_G19_128 = 0x05,
+   CXD2880_DVBT2_G19_256 = 0x06,
+   CXD2880_DVBT2_G_RSVD1 = 0x07,
+   CXD2880_DVBT2_G_UNKNOWN = 0xFF
+};
+
+enum cxd2880_dvbt2_mode {
+   CXD2880_DVBT2_M2K = 0x00,
+   CXD2880_DVBT2_M8K = 0x01,
+   CXD2880_DVBT2_M4K = 0x02,
+   CXD2880_DVBT2_M1K = 0x03,
+   CXD2880_DVBT2_M16K = 0x04,
+   CXD2880_DVBT2_M32K = 0x05,
+   CXD2880_DVBT2_M_RSVD1 = 0x06,
+   CXD2880_DVBT2_M_RSVD2 = 0x07
+};
+
+enum cxd2880_dvbt2_bw {
+   CXD2880_DVBT2_BW_8 = 0x00,
+   

[PATCH v2 10/15] [media] cxd2880: Add DVB-T monitor and integration layer functions

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide monitor and integration layer functions (DVB-T)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.c |  197 
 .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.h |   58 +
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 1190 
 .../cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  106 ++
 4 files changed, 1551 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
new file mode 100644
index ..43b7da69fc6d
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
@@ -0,0 +1,197 @@
+/*
+ * cxd2880_integ_dvbt.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer functions for DVB-T
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd_dvbt.h"
+#include "cxd2880_integ_dvbt.h"
+
+static enum cxd2880_ret dvbt_wait_demod_lock(struct cxd2880_tnrdmd *tnr_dmd);
+
+enum cxd2880_ret cxd2880_integ_dvbt_tune(struct cxd2880_tnrdmd *tnr_dmd,
+struct cxd2880_dvbt_tune_param
+*tune_param)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+
+   if ((!tnr_dmd) || (!tune_param))
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if ((tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP) &&
+   (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE))
+   return CXD2880_RESULT_ERROR_SW_STATE;
+
+   cxd2880_atomic_set(_dmd->cancel, 0);
+
+   if ((tune_param->bandwidth != CXD2880_DTV_BW_5_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_6_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_7_MHZ) &&
+   (tune_param->bandwidth != CXD2880_DTV_BW_8_MHZ)) {
+   return CXD2880_RESULT_ERROR_NOSUPPORT;
+   }
+
+   ret = cxd2880_tnrdmd_dvbt_tune1(tnr_dmd, tune_param);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   CXD2880_SLEEP(CXD2880_TNRDMD_WAIT_AGC_STABLE);
+
+   ret = cxd2880_tnrdmd_dvbt_tune2(tnr_dmd, tune_param);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   ret = dvbt_wait_demod_lock(tnr_dmd);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   return ret;
+}
+
+enum cxd2880_ret cxd2880_integ_dvbt_wait_ts_lock(struct cxd2880_tnrdmd 
*tnr_dmd)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+   enum cxd2880_tnrdmd_lock_result lock =
+   CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
+   struct cxd2880_stopwatch timer;
+   u8 continue_wait = 1;
+   u32 elapsed = 0;
+
+   if (!tnr_dmd)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return CXD2880_RESULT_ERROR_SW_STATE;
+
+   ret = 

[PATCH v2 09/15] [media] cxd2880: Add DVB-T control functions the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide definitions, interfaces and functions needed for DVB-T
of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h |   91 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c| 1072 
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h|   62 ++
 3 files changed, 1225 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
new file mode 100644
index ..345c094760d2
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h
@@ -0,0 +1,91 @@
+/*
+ * cxd2880_dvbt.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DVB-T related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DVBT_H
+#define CXD2880_DVBT_H
+
+#include "cxd2880_common.h"
+
+enum cxd2880_dvbt_constellation {
+   CXD2880_DVBT_CONSTELLATION_QPSK,
+   CXD2880_DVBT_CONSTELLATION_16QAM,
+   CXD2880_DVBT_CONSTELLATION_64QAM,
+   CXD2880_DVBT_CONSTELLATION_RESERVED_3
+};
+
+enum cxd2880_dvbt_hierarchy {
+   CXD2880_DVBT_HIERARCHY_NON,
+   CXD2880_DVBT_HIERARCHY_1,
+   CXD2880_DVBT_HIERARCHY_2,
+   CXD2880_DVBT_HIERARCHY_4
+};
+
+enum cxd2880_dvbt_coderate {
+   CXD2880_DVBT_CODERATE_1_2,
+   CXD2880_DVBT_CODERATE_2_3,
+   CXD2880_DVBT_CODERATE_3_4,
+   CXD2880_DVBT_CODERATE_5_6,
+   CXD2880_DVBT_CODERATE_7_8,
+   CXD2880_DVBT_CODERATE_RESERVED_5,
+   CXD2880_DVBT_CODERATE_RESERVED_6,
+   CXD2880_DVBT_CODERATE_RESERVED_7
+};
+
+enum cxd2880_dvbt_guard {
+   CXD2880_DVBT_GUARD_1_32,
+   CXD2880_DVBT_GUARD_1_16,
+   CXD2880_DVBT_GUARD_1_8,
+   CXD2880_DVBT_GUARD_1_4
+};
+
+enum cxd2880_dvbt_mode {
+   CXD2880_DVBT_MODE_2K,
+   CXD2880_DVBT_MODE_8K,
+   CXD2880_DVBT_MODE_RESERVED_2,
+   CXD2880_DVBT_MODE_RESERVED_3
+};
+
+enum cxd2880_dvbt_profile {
+   CXD2880_DVBT_PROFILE_HP = 0,
+   CXD2880_DVBT_PROFILE_LP
+};
+
+struct cxd2880_dvbt_tpsinfo {
+   enum cxd2880_dvbt_constellation constellation;
+   enum cxd2880_dvbt_hierarchy hierarchy;
+   enum cxd2880_dvbt_coderate rate_hp;
+   enum cxd2880_dvbt_coderate rate_lp;
+   enum cxd2880_dvbt_guard guard;
+   enum cxd2880_dvbt_mode mode;
+   u8 fnum;
+   u8 length_indicator;
+   u16 cell_id;
+   u8 cell_id_ok;
+   u8 reserved_even;
+   u8 reserved_odd;
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
new file mode 100644
index ..f36cf533ec17
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c
@@ -0,0 +1,1072 @@
+/*
+ * cxd2880_tnrdmd_dvbt.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * control functions for DVB-T
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * 

[PATCH v2 08/15] [media] cxd2880: Add top level of the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This provides the main dvb frontend operation functions
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c | 1550 +
 1 file changed, 1550 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
new file mode 100644
index ..66d78fb93a13
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c
@@ -0,0 +1,1550 @@
+/*
+ * cxd2880_top.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include 
+
+#include "dvb_frontend.h"
+
+#include "cxd2880.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_tnrdmd_dvbt2_mon.h"
+#include "cxd2880_tnrdmd_dvbt_mon.h"
+#include "cxd2880_integ_dvbt2.h"
+#include "cxd2880_integ_dvbt.h"
+#include "cxd2880_devio_spi.h"
+#include "cxd2880_spi_device.h"
+#include "cxd2880_tnrdmd_driver_version.h"
+
+struct cxd2880_priv {
+   struct cxd2880_tnrdmd tnrdmd;
+   struct spi_device *spi;
+   struct cxd2880_io regio;
+   struct cxd2880_spi_device spi_device;
+   struct cxd2880_spi cxd2880_spi;
+   struct cxd2880_dvbt_tune_param dvbt_tune_param;
+   struct cxd2880_dvbt2_tune_param dvbt2_tune_param;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+};
+
+/*
+ * return value conversion table
+ */
+static int return_tbl[] = {
+   0, /* CXD2880_RESULT_OK */
+   -EINVAL,   /* CXD2880_RESULT_ERROR_ARG*/
+   -EIO,  /* CXD2880_RESULT_ERROR_IO */
+   -EPERM,/* CXD2880_RESULT_ERROR_SW_STATE */
+   -EBUSY,/* CXD2880_RESULT_ERROR_HW_STATE */
+   -ETIME,/* CXD2880_RESULT_ERROR_TIMEOUT */
+   -EAGAIN,   /* CXD2880_RESULT_ERROR_UNLOCK */
+   -ERANGE,   /* CXD2880_RESULT_ERROR_RANGE */
+   -EOPNOTSUPP,   /* CXD2880_RESULT_ERROR_NOSUPPORT */
+   -ECANCELED,/* CXD2880_RESULT_ERROR_CANCEL */
+   -EPERM,/* CXD2880_RESULT_ERROR_OTHER */
+   -EOVERFLOW,/* CXD2880_RESULT_ERROR_OVERFLOW */
+   0, /* CXD2880_RESULT_OK_CONFIRM */
+};
+
+static enum cxd2880_ret cxd2880_pre_bit_err_t(
+   struct cxd2880_tnrdmd *tnrdmd, u32 *pre_bit_err,
+   u32 *pre_bit_count)
+{
+   u8 rdata[2];
+
+   if ((!tnrdmd) || (!pre_bit_err) || (!pre_bit_count))
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnrdmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (tnrdmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
+   return CXD2880_RESULT_ERROR_SW_STATE;
+
+   if (tnrdmd->sys != CXD2880_DTV_SYS_DVBT)
+   return CXD2880_RESULT_ERROR_SW_STATE;
+
+   if (slvt_freeze_reg(tnrdmd) != CXD2880_RESULT_OK)
+   return CXD2880_RESULT_ERROR_IO;
+
+   if (tnrdmd->io->write_reg(tnrdmd->io, CXD2880_IO_TGT_DMD,
+   0x00, 0x10) != CXD2880_RESULT_OK) {
+   slvt_unfreeze_reg(tnrdmd);
+   return CXD2880_RESULT_ERROR_IO;
+   }
+
+   if (tnrdmd->io->read_regs(tnrdmd->io, CXD2880_IO_TGT_DMD,
+   0x39, rdata, 1) != CXD2880_RESULT_OK) {
+   slvt_unfreeze_reg(tnrdmd);
+   return CXD2880_RESULT_ERROR_IO;
+   }

[PATCH v2 07/15] [media] cxd2880: Add integration layer for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These functions monitor the driver and watch for task completion.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../media/dvb-frontends/cxd2880/cxd2880_integ.c| 99 ++
 .../media/dvb-frontends/cxd2880/cxd2880_integ.h| 44 ++
 2 files changed, 143 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
new file mode 100644
index ..5ad6685e2a1d
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
@@ -0,0 +1,99 @@
+/*
+ * cxd2880_integ.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration layer common functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_tnrdmd.h"
+#include "cxd2880_tnrdmd_mon.h"
+#include "cxd2880_integ.h"
+
+enum cxd2880_ret cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+   struct cxd2880_stopwatch timer;
+   u32 elapsed_time = 0;
+   u8 cpu_task_completed = 0;
+
+   if (!tnr_dmd)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   ret = cxd2880_tnrdmd_init1(tnr_dmd);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   ret = cxd2880_stopwatch_start();
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   while (1) {
+   ret = cxd2880_stopwatch_elapsed(, _time);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   ret =
+   cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
+_task_completed);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   if (cpu_task_completed)
+   break;
+
+   if (elapsed_time > CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
+   return CXD2880_RESULT_ERROR_TIMEOUT;
+   ret =
+   cxd2880_stopwatch_sleep(,
+   CXD2880_TNRDMD_WAIT_INIT_INTVL);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+   }
+
+   ret = cxd2880_tnrdmd_init2(tnr_dmd);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   return CXD2880_RESULT_OK;
+}
+
+enum cxd2880_ret cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   cxd2880_atomic_set(_dmd->cancel, 1);
+
+   return CXD2880_RESULT_OK;
+}
+
+enum cxd2880_ret cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd
+ *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (cxd2880_atomic_read(_dmd->cancel) != 0)
+   return CXD2880_RESULT_ERROR_CANCEL;
+
+   return CXD2880_RESULT_OK;
+}
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
new file mode 100644
index ..9cfc52dbf9d4
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
@@ -0,0 +1,44 @@
+/*
+ * cxd2880_integ.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * integration 

[PATCH v2 06/15] [media] cxd2880: Add tuner part of the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This part of the driver has the main routines to handle
the tuner and demodulator functionality.  The tnrdmd_mon.* files
have monitor functions for the driver.
This is part of the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h  |   50 +
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c   | 3925 
 .../media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h   |  395 ++
 .../cxd2880/cxd2880_tnrdmd_driver_version.h|   29 +
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c |  207 ++
 .../dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h |   52 +
 6 files changed, 4658 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
 create mode 100644 
drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
new file mode 100644
index ..7de098d556fe
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
@@ -0,0 +1,50 @@
+/*
+ * cxd2880_dtv.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * DTV related definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_DTV_H
+#define CXD2880_DTV_H
+
+enum cxd2880_dtv_sys {
+   CXD2880_DTV_SYS_UNKNOWN,
+   CXD2880_DTV_SYS_DVBT,
+   CXD2880_DTV_SYS_DVBT2,
+   CXD2880_DTV_SYS_ISDBT,
+   CXD2880_DTV_SYS_ISDBTSB,
+   CXD2880_DTV_SYS_ISDBTMM_A,
+   CXD2880_DTV_SYS_ISDBTMM_B,
+   CXD2880_DTV_SYS_ANY
+};
+
+enum cxd2880_dtv_bandwidth {
+   CXD2880_DTV_BW_UNKNOWN = 0,
+   CXD2880_DTV_BW_1_7_MHZ = 1,
+   CXD2880_DTV_BW_5_MHZ = 5,
+   CXD2880_DTV_BW_6_MHZ = 6,
+   CXD2880_DTV_BW_7_MHZ = 7,
+   CXD2880_DTV_BW_8_MHZ = 8
+};
+
+#endif
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
new file mode 100644
index ..286384ae0124
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
@@ -0,0 +1,3925 @@
+/*
+ * cxd2880_tnrdmd.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * common control functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, 

[PATCH v2 05/15] [media] cxd2880: Add spi device IO routines

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Add functions for initializing, reading and writing to the SPI
device for the Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.c  | 147 +
 .../dvb-frontends/cxd2880/cxd2880_devio_spi.h  |  40 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h  |  51 +++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.c | 130 ++
 .../dvb-frontends/cxd2880/cxd2880_spi_device.h |  45 +++
 5 files changed, 413 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
new file mode 100644
index ..516efade6bf5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
@@ -0,0 +1,147 @@
+/*
+ * cxd2880_devio_spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * I/O interface via SPI
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_devio_spi.h"
+#include "cxd2880_stdlib.h"
+
+#define BURST_WRITE_MAX 128
+
+static enum cxd2880_ret cxd2880_io_spi_read_reg(struct cxd2880_io *io,
+   enum cxd2880_io_tgt tgt,
+   u8 sub_address, u8 *data,
+   u32 size)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[6];
+   u8 *read_data_top = data;
+
+   if ((!io) || (!io->if_object) || (!data))
+   return CXD2880_RESULT_ERROR_ARG;
+
+   if (sub_address + size > 0x100)
+   return CXD2880_RESULT_ERROR_RANGE;
+
+   spi = (struct cxd2880_spi *)(io->if_object);
+
+   if (tgt == CXD2880_IO_TGT_SYS)
+   send_data[0] = 0x0B;
+   else
+   send_data[0] = 0x0A;
+
+   send_data[3] = 0;
+   send_data[4] = 0;
+   send_data[5] = 0;
+
+   while (size > 0) {
+   send_data[1] = sub_address;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = (u8)size;
+
+   ret =
+   spi->write_read(spi, send_data, sizeof(send_data),
+   read_data_top, send_data[2]);
+   if (ret != CXD2880_RESULT_OK)
+   return ret;
+
+   sub_address += send_data[2];
+   read_data_top += send_data[2];
+   size -= send_data[2];
+   }
+
+   return ret;
+}
+
+static enum cxd2880_ret cxd2880_io_spi_write_reg(struct cxd2880_io *io,
+enum cxd2880_io_tgt tgt,
+u8 sub_address,
+const u8 *data, u32 size)
+{
+   enum cxd2880_ret ret = CXD2880_RESULT_OK;
+   struct cxd2880_spi *spi = NULL;
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = data;
+
+   if ((!io) || (!io->if_object) || (!data))
+ 

[PATCH v2 04/15] [media] cxd2880: Add math functions for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Provide some math support functions (fixed-point log functions)
for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c | 89 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h | 40 ++
 2 files changed, 129 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_math.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
new file mode 100644
index ..434c827898ff
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
@@ -0,0 +1,89 @@
+/*
+ * cxd2880_math.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * mathmatics functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "cxd2880_math.h"
+
+#define MAX_BIT_PRECISION5
+#define FRAC_BITMASK   0x1F
+#define LOG2_10_100X332
+#define LOG2_E_100X  144
+
+static const u8 log2_look_up[] = {
+   0, 4,
+   9, 13,
+   17, 21,
+   25, 29,
+   32, 36,
+   39, 43,
+   46, 49,
+   52, 55,
+   58, 61,
+   64, 67,
+   70, 73,
+   75, 78,
+   81, 83,
+   86, 88,
+   91, 93,
+   95, 98
+};
+
+u32 cxd2880_math_log2(u32 x)
+{
+   u8 count = 0;
+   u8 index = 0;
+   u32 xval = x;
+
+   for (x >>= 1; x > 0; x >>= 1)
+   count++;
+
+   x = count * 100;
+
+   if (count > 0) {
+   if (count <= MAX_BIT_PRECISION) {
+   index =
+   (u8)(xval << (MAX_BIT_PRECISION - count)) &
+   FRAC_BITMASK;
+   x += log2_look_up[index];
+   } else {
+   index =
+   (u8)(xval >> (count - MAX_BIT_PRECISION)) &
+   FRAC_BITMASK;
+   x += log2_look_up[index];
+   }
+   }
+
+   return x;
+}
+
+u32 cxd2880_math_log10(u32 x)
+{
+   return ((100 * cxd2880_math_log2(x) + LOG2_10_100X / 2) / LOG2_10_100X);
+}
+
+u32 cxd2880_math_log(u32 x)
+{
+   return ((100 * cxd2880_math_log2(x) + LOG2_E_100X / 2) / LOG2_E_100X);
+}
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_math.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_math.h
new file mode 100644
index ..94211835a4ad
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_math.h
@@ -0,0 +1,40 @@
+/*
+ * cxd2880_math.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * mathmatics definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ 

[PATCH v2 03/15] [media] cxd2880: Add common files for the driver

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

These are common files for the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.
These contains helper functions for the driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/dvb-frontends/cxd2880/cxd2880.h  | 46 
 .../media/dvb-frontends/cxd2880/cxd2880_common.c   | 84 +
 .../media/dvb-frontends/cxd2880/cxd2880_common.h   | 86 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c   | 68 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h   | 62 
 .../media/dvb-frontends/cxd2880/cxd2880_stdlib.h   | 35 +
 .../dvb-frontends/cxd2880/cxd2880_stopwatch_port.c | 71 ++
 7 files changed, 452 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c

diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h 
b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
new file mode 100644
index ..281f9a784eb5
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h
@@ -0,0 +1,46 @@
+/*
+ * cxd2880.h
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef CXD2880_H
+#define CXD2880_H
+
+struct cxd2880_config {
+   struct spi_device *spi;
+   struct mutex *spi_mutex; /* For SPI access exclusive control */
+};
+
+#if IS_REACHABLE(CONFIG_DVB_CXD2880)
+extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg);
+#else
+static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe,
+   struct cxd2880_config *cfg)
+{
+   pr_warn("%s: driver disabled by Kconfig\n", __func__);
+   return NULL;
+}
+#endif /* CONFIG_DVB_CXD2880 */
+
+#endif /* CXD2880_H */
diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
new file mode 100644
index ..850f3a76b2c7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
@@ -0,0 +1,84 @@
+/*
+ * cxd2880_common.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * common functions
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 

[PATCH v2 02/15] [media] cxd2880-spi: Add support for CXD2008 SPI interface

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the SPI adapter part of the driver for the
Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/spi/cxd2880-spi.c | 728 
 1 file changed, 728 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index ..82e122349055
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,728 @@
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PACKET 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready;
+   u8 almost_full;
+   u8 almost_empty;
+   u8 overflow;
+   u8 underflow;
+   u16 packet_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex; /* For SPI access exclusive control */
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("%s: invalid arg\n", __func__);
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+   ret = spi_sync(spi, );
+
+   return ret;
+}
+
+static int cxd2880_write_reg(struct spi_device *spi,
+   u8 subAddress, const u8 *data, u32 size)
+{
+   u8 send_data[BURST_WRITE_MAX + 4];
+   const u8 *write_data_top = NULL;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("%s: invalid arg\n", __func__);
+   return -EINVAL;
+   }
+   if (size > BURST_WRITE_MAX) {
+   pr_err("%s: data size > WRITE_MAX\n", __func__);
+   return -EINVAL;
+   }
+
+   if (subAddress + size > 0x100) {
+   pr_err("%s: out of range\n", __func__);
+   return -EINVAL;
+   }
+
+   send_data[0] = 0x0E;
+   write_data_top = data;
+
+   while (size > 0) {
+   send_data[1] = subAddress;
+   if (size > 255)
+   send_data[2] = 255;
+   else
+   send_data[2] = (u8)size;
+
+   memcpy(_data[3], write_data_top, send_data[2]);
+
+   ret = cxd2880_write_spi(spi, send_data, send_data[2] + 3);
+   if (ret) {
+   dev_err(>dev, "%s: write spi failed %d\n",
+   __func__, ret);
+  

[PATCH v2 01/15] [dt-bindings] [media] Add document file for CXD2880 SPI I/F

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the document file for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the description of the SPI adapter binding.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../devicetree/bindings/media/spi/sony-cxd2880.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index ..fc5aa263abe5
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,14 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+};
-- 
2.11.0



[PATCH v2 0/15] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-04-13 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the patch series (version 2) of Sony CXD2880 DVB-T2/T tuner + 
demodulator driver.
The driver supports DVB-API and interfaces through SPI.

We have tested the driver on Raspberry Pi 3 and got picture and sound from a 
media player.

Thanks,
Takiguchi
---
 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt|   14 
++
 drivers/media/spi/cxd2880-spi.c | 728 

 drivers/media/dvb-frontends/cxd2880/cxd2880.h   |   46 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c|   84 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h|   86 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c|   68 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h|   62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h|   35 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c|   71 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c  |   89 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h  |   40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c |  147 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h |   40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h   |   51 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c|  130 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h|   45 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h   |   50 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c| 3925 

 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h|  395 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h |   29 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c|  207 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h|   52 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c |   99 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h |   44 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c   | 1550 

 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h  |   91 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c   | 1072 
+
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h   |   62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c|  197 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h|   58 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c   | 1190 
+
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h   |  106 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h |  402 
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c  | 1309 
++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h  |   82 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c   |  311 +++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h   |   64 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c  | 2523 

 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h  |  170 ++
 drivers/media/dvb-frontends/Makefile|1 +
 drivers/media/dvb-frontends/cxd2880/Makefile|   21 
+
 drivers/media/spi/Makefile  |5 
+
 drivers/media/dvb-frontends/Kconfig |2 ++
 drivers/media/dvb-frontends/cxd2880/Kconfig |6 
++
 drivers/media/spi/Kconfig   |   14 
++
 MAINTAINERS |9 
+

 46 files changed, 15782 insertions(+)

 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
 create mode 100644 drivers/media/spi/cxd2880-spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h
 create mode 100644 

[PATCH 5/5] media: Update MAINTAINERS file for CXD2880

2017-04-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is MAINTAINERS file update about the driver for
Sony CXD2880 DVB-T2/T tuner + demodulator.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 MAINTAINERS |9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6640601..c34335d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8034,6 +8034,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR HORUS3A
 M: Sergey Kozlov 
 M: Abylay Ospan 
-- 
1.7.9.5



[PATCH 2/5] media: Add support for CXD2880 SPI I/F

2017-04-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the SPI adapter part of the driver.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/spi/Kconfig   |   14 +
 drivers/media/spi/Makefile  |5 +
 drivers/media/spi/cxd2880-spi.c |  727 +++
 3 files changed, 746 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a3..b07ac86 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+   depends on DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Choose if you would like to have SPI interface support for Sony 
CXD2880.
+
+endmenu
+
+endif
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
index ea64013..40e0f88 100644
--- a/drivers/media/spi/Makefile
+++ b/drivers/media/spi/Makefile
@@ -1 +1,6 @@
 obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
+obj-$(CONFIG_CXD2880_SPI_DRV) += cxd2880-spi.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/dvb-frontends/cxd2880
\ No newline at end of file
diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index 000..7ba0ed8
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,727 @@
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PACKET 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready;
+   u8 almost_full;
+   u8 almost_empty;
+   u8 overflow;
+   u8 underflow;
+   u16 packet_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex; /* For SPI access exclusive control */
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("%s: invalid arg\n", __func__);
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+   ret = spi_sync(spi, );
+
+   return ret;
+}
+
+static int cxd2880_write_reg(struct spi_device *spi,
+   u8 subAddress, const u8 *data, u32 size)
+{
+   u8 send_data[BURST_WRITE_MAX + 

[PATCH 1/5] dt-bindings: media: Add document file for CXD2880 SPI I/F

2017-04-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the document file for Sony CXD2880 DVB-T2/T tuner + demodulator.
It contains the description of the SPI adapter binding.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../devicetree/bindings/media/spi/sony-cxd2880.txt |   14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index 000..fc5aa26
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,14 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+};
-- 
1.7.9.5



[PATCH 0/5] dt-bindings: media: Add document file and driver

2017-04-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is the patch series of Sony CXD2880 DVB-T2/T tuner + demodulator driver.
The driver supports DVB-API and interfaces through SPI.

We have tested the driver on Raspberry Pi 3 and got picture and sound from a 
media player.

Thanks,
Takiguchi
---
 Documentation//devicetree/bindings/media/spi/sony-cxd2880.txt|   14 
++
 drivers/media/spi/Kconfig|   14 +
 drivers/media/spi/Makefile   |5 +
 drivers/media/spi/cxd2880-spi.c  |  727 
+++
 drivers/media/dvb-frontends/Kconfig  |2 +
 drivers/media/dvb-frontends/Makefile |1 +
 drivers/media/dvb-frontends/cxd2880/Kconfig  |6 +
 drivers/media/dvb-frontends/cxd2880/Makefile |   22 +
 drivers/media/dvb-frontends/cxd2880/cxd2880.h|   46 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c |   84 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h |   86 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c  |  147 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h  |   40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h|   50 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c  |   99 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h  |   44 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c |   68 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h |   62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c   |   89 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h   |   40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h|   51 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c |  130 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h |   45 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h |   35 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c |   71 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c | 3925 

 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h |  395 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h  |   29 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c |  207 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h |   52 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c| 1550 

 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h   |   91 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h  |  402 

 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c |  197 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h |   58 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c|  311 +++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h|   64 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c| 1072 
+
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h|   62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c   | 1309 
++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h   |   82 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c   | 2523 

 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h   |  170 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c| 1190 
+
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h|  106 +
 MAINTAINERS  |9 
+
 46 files changed, 15782 insertions(+)

 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
 create mode 100644 drivers/media/spi/cxd2880-spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h
 create mode 100644 

[RFC PATCH 1/5] Document: Add document file for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-03-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator.

Regarding this third Beta Release, the status is:
- Tested on Raspberry Pi 3.
- The DVB-API operates under dvbv5 tools.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 .../devicetree/bindings/media/spi/sony-cxd2880.txt |   16 
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt

diff --git a/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt 
b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
new file mode 100644
index 000..bdbb047
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
@@ -0,0 +1,16 @@
+Sony CXD2880 DVB-T2/T tuner + demodulator driver SPI adapter
+
+Required properties:
+- compatible: Should be "sony,cxd2880".
+- reg: SPI chip select number for the device.
+- spi-max-frequency: Maximum bus speed, should be set to <5500> (55MHz).
+- status: Should be "okay"
+
+Example:
+
+cxd2880@0 {
+   compatible = "sony,cxd2880";
+   reg = <0>; /* CE0 */
+   spi-max-frequency = <5500>; /* 55MHz */
+   status = "okay";
+};
-- 
1.7.9.5



[RFC PATCH 5/5] media: Update MAINTAINERS file for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-03-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator.

Regarding this third Beta Release, the status is:
- Tested on Raspberry Pi 3.
- The DVB-API operates under dvbv5 tools.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 MAINTAINERS |9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c265a5f..fe86728 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8034,6 +8034,15 @@ T:   git git://linuxtv.org/media_tree.git
 S: Supported
 F: drivers/media/dvb-frontends/cxd2841er*
 
+MEDIA DRIVERS FOR CXD2880
+M: Yasunari Takiguchi 
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+T: git git://linuxtv.org/media_tree.git
+S: Supported
+F: drivers/media/dvb-frontends/cxd2880/*
+F: drivers/media/spi/cxd2880*
+
 MEDIA DRIVERS FOR HORUS3A
 M: Sergey Kozlov 
 M: Abylay Ospan 
-- 
1.7.9.5



[RFC PATCH 0/5] Document: Add document file for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-03-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

Hi,

This is a patch series of Sony CXD2880 DVB-T2/T tuner + demodulator driver.  
It supports DVB-API and interfaces through SPI.  

We have tested the driver on Raspberry Pi 3 and got picture and sound from a 
media player.  


Regarding this third Beta Release, the status is:
- Tested on Raspberry Pi 3.
- Compiled on Linux 4.10.
- The DVB-API operates under dvbv5 tools.
- No error/warning from checkpatch.pl

Feedback is appreciated.  


Thanks,
Takiguchi

---
 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt   |   
16 
 drivers/media/spi/Kconfig  |   
14 +
 drivers/media/spi/Makefile |   
 5 +
 drivers/media/spi/cxd2880-spi.c|  
737 +++
 drivers/media/dvb-frontends/Kconfig|   
 2 +
 drivers/media/dvb-frontends/Makefile   |   
 1 +
 drivers/media/dvb-frontends/cxd2880/Kconfig|   
 6 +
 drivers/media/dvb-frontends/cxd2880/Makefile   |   
22 +
 drivers/media/dvb-frontends/cxd2880/cxd2880.h  |   
37 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c   |   
84 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h   |   
85 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c|  
145 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h|   
40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dtv.h  |   
50 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.c|  
101 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ.h|   
44 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c   |   
68 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h   |   
62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.c |   
89 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_math.h |   
40 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h  |   
51 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c   |  
130 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h   |   
45 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h   |   
35 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c   |   
73 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c   | 
3936 
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h   |  
395 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h|   
29 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.c   |  
207 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_mon.h   |   
52 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c  | 
1558 
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt.h |   
91 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_dvbt2.h|  
402 
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c   |  
197 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h   |   
58 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.c  |  
311 +++
 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt2.h  |   
64 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.c  | 
1074 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt.h  |   
62 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.c | 
1312 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2.h |   
82 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.c | 
2545 
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt2_mon.h |  
170 ++
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 
1192 +
 drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  
106 +
 MAINTAINERS|   
 9 +
 46 files changed, 15834 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/spi/sony-cxd2880.txt
 create mode 100644 drivers/media/spi/cxd2880-spi.c
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Kconfig
 create mode 100644 drivers/media/dvb-frontends/cxd2880/Makefile
 create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h
 create mode 

[RFC PATCH 2/5] media: Add SPI I/F for Sony CXD2880 DVB-T2/T tuner + demodulator

2017-03-06 Thread Yasunari.Takiguchi
From: Yasunari Takiguchi 

This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator.

Regarding this third Beta Release, the status is:
- Tested on Raspberry Pi 3.
- The DVB-API operates under dvbv5 tools.

Signed-off-by: Yasunari Takiguchi 
Signed-off-by: Masayuki Yamamoto 
Signed-off-by: Hideki Nozawa 
Signed-off-by: Kota Yonezawa 
Signed-off-by: Toshihiko Matsumoto 
Signed-off-by: Satoshi Watanabe 
---
 drivers/media/spi/Kconfig   |   14 +
 drivers/media/spi/Makefile  |5 +
 drivers/media/spi/cxd2880-spi.c |  737 +++
 3 files changed, 756 insertions(+)
 create mode 100644 drivers/media/spi/cxd2880-spi.c

diff --git a/drivers/media/spi/Kconfig b/drivers/media/spi/Kconfig
index a21f5a3..cce36dc 100644
--- a/drivers/media/spi/Kconfig
+++ b/drivers/media/spi/Kconfig
@@ -12,3 +12,17 @@ config VIDEO_GS1662
 endmenu
 
 endif
+
+if SPI
+menu "Media SPI Adapters"
+
+config CXD2880_SPI_DRV
+   tristate "Sony CXD2880 SPI support"
+   depends on DVB_CXD2880 && DVB_CORE && SPI
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Choose if you would like to have SPI interface support for Sony 
CXD2880.
+
+endmenu
+
+endif
diff --git a/drivers/media/spi/Makefile b/drivers/media/spi/Makefile
index ea64013..9e53677 100644
--- a/drivers/media/spi/Makefile
+++ b/drivers/media/spi/Makefile
@@ -1 +1,6 @@
 obj-$(CONFIG_VIDEO_GS1662) += gs1662.o
+obj-$(CONFIG_CXD2880_SPI_DRV) += cxd2880-spi.o
+
+ccflags-y += -Idrivers/media/dvb-core
+ccflags-y += -Idrivers/media/dvb-frontends
+ccflags-y += -Idrivers/media/dvb-frontends/cxd2880
diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c
new file mode 100644
index 000..0752b76
--- /dev/null
+++ b/drivers/media/spi/cxd2880-spi.c
@@ -0,0 +1,737 @@
+/*
+ * cxd2880-spi.c
+ * Sony CXD2880 DVB-T2/T tuner + demodulator driver
+ * SPI adapter
+ *
+ * Copyright (C) 2016 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "dvb_demux.h"
+#include "dmxdev.h"
+#include "dvb_frontend.h"
+#include "cxd2880.h"
+
+#define CXD2880_MAX_FILTER_SIZE 32
+#define BURST_WRITE_MAX 128
+#define MAX_TRANS_PACKET 300
+
+struct cxd2880_ts_buf_info {
+   u8 read_ready;
+   u8 almost_full;
+   u8 almost_empty;
+   u8 overflow;
+   u8 underflow;
+   u16 packet_num;
+};
+
+struct cxd2880_pid_config {
+   u8 is_enable;
+   u16 pid;
+};
+
+struct cxd2880_pid_filter_config {
+   u8 is_negative;
+   struct cxd2880_pid_config pid_config[CXD2880_MAX_FILTER_SIZE];
+};
+
+struct cxd2880_dvb_spi {
+   struct dvb_frontend dvb_fe;
+   struct dvb_adapter adapter;
+   struct dvb_demux demux;
+   struct dmxdev dmxdev;
+   struct dmx_frontend dmx_fe;
+   struct task_struct *cxd2880_ts_read_thread;
+   struct spi_device *spi;
+   struct mutex spi_mutex;
+   int feed_count;
+   int all_pid_feed_count;
+   u8 *ts_buf;
+   struct cxd2880_pid_filter_config filter_config;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size)
+{
+   struct spi_message msg;
+   struct spi_transfer tx;
+   int ret = 0;
+
+   if ((!spi) || (!data)) {
+   pr_err("%s: invalid arg\n", __func__);
+   return -EINVAL;
+   }
+
+   memset(, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init();
+   spi_message_add_tail(, );
+   ret = spi_sync(spi, );
+
+   return ret;
+}
+
+static int cxd2880_write_reg(struct