* [PATCH 2/5] iio: light: noa1305: Assign val in noa1305_measure()
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
@ 2024-07-15 18:28 ` Marek Vasut
2024-07-15 18:28 ` [PATCH 3/5] iio: light: noa1305: Use static table lookup of scale values Marek Vasut
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-07-15 18:28 UTC (permalink / raw)
To: linux-iio
Cc: Marek Vasut, Uwe Kleine-König, Jonathan Cameron,
Lars-Peter Clausen
Make noa1305_measure() behave similar to noa1305_scale(), make it
assign the 'val' output variable on success and return IIO_VAL_INT.
This further simplifies noa1305_read_raw() and allows removal of
ret variable altogether.
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
drivers/iio/light/noa1305.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index a76f158bb50e5..a7e4c68bea09e 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -48,7 +48,7 @@ struct noa1305_priv {
struct regmap *regmap;
};
-static int noa1305_measure(struct noa1305_priv *priv)
+static int noa1305_measure(struct noa1305_priv *priv, int *val)
{
__le16 data;
int ret;
@@ -58,7 +58,9 @@ static int noa1305_measure(struct noa1305_priv *priv)
if (ret < 0)
return ret;
- return le16_to_cpu(data);
+ *val = le16_to_cpu(data);
+
+ return IIO_VAL_INT;
}
static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2)
@@ -129,18 +131,13 @@ static int noa1305_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct noa1305_priv *priv = iio_priv(indio_dev);
- int ret;
if (chan->type != IIO_LIGHT)
return -EINVAL;
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = noa1305_measure(priv);
- if (ret < 0)
- return ret;
- *val = ret;
- return IIO_VAL_INT;
+ return noa1305_measure(priv, val);
case IIO_CHAN_INFO_SCALE:
return noa1305_scale(priv, val, val2);
default:
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/5] iio: light: noa1305: Use static table lookup of scale values
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
2024-07-15 18:28 ` [PATCH 2/5] iio: light: noa1305: Assign val in noa1305_measure() Marek Vasut
@ 2024-07-15 18:28 ` Marek Vasut
2024-07-15 18:28 ` [PATCH 4/5] iio: light: noa1305: Report available " Marek Vasut
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-07-15 18:28 UTC (permalink / raw)
To: linux-iio
Cc: Marek Vasut, Uwe Kleine-König, Jonathan Cameron,
Lars-Peter Clausen
Move scale values into a static table, perform look up of those
scale values in noa1305_scale() simply by using the integration
time register content as an index, because the integration time
register content directly maps to the table values.
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
drivers/iio/light/noa1305.c | 51 +++++++++++--------------------------
1 file changed, 15 insertions(+), 36 deletions(-)
diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index a7e4c68bea09e..202a5c1bbf798 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -29,6 +29,7 @@
#define NOA1305_INTEGR_TIME_25MS 0x05
#define NOA1305_INTEGR_TIME_12_5MS 0x06
#define NOA1305_INTEGR_TIME_6_25MS 0x07
+#define NOA1305_INTEGR_TIME_MASK 0x07
#define NOA1305_REG_INT_SELECT 0x3
#define NOA1305_INT_SEL_ACTIVE_HIGH 0x01
#define NOA1305_INT_SEL_ACTIVE_LOW 0x02
@@ -43,6 +44,17 @@
#define NOA1305_DEVICE_ID 0x0519
#define NOA1305_DRIVER_NAME "noa1305"
+static int noa1305_scale_available[] = {
+ 100, 8 * 77, /* 800 ms */
+ 100, 4 * 77, /* 400 ms */
+ 100, 2 * 77, /* 200 ms */
+ 100, 1 * 77, /* 100 ms */
+ 1000, 5 * 77, /* 50 ms */
+ 10000, 25 * 77, /* 25 ms */
+ 100000, 125 * 77, /* 12.5 ms */
+ 1000000, 625 * 77, /* 6.25 ms */
+};
+
struct noa1305_priv {
struct i2c_client *client;
struct regmap *regmap;
@@ -78,42 +90,9 @@ static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2)
* Integration Constant = 7.7
* Integration Time in Seconds
*/
- switch (data) {
- case NOA1305_INTEGR_TIME_800MS:
- *val = 100;
- *val2 = 77 * 8;
- break;
- case NOA1305_INTEGR_TIME_400MS:
- *val = 100;
- *val2 = 77 * 4;
- break;
- case NOA1305_INTEGR_TIME_200MS:
- *val = 100;
- *val2 = 77 * 2;
- break;
- case NOA1305_INTEGR_TIME_100MS:
- *val = 100;
- *val2 = 77;
- break;
- case NOA1305_INTEGR_TIME_50MS:
- *val = 1000;
- *val2 = 77 * 5;
- break;
- case NOA1305_INTEGR_TIME_25MS:
- *val = 10000;
- *val2 = 77 * 25;
- break;
- case NOA1305_INTEGR_TIME_12_5MS:
- *val = 100000;
- *val2 = 77 * 125;
- break;
- case NOA1305_INTEGR_TIME_6_25MS:
- *val = 1000000;
- *val2 = 77 * 625;
- break;
- default:
- return -EINVAL;
- }
+ data &= NOA1305_INTEGR_TIME_MASK;
+ *val = noa1305_scale_available[2 * data + 0];
+ *val2 = noa1305_scale_available[2 * data + 1];
return IIO_VAL_FRACTIONAL;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/5] iio: light: noa1305: Report available scale values
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
2024-07-15 18:28 ` [PATCH 2/5] iio: light: noa1305: Assign val in noa1305_measure() Marek Vasut
2024-07-15 18:28 ` [PATCH 3/5] iio: light: noa1305: Use static table lookup of scale values Marek Vasut
@ 2024-07-15 18:28 ` Marek Vasut
2024-07-15 18:28 ` [PATCH 5/5] iio: light: noa1305: Make integration time configurable Marek Vasut
2024-07-20 13:29 ` [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Jonathan Cameron
4 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-07-15 18:28 UTC (permalink / raw)
To: linux-iio
Cc: Marek Vasut, Uwe Kleine-König, Jonathan Cameron,
Lars-Peter Clausen
Make use of the new static table of scale values and expose available
scale values via sysfs attribute of the IIO device.
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
drivers/iio/light/noa1305.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index 202a5c1bbf798..e778714a942a0 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -102,9 +102,29 @@ static const struct iio_chan_spec noa1305_channels[] = {
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+ .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),
}
};
+static int noa1305_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type,
+ int *length, long mask)
+{
+ if (chan->type != IIO_LIGHT)
+ return -EINVAL;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ *vals = noa1305_scale_available;
+ *length = ARRAY_SIZE(noa1305_scale_available);
+ *type = IIO_VAL_FRACTIONAL;
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
+
static int noa1305_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -125,6 +145,7 @@ static int noa1305_read_raw(struct iio_dev *indio_dev,
}
static const struct iio_info noa1305_info = {
+ .read_avail = noa1305_read_avail,
.read_raw = noa1305_read_raw,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 5/5] iio: light: noa1305: Make integration time configurable
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
` (2 preceding siblings ...)
2024-07-15 18:28 ` [PATCH 4/5] iio: light: noa1305: Report available " Marek Vasut
@ 2024-07-15 18:28 ` Marek Vasut
2024-07-20 13:29 ` [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Jonathan Cameron
4 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-07-15 18:28 UTC (permalink / raw)
To: linux-iio
Cc: Marek Vasut, Uwe Kleine-König, Jonathan Cameron,
Lars-Peter Clausen
Add another attribute which is the integration time. Report available
integration time settings, support read of integration time currently
configured in hardware, and support configuration of integration time
into hardware.
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
drivers/iio/light/noa1305.c | 61 +++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index e778714a942a0..da83425fd9100 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -55,6 +55,17 @@ static int noa1305_scale_available[] = {
1000000, 625 * 77, /* 6.25 ms */
};
+static int noa1305_int_time_available[] = {
+ 0, 800000, /* 800 ms */
+ 0, 400000, /* 400 ms */
+ 0, 200000, /* 200 ms */
+ 0, 100000, /* 100 ms */
+ 0, 50000, /* 50 ms */
+ 0, 25000, /* 25 ms */
+ 0, 12500, /* 12.5 ms */
+ 0, 6250, /* 6.25 ms */
+};
+
struct noa1305_priv {
struct i2c_client *client;
struct regmap *regmap;
@@ -97,12 +108,30 @@ static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2)
return IIO_VAL_FRACTIONAL;
}
+static int noa1305_int_time(struct noa1305_priv *priv, int *val, int *val2)
+{
+ int data;
+ int ret;
+
+ ret = regmap_read(priv->regmap, NOA1305_REG_INTEGRATION_TIME, &data);
+ if (ret < 0)
+ return ret;
+
+ data &= NOA1305_INTEGR_TIME_MASK;
+ *val = noa1305_int_time_available[2 * data + 0];
+ *val2 = noa1305_int_time_available[2 * data + 1];
+
+ return IIO_VAL_INT_PLUS_MICRO;
+}
+
static const struct iio_chan_spec noa1305_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),
+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
+ .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
}
};
@@ -120,6 +149,11 @@ static int noa1305_read_avail(struct iio_dev *indio_dev,
*length = ARRAY_SIZE(noa1305_scale_available);
*type = IIO_VAL_FRACTIONAL;
return IIO_AVAIL_LIST;
+ case IIO_CHAN_INFO_INT_TIME:
+ *vals = noa1305_int_time_available;
+ *length = ARRAY_SIZE(noa1305_int_time_available);
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ return IIO_AVAIL_LIST;
default:
return -EINVAL;
}
@@ -139,14 +173,41 @@ static int noa1305_read_raw(struct iio_dev *indio_dev,
return noa1305_measure(priv, val);
case IIO_CHAN_INFO_SCALE:
return noa1305_scale(priv, val, val2);
+ case IIO_CHAN_INFO_INT_TIME:
+ return noa1305_int_time(priv, val, val2);
default:
return -EINVAL;
}
}
+static int noa1305_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ struct noa1305_priv *priv = iio_priv(indio_dev);
+ int i;
+
+ if (chan->type != IIO_LIGHT)
+ return -EINVAL;
+
+ if (mask != IIO_CHAN_INFO_INT_TIME)
+ return -EINVAL;
+
+ if (val) /* >= 1s integration time not supported */
+ return -EINVAL;
+
+ /* Look up integration time register settings and write it if found. */
+ for (i = 0; i < ARRAY_SIZE(noa1305_int_time_available); i++)
+ if (noa1305_int_time_available[2 * i + 1] == val2)
+ return regmap_write(priv->regmap, NOA1305_REG_INTEGRATION_TIME, i);
+
+ return -EINVAL;
+}
+
static const struct iio_info noa1305_info = {
.read_avail = noa1305_read_avail,
.read_raw = noa1305_read_raw,
+ .write_raw = noa1305_write_raw,
};
static bool noa1305_writable_reg(struct device *dev, unsigned int reg)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw()
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
` (3 preceding siblings ...)
2024-07-15 18:28 ` [PATCH 5/5] iio: light: noa1305: Make integration time configurable Marek Vasut
@ 2024-07-20 13:29 ` Jonathan Cameron
2024-07-20 16:22 ` Marek Vasut
4 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2024-07-20 13:29 UTC (permalink / raw)
To: Marek Vasut; +Cc: linux-iio, Uwe Kleine-König, Lars-Peter Clausen
On Mon, 15 Jul 2024 20:28:55 +0200
Marek Vasut <marex@denx.de> wrote:
> The only channel this hardware supports is IIO_LIGHT, if the channel
> is anything else, exit right away. The 'ret' variable is now always
> only assigned by noa1305_measure(), do not initialize it anymore.
> Update function parameter indent. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
Hi Marek,
One minor thing - please use a cover letter.
Provides an obvious place for me to reply when picking things up and
gives the whole series a meaningful title in patchwork.
Anyhow, looks straight forward to me so I'll apply it to my current testing
tree. Not that will get rebased on rc1 once available.
If anyone has additional feedback in the meantime I'm happy to rebase
until this gets pushed out as togreg so can add tags or make other changes.
Thanks,
Jonathan
> ---
> Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: linux-iio@vger.kernel.org
> ---
> drivers/iio/light/noa1305.c | 37 +++++++++++++------------------------
> 1 file changed, 13 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
> index 596cc48c4c341..a76f158bb50e5 100644
> --- a/drivers/iio/light/noa1305.c
> +++ b/drivers/iio/light/noa1305.c
> @@ -125,38 +125,27 @@ static const struct iio_chan_spec noa1305_channels[] = {
> };
>
> static int noa1305_read_raw(struct iio_dev *indio_dev,
> - struct iio_chan_spec const *chan,
> - int *val, int *val2, long mask)
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> {
> - int ret = -EINVAL;
> struct noa1305_priv *priv = iio_priv(indio_dev);
> + int ret;
> +
> + if (chan->type != IIO_LIGHT)
> + return -EINVAL;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - switch (chan->type) {
> - case IIO_LIGHT:
> - ret = noa1305_measure(priv);
> - if (ret < 0)
> - return ret;
> - *val = ret;
> - return IIO_VAL_INT;
> - default:
> - break;
> - }
> - break;
> + ret = noa1305_measure(priv);
> + if (ret < 0)
> + return ret;
> + *val = ret;
> + return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> - switch (chan->type) {
> - case IIO_LIGHT:
> - return noa1305_scale(priv, val, val2);
> - default:
> - break;
> - }
> - break;
> + return noa1305_scale(priv, val, val2);
> default:
> - break;
> + return -EINVAL;
> }
> -
> - return ret;
> }
>
> static const struct iio_info noa1305_info = {
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw()
2024-07-20 13:29 ` [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Jonathan Cameron
@ 2024-07-20 16:22 ` Marek Vasut
0 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2024-07-20 16:22 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Uwe Kleine-König, Lars-Peter Clausen
On 7/20/24 3:29 PM, Jonathan Cameron wrote:
> On Mon, 15 Jul 2024 20:28:55 +0200
> Marek Vasut <marex@denx.de> wrote:
>
>> The only channel this hardware supports is IIO_LIGHT, if the channel
>> is anything else, exit right away. The 'ret' variable is now always
>> only assigned by noa1305_measure(), do not initialize it anymore.
>> Update function parameter indent. No functional change.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
> Hi Marek,
>
> One minor thing - please use a cover letter.
> Provides an obvious place for me to reply when picking things up and
> gives the whole series a meaningful title in patchwork.
I will keep that in mind, thanks for the reminder.
^ permalink raw reply [flat|nested] 7+ messages in thread