From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>,
linux-iio@vger.kernel.org, drivers@analog.com
Subject: Re: [PATCH 1/2] iio: Add a logarithmic fractional value type
Date: Fri, 19 Oct 2012 16:56:43 +0100 [thread overview]
Message-ID: <5081783B.4020602@kernel.org> (raw)
In-Reply-To: <1350404979-29253-1-git-send-email-lars@metafoo.de>
On 10/16/2012 05:29 PM, Lars-Peter Clausen wrote:
> For ADCs or DACs the denominator for fractional types often is a power of two.
> In this case we can use a shift operation instead of the rather expensive 64 bit
> division. This patch adds a new fractional type which expects the denominator to
> be specified as the log2 of the actual denominator. E.g. for ADCs and DACs this
> will usually be the number of significant bits.
Only slight issue with this is that continual addition of these will eventually
make for a mess. Having said that, this one is sensible and as you say
common.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Added to togreg branch of iio.git
> ---
> drivers/iio/industrialio-core.c | 5 +++++
> drivers/iio/inkern.c | 3 +++
> include/linux/iio/types.h | 1 +
> 3 files changed, 9 insertions(+)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 6eb24db..37650a7 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -397,6 +397,11 @@ static ssize_t iio_read_channel_info(struct device *dev,
> val2 = do_div(tmp, 1000000000LL);
> val = tmp;
> return sprintf(buf, "%d.%09u\n", val, val2);
> + case IIO_VAL_FRACTIONAL_LOG2:
> + tmp = (s64)val * 1000000000LL >> val2;
> + val2 = do_div(tmp, 1000000000LL);
> + val = tmp;
> + return sprintf(buf, "%d.%09u\n", val, val2);
> default:
> return 0;
> }
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index f2b78d4..2ee4450 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -314,6 +314,9 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> *processed = div_s64(raw64 * (s64)scale_val * scale,
> scale_val2);
> break;
> + case IIO_VAL_FRACTIONAL_LOG2:
> + *processed = (raw64 * (s64)scale_val * scale) >> scale_val2;
> + break;
> default:
> return -EINVAL;
> }
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index 5c647ec..87b196a 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -58,5 +58,6 @@ enum iio_modifier {
> #define IIO_VAL_INT_PLUS_NANO 3
> #define IIO_VAL_INT_PLUS_MICRO_DB 4
> #define IIO_VAL_FRACTIONAL 10
> +#define IIO_VAL_FRACTIONAL_LOG2 11
>
> #endif /* _IIO_TYPES_H_ */
>
prev parent reply other threads:[~2012-10-19 17:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-16 16:29 [PATCH 1/2] iio: Add a logarithmic fractional value type Lars-Peter Clausen
2012-10-16 16:29 ` [PATCH 2/2] iio:dac: Add support for the ad5449 Lars-Peter Clausen
2012-10-19 15:56 ` Jonathan Cameron
2012-10-19 15:56 ` Jonathan Cameron [this message]
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=5081783B.4020602@kernel.org \
--to=jic23@kernel.org \
--cc=drivers@analog.com \
--cc=jic23@cam.ac.uk \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.