[PATCH] [media] radio: constify pnp_device_id

2017-08-15 Thread Arvind Yadav
pnp_device_id are not supposed to change at runtime. All functions
working with pnp_device_id provided by  work with
const pnp_device_id. So mark the non-const structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/radio/radio-cadet.c| 2 +-
 drivers/media/radio/radio-gemtek.c   | 2 +-
 drivers/media/radio/radio-sf16fmr2.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/radio/radio-cadet.c 
b/drivers/media/radio/radio-cadet.c
index cbaf850..6888b7d 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -528,7 +528,7 @@ static const struct v4l2_ctrl_ops cadet_ctrl_ops = {
 
 #ifdef CONFIG_PNP
 
-static struct pnp_device_id cadet_pnp_devices[] = {
+static const struct pnp_device_id cadet_pnp_devices[] = {
/* ADS Cadet AM/FM Radio Card */
{.id = "MSM0c24", .driver_data = 0},
{.id = ""}
diff --git a/drivers/media/radio/radio-gemtek.c 
b/drivers/media/radio/radio-gemtek.c
index ca051ccb..ddc12b1 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -281,7 +281,7 @@ static const struct radio_isa_ops gemtek_ops = {
 static const int gemtek_ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c 
};
 
 #ifdef CONFIG_PNP
-static struct pnp_device_id gemtek_pnp_devices[] = {
+static const struct pnp_device_id gemtek_pnp_devices[] = {
/* AOpen FX-3D/Pro Radio */
{.id = "ADS7183", .driver_data = 0},
{.id = ""}
diff --git a/drivers/media/radio/radio-sf16fmr2.c 
b/drivers/media/radio/radio-sf16fmr2.c
index dc81d42..de79d55 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -197,7 +197,7 @@ static int fmr2_tea_ext_init(struct snd_tea575x *tea)
return 0;
 }
 
-static struct pnp_device_id fmr2_pnp_ids[] = {
+static const struct pnp_device_id fmr2_pnp_ids[] = {
{ .id = "MFRad13" }, /* tuner subdevice of SF16-FMD2 */
{ .id = "" }
 };
-- 
2.7.4



[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(&tnr_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);
+   if (ret)
+   return ret;
+
+   usleep_range(CXD2880_TNRDMD_WAIT_AGC_STABLE * 1,
+CXD2880_TNRDMD_WAIT_AGC_STABLE * 1 + 1000);
+
+   ret = cxd28

[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,
+   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

[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(&tnr_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 =
+   CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
+   struct cxd2880_stopwatch timer;
+   u8 continue_wait = 1;
+   unsigned int elapsed = 0;
+
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   if (tnr_dmd->

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

[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,
+   CXD2880_IO_TGT_DMD,
+   0x22, rdata, 2);
+   if (ret) {
+   slvt_unfreeze_reg(tnrdmd);
+   return ret;
+   }
+
+   *pre

[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(&timer);
+   if (ret)
+   return ret;
+
+   while (1) {
+   ret = cxd2880_stopwatch_elapsed(&timer, &elapsed_time);
+   if (ret)
+   return ret;
+
+   ret =
+   cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
+&cpu_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(&timer,
+   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(&tnr_dmd->cancel, 1);
+
+   return 0;
+}
+
+int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
+{
+   if (!tnr_dmd)
+   return -EINVAL;
+
+   if (atomic_read(&tnr_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 Sony Semiconductor Solutions Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Gener

[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 
b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
new file mode 100644
index ..044dc26d2ff3
--- /dev/null
+++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c
@@ -0,0 +1,4030 @@

[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 cxd2880_io_tgt tgt,
+   u8 sub_address,
+   const u8 *data, u32 size)
+{
+   int ret = 0;
+   struct cxd2880_spi *spi = NULL;

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

[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(&tx, 0, sizeof(tx));
+   tx.tx_buf = data;
+   tx.len = size;
+
+   spi_message_init(&msg);
+   spi_message_add_tail(&tx, &msg);
+   ret = spi_sync(spi, &msg);
+
+   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)
+   send_data[2] = 255;
+   else
+   send_data[2] = (u8)size;
+
+   memcpy(&send_data[3], write_data_top, send_data[2]);
+
+   r

[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() 
  -modified about measureme

cron job: media_tree daily build: ERRORS

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

Results of the daily build of media_tree:

date:   Wed Aug 16 05:00:18 CEST 2017
media-tree git hash:ec0c3ec497cabbf3bfa03a9eb5edcc252190a4e0
media_build git hash:   a03e89634b47f570039c7d6931cd751777d4bba1
v4l-utils git hash: 5a67da05fded64b5f678033c16196799e134c62c
gcc version:i686-linux-gcc (GCC) 7.1.0
sparse version: v0.5.0
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.11.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-blackfin-bf561: OK
linux-git-i686: WARNINGS
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: WARNINGS
linux-2.6.36.4-i686: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.2.37-i686: WARNINGS
linux-3.3.8-i686: WARNINGS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.12.67-i686: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.16.7-i686: WARNINGS
linux-3.17.8-i686: ERRORS
linux-3.18.7-i686: ERRORS
linux-3.19-i686: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.1.33-i686: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.4.22-i686: WARNINGS
linux-4.5.7-i686: WARNINGS
linux-4.6.7-i686: WARNINGS
linux-4.7.5-i686: WARNINGS
linux-4.8-i686: WARNINGS
linux-4.9.26-i686: WARNINGS
linux-4.10.14-i686: WARNINGS
linux-4.11-i686: WARNINGS
linux-4.12.1-i686: WARNINGS
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.37-x86_64: WARNINGS
linux-3.3.8-x86_64: WARNINGS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.67-x86_64: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.7-x86_64: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.7-x86_64: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.33-x86_64: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.22-x86_64: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-x86_64: WARNINGS
linux-4.8-x86_64: WARNINGS
linux-4.9.26-x86_64: WARNINGS
linux-4.10.14-x86_64: WARNINGS
linux-4.11-x86_64: WARNINGS
linux-4.12.1-x86_64: WARNINGS
apps: WARNINGS
spec-git: OK

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[PATCH] v4l: vsp1: Start and stop DRM pipeline independently of planes

2017-08-15 Thread Laurent Pinchart
The KMS API supports enabling a CRTC without any plane. To enable that
use case, we need to start the pipeline when configuring the LIF,
instead of when enabling the first plane.

Signed-off-by: Laurent Pinchart 
---
 drivers/media/platform/vsp1/vsp1_drm.c | 37 +-
 1 file changed, 27 insertions(+), 10 deletions(-)

This patch is based on top of the VSP+DU large patch series queued through
Dave's DRM tree for v4.14-rc1. It doesn't can't be merged independently
through the linux-media tree for the same kernel version. As the change is not
urgent, it can be delayed until v4.15-rc1.

diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
b/drivers/media/platform/vsp1/vsp1_drm.c
index 4dfbeac8f42c..7ce69f23f50a 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -84,8 +84,12 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int 
pipe_index,
struct vsp1_drm_pipeline *drm_pipe;
struct vsp1_pipeline *pipe;
struct vsp1_bru *bru;
+   struct vsp1_entity *entity;
+   struct vsp1_entity *next;
+   struct vsp1_dl_list *dl;
struct v4l2_subdev_format format;
const char *bru_name;
+   unsigned long flags;
unsigned int i;
int ret;
 
@@ -250,6 +254,29 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int 
pipe_index,
vsp1_write(vsp1, VI6_DISP_IRQ_STA, 0);
vsp1_write(vsp1, VI6_DISP_IRQ_ENB, 0);
 
+   /* Configure all entities in the pipeline. */
+   dl = vsp1_dl_list_get(pipe->output->dlm);
+
+   list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) {
+   vsp1_entity_route_setup(entity, pipe, dl);
+
+   if (entity->ops->configure) {
+   entity->ops->configure(entity, pipe, dl,
+  VSP1_ENTITY_PARAMS_INIT);
+   entity->ops->configure(entity, pipe, dl,
+  VSP1_ENTITY_PARAMS_RUNTIME);
+   entity->ops->configure(entity, pipe, dl,
+  VSP1_ENTITY_PARAMS_PARTITION);
+   }
+   }
+
+   vsp1_dl_list_commit(dl);
+
+   /* Start the pipeline. */
+   spin_lock_irqsave(&pipe->irqlock, flags);
+   vsp1_pipeline_run(pipe);
+   spin_unlock_irqrestore(&pipe->irqlock, flags);
+
dev_dbg(vsp1->dev, "%s: pipeline enabled\n", __func__);
 
return 0;
@@ -488,7 +515,6 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int 
pipe_index)
struct vsp1_entity *next;
struct vsp1_dl_list *dl;
const char *bru_name;
-   unsigned long flags;
unsigned int i;
int ret;
 
@@ -570,15 +596,6 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int 
pipe_index)
}
 
vsp1_dl_list_commit(dl);
-
-   /* Start or stop the pipeline if needed. */
-   if (!drm_pipe->enabled && pipe->num_inputs) {
-   spin_lock_irqsave(&pipe->irqlock, flags);
-   vsp1_pipeline_run(pipe);
-   spin_unlock_irqrestore(&pipe->irqlock, flags);
-   } else if (drm_pipe->enabled && !pipe->num_inputs) {
-   vsp1_pipeline_stop(pipe);
-   }
 }
 EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush);
 
-- 
Regards,

Laurent Pinchart



Re: [PATCH v2] media: isl6421: add checks for current overflow

2017-08-15 Thread Jemma Denson

Hi Mauro,

On 13/08/17 20:35, Mauro Carvalho Chehab wrote:


This Kaffeine's BZ:
https://bugs.kde.org/show_bug.cgi?id=374693

affects SkyStar S2 PCI DVB-S/S2 rev 3.3 device. It could be due to
a Kernel bug.

While checking the Isil 6421, comparing with its manual, available at:

http://www.intersil.com/content/dam/Intersil/documents/isl6/isl6421a.pdf

It was noticed that, if the output load is highly capacitive, a different 
approach
is recomended when energizing the LNBf.

Also, it is possible to detect if a current overload is happening, by checking 
an
special flag.

Add support for it.

Compile-tested only.

Signed-off-by: Mauro Carvalho Chehab 
---
  drivers/media/dvb-frontends/isl6421.c | 72 +--
  1 file changed, 68 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/isl6421.c 
b/drivers/media/dvb-frontends/isl6421.c
index 838b42771a05..b04d56ad4ce8 100644
--- a/drivers/media/dvb-frontends/isl6421.c
+++ b/drivers/media/dvb-frontends/isl6421.c
@@ -38,25 +38,43 @@ struct isl6421 {
u8  override_and;
struct i2c_adapter  *i2c;
u8  i2c_addr;
+   boolis_off;
  };
  
  static int isl6421_set_voltage(struct dvb_frontend *fe,

   enum fe_sec_voltage voltage)
  {
+   int ret;
+   u8 buf;
+   bool is_off;
struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
-   struct i2c_msg msg = {  .addr = isl6421->i2c_addr, .flags = 0,
-   .buf = &isl6421->config,
-   .len = sizeof(isl6421->config) };
+   struct i2c_msg msg[2] = {
+   {
+ .addr = isl6421->i2c_addr,
+ .flags = 0,
+ .buf = &isl6421->config,
+ .len = 1,
+   }, {
+ .addr = isl6421->i2c_addr,
+ .flags = I2C_M_RD,
+ .buf = &buf,
+ .len = 1,
+   }
+
+   };
  
  	isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
  
  	switch(voltage) {

case SEC_VOLTAGE_OFF:
+   is_off = true;
break;
case SEC_VOLTAGE_13:
+   is_off = false;
isl6421->config |= ISL6421_EN1;
break;
case SEC_VOLTAGE_18:
+   is_off = false;
isl6421->config |= (ISL6421_EN1 | ISL6421_VSEL1);
break;
default:
@@ -66,7 +84,51 @@ static int isl6421_set_voltage(struct dvb_frontend *fe,
isl6421->config |= isl6421->override_or;
isl6421->config &= isl6421->override_and;
  
-	return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;

+   /*
+* If LNBf were not powered on, disable dynamic current limit, as,
+* according with datasheet, highly capacitive load on the output may
+* cause a difficult start-up.
+*/
+   if (isl6421->is_off && !is_off)
+   isl6421->config |= ISL6421_EN1;


Checking the datasheet I think we need to be setting DCL high instead. EN1 is
already set anyway.


+
+   ret = i2c_transfer(isl6421->i2c, msg, 2);
+   if (ret < 0)
+   return ret;
+   if (ret != 2)
+   return -EIO;
+
+   isl6421->is_off = is_off;


Is this in the right place?


+
+   /* On overflow, the device will try again after 900 ms (typically) */
+   if (isl6421->is_off && (buf & ISL6421_OLF1))
+   msleep(1000);


1000ms does only cover one cycle of OFF then ON - the device will keep cycling
900ms off then 20ms on until overflow is cleared so it might take longer but
adding the code to support longer is  probably not worth it. Waiting one cycle
is better than the current none anyway.


+
+   if (isl6421->is_off && !is_off) {
+   isl6421->config &= ~ISL6421_EN1;
+
+   ret = i2c_transfer(isl6421->i2c, msg, 2);
+   if (ret < 0)
+   return ret;
+   if (ret != 2)
+   return -EIO;
+   }


Does this if statement ever match? isl6421->is_off and is_off are the same value
at this point. I presume this is supposed to be re-enabling DCL so would again
also need that bit instead of EN1. We might also need a little delay before
turning it on - the datasheet mentions a "chosen amount of time". I've no idea
what's appropriate here, 200ms?

A simpler if statement might be just (isl6421->config & ISL6421_DCL), we just
need to check DCL was set high above.


+
+   /* Check if overload flag is active. If so, disable power */
+   if (buf & ISL6421_OLF1) {
+   isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
+   ret = i2c_transfer(isl6421->i2c, msg, 1);
+   if (ret < 0)
+   return ret;
+   if (ret != 1)
+   return -EIO;
+   isl6421->is_

[PATCHv2] cec: rename pin events/function

2017-08-15 Thread Hans Verkuil
The CEC_EVENT_PIN_LOW/HIGH defines and the cec_queue_pin_event() function
did not specify that these were about CEC pin events.

Since in the future there will also be HPD pin events it is wise to rename
the event defines and function to CEC_EVENT_PIN_CEC_LOW/HIGH and
cec_queue_pin_cec_event() now before these become part of the ABI.

Signed-off-by: Hans Verkuil 
---
Changes since v1: forgot to change the CEC-EVENT-PIN-LOW/HIGH IDs in the
documentation.
---
diff --git a/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst 
b/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
index 0a7aa21f24f4..6c1f6efb822e 100644
--- a/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
@@ -127,7 +127,7 @@ returns the information to the application. The ioctl never 
fails.
   - 0x0080
   - The CEC hardware can monitor CEC pin changes from low to high voltage
 and vice versa. When in pin monitoring mode the application will
-   receive ``CEC_EVENT_PIN_LOW`` and ``CEC_EVENT_PIN_HIGH`` events.
+   receive ``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events.



diff --git a/Documentation/media/uapi/cec/cec-ioc-dqevent.rst 
b/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
index 766d8b0ce431..db615e3405c0 100644
--- a/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
@@ -146,16 +146,16 @@ it is guaranteed that the state did change in between the 
two events.
   - 2
   - Generated if one or more CEC messages were lost because the
application didn't dequeue CEC messages fast enough.
-* .. _`CEC-EVENT-PIN-LOW`:
+* .. _`CEC-EVENT-PIN-CEC-LOW`:

-  - ``CEC_EVENT_PIN_LOW``
+  - ``CEC_EVENT_PIN_CEC_LOW``
   - 3
   - Generated if the CEC pin goes from a high voltage to a low voltage.
 Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
capability set.
-* .. _`CEC-EVENT-PIN-HIGH`:
+* .. _`CEC-EVENT-PIN-CEC-HIGH`:

-  - ``CEC_EVENT_PIN_HIGH``
+  - ``CEC_EVENT_PIN_CEC_HIGH``
   - 4
   - Generated if the CEC pin goes from a low voltage to a high voltage.
 Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
diff --git a/Documentation/media/uapi/cec/cec-ioc-g-mode.rst 
b/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
index 494154e9d449..4d8e0647e832 100644
--- a/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
@@ -159,7 +159,7 @@ Available follower modes are:
This mode requires that the :ref:`CEC_CAP_MONITOR_PIN 
`
capability is set, otherwise the ``EINVAL`` error code is returned.
While in pin monitoring mode this file descriptor can receive the
-   ``CEC_EVENT_PIN_LOW`` and ``CEC_EVENT_PIN_HIGH`` events to see the
+   ``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see 
the
low-level CEC pin transitions. This is very useful for debugging.
This mode is only allowed if the process has the ``CAP_NET_ADMIN``
capability. If that is not set, then the ``EPERM`` error code is 
returned.
diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index 8ac39ddf892c..d9adeb505c09 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -154,10 +154,11 @@ static void cec_queue_event(struct cec_adapter *adap,
 }

 /* Notify userspace that the CEC pin changed state at the given time. */
-void cec_queue_pin_event(struct cec_adapter *adap, bool is_high, ktime_t ts)
+void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, ktime_t 
ts)
 {
struct cec_event ev = {
-   .event = is_high ? CEC_EVENT_PIN_HIGH : CEC_EVENT_PIN_LOW,
+   .event = is_high ? CEC_EVENT_PIN_CEC_HIGH :
+  CEC_EVENT_PIN_CEC_LOW,
};
struct cec_fh *fh;

@@ -167,7 +168,7 @@ void cec_queue_pin_event(struct cec_adapter *adap, bool 
is_high, ktime_t ts)
cec_queue_event_fh(fh, &ev, ktime_to_ns(ts));
mutex_unlock(&adap->devnode.lock);
 }
-EXPORT_SYMBOL_GPL(cec_queue_pin_event);
+EXPORT_SYMBOL_GPL(cec_queue_pin_cec_event);

 /*
  * Queue a new message for this filehandle.
diff --git a/drivers/media/cec/cec-api.c b/drivers/media/cec/cec-api.c
index 00d43d74020f..87649b0c6381 100644
--- a/drivers/media/cec/cec-api.c
+++ b/drivers/media/cec/cec-api.c
@@ -449,8 +449,8 @@ static long cec_s_mode(struct cec_adapter *adap, struct 
cec_fh *fh,
.flags = CEC_EVENT_FL_INITIAL_STATE,
};

-   ev.event = adap->pin->cur_value ? CEC_EVENT_PIN_HIGH :
- CEC_EVENT_PIN_LOW;
+   ev.event = adap->pin->cur_value ? CEC_EVENT_PIN_CEC_HIGH :
+ CEC_EVENT_PIN_CEC_LOW;
cec_queue_event_fh(fh, &ev, 0);
 #endi

[PATCH] cec: rename pin events/function

2017-08-15 Thread Hans Verkuil
The CEC_EVENT_PIN_LOW/HIGH defines and the cec_queue_pin_event() function
did not specify that these were about CEC pin events.

Since in the future there will also be HPD pin events it is wise to rename
the event defines and function to CEC_EVENT_PIN_CEC_LOW/HIGH and
cec_queue_pin_cec_event() now before these become part of the ABI.

Signed-off-by: Hans Verkuil 
---
diff --git a/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst 
b/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
index 0a7aa21f24f4..6c1f6efb822e 100644
--- a/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-adap-g-caps.rst
@@ -127,7 +127,7 @@ returns the information to the application. The ioctl never 
fails.
   - 0x0080
   - The CEC hardware can monitor CEC pin changes from low to high voltage
 and vice versa. When in pin monitoring mode the application will
-   receive ``CEC_EVENT_PIN_LOW`` and ``CEC_EVENT_PIN_HIGH`` events.
+   receive ``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events.



diff --git a/Documentation/media/uapi/cec/cec-ioc-dqevent.rst 
b/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
index 766d8b0ce431..a4a107dc4822 100644
--- a/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-dqevent.rst
@@ -148,14 +148,14 @@ it is guaranteed that the state did change in between the 
two events.
application didn't dequeue CEC messages fast enough.
 * .. _`CEC-EVENT-PIN-LOW`:

-  - ``CEC_EVENT_PIN_LOW``
+  - ``CEC_EVENT_PIN_CEC_LOW``
   - 3
   - Generated if the CEC pin goes from a high voltage to a low voltage.
 Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
capability set.
 * .. _`CEC-EVENT-PIN-HIGH`:

-  - ``CEC_EVENT_PIN_HIGH``
+  - ``CEC_EVENT_PIN_CEC_HIGH``
   - 4
   - Generated if the CEC pin goes from a low voltage to a high voltage.
 Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
diff --git a/Documentation/media/uapi/cec/cec-ioc-g-mode.rst 
b/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
index 494154e9d449..4d8e0647e832 100644
--- a/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
+++ b/Documentation/media/uapi/cec/cec-ioc-g-mode.rst
@@ -159,7 +159,7 @@ Available follower modes are:
This mode requires that the :ref:`CEC_CAP_MONITOR_PIN 
`
capability is set, otherwise the ``EINVAL`` error code is returned.
While in pin monitoring mode this file descriptor can receive the
-   ``CEC_EVENT_PIN_LOW`` and ``CEC_EVENT_PIN_HIGH`` events to see the
+   ``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see 
the
low-level CEC pin transitions. This is very useful for debugging.
This mode is only allowed if the process has the ``CAP_NET_ADMIN``
capability. If that is not set, then the ``EPERM`` error code is 
returned.
diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c
index 8ac39ddf892c..d9adeb505c09 100644
--- a/drivers/media/cec/cec-adap.c
+++ b/drivers/media/cec/cec-adap.c
@@ -154,10 +154,11 @@ static void cec_queue_event(struct cec_adapter *adap,
 }

 /* Notify userspace that the CEC pin changed state at the given time. */
-void cec_queue_pin_event(struct cec_adapter *adap, bool is_high, ktime_t ts)
+void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, ktime_t 
ts)
 {
struct cec_event ev = {
-   .event = is_high ? CEC_EVENT_PIN_HIGH : CEC_EVENT_PIN_LOW,
+   .event = is_high ? CEC_EVENT_PIN_CEC_HIGH :
+  CEC_EVENT_PIN_CEC_LOW,
};
struct cec_fh *fh;

@@ -167,7 +168,7 @@ void cec_queue_pin_event(struct cec_adapter *adap, bool 
is_high, ktime_t ts)
cec_queue_event_fh(fh, &ev, ktime_to_ns(ts));
mutex_unlock(&adap->devnode.lock);
 }
-EXPORT_SYMBOL_GPL(cec_queue_pin_event);
+EXPORT_SYMBOL_GPL(cec_queue_pin_cec_event);

 /*
  * Queue a new message for this filehandle.
diff --git a/drivers/media/cec/cec-api.c b/drivers/media/cec/cec-api.c
index 00d43d74020f..87649b0c6381 100644
--- a/drivers/media/cec/cec-api.c
+++ b/drivers/media/cec/cec-api.c
@@ -449,8 +449,8 @@ static long cec_s_mode(struct cec_adapter *adap, struct 
cec_fh *fh,
.flags = CEC_EVENT_FL_INITIAL_STATE,
};

-   ev.event = adap->pin->cur_value ? CEC_EVENT_PIN_HIGH :
- CEC_EVENT_PIN_LOW;
+   ev.event = adap->pin->cur_value ? CEC_EVENT_PIN_CEC_HIGH :
+ CEC_EVENT_PIN_CEC_LOW;
cec_queue_event_fh(fh, &ev, 0);
 #endif
adap->monitor_pin_cnt++;
diff --git a/drivers/media/cec/cec-pin.c b/drivers/media/cec/cec-pin.c
index 03f800e5ec1f..31a26d3b8bd8 100644
--- a/drivers/media/cec/cec-pin.c
+++ b/drivers/media/cec/cec-pin.c
@@ -609,8 +609,9 @@ sta

Re: [PATCH 2/2] media: ov7670: Add the s_power operation

2017-08-15 Thread Sakari Ailus
Hi Wenyou,

On Thu, Aug 10, 2017 at 05:06:45PM +0800, Wenyou Yang wrote:
> Add the s_power operation which is responsible for manipulating the
> power dowm mode through the PWDN pin and the reset operation through
> the RESET pin.
> 
> Signed-off-by: Wenyou Yang 
> ---
> 
>  drivers/media/i2c/ov7670.c | 30 +++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
> index 5c8460ee65c3..5ed79ccfaf91 100644
> --- a/drivers/media/i2c/ov7670.c
> +++ b/drivers/media/i2c/ov7670.c
> @@ -1506,6 +1506,22 @@ static int ov7670_s_register(struct v4l2_subdev *sd, 
> const struct v4l2_dbg_regis
>  }
>  #endif
>  
> +static int ov7670_s_power(struct v4l2_subdev *sd, int on)
> +{
> + struct ov7670_info *info = to_state(sd);
> +
> + if (info->pwdn_gpio)
> + gpiod_direction_output(info->pwdn_gpio, !on);

gpiod_direction_output() can cope with NULL gpio_desc.

> + if (on && info->resetb_gpio) {
> + gpiod_set_value(info->resetb_gpio, 1);
> + usleep_range(500, 1000);
> + gpiod_set_value(info->resetb_gpio, 0);
> + usleep_range(3000, 5000);
> + }
> +
> + return 0;
> +}
> +
>  /* --- */
>  
>  static const struct v4l2_subdev_core_ops ov7670_core_ops = {
> @@ -1515,6 +1531,7 @@ static const struct v4l2_subdev_core_ops 
> ov7670_core_ops = {
>   .g_register = ov7670_g_register,
>   .s_register = ov7670_s_register,
>  #endif
> + .s_power = ov7670_s_power,
>  };
>  
>  static const struct v4l2_subdev_video_ops ov7670_video_ops = {
> @@ -1568,8 +1585,6 @@ static int ov7670_init_gpio(struct i2c_client *client, 
> struct ov7670_info *info)
>   return PTR_ERR(info->resetb_gpio);
>   }
>  
> - usleep_range(3000, 5000);
> -
>   return 0;
>  }
>  
> @@ -1630,13 +1645,19 @@ static int ov7670_probe(struct i2c_client *client,
>   goto clk_disable;
>   }
>  
> + ret = ov7670_init_gpio(client, info);

ov7670_init_gpio() is already called a few lines above this. Was this
intended?

> + if (ret)
> + goto clk_disable;
> +
> + ov7670_s_power(sd, 1);
> +
>   /* Make sure it's an ov7670 */
>   ret = ov7670_detect(sd);
>   if (ret) {
>   v4l_dbg(1, debug, client,
>   "chip found @ 0x%x (%s) is not an ov7670 chip.\n",
>   client->addr << 1, client->adapter->name);
> - goto clk_disable;
> + goto power_off;
>   }
>   v4l_info(client, "chip found @ 0x%02x (%s)\n",
>   client->addr << 1, client->adapter->name);
> @@ -1708,6 +1729,8 @@ static int ov7670_probe(struct i2c_client *client,
>   media_entity_cleanup(&info->sd.entity);
>  hdl_free:
>   v4l2_ctrl_handler_free(&info->hdl);
> +power_off:
> + ov7670_s_power(sd, 0);
>  clk_disable:
>   clk_disable_unprepare(info->clk);
>   return ret;
> @@ -1723,6 +1746,7 @@ static int ov7670_remove(struct i2c_client *client)
>   v4l2_ctrl_handler_free(&info->hdl);
>   clk_disable_unprepare(info->clk);
>   media_entity_cleanup(&info->sd.entity);
> + ov7670_s_power(sd, 0);
>   return 0;
>  }
>  

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH 1/2] media: ov7670: Add entity pads initialization

2017-08-15 Thread Sakari Ailus
Hi Wenyou,

On Thu, Aug 10, 2017 at 05:06:44PM +0800, Wenyou Yang wrote:
> Add the media entity pads initialization.
> 
> Signed-off-by: Wenyou Yang 

The patch itself seems fine. However the driver is lacking support for
get_fmt which I think would be necessary for the user space API to work
properly. Without sub-device nodes it might not have been an issue with
certain master drivers.

Could you add that in v2, in a separate patch before this one, please?

> ---
> 
>  drivers/media/i2c/ov7670.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
> index e88549f0e704..5c8460ee65c3 100644
> --- a/drivers/media/i2c/ov7670.c
> +++ b/drivers/media/i2c/ov7670.c
> @@ -213,6 +213,7 @@ struct ov7670_devtype {
>  struct ov7670_format_struct;  /* coming later */
>  struct ov7670_info {
>   struct v4l2_subdev sd;
> + struct media_pad pad;
>   struct v4l2_ctrl_handler hdl;
>   struct {
>   /* gain cluster */
> @@ -1688,14 +1689,23 @@ static int ov7670_probe(struct i2c_client *client,
>   v4l2_ctrl_auto_cluster(2, &info->auto_exposure,
>  V4L2_EXPOSURE_MANUAL, false);
>   v4l2_ctrl_cluster(2, &info->saturation);
> +
> + info->pad.flags = MEDIA_PAD_FL_SOURCE;
> + info->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
> + ret = media_entity_pads_init(&info->sd.entity, 1, &info->pad);
> + if (ret < 0)
> + goto hdl_free;
> +
>   v4l2_ctrl_handler_setup(&info->hdl);
>  
>   ret = v4l2_async_register_subdev(&info->sd);
>   if (ret < 0)
> - goto hdl_free;
> + goto entity_cleanup;
>  
>   return 0;
>  
> +entity_cleanup:
> + media_entity_cleanup(&info->sd.entity);
>  hdl_free:
>   v4l2_ctrl_handler_free(&info->hdl);
>  clk_disable:
> @@ -1712,6 +1722,7 @@ static int ov7670_remove(struct i2c_client *client)
>   v4l2_device_unregister_subdev(sd);
>   v4l2_ctrl_handler_free(&info->hdl);
>   clk_disable_unprepare(info->clk);
> + media_entity_cleanup(&info->sd.entity);
>   return 0;
>  }
>  
> -- 
> 2.13.0
> 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH 1/4] v4l: async: fix unbind error in v4l2_async_notifier_unregister()

2017-08-15 Thread Sakari Ailus
On Mon, Jul 31, 2017 at 12:31:55AM +0200, Niklas Söderlund wrote:
> The call to v4l2_async_cleanup() will set sd->asd to NULL so passing it
> to notifier->unbind() have no effect and leaves the notifier confused.
> Call the unbind() callback prior to cleaning up the subdevice to avoid
> this.
> 
> Signed-off-by: Niklas Söderlund 

This is a bugfix and worthy without any other patches and so should be
applied separately.

I think it'd be safer to store sd->asd locally and call the notifier unbind
with that. Now you're making changes to the order in which things work, and
that's not necessary to achieve the objective of passing the async subdev
pointer to the notifier.

With that changed,

Acked-by: Sakari Ailus 

> ---
>  drivers/media/v4l2-core/v4l2-async.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index 851f128eba2219ad..0acf288d7227ba97 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -226,14 +226,14 @@ void v4l2_async_notifier_unregister(struct 
> v4l2_async_notifier *notifier)
>  
>   d = get_device(sd->dev);
>  
> + if (notifier->unbind)
> + notifier->unbind(notifier, sd, sd->asd);
> +
>   v4l2_async_cleanup(sd);
>  
>   /* If we handled USB devices, we'd have to lock the parent too 
> */
>   device_release_driver(d);
>  
> - if (notifier->unbind)
> - notifier->unbind(notifier, sd, sd->asd);
> -
>   /*
>* Store device at the device cache, in order to call
>* put_device() on the final step
> -- 
> 2.13.3
> 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH 4/4] v4l: async: add comment about re-probing to v4l2_async_notifier_unregister()

2017-08-15 Thread Sakari Ailus
Hi Niklas,

Thanks for the patchset.

On Mon, Jul 31, 2017 at 12:31:58AM +0200, Niklas Söderlund wrote:
> The re-probing of subdevices when unregistering a notifier is tricky to
> understand, and implemented somewhat as a hack. Add a comment trying to
> explain why the re-probing is needed in the first place and why existing
> helper functions can't be used in this situation.
> 
> Signed-off-by: Niklas Söderlund 
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index d91ff0a33fd3eaff..a3c5a1f6d4d2ab03 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -234,6 +234,23 @@ void v4l2_async_notifier_unregister(struct 
> v4l2_async_notifier *notifier)
>  
>   mutex_unlock(&list_lock);
>  
> + /*
> +  * Try to re-probe the subdevices which where part of the notifier.
> +  * This is done so subdevices which where part of the notifier will
> +  * be re-probed to a pristine state and put back on the global
> +  * list of subdevices so they can once more be found and associated
> +  * with a new notifier.

Instead of tweaking the code trying to handle unhandleable error conditions
in notifier unregistration and adding lengthy stories on why this is done
the way it is, could we simply get rid of the driver re-probing?

I can't see why drivers shouldn't simply cope with the current interfaces
without re-probing to which I've never seen any reasoned cause. When a
sub-device driver is unbound, simply return the sub-device node to the list
of async sub-devices.

Or can someone come up with a valid reason why the re-probing code should
stay? :-)

> +  *
> +  * One might be tempted to use device_reprobe() to handle the re-
> +  * probing. Unfortunately this is not possible since some video
> +  * device drivers call v4l2_async_notifier_unregister() from
> +  * there remove function leading to a dead lock situation on
> +  * device_lock(dev->parent). This lock is held when video device
> +  * drivers remove function is called and device_reprobe() also
> +  * tries to take the same lock, so using it here could lead to a
> +  * dead lock situation.
> +  */
> +
>   for (i = 0; i < count; i++) {
>   /* If we handled USB devices, we'd have to lock the parent too 
> */
>   device_release_driver(dev[i]);

-- 
Regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH 2/3] [media] rc: constify usb_device_id

2017-08-15 Thread Sean Young
On Sun, Aug 13, 2017 at 02:24:44PM +0530, Arvind Yadav wrote:
> usb_device_id are not supposed to change at runtime. All functions
> working with usb_device_id provided by  work with
> const usb_device_id. So mark the non-const structs as const.
> 
> Signed-off-by: Arvind Yadav 

Acked-by: Sean Young 

Thanks for spotting that.

Sean

> ---
>  drivers/media/rc/ati_remote.c  | 2 +-
>  drivers/media/rc/igorplugusb.c | 2 +-
>  drivers/media/rc/imon.c| 2 +-
>  drivers/media/rc/mceusb.c  | 2 +-
>  drivers/media/rc/redrat3.c | 2 +-
>  drivers/media/rc/streamzap.c   | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/rc/ati_remote.c b/drivers/media/rc/ati_remote.c
> index a4c6ad4..d1d0c48 100644
> --- a/drivers/media/rc/ati_remote.c
> +++ b/drivers/media/rc/ati_remote.c
> @@ -198,7 +198,7 @@ static const struct ati_receiver_type type_firefly
> = {
>   .default_keymap = RC_MAP_SNAPSTREAM_FIREFLY
>  };
>  
> -static struct usb_device_id ati_remote_table[] = {
> +static const struct usb_device_id ati_remote_table[] = {
>   {
>   USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),
>   .driver_info = (unsigned long)&type_ati
> diff --git a/drivers/media/rc/igorplugusb.c b/drivers/media/rc/igorplugusb.c
> index cb6d4f1..c294ec5 100644
> --- a/drivers/media/rc/igorplugusb.c
> +++ b/drivers/media/rc/igorplugusb.c
> @@ -244,7 +244,7 @@ static void igorplugusb_disconnect(struct usb_interface 
> *intf)
>   usb_free_urb(ir->urb);
>  }
>  
> -static struct usb_device_id igorplugusb_table[] = {
> +static const struct usb_device_id igorplugusb_table[] = {
>   /* Igor Plug USB (Atmel's Manufact. ID) */
>   { USB_DEVICE(0x03eb, 0x0002) },
>   /* Fit PC2 Infrared Adapter */
> diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
> index bd76534..3f414ab 100644
> --- a/drivers/media/rc/imon.c
> +++ b/drivers/media/rc/imon.c
> @@ -346,7 +346,7 @@ static const struct imon_usb_dev_descr imon_ir_raw = {
>   * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
>   * the ffdc and later devices, which do onboard decoding.
>   */
> -static struct usb_device_id imon_usb_id_table[] = {
> +static const struct usb_device_id imon_usb_id_table[] = {
>   /*
>* Several devices with this same device ID, all use iMON_PAD.inf
>* SoundGraph iMON PAD (IR & VFD)
> diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
> index eb13069..6664d91 100644
> --- a/drivers/media/rc/mceusb.c
> +++ b/drivers/media/rc/mceusb.c
> @@ -249,7 +249,7 @@ static const struct mceusb_model mceusb_model[] = {
>   },
>  };
>  
> -static struct usb_device_id mceusb_dev_table[] = {
> +static const struct usb_device_id mceusb_dev_table[] = {
>   /* Original Microsoft MCE IR Transceiver (often HP-branded) */
>   { USB_DEVICE(VENDOR_MICROSOFT, 0x006d),
> .driver_info = MCE_GEN1 },
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
> index 56d43be..48f27ac 100644
> --- a/drivers/media/rc/redrat3.c
> +++ b/drivers/media/rc/redrat3.c
> @@ -186,7 +186,7 @@ struct redrat3_error {
>  } __packed;
>  
>  /* table of devices that work with this driver */
> -static struct usb_device_id redrat3_dev_table[] = {
> +static const struct usb_device_id redrat3_dev_table[] = {
>   /* Original version of the RedRat3 */
>   {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3USB_PRODUCT_ID)},
>   /* Second Version/release of the RedRat3 - RetRat3-II */
> diff --git a/drivers/media/rc/streamzap.c b/drivers/media/rc/streamzap.c
> index b09c45a..1f00727 100644
> --- a/drivers/media/rc/streamzap.c
> +++ b/drivers/media/rc/streamzap.c
> @@ -43,7 +43,7 @@
>  #define USB_STREAMZAP_PRODUCT_ID 0x
>  
>  /* table of devices that work with this driver */
> -static struct usb_device_id streamzap_table[] = {
> +static const struct usb_device_id streamzap_table[] = {
>   /* Streamzap Remote Control */
>   { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
>   /* Terminating entry */
> -- 
> 2.7.4


Re: [PATCH 1/3] [media] coda: constify platform_device_id

2017-08-15 Thread Philipp Zabel
On Tue, 2017-08-15 at 16:53 +0530, Arvind Yadav wrote:
> platform_device_id are not supposed to change at runtime. All
> functions
> working with platform_device_id provided by 
> work with const platform_device_id. So mark the non-const structs as
> const.
> 
> Signed-off-by: Arvind Yadav 

Acked-by: Philipp Zabel 

thanks
Philipp



Re: [GIT PULL] linux-firmware: intel: Add Kabylake IPU3 firmware

2017-08-15 Thread Tomasz Figa
Hi everyone,

On Sat, Aug 5, 2017 at 9:04 AM, Mani, Rajmohan  wrote:
> Hi,
>
> Please review this PULL request to add Kabylake IPU3 firmware to the 
> linux-firmware repository.
>
>
> The following changes since commit 7d2c913dcd1be083350d97a8cb1eba24cfacbc8a:
>
>   ath10k: update year in license (2017-06-22 12:06:02 -0700)
>
> are available in the git repository at:
>
>   https://github.com/RajmohanMani/linux-firmware.git tags/v1
>
> for you to fetch changes up to 2c27b0cb02f18c022d8378e0e1abaf8b7ae8188f:
>
>   linux-firmware: intel: Add Kabylake IPU3 firmware (2017-08-04 15:53:13 
> -0700)
>
> 
> IPU3 firmware version irci_irci_ecr-master_20161208_0213_20170112_1500
>
> 
> Rajmohan Mani (1):
>   linux-firmware: intel: Add Kabylake IPU3 firmware
>
>  LICENSE.ipu3_firmware  |  36 
> 
>  WHENCE |  11 +++
>  intel/ipu3-fw.bin  |   1 +
>  intel/irci_irci_ecr-master_20161208_0213_20170112_1500.bin | Bin 0 -> 
> 1212984 bytes
>  4 files changed, 48 insertions(+)
>  create mode 100644 LICENSE.ipu3_firmware
>  create mode 12 intel/ipu3-fw.bin
>  create mode 100644 intel/irci_irci_ecr-master_20161208_0213_20170112_1500.bin

A gentle ping. Perhaps any issue with this pull request?

Best regards,
Tomasz


[PATCH v3.2 2/3] v4l2-flash-led-class: Create separate sub-devices for indicators

2017-08-15 Thread Sakari Ailus
The V4L2 flash interface allows controlling multiple LEDs through a single
sub-devices if, and only if, these LEDs are of different types. This
approach scales badly for flash controllers that drive multiple flash LEDs
or for LED specific associations. Essentially, the original assumption of a
LED driver chip that drives a single flash LED and an indicator LED is no
longer valid.

Address the matter by registering one sub-device per LED.

Signed-off-by: Sakari Ailus 
Reviewed-by: Jacek Anaszewski 
Acked-by: Pavel Machek 
Reviewed-by: Rui Miguel Silva  (for greybus/light)
Acked-by: Hans Verkuil 
---
since v3.2:

- Fix a hastily made fix, one semicolon removed.

 drivers/leds/leds-aat1290.c|   4 +-
 drivers/leds/leds-max77693.c   |   4 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++--
 drivers/staging/greybus/light.c|  23 +++--
 include/media/v4l2-flash-led-class.h   |  40 ++---
 5 files changed, 117 insertions(+), 67 deletions(-)

diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
index a21e19297745..424898e6c69d 100644
--- a/drivers/leds/leds-aat1290.c
+++ b/drivers/leds/leds-aat1290.c
@@ -432,7 +432,7 @@ static void aat1290_init_v4l2_flash_config(struct 
aat1290_led *led,
strlcpy(v4l2_sd_cfg->dev_name, led_cdev->name,
sizeof(v4l2_sd_cfg->dev_name));
 
-   s = &v4l2_sd_cfg->torch_intensity;
+   s = &v4l2_sd_cfg->intensity;
s->min = led->mm_current_scale[0];
s->max = led_cfg->max_mm_current;
s->step = 1;
@@ -504,7 +504,7 @@ static int aat1290_led_probe(struct platform_device *pdev)
 
/* Create V4L2 Flash subdev. */
led->v4l2_flash = v4l2_flash_init(dev, of_fwnode_handle(sub_node),
- fled_cdev, NULL, &v4l2_flash_ops,
+ fled_cdev, &v4l2_flash_ops,
  &v4l2_sd_cfg);
if (IS_ERR(led->v4l2_flash)) {
ret = PTR_ERR(led->v4l2_flash);
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
index 2d3062d53325..adf0f191f794 100644
--- a/drivers/leds/leds-max77693.c
+++ b/drivers/leds/leds-max77693.c
@@ -856,7 +856,7 @@ static void max77693_init_v4l2_flash_config(struct 
max77693_sub_led *sub_led,
 "%s %d-%04x", sub_led->fled_cdev.led_cdev.name,
 i2c_adapter_id(i2c->adapter), i2c->addr);
 
-   s = &v4l2_sd_cfg->torch_intensity;
+   s = &v4l2_sd_cfg->intensity;
s->min = TORCH_IOUT_MIN;
s->max = sub_led->fled_cdev.led_cdev.max_brightness * TORCH_IOUT_STEP;
s->step = TORCH_IOUT_STEP;
@@ -931,7 +931,7 @@ static int max77693_register_led(struct max77693_sub_led 
*sub_led,
 
/* Register in the V4L2 subsystem. */
sub_led->v4l2_flash = v4l2_flash_init(dev, of_fwnode_handle(sub_node),
- fled_cdev, NULL, &v4l2_flash_ops,
+ fled_cdev, &v4l2_flash_ops,
  &v4l2_sd_cfg);
if (IS_ERR(sub_led->v4l2_flash)) {
ret = PTR_ERR(sub_led->v4l2_flash);
diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c 
b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index aabc85dbb8b5..4ceef217de83 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -197,7 +197,7 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
 {
struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
-   struct led_classdev *led_cdev = &fled_cdev->led_cdev;
+   struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL;
struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
bool external_strobe;
int ret = 0;
@@ -299,10 +299,26 @@ static void __fill_ctrl_init_data(struct v4l2_flash 
*v4l2_flash,
  struct v4l2_flash_ctrl_data *ctrl_init_data)
 {
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
-   struct led_classdev *led_cdev = &fled_cdev->led_cdev;
+   struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL;
struct v4l2_ctrl_config *ctrl_cfg;
u32 mask;
 
+   /* Init INDICATOR_INTENSITY ctrl data */
+   if (v4l2_flash->iled_cdev) {
+   ctrl_init_data[INDICATOR_INTENSITY].cid =
+   V4L2_CID_FLASH_INDICATOR_INTENSITY;
+   ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY].config;
+   __lfs_to_v4l2_ctrl_config(&flash_cfg->intensity,
+ ctrl_cfg);
+   ctrl_cfg->id = V4L2_CID_FLASH_INDICATOR_INTENSITY;
+   ctrl_cfg->min = 0;
+   ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE |
+   

[PATCH 3/3] [media] omap3isp: constify platform_device_id

2017-08-15 Thread Arvind Yadav
platform_device_id are not supposed to change at runtime. All functions
working with platform_device_id provided by 
work with const platform_device_id. So mark the non-const structs as
const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/platform/omap3isp/isp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/omap3isp/isp.c 
b/drivers/media/platform/omap3isp/isp.c
index 9df64c1..ddb2cf5 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -2373,7 +2373,7 @@ static const struct dev_pm_ops omap3isp_pm_ops = {
.complete = isp_pm_complete,
 };
 
-static struct platform_device_id omap3isp_id_table[] = {
+static const struct platform_device_id omap3isp_id_table[] = {
{ "omap3isp", 0 },
{ },
 };
-- 
2.7.4



[PATCH 1/3] [media] coda: constify platform_device_id

2017-08-15 Thread Arvind Yadav
platform_device_id are not supposed to change at runtime. All functions
working with platform_device_id provided by 
work with const platform_device_id. So mark the non-const structs as
const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/platform/coda/coda-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda/coda-common.c 
b/drivers/media/platform/coda/coda-common.c
index f92cc7d..530c937 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -2390,7 +2390,7 @@ static const struct coda_devtype coda_devdata[] = {
},
 };
 
-static struct platform_device_id coda_platform_ids[] = {
+static const struct platform_device_id coda_platform_ids[] = {
{ .name = "coda-imx27", .driver_data = CODA_IMX27 },
{ /* sentinel */ }
 };
-- 
2.7.4



[PATCH 2/3] [media] davinci: constify platform_device_id

2017-08-15 Thread Arvind Yadav
platform_device_id are not supposed to change at runtime. All functions
working with platform_device_id provided by 
work with const platform_device_id. So mark the non-const structs as
const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/platform/davinci/vpbe_osd.c  | 2 +-
 drivers/media/platform/davinci/vpbe_venc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_osd.c 
b/drivers/media/platform/davinci/vpbe_osd.c
index df042e8..6644979 100644
--- a/drivers/media/platform/davinci/vpbe_osd.c
+++ b/drivers/media/platform/davinci/vpbe_osd.c
@@ -37,7 +37,7 @@
 
 #define MODULE_NAME"davinci-vpbe-osd"
 
-static struct platform_device_id vpbe_osd_devtype[] = {
+static const struct platform_device_id vpbe_osd_devtype[] = {
{
.name = DM644X_VPBE_OSD_SUBDEV_NAME,
.driver_data = VPBE_VERSION_1,
diff --git a/drivers/media/platform/davinci/vpbe_venc.c 
b/drivers/media/platform/davinci/vpbe_venc.c
index 8bfe90a..3a4e785 100644
--- a/drivers/media/platform/davinci/vpbe_venc.c
+++ b/drivers/media/platform/davinci/vpbe_venc.c
@@ -36,7 +36,7 @@
 
 #define MODULE_NAME"davinci-vpbe-venc"
 
-static struct platform_device_id vpbe_venc_devtype[] = {
+static const struct platform_device_id vpbe_venc_devtype[] = {
{
.name = DM644X_VPBE_VENC_SUBDEV_NAME,
.driver_data = VPBE_VERSION_1,
-- 
2.7.4



Re: [RFC 04/19] dt: bindings: Add lens-focus binding for image sensors

2017-08-15 Thread Sakari Ailus
Hi Hans,

On Fri, Jul 28, 2017 at 10:53:35AM +0200, Hans Verkuil wrote:
> Hi Sakari,
> 
> Is the lens-focus phandle specific to voice-coil controllers? What about

I think it's not important. Right now the information is used for making
the association only.

> motor-controlled focus systems? What when there are multiple motors? E.g.
> one for the focus, one for the iris control (yes, we have that).

I'd add another property for this purpose.

> 
> What if you have two sensors (stereoscopic) controlled by one motor?

You can refer to the same controller from both, I don't see a problem with
that. The software would need to support that though, I think changes to
the async framework would be needed.

> 
> Just trying to understand this from a bigger perspective. Specifically
> how this will scale when more of these supporting devices as added.
> 
> Regards,
> 
>   Hans
> 
> On 07/18/2017 09:03 PM, Sakari Ailus wrote:
> > The lens-focus property contains a phandle to the lens voice coil driver
> > that is associated to the sensor; typically both are contained in the same
> > camera module.
> > 
> > Signed-off-by: Sakari Ailus 
> > Acked-by: Pavel Machek 
> > Reviewed-by: Sebastian Reichel 
> > Acked-by: Rob Herring 
> > ---
> >  Documentation/devicetree/bindings/media/video-interfaces.txt | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/media/video-interfaces.txt 
> > b/Documentation/devicetree/bindings/media/video-interfaces.txt
> > index 9723f7e1c7db..a18d9b2d309f 100644
> > --- a/Documentation/devicetree/bindings/media/video-interfaces.txt
> > +++ b/Documentation/devicetree/bindings/media/video-interfaces.txt
> > @@ -74,6 +74,8 @@ Optional properties
> >  - flash: phandle referring to the flash driver chip. A flash driver may
> >have multiple flashes connected to it.
> >  
> > +- lens-focus: A phandle to the node of the focus lens controller.
> > +
> >  
> >  Optional endpoint properties
> >  
> > 
> 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


[PATCH 0/3] constify media platform_device_id

2017-08-15 Thread Arvind Yadav
platform_device_id are not supposed to change at runtime. All functions
working with platform_device_id provided by 
work with const platform_device_id. So mark the non-const structs as const.

Arvind Yadav (3):
  [PATCH 1/3] [media] coda: constify platform_device_id
  [PATCH 2/3] [media] davinci: constify platform_device_id
  [PATCH 3/3] [media] omap3isp: constify platform_device_id

 drivers/media/platform/coda/coda-common.c  | 2 +-
 drivers/media/platform/davinci/vpbe_osd.c  | 2 +-
 drivers/media/platform/davinci/vpbe_venc.c | 2 +-
 drivers/media/platform/omap3isp/isp.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.7.4



[PATCH] uvcvideo: Apply flags from device to actual properties

2017-08-15 Thread Edgar Thier
Use flags the device exposes for UVC controls.

Signed-off-by: Edgar Thier 
---
 drivers/media/usb/uvc/uvc_ctrl.c | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index c2ee6e3..bc69e92 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1568,7 +1568,8 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
return ret;
}

-   ctrl->loaded = 1;
+   if (!(ctrl->info.flags && UVC_CTRL_FLAG_AUTO_UPDATE))
+   ctrl->loaded = 1;
}

/* Backup the current value in case we need to rollback later. */
@@ -1889,8 +1890,13 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)
 static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl,
const struct uvc_control_info *info)
 {
+   u8 *data;
int ret = 0;

+   data = kmalloc(2, GFP_KERNEL);
+   if (data == NULL)
+   return -ENOMEM;
+
ctrl->info = *info;
INIT_LIST_HEAD(&ctrl->info.mappings);

@@ -1904,6 +1910,23 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, 
struct uvc_control *ctrl,

ctrl->initialized = 1;

+   ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum,
+ info->selector, data, 1);
+   if (ret < 0) {
+   uvc_trace(UVC_TRACE_CONTROL,
+ "GET_INFO failed on control %pUl/%u (%d).\n",
+ info->entity, info->selector, ret);
+   }
+   else {
+   ctrl->info.flags = UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX
+   | UVC_CTRL_FLAG_GET_RES | UVC_CTRL_FLAG_GET_DEF
+   | (data[0] & UVC_CONTROL_CAP_GET ?
+  UVC_CTRL_FLAG_GET_CUR : 0)
+   | (data[0] & UVC_CONTROL_CAP_SET ?
+  UVC_CTRL_FLAG_SET_CUR : 0)
+   | (data[0] & UVC_CONTROL_CAP_AUTOUPDATE ?
+  UVC_CTRL_FLAG_AUTO_UPDATE : 0);
+   }
uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s "
"entity %u\n", ctrl->info.entity, ctrl->info.selector,
dev->udev->devpath, ctrl->entity->id);
@@ -1911,6 +1934,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, 
struct uvc_control *ctrl,
 done:
if (ret < 0)
kfree(ctrl->uvc_data);
+   kfree(data);
return ret;
 }

-- 
2.7.4



[GIT PULL v2 for 4.14] Flash LED class improvements

2017-08-15 Thread Sakari Ailus
Hi Mauro,

Here is greybus flash memory leak fix as well as V4L2 flash class change
for making the interface more logical by creating a sub-device per LED.

since v1: Fix arguments in nop implementation of v4l2_flash_init().

Please pull.


The following changes since commit ec0c3ec497cabbf3bfa03a9eb5edcc252190a4e0:

  media: ddbridge: split code into multiple files (2017-08-09 12:17:01 -0400)

are available in the git repository at:

  ssh://linuxtv.org/git/sailus/media_tree.git flash

for you to fetch changes up to f91e3cfb56025111d83d9d86a7024acc3a692c39:

  v4l2-flash-led-class: Document v4l2_flash_init() references (2017-08-15 
13:38:02 +0300)


Rui Miguel Silva (1):
  staging: greybus: light: fix memory leak in v4l2 register

Sakari Ailus (2):
  v4l2-flash-led-class: Create separate sub-devices for indicators
  v4l2-flash-led-class: Document v4l2_flash_init() references

 drivers/leds/leds-aat1290.c|   4 +-
 drivers/leds/leds-max77693.c   |   4 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++--
 drivers/staging/greybus/light.c|  42 -
 include/media/v4l2-flash-led-class.h   |  46 +++---
 5 files changed, 127 insertions(+), 82 deletions(-)


-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


[PATCH v3.1 2/3] v4l2-flash-led-class: Create separate sub-devices for indicators

2017-08-15 Thread Sakari Ailus
The V4L2 flash interface allows controlling multiple LEDs through a single
sub-devices if, and only if, these LEDs are of different types. This
approach scales badly for flash controllers that drive multiple flash LEDs
or for LED specific associations. Essentially, the original assumption of a
LED driver chip that drives a single flash LED and an indicator LED is no
longer valid.

Address the matter by registering one sub-device per LED.

Signed-off-by: Sakari Ailus 
Reviewed-by: Jacek Anaszewski 
Acked-by: Pavel Machek 
Reviewed-by: Rui Miguel Silva  (for greybus/light)
Acked-by: Hans Verkuil 
---
since v3:

- Fix v4l2_flash_init() static inline function arguments used when the V4L2
  flash LED class is disabled; they were different from the real one.

 drivers/leds/leds-aat1290.c|   4 +-
 drivers/leds/leds-max77693.c   |   4 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++--
 drivers/staging/greybus/light.c|  23 +++--
 include/media/v4l2-flash-led-class.h   |  40 ++---
 5 files changed, 117 insertions(+), 67 deletions(-)

diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
index a21e19297745..424898e6c69d 100644
--- a/drivers/leds/leds-aat1290.c
+++ b/drivers/leds/leds-aat1290.c
@@ -432,7 +432,7 @@ static void aat1290_init_v4l2_flash_config(struct 
aat1290_led *led,
strlcpy(v4l2_sd_cfg->dev_name, led_cdev->name,
sizeof(v4l2_sd_cfg->dev_name));
 
-   s = &v4l2_sd_cfg->torch_intensity;
+   s = &v4l2_sd_cfg->intensity;
s->min = led->mm_current_scale[0];
s->max = led_cfg->max_mm_current;
s->step = 1;
@@ -504,7 +504,7 @@ static int aat1290_led_probe(struct platform_device *pdev)
 
/* Create V4L2 Flash subdev. */
led->v4l2_flash = v4l2_flash_init(dev, of_fwnode_handle(sub_node),
- fled_cdev, NULL, &v4l2_flash_ops,
+ fled_cdev, &v4l2_flash_ops,
  &v4l2_sd_cfg);
if (IS_ERR(led->v4l2_flash)) {
ret = PTR_ERR(led->v4l2_flash);
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
index 2d3062d53325..adf0f191f794 100644
--- a/drivers/leds/leds-max77693.c
+++ b/drivers/leds/leds-max77693.c
@@ -856,7 +856,7 @@ static void max77693_init_v4l2_flash_config(struct 
max77693_sub_led *sub_led,
 "%s %d-%04x", sub_led->fled_cdev.led_cdev.name,
 i2c_adapter_id(i2c->adapter), i2c->addr);
 
-   s = &v4l2_sd_cfg->torch_intensity;
+   s = &v4l2_sd_cfg->intensity;
s->min = TORCH_IOUT_MIN;
s->max = sub_led->fled_cdev.led_cdev.max_brightness * TORCH_IOUT_STEP;
s->step = TORCH_IOUT_STEP;
@@ -931,7 +931,7 @@ static int max77693_register_led(struct max77693_sub_led 
*sub_led,
 
/* Register in the V4L2 subsystem. */
sub_led->v4l2_flash = v4l2_flash_init(dev, of_fwnode_handle(sub_node),
- fled_cdev, NULL, &v4l2_flash_ops,
+ fled_cdev, &v4l2_flash_ops,
  &v4l2_sd_cfg);
if (IS_ERR(sub_led->v4l2_flash)) {
ret = PTR_ERR(sub_led->v4l2_flash);
diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c 
b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index aabc85dbb8b5..4ceef217de83 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -197,7 +197,7 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
 {
struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
-   struct led_classdev *led_cdev = &fled_cdev->led_cdev;
+   struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL;
struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
bool external_strobe;
int ret = 0;
@@ -299,10 +299,26 @@ static void __fill_ctrl_init_data(struct v4l2_flash 
*v4l2_flash,
  struct v4l2_flash_ctrl_data *ctrl_init_data)
 {
struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
-   struct led_classdev *led_cdev = &fled_cdev->led_cdev;
+   struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL;
struct v4l2_ctrl_config *ctrl_cfg;
u32 mask;
 
+   /* Init INDICATOR_INTENSITY ctrl data */
+   if (v4l2_flash->iled_cdev) {
+   ctrl_init_data[INDICATOR_INTENSITY].cid =
+   V4L2_CID_FLASH_INDICATOR_INTENSITY;
+   ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY].config;
+   __lfs_to_v4l2_ctrl_config(&flash_cfg->intensity,
+ ctrl_cfg);
+   ctrl_cfg->id = V4L2_CID_FLASH_INDICATOR_INTENSITY;
+   ctrl_cfg->mi

Re: [RFC PATCH] media: vb2: add bidirectional flag in vb2_queue

2017-08-15 Thread Hans Verkuil
On 08/14/17 10:41, Stanimir Varbanov wrote:
> Hi,
> 
> This RFC patch is intended to give to the drivers a choice to change
> the default behavior of the v4l2-core DMA mapping direction from
> DMA_TO/FROM_DEVICE (depending on the buffer type CAPTURE or OUTPUT)
> to DMA_BIDIRECTIONAL during queue_init time.
> 
> Initially the issue with DMA mapping direction has been found in
> Venus encoder driver where the firmware side of the driver adds few
> lines padding on bottom of the image buffer, and the consequence was
> triggering of IOMMU protection faults. 
> 
> Probably other drivers could also has a benefit of this feature (hint)
> in the future.
> 
> Signed-off-by: Stanimir Varbanov 
> ---
>  drivers/media/v4l2-core/videobuf2-core.c |  3 +++
>  include/media/videobuf2-core.h   | 11 +++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
> b/drivers/media/v4l2-core/videobuf2-core.c
> index 14f83cecfa92..17d07fda4cdc 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -200,6 +200,9 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
>   int plane;
>   int ret = -ENOMEM;
>  
> + if (q->bidirectional)
> + dma_dir = DMA_BIDIRECTIONAL;
> +

Does this only have to be used in mem_alloc? In the __prepare_*() it is still 
using
DMA_TO/FROM_DEVICE.

I don't know enough of the low-level handling to be able to tell whether that is
a problem or not, but even if it is not then a comment somewhere to explain that
it is OK is probably a good idea.

Regards,

Hans

>   /*
>* Allocate memory for all planes in this buffer
>* NOTE: mmapped areas should be page aligned
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index cb97c224be73..0b6e88e1aa79 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -427,6 +427,16 @@ struct vb2_buf_ops {
>   * @dev: device to use for the default allocation context if the driver
>   *   doesn't fill in the @alloc_devs array.
>   * @dma_attrs:   DMA attributes to use for the DMA.
> + * @bidirectional: when this flag is set the DMA direction for the buffers of
> + *   this queue will be overridden with DMA_BIDIRECTIONAL direction.
> + *   This is useful in cases where the hardware (firmware) writes to
> + *   a buffer which is mapped as read (DMA_TO_DEVICE), or reads from
> + *   buffer which is mapped for write (DMA_FROM_DEVICE) in order
> + *   to satisfy some internal hardware restrictions or adds a padding
> + *   needed by the processing algorithm. In case the DMA mapping is
> + *   not bidirectional but the hardware (firmware) trying to access
> + *   the buffer (in the opposite direction) this could lead to an
> + *   IOMMU protection faults.
>   * @fileio_read_once:report EOF after reading the first 
> buffer
>   * @fileio_write_immediately:queue buffer after each write() call
>   * @allow_zero_bytesused:allow bytesused == 0 to be passed to the driver
> @@ -495,6 +505,7 @@ struct vb2_queue {
>   unsigned intio_modes;
>   struct device   *dev;
>   unsigned long   dma_attrs;
> + unsignedbidirectional:1;
>   unsignedfileio_read_once:1;
>   unsignedfileio_write_immediately:1;
>   unsignedallow_zero_bytesused:1;
> 



[GIT PULL for 4.14] Flash LED class improvements

2017-08-15 Thread Sakari Ailus
Hi Mauro,

Here is greybus flash memory leak fix as well as V4L2 flash class change
for making the interface more logical by creating a sub-device per LED.

Please pull.


The following changes since commit ec0c3ec497cabbf3bfa03a9eb5edcc252190a4e0:

  media: ddbridge: split code into multiple files (2017-08-09 12:17:01 -0400)

are available in the git repository at:

  ssh://linuxtv.org/git/sailus/media_tree.git flash

for you to fetch changes up to c7b3e4618d02b9fe5821cd42a47cd325e85c7e4b:

  v4l2-flash-led-class: Document v4l2_flash_init() references (2017-08-10 
18:43:36 +0300)


Rui Miguel Silva (1):
  staging: greybus: light: fix memory leak in v4l2 register

Sakari Ailus (2):
  v4l2-flash-led-class: Create separate sub-devices for indicators
  v4l2-flash-led-class: Document v4l2_flash_init() references

 drivers/leds/leds-aat1290.c|   4 +-
 drivers/leds/leds-max77693.c   |   4 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++--
 drivers/staging/greybus/light.c|  42 -
 include/media/v4l2-flash-led-class.h   |  47 +++---
 5 files changed, 127 insertions(+), 83 deletions(-)

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [RFC PATCH] media: vb2: add bidirectional flag in vb2_queue

2017-08-15 Thread Sakari Ailus
On Mon, Aug 14, 2017 at 11:41:55AM +0300, Stanimir Varbanov wrote:
> Hi,
> 
> This RFC patch is intended to give to the drivers a choice to change
> the default behavior of the v4l2-core DMA mapping direction from
> DMA_TO/FROM_DEVICE (depending on the buffer type CAPTURE or OUTPUT)
> to DMA_BIDIRECTIONAL during queue_init time.
> 
> Initially the issue with DMA mapping direction has been found in
> Venus encoder driver where the firmware side of the driver adds few
> lines padding on bottom of the image buffer, and the consequence was
> triggering of IOMMU protection faults. 
> 
> Probably other drivers could also has a benefit of this feature (hint)
> in the future.
> 
> Signed-off-by: Stanimir Varbanov 

Acked-by: Sakari Ailus 

> ---
>  drivers/media/v4l2-core/videobuf2-core.c |  3 +++
>  include/media/videobuf2-core.h   | 11 +++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
> b/drivers/media/v4l2-core/videobuf2-core.c
> index 14f83cecfa92..17d07fda4cdc 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -200,6 +200,9 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
>   int plane;
>   int ret = -ENOMEM;
>  
> + if (q->bidirectional)
> + dma_dir = DMA_BIDIRECTIONAL;
> +
>   /*
>* Allocate memory for all planes in this buffer
>* NOTE: mmapped areas should be page aligned
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index cb97c224be73..0b6e88e1aa79 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -427,6 +427,16 @@ struct vb2_buf_ops {
>   * @dev: device to use for the default allocation context if the driver
>   *   doesn't fill in the @alloc_devs array.
>   * @dma_attrs:   DMA attributes to use for the DMA.
> + * @bidirectional: when this flag is set the DMA direction for the buffers of
> + *   this queue will be overridden with DMA_BIDIRECTIONAL direction.
> + *   This is useful in cases where the hardware (firmware) writes to
> + *   a buffer which is mapped as read (DMA_TO_DEVICE), or reads from
> + *   buffer which is mapped for write (DMA_FROM_DEVICE) in order
> + *   to satisfy some internal hardware restrictions or adds a padding
> + *   needed by the processing algorithm. In case the DMA mapping is
> + *   not bidirectional but the hardware (firmware) trying to access
> + *   the buffer (in the opposite direction) this could lead to an
> + *   IOMMU protection faults.
>   * @fileio_read_once:report EOF after reading the first 
> buffer
>   * @fileio_write_immediately:queue buffer after each write() call
>   * @allow_zero_bytesused:allow bytesused == 0 to be passed to the driver
> @@ -495,6 +505,7 @@ struct vb2_queue {
>   unsigned intio_modes;
>   struct device   *dev;
>   unsigned long   dma_attrs;
> + unsignedbidirectional:1;
>   unsignedfileio_read_once:1;
>   unsignedfileio_write_immediately:1;
>   unsignedallow_zero_bytesused:1;
> -- 
> 2.11.0
> 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi