This patchset introduces a new interface for supporting some of the composite
sensors in Android [1]. First supported sensors are activity and pedometer.
This is a follow up of the discussion about adding new channels to IIO
initiated some time ago on IIO list [2].
A device that has the activity/pedometer functionality is Freescale's MMA9553L ([3]).
Because we don't have yet the hardware, to demonstrate these new channels we
update iio_dummy kernel module and iio_event_monitor test program. We want
to get an early feedback about extending the IIO interface in the correct
direction.
[1] http://source.android.com/devices/sensors/composite_sensors.html
[2] http://marc.info/?l=linux-iio&m=138374342831057&w=2
[3] http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
Changes since v1 (mostly based on comments from Jonathan)
* introduce TRANSITION event instead of MOTION to better
represent multilevel state change
* remove pedometer channel type and steps modifier and replace it
with steps channel type
* squashed together patches introducing channels and associated events
* introduced IIO_EV_DIR_NONE
* changed cover letter subject to reflect the changes
Daniel Baluta (4):
iio: dummy: Add virtual registers for dummy device
iio: core: Introduce IIO_ACTIVITY channel and TRANSITION event
iio: dummy: Demonstrate the usage of new channel types
iio: event_monitor: Add support for new channel types
Irina Tirdea (3):
iio: core: Introduce IIO_EV_DIR_NONE
iio: core: Introduce STEPS channel type, ENABLE mask and INSTANCE
event
iio: core: Introduce HEIGHT channel type
Documentation/ABI/testing/sysfs-bus-iio | 75 ++++++++
drivers/iio/industrialio-core.c | 8 +
drivers/iio/industrialio-event.c | 14 +-
.../staging/iio/Documentation/iio_event_monitor.c | 25 ++-
drivers/staging/iio/iio_dummy_evgen.c | 16 ++
drivers/staging/iio/iio_dummy_evgen.h | 6 +
drivers/staging/iio/iio_simple_dummy.c | 199 +++++++++++++++++++--
drivers/staging/iio/iio_simple_dummy.h | 7 +
drivers/staging/iio/iio_simple_dummy_events.c | 61 ++++++-
include/linux/iio/iio.h | 1 +
include/linux/iio/types.h | 12 +-
11 files changed, 393 insertions(+), 31 deletions(-)
--
1.9.1
From: Irina Tirdea <[email protected]>
These changes are needed to support the functionality of a pedometer.
A pedometer has two basic functionalities: step counter and step detector.
The step counter needs to be enabled and then it will count the steps
in its hardware register. Whenever the application needs to check
the step count, it will read the step counter register. To support the
step counter a new channel type STEPS is added. Since the pedometer needs
to be enabled first so that the hardware can count and store the steps,
we need a specific ENABLE channel info mask.
The step detector will generate an interrupt each time a step is detected.
To support this functionality we add a new event type INSTANCE.
For more information on the Android requirements for step counter and step
detector see:
http://source.android.com/devices/sensors/composite_sensors.html#counter
and http://source.android.com/devices/sensors/composite_sensors.html#detector.
A device that has the pedometer functionality this interface needs to
support is Freescale's MMA9553L:
http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-iio | 22 ++++++++++++++++++++++
drivers/iio/industrialio-core.c | 2 ++
drivers/iio/industrialio-event.c | 1 +
include/linux/iio/iio.h | 1 +
include/linux/iio/types.h | 2 ++
5 files changed, 28 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 12d0385..3557a69 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -842,6 +842,13 @@ Description:
number or direction is not specified, applies to all channels of
this type.
+What: /sys/.../events/in_steps_instance_en
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ Enables or disables step detection. Each time the user takes a step an
+ event of this type will be generated.
+
What: /sys/bus/iio/devices/iio:deviceX/trigger/current_trigger
KernelVersion: 2.6.35
Contact: [email protected]
@@ -1072,3 +1079,18 @@ Contact: [email protected]
Description:
Raw value of rotation from true/magnetic north measured with
or without compensation from tilt sensors.
+
+What: /sys/.../iio:deviceX/in_steps_enable
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ Activates the step counter. After activation, the number of steps
+ taken by the user will be counted in hardware and exported through
+ in_steps_input.
+
+What: /sys/.../iio:deviceX/in_steps_input
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ This attribute is used to read the number of steps taken by the user
+ since the last reboot while activated.
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index e453ef9..1e060f3 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -71,6 +71,7 @@ static const char * const iio_chan_type_name_spec[] = {
[IIO_PRESSURE] = "pressure",
[IIO_HUMIDITYRELATIVE] = "humidityrelative",
[IIO_ACTIVITY] = "activity",
+ [IIO_STEPS] = "steps",
};
static const char * const iio_modifier_names[] = {
@@ -118,6 +119,7 @@ static const char * const iio_chan_info_postfix[] = {
[IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
[IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
[IIO_CHAN_INFO_INT_TIME] = "integration_time",
+ [IIO_CHAN_INFO_ENABLE] = "en",
};
/**
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index a9c9f34..db63d29 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -198,6 +198,7 @@ static const char * const iio_ev_type_text[] = {
[IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
[IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
[IIO_EV_TYPE_TRANSITION] = "transition",
+ [IIO_EV_TYPE_INSTANCE] = "instance",
};
static const char * const iio_ev_dir_text[] = {
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 15dc6bc..3d3f06f 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -37,6 +37,7 @@ enum iio_chan_info_enum {
IIO_CHAN_INFO_HARDWAREGAIN,
IIO_CHAN_INFO_HYSTERESIS,
IIO_CHAN_INFO_INT_TIME,
+ IIO_CHAN_INFO_ENABLE,
};
enum iio_shared_by {
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 9a1cc01..af0b6e0 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -31,6 +31,7 @@ enum iio_chan_type {
IIO_PRESSURE,
IIO_HUMIDITYRELATIVE,
IIO_ACTIVITY,
+ IIO_STEPS,
};
enum iio_modifier {
@@ -74,6 +75,7 @@ enum iio_event_type {
IIO_EV_TYPE_THRESH_ADAPTIVE,
IIO_EV_TYPE_MAG_ADAPTIVE,
IIO_EV_TYPE_TRANSITION,
+ IIO_EV_TYPE_INSTANCE,
};
enum iio_event_info {
--
1.9.1
From: Irina Tirdea <[email protected]>
Some devices need the height of the user to compute various
parameters. One of this devices is Freescale's MMA9553L
(http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf)
that needs the height of the user to compute the stride length which
is used further to determine distance, speed and activity type.
Introduce a new channel type HEIGHT to export these values.
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-iio | 9 +++++++++
drivers/iio/industrialio-core.c | 1 +
include/linux/iio/types.h | 1 +
3 files changed, 11 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 3557a69..fc027cb 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -256,6 +256,7 @@ What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale
What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale
What: /sys/bus/iio/devices/iio:deviceX/in_accel_peak_scale
What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_scale
+What: /sys/bus/iio/devices/iio:deviceX/in_height_scale
What: /sys/bus/iio/devices/iio:deviceX/in_magn_scale
What: /sys/bus/iio/devices/iio:deviceX/in_magn_x_scale
What: /sys/bus/iio/devices/iio:deviceX/in_magn_y_scale
@@ -1010,6 +1011,14 @@ Description:
For a list of available output power modes read
in_accel_power_mode_available.
+What: /sys/.../iio:deviceX/in_height_input
+What: /sys/.../iio:deviceX/in_height_raw
+KernelVersion: 3.17
+Contact: [email protected]
+Description:
+ This attribute is used to set and read the user's height.
+ Units after application of scale are centimeters.
+
What: /sys/bus/iio/devices/iio:deviceX/store_eeprom
KernelVersion: 3.4.0
Contact: [email protected]
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 1e060f3..f08b278 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -72,6 +72,7 @@ static const char * const iio_chan_type_name_spec[] = {
[IIO_HUMIDITYRELATIVE] = "humidityrelative",
[IIO_ACTIVITY] = "activity",
[IIO_STEPS] = "steps",
+ [IIO_HEIGHT] = "height",
};
static const char * const iio_modifier_names[] = {
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index af0b6e0..a23b2e7 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -32,6 +32,7 @@ enum iio_chan_type {
IIO_HUMIDITYRELATIVE,
IIO_ACTIVITY,
IIO_STEPS,
+ IIO_HEIGHT,
};
enum iio_modifier {
--
1.9.1
We have the following testing scenario:
$ insmod iio_dummy_evgen.ko
$ insmod iio_dummy.ko
./iio_event_monitor /dev/iio:device0
Event: time: 1412786467971335337, type: activity(running), channel: 0, evtype: transition, direction:
rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0, evtype: transition, direction:
falling
Event: time: 1412764319184761765, type: steps, channel: 0, evtype: instance
$ echo 1 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 2 > /sys/bus/iio/devices/iio_evgen/poke_ev0
$ echo 3 > /sys/bus/iio/devices/iio_evgen/poke_ev0
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
.../staging/iio/Documentation/iio_event_monitor.c | 25 +++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/Documentation/iio_event_monitor.c b/drivers/staging/iio/Documentation/iio_event_monitor.c
index 569d6f8..47de74b2 100644
--- a/drivers/staging/iio/Documentation/iio_event_monitor.c
+++ b/drivers/staging/iio/Documentation/iio_event_monitor.c
@@ -49,6 +49,8 @@ static const char * const iio_chan_type_name_spec[] = {
[IIO_CCT] = "cct",
[IIO_PRESSURE] = "pressure",
[IIO_HUMIDITYRELATIVE] = "humidityrelative",
+ [IIO_ACTIVITY] = "activity",
+ [IIO_STEPS] = "steps",
};
static const char * const iio_ev_type_text[] = {
@@ -57,6 +59,8 @@ static const char * const iio_ev_type_text[] = {
[IIO_EV_TYPE_ROC] = "roc",
[IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
[IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
+ [IIO_EV_TYPE_TRANSITION] = "transition",
+ [IIO_EV_TYPE_INSTANCE] = "instance",
};
static const char * const iio_ev_dir_text[] = {
@@ -79,6 +83,10 @@ static const char * const iio_modifier_names[] = {
[IIO_MOD_LIGHT_RED] = "red",
[IIO_MOD_LIGHT_GREEN] = "green",
[IIO_MOD_LIGHT_BLUE] = "blue",
+ [IIO_MOD_RUNNING] = "running",
+ [IIO_MOD_JOGGING] = "jogging",
+ [IIO_MOD_WALKING] = "walking",
+ [IIO_MOD_STILL] = "still",
};
static bool event_is_known(struct iio_event_data *event)
@@ -108,6 +116,8 @@ static bool event_is_known(struct iio_event_data *event)
case IIO_CCT:
case IIO_PRESSURE:
case IIO_HUMIDITYRELATIVE:
+ case IIO_ACTIVITY:
+ case IIO_STEPS:
break;
default:
return false;
@@ -126,6 +136,10 @@ static bool event_is_known(struct iio_event_data *event)
case IIO_MOD_LIGHT_RED:
case IIO_MOD_LIGHT_GREEN:
case IIO_MOD_LIGHT_BLUE:
+ case IIO_MOD_RUNNING:
+ case IIO_MOD_JOGGING:
+ case IIO_MOD_WALKING:
+ case IIO_MOD_STILL:
break;
default:
return false;
@@ -137,6 +151,8 @@ static bool event_is_known(struct iio_event_data *event)
case IIO_EV_TYPE_ROC:
case IIO_EV_TYPE_THRESH_ADAPTIVE:
case IIO_EV_TYPE_MAG_ADAPTIVE:
+ case IIO_EV_TYPE_TRANSITION:
+ case IIO_EV_TYPE_INSTANCE:
break;
default:
return false;
@@ -146,6 +162,7 @@ static bool event_is_known(struct iio_event_data *event)
case IIO_EV_DIR_EITHER:
case IIO_EV_DIR_RISING:
case IIO_EV_DIR_FALLING:
+ case IIO_EV_DIR_NONE:
break;
default:
return false;
@@ -186,9 +203,11 @@ static void print_event(struct iio_event_data *event)
else if (chan >= 0)
printf("channel: %d, ", chan);
- printf("evtype: %s, direction: %s\n",
- iio_ev_type_text[ev_type],
- iio_ev_dir_text[dir]);
+ printf("evtype: %s", iio_ev_type_text[ev_type]);
+
+ if (dir != IIO_EV_DIR_NONE)
+ printf(", direction: %s", iio_ev_dir_text[dir]);
+ printf("\n");
}
int main(int argc, char **argv)
--
1.9.1
Adds support for the new channel types in the dummy driver:
* a new channel IIO_ACTIVITY
* two state transition events (running and walking)
* a new channel IIO_STEPS and support for reading and writing
pedometer step counter
* step detect event
* a new channel IIO_HEIGHT and support for reading and writing
height
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
drivers/staging/iio/iio_simple_dummy.c | 199 +++++++++++++++++++++++---
drivers/staging/iio/iio_simple_dummy.h | 5 +
drivers/staging/iio/iio_simple_dummy_events.c | 38 +++++
3 files changed, 223 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index bf78e6f..5430aed 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -69,6 +69,34 @@ static const struct iio_event_spec iio_dummy_event = {
.mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
};
+/*
+ * simple step detect event - triggered when a step is detected
+ */
+static const struct iio_event_spec step_detect_event = {
+ .type = IIO_EV_TYPE_INSTANCE,
+ .dir = IIO_EV_DIR_NONE,
+ .mask_separate = BIT(IIO_EV_INFO_ENABLE),
+};
+
+/*
+ * simple transition event - triggered when the reported running confidence
+ * value rises above a threshold value
+ */
+static const struct iio_event_spec iio_running_event = {
+ .type = IIO_EV_TYPE_TRANSITION,
+ .dir = IIO_EV_DIR_RISING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
+};
+
+/*
+ * simple transition event - triggered when the reported walking confidence
+ * value falls under a threshold value
+ */
+static const struct iio_event_spec iio_walking_event = {
+ .type = IIO_EV_TYPE_TRANSITION,
+ .dir = IIO_EV_DIR_FALLING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
+};
#endif
/*
@@ -215,6 +243,42 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
.indexed = 1,
.channel = 0,
},
+ {
+ .type = IIO_STEPS,
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_ENABLE),
+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+ .scan_index = -1,
+#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
+ .event_spec = &step_detect_event,
+ .num_event_specs = 1,
+#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
+ },
+ {
+ .type = IIO_HEIGHT,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+ .scan_index = -1,
+ },
+ {
+ .type = IIO_ACTIVITY,
+ .modified = 1,
+ .channel2 = IIO_MOD_RUNNING,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
+ .event_spec = &iio_running_event,
+ .num_event_specs = 1,
+#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
+ },
+ {
+ .type = IIO_ACTIVITY,
+ .modified = 1,
+ .channel2 = IIO_MOD_WALKING,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
+ .event_spec = &iio_walking_event,
+ .num_event_specs = 1,
+#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
+ },
};
/**
@@ -259,6 +323,34 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
*val = st->accel_val;
ret = IIO_VAL_INT;
break;
+ case IIO_HEIGHT:
+ *val = st->height;
+ ret = IIO_VAL_INT;
+ break;
+ default:
+ break;
+ }
+ break;
+ case IIO_CHAN_INFO_PROCESSED:
+ switch (chan->type) {
+ case IIO_STEPS:
+ *val = st->steps;
+ ret = IIO_VAL_INT;
+ break;
+ case IIO_ACTIVITY:
+ switch (chan->channel2) {
+ case IIO_MOD_RUNNING:
+ *val = st->activity_running;
+ ret = IIO_VAL_INT;
+ break;
+ case IIO_MOD_WALKING:
+ *val = st->activity_walking;
+ ret = IIO_VAL_INT;
+ break;
+ default:
+ break;
+ }
+ break;
default:
break;
}
@@ -269,18 +361,29 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
ret = IIO_VAL_INT;
break;
case IIO_CHAN_INFO_SCALE:
- switch (chan->differential) {
- case 0:
- /* only single ended adc -> 0.001333 */
- *val = 0;
- *val2 = 1333;
- ret = IIO_VAL_INT_PLUS_MICRO;
+ switch (chan->type) {
+ case IIO_VOLTAGE:
+ switch (chan->differential) {
+ case 0:
+ /* only single ended adc -> 0.001333 */
+ *val = 0;
+ *val2 = 1333;
+ ret = IIO_VAL_INT_PLUS_MICRO;
+ break;
+ case 1:
+ /* all differential adc channels ->
+ * 0.000001344 */
+ *val = 0;
+ *val2 = 1344;
+ ret = IIO_VAL_INT_PLUS_NANO;
+ }
+ break;
+ case IIO_HEIGHT:
+ *val = 1;
+ ret = IIO_VAL_INT;
+ break;
+ default:
break;
- case 1:
- /* all differential adc channels -> 0.000001344 */
- *val = 0;
- *val2 = 1344;
- ret = IIO_VAL_INT_PLUS_NANO;
}
break;
case IIO_CHAN_INFO_CALIBBIAS:
@@ -298,6 +401,16 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
*val2 = 33;
ret = IIO_VAL_INT_PLUS_NANO;
break;
+ case IIO_CHAN_INFO_ENABLE:
+ switch (chan->type) {
+ case IIO_STEPS:
+ *val = st->steps_enabled;
+ ret = IIO_VAL_INT;
+ break;
+ default:
+ break;
+ }
+ break;
default:
break;
}
@@ -330,14 +443,50 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- if (chan->output == 0)
+ switch (chan->type) {
+ case IIO_VOLTAGE:
+ if (chan->output == 0)
+ return -EINVAL;
+
+ /* Locking not required as writing single value */
+ mutex_lock(&st->lock);
+ st->dac_val = val;
+ mutex_unlock(&st->lock);
+ return 0;
+ case IIO_HEIGHT:
+ mutex_lock(&st->lock);
+ st->height = val;
+ mutex_unlock(&st->lock);
+ return 0;
+ default:
return -EINVAL;
-
- /* Locking not required as writing single value */
- mutex_lock(&st->lock);
- st->dac_val = val;
- mutex_unlock(&st->lock);
- return 0;
+ }
+ case IIO_CHAN_INFO_PROCESSED:
+ switch (chan->type) {
+ case IIO_STEPS:
+ mutex_lock(&st->lock);
+ st->steps = val;
+ mutex_unlock(&st->lock);
+ return 0;
+ case IIO_ACTIVITY:
+ if (val < 0)
+ val = 0;
+ if (val > 100)
+ val = 100;
+ switch (chan->channel2) {
+ case IIO_MOD_RUNNING:
+ st->activity_running = val;
+ return 0;
+ case IIO_MOD_WALKING:
+ st->activity_walking = val;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+ break;
+ default:
+ return -EINVAL;
+ }
case IIO_CHAN_INFO_CALIBSCALE:
mutex_lock(&st->lock);
/* Compare against table - hard matching here */
@@ -356,7 +505,16 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
st->accel_calibbias = val;
mutex_unlock(&st->lock);
return 0;
-
+ case IIO_CHAN_INFO_ENABLE:
+ switch (chan->type) {
+ case IIO_STEPS:
+ mutex_lock(&st->lock);
+ st->steps_enabled = val;
+ mutex_unlock(&st->lock);
+ return 0;
+ default:
+ return -EINVAL;
+ }
default:
return -EINVAL;
}
@@ -395,6 +553,9 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
st->accel_val = 34;
st->accel_calibbias = -7;
st->accel_calibscale = &dummy_scales[0];
+ st->steps = 47;
+ st->activity_running = 98;
+ st->activity_walking = 4;
return 0;
}
diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
index 1a74e26..d49aec3 100644
--- a/drivers/staging/iio/iio_simple_dummy.h
+++ b/drivers/staging/iio/iio_simple_dummy.h
@@ -32,9 +32,14 @@ struct iio_dummy_state {
int differential_adc_val[2];
int accel_val;
int accel_calibbias;
+ int activity_running;
+ int activity_walking;
const struct iio_dummy_accel_calibscale *accel_calibscale;
struct mutex lock;
struct iio_dummy_regs *regs;
+ int steps_enabled;
+ int steps;
+ int height;
#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
int event_irq;
int event_val;
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index 719dfa5..ae37620 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -66,12 +66,23 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
*/
switch (chan->type) {
case IIO_VOLTAGE:
+ case IIO_ACTIVITY:
switch (type) {
case IIO_EV_TYPE_THRESH:
if (dir == IIO_EV_DIR_RISING)
st->event_en = state;
else
return -EINVAL;
+ case IIO_EV_TYPE_TRANSITION:
+ st->event_en = state;
+ break;
+ default:
+ return -EINVAL;
+ }
+ case IIO_STEPS:
+ switch (type) {
+ case IIO_EV_TYPE_INSTANCE:
+ st->event_en = state;
break;
default:
return -EINVAL;
@@ -161,6 +172,33 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
IIO_EV_TYPE_THRESH, 0, 0, 0),
iio_get_time_ns());
break;
+ case 1:
+ if (st->activity_running > st->event_val)
+ iio_push_event(indio_dev,
+ IIO_EVENT_CODE(IIO_ACTIVITY, 0,
+ IIO_MOD_RUNNING,
+ IIO_EV_DIR_RISING,
+ IIO_EV_TYPE_TRANSITION,
+ 0, 0, 0),
+ iio_get_time_ns());
+ break;
+ case 2:
+ if (st->activity_walking < st->event_val)
+ iio_push_event(indio_dev,
+ IIO_EVENT_CODE(IIO_ACTIVITY, 0,
+ IIO_MOD_WALKING,
+ IIO_EV_DIR_FALLING,
+ IIO_EV_TYPE_TRANSITION,
+ 0, 0, 0),
+ iio_get_time_ns());
+ break;
+ case 3:
+ iio_push_event(indio_dev,
+ IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
+ IIO_EV_DIR_NONE,
+ IIO_EV_TYPE_INSTANCE, 0, 0, 0),
+ iio_get_time_ns());
+ break;
default:
break;
}
--
1.9.1
From: Irina Tirdea <[email protected]>
For some events (e.g.: step detector) a direction does not make sense.
Add IIO_EV_DIR_NONE to be used with such events and generate sysfs event
attributes that do not contain direction.
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
drivers/iio/industrialio-event.c | 12 +++++++++---
include/linux/iio/types.h | 1 +
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index afcf154..a9c9f34 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -328,9 +328,15 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
for_each_set_bit(i, mask, sizeof(*mask)*8) {
if (i >= ARRAY_SIZE(iio_ev_info_text))
return -EINVAL;
- postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
- iio_ev_type_text[type], iio_ev_dir_text[dir],
- iio_ev_info_text[i]);
+ if (dir != IIO_EV_DIR_NONE)
+ postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
+ iio_ev_type_text[type],
+ iio_ev_dir_text[dir],
+ iio_ev_info_text[i]);
+ else
+ postfix = kasprintf(GFP_KERNEL, "%s_%s",
+ iio_ev_type_text[type],
+ iio_ev_info_text[i]);
if (postfix == NULL)
return -ENOMEM;
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index a08ee6c..9a1cc01 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -87,6 +87,7 @@ enum iio_event_direction {
IIO_EV_DIR_EITHER,
IIO_EV_DIR_RISING,
IIO_EV_DIR_FALLING,
+ IIO_EV_DIR_NONE,
};
#define IIO_VAL_INT 1
--
1.9.1
This channel will be used for exposing information about
activity composite sensors. Activities supported so far:
* running
* jogging
* walking
* still
TRANSITION event is used to signal a change in the activity
state.
We associate a confidence interval for each activity expressed
as a percentage from 0 to 100.
* 0, means the sensor IS NOT reporting that activity.
* 100, means the sensor IS reporting that activity.
Users of this interface have two possibile means to gather
information about the ongoing activities.
1. Event based, via event file descriptor
* sensor may report an event when ENTERING an activity or LEAVING
an activity based on a threshold value.
* drivers will wake up applications waiting data on the event fd
2. Polling, by reading the sysfs associated attribute files:
* /sys/bus/iio/devices/iio:device0/in_activity_running_input
expressed as percentage confidence value from 0 to 100.
This will offer an interface for Android significant motion
composite sensor defined here:
http://source.android.com/devices/sensors/composite_sensors.html
Activities listed above are supported by Freescale's MMA9553 sensor:
http://freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-iio | 44 +++++++++++++++++++++++++++++++++
drivers/iio/industrialio-core.c | 5 ++++
drivers/iio/industrialio-event.c | 1 +
include/linux/iio/types.h | 8 +++++-
4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index d760b02..12d0385 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -776,6 +776,40 @@ Description:
met before an event is generated. If direction is not
specified then this period applies to both directions.
+What: /sys/.../events/in_activity_still_transition_rising_en
+What: /sys/.../events/in_activity_still_transition_falling_en
+What: /sys/.../events/in_activity_walking_transition_rising_en
+What: /sys/.../events/in_activity_walking_transition_falling_en
+What: /sys/.../events/in_activity_jogging_transition_rising_en
+What: /sys/.../events/in_activity_jogging_transition_falling_en
+What: /sys/.../events/in_activity_running_transition_rising_en
+What: /sys/.../events/in_activity_running_transition_falling_en
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ Enables or disables activitity events. Depending on direction
+ an event is generated when sensor ENTERS or LEAVES a given state.
+
+What: /sys/.../events/in_activity_still_transition_rising_value
+What: /sys/.../events/in_activity_still_transition_falling_value
+What: /sys/.../events/in_activity_walking_transition_rising_value
+What: /sys/.../events/in_activity_walking_transition_falling_value
+What: /sys/.../events/in_activity_jogging_transition_rising_value
+What: /sys/.../events/in_activity_jogging_transition_falling_value
+What: /sys/.../events/in_activity_running_transition_rising_value
+What: /sys/.../events/in_activity_running_transition_falling_value
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ Confidence value (in units as percentage) to be used
+ for deciding when an event should be generated. E.g for
+ running: If the confidence value reported by the sensor
+ is greater then in_activity_running_transition_rising_value
+ then the sensor ENTERS running state. Conversely, if the
+ confidence value reported by the sensor is lower than
+ in_activity_running_transition_rising_value then the sensor
+ is LEAVING running state.
+
What: /sys/.../iio:deviceX/events/in_accel_mag_en
What: /sys/.../iio:deviceX/events/in_accel_mag_rising_en
What: /sys/.../iio:deviceX/events/in_accel_mag_falling_en
@@ -942,6 +976,16 @@ Description:
and the relevant _type attributes to establish the data storage
format.
+What: /sys/.../iio:deviceX/in_activity_still_input
+What: /sys/.../iio:deviceX/in_activity_walking_input
+What: /sys/.../iio:deviceX/in_activity_jogging_input
+What: /sys/.../iio:deviceX/in_activity_running_input
+KernelVersion: 3.19
+Contact: [email protected]
+Description:
+ This attribute is used to read the confidence for an activity
+ expressed in units as percentage.
+
What: /sys/.../iio:deviceX/in_anglvel_z_quadrature_correction_raw
KernelVersion: 2.6.38
Contact: [email protected]
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index af3e76d..e453ef9 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -70,6 +70,7 @@ static const char * const iio_chan_type_name_spec[] = {
[IIO_CCT] = "cct",
[IIO_PRESSURE] = "pressure",
[IIO_HUMIDITYRELATIVE] = "humidityrelative",
+ [IIO_ACTIVITY] = "activity",
};
static const char * const iio_modifier_names[] = {
@@ -91,6 +92,10 @@ static const char * const iio_modifier_names[] = {
[IIO_MOD_NORTH_TRUE] = "from_north_true",
[IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
[IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
+ [IIO_MOD_RUNNING] = "running",
+ [IIO_MOD_JOGGING] = "jogging",
+ [IIO_MOD_WALKING] = "walking",
+ [IIO_MOD_STILL] = "still",
};
/* relies on pairs of these shared then separate */
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 0c1e37e..afcf154 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -197,6 +197,7 @@ static const char * const iio_ev_type_text[] = {
[IIO_EV_TYPE_ROC] = "roc",
[IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
[IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
+ [IIO_EV_TYPE_TRANSITION] = "transition",
};
static const char * const iio_ev_dir_text[] = {
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 4a2af8a..a08ee6c 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -30,6 +30,7 @@ enum iio_chan_type {
IIO_CCT,
IIO_PRESSURE,
IIO_HUMIDITYRELATIVE,
+ IIO_ACTIVITY,
};
enum iio_modifier {
@@ -59,7 +60,11 @@ enum iio_modifier {
IIO_MOD_NORTH_MAGN,
IIO_MOD_NORTH_TRUE,
IIO_MOD_NORTH_MAGN_TILT_COMP,
- IIO_MOD_NORTH_TRUE_TILT_COMP
+ IIO_MOD_NORTH_TRUE_TILT_COMP,
+ IIO_MOD_RUNNING,
+ IIO_MOD_JOGGING,
+ IIO_MOD_WALKING,
+ IIO_MOD_STILL,
};
enum iio_event_type {
@@ -68,6 +73,7 @@ enum iio_event_type {
IIO_EV_TYPE_ROC,
IIO_EV_TYPE_THRESH_ADAPTIVE,
IIO_EV_TYPE_MAG_ADAPTIVE,
+ IIO_EV_TYPE_TRANSITION,
};
enum iio_event_info {
--
1.9.1
We need a way to store events generated by iio_dummy_evgen module,
in order to correctly process IRQs in iio_simple_dummy_events.
For the moment, we add two registers:
* id_reg - ID register, stores the source of the event
* id_data - DATA register, stores the type of the event
e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
id_reg 0x02, id_data 0x04
This means, event of type 4 was generated by fake device 2.
We currently use a hardcoded mapping of virtual events to IIO events.
Signed-off-by: Irina Tirdea <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
drivers/staging/iio/iio_dummy_evgen.c | 16 ++++++++++++++++
drivers/staging/iio/iio_dummy_evgen.h | 6 ++++++
drivers/staging/iio/iio_simple_dummy.h | 2 ++
drivers/staging/iio/iio_simple_dummy_events.c | 23 ++++++++++++++++++-----
4 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
index 5a804f1..d44f138 100644
--- a/drivers/staging/iio/iio_dummy_evgen.c
+++ b/drivers/staging/iio/iio_dummy_evgen.c
@@ -33,6 +33,7 @@
* @base: base of irq range
* @enabled: mask of which irqs are enabled
* @inuse: mask of which irqs are connected
+ * @regs: irq regs we are faking
* @lock: protect the evgen state
*/
struct iio_dummy_eventgen {
@@ -40,6 +41,7 @@ struct iio_dummy_eventgen {
int base;
bool enabled[IIO_EVENTGEN_NO];
bool inuse[IIO_EVENTGEN_NO];
+ struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
struct mutex lock;
};
@@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
}
EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
+struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
+{
+ return &iio_evgen->regs[irq - iio_evgen->base];
+}
+EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
+
static void iio_dummy_evgen_free(void)
{
irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
@@ -153,6 +161,14 @@ static ssize_t iio_evgen_poke(struct device *dev,
size_t len)
{
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+ unsigned long event, ret;
+
+ ret = kstrtoul(buf, 10, &event);
+ if (ret)
+ return ret;
+
+ iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
+ iio_evgen->regs[this_attr->address].reg_data = event;
if (iio_evgen->enabled[this_attr->address])
handle_nested_irq(iio_evgen->base + this_attr->address);
diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/staging/iio/iio_dummy_evgen.h
index d8845e2..3ef3a1c 100644
--- a/drivers/staging/iio/iio_dummy_evgen.h
+++ b/drivers/staging/iio/iio_dummy_evgen.h
@@ -1,2 +1,8 @@
+struct iio_dummy_regs {
+ u32 reg_id;
+ u32 reg_data;
+};
+
+struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
int iio_dummy_evgen_get_irq(void);
int iio_dummy_evgen_release_irq(int irq);
diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
index b126196..1a74e26 100644
--- a/drivers/staging/iio/iio_simple_dummy.h
+++ b/drivers/staging/iio/iio_simple_dummy.h
@@ -11,6 +11,7 @@
#include <linux/kernel.h>
struct iio_dummy_accel_calibscale;
+struct iio_dummy_regs;
/**
* struct iio_dummy_state - device instance specific state.
@@ -33,6 +34,7 @@ struct iio_dummy_state {
int accel_calibbias;
const struct iio_dummy_accel_calibscale *accel_calibscale;
struct mutex lock;
+ struct iio_dummy_regs *regs;
#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
int event_irq;
int event_val;
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index 64b45b0..719dfa5 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
+ struct iio_dummy_state *st = iio_priv(indio_dev);
+
+ dev_dbg(&indio_dev->dev, "id %x event %x\n",
+ st->regs->reg_id, st->regs->reg_data);
+
+ switch (st->regs->reg_data) {
+ case 0:
+ iio_push_event(indio_dev,
+ IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
+ IIO_EV_DIR_RISING,
+ IIO_EV_TYPE_THRESH, 0, 0, 0),
+ iio_get_time_ns());
+ break;
+ default:
+ break;
+ }
- iio_push_event(indio_dev,
- IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
- IIO_EV_DIR_RISING,
- IIO_EV_TYPE_THRESH, 0, 0, 0),
- iio_get_time_ns());
return IRQ_HANDLED;
}
@@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
ret = st->event_irq;
goto error_ret;
}
+ st->regs = iio_dummy_evgen_get_regs(st->event_irq);
+
ret = request_threaded_irq(st->event_irq,
NULL,
&iio_simple_dummy_event_handler,
--
1.9.1
Daniel Baluta schrieb am 09.10.2014 14:39:
> From: Irina Tirdea <[email protected]>
>
> These changes are needed to support the functionality of a pedometer.
> A pedometer has two basic functionalities: step counter and step detector.
>
> The step counter needs to be enabled and then it will count the steps
> in its hardware register. Whenever the application needs to check
> the step count, it will read the step counter register. To support the
> step counter a new channel type STEPS is added. Since the pedometer needs
> to be enabled first so that the hardware can count and store the steps,
> we need a specific ENABLE channel info mask.
>
> The step detector will generate an interrupt each time a step is detected.
> To support this functionality we add a new event type INSTANCE.
>
Hi,
I was wondering, if it would be better to name this channel somehow more generic. What you are actually counting are some pulses, and only the implementation of the hardware leads to the interpretation of these pulses as for example steps.
Other devices for this category would be pulse counters - either stand alone, or as part of SoCs. Some use cases I could think of are: liquid/gas flow measurements, engine rotation/RPM counts, object counts, ...
Any opinions?
Thanks
Hartmut
> For more information on the Android requirements for step counter and step
> detector see:
> http://source.android.com/devices/sensors/composite_sensors.html#counter
> and http://source.android.com/devices/sensors/composite_sensors.html#detector.
>
> A device that has the pedometer functionality this interface needs to
> support is Freescale's MMA9553L:
> http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-bus-iio | 22 ++++++++++++++++++++++
> drivers/iio/industrialio-core.c | 2 ++
> drivers/iio/industrialio-event.c | 1 +
> include/linux/iio/iio.h | 1 +
> include/linux/iio/types.h | 2 ++
> 5 files changed, 28 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 12d0385..3557a69 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -842,6 +842,13 @@ Description:
> number or direction is not specified, applies to all channels of
> this type.
>
> +What: /sys/.../events/in_steps_instance_en
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Enables or disables step detection. Each time the user takes a step an
> + event of this type will be generated.
> +
> What: /sys/bus/iio/devices/iio:deviceX/trigger/current_trigger
> KernelVersion: 2.6.35
> Contact: [email protected]
> @@ -1072,3 +1079,18 @@ Contact: [email protected]
> Description:
> Raw value of rotation from true/magnetic north measured with
> or without compensation from tilt sensors.
> +
> +What: /sys/.../iio:deviceX/in_steps_enable
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Activates the step counter. After activation, the number of steps
> + taken by the user will be counted in hardware and exported through
> + in_steps_input.
> +
> +What: /sys/.../iio:deviceX/in_steps_input
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + This attribute is used to read the number of steps taken by the user
> + since the last reboot while activated.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index e453ef9..1e060f3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -71,6 +71,7 @@ static const char * const iio_chan_type_name_spec[] = {
> [IIO_PRESSURE] = "pressure",
> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
> [IIO_ACTIVITY] = "activity",
> + [IIO_STEPS] = "steps",
> };
>
> static const char * const iio_modifier_names[] = {
> @@ -118,6 +119,7 @@ static const char * const iio_chan_info_postfix[] = {
> [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
> [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
> [IIO_CHAN_INFO_INT_TIME] = "integration_time",
> + [IIO_CHAN_INFO_ENABLE] = "en",
> };
>
> /**
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index a9c9f34..db63d29 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -198,6 +198,7 @@ static const char * const iio_ev_type_text[] = {
> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
> [IIO_EV_TYPE_TRANSITION] = "transition",
> + [IIO_EV_TYPE_INSTANCE] = "instance",
> };
>
> static const char * const iio_ev_dir_text[] = {
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 15dc6bc..3d3f06f 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -37,6 +37,7 @@ enum iio_chan_info_enum {
> IIO_CHAN_INFO_HARDWAREGAIN,
> IIO_CHAN_INFO_HYSTERESIS,
> IIO_CHAN_INFO_INT_TIME,
> + IIO_CHAN_INFO_ENABLE,
> };
>
> enum iio_shared_by {
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index 9a1cc01..af0b6e0 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -31,6 +31,7 @@ enum iio_chan_type {
> IIO_PRESSURE,
> IIO_HUMIDITYRELATIVE,
> IIO_ACTIVITY,
> + IIO_STEPS,
> };
>
> enum iio_modifier {
> @@ -74,6 +75,7 @@ enum iio_event_type {
> IIO_EV_TYPE_THRESH_ADAPTIVE,
> IIO_EV_TYPE_MAG_ADAPTIVE,
> IIO_EV_TYPE_TRANSITION,
> + IIO_EV_TYPE_INSTANCE,
> };
>
> enum iio_event_info {
>
On 09/10/14 13:39, Daniel Baluta wrote:
> We need a way to store events generated by iio_dummy_evgen module,
> in order to correctly process IRQs in iio_simple_dummy_events.
>
> For the moment, we add two registers:
>
> * id_reg - ID register, stores the source of the event
> * id_data - DATA register, stores the type of the event
>
> e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
>
> id_reg 0x02, id_data 0x04
>
> This means, event of type 4 was generated by fake device 2.
>
> We currently use a hardcoded mapping of virtual events to IIO events.
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
Applied to the togreg branch of iio.git.
Initially pushed out as testing for the autobuilders to play with it.
> ---
> drivers/staging/iio/iio_dummy_evgen.c | 16 ++++++++++++++++
> drivers/staging/iio/iio_dummy_evgen.h | 6 ++++++
> drivers/staging/iio/iio_simple_dummy.h | 2 ++
> drivers/staging/iio/iio_simple_dummy_events.c | 23 ++++++++++++++++++-----
> 4 files changed, 42 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
> index 5a804f1..d44f138 100644
> --- a/drivers/staging/iio/iio_dummy_evgen.c
> +++ b/drivers/staging/iio/iio_dummy_evgen.c
> @@ -33,6 +33,7 @@
> * @base: base of irq range
> * @enabled: mask of which irqs are enabled
> * @inuse: mask of which irqs are connected
> + * @regs: irq regs we are faking
> * @lock: protect the evgen state
> */
> struct iio_dummy_eventgen {
> @@ -40,6 +41,7 @@ struct iio_dummy_eventgen {
> int base;
> bool enabled[IIO_EVENTGEN_NO];
> bool inuse[IIO_EVENTGEN_NO];
> + struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
> struct mutex lock;
> };
>
> @@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
> }
> EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
>
> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
> +{
> + return &iio_evgen->regs[irq - iio_evgen->base];
> +}
> +EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
> +
> static void iio_dummy_evgen_free(void)
> {
> irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
> @@ -153,6 +161,14 @@ static ssize_t iio_evgen_poke(struct device *dev,
> size_t len)
> {
> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> + unsigned long event, ret;
> +
> + ret = kstrtoul(buf, 10, &event);
> + if (ret)
> + return ret;
> +
> + iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
> + iio_evgen->regs[this_attr->address].reg_data = event;
>
> if (iio_evgen->enabled[this_attr->address])
> handle_nested_irq(iio_evgen->base + this_attr->address);
> diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/staging/iio/iio_dummy_evgen.h
> index d8845e2..3ef3a1c 100644
> --- a/drivers/staging/iio/iio_dummy_evgen.h
> +++ b/drivers/staging/iio/iio_dummy_evgen.h
> @@ -1,2 +1,8 @@
> +struct iio_dummy_regs {
> + u32 reg_id;
> + u32 reg_data;
> +};
> +
> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
> int iio_dummy_evgen_get_irq(void);
> int iio_dummy_evgen_release_irq(int irq);
> diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
> index b126196..1a74e26 100644
> --- a/drivers/staging/iio/iio_simple_dummy.h
> +++ b/drivers/staging/iio/iio_simple_dummy.h
> @@ -11,6 +11,7 @@
> #include <linux/kernel.h>
>
> struct iio_dummy_accel_calibscale;
> +struct iio_dummy_regs;
>
> /**
> * struct iio_dummy_state - device instance specific state.
> @@ -33,6 +34,7 @@ struct iio_dummy_state {
> int accel_calibbias;
> const struct iio_dummy_accel_calibscale *accel_calibscale;
> struct mutex lock;
> + struct iio_dummy_regs *regs;
> #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> int event_irq;
> int event_val;
> diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
> index 64b45b0..719dfa5 100644
> --- a/drivers/staging/iio/iio_simple_dummy_events.c
> +++ b/drivers/staging/iio/iio_simple_dummy_events.c
> @@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
> static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
> {
> struct iio_dev *indio_dev = private;
> + struct iio_dummy_state *st = iio_priv(indio_dev);
> +
> + dev_dbg(&indio_dev->dev, "id %x event %x\n",
> + st->regs->reg_id, st->regs->reg_data);
> +
> + switch (st->regs->reg_data) {
> + case 0:
> + iio_push_event(indio_dev,
> + IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
> + IIO_EV_DIR_RISING,
> + IIO_EV_TYPE_THRESH, 0, 0, 0),
> + iio_get_time_ns());
> + break;
> + default:
> + break;
> + }
>
> - iio_push_event(indio_dev,
> - IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
> - IIO_EV_DIR_RISING,
> - IIO_EV_TYPE_THRESH, 0, 0, 0),
> - iio_get_time_ns());
> return IRQ_HANDLED;
> }
>
> @@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
> ret = st->event_irq;
> goto error_ret;
> }
> + st->regs = iio_dummy_evgen_get_regs(st->event_irq);
> +
> ret = request_threaded_irq(st->event_irq,
> NULL,
> &iio_simple_dummy_event_handler,
>
On 09/10/14 13:39, Daniel Baluta wrote:
> This channel will be used for exposing information about
> activity composite sensors. Activities supported so far:
> * running
> * jogging
> * walking
> * still
>
> TRANSITION event is used to signal a change in the activity
> state.
>
> We associate a confidence interval for each activity expressed
> as a percentage from 0 to 100.
> * 0, means the sensor IS NOT reporting that activity.
> * 100, means the sensor IS reporting that activity.
>
> Users of this interface have two possibile means to gather
> information about the ongoing activities.
>
> 1. Event based, via event file descriptor
> * sensor may report an event when ENTERING an activity or LEAVING
> an activity based on a threshold value.
> * drivers will wake up applications waiting data on the event fd
>
> 2. Polling, by reading the sysfs associated attribute files:
> * /sys/bus/iio/devices/iio:device0/in_activity_running_input
> expressed as percentage confidence value from 0 to 100.
>
> This will offer an interface for Android significant motion
> composite sensor defined here:
> http://source.android.com/devices/sensors/composite_sensors.html
>
> Activities listed above are supported by Freescale's MMA9553 sensor:
> http://freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
I don't see why we need the transition event. A transition is simply
a threshold rising (or falling) event much like any other - just
on a confidence interval.
So it would be possible to be interested in the confidence that are not
sitting rising above 20% on the basis that some other sensor needs enabling.
See below for resulting suggestions.
Other than that little point this looks good to me.
> ---
> Documentation/ABI/testing/sysfs-bus-iio | 44 +++++++++++++++++++++++++++++++++
> drivers/iio/industrialio-core.c | 5 ++++
> drivers/iio/industrialio-event.c | 1 +
> include/linux/iio/types.h | 8 +++++-
> 4 files changed, 57 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index d760b02..12d0385 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -776,6 +776,40 @@ Description:
> met before an event is generated. If direction is not
> specified then this period applies to both directions.
>
> +What: /sys/.../events/in_activity_still_transition_rising_en
What: /sys/.../events/in_activity_threshold_rising_en
> +What: /sys/.../events/in_activity_still_transition_falling_en
What: /sys/.../events/in_activity_threshold_falling_en
etc
> +What: /sys/.../events/in_activity_walking_transition_rising_en
> +What: /sys/.../events/in_activity_walking_transition_falling_en
> +What: /sys/.../events/in_activity_jogging_transition_rising_en
> +What: /sys/.../events/in_activity_jogging_transition_falling_en
> +What: /sys/.../events/in_activity_running_transition_rising_en
> +What: /sys/.../events/in_activity_running_transition_falling_en
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Enables or disables activitity events. Depending on direction
> + an event is generated when sensor ENTERS or LEAVES a given state.
> +
> +What: /sys/.../events/in_activity_still_transition_rising_value
What: /sys/.../events/in_activity_still_threshold_rising_value etc
> +What: /sys/.../events/in_activity_still_transition_falling_value
> +What: /sys/.../events/in_activity_walking_transition_rising_value
> +What: /sys/.../events/in_activity_walking_transition_falling_value
> +What: /sys/.../events/in_activity_jogging_transition_rising_value
> +What: /sys/.../events/in_activity_jogging_transition_falling_value
> +What: /sys/.../events/in_activity_running_transition_rising_value
> +What: /sys/.../events/in_activity_running_transition_falling_value
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Confidence value (in units as percentage) to be used
> + for deciding when an event should be generated. E.g for
> + running: If the confidence value reported by the sensor
> + is greater then in_activity_running_transition_rising_value
> + then the sensor ENTERS running state. Conversely, if the
> + confidence value reported by the sensor is lower than
> + in_activity_running_transition_rising_value then the sensor
> + is LEAVING running state.
> +
> What: /sys/.../iio:deviceX/events/in_accel_mag_en
> What: /sys/.../iio:deviceX/events/in_accel_mag_rising_en
> What: /sys/.../iio:deviceX/events/in_accel_mag_falling_en
> @@ -942,6 +976,16 @@ Description:
> and the relevant _type attributes to establish the data storage
> format.
>
> +What: /sys/.../iio:deviceX/in_activity_still_input
> +What: /sys/.../iio:deviceX/in_activity_walking_input
> +What: /sys/.../iio:deviceX/in_activity_jogging_input
> +What: /sys/.../iio:deviceX/in_activity_running_input
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + This attribute is used to read the confidence for an activity
> + expressed in units as percentage.
> +
> What: /sys/.../iio:deviceX/in_anglvel_z_quadrature_correction_raw
> KernelVersion: 2.6.38
> Contact: [email protected]
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index af3e76d..e453ef9 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -70,6 +70,7 @@ static const char * const iio_chan_type_name_spec[] = {
> [IIO_CCT] = "cct",
> [IIO_PRESSURE] = "pressure",
> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
> + [IIO_ACTIVITY] = "activity",
> };
>
> static const char * const iio_modifier_names[] = {
> @@ -91,6 +92,10 @@ static const char * const iio_modifier_names[] = {
> [IIO_MOD_NORTH_TRUE] = "from_north_true",
> [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
> [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
> + [IIO_MOD_RUNNING] = "running",
> + [IIO_MOD_JOGGING] = "jogging",
> + [IIO_MOD_WALKING] = "walking",
> + [IIO_MOD_STILL] = "still",
> };
>
> /* relies on pairs of these shared then separate */
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index 0c1e37e..afcf154 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -197,6 +197,7 @@ static const char * const iio_ev_type_text[] = {
> [IIO_EV_TYPE_ROC] = "roc",
> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
> + [IIO_EV_TYPE_TRANSITION] = "transition",
> };
>
> static const char * const iio_ev_dir_text[] = {
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index 4a2af8a..a08ee6c 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -30,6 +30,7 @@ enum iio_chan_type {
> IIO_CCT,
> IIO_PRESSURE,
> IIO_HUMIDITYRELATIVE,
> + IIO_ACTIVITY,
> };
>
> enum iio_modifier {
> @@ -59,7 +60,11 @@ enum iio_modifier {
> IIO_MOD_NORTH_MAGN,
> IIO_MOD_NORTH_TRUE,
> IIO_MOD_NORTH_MAGN_TILT_COMP,
> - IIO_MOD_NORTH_TRUE_TILT_COMP
> + IIO_MOD_NORTH_TRUE_TILT_COMP,
> + IIO_MOD_RUNNING,
> + IIO_MOD_JOGGING,
> + IIO_MOD_WALKING,
> + IIO_MOD_STILL,
> };
>
> enum iio_event_type {
> @@ -68,6 +73,7 @@ enum iio_event_type {
> IIO_EV_TYPE_ROC,
> IIO_EV_TYPE_THRESH_ADAPTIVE,
> IIO_EV_TYPE_MAG_ADAPTIVE,
> + IIO_EV_TYPE_TRANSITION,
> };
>
> enum iio_event_info {
>
On 09/10/14 13:39, Daniel Baluta wrote:
> From: Irina Tirdea <[email protected]>
>
> For some events (e.g.: step detector) a direction does not make sense.
>
> Add IIO_EV_DIR_NONE to be used with such events and generate sysfs event
> attributes that do not contain direction.
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
Happy with this one.
J
> ---
> drivers/iio/industrialio-event.c | 12 +++++++++---
> include/linux/iio/types.h | 1 +
> 2 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index afcf154..a9c9f34 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -328,9 +328,15 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
> for_each_set_bit(i, mask, sizeof(*mask)*8) {
> if (i >= ARRAY_SIZE(iio_ev_info_text))
> return -EINVAL;
> - postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
> - iio_ev_type_text[type], iio_ev_dir_text[dir],
> - iio_ev_info_text[i]);
> + if (dir != IIO_EV_DIR_NONE)
> + postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
> + iio_ev_type_text[type],
> + iio_ev_dir_text[dir],
> + iio_ev_info_text[i]);
> + else
> + postfix = kasprintf(GFP_KERNEL, "%s_%s",
> + iio_ev_type_text[type],
> + iio_ev_info_text[i]);
> if (postfix == NULL)
> return -ENOMEM;
>
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index a08ee6c..9a1cc01 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -87,6 +87,7 @@ enum iio_event_direction {
> IIO_EV_DIR_EITHER,
> IIO_EV_DIR_RISING,
> IIO_EV_DIR_FALLING,
> + IIO_EV_DIR_NONE,
> };
>
> #define IIO_VAL_INT 1
>
On 09/10/14 13:39, Daniel Baluta wrote:
> From: Irina Tirdea <[email protected]>
>
> These changes are needed to support the functionality of a pedometer.
> A pedometer has two basic functionalities: step counter and step detector.
>
> The step counter needs to be enabled and then it will count the steps
> in its hardware register. Whenever the application needs to check
> the step count, it will read the step counter register. To support the
> step counter a new channel type STEPS is added. Since the pedometer needs
> to be enabled first so that the hardware can count and store the steps,
> we need a specific ENABLE channel info mask.
Perhaps enable and zero? (thus a second hit on it would reset the counter?)
Actually you have to wonder why these don't free run and just let userspace
do the subtraction. Would make things slightly simpler all round.
Chances are we'll soon get a device that does exactly that but then I suppose
that just doesn't supply an 'enable' attribute.
>
> The step detector will generate an interrupt each time a step is detected.
> To support this functionality we add a new event type INSTANCE.
Hmm. Other option on this would be to use it as a trigger and do buffered output
of the steps counter. However, I think the approach you have is preferable.
I wonder if instance is the best name. Not that I've come up with a better
one. Btw, drop the RFC probably at this point as I suspect it means some
of my keen reviewers aren't reading the patches yet ;) I think you are rapidly
progressing beyond the RFC stage anyway!
>
> For more information on the Android requirements for step counter and step
> detector see:
> http://source.android.com/devices/sensors/composite_sensors.html#counter
> and http://source.android.com/devices/sensors/composite_sensors.html#detector.
>
> A device that has the pedometer functionality this interface needs to
> support is Freescale's MMA9553L:
> http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-bus-iio | 22 ++++++++++++++++++++++
> drivers/iio/industrialio-core.c | 2 ++
> drivers/iio/industrialio-event.c | 1 +
> include/linux/iio/iio.h | 1 +
> include/linux/iio/types.h | 2 ++
> 5 files changed, 28 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 12d0385..3557a69 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -842,6 +842,13 @@ Description:
> number or direction is not specified, applies to all channels of
> this type.
>
> +What: /sys/.../events/in_steps_instance_en
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Enables or disables step detection. Each time the user takes a step an
> + event of this type will be generated.
> +
> What: /sys/bus/iio/devices/iio:deviceX/trigger/current_trigger
> KernelVersion: 2.6.35
> Contact: [email protected]
> @@ -1072,3 +1079,18 @@ Contact: [email protected]
> Description:
> Raw value of rotation from true/magnetic north measured with
> or without compensation from tilt sensors.
> +
> +What: /sys/.../iio:deviceX/in_steps_enable
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + Activates the step counter. After activation, the number of steps
> + taken by the user will be counted in hardware and exported through
> + in_steps_input.
> +
> +What: /sys/.../iio:deviceX/in_steps_input
> +KernelVersion: 3.19
> +Contact: [email protected]
> +Description:
> + This attribute is used to read the number of steps taken by the user
> + since the last reboot while activated.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index e453ef9..1e060f3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -71,6 +71,7 @@ static const char * const iio_chan_type_name_spec[] = {
> [IIO_PRESSURE] = "pressure",
> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
> [IIO_ACTIVITY] = "activity",
> + [IIO_STEPS] = "steps",
> };
>
> static const char * const iio_modifier_names[] = {
> @@ -118,6 +119,7 @@ static const char * const iio_chan_info_postfix[] = {
> [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
> [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
> [IIO_CHAN_INFO_INT_TIME] = "integration_time",
> + [IIO_CHAN_INFO_ENABLE] = "en",
you have en here and enable in the docs.
> };
>
> /**
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index a9c9f34..db63d29 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -198,6 +198,7 @@ static const char * const iio_ev_type_text[] = {
> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
> [IIO_EV_TYPE_TRANSITION] = "transition",
> + [IIO_EV_TYPE_INSTANCE] = "instance",
> };
>
> static const char * const iio_ev_dir_text[] = {
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 15dc6bc..3d3f06f 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -37,6 +37,7 @@ enum iio_chan_info_enum {
> IIO_CHAN_INFO_HARDWAREGAIN,
> IIO_CHAN_INFO_HYSTERESIS,
> IIO_CHAN_INFO_INT_TIME,
> + IIO_CHAN_INFO_ENABLE,
> };
>
> enum iio_shared_by {
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index 9a1cc01..af0b6e0 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -31,6 +31,7 @@ enum iio_chan_type {
> IIO_PRESSURE,
> IIO_HUMIDITYRELATIVE,
> IIO_ACTIVITY,
> + IIO_STEPS,
> };
>
> enum iio_modifier {
> @@ -74,6 +75,7 @@ enum iio_event_type {
> IIO_EV_TYPE_THRESH_ADAPTIVE,
> IIO_EV_TYPE_MAG_ADAPTIVE,
> IIO_EV_TYPE_TRANSITION,
> + IIO_EV_TYPE_INSTANCE,
> };
>
> enum iio_event_info {
>
On 24/10/14 23:31, Hartmut Knaack wrote:
> Daniel Baluta schrieb am 09.10.2014 14:39:
>> From: Irina Tirdea <[email protected]>
>>
>> These changes are needed to support the functionality of a pedometer.
>> A pedometer has two basic functionalities: step counter and step detector.
>>
>> The step counter needs to be enabled and then it will count the steps
>> in its hardware register. Whenever the application needs to check
>> the step count, it will read the step counter register. To support the
>> step counter a new channel type STEPS is added. Since the pedometer needs
>> to be enabled first so that the hardware can count and store the steps,
>> we need a specific ENABLE channel info mask.
>>
>> The step detector will generate an interrupt each time a step is detected.
>> To support this functionality we add a new event type INSTANCE.
>>
> Hi,
> I was wondering, if it would be better to name this channel somehow more generic. What you are actually counting are some pulses, and only the implementation of the hardware leads to the interpretation of these pulses as for example steps.
> Other devices for this category would be pulse counters - either stand alone, or as part of SoCs. Some use cases I could think of are: liquid/gas flow measurements, engine rotation/RPM counts, object counts, ...
> Any opinions?
I agree there might be potential here for a broader interface... RPM however
would be a rotational speed measurement and hence in radians / second or
radians if just a count of pulses off an encoder.
We have just recently had a human pulse counter as well which is another count.
The question to my mind is do we gain anything by making it more generic?
Does it help userspace? Chances of having many applications that don't care
about the difference between steps and other pulse counts is probably low
so right now I'm (slightly) falling on the side of have these more specific
counts.
So what does everyone else think?
Jonathan
> Thanks
>
> Hartmut
>> For more information on the Android requirements for step counter and step
>> detector see:
>> http://source.android.com/devices/sensors/composite_sensors.html#counter
>> and http://source.android.com/devices/sensors/composite_sensors.html#detector.
>>
>> A device that has the pedometer functionality this interface needs to
>> support is Freescale's MMA9553L:
>> http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>>
>> Signed-off-by: Irina Tirdea <[email protected]>
>> Signed-off-by: Daniel Baluta <[email protected]>
>> ---
>> Documentation/ABI/testing/sysfs-bus-iio | 22 ++++++++++++++++++++++
>> drivers/iio/industrialio-core.c | 2 ++
>> drivers/iio/industrialio-event.c | 1 +
>> include/linux/iio/iio.h | 1 +
>> include/linux/iio/types.h | 2 ++
>> 5 files changed, 28 insertions(+)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
>> index 12d0385..3557a69 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-iio
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio
>> @@ -842,6 +842,13 @@ Description:
>> number or direction is not specified, applies to all channels of
>> this type.
>>
>> +What: /sys/.../events/in_steps_instance_en
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + Enables or disables step detection. Each time the user takes a step an
>> + event of this type will be generated.
>> +
>> What: /sys/bus/iio/devices/iio:deviceX/trigger/current_trigger
>> KernelVersion: 2.6.35
>> Contact: [email protected]
>> @@ -1072,3 +1079,18 @@ Contact: [email protected]
>> Description:
>> Raw value of rotation from true/magnetic north measured with
>> or without compensation from tilt sensors.
>> +
>> +What: /sys/.../iio:deviceX/in_steps_enable
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + Activates the step counter. After activation, the number of steps
>> + taken by the user will be counted in hardware and exported through
>> + in_steps_input.
>> +
>> +What: /sys/.../iio:deviceX/in_steps_input
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + This attribute is used to read the number of steps taken by the user
>> + since the last reboot while activated.
>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>> index e453ef9..1e060f3 100644
>> --- a/drivers/iio/industrialio-core.c
>> +++ b/drivers/iio/industrialio-core.c
>> @@ -71,6 +71,7 @@ static const char * const iio_chan_type_name_spec[] = {
>> [IIO_PRESSURE] = "pressure",
>> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
>> [IIO_ACTIVITY] = "activity",
>> + [IIO_STEPS] = "steps",
>> };
>>
>> static const char * const iio_modifier_names[] = {
>> @@ -118,6 +119,7 @@ static const char * const iio_chan_info_postfix[] = {
>> [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
>> [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
>> [IIO_CHAN_INFO_INT_TIME] = "integration_time",
>> + [IIO_CHAN_INFO_ENABLE] = "en",
>> };
>>
>> /**
>> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
>> index a9c9f34..db63d29 100644
>> --- a/drivers/iio/industrialio-event.c
>> +++ b/drivers/iio/industrialio-event.c
>> @@ -198,6 +198,7 @@ static const char * const iio_ev_type_text[] = {
>> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
>> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
>> [IIO_EV_TYPE_TRANSITION] = "transition",
>> + [IIO_EV_TYPE_INSTANCE] = "instance",
>> };
>>
>> static const char * const iio_ev_dir_text[] = {
>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>> index 15dc6bc..3d3f06f 100644
>> --- a/include/linux/iio/iio.h
>> +++ b/include/linux/iio/iio.h
>> @@ -37,6 +37,7 @@ enum iio_chan_info_enum {
>> IIO_CHAN_INFO_HARDWAREGAIN,
>> IIO_CHAN_INFO_HYSTERESIS,
>> IIO_CHAN_INFO_INT_TIME,
>> + IIO_CHAN_INFO_ENABLE,
>> };
>>
>> enum iio_shared_by {
>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>> index 9a1cc01..af0b6e0 100644
>> --- a/include/linux/iio/types.h
>> +++ b/include/linux/iio/types.h
>> @@ -31,6 +31,7 @@ enum iio_chan_type {
>> IIO_PRESSURE,
>> IIO_HUMIDITYRELATIVE,
>> IIO_ACTIVITY,
>> + IIO_STEPS,
>> };
>>
>> enum iio_modifier {
>> @@ -74,6 +75,7 @@ enum iio_event_type {
>> IIO_EV_TYPE_THRESH_ADAPTIVE,
>> IIO_EV_TYPE_MAG_ADAPTIVE,
>> IIO_EV_TYPE_TRANSITION,
>> + IIO_EV_TYPE_INSTANCE,
>> };
>>
>> enum iio_event_info {
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
On Sat, Oct 25, 2014 at 10:01 PM, Jonathan Cameron <[email protected]> wrote:
> On 09/10/14 13:39, Daniel Baluta wrote:
>> This channel will be used for exposing information about
>> activity composite sensors. Activities supported so far:
>> * running
>> * jogging
>> * walking
>> * still
>>
>> TRANSITION event is used to signal a change in the activity
>> state.
>>
>> We associate a confidence interval for each activity expressed
>> as a percentage from 0 to 100.
>> * 0, means the sensor IS NOT reporting that activity.
>> * 100, means the sensor IS reporting that activity.
>>
>> Users of this interface have two possibile means to gather
>> information about the ongoing activities.
>>
>> 1. Event based, via event file descriptor
>> * sensor may report an event when ENTERING an activity or LEAVING
>> an activity based on a threshold value.
>> * drivers will wake up applications waiting data on the event fd
>>
>> 2. Polling, by reading the sysfs associated attribute files:
>> * /sys/bus/iio/devices/iio:device0/in_activity_running_input
>> expressed as percentage confidence value from 0 to 100.
>>
>> This will offer an interface for Android significant motion
>> composite sensor defined here:
>> http://source.android.com/devices/sensors/composite_sensors.html
>>
>> Activities listed above are supported by Freescale's MMA9553 sensor:
>> http://freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>>
>> Signed-off-by: Irina Tirdea <[email protected]>
>> Signed-off-by: Daniel Baluta <[email protected]>
>
> I don't see why we need the transition event. A transition is simply
> a threshold rising (or falling) event much like any other - just
> on a confidence interval.
>
> So it would be possible to be interested in the confidence that are not
> sitting rising above 20% on the basis that some other sensor needs enabling.
>
Using a THRESHOLD event type also work for us.
> See below for resulting suggestions.
>
> Other than that little point this looks good to me.
>> ---
>> Documentation/ABI/testing/sysfs-bus-iio | 44 +++++++++++++++++++++++++++++++++
>> drivers/iio/industrialio-core.c | 5 ++++
>> drivers/iio/industrialio-event.c | 1 +
>> include/linux/iio/types.h | 8 +++++-
>> 4 files changed, 57 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
>> index d760b02..12d0385 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-iio
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio
>> @@ -776,6 +776,40 @@ Description:
>> met before an event is generated. If direction is not
>> specified then this period applies to both directions.
>>
>> +What: /sys/.../events/in_activity_still_transition_rising_en
> What: /sys/.../events/in_activity_threshold_rising_en
Shouldn't this be:
What: /sys/.../events/in_activity_still_threshold_rising_en ?
Perhaps, one needs to enable events per activity type.
>> +What: /sys/.../events/in_activity_still_transition_falling_en
> What: /sys/.../events/in_activity_threshold_falling_en
Also, here:
What: /sys/.../events/in_activity_still_threshold_falling_en
> etc
>> +What: /sys/.../events/in_activity_walking_transition_rising_en
>> +What: /sys/.../events/in_activity_walking_transition_falling_en
>> +What: /sys/.../events/in_activity_jogging_transition_rising_en
>> +What: /sys/.../events/in_activity_jogging_transition_falling_en
>> +What: /sys/.../events/in_activity_running_transition_rising_en
>> +What: /sys/.../events/in_activity_running_transition_falling_en
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + Enables or disables activitity events. Depending on direction
>> + an event is generated when sensor ENTERS or LEAVES a given state.
>> +
>> +What: /sys/.../events/in_activity_still_transition_rising_value
> What: /sys/.../events/in_activity_still_threshold_rising_value etc
This looks good to me :)
>> +What: /sys/.../events/in_activity_still_transition_falling_value
>> +What: /sys/.../events/in_activity_walking_transition_rising_value
>> +What: /sys/.../events/in_activity_walking_transition_falling_value
>> +What: /sys/.../events/in_activity_jogging_transition_rising_value
>> +What: /sys/.../events/in_activity_jogging_transition_falling_value
>> +What: /sys/.../events/in_activity_running_transition_rising_value
>> +What: /sys/.../events/in_activity_running_transition_falling_value
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + Confidence value (in units as percentage) to be used
>> + for deciding when an event should be generated. E.g for
>> + running: If the confidence value reported by the sensor
>> + is greater then in_activity_running_transition_rising_value
>> + then the sensor ENTERS running state. Conversely, if the
>> + confidence value reported by the sensor is lower than
>> + in_activity_running_transition_rising_value then the sensor
>> + is LEAVING running state.
>> +
>> What: /sys/.../iio:deviceX/events/in_accel_mag_en
>> What: /sys/.../iio:deviceX/events/in_accel_mag_rising_en
>> What: /sys/.../iio:deviceX/events/in_accel_mag_falling_en
>> @@ -942,6 +976,16 @@ Description:
>> and the relevant _type attributes to establish the data storage
>> format.
>>
>> +What: /sys/.../iio:deviceX/in_activity_still_input
>> +What: /sys/.../iio:deviceX/in_activity_walking_input
>> +What: /sys/.../iio:deviceX/in_activity_jogging_input
>> +What: /sys/.../iio:deviceX/in_activity_running_input
>> +KernelVersion: 3.19
>> +Contact: [email protected]
>> +Description:
>> + This attribute is used to read the confidence for an activity
>> + expressed in units as percentage.
>> +
>> What: /sys/.../iio:deviceX/in_anglvel_z_quadrature_correction_raw
>> KernelVersion: 2.6.38
>> Contact: [email protected]
>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>> index af3e76d..e453ef9 100644
>> --- a/drivers/iio/industrialio-core.c
>> +++ b/drivers/iio/industrialio-core.c
>> @@ -70,6 +70,7 @@ static const char * const iio_chan_type_name_spec[] = {
>> [IIO_CCT] = "cct",
>> [IIO_PRESSURE] = "pressure",
>> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
>> + [IIO_ACTIVITY] = "activity",
>> };
>>
>> static const char * const iio_modifier_names[] = {
>> @@ -91,6 +92,10 @@ static const char * const iio_modifier_names[] = {
>> [IIO_MOD_NORTH_TRUE] = "from_north_true",
>> [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
>> [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
>> + [IIO_MOD_RUNNING] = "running",
>> + [IIO_MOD_JOGGING] = "jogging",
>> + [IIO_MOD_WALKING] = "walking",
>> + [IIO_MOD_STILL] = "still",
>> };
>>
>> /* relies on pairs of these shared then separate */
>> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
>> index 0c1e37e..afcf154 100644
>> --- a/drivers/iio/industrialio-event.c
>> +++ b/drivers/iio/industrialio-event.c
>> @@ -197,6 +197,7 @@ static const char * const iio_ev_type_text[] = {
>> [IIO_EV_TYPE_ROC] = "roc",
>> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
>> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
>> + [IIO_EV_TYPE_TRANSITION] = "transition",
>> };
>>
>> static const char * const iio_ev_dir_text[] = {
>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>> index 4a2af8a..a08ee6c 100644
>> --- a/include/linux/iio/types.h
>> +++ b/include/linux/iio/types.h
>> @@ -30,6 +30,7 @@ enum iio_chan_type {
>> IIO_CCT,
>> IIO_PRESSURE,
>> IIO_HUMIDITYRELATIVE,
>> + IIO_ACTIVITY,
>> };
>>
>> enum iio_modifier {
>> @@ -59,7 +60,11 @@ enum iio_modifier {
>> IIO_MOD_NORTH_MAGN,
>> IIO_MOD_NORTH_TRUE,
>> IIO_MOD_NORTH_MAGN_TILT_COMP,
>> - IIO_MOD_NORTH_TRUE_TILT_COMP
>> + IIO_MOD_NORTH_TRUE_TILT_COMP,
>> + IIO_MOD_RUNNING,
>> + IIO_MOD_JOGGING,
>> + IIO_MOD_WALKING,
>> + IIO_MOD_STILL,
>> };
>>
>> enum iio_event_type {
>> @@ -68,6 +73,7 @@ enum iio_event_type {
>> IIO_EV_TYPE_ROC,
>> IIO_EV_TYPE_THRESH_ADAPTIVE,
>> IIO_EV_TYPE_MAG_ADAPTIVE,
>> + IIO_EV_TYPE_TRANSITION,
>> };
>>
>> enum iio_event_info {
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
On 09/10/14 13:39, Daniel Baluta wrote:
> From: Irina Tirdea <[email protected]>
>
> Some devices need the height of the user to compute various
> parameters. One of this devices is Freescale's MMA9553L
> (http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf)
> that needs the height of the user to compute the stride length which
> is used further to determine distance, speed and activity type.
>
> Introduce a new channel type HEIGHT to export these values.
Now I'd love to make this generic as
in_distance_z_input etc but I guess that's pretty confusing for users ;)
Sadly altitude is going to be even more confusing.
I wonder if we should make this more explicit and have it as
in_steps_calibheight (repeated for all the channels whose computation
it effects). It's really a parameter of those channels rather than on
its own.
It should be out_height_input etc given you are setting it (like a trim
DAC on some ADC setup)
The there is an implication as that you are changing the users height
which, whilst it would be 'interesting', is probably the wrong impression!
*laughs* Maybe you were right to keep this an RFC for now ;)
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-bus-iio | 9 +++++++++
> drivers/iio/industrialio-core.c | 1 +
> include/linux/iio/types.h | 1 +
> 3 files changed, 11 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 3557a69..fc027cb 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -256,6 +256,7 @@ What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_accel_peak_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_scale
> +What: /sys/bus/iio/devices/iio:deviceX/in_height_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_magn_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_magn_x_scale
> What: /sys/bus/iio/devices/iio:deviceX/in_magn_y_scale
> @@ -1010,6 +1011,14 @@ Description:
> For a list of available output power modes read
> in_accel_power_mode_available.
>
> +What: /sys/.../iio:deviceX/in_height_input
> +What: /sys/.../iio:deviceX/in_height_raw
> +KernelVersion: 3.17
> +Contact: [email protected]
> +Description:
> + This attribute is used to set and read the user's height.
> + Units after application of scale are centimeters.
> +
> What: /sys/bus/iio/devices/iio:deviceX/store_eeprom
> KernelVersion: 3.4.0
> Contact: [email protected]
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 1e060f3..f08b278 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -72,6 +72,7 @@ static const char * const iio_chan_type_name_spec[] = {
> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
> [IIO_ACTIVITY] = "activity",
> [IIO_STEPS] = "steps",
> + [IIO_HEIGHT] = "height",
> };
>
> static const char * const iio_modifier_names[] = {
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index af0b6e0..a23b2e7 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -32,6 +32,7 @@ enum iio_chan_type {
> IIO_HUMIDITYRELATIVE,
> IIO_ACTIVITY,
> IIO_STEPS,
> + IIO_HEIGHT,
> };
>
> enum iio_modifier {
>
On 09/10/14 13:39, Daniel Baluta wrote:
> Adds support for the new channel types in the dummy driver:
> * a new channel IIO_ACTIVITY
> * two state transition events (running and walking)
> * a new channel IIO_STEPS and support for reading and writing
> pedometer step counter
> * step detect event
> * a new channel IIO_HEIGHT and support for reading and writing
> height
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Signed-off-by: Daniel Baluta <[email protected]>
This looks fine, allowing for changes due to suggestions / discussions
about earlier patches.
> ---
> drivers/staging/iio/iio_simple_dummy.c | 199 +++++++++++++++++++++++---
> drivers/staging/iio/iio_simple_dummy.h | 5 +
> drivers/staging/iio/iio_simple_dummy_events.c | 38 +++++
> 3 files changed, 223 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
> index bf78e6f..5430aed 100644
> --- a/drivers/staging/iio/iio_simple_dummy.c
> +++ b/drivers/staging/iio/iio_simple_dummy.c
> @@ -69,6 +69,34 @@ static const struct iio_event_spec iio_dummy_event = {
> .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
> };
>
> +/*
> + * simple step detect event - triggered when a step is detected
> + */
> +static const struct iio_event_spec step_detect_event = {
> + .type = IIO_EV_TYPE_INSTANCE,
> + .dir = IIO_EV_DIR_NONE,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> +};
> +
> +/*
> + * simple transition event - triggered when the reported running confidence
> + * value rises above a threshold value
> + */
> +static const struct iio_event_spec iio_running_event = {
> + .type = IIO_EV_TYPE_TRANSITION,
> + .dir = IIO_EV_DIR_RISING,
> + .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
> +};
> +
> +/*
> + * simple transition event - triggered when the reported walking confidence
> + * value falls under a threshold value
> + */
> +static const struct iio_event_spec iio_walking_event = {
> + .type = IIO_EV_TYPE_TRANSITION,
> + .dir = IIO_EV_DIR_FALLING,
> + .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
> +};
> #endif
>
> /*
> @@ -215,6 +243,42 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
> .indexed = 1,
> .channel = 0,
> },
> + {
> + .type = IIO_STEPS,
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_ENABLE),
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + .scan_index = -1,
> +#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> + .event_spec = &step_detect_event,
> + .num_event_specs = 1,
> +#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
> + },
> + {
> + .type = IIO_HEIGHT,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = -1,
> + },
> + {
> + .type = IIO_ACTIVITY,
> + .modified = 1,
> + .channel2 = IIO_MOD_RUNNING,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> + .event_spec = &iio_running_event,
> + .num_event_specs = 1,
> +#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
> + },
> + {
> + .type = IIO_ACTIVITY,
> + .modified = 1,
> + .channel2 = IIO_MOD_WALKING,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> + .event_spec = &iio_walking_event,
> + .num_event_specs = 1,
> +#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
> + },
> };
>
> /**
> @@ -259,6 +323,34 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
> *val = st->accel_val;
> ret = IIO_VAL_INT;
> break;
> + case IIO_HEIGHT:
> + *val = st->height;
> + ret = IIO_VAL_INT;
> + break;
> + default:
> + break;
> + }
> + break;
> + case IIO_CHAN_INFO_PROCESSED:
> + switch (chan->type) {
> + case IIO_STEPS:
> + *val = st->steps;
> + ret = IIO_VAL_INT;
> + break;
> + case IIO_ACTIVITY:
> + switch (chan->channel2) {
> + case IIO_MOD_RUNNING:
> + *val = st->activity_running;
> + ret = IIO_VAL_INT;
> + break;
> + case IIO_MOD_WALKING:
> + *val = st->activity_walking;
> + ret = IIO_VAL_INT;
> + break;
> + default:
> + break;
> + }
> + break;
> default:
> break;
> }
> @@ -269,18 +361,29 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
> ret = IIO_VAL_INT;
> break;
> case IIO_CHAN_INFO_SCALE:
> - switch (chan->differential) {
> - case 0:
> - /* only single ended adc -> 0.001333 */
> - *val = 0;
> - *val2 = 1333;
> - ret = IIO_VAL_INT_PLUS_MICRO;
> + switch (chan->type) {
> + case IIO_VOLTAGE:
> + switch (chan->differential) {
> + case 0:
> + /* only single ended adc -> 0.001333 */
> + *val = 0;
> + *val2 = 1333;
> + ret = IIO_VAL_INT_PLUS_MICRO;
> + break;
> + case 1:
> + /* all differential adc channels ->
> + * 0.000001344 */
> + *val = 0;
> + *val2 = 1344;
> + ret = IIO_VAL_INT_PLUS_NANO;
> + }
> + break;
> + case IIO_HEIGHT:
> + *val = 1;
> + ret = IIO_VAL_INT;
> + break;
> + default:
> break;
> - case 1:
> - /* all differential adc channels -> 0.000001344 */
> - *val = 0;
> - *val2 = 1344;
> - ret = IIO_VAL_INT_PLUS_NANO;
> }
> break;
> case IIO_CHAN_INFO_CALIBBIAS:
> @@ -298,6 +401,16 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
> *val2 = 33;
> ret = IIO_VAL_INT_PLUS_NANO;
> break;
> + case IIO_CHAN_INFO_ENABLE:
> + switch (chan->type) {
> + case IIO_STEPS:
> + *val = st->steps_enabled;
> + ret = IIO_VAL_INT;
> + break;
> + default:
> + break;
> + }
> + break;
> default:
> break;
> }
> @@ -330,14 +443,50 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - if (chan->output == 0)
> + switch (chan->type) {
> + case IIO_VOLTAGE:
> + if (chan->output == 0)
> + return -EINVAL;
> +
> + /* Locking not required as writing single value */
> + mutex_lock(&st->lock);
> + st->dac_val = val;
> + mutex_unlock(&st->lock);
> + return 0;
> + case IIO_HEIGHT:
> + mutex_lock(&st->lock);
> + st->height = val;
> + mutex_unlock(&st->lock);
> + return 0;
> + default:
> return -EINVAL;
> -
> - /* Locking not required as writing single value */
> - mutex_lock(&st->lock);
> - st->dac_val = val;
> - mutex_unlock(&st->lock);
> - return 0;
> + }
> + case IIO_CHAN_INFO_PROCESSED:
> + switch (chan->type) {
> + case IIO_STEPS:
> + mutex_lock(&st->lock);
> + st->steps = val;
> + mutex_unlock(&st->lock);
> + return 0;
> + case IIO_ACTIVITY:
> + if (val < 0)
> + val = 0;
> + if (val > 100)
> + val = 100;
> + switch (chan->channel2) {
> + case IIO_MOD_RUNNING:
> + st->activity_running = val;
> + return 0;
> + case IIO_MOD_WALKING:
> + st->activity_walking = val;
> + return 0;
> + default:
> + return -EINVAL;
> + }
> + break;
> + default:
> + return -EINVAL;
> + }
> case IIO_CHAN_INFO_CALIBSCALE:
> mutex_lock(&st->lock);
> /* Compare against table - hard matching here */
> @@ -356,7 +505,16 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
> st->accel_calibbias = val;
> mutex_unlock(&st->lock);
> return 0;
> -
> + case IIO_CHAN_INFO_ENABLE:
> + switch (chan->type) {
> + case IIO_STEPS:
> + mutex_lock(&st->lock);
> + st->steps_enabled = val;
> + mutex_unlock(&st->lock);
> + return 0;
> + default:
> + return -EINVAL;
> + }
> default:
> return -EINVAL;
> }
> @@ -395,6 +553,9 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
> st->accel_val = 34;
> st->accel_calibbias = -7;
> st->accel_calibscale = &dummy_scales[0];
> + st->steps = 47;
> + st->activity_running = 98;
> + st->activity_walking = 4;
>
> return 0;
> }
> diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
> index 1a74e26..d49aec3 100644
> --- a/drivers/staging/iio/iio_simple_dummy.h
> +++ b/drivers/staging/iio/iio_simple_dummy.h
> @@ -32,9 +32,14 @@ struct iio_dummy_state {
> int differential_adc_val[2];
> int accel_val;
> int accel_calibbias;
> + int activity_running;
> + int activity_walking;
> const struct iio_dummy_accel_calibscale *accel_calibscale;
> struct mutex lock;
> struct iio_dummy_regs *regs;
> + int steps_enabled;
> + int steps;
> + int height;
> #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> int event_irq;
> int event_val;
> diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
> index 719dfa5..ae37620 100644
> --- a/drivers/staging/iio/iio_simple_dummy_events.c
> +++ b/drivers/staging/iio/iio_simple_dummy_events.c
> @@ -66,12 +66,23 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
> */
> switch (chan->type) {
> case IIO_VOLTAGE:
> + case IIO_ACTIVITY:
> switch (type) {
> case IIO_EV_TYPE_THRESH:
> if (dir == IIO_EV_DIR_RISING)
> st->event_en = state;
> else
> return -EINVAL;
> + case IIO_EV_TYPE_TRANSITION:
> + st->event_en = state;
> + break;
> + default:
> + return -EINVAL;
> + }
> + case IIO_STEPS:
> + switch (type) {
> + case IIO_EV_TYPE_INSTANCE:
> + st->event_en = state;
> break;
> default:
> return -EINVAL;
> @@ -161,6 +172,33 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
> IIO_EV_TYPE_THRESH, 0, 0, 0),
> iio_get_time_ns());
> break;
> + case 1:
> + if (st->activity_running > st->event_val)
> + iio_push_event(indio_dev,
> + IIO_EVENT_CODE(IIO_ACTIVITY, 0,
> + IIO_MOD_RUNNING,
> + IIO_EV_DIR_RISING,
> + IIO_EV_TYPE_TRANSITION,
> + 0, 0, 0),
> + iio_get_time_ns());
> + break;
> + case 2:
> + if (st->activity_walking < st->event_val)
> + iio_push_event(indio_dev,
> + IIO_EVENT_CODE(IIO_ACTIVITY, 0,
> + IIO_MOD_WALKING,
> + IIO_EV_DIR_FALLING,
> + IIO_EV_TYPE_TRANSITION,
> + 0, 0, 0),
> + iio_get_time_ns());
> + break;
> + case 3:
> + iio_push_event(indio_dev,
> + IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
> + IIO_EV_DIR_NONE,
> + IIO_EV_TYPE_INSTANCE, 0, 0, 0),
> + iio_get_time_ns());
> + break;
> default:
> break;
> }
>
On 25/10/14 20:19, Daniel Baluta wrote:
> On Sat, Oct 25, 2014 at 10:01 PM, Jonathan Cameron <[email protected]> wrote:
>> On 09/10/14 13:39, Daniel Baluta wrote:
>>> This channel will be used for exposing information about
>>> activity composite sensors. Activities supported so far:
>>> * running
>>> * jogging
>>> * walking
>>> * still
>>>
>>> TRANSITION event is used to signal a change in the activity
>>> state.
>>>
>>> We associate a confidence interval for each activity expressed
>>> as a percentage from 0 to 100.
>>> * 0, means the sensor IS NOT reporting that activity.
>>> * 100, means the sensor IS reporting that activity.
>>>
>>> Users of this interface have two possibile means to gather
>>> information about the ongoing activities.
>>>
>>> 1. Event based, via event file descriptor
>>> * sensor may report an event when ENTERING an activity or LEAVING
>>> an activity based on a threshold value.
>>> * drivers will wake up applications waiting data on the event fd
>>>
>>> 2. Polling, by reading the sysfs associated attribute files:
>>> * /sys/bus/iio/devices/iio:device0/in_activity_running_input
>>> expressed as percentage confidence value from 0 to 100.
>>>
>>> This will offer an interface for Android significant motion
>>> composite sensor defined here:
>>> http://source.android.com/devices/sensors/composite_sensors.html
>>>
>>> Activities listed above are supported by Freescale's MMA9553 sensor:
>>> http://freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf
>>>
>>> Signed-off-by: Irina Tirdea <[email protected]>
>>> Signed-off-by: Daniel Baluta <[email protected]>
>>
>> I don't see why we need the transition event. A transition is simply
>> a threshold rising (or falling) event much like any other - just
>> on a confidence interval.
>>
>> So it would be possible to be interested in the confidence that are not
>> sitting rising above 20% on the basis that some other sensor needs enabling.
>>
>
> Using a THRESHOLD event type also work for us.
>
>> See below for resulting suggestions.
>>
>> Other than that little point this looks good to me.
>>> ---
>>> Documentation/ABI/testing/sysfs-bus-iio | 44 +++++++++++++++++++++++++++++++++
>>> drivers/iio/industrialio-core.c | 5 ++++
>>> drivers/iio/industrialio-event.c | 1 +
>>> include/linux/iio/types.h | 8 +++++-
>>> 4 files changed, 57 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
>>> index d760b02..12d0385 100644
>>> --- a/Documentation/ABI/testing/sysfs-bus-iio
>>> +++ b/Documentation/ABI/testing/sysfs-bus-iio
>>> @@ -776,6 +776,40 @@ Description:
>>> met before an event is generated. If direction is not
>>> specified then this period applies to both directions.
>>>
>>> +What: /sys/.../events/in_activity_still_transition_rising_en
>> What: /sys/.../events/in_activity_threshold_rising_en
>
> Shouldn't this be:
>
> What: /sys/.../events/in_activity_still_threshold_rising_en ?
>
> Perhaps, one needs to enable events per activity type.
Absolutely.
>
>>> +What: /sys/.../events/in_activity_still_transition_falling_en
>> What: /sys/.../events/in_activity_threshold_falling_en
> Also, here:
>
> What: /sys/.../events/in_activity_still_threshold_falling_en
>
>> etc
>>> +What: /sys/.../events/in_activity_walking_transition_rising_en
>>> +What: /sys/.../events/in_activity_walking_transition_falling_en
>>> +What: /sys/.../events/in_activity_jogging_transition_rising_en
>>> +What: /sys/.../events/in_activity_jogging_transition_falling_en
>>> +What: /sys/.../events/in_activity_running_transition_rising_en
>>> +What: /sys/.../events/in_activity_running_transition_falling_en
>>> +KernelVersion: 3.19
>>> +Contact: [email protected]
>>> +Description:
>>> + Enables or disables activitity events. Depending on direction
>>> + an event is generated when sensor ENTERS or LEAVES a given state.
>>> +
>>> +What: /sys/.../events/in_activity_still_transition_rising_value
>> What: /sys/.../events/in_activity_still_threshold_rising_value etc
>
> This looks good to me :)
>
>>> +What: /sys/.../events/in_activity_still_transition_falling_value
>>> +What: /sys/.../events/in_activity_walking_transition_rising_value
>>> +What: /sys/.../events/in_activity_walking_transition_falling_value
>>> +What: /sys/.../events/in_activity_jogging_transition_rising_value
>>> +What: /sys/.../events/in_activity_jogging_transition_falling_value
>>> +What: /sys/.../events/in_activity_running_transition_rising_value
>>> +What: /sys/.../events/in_activity_running_transition_falling_value
>>> +KernelVersion: 3.19
>>> +Contact: [email protected]
>>> +Description:
>>> + Confidence value (in units as percentage) to be used
>>> + for deciding when an event should be generated. E.g for
>>> + running: If the confidence value reported by the sensor
>>> + is greater then in_activity_running_transition_rising_value
>>> + then the sensor ENTERS running state. Conversely, if the
>>> + confidence value reported by the sensor is lower than
>>> + in_activity_running_transition_rising_value then the sensor
>>> + is LEAVING running state.
>>> +
>>> What: /sys/.../iio:deviceX/events/in_accel_mag_en
>>> What: /sys/.../iio:deviceX/events/in_accel_mag_rising_en
>>> What: /sys/.../iio:deviceX/events/in_accel_mag_falling_en
>>> @@ -942,6 +976,16 @@ Description:
>>> and the relevant _type attributes to establish the data storage
>>> format.
>>>
>>> +What: /sys/.../iio:deviceX/in_activity_still_input
>>> +What: /sys/.../iio:deviceX/in_activity_walking_input
>>> +What: /sys/.../iio:deviceX/in_activity_jogging_input
>>> +What: /sys/.../iio:deviceX/in_activity_running_input
>>> +KernelVersion: 3.19
>>> +Contact: [email protected]
>>> +Description:
>>> + This attribute is used to read the confidence for an activity
>>> + expressed in units as percentage.
>>> +
>>> What: /sys/.../iio:deviceX/in_anglvel_z_quadrature_correction_raw
>>> KernelVersion: 2.6.38
>>> Contact: [email protected]
>>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>>> index af3e76d..e453ef9 100644
>>> --- a/drivers/iio/industrialio-core.c
>>> +++ b/drivers/iio/industrialio-core.c
>>> @@ -70,6 +70,7 @@ static const char * const iio_chan_type_name_spec[] = {
>>> [IIO_CCT] = "cct",
>>> [IIO_PRESSURE] = "pressure",
>>> [IIO_HUMIDITYRELATIVE] = "humidityrelative",
>>> + [IIO_ACTIVITY] = "activity",
>>> };
>>>
>>> static const char * const iio_modifier_names[] = {
>>> @@ -91,6 +92,10 @@ static const char * const iio_modifier_names[] = {
>>> [IIO_MOD_NORTH_TRUE] = "from_north_true",
>>> [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
>>> [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
>>> + [IIO_MOD_RUNNING] = "running",
>>> + [IIO_MOD_JOGGING] = "jogging",
>>> + [IIO_MOD_WALKING] = "walking",
>>> + [IIO_MOD_STILL] = "still",
>>> };
>>>
>>> /* relies on pairs of these shared then separate */
>>> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
>>> index 0c1e37e..afcf154 100644
>>> --- a/drivers/iio/industrialio-event.c
>>> +++ b/drivers/iio/industrialio-event.c
>>> @@ -197,6 +197,7 @@ static const char * const iio_ev_type_text[] = {
>>> [IIO_EV_TYPE_ROC] = "roc",
>>> [IIO_EV_TYPE_THRESH_ADAPTIVE] = "thresh_adaptive",
>>> [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive",
>>> + [IIO_EV_TYPE_TRANSITION] = "transition",
>>> };
>>>
>>> static const char * const iio_ev_dir_text[] = {
>>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>>> index 4a2af8a..a08ee6c 100644
>>> --- a/include/linux/iio/types.h
>>> +++ b/include/linux/iio/types.h
>>> @@ -30,6 +30,7 @@ enum iio_chan_type {
>>> IIO_CCT,
>>> IIO_PRESSURE,
>>> IIO_HUMIDITYRELATIVE,
>>> + IIO_ACTIVITY,
>>> };
>>>
>>> enum iio_modifier {
>>> @@ -59,7 +60,11 @@ enum iio_modifier {
>>> IIO_MOD_NORTH_MAGN,
>>> IIO_MOD_NORTH_TRUE,
>>> IIO_MOD_NORTH_MAGN_TILT_COMP,
>>> - IIO_MOD_NORTH_TRUE_TILT_COMP
>>> + IIO_MOD_NORTH_TRUE_TILT_COMP,
>>> + IIO_MOD_RUNNING,
>>> + IIO_MOD_JOGGING,
>>> + IIO_MOD_WALKING,
>>> + IIO_MOD_STILL,
>>> };
>>>
>>> enum iio_event_type {
>>> @@ -68,6 +73,7 @@ enum iio_event_type {
>>> IIO_EV_TYPE_ROC,
>>> IIO_EV_TYPE_THRESH_ADAPTIVE,
>>> IIO_EV_TYPE_MAG_ADAPTIVE,
>>> + IIO_EV_TYPE_TRANSITION,
>>> };
>>>
>>> enum iio_event_info {
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
Jonathan Cameron schrieb am 25.10.2014 20:55:
> On 09/10/14 13:39, Daniel Baluta wrote:
>> We need a way to store events generated by iio_dummy_evgen module,
>> in order to correctly process IRQs in iio_simple_dummy_events.
>>
>> For the moment, we add two registers:
>>
>> * id_reg - ID register, stores the source of the event
>> * id_data - DATA register, stores the type of the event
>>
>> e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
>>
>> id_reg 0x02, id_data 0x04
>>
>> This means, event of type 4 was generated by fake device 2.
>>
>> We currently use a hardcoded mapping of virtual events to IIO events.
>>
>> Signed-off-by: Irina Tirdea <[email protected]>
>> Signed-off-by: Daniel Baluta <[email protected]>
> Applied to the togreg branch of iio.git.
> Initially pushed out as testing for the autobuilders to play with it.
I think Daniel wanted to work on a V3 for (at least) this one, fixing variable type of ret from long to int in iio_evgen_poke(). Had spotted it in V1, when V2 was already sent out - sorry for that. See [1].
[1] http://marc.info/?l=linux-iio&m=141375116229102&w=2
>> ---
>> drivers/staging/iio/iio_dummy_evgen.c | 16 ++++++++++++++++
>> drivers/staging/iio/iio_dummy_evgen.h | 6 ++++++
>> drivers/staging/iio/iio_simple_dummy.h | 2 ++
>> drivers/staging/iio/iio_simple_dummy_events.c | 23 ++++++++++++++++++-----
>> 4 files changed, 42 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
>> index 5a804f1..d44f138 100644
>> --- a/drivers/staging/iio/iio_dummy_evgen.c
>> +++ b/drivers/staging/iio/iio_dummy_evgen.c
>> @@ -33,6 +33,7 @@
>> * @base: base of irq range
>> * @enabled: mask of which irqs are enabled
>> * @inuse: mask of which irqs are connected
>> + * @regs: irq regs we are faking
>> * @lock: protect the evgen state
>> */
>> struct iio_dummy_eventgen {
>> @@ -40,6 +41,7 @@ struct iio_dummy_eventgen {
>> int base;
>> bool enabled[IIO_EVENTGEN_NO];
>> bool inuse[IIO_EVENTGEN_NO];
>> + struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
>> struct mutex lock;
>> };
>>
>> @@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
>> }
>> EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
>>
>> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
>> +{
>> + return &iio_evgen->regs[irq - iio_evgen->base];
>> +}
>> +EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
>> +
>> static void iio_dummy_evgen_free(void)
>> {
>> irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
>> @@ -153,6 +161,14 @@ static ssize_t iio_evgen_poke(struct device *dev,
>> size_t len)
>> {
>> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>> + unsigned long event, ret;
>> +
>> + ret = kstrtoul(buf, 10, &event);
>> + if (ret)
>> + return ret;
>> +
>> + iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
>> + iio_evgen->regs[this_attr->address].reg_data = event;
>>
>> if (iio_evgen->enabled[this_attr->address])
>> handle_nested_irq(iio_evgen->base + this_attr->address);
>> diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/staging/iio/iio_dummy_evgen.h
>> index d8845e2..3ef3a1c 100644
>> --- a/drivers/staging/iio/iio_dummy_evgen.h
>> +++ b/drivers/staging/iio/iio_dummy_evgen.h
>> @@ -1,2 +1,8 @@
>> +struct iio_dummy_regs {
>> + u32 reg_id;
>> + u32 reg_data;
>> +};
>> +
>> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
>> int iio_dummy_evgen_get_irq(void);
>> int iio_dummy_evgen_release_irq(int irq);
>> diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
>> index b126196..1a74e26 100644
>> --- a/drivers/staging/iio/iio_simple_dummy.h
>> +++ b/drivers/staging/iio/iio_simple_dummy.h
>> @@ -11,6 +11,7 @@
>> #include <linux/kernel.h>
>>
>> struct iio_dummy_accel_calibscale;
>> +struct iio_dummy_regs;
>>
>> /**
>> * struct iio_dummy_state - device instance specific state.
>> @@ -33,6 +34,7 @@ struct iio_dummy_state {
>> int accel_calibbias;
>> const struct iio_dummy_accel_calibscale *accel_calibscale;
>> struct mutex lock;
>> + struct iio_dummy_regs *regs;
>> #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
>> int event_irq;
>> int event_val;
>> diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
>> index 64b45b0..719dfa5 100644
>> --- a/drivers/staging/iio/iio_simple_dummy_events.c
>> +++ b/drivers/staging/iio/iio_simple_dummy_events.c
>> @@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
>> static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
>> {
>> struct iio_dev *indio_dev = private;
>> + struct iio_dummy_state *st = iio_priv(indio_dev);
>> +
>> + dev_dbg(&indio_dev->dev, "id %x event %x\n",
>> + st->regs->reg_id, st->regs->reg_data);
>> +
>> + switch (st->regs->reg_data) {
>> + case 0:
>> + iio_push_event(indio_dev,
>> + IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
>> + IIO_EV_DIR_RISING,
>> + IIO_EV_TYPE_THRESH, 0, 0, 0),
>> + iio_get_time_ns());
>> + break;
>> + default:
>> + break;
>> + }
>>
>> - iio_push_event(indio_dev,
>> - IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
>> - IIO_EV_DIR_RISING,
>> - IIO_EV_TYPE_THRESH, 0, 0, 0),
>> - iio_get_time_ns());
>> return IRQ_HANDLED;
>> }
>>
>> @@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
>> ret = st->event_irq;
>> goto error_ret;
>> }
>> + st->regs = iio_dummy_evgen_get_regs(st->event_irq);
>> +
>> ret = request_threaded_irq(st->event_irq,
>> NULL,
>> &iio_simple_dummy_event_handler,
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
HOn 25/10/14 20:49, Hartmut Knaack wrote:
> Jonathan Cameron schrieb am 25.10.2014 20:55:
>> On 09/10/14 13:39, Daniel Baluta wrote:
>>> We need a way to store events generated by iio_dummy_evgen module,
>>> in order to correctly process IRQs in iio_simple_dummy_events.
>>>
>>> For the moment, we add two registers:
>>>
>>> * id_reg - ID register, stores the source of the event
>>> * id_data - DATA register, stores the type of the event
>>>
>>> e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
>>>
>>> id_reg 0x02, id_data 0x04
>>>
>>> This means, event of type 4 was generated by fake device 2.
>>>
>>> We currently use a hardcoded mapping of virtual events to IIO events.
>>>
>>> Signed-off-by: Irina Tirdea <[email protected]>
>>> Signed-off-by: Daniel Baluta <[email protected]>
>> Applied to the togreg branch of iio.git.
>> Initially pushed out as testing for the autobuilders to play with it.
> I think Daniel wanted to work on a V3 for (at least) this one, fixing variable type of ret from long to int in iio_evgen_poke(). Had spotted it in V1, when V2 was already sent out - sorry for that. See [1].
>
> [1] http://marc.info/?l=linux-iio&m=141375116229102&w=2
Backed out. Thanks for letting me know.
>
>>> ---
>>> drivers/staging/iio/iio_dummy_evgen.c | 16 ++++++++++++++++
>>> drivers/staging/iio/iio_dummy_evgen.h | 6 ++++++
>>> drivers/staging/iio/iio_simple_dummy.h | 2 ++
>>> drivers/staging/iio/iio_simple_dummy_events.c | 23 ++++++++++++++++++-----
>>> 4 files changed, 42 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
>>> index 5a804f1..d44f138 100644
>>> --- a/drivers/staging/iio/iio_dummy_evgen.c
>>> +++ b/drivers/staging/iio/iio_dummy_evgen.c
>>> @@ -33,6 +33,7 @@
>>> * @base: base of irq range
>>> * @enabled: mask of which irqs are enabled
>>> * @inuse: mask of which irqs are connected
>>> + * @regs: irq regs we are faking
>>> * @lock: protect the evgen state
>>> */
>>> struct iio_dummy_eventgen {
>>> @@ -40,6 +41,7 @@ struct iio_dummy_eventgen {
>>> int base;
>>> bool enabled[IIO_EVENTGEN_NO];
>>> bool inuse[IIO_EVENTGEN_NO];
>>> + struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
>>> struct mutex lock;
>>> };
>>>
>>> @@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
>>> }
>>> EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
>>>
>>> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
>>> +{
>>> + return &iio_evgen->regs[irq - iio_evgen->base];
>>> +}
>>> +EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
>>> +
>>> static void iio_dummy_evgen_free(void)
>>> {
>>> irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
>>> @@ -153,6 +161,14 @@ static ssize_t iio_evgen_poke(struct device *dev,
>>> size_t len)
>>> {
>>> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>>> + unsigned long event, ret;
>>> +
>>> + ret = kstrtoul(buf, 10, &event);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
>>> + iio_evgen->regs[this_attr->address].reg_data = event;
>>>
>>> if (iio_evgen->enabled[this_attr->address])
>>> handle_nested_irq(iio_evgen->base + this_attr->address);
>>> diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/staging/iio/iio_dummy_evgen.h
>>> index d8845e2..3ef3a1c 100644
>>> --- a/drivers/staging/iio/iio_dummy_evgen.h
>>> +++ b/drivers/staging/iio/iio_dummy_evgen.h
>>> @@ -1,2 +1,8 @@
>>> +struct iio_dummy_regs {
>>> + u32 reg_id;
>>> + u32 reg_data;
>>> +};
>>> +
>>> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
>>> int iio_dummy_evgen_get_irq(void);
>>> int iio_dummy_evgen_release_irq(int irq);
>>> diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
>>> index b126196..1a74e26 100644
>>> --- a/drivers/staging/iio/iio_simple_dummy.h
>>> +++ b/drivers/staging/iio/iio_simple_dummy.h
>>> @@ -11,6 +11,7 @@
>>> #include <linux/kernel.h>
>>>
>>> struct iio_dummy_accel_calibscale;
>>> +struct iio_dummy_regs;
>>>
>>> /**
>>> * struct iio_dummy_state - device instance specific state.
>>> @@ -33,6 +34,7 @@ struct iio_dummy_state {
>>> int accel_calibbias;
>>> const struct iio_dummy_accel_calibscale *accel_calibscale;
>>> struct mutex lock;
>>> + struct iio_dummy_regs *regs;
>>> #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
>>> int event_irq;
>>> int event_val;
>>> diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
>>> index 64b45b0..719dfa5 100644
>>> --- a/drivers/staging/iio/iio_simple_dummy_events.c
>>> +++ b/drivers/staging/iio/iio_simple_dummy_events.c
>>> @@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
>>> static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
>>> {
>>> struct iio_dev *indio_dev = private;
>>> + struct iio_dummy_state *st = iio_priv(indio_dev);
>>> +
>>> + dev_dbg(&indio_dev->dev, "id %x event %x\n",
>>> + st->regs->reg_id, st->regs->reg_data);
>>> +
>>> + switch (st->regs->reg_data) {
>>> + case 0:
>>> + iio_push_event(indio_dev,
>>> + IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
>>> + IIO_EV_DIR_RISING,
>>> + IIO_EV_TYPE_THRESH, 0, 0, 0),
>>> + iio_get_time_ns());
>>> + break;
>>> + default:
>>> + break;
>>> + }
>>>
>>> - iio_push_event(indio_dev,
>>> - IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
>>> - IIO_EV_DIR_RISING,
>>> - IIO_EV_TYPE_THRESH, 0, 0, 0),
>>> - iio_get_time_ns());
>>> return IRQ_HANDLED;
>>> }
>>>
>>> @@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
>>> ret = st->event_irq;
>>> goto error_ret;
>>> }
>>> + st->regs = iio_dummy_evgen_get_regs(st->event_irq);
>>> +
>>> ret = request_threaded_irq(st->event_irq,
>>> NULL,
>>> &iio_simple_dummy_event_handler,
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
On Sat, Oct 25, 2014 at 10:49 PM, Hartmut Knaack <[email protected]> wrote:
> Jonathan Cameron schrieb am 25.10.2014 20:55:
>> On 09/10/14 13:39, Daniel Baluta wrote:
>>> We need a way to store events generated by iio_dummy_evgen module,
>>> in order to correctly process IRQs in iio_simple_dummy_events.
>>>
>>> For the moment, we add two registers:
>>>
>>> * id_reg - ID register, stores the source of the event
>>> * id_data - DATA register, stores the type of the event
>>>
>>> e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
>>>
>>> id_reg 0x02, id_data 0x04
>>>
>>> This means, event of type 4 was generated by fake device 2.
>>>
>>> We currently use a hardcoded mapping of virtual events to IIO events.
>>>
>>> Signed-off-by: Irina Tirdea <[email protected]>
>>> Signed-off-by: Daniel Baluta <[email protected]>
>> Applied to the togreg branch of iio.git.
>> Initially pushed out as testing for the autobuilders to play with it.
> I think Daniel wanted to work on a V3 for (at least) this one, fixing variable type of ret from long to int in iio_evgen_poke(). Had spotted it in V1, when V2 was already sent out - sorry for that. See [1].
Correct, I was just waiting on feedback for other patches.
I will send v3 as soon as possible.
thanks,
Daniel.
On Sat, Oct 25, 2014 at 10:18 PM, Jonathan Cameron <[email protected]> wrote:
> On 24/10/14 23:31, Hartmut Knaack wrote:
>> Daniel Baluta schrieb am 09.10.2014 14:39:
>>> From: Irina Tirdea <[email protected]>
>>>
>>> These changes are needed to support the functionality of a pedometer.
>>> A pedometer has two basic functionalities: step counter and step detector.
>>>
>>> The step counter needs to be enabled and then it will count the steps
>>> in its hardware register. Whenever the application needs to check
>>> the step count, it will read the step counter register. To support the
>>> step counter a new channel type STEPS is added. Since the pedometer needs
>>> to be enabled first so that the hardware can count and store the steps,
>>> we need a specific ENABLE channel info mask.
>>>
>>> The step detector will generate an interrupt each time a step is detected.
>>> To support this functionality we add a new event type INSTANCE.
>>>
>> Hi,
>> I was wondering, if it would be better to name this channel somehow more generic. What you are actually counting are some pulses, and only the implementation of the hardware leads to the interpretation of these pulses as for example steps.
>> Other devices for this category would be pulse counters - either stand alone, or as part of SoCs. Some use cases I could think of are: liquid/gas flow measurements, engine rotation/RPM counts, object counts, ...
>> Any opinions?
>
> I agree there might be potential here for a broader interface... RPM however
> would be a rotational speed measurement and hence in radians / second or
> radians if just a count of pulses off an encoder.
>
> We have just recently had a human pulse counter as well which is another count.
>
> The question to my mind is do we gain anything by making it more generic?
> Does it help userspace? Chances of having many applications that don't care
> about the difference between steps and other pulse counts is probably low
> so right now I'm (slightly) falling on the side of have these more specific
> counts.
>
> So what does everyone else think?
I think making this more generic might confuse the users. Having this
more specific makes the interface very clear about who should use it.
Daniel.