Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 0/2] iio: light: opt3001: Enable operation w/o IRQ

43 views
Skip to first unread message

Alexander Koch

unread,
Jan 12, 2016, 1:20:07 PM1/12/16
to
This patch series aims at enabling IRQ-less operation for the TI OPT3001 light
sensor.

The current version of the driver requires an interrupt line to be connected to
the INT pin of the sensor, through which the IIO framework gets notified about
readout values being ready. In the datasheet this is described as optional (sec.
8.1.1).

In my use case of the OPT3001 I do not have any interrupt lines or GPIOs
available to connect the INT pin to, so I have implemented an interrupt-less
operation mode that simply sleeps for the specified worst-case readout time
instead of waiting for the interrupt.

This change is transparent as interrupt-less operation mode is done only when no
valid interrupt no. is configured via device tree.

Patches are taken against linux-next/master, tested by compilation,
checkpatch.pl and by running on an embedded developer board (both IRQ-enabled
and IRQ-less mode).


Alexander Koch (2):
iio: light: opt3001: extract int. time constants
iio: light: opt3001: enable operation w/o IRQ

drivers/iio/light/opt3001.c | 152 ++++++++++++++++++++++++++++++--------------
1 file changed, 104 insertions(+), 48 deletions(-)

--
2.7.0

Alexander Koch

unread,
Jan 12, 2016, 1:20:09 PM1/12/16
to
Extract integration times as #define constants. This prepares using them
for delay/timeout length determination.

Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
Signed-off-by: Michael Hornung <mhornun...@gmail.com>
---
drivers/iio/light/opt3001.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 01e111e..aefbd79 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -65,6 +65,9 @@
#define OPT3001_REG_EXPONENT(n) ((n) >> 12)
#define OPT3001_REG_MANTISSA(n) ((n) & 0xfff)

+#define OPT3001_INT_TIME_LONG 800000
+#define OPT3001_INT_TIME_SHORT 100000
+
/*
* Time to wait for conversion result to be ready. The device datasheet
* worst-case max value is 880ms. Add some slack to be on the safe side.
@@ -325,13 +328,13 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time)
reg = ret;

switch (time) {
- case 100000:
+ case OPT3001_INT_TIME_SHORT:
reg &= ~OPT3001_CONFIGURATION_CT;
- opt->int_time = 100000;
+ opt->int_time = OPT3001_INT_TIME_SHORT;
break;
- case 800000:
+ case OPT3001_INT_TIME_LONG:
reg |= OPT3001_CONFIGURATION_CT;
- opt->int_time = 800000;
+ opt->int_time = OPT3001_INT_TIME_LONG;
break;
default:
return -EINVAL;
@@ -597,9 +600,9 @@ static int opt3001_configure(struct opt3001 *opt)

/* Reflect status of the device's integration time setting */
if (reg & OPT3001_CONFIGURATION_CT)
- opt->int_time = 800000;
+ opt->int_time = OPT3001_INT_TIME_LONG;
else
- opt->int_time = 100000;
+ opt->int_time = OPT3001_INT_TIME_SHORT;

/* Ensure device is in shutdown initially */
opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
--
2.7.0

Alexander Koch

unread,
Jan 16, 2016, 11:20:06 AM1/16/16
to
This patch series aims at enabling IRQ-less operation for the TI OPT3001 light
sensor.

The current version of the driver requires an interrupt line to be connected to
the INT pin of the sensor, through which the IIO framework gets notified about
readout values being ready. In the datasheet this is described as optional (sec.
8.1.1).

In my use case of the OPT3001 I do not have any interrupt lines or GPIOs
available to connect the INT pin to, so I have implemented an interrupt-less
operation mode that simply sleeps for the specified worst-case readout time
instead of waiting for the interrupt.

This change is transparent as interrupt-less operation mode is done only when no
valid interrupt no. is configured via device tree.

Patches are taken against linux-next/master, tested by compilation,
checkpatch.pl and by running on an embedded developer board (both IRQ-enabled
and IRQ-less mode).


Changes from v1:

- use type bool for introduced member 'use_irq'
- include trivial refactoring step that changes the types of two other members
to bool, in order to match 'use_irq'


Alexander Koch (3):
iio: light: opt3001: extract int. time constants
iio: light: opt3001: trivial type refactoring
iio: light: opt3001: enable operation w/o IRQ

drivers/iio/light/opt3001.c | 156 ++++++++++++++++++++++++++++++--------------
1 file changed, 106 insertions(+), 50 deletions(-)

--
2.7.0

Alexander Koch

unread,
Jan 16, 2016, 11:20:06 AM1/16/16
to

Alexander Koch

unread,
Jan 16, 2016, 11:20:07 AM1/16/16
to
Change variable type of struct opt3001 members 'ok_to_ignore_lock' and
'result_ready' uint16-bitfield of length one to bool.

They are used as bool, let the compiler do the optimization.

Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
Signed-off-by: Michael Hornung <mhornun...@gmail.com>
---
drivers/iio/light/opt3001.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index aefbd79..b05c484 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -79,8 +79,8 @@ struct opt3001 {
struct device *dev;

struct mutex lock;
- u16 ok_to_ignore_lock:1;
- u16 result_ready:1;
+ bool ok_to_ignore_lock;
+ bool result_ready;
wait_queue_head_t result_ready_queue;
u16 result;

--
2.7.0

Jonathan Cameron

unread,
Jan 24, 2016, 10:10:07 AM1/24/16
to
On 16/01/16 16:14, Alexander Koch wrote:
> Change variable type of struct opt3001 members 'ok_to_ignore_lock' and
> 'result_ready' uint16-bitfield of length one to bool.
>
> They are used as bool, let the compiler do the optimization.
>
> Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
> Signed-off-by: Michael Hornung <mhornun...@gmail.com>
I find it hard to care much about this one, but consistency is
always good and the bitfield never made much sense in here.

Applied to the togreg branch of iio.git - pushed out as testing... etc.

Thanks,

Jonathan

Jonathan Cameron

unread,
Jan 24, 2016, 10:10:07 AM1/24/16
to
On 16/01/16 16:14, Alexander Koch wrote:
> Extract integration times as #define constants. This prepares using them
> for delay/timeout length determination.
>
> Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
> Signed-off-by: Michael Hornung <mhornun...@gmail.com>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.

Andreas Dannenberg

unread,
Jan 29, 2016, 1:10:07 PM1/29/16
to
On Sat, Jan 16, 2016 at 05:14:36PM +0100, Alexander Koch wrote:
> Extract integration times as #define constants. This prepares using them
> for delay/timeout length determination.
>
> Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
> Signed-off-by: Michael Hornung <mhornun...@gmail.com>

Tested-by: Andreas Dannenberg <danne...@ti.com>

Thanks for the patch series!

Andreas Dannenberg

unread,
Jan 29, 2016, 1:10:07 PM1/29/16
to
On Sat, Jan 16, 2016 at 05:14:35PM +0100, Alexander Koch wrote:
> This patch series aims at enabling IRQ-less operation for the TI OPT3001 light
> sensor.

Jon,
I was checking to see if the DT bindings have been updated to reflect
the interrupt-less operation however I can't seem to find it in the
Kernel tree. The last activity I can find is this one...

https://patchwork.ozlabs.org/patch/490819/

I guess it may have slipped through the cracks so I'm going to update
the bindings document and re-submit.

Regards,
Andreas

Andreas Dannenberg

unread,
Jan 29, 2016, 1:10:11 PM1/29/16
to
On Sat, Jan 16, 2016 at 05:14:37PM +0100, Alexander Koch wrote:
> Change variable type of struct opt3001 members 'ok_to_ignore_lock' and
> 'result_ready' uint16-bitfield of length one to bool.
>
> They are used as bool, let the compiler do the optimization.
>
> Signed-off-by: Alexander Koch <ma...@alexanderkoch.net>
> Signed-off-by: Michael Hornung <mhornun...@gmail.com>

Tested-by: Andreas Dannenberg <danne...@ti.com>
0 new messages