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

2017-08-27 Thread Mauro Carvalho Chehab
Em Wed, 16 Aug 2017 13:41:42 +0900
 escreveu:

> From: Yasunari Takiguchi 
> 
> Provide monitor and integration layer functions (DVB-T)
> for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.
> 
> [Change list]
> Changes in V3
>drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
>   -changed CXD2880_SLEEP to usleep_range
>   -chnaged cxd2880_atomic_set to atomic_set
>   -modified return code
>   -modified coding style of if() 
>drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
>   -modified return code
>drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
>   -removed unnecessary cast
>   -changed cxd2880_math_log to intlog10
>   -changed hexadecimal code to lower case. 
>drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
>   -modified return code
> 
> Signed-off-by: Yasunari Takiguchi 
> Signed-off-by: Masayuki Yamamoto 
> Signed-off-by: Hideki Nozawa 
> Signed-off-by: Kota Yonezawa 
> Signed-off-by: Toshihiko Matsumoto 
> Signed-off-by: Satoshi Watanabe 
> ---
>  .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.c |  198 
>  .../dvb-frontends/cxd2880/cxd2880_integ_dvbt.h |   58 +
>  .../cxd2880/cxd2880_tnrdmd_dvbt_mon.c  | 1227 
> 
>  .../cxd2880/cxd2880_tnrdmd_dvbt_mon.h  |  106 ++
>  4 files changed, 1589 insertions(+)
>  create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
>  create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.h
>  create mode 100644 
> drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.c
>  create mode 100644 
> drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_dvbt_mon.h
> 
> diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c 
> b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
> new file mode 100644
> index ..729cb0939203
> --- /dev/null
> +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_integ_dvbt.c
> @@ -0,0 +1,198 @@
> +/*
> + * cxd2880_integ_dvbt.c
> + * Sony CXD2880 DVB-T2/T tuner + demodulator driver
> + * integration layer functions for DVB-T
> + *
> + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; version 2 of the License.
> + *
> + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
> + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
> + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
> + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
> + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see .
> + */
> +
> +#include "cxd2880_tnrdmd_dvbt.h"
> +#include "cxd2880_integ_dvbt.h"
> +
> +static int dvbt_wait_demod_lock(struct cxd2880_tnrdmd *tnr_dmd);
> +
> +int cxd2880_integ_dvbt_tune(struct cxd2880_tnrdmd *tnr_dmd,
> + struct cxd2880_dvbt_tune_param
> + *tune_param)
> +{
> + int ret = 0;
> +
> + if ((!tnr_dmd) || (!tune_param))
> + return -EINVAL;
> +
> + if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
> + return -EINVAL;
> +
> + if ((tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP) &&
> + (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE))
> + return -EPERM;
> +
> + atomic_set(_dmd->cancel, 0);
> +
> + if ((tune_param->bandwidth != CXD2880_DTV_BW_5_MHZ) &&
> + (tune_param->bandwidth != CXD2880_DTV_BW_6_MHZ) &&
> + (tune_param->bandwidth != CXD2880_DTV_BW_7_MHZ) &&
> + (tune_param->bandwidth != CXD2880_DTV_BW_8_MHZ)) {
> + return -EOPNOTSUPP;
> + }
> +
> + ret = cxd2880_tnrdmd_dvbt_tune1(tnr_dmd, tune_param);
> + if (ret)
> + return ret;
> +
> + usleep_range(CXD2880_TNRDMD_WAIT_AGC_STABLE * 1,
> +  CXD2880_TNRDMD_WAIT_AGC_STABLE * 1 + 1000);
> +
> + ret = cxd2880_tnrdmd_dvbt_tune2(tnr_dmd, tune_param);
> + if (ret)
> + return ret;
> +
> + ret = 

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

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

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

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

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

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