Introduce IIO interface for Android advanced features
Subsystems (3)
v3 cover Introduce IIO interface for Android advanced features
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 v2: (comments from Jonathan and Hartmut)
* dropped the RFC tag
* use int instead of unsigned long for ret in iio_evgen_poke
* remove TRANSITION event and use THRESHOLD instead
* remove IIO_HEIGHT channel and use CALIBHEIGHT mask instead
* adapt iio_dummy modules and iio_event_monitor to reflect IIO interface changes.
Daniel Baluta (4):
iio: dummy: Add virtual registers for dummy device
iio: core: Introduce IIO_ACTIVITY channel
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 IIO_CHAN_INFO_CALIBHEIGHT
Documentation/ABI/testing/sysfs-bus-iio | 74 ++++++++ drivers/iio/industrialio-core.c | 8 + drivers/iio/industrialio-event.c | 13 +- .../staging/iio/Documentation/iio_event_monitor.c | 23 ++- drivers/staging/iio/iio_dummy_evgen.c | 17 ++ 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 | 66 ++++++- include/linux/iio/iio.h | 2 + include/linux/iio/types.h | 10 +- 11 files changed, 395 insertions(+), 30 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/7 iio: dummy: Add virtual registers for dummy device
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.
--- drivers/staging/iio/iio_dummy_evgen.c | 17 +++++++++++++++++ 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, 43 insertions(+), 5 deletions(-)
drivers/staging/iio/iio_dummy_evgen.c +17 -0
@@ -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,15 @@ 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; +int 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);
drivers/staging/iio/iio_dummy_evgen.h +6 -0
@@ -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);
drivers/staging/iio/iio_simple_dummy.h +2 -0
@@ -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;
drivers/staging/iio/iio_simple_dummy_events.c +18 -5
@@ -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,
Signature · 1 line
1.9.1
PATCH v3 2/7 iio: core: Introduce IIO_ACTIVITY channel
In reply to Daniel BalutaThis channel will be used for exposing information about activity composite sensors. Activities supported so far:
* running
* jogging
* walking
* still
THRESHOLD 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
--- Documentation/ABI/testing/sysfs-bus-iio | 44 +++++++++++++++++++++++++++++++++ drivers/iio/industrialio-core.c | 5 ++++ include/linux/iio/types.h | 7 +++++- 3 files changed, 55 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-iio +44 -0
@@ -783,6 +783,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_thresh_rising_en +What: /sys/.../events/in_activity_still_thresh_falling_en +What: /sys/.../events/in_activity_walking_thresh_rising_en +What: /sys/.../events/in_activity_walking_thresh_falling_en +What: /sys/.../events/in_activity_jogging_thresh_rising_en +What: /sys/.../events/in_activity_jogging_thresh_falling_en +What: /sys/.../events/in_activity_running_thresh_rising_en +What: /sys/.../events/in_activity_running_thresh_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_thresh_rising_value +What: /sys/.../events/in_activity_still_thresh_falling_value +What: /sys/.../events/in_activity_walking_thresh_rising_value +What: /sys/.../events/in_activity_walking_thresh_falling_value +What: /sys/.../events/in_activity_jogging_thresh_rising_value +What: /sys/.../events/in_activity_jogging_thresh_falling_value +What: /sys/.../events/in_activity_running_thresh_rising_value +What: /sys/.../events/in_activity_running_thresh_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_thresh_rising_value + then the sensor ENTERS running state. Conversely, if the + confidence value reported by the sensor is lower than + in_activity_running_thresh_falling_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
@@ -949,6 +983,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]
drivers/iio/industrialio-core.c +5 -0
@@ -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 */
include/linux/iio/types.h +6 -1
@@ -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 {
Signature · 1 line
1.9.1
Re: [PATCH v3 2/7] iio: core: Introduce IIO_ACTIVITY channel
Just some typos left, maybe Jonathan can take care of them, if there are no issues for having a V4. Daniel Baluta schrieb am 28.10.2014 11:19:
Quoted 10 lines
This channel will be used for exposing information about activity composite sensors. Activities supported so far:
* running
* jogging
* walking
* stillTHRESHOLD event is used to signal a change in the activity state.
Quoted 6 lines
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
Typo: possible
Quoted 53 lines
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 fd2. 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.htmlActivities listed above are supported by Freescale's MMA9553 sensor:
http://freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdfSigned-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 ++++ include/linux/iio/types.h | 7 +++++- 3 files changed, 55 insertions(+), 1 deletion(-)Documentation/ABI/testing/sysfs-bus-iio +19
-0@@ -783,6 +783,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_thresh_rising_en +What: /sys/.../events/in_activity_still_thresh_falling_en +What: /sys/.../events/in_activity_walking_thresh_rising_en +What: /sys/.../events/in_activity_walking_thresh_falling_en +What: /sys/.../events/in_activity_jogging_thresh_rising_en +What: /sys/.../events/in_activity_jogging_thresh_falling_en +What: /sys/.../events/in_activity_running_thresh_rising_en +What: /sys/.../events/in_activity_running_thresh_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_thresh_rising_value +What: /sys/.../events/in_activity_still_thresh_falling_value +What: /sys/.../events/in_activity_walking_thresh_rising_value +What: /sys/.../events/in_activity_walking_thresh_falling_value +What: /sys/.../events/in_activity_jogging_thresh_rising_value
Documentation/ABI/testing/sysfs-bus-iio Description: · line 814
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio +10
-0+What: /sys/.../events/in_activity_jogging_thresh_falling_value +What: /sys/.../events/in_activity_running_thresh_rising_value +What: /sys/.../events/in_activity_running_thresh_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_thresh_rising_value
Typo: greater than
Quoted 74 lines
Documentation/ABI/testing/sysfs-bus-iio +15
-0+ then the sensor ENTERS running state. Conversely, if the + confidence value reported by the sensor is lower than + in_activity_running_thresh_falling_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@@ -949,6 +983,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]drivers/iio/industrialio-core.c +5
-0@@ -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 */ include/linux/iio/types.h +6
-1@@ -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 {
PATCH v3 3/7 iio: core: Introduce IIO_EV_DIR_NONE
In reply to Daniel BalutaFrom: 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.
--- drivers/iio/industrialio-event.c | 12 +++++++++--- include/linux/iio/types.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/iio/industrialio-event.c +9 -3
@@ -327,9 +327,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 ;
include/linux/iio/types.h +1 -0
@@ -86,6 +86,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
Signature · 1 line
1.9.1
PATCH v3 4/7 iio: core: Introduce STEPS channel, ENABLE mask and INSTANCE event
In reply to Daniel BalutaFrom: 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
--- 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(+)
Documentation/ABI/testing/sysfs-bus-iio +22 -0
@@ -849,6 +849,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]
@@ -1088,3 +1095,18 @@ Description: after application of scale and offset. If no offset or scale is present, output should be considered as processed with the unit in milliamps. + +What: /sys/.../iio:deviceX/in_steps_en +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.
drivers/iio/industrialio-core.c +2 -0
@@ -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", };/**
drivers/iio/industrialio-event.c +1 -0
@@ -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_INSTANCE] = "instance", };static const char *const iio_ev_dir_text[] = {
include/linux/iio/iio.h +1 -0
@@ -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 {
include/linux/iio/types.h +2 -0
@@ -31,6 +31,7 @@ enum iio_chan_type {IIO_PRESSURE ,IIO_HUMIDITYRELATIVE ,IIO_ACTIVITY , + IIO_STEPS, }; enum iio_modifier {
@@ -73,6 +74,7 @@ enum iio_event_type {IIO_EV_TYPE_ROC ,IIO_EV_TYPE_THRESH_ADAPTIVE ,IIO_EV_TYPE_MAG_ADAPTIVE , + IIO_EV_TYPE_INSTANCE, }; enum iio_event_info {
Signature · 1 line
1.9.1
PATCH v3 5/7 iio: core: Introduce IIO_CHAN_INFO_CALIBHEIGHT
In reply to Daniel BalutaFrom: 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.
--- Documentation/ABI/testing/sysfs-bus-iio | 8 ++++++++ drivers/iio/industrialio-core.c | 1 + include/linux/iio/iio.h | 1 + 3 files changed, 10 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +8 -0
@@ -320,6 +320,14 @@ Description: production inaccuracies). If shared across all channels, <type>_calibscale is used. +What: /sys/bus/iio/devices/iio:deviceX/in_steps_calibheight +KernelVersion: 3.19 +Contact: [email protected] +Description: + Height of the user (in centimeters) used by some pedometers + to compute the stride length, distance, speed and activity + type. + What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available What: /sys/.../iio:deviceX/in_voltageX_scale_available What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available
drivers/iio/industrialio-core.c +1 -0
@@ -120,6 +120,7 @@ static const char * const iio_chan_info_postfix[] = { [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis", [IIO_CHAN_INFO_INT_TIME] = "integration_time", [IIO_CHAN_INFO_ENABLE] = "en", + [IIO_CHAN_INFO_CALIBHEIGHT] = "calibheight", };/**
include/linux/iio/iio.h +1 -0
@@ -38,6 +38,7 @@ enum iio_chan_info_enum {IIO_CHAN_INFO_HYSTERESIS ,IIO_CHAN_INFO_INT_TIME ,IIO_CHAN_INFO_ENABLE , + IIO_CHAN_INFO_CALIBHEIGHT, }; enum iio_shared_by {
Signature · 1 line
1.9.1
PATCH v3 6/7 iio: dummy: Demonstrate the usage of new channel types
In reply to Daniel BalutaAdds 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 IIO_CHAN_INFO_CALIBHEIGHT mask bit for reading and writing user's height.
--- drivers/staging/iio/iio_simple_dummy.c | 199 +++++++++++++++++++++++--- drivers/staging/iio/iio_simple_dummy.h | 5 + drivers/staging/iio/iio_simple_dummy_events.c | 43 ++++++ 3 files changed, 229 insertions(+), 18 deletions(-)
drivers/staging/iio/iio_simple_dummy.c +181 -18
@@ -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_THRESH , + .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_THRESH , + .dir =IIO_EV_DIR_FALLING , + .mask_separate =BIT (IIO_EV_INFO_VALUE ) |BIT (IIO_EV_INFO_ENABLE ), +};#endif /*
@@ -215,6 +243,37 @@ 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 ) | + BIT(IIO_CHAN_INFO_CALIBHEIGHT), + .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_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 */ + }, };/**
@@ -263,24 +322,55 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,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 ; + } +break ;case IIO_CHAN_INFO_OFFSET :/* only single ended adc -> 7 */ *val =7 ; 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 ; +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 +388,27 @@ 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 ; +case IIO_CHAN_INFO_CALIBHEIGHT : +switch (chan->type) { +case IIO_STEPS : + *val = st->height; + ret =IIO_VAL_INT ; +break ; +default : +break ; + } +break ; +default :break ; }
@@ -330,14 +441,45 @@ 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 ; +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,6 +498,24 @@ 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 ; + } +case IIO_CHAN_INFO_CALIBHEIGHT : +switch (chan->type) { +case IIO_STEPS : + st->height = val; +return 0 ; +default : +return -EINVAL ; + }default :return -EINVAL ;
@@ -395,6 +555,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 ; }
drivers/staging/iio/iio_simple_dummy.h +5 -0
@@ -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;
drivers/staging/iio/iio_simple_dummy_events.c +43 -0
55 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 7/7 iio: event_monitor: Add support for new channel types
In reply to Daniel BalutaWe 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: thresh, direction: rising
Event: time: 1412786530792974091, type: activity(walking), channel: 0,
evtype: thresh, 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
--- .../staging/iio/Documentation/iio_event_monitor.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/staging/iio/Documentation/iio_event_monitor.c +20 -3
@@ -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,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_INSTANCE] = "instance", };static const char *const iio_ev_dir_text[] = {
@@ -79,6 +82,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 +115,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 +135,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 +150,7 @@ 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_INSTANCE :break ;default :return false;
@@ -146,6 +160,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 +201,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)
Signature · 1 line
1.9.1