* [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler
@ 2017-03-21 22:27 Lorenzo Bianconi
2017-03-25 16:45 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2017-03-21 22:27 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, lorenzo.bianconi
introduce st_lsm6dsx_get_odr_val() routine to check ODR consistency in
write_raw hablder in order to apply frequency configuration just in
st_lsm6dsx_set_odr()
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 41 ++++++++++++++++++----------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index c433223..70096f4 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -308,32 +308,40 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
return 0;
}
-static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
+static int st_lsm6dsx_get_odr_val(struct st_lsm6dsx_sensor *sensor, u16 odr,
+ u8 *val)
{
- enum st_lsm6dsx_sensor_id id = sensor->id;
- int i, err;
- u8 val;
+ int i;
for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
- if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
+ if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz == odr)
break;
if (i == ST_LSM6DSX_ODR_LIST_SIZE)
return -EINVAL;
- val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
- err = st_lsm6dsx_write_with_mask(sensor->hw,
- st_lsm6dsx_odr_table[id].reg.addr,
- st_lsm6dsx_odr_table[id].reg.mask,
- val);
- if (err < 0)
- return err;
-
+ *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
sensor->odr = odr;
return 0;
}
+static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
+{
+ enum st_lsm6dsx_sensor_id id = sensor->id;
+ int err;
+ u8 val;
+
+ err = st_lsm6dsx_get_odr_val(sensor, odr, &val);
+ if (err < 0)
+ return err;
+
+ return st_lsm6dsx_write_with_mask(sensor->hw,
+ st_lsm6dsx_odr_table[id].reg.addr,
+ st_lsm6dsx_odr_table[id].reg.mask,
+ val);
+}
+
int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
{
int err;
@@ -436,9 +444,12 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
case IIO_CHAN_INFO_SCALE:
err = st_lsm6dsx_set_full_scale(sensor, val2);
break;
- case IIO_CHAN_INFO_SAMP_FREQ:
- err = st_lsm6dsx_set_odr(sensor, val);
+ case IIO_CHAN_INFO_SAMP_FREQ: {
+ u8 data;
+
+ err = st_lsm6dsx_get_odr_val(sensor, val, &data);
break;
+ }
default:
err = -EINVAL;
break;
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler
2017-03-21 22:27 [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler Lorenzo Bianconi
@ 2017-03-25 16:45 ` Jonathan Cameron
2017-03-25 17:00 ` Lorenzo Bianconi
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2017-03-25 16:45 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi
On 21/03/17 22:27, Lorenzo Bianconi wrote:
> introduce st_lsm6dsx_get_odr_val() routine to check ODR consistency in
> write_raw hablder in order to apply frequency configuration just in
> st_lsm6dsx_set_odr()
handler.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
So the advantage of this one is that it saves a pointless double write?
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 41 ++++++++++++++++++----------
> 1 file changed, 26 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index c433223..70096f4 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -308,32 +308,40 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> return 0;
> }
>
> -static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
> +static int st_lsm6dsx_get_odr_val(struct st_lsm6dsx_sensor *sensor, u16 odr,
> + u8 *val)
Odd naming.., this sounds like it is reading the value back, whereas it's just
checking for validity.
> {
> - enum st_lsm6dsx_sensor_id id = sensor->id;
> - int i, err;
> - u8 val;
> + int i;
>
> for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
> - if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
> + if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz == odr)
> break;
>
> if (i == ST_LSM6DSX_ODR_LIST_SIZE)
> return -EINVAL;
>
> - val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
> - err = st_lsm6dsx_write_with_mask(sensor->hw,
> - st_lsm6dsx_odr_table[id].reg.addr,
> - st_lsm6dsx_odr_table[id].reg.mask,
> - val);
> - if (err < 0)
> - return err;
> -
> + *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
Nothing ever looks at the value in *val after this call so why update?
> sensor->odr = odr;
>
> return 0;
> }
>
> +static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
> +{
> + enum st_lsm6dsx_sensor_id id = sensor->id;
> + int err;
> + u8 val;
> +
> + err = st_lsm6dsx_get_odr_val(sensor, odr, &val);
> + if (err < 0)
> + return err;
> +
> + return st_lsm6dsx_write_with_mask(sensor->hw,
> + st_lsm6dsx_odr_table[id].reg.addr,
> + st_lsm6dsx_odr_table[id].reg.mask,
> + val);
> +}
> +
> int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
> {
> int err;
> @@ -436,9 +444,12 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
> case IIO_CHAN_INFO_SCALE:
> err = st_lsm6dsx_set_full_scale(sensor, val2);
> break;
> - case IIO_CHAN_INFO_SAMP_FREQ:
> - err = st_lsm6dsx_set_odr(sensor, val);
> + case IIO_CHAN_INFO_SAMP_FREQ: {
> + u8 data;
> +
> + err = st_lsm6dsx_get_odr_val(sensor, val, &data);
> break;
> + }
> default:
> err = -EINVAL;
> break;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler
2017-03-25 16:45 ` Jonathan Cameron
@ 2017-03-25 17:00 ` Lorenzo Bianconi
2017-03-25 17:39 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2017-03-25 17:00 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lorenzo BIANCONI
Hi Jonathan,
> On 21/03/17 22:27, Lorenzo Bianconi wrote:
>> introduce st_lsm6dsx_get_odr_val() routine to check ODR consistency in
>> write_raw hablder in order to apply frequency configuration just in
>> st_lsm6dsx_set_odr()
> handler.
>>
>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
> So the advantage of this one is that it saves a pointless double write?
Right. Moreover this patch allows to avoid a transitory that occurs
when a given sensor has been already enabled (i.e. gyroscope) and the
user is configuring the sample frequency of the other one (i.e.
accel).
Until the accel is enabled ODR of gyro is modified as well. I will add
this comment in v2.
>> ---
>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 41 ++++++++++++++++++----------
>> 1 file changed, 26 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> index c433223..70096f4 100644
>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>> @@ -308,32 +308,40 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
>> return 0;
>> }
>>
>> -static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
>> +static int st_lsm6dsx_get_odr_val(struct st_lsm6dsx_sensor *sensor, u16 odr,
>> + u8 *val)
> Odd naming.., this sounds like it is reading the value back, whereas it's just
> checking for validity.
Right, it checks the validity of requested odr and return back the
corresponding hw value.
Maybe it is better to split it in two separate routines, what do you think?
>> {
>> - enum st_lsm6dsx_sensor_id id = sensor->id;
>> - int i, err;
>> - u8 val;
>> + int i;
>>
>> for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
>> - if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
>> + if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz == odr)
>> break;
>>
>> if (i == ST_LSM6DSX_ODR_LIST_SIZE)
>> return -EINVAL;
>>
>> - val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
>> - err = st_lsm6dsx_write_with_mask(sensor->hw,
>> - st_lsm6dsx_odr_table[id].reg.addr,
>> - st_lsm6dsx_odr_table[id].reg.mask,
>> - val);
>> - if (err < 0)
>> - return err;
>> -
>> + *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
> Nothing ever looks at the value in *val after this call so why update?
it is used in st_lsm6dsx_set_odr()
>> sensor->odr = odr;
>>
>> return 0;
>> }
>>
>> +static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
>> +{
>> + enum st_lsm6dsx_sensor_id id = sensor->id;
>> + int err;
>> + u8 val;
>> +
>> + err = st_lsm6dsx_get_odr_val(sensor, odr, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + return st_lsm6dsx_write_with_mask(sensor->hw,
>> + st_lsm6dsx_odr_table[id].reg.addr,
>> + st_lsm6dsx_odr_table[id].reg.mask,
>> + val);
>> +}
>> +
>> int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
>> {
>> int err;
>> @@ -436,9 +444,12 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>> case IIO_CHAN_INFO_SCALE:
>> err = st_lsm6dsx_set_full_scale(sensor, val2);
>> break;
>> - case IIO_CHAN_INFO_SAMP_FREQ:
>> - err = st_lsm6dsx_set_odr(sensor, val);
>> + case IIO_CHAN_INFO_SAMP_FREQ: {
>> + u8 data;
>> +
>> + err = st_lsm6dsx_get_odr_val(sensor, val, &data);
>> break;
>> + }
>> default:
>> err = -EINVAL;
>> break;
>>
>
Regards,
Lorenzo
--
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch;
unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp;
umount; make clean; sleep
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler
2017-03-25 17:00 ` Lorenzo Bianconi
@ 2017-03-25 17:39 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-03-25 17:39 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: linux-iio, Lorenzo BIANCONI
On 25/03/17 17:00, Lorenzo Bianconi wrote:
> Hi Jonathan,
>
>> On 21/03/17 22:27, Lorenzo Bianconi wrote:
>>> introduce st_lsm6dsx_get_odr_val() routine to check ODR consistency in
>>> write_raw hablder in order to apply frequency configuration just in
>>> st_lsm6dsx_set_odr()
>> handler.
>>>
>>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
>> So the advantage of this one is that it saves a pointless double write?
>
> Right. Moreover this patch allows to avoid a transitory that occurs
> when a given sensor has been already enabled (i.e. gyroscope) and the
> user is configuring the sample frequency of the other one (i.e.
> accel).
> Until the accel is enabled ODR of gyro is modified as well. I will add
> this comment in v2.
>
>>> ---
>>> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 41 ++++++++++++++++++----------
>>> 1 file changed, 26 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> index c433223..70096f4 100644
>>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> @@ -308,32 +308,40 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
>>> return 0;
>>> }
>>>
>>> -static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
>>> +static int st_lsm6dsx_get_odr_val(struct st_lsm6dsx_sensor *sensor, u16 odr,
>>> + u8 *val)
>> Odd naming.., this sounds like it is reading the value back, whereas it's just
>> checking for validity.
>
> Right, it checks the validity of requested odr and return back the
> corresponding hw value.
> Maybe it is better to split it in two separate routines, what do you think?
Fine as is, just rename.
>
>>> {
>>> - enum st_lsm6dsx_sensor_id id = sensor->id;
>>> - int i, err;
>>> - u8 val;
>>> + int i;
>>>
>>> for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
>>> - if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
>>> + if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz == odr)
>>> break;
>>>
>>> if (i == ST_LSM6DSX_ODR_LIST_SIZE)
>>> return -EINVAL;
>>>
>>> - val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
>>> - err = st_lsm6dsx_write_with_mask(sensor->hw,
>>> - st_lsm6dsx_odr_table[id].reg.addr,
>>> - st_lsm6dsx_odr_table[id].reg.mask,
>>> - val);
>>> - if (err < 0)
>>> - return err;
>>> -
>>> + *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
>> Nothing ever looks at the value in *val after this call so why update?
>
> it is used in st_lsm6dsx_set_odr()
oops, so it is ;)
>
>>> sensor->odr = odr;
>>>
>>> return 0;
>>> }
>>>
>>> +static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
>>> +{
>>> + enum st_lsm6dsx_sensor_id id = sensor->id;
>>> + int err;
>>> + u8 val;
>>> +
>>> + err = st_lsm6dsx_get_odr_val(sensor, odr, &val);
>>> + if (err < 0)
>>> + return err;
>>> +
>>> + return st_lsm6dsx_write_with_mask(sensor->hw,
>>> + st_lsm6dsx_odr_table[id].reg.addr,
>>> + st_lsm6dsx_odr_table[id].reg.mask,
>>> + val);
>>> +}
>>> +
>>> int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
>>> {
>>> int err;
>>> @@ -436,9 +444,12 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>>> case IIO_CHAN_INFO_SCALE:
>>> err = st_lsm6dsx_set_full_scale(sensor, val2);
>>> break;
>>> - case IIO_CHAN_INFO_SAMP_FREQ:
>>> - err = st_lsm6dsx_set_odr(sensor, val);
>>> + case IIO_CHAN_INFO_SAMP_FREQ: {
>>> + u8 data;
>>> +
>>> + err = st_lsm6dsx_get_odr_val(sensor, val, &data);
>>> break;
>>> + }
>>> default:
>>> err = -EINVAL;
>>> break;
>>>
>>
>
> Regards,
> Lorenzo
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-25 17:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-21 22:27 [PATCH] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler Lorenzo Bianconi
2017-03-25 16:45 ` Jonathan Cameron
2017-03-25 17:00 ` Lorenzo Bianconi
2017-03-25 17:39 ` Jonathan Cameron
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).