linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Jonathan Cameron <jic23@cam.ac.uk>,
	Michael Hennerich <michael.hennerich@analog.com>,
	linux-iio@vger.kernel.org,
	device-drivers-devel@blackfin.uclinux.org, drivers@analog.com
Subject: Re: [PATCH] staging:iio:dac: Add helper function for formating scale
Date: Tue, 15 Nov 2011 21:31:39 +0100	[thread overview]
Message-ID: <4EC2CC2B.3020505@metafoo.de> (raw)
In-Reply-To: <4EC2C011.4040100@kernel.org>

On 11/15/2011 08:40 PM, Jonathan Cameron wrote:
> On 11/15/2011 04:30 PM, Lars-Peter Clausen wrote:
>> We basically use the same for formating the DACs scale in almost all DAC
>> drivers. So put this into a common helper function which does the job for us.
>> The helper function uses 64-bit math to be as accurate as possible to minimize
>> the error we get when multiplying out_voltage_scale with out_voltage_raw.
>>
> Nice idea.
> As stated below, I do wonder if this isn't more general than dacs and
> perhaps needs a more descriptive name?
[...]
> This is actually pretty similar to that used for some adc's as well.
> Maybe it wants a less dac focused and more descriptive name?

Hm, yes. So what it basically does is, it maps the fullscale value to one lsb
based on the channels realbits. I'm open for suggestions for a good name.

Maybe:
iio_channel_[lsb]_get_scale(const struct iio_chan_spec *chan, unsigned long
fullscale, unsigned int *val, unsigned int *val2)


>> +/* iio_dac_format_scale: Helper function for formating the scale attribute for a
>> + * DAC.
> kernel doc formatting please. Close, but few minor differences..

Anything else except the /** and the missing parenthesis after the function name?

>> + *
>> + * @vref_span_uv:	span of the reference voltage in microvolts
>> + * @chan:			channel to format for
>> + * @val:			val of iio raw_write callback
>> + * @val2:			val2 of the iio raw_write callback
>> + */
>> +static inline int iio_dac_format_scale(unsigned long vref_span_uv,
>> +	const struct iio_chan_spec *chan, unsigned int *val, unsigned int *val2)
>> +{
>> +	u64 result;
>> +	u32 _val2;
>> +
>> +	result = (((u64)vref_span_uv) * 1000) >> chan->scan_type.realbits;
>> +
>> +	*val = div_u64_rem(result, 1000000, &_val2);
>> +	*val2 = _val2;
>> +
>> +	return IIO_VAL_INT_PLUS_MICRO;
>> +}
> 

      reply	other threads:[~2011-11-15 20:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-15 16:30 [PATCH] staging:iio:dac: Add helper function for formating scale Lars-Peter Clausen
2011-11-15 19:40 ` Jonathan Cameron
2011-11-15 20:31   ` Lars-Peter Clausen [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=4EC2CC2B.3020505@metafoo.de \
    --to=lars@metafoo.de \
    --cc=device-drivers-devel@blackfin.uclinux.org \
    --cc=drivers@analog.com \
    --cc=jic23@cam.ac.uk \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.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).