From: Jonathan Cameron <jic23@kernel.org>
To: balbi@ti.com
Cc: Peter Meerwald <pmeerw@pmeerw.net>, linux-iio@vger.kernel.org
Subject: Re: [RFC/PATCH] iio: light: add support for TI's opt3001 ligth sensor
Date: Thu, 07 Aug 2014 17:27:56 +0100 [thread overview]
Message-ID: <53E3A90C.6080006@kernel.org> (raw)
In-Reply-To: <20140807143943.GB24581@saruman.home>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/08/14 15:39, Felipe Balbi wrote:
> Hi,
>
> On Thu, Aug 07, 2014 at 11:08:24AM +0100, Jonathan Cameron wrote:
>>>>> + OPT3001_CONFIGURATION); + return ret; + } + + /* wait for conversion and give it an extra 5ms */ +
>>>>> usleep_range(opt->int_time + 5000, opt->int_time + 10000); + + ret = opt3001_read(opt,
>>>>> OPT3001_CONFIGURATION); + if (ret < 0) { + dev_err(opt->dev, "failed to read register %02x\n", +
>>>>> OPT3001_CONFIGURATION); + return ret; + } + + reg = ret; + if (!(reg & OPT3001_CONFIGURATION_CRF)) +
>>>>> return -EPIPE; + + ret = opt3001_read(opt, OPT3001_RESULT); + if (ret < 0) { + dev_err(opt->dev, "failed
>>>>> to read register %02x\n", + OPT3001_RESULT); + return ret; + } + + exponent =
>>>>> OPT3001_REG_EXPONENT(ret); + mantissa = OPT3001_REG_MANTISSA(ret); + + opt3001_to_iio_ret(opt, exponent,
>>>>> mantissa, val, val2); + + return IIO_VAL_INT_PLUS_MICRO; +} + +static int opt3001_get_scale(struct opt3001
>>>>> *opt, int *val, int *val2) +{ + int ret; + u8 exponent; +
>>>>
>>>> I guess OPT3001_RESULT is only valid AFTER performing opt3001_get_lux()
>>>
>>> right. I'm only interested in the exponent part. It'll latch the exponent from last conversion, 0 being
>>> default.
>> Given you unwind the scale anyway in your read raw, I'd not bother having a scale interface at all (assuming I'm
>> right in thinking your read raw is returning the value in lux?) Also as you are in lux, it should be the
>> processed form not the raw one to indicate the scale does not need to be applied to the value to convert to lux.
>
> alright, I'll switch to processed and remove scale.
>
>> For a light sensor, the conversion here is actually fairly straight forward. Almost all of them have to use the
>> processed interface as they are horribly non linear.
>
> :)
>
>>>
>>>>> + + if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS) + return -EBUSY; + + if (chan->type != IIO_LIGHT)
>>>>> + return -EINVAL; + + mutex_lock(&opt->lock); + + switch (mask) {
>>>>
>>>> is there no way to control the scale?
>>>
>>> yeah, but the HW does auto-scaling which works pretty well. Why would you want to control the scale manually ?
>> On a slow device like this you probably wouldn't but for quicker devices the overhead of converting into a
>> standard form in kernel might be excessive.
>
> hehe, even when you _do_ set the scale, you still have the top 4 bits as exponent, the difference is that you know
> what they are before the conversion is done :-)
Then you can junk them and let userspace use the known value to deal with the raw data.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJT46kMAAoJEFSFNJnE9BaICmQP/iY3mtojtzobsU1BTFiyd6ah
xp/5vsyCM4pdqMOm8xUDwp6aBlvBvAQfVDGcQetR/KawJt7SMtKJdDxhR/hkFodE
E/3thrUXjCYw0VW9Xkg5doBucqbaWOjNsjnZDFH8HBZupFTWHv3I/QQq3acbdAbJ
DC0DRtfrTBF2JEOSLRssY11pAbxkDdeuZvIqQLpwZ80+Ptpi9MkeWoHlwOq9v67P
s0KODDTep2n7Z2w9KaY4V5L5YgLjW5YsDW+qv3zpQyq54+LB+CnCFMK2DZ4RqQlt
zPDuz7Cw8ujiqoHJlrs+bc/AbTk6gV/+puOyzb9zp6/HbSF/Q72Drw/1yF+2dIz4
rZtNaxsg0I+mH0e8xiKRYIeYHEKnHvwhO2e+6CJdLWabYvS8tSiYrU7qHKwkZVja
P04RGZNdqWrdmEOmxidd9CO+K7lvMqv/pSzVmVpQWq7Zw9EDx77h1SxyIHWtnD+3
CsiZluC++2JqCdvU01Cen+x95DPZPfK3hp6u7Y8SGgKwGluxxRMlN3QyYQXC5g5s
o9G4Jw/0wV0hshuTmwR9SifwkS2XMp/FbCJC2/c6A8PUx9O9H5IVIqk+ChSaWXkP
3NPl2O1hQIdjLgoDF5Xn4SD+F/CC3WPczMV+zcW8GrmZKjb30X0x5BNIv2UxKN0H
zJyy8hv/NLTUBaoXd5BG
=QBgz
-----END PGP SIGNATURE-----
next prev parent reply other threads:[~2014-08-07 16:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-06 16:10 [RFC/PATCH] iio: light: add support for TI's opt3001 ligth sensor Felipe Balbi
2014-08-06 21:11 ` Peter Meerwald
2014-08-06 21:42 ` Felipe Balbi
2014-08-06 22:09 ` Peter Meerwald
2014-08-06 22:18 ` Felipe Balbi
2014-08-06 22:25 ` Peter Meerwald
2014-08-06 22:30 ` Felipe Balbi
2014-08-06 22:35 ` Peter Meerwald
2014-08-06 22:38 ` Felipe Balbi
2014-08-07 10:13 ` Jonathan Cameron
2014-08-07 10:08 ` Jonathan Cameron
2014-08-07 14:39 ` Felipe Balbi
2014-08-07 16:27 ` Jonathan Cameron [this message]
2014-08-07 16:36 ` Felipe Balbi
2014-08-07 17:00 ` Jonathan Cameron
2014-08-07 10:01 ` Jonathan Cameron
2014-08-07 14:28 ` Felipe Balbi
2014-08-07 16:26 ` Jonathan Cameron
2014-08-07 16:30 ` Jonathan Cameron
2014-08-07 16:35 ` Felipe Balbi
2014-08-07 16:58 ` Jonathan Cameron
2014-08-07 17:54 ` Felipe Balbi
2014-08-11 14:34 ` [RFC/PATCH v2] " Felipe Balbi
2014-08-11 14:46 ` Peter Meerwald
2014-08-11 14:58 ` Felipe Balbi
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=53E3A90C.6080006@kernel.org \
--to=jic23@kernel.org \
--cc=balbi@ti.com \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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.