devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Yasunari.Takiguchi@sony.com
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-media@vger.kernel.org, tbird20d@gmail.com,
	frowand.list@gmail.com,
	Masayuki Yamamoto <Masayuki.Yamamoto@sony.com>,
	Hideki Nozawa <Hideki.Nozawa@sony.com>,
	Kota Yonezawa <Kota.Yonezawa@sony.com>,
	Toshihiko Matsumoto <Toshihiko.Matsumoto@sony.com>,
	Satoshi Watanabe <Satoshi.C.Watanabe@sony.com>
Subject: Re: [PATCH v2 04/15] [media] cxd2880: Add math functions for the driver
Date: Tue, 13 Jun 2017 09:18:55 -0300	[thread overview]
Message-ID: <20170613091855.046d60a3@vento.lan> (raw)
In-Reply-To: <20170414022237.17269-1-Yasunari.Takiguchi@sony.com>

Em Fri, 14 Apr 2017 11:22:37 +0900
<Yasunari.Takiguchi@sony.com> escreveu:

> From: Yasunari Takiguchi <Yasunari.Takiguchi@sony.com>
> 
> Provide some math support functions (fixed-point log functions)
> for the Sony CXD2880 DVB-T2/T tuner + demodulator driver.

No need. The Kernel already provide log functions. You should use the
existing ones, instead of reinventing the wheel. The log2 functions
are at:
	include/linux/log2.h

We also have both log2 and log10 functions at:
	drivers/media/dvb-core/dvb_math.h

That should likely what you want.


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

We also have min() macro at the Kernel.

> +
> +#endif



Thanks,
Mauro

  reply	other threads:[~2017-06-13 12:18 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14  1:50 [PATCH v2 0/15] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator Yasunari.Takiguchi
2017-04-14  2:25 ` [PATCH v2 05/15] [media] cxd2880: Add spi device IO routines Yasunari.Takiguchi
     [not found]   ` <20170414022523.17417-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-06-13 12:25     ` Mauro Carvalho Chehab
2017-04-14  2:29 ` [PATCH v2 07/15] [media] cxd2880: Add integration layer for the driver Yasunari.Takiguchi
2017-04-14  2:31 ` [PATCH v2 08/15] [media] cxd2880: Add top level of " Yasunari.Takiguchi
     [not found]   ` <20170414023150.17685-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-06-13 13:30     ` Mauro Carvalho Chehab
2017-06-19  7:56       ` Takiguchi, Yasunari
2017-06-23 13:02         ` Mauro Carvalho Chehab
2017-06-25 12:15           ` Mauro Carvalho Chehab
2017-06-26  1:24             ` Mauro Carvalho Chehab
2017-06-27  1:51               ` Takiguchi, Yasunari
     [not found] ` <20170414015043.16731-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-04-14  2:00   ` [PATCH v2 01/15] [dt-bindings] [media] Add document file for CXD2880 SPI I/F Yasunari.Takiguchi-7U/KSKJipcs
2017-04-17  4:58     ` Takiguchi, Yasunari
2017-04-14  2:08   ` [PATCH v2 02/15] [media] cxd2880-spi: Add support for CXD2008 SPI interface Yasunari.Takiguchi-7U/KSKJipcs
     [not found]     ` <20170414020823.17034-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-06-13 11:55       ` Mauro Carvalho Chehab
2017-04-14  2:17   ` [PATCH v2 03/15] [media] cxd2880: Add common files for the driver Yasunari.Takiguchi-7U/KSKJipcs
     [not found]     ` <20170414021701.17133-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-06-13 12:13       ` Mauro Carvalho Chehab
2017-04-14  2:22   ` [PATCH v2 04/15] [media] cxd2880: Add math functions " Yasunari.Takiguchi-7U/KSKJipcs
2017-06-13 12:18     ` Mauro Carvalho Chehab [this message]
2017-04-14  2:26   ` [PATCH v2 06/15] [media] cxd2880: Add tuner part of " Yasunari.Takiguchi-7U/KSKJipcs
     [not found]     ` <20170414022656.17505-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org>
2017-06-13 13:09       ` Mauro Carvalho Chehab
2017-04-14  2:33   ` [PATCH v2 09/15] [media] cxd2880: Add DVB-T control functions " Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:35   ` [PATCH v2 10/15] [media] cxd2880: Add DVB-T monitor and integration layer functions Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:40   ` [PATCH v2 12/15] [media] cxd2880: Add DVB-T2 " Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:44   ` [PATCH v2 13/15] [media] cxd2880: Add all Makefile files for the driver Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:47   ` [PATCH v2 14/15] [media] cxd2880: Add all Kconfig " Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:48   ` [PATCH v2 15/15] [media] cxd2880 : Update MAINTAINERS file for CXD2880 driver Yasunari.Takiguchi-7U/KSKJipcs
2017-04-14  2:38 ` [PATCH v2 11/15] [media] cxd2880: Add DVB-T2 control functions for the driver Yasunari.Takiguchi
2017-04-17  5:09 ` [PATCH v2 0/15] [dt-bindings] [media] Add document file and driver for Sony CXD2880 DVB-T2/T tuner + demodulator Takiguchi, Yasunari
     [not found]   ` <5188b958-9a34-4519-5845-a318273592e0-7U/KSKJipcs@public.gmane.org>
2017-05-25  6:15     ` Takiguchi, Yasunari
2017-06-01  1:41       ` Takiguchi, Yasunari
2017-06-12 13:33         ` Abylay Ospan
     [not found]           ` <CAK3bHNXgbZ0oXbUAYCznpW-iLwQeStFcYRERfRPQcVrk18Pm6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-06-13  5:35             ` Takiguchi, Yasunari
     [not found]               ` <6586e809-417f-bb4b-5ca5-e38b9641894b-7U/KSKJipcs@public.gmane.org>
2017-06-13  5:39                 ` Abylay Ospan
     [not found]       ` <d7c70c53-3fb0-a045-5e1a-1a736bdeda1f-7U/KSKJipcs@public.gmane.org>
2017-06-13 14:38         ` Mauro Carvalho Chehab
2017-06-14  3:01           ` Takiguchi, Yasunari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170613091855.046d60a3@vento.lan \
    --to=mchehab@s-opensource.com \
    --cc=Hideki.Nozawa@sony.com \
    --cc=Kota.Yonezawa@sony.com \
    --cc=Masayuki.Yamamoto@sony.com \
    --cc=Satoshi.C.Watanabe@sony.com \
    --cc=Toshihiko.Matsumoto@sony.com \
    --cc=Yasunari.Takiguchi@sony.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=tbird20d@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).