2022-07-21 19:45:27

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 0/4] iio: afe/rescale improvements

Hi Jonathan,

This patchset adds support for converting the "scale avail" list that
may be provided by the source drivers. It also implements the
.write_raw() callback.

These two features will later be used by the
(drivers/power/supply/ingenic-battery.c) driver, which will pick the
best scale possible for the battery's max voltage (it's already
implemented in there, but doesn't yet support iio-rescale being in the
middle).

As you suggested after my RFC I added support for a new
IIO_AVAIL_LIST_WITH_TYPE and it's been a perfect solution, so thank you
for that.

Cheers,
-Paul

Paul Cercueil (4):
iio: inkern: Remove useless argument to iio_channel_read_max()
iio: core: Add support for IIO_AVAIL_LIST_WITH_TYPE
iio: afe/rescale: Add support for converting scale avail table
iio: afe/rescale: Implement write_raw

drivers/iio/afe/iio-rescale.c | 107 ++++++++++++++++++++++++++++++++
drivers/iio/industrialio-core.c | 25 ++++++++
drivers/iio/inkern.c | 35 +++++++++--
include/linux/iio/afe/rescale.h | 2 +
include/linux/iio/consumer.h | 6 +-
include/linux/iio/types.h | 1 +
6 files changed, 168 insertions(+), 8 deletions(-)

--
2.35.1


2022-07-21 19:46:15

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 1/4] iio: inkern: Remove useless argument to iio_channel_read_max()

The 'type' argument was passed by the only caller of the
iio_channel_read_max() function as a pointer to return an extra value,
but the value of the variable passed by the caller was never read
afterwards.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/iio/inkern.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index df74765d33dc..e8a25852f0df 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -813,21 +813,22 @@ int iio_read_avail_channel_raw(struct iio_channel *chan,
EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);

static int iio_channel_read_max(struct iio_channel *chan,
- int *val, int *val2, int *type,
+ int *val, int *val2,
enum iio_chan_info_enum info)
{
int unused;
const int *vals;
int length;
int ret;
+ int type;

if (!val2)
val2 = &unused;

- ret = iio_channel_read_avail(chan, &vals, type, &length, info);
+ ret = iio_channel_read_avail(chan, &vals, &type, &length, info);
switch (ret) {
case IIO_AVAIL_RANGE:
- switch (*type) {
+ switch (type) {
case IIO_VAL_INT:
*val = vals[2];
break;
@@ -840,7 +841,7 @@ static int iio_channel_read_max(struct iio_channel *chan,
case IIO_AVAIL_LIST:
if (length <= 0)
return -EINVAL;
- switch (*type) {
+ switch (type) {
case IIO_VAL_INT:
*val = vals[--length];
while (length) {
@@ -863,7 +864,6 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
{
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- int type;

mutex_lock(&iio_dev_opaque->info_exist_lock);
if (!chan->indio_dev->info) {
@@ -871,7 +871,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
goto err_unlock;
}

- ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
+ ret = iio_channel_read_max(chan, val, NULL, IIO_CHAN_INFO_RAW);
err_unlock:
mutex_unlock(&iio_dev_opaque->info_exist_lock);

--
2.35.1

2022-07-31 17:20:12

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/4] iio: inkern: Remove useless argument to iio_channel_read_max()

On Thu, 21 Jul 2022 20:15:23 +0100
Paul Cercueil <[email protected]> wrote:

> The 'type' argument was passed by the only caller of the
> iio_channel_read_max() function as a pointer to return an extra value,
> but the value of the variable passed by the caller was never read
> afterwards.
>
> Signed-off-by: Paul Cercueil <[email protected]>

Curious. I'm playing guess the intent here and I suspect that what
we should really be doing is checking type in
iio_read_max_channel_raw() and returning an error if it is not IIO_VAL_INT
(can only get there for IIO_AVAIL_RANGE currently as there is a FIXME for
IIO_AVAIL_LIST for non IIO_VAL_INT types)

I'm not sure we've ever documented that _RAW can't be non integer even if
that makes relatively little sense most of the time..

Jonathan

> ---
> drivers/iio/inkern.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index df74765d33dc..e8a25852f0df 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -813,21 +813,22 @@ int iio_read_avail_channel_raw(struct iio_channel *chan,
> EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);
>
> static int iio_channel_read_max(struct iio_channel *chan,
> - int *val, int *val2, int *type,
> + int *val, int *val2,
> enum iio_chan_info_enum info)
> {
> int unused;
> const int *vals;
> int length;
> int ret;
> + int type;
>
> if (!val2)
> val2 = &unused;
>
> - ret = iio_channel_read_avail(chan, &vals, type, &length, info);
> + ret = iio_channel_read_avail(chan, &vals, &type, &length, info);
> switch (ret) {
> case IIO_AVAIL_RANGE:
> - switch (*type) {
> + switch (type) {
> case IIO_VAL_INT:
> *val = vals[2];
> break;
> @@ -840,7 +841,7 @@ static int iio_channel_read_max(struct iio_channel *chan,
> case IIO_AVAIL_LIST:
> if (length <= 0)
> return -EINVAL;
> - switch (*type) {
> + switch (type) {
> case IIO_VAL_INT:
> *val = vals[--length];
> while (length) {
> @@ -863,7 +864,6 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
> {
> struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
> int ret;
> - int type;
>
> mutex_lock(&iio_dev_opaque->info_exist_lock);
> if (!chan->indio_dev->info) {
> @@ -871,7 +871,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
> goto err_unlock;
> }
>
> - ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
> + ret = iio_channel_read_max(chan, val, NULL, IIO_CHAN_INFO_RAW);
> err_unlock:
> mutex_unlock(&iio_dev_opaque->info_exist_lock);
>