Add configfs support for software triggers in IIO
Subsystems (2)
cover Add configfs support for software triggers in IIO
This patchset adds initial support for configfs in IIO. It is structured in the following way:
* patch 1 - adds configfs infrastructure creating an "iio" configfs subystem + an initial "triggers" group.
* patch 2 - adds the first "real" trigger type - hrtimer.
* patch 3 - adds Documentation
Daniel Baluta (3):
iio: configfs: Add configfs support to IIO
iio: trigger: Add support for highres timer trigger
iio: Documentation: Add initial documentaton for IIO
Documentation/iio/iio_configfs.txt | 74 ++++++++ drivers/iio/Kconfig | 8 + drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 301 +++++++++++++++++++++++++++++++ drivers/iio/trigger/Kconfig | 8 + drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 146 +++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 49 +++++ 8 files changed, 589 insertions(+) create mode 100644 Documentation/iio/iio_configfs.txt create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c create mode 100644 include/linux/iio/iio_configfs_trigger.h
Signature · 1 line
1.9.1
PATCH 1/3 iio: configfs: Add configfs support to IIO
This creates an IIO configfs subsystem named "iio", which has one default group named "triggers". This allows us to easily create/destroy software triggers. One must create a driver which implements iio_configfs_trigger.h interface and then add its trigger type to IIO configfs core.
See Documentation/iio/iio_configfs.txt for more details on how configfs support for IIO works.
--- drivers/iio/Kconfig | 8 + drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 297 +++++++++++++++++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 48 +++++ 4 files changed, 354 insertions(+) create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 include/linux/iio/iio_configfs_trigger.h
drivers/iio/Kconfig +8 -0
@@ -18,6 +18,14 @@ config IIO_BUFFER Provide core support for various buffer based data acquisition methods. +config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g software trigger creation / destruction). For more info + see Documentation/iio/iio_configfs.txt. + if IIO_BUFFER config IIO_BUFFER_CB
drivers/iio/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o +industrialio-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o
drivers/iio/industrialio-configfs.c new file +297 -0
297 lines not on this page · raw message
include/linux/iio/iio_configfs_trigger.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 1/3] iio: configfs: Add configfs support to IIO
Quoted 5 lines
This creates an IIO configfs subsystem named "iio", which has one default group named "triggers". This allows us to easily create/destroy software triggers. One must create a driver which implements
iio_configfs_trigger.hinterface and then add its trigger type to IIO configfs core.
some minor things noted below... I'm just trying to understand what this is about :)
Quoted 84 lines
See
Documentation/iio/iio_configfs.txtfor more details on how configfs support for IIO works.Signed-off-by Daniel Baluta <[email protected]>--- drivers/iio/Kconfig | 8 + drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 297 +++++++++++++++++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 48 +++++ 4 files changed, 354 insertions(+) create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 include/linux/iio/iio_configfs_trigger.hdrivers/iio/Kconfig +8
-0@@ -18,6 +18,14 @@ config IIO_BUFFER Provide core support for various buffer based data acquisition methods. +config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g software trigger creation / destruction). For more info + see Documentation/iio/iio_configfs.txt. + if IIO_BUFFER config IIO_BUFFER_CBdrivers/iio/Makefile +1
-0@@ -5,6 +5,7 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o +industrialio-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.odrivers/iio/industrialio-configfs.c new file +34
-0@@ -0,0 +1,297 @@ +/* +* Industrial I/O configfs bits +* +* Copyright (c) 2015 Intel Corporation +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ + +#include <linux/configfs.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/iio/iio_configfs_trigger.h> + +static const char *trigger_types[] = +{ +"none" , +}; + +struct iio_configfs_ops iio_none_ops = { + .get_freq = iio_none_get_freq, + .set_freq = iio_none_set_freq, + .probe = iio_none_probe, + .remove = iio_none_remove, +}; + +struct iio_trigger_item { +struct config_item item; +struct iio_configfs_trigger_info *trigger_info; +}; + +static
drivers/iio/industrialio-configfs.c line 44
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+inline struct iio_trigger_item *to_iio_trigger_item (struct config_item *item) +{ +if (!item) +return NULL ; + return container_of(item, struct iio_trigger_item, item); +} + +static unsigned int iio_trigger_get_type (const char *type_str) +{ +int i;
unsigned
the function returns an index, not a type; probably get_type_index()?
Quoted 9 lines
drivers/iio/industrialio-configfs.c new file +9
-0+ +for (i =0 ; i <ARRAY_SIZE (trigger_types); i++) { +if (!strncmp (trigger_types[i], type_str, +strlen (trigger_types[i]))) +return i; + } +return -EINVAL ; +} +
drivers/iio/industrialio-configfs.c line 63
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+static +void iio_trigger_set_configfs_ops (struct iio_configfs_trigger_info *trig_info, +unsigned int type) +{ +switch (type) { +case IIO_TRIGGER_TYPE_NONE : + trig_info->configfs_ops = &iio_none_ops; +break ; +default : +pr_err ("Setting configfs ops failed! Unknown type %d\n" , type);
%u
Quoted 73 lines
drivers/iio/industrialio-configfs.c new file +73
-0+break ; + } +} + +CONFIGFS_ATTR_STRUCT (iio_trigger_item); + +#define IIO_TRIGGER_ITEM_ATTR (_name, _mode, _show, _store) \ +struct iio_trigger_item_attribute iio_trigger_item_attr_##_name = \ + __CONFIGFS_ATTR(_name, _mode, _show, _store) + +static ssize_t iio_trigger_item_type_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%s\n" , trigger_types[item->trigger_info->type]); +} + +static ssize_t iio_trigger_item_type_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +int type; + +if (item->trigger_info->active) +return -EBUSY ; + + type =iio_trigger_get_type (page); +if (type <0 ) +return -EINVAL ; + + item->trigger_info->type = type; + +iio_trigger_set_configfs_ops (item->trigger_info, type); + +return count; +} + +static ssize_t iio_trigger_item_activate_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%d\n" , item->trigger_info->active); +} + +static ssize_t iio_trigger_item_activate_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +bool requested_action; +int ret; + + ret =strtobool (page, &requested_action); +if (ret <0 ) +return ret; + +if (requested_action == item->trigger_info->active) +return -EINVAL ; + +if (requested_action) + item->trigger_info->configfs_ops->probe (item->trigger_info); +else + item->trigger_info->configfs_ops->remove (item->trigger_info); + + item->trigger_info->active = requested_action; + +return count; +} + +static +ssize_t iio_trigger_item_get_sampling_freq (struct iio_trigger_item *item, +char *page) +{ +int ret; + +if (!item->trigger_info->active) +return -ENODEV ; +
drivers/iio/industrialio-configfs.c line 146
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+ ret = item->trigger_info->configfs_ops->get_freq (item->trigger_info); +if (ret <0 ) +return ret; +return sprintf (page,"%d\n" , ret); +} + +static +ssize_t iio_trigger_item_set_sampling_freq (struct iio_trigger_item *item, +const char *page, +size_t count)
count is size_t, return type is ssize_t
Quoted 157 lines
drivers/iio/industrialio-configfs.c new file +151
-0+{ +int ret; +unsigned long freq; + +if (!item->trigger_info->active) +return -ENODEV ; + + ret =kstrtoul (page,10 , &freq); +if (ret <0 ) +return 0 ; + + ret = item->trigger_info->configfs_ops->set_freq (item->trigger_info, + freq); +if (ret <0 ) +return ret; + +return count; +} + +IIO_TRIGGER_ITEM_ATTR (type,S_IRUGO |S_IWUSR , + iio_trigger_item_type_read, + iio_trigger_item_type_write); + +IIO_TRIGGER_ITEM_ATTR (activate,S_IRUGO |S_IWUSR , + iio_trigger_item_activate_read, + iio_trigger_item_activate_write); + +IIO_TRIGGER_ITEM_ATTR (sampling_frequency,S_IRUGO |S_IWUSR , + iio_trigger_item_get_sampling_freq, + iio_trigger_item_set_sampling_freq); + +static struct configfs_attribute *iio_trigger_item_attrs[] = { + &iio_trigger_item_attr_type.attr, + &iio_trigger_item_attr_sampling_frequency.attr, + &iio_trigger_item_attr_activate.attr, +NULL +}; + +CONFIGFS_ATTR_OPS (iio_trigger_item); + +static struct configfs_item_operations iio_trigger_item_ops = { + .show_attribute = iio_trigger_item_attr_show, + .store_attribute = iio_trigger_item_attr_store, +}; + +static struct config_item_type iio_triggers_item_type; + +static struct config_item *iio_triggers_make_item (struct config_group *group, +const char *name) +{ +struct iio_trigger_item *trigger_item; +struct iio_configfs_trigger_info *trigger_info; + + trigger_item =kzalloc (sizeof (*trigger_item),GFP_KERNEL ); +if (!trigger_item) +return ERR_PTR (-ENOMEM ); + trigger_info =kzalloc (sizeof (*trigger_info),GFP_KERNEL ); +if (!trigger_info) + goto out_free_trigger_item; + + trigger_info->name =kstrdup (name,GFP_KERNEL ); +if (!trigger_info->name) + goto out_free_trigger_info; + + trigger_info->type =IIO_TRIGGER_TYPE_NONE ; + trigger_info->configfs_ops = &iio_none_ops; + + trigger_item->trigger_info = trigger_info; +config_item_init_type_name (&trigger_item->item, name, + &iio_triggers_item_type); + +return &trigger_item->item; +out_free_trigger_info: +kfree (trigger_info); +out_free_trigger_item: +kfree (trigger_item); +return ERR_PTR (-ENOMEM ); +} + +static void iio_triggers_drop_item (struct config_group *group, +struct config_item *item) +{ +struct iio_trigger_item *trigger_item; + + trigger_item = container_of(item, struct iio_trigger_item, item); + +kfree (trigger_item->trigger_info->name); +kfree (trigger_item->trigger_info); +kfree (trigger_item); +} + +static struct configfs_group_operations iio_triggers_group_ops = { + .make_item = iio_triggers_make_item, + .drop_item = iio_triggers_drop_item, +}; + +static struct config_item_type iio_triggers_item_type = { + .ct_owner =THIS_MODULE , + .ct_item_ops = &iio_trigger_item_ops, + .ct_attrs = iio_trigger_item_attrs, +}; + +static struct config_item_type iio_triggers_root_type = { + .ct_owner =THIS_MODULE , + .ct_group_ops = &iio_triggers_group_ops, +}; + +static struct config_group iio_triggers_group = { + .cg_item = { + .ci_namebuf ="triggers" , + .ci_type = &iio_triggers_root_type, + }, +}; + +static struct config_group *iio_default_groups[] = { + &iio_triggers_group, +NULL +}; + +static struct config_item_type iio_root_group_type = { + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem iio_configfs_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf ="iio" , + .ci_type = &iio_root_group_type, + }, + .default_groups = iio_default_groups, + }, + .su_mutex =__MUTEX_INITIALIZER (iio_configfs_subsys.su_mutex), +}; + +static int __init iio_configfs_init (void ) +{ +config_group_init (&iio_triggers_group); +config_group_init (&iio_configfs_subsys.su_group); + +return configfs_register_subsystem (&iio_configfs_subsys); +} +module_init (iio_configfs_init); + +static void __exit iio_configfs_exit(void) +{ +configfs_unregister_subsystem (&iio_configfs_subsys); +} +module_exit (iio_configfs_exit); + +MODULE_AUTHOR ("Daniel Baluta <[email protected]>" ); +MODULE_DESCRIPTION ("Industrial I/O configfs support" );include/linux/iio/iio_configfs_trigger.h new file +0
-0
include/linux/iio/iio_configfs_trigger.h line 9
Quoted 9 lines
include/linux/iio/iio_configfs_trigger.h new file +9
-0@@ -0,0 +1,48 @@ +#ifndef __IIO_CONFIGFS_TRIGGER +#define __IIO_CONFIGFS_TRIGGER + +#define IIO_TRIGGER_TYPE_NONE 0 + +struct iio_configfs_trigger_info { + const char *name; + unsigned int type; + unsigned int active;
bool?
include/linux/iio/iio_configfs_trigger.h line 15
Quoted 6 lines
include/linux/iio/iio_configfs_trigger.h new file +6
-0+struct iio_trigger *trigger; +struct iio_configfs_ops *configfs_ops; +}; + +struct iio_configfs_ops { +int (*get_freq)(struct iio_configfs_trigger_info * );
should return unsigned long?
extra space after * and before ) looks weird
Quoted 21 lines
include/linux/iio/iio_configfs_trigger.h new file +21
-0+int (*set_freq)(struct iio_configfs_trigger_info *,unsigned long ); +int (*probe)(struct iio_configfs_trigger_info * ); +int (*remove)(struct iio_configfs_trigger_info * ); +}; + +static +inline int iio_none_get_freq (struct iio_configfs_trigger_info *trigger_info) +{ +return 0 ; +} + +static +inline int iio_none_set_freq (struct iio_configfs_trigger_info *trigger_info, +unsigned long f) +{ +return 0 ; +} + +static +inline int iio_none_probe (struct iio_configfs_trigger_info *trigger_info) +{
include/linux/iio/iio_configfs_trigger.h line 46
Quoted 10 lines
include/linux/iio/iio_configfs_trigger.h new file +10
-0+return 0 ; +} + +static +inline int iio_none_remove (struct iio_configfs_trigger_info *trigger_info) +{ +return 0 ; +} + +extern struct iio_configfs_ops iio_hrtimer_ops;
shouldn't probably be here yet
Quoted 3 lines
include/linux/iio/iio_configfs_trigger.h new file +2
-0+ +#endif /* __IIO_CONFIGFS_TRIGGER */
Signature · 2 lines
Peter Meerwald +43-664-2444418 (mobile)
Re: [PATCH 1/3] iio: configfs: Add configfs support to IIO
In reply to Daniel BalutaA license nit.
drivers/iio/industrialio-configfs.c
Quoted 9 lines · Daniel Baluta
drivers/iio/industrialio-configfs.c new file +5
-0+* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +MODULE_AUTHOR("Daniel Baluta <[email protected]>"); +MODULE_DESCRIPTION("Industrial I/O configfs support");
You probably want
MODULE_LICENSE("GPL v2");here too. Because now, at module load time, the license will default to "unspecified" which will taint the kernel.
Paul Bolle
Re: [PATCH 1/3] iio: configfs: Add configfs support to IIO
Quoted 10 lines · Paul Bolle
A license nit.
Quoted 6 lines · Daniel Baluta
drivers/iio/industrialio-configfs.c new file +3
-0+* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation.
Quoted 8 lines
drivers/iio/industrialio-configfs.c line 297
Quoted 2 lines
drivers/iio/industrialio-configfs.c new file +2
-0+MODULE_AUTHOR ("Daniel Baluta <[email protected]>" ); +MODULE_DESCRIPTION ("Industrial I/O configfs support" );You probably want
MODULE_LICENSE("GPL v2");here too. Because now, at module load time, the license will default to "unspecified" which will taint the kernel.
:), correct! I forgot about it.
Daniel.
Re: [PATCH 1/3] iio: configfs: Add configfs support to IIO
In reply to Daniel BalutaQuoted 9 lines · Daniel Baluta
This creates an IIO configfs subsystem named "iio", which has one default group named "triggers". This allows us to easily create/destroy software triggers. One must create a driver which implements
iio_configfs_trigger.hinterface and then add its trigger type to IIO configfs core.See
Documentation/iio/iio_configfs.txtfor more details on how configfs support for IIO works.Signed-off-by Daniel Baluta <[email protected]>
Very good stuff, thanks.
[...]
Quoted 16 lines
drivers/iio/industrialio-configfs.c new file +10
-0@@ -0,0 +1,297 @@ +/* +* Industrial I/O configfs bits +* +* Copyright (c) 2015 Intel Corporation +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ +
drivers/iio/industrialio-configfs.c line 20
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+#include <linux/configfs.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/iio/iio_configfs_trigger.h> + +static const char *trigger_types[] = +{ +"none" , +};
This doesn't necessarily need to be in the initial implementation, but it would be good instead of having a global registry inside the core module to have a set of functions that allow to register a configfs trigger. These functions can be called from the module that implements the trigger in the init and exit section. A helper macro similar to module_platform_driver that auto-generates those section would be helpful.
Cause right now we do have the dependencies wrong. The core module has a symbol dependency on the trigger modules implementing the trigger. That means you need to load the trigger module before the core module and also means that if at least one trigger is build as a module the core also needs to be built as a module.
E.g. lets say there are triggerA, triggerB and triggerC. All build as a module. If you want to use any of them you still have to load all of them since the core module has a dependency on all of them.
Quoted 36 lines
drivers/iio/industrialio-configfs.c new file +36
-0+ +struct iio_configfs_ops iio_none_ops = { + .get_freq = iio_none_get_freq, + .set_freq = iio_none_set_freq, + .probe = iio_none_probe, + .remove = iio_none_remove, +}; + +struct iio_trigger_item { +struct config_item item; +struct iio_configfs_trigger_info *trigger_info; +}; + +static +inline struct iio_trigger_item *to_iio_trigger_item (struct config_item *item) +{ +if (!item) +return NULL ; + return container_of(item, struct iio_trigger_item, item); +} + +static unsigned int iio_trigger_get_type (const char *type_str) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (trigger_types); i++) { +if (!strncmp (trigger_types[i], type_str, +strlen (trigger_types[i]))) +return i; + } +return -EINVAL ; +} + +static +void iio_trigger_set_configfs_ops (struct iio_configfs_trigger_info *trig_info, +unsigned int type)
drivers/iio/industrialio-configfs.c line 66
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+{ +switch (type) { +case IIO_TRIGGER_TYPE_NONE : + trig_info->configfs_ops = &iio_none_ops; +break ; +default : +pr_err ("Setting configfs ops failed! Unknown type %d\n" , type); +break ; + } +}
I wonder if it is not better to have a sub-directory per trigger type and if you create a trigger in the sub-directory it is automatically of that type.
The advantage is that you can have e.g. trigger specific properties.
The downside is that you no longer have a global namespace and there could be name collisions by creating triggers with the same name, but with different types. This could be solved though by making sure that the internal name is pre-fixed by the type. E.g. "hrtimer-foobar" or "hrtimer/foobar".
Quoted 50 lines
drivers/iio/industrialio-configfs.c new file +50
-0+ +CONFIGFS_ATTR_STRUCT (iio_trigger_item); + +#define IIO_TRIGGER_ITEM_ATTR (_name, _mode, _show, _store) \ +struct iio_trigger_item_attribute iio_trigger_item_attr_##_name = \ + __CONFIGFS_ATTR(_name, _mode, _show, _store) + +static ssize_t iio_trigger_item_type_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%s\n" , trigger_types[item->trigger_info->type]); +} + +static ssize_t iio_trigger_item_type_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +int type; + +if (item->trigger_info->active) +return -EBUSY ; + + type =iio_trigger_get_type (page); +if (type <0 ) +return -EINVAL ; + + item->trigger_info->type = type; + +iio_trigger_set_configfs_ops (item->trigger_info, type); + +return count; +} + +static ssize_t iio_trigger_item_activate_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%d\n" , item->trigger_info->active); +} + +static ssize_t iio_trigger_item_activate_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +bool requested_action; +int ret; + + ret =strtobool (page, &requested_action); +if (ret <0 ) +return ret; + +if (requested_action == item->trigger_info->active) +return -EINVAL ;
drivers/iio/industrialio-configfs.c line 126
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+ +if (requested_action) + item->trigger_info->configfs_ops->probe (item->trigger_info); +else + item->trigger_info->configfs_ops->remove (item->trigger_info); + + item->trigger_info->active = requested_action; + +return count; +}
Do we need the activate attribute? Shouldn't the trigger be create/destroyed if the type field is changed? Or if we have one directory per trigger type when the directory for the trigger is created using mkdir? I think that would make a nice more natural API.
[...]
Jonathan Cameron
maintainerRe: [PATCH 1/3] iio: configfs: Add configfs support to IIO
Quoted 90 lines · Lars-Peter Clausen
Quoted 9 lines · Daniel Baluta
This creates an IIO configfs subsystem named "iio", which has one default group named "triggers". This allows us to easily create/destroy software triggers. One must create a driver which implements
iio_configfs_trigger.hinterface and then add its trigger type to IIO configfs core.See
Documentation/iio/iio_configfs.txtfor more details on how configfs support for IIO works.Signed-off-by Daniel Baluta <[email protected]>Very good stuff, thanks.
[...]
Quoted 16 lines
drivers/iio/industrialio-configfs.c new file +10
-0@@ -0,0 +1,297 @@ +/* +* Industrial I/O configfs bits +* +* Copyright (c) 2015 Intel Corporation +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ +drivers/iio/industrialio-configfs.c line 20
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+#include <linux/configfs.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/iio/iio_configfs_trigger.h> + +static const char *trigger_types[] = +{ +"none" , +};This doesn't necessarily need to be in the initial implementation, but it would be good instead of having a global registry inside the core module to have a set of functions that allow to register a configfs trigger. These functions can be called from the module that implements the trigger in the init and exit section. A helper macro similar to
module_platform_driverthat auto-generates those section would be helpful.Cause right now we do have the dependencies wrong. The core module has a symbol dependency on the trigger modules implementing the trigger. That means you need to load the trigger module before the core module and also means that if at least one trigger is build as a module the core also needs to be built as a module.
E.g. lets say there are triggerA, triggerB and triggerC. All build as a module. If you want to use any of them you still have to load all of them since the core module has a dependency on all of them.
Quoted 43 lines
drivers/iio/industrialio-configfs.c new file +43
-0+ +struct iio_configfs_ops iio_none_ops = { + .get_freq = iio_none_get_freq, + .set_freq = iio_none_set_freq, + .probe = iio_none_probe, + .remove = iio_none_remove, +}; + +struct iio_trigger_item { +struct config_item item; +struct iio_configfs_trigger_info *trigger_info; +}; + +static +inline struct iio_trigger_item *to_iio_trigger_item (struct config_item *item) +{ +if (!item) +return NULL ; + return container_of(item, struct iio_trigger_item, item); +} + +static unsigned int iio_trigger_get_type (const char *type_str) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (trigger_types); i++) { +if (!strncmp (trigger_types[i], type_str, +strlen (trigger_types[i]))) +return i; + } +return -EINVAL ; +} + +static +void iio_trigger_set_configfs_ops (struct iio_configfs_trigger_info *trig_info, +unsigned int type) +{ +switch (type) { +case IIO_TRIGGER_TYPE_NONE : + trig_info->configfs_ops = &iio_none_ops; +break ; +default : +pr_err ("Setting configfs ops failed! Unknown type %d\n" , type);
Quoted 8 lines
drivers/iio/industrialio-configfs.c line 66
Quoted 3 lines
drivers/iio/industrialio-configfs.c new file +3
-0+break ; + } +}I wonder if it is not better to have a sub-directory per trigger type and if you create a trigger in the sub-directory it is automatically of that type.
I agree, this would perhaps be more flexible / intuitive.
Quoted 2 lines
The advantage is that you can have e.g. trigger specific properties.
The initial set of triggers will be (I guess!)
* high resolution timer
* sysfs (userspace trigger) - in parallel with it's existing sysfs interface which unfortunately we'll have to keep for at least a few years.
Later on, once we have in kernel interfaces for events I'd expect we'll want event fired triggers (grab data based on an event from the same device or a different one for that matter)...
Anyhow, definitely going to want different properties for these!
Quoted 6 lines
The downside is that you no longer have a global namespace and there could be name collisions by creating triggers with the same name, but with different types. This could be solved though by making sure that the internal name is pre-fixed by the type. E.g. "hrtimer-foobar" or "hrtimer/foobar".
Yes, the prefix would be sensible.
Quoted 59 lines
Quoted 59 lines
drivers/iio/industrialio-configfs.c new file +59
-0+ +CONFIGFS_ATTR_STRUCT (iio_trigger_item); + +#define IIO_TRIGGER_ITEM_ATTR (_name, _mode, _show, _store) \ +struct iio_trigger_item_attribute iio_trigger_item_attr_##_name = \ + __CONFIGFS_ATTR(_name, _mode, _show, _store) + +static ssize_t iio_trigger_item_type_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%s\n" , trigger_types[item->trigger_info->type]); +} + +static ssize_t iio_trigger_item_type_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +int type; + +if (item->trigger_info->active) +return -EBUSY ; + + type =iio_trigger_get_type (page); +if (type <0 ) +return -EINVAL ; + + item->trigger_info->type = type; + +iio_trigger_set_configfs_ops (item->trigger_info, type); + +return count; +} + +static ssize_t iio_trigger_item_activate_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%d\n" , item->trigger_info->active); +} + +static ssize_t iio_trigger_item_activate_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +bool requested_action; +int ret; + + ret =strtobool (page, &requested_action); +if (ret <0 ) +return ret; + +if (requested_action == item->trigger_info->active) +return -EINVAL ; + +if (requested_action) + item->trigger_info->configfs_ops->probe (item->trigger_info); +else + item->trigger_info->configfs_ops->remove (item->trigger_info); + + item->trigger_info->active = requested_action; + +return count;
Quoted 8 lines
drivers/iio/industrialio-configfs.c line 126
Quoted 1 line
drivers/iio/industrialio-configfs.c new file +1
-0+}Do we need the activate attribute? Shouldn't the trigger be create/destroyed if the type field is changed? Or if we have one directory per trigger type when the directory for the trigger is created using mkdir? I think that would make a nice more natural API.>
[...]
Only exception would be a trigger that has no meaning until we have configured it - e.g. the event triggers mentioned above. That would need an explicit activate. Question is whether we want to start out with that interface for all triggers on the basis it will be needed later?
Actually come to think of it, there is no problem with registering an unconfigured trigger - just with using it. Hence we could do so and only fault out when a buffer using the trigger is started. That works for the complex usecase (as long as we spit out appropriate log messages / error codes).
Hence if we can get away with doing everything on the mkdir that would be great.
Quoted 5 lines
Signature · 4 lines
-- 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
Re: [PATCH 1/3] iio: configfs: Add configfs support to IIO
Quoted 44 lines · Jonathan Cameron
Quoted 43 lines · Lars-Peter Clausen
Quoted 9 lines · Daniel Baluta
This creates an IIO configfs subsystem named "iio", which has one default group named "triggers". This allows us to easily create/destroy software triggers. One must create a driver which implements
iio_configfs_trigger.hinterface and then add its trigger type to IIO configfs core.See
Documentation/iio/iio_configfs.txtfor more details on how configfs support for IIO works.Signed-off-by Daniel Baluta <[email protected]>Very good stuff, thanks.
[...]
Quoted 16 lines
drivers/iio/industrialio-configfs.c new file +10
-0@@ -0,0 +1,297 @@ +/* +* Industrial I/O configfs bits +* +* Copyright (c) 2015 Intel Corporation +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ +drivers/iio/industrialio-configfs.c line 20
Quoted 10 lines
drivers/iio/industrialio-configfs.c new file +10
-0+#include <linux/configfs.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/iio/iio_configfs_trigger.h> + +static const char *trigger_types[] = +{ +"none" , +};This doesn't necessarily need to be in the initial implementation, but it would be good instead of having a global registry inside the core module to have a set of functions that allow to register a configfs trigger. These functions can be called from the module that implements the trigger in the init and exit section. A helper macro similar to
module_platform_driverthat auto-generates those section would be helpful.
Quoted 3 lines
Quoted 3 lines
Cause right now we do have the dependencies wrong. The core module has a symbol dependency on the trigger modules implementing the trigger. That means you need to load the trigger module before the core module and also means that if at least one trigger is build as a module the core also needs to be built as a module.
E.g. lets say there are triggerA, triggerB and triggerC. All build as a module. If you want to use any of them you still have to load all of them since the core module has a dependency on all of them.
Good point. I think this is the correct solution. I will add this approach in v2.
Quoted 49 lines
Quoted 48 lines
Quoted 47 lines
drivers/iio/industrialio-configfs.c new file +46
-0+ +struct iio_configfs_ops iio_none_ops = { + .get_freq = iio_none_get_freq, + .set_freq = iio_none_set_freq, + .probe = iio_none_probe, + .remove = iio_none_remove, +}; + +struct iio_trigger_item { +struct config_item item; +struct iio_configfs_trigger_info *trigger_info; +}; + +static +inline struct iio_trigger_item *to_iio_trigger_item (struct config_item *item) +{ +if (!item) +return NULL ; + return container_of(item, struct iio_trigger_item, item); +} + +static unsigned int iio_trigger_get_type (const char *type_str) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (trigger_types); i++) { +if (!strncmp (trigger_types[i], type_str, +strlen (trigger_types[i]))) +return i; + } +return -EINVAL ; +} + +static +void iio_trigger_set_configfs_ops (struct iio_configfs_trigger_info *trig_info, +unsigned int type) +{ +switch (type) { +case IIO_TRIGGER_TYPE_NONE : + trig_info->configfs_ops = &iio_none_ops; +break ; +default : +pr_err ("Setting configfs ops failed! Unknown type %d\n" , type); +break ; + } +}
Quoted 4 lines
Quoted 3 lines
I wonder if it is not better to have a sub-directory per trigger type and if you create a trigger in the sub-directory it is automatically of that type.
I agree, this would perhaps be more flexible / intuitive.
Great, this sounds more in the spirit of configfs. Will add it in v2.
Quoted 14 lines
Quoted 2 lines
The advantage is that you can have e.g. trigger specific properties.
The initial set of triggers will be (I guess!)
* high resolution timer
* sysfs (userspace trigger) - in parallel with it's existing sysfs interface which unfortunately we'll have to keep for at least a few years.
Later on, once we have in kernel interfaces for events I'd expect we'll want event fired triggers (grab data based on an event from the same device or a different one for that matter)...Anyhow, definitely going to want different properties for these!
Quoted 1 line
Quoted 6 lines
Quoted 5 lines
The downside is that you no longer have a global namespace and there could be name collisions by creating triggers with the same name, but with different types. This could be solved though by making sure that the internal name is pre-fixed by the type. E.g. "hrtimer-foobar" or "hrtimer/foobar".
Yes, the prefix would be sensible.
It is sensible, but we will enforce it at the driver level.
Quoted 68 lines
Quoted 60 lines
Quoted 60 lines
drivers/iio/industrialio-configfs.c new file +59
-0+ +CONFIGFS_ATTR_STRUCT (iio_trigger_item); + +#define IIO_TRIGGER_ITEM_ATTR (_name, _mode, _show, _store) \ +struct iio_trigger_item_attribute iio_trigger_item_attr_##_name = \ + __CONFIGFS_ATTR(_name, _mode, _show, _store) + +static ssize_t iio_trigger_item_type_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%s\n" , trigger_types[item->trigger_info->type]); +} + +static ssize_t iio_trigger_item_type_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +int type; + +if (item->trigger_info->active) +return -EBUSY ; + + type =iio_trigger_get_type (page); +if (type <0 ) +return -EINVAL ; + + item->trigger_info->type = type; + +iio_trigger_set_configfs_ops (item->trigger_info, type); + +return count; +} + +static ssize_t iio_trigger_item_activate_read (struct iio_trigger_item *item, +char *page) +{ +return sprintf (page,"%d\n" , item->trigger_info->active); +} + +static ssize_t iio_trigger_item_activate_write (struct iio_trigger_item *item, +const char *page,size_t count) +{ +bool requested_action; +int ret; + + ret =strtobool (page, &requested_action); +if (ret <0 ) +return ret; + +if (requested_action == item->trigger_info->active) +return -EINVAL ; + +if (requested_action) + item->trigger_info->configfs_ops->probe (item->trigger_info); +else + item->trigger_info->configfs_ops->remove (item->trigger_info); + + item->trigger_info->active = requested_action; + +return count;Quoted 8 lines
drivers/iio/industrialio-configfs.c line 126
Quoted 1 line
drivers/iio/industrialio-configfs.c new file +1
-0+}Do we need the activate attribute? Shouldn't the trigger be create/destroyed if the type field is changed? Or if we have one directory per trigger type when the directory for the trigger is created using mkdir? I think that would make a nice more natural API.>
[...]
Quoted 5 lines
Only exception would be a trigger that has no meaning until we have configured it - e.g. the event triggers mentioned above. That would need an explicit activate. Question is whether we want to start out with that interface for all triggers on the basis it will be needed later?
Yes, I was thinking at the case where the trigger needs first to be configured and then activated. But for hrtimers I think we can remove activate attribute for now.
Quoted 9 lines
Actually come to think of it, there is no problem with registering an unconfigured trigger - just with using it. Hence we could do so and only fault out when a buffer using the trigger is started. That works for the complex usecase (as long as we spit out appropriate log messages / error codes).
Hence if we can get away with doing everything on the mkdir that would be great.
Thanks for the feedback. I will send v2 asap.
Daniel.
PATCH 2/3 iio: trigger: Add support for highres timer trigger
In reply to Daniel BalutaThis patch adds an IIO trigger driver which uses a high resolution timer to provide a frequency based trigger.
--- drivers/iio/industrialio-configfs.c | 4 + drivers/iio/trigger/Kconfig | 8 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 146 +++++++++++++++++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 1 + 5 files changed, 161 insertions(+) create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c
drivers/iio/industrialio-configfs.c +4 -0
@@ -17,6 +17,7 @@static const char *trigger_types[] = {"none" , +"hrtimer" , };struct iio_configfs_ops iio_none_ops = {
@@ -59,6 +60,9 @@ void iio_trigger_set_configfs_ops(struct iio_configfs_trigger_info *trig_info,case IIO_TRIGGER_TYPE_NONE : trig_info->configfs_ops = &iio_none_ops;break ; +case IIO_TRIGGER_TYPE_HRTIMER : + trig_info->configfs_ops = &iio_hrtimer_ops; +break ;default :pr_err ("Setting configfs ops failed! Unknown type %d\n" , type);break ;
drivers/iio/trigger/Kconfig +8 -0
@@ -5,6 +5,14 @@ menu "Triggers - standalone" +config IIO_TRIGGER_HRTIMER + tristate "High resolution timer trigger" + help + Provides a frequency based IIO trigger using hrtimers. + + To compile this driver as a module, choose M here: the + module will be called iio-trig-hrtimer. + config IIO_INTERRUPT_TRIGGER tristate "Generic interrupt trigger" help
drivers/iio/trigger/Makefile +2 -0
@@ -3,5 +3,7 @@ # # When adding new entries keep the list in alphabetical order + +obj-$(CONFIG_IIO_TRIGGER_HRTIMER) += iio-trig-hrtimer.o obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
drivers/iio/trigger/iio-trig-hrtimer.c new file +146 -0
146 lines not on this page · raw message
include/linux/iio/iio_configfs_trigger.h +1 -0
@@ -2,6 +2,7 @@#define __IIO_CONFIGFS_TRIGGER#define IIO_TRIGGER_TYPE_NONE 0 +#define IIO_TRIGGER_TYPE_HRTIMER 1struct iio_configfs_trigger_info {const char *name;
Signature · 1 line
1.9.1
PATCH 3/3 iio: Documentation: Add initial documentaton for IIO
In reply to Daniel BalutaThis file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
--- Documentation/iio/iio_configfs.txt | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/iio/iio_configfs.txt
Documentation/iio/iio_configfs.txt new file +74 -0
@@ -0,0 +1,74 @@ +Industrial IIO configfs support + +1. Overview + +Configfs is a filesystem-based manager of kernel objects. IIO uses some +objects that could be easily configured using configfs (e.g: devices, +triggers). + +See Documentation/filesystems/configfs/configfs.txt for more information about +how configfs works. + +2. Usage + +In order to use configfs support in IIO we need to select it at compile time +via CONFIG_IIO_CONFIGFS config option. + +Then, mount the configfs filesystem (usually under /config directory): + +$ mkdir /config +$ mount -t configfs none /config + +At this point, all default IIO groups will be creatd and can be accessed under +/config/iio. Next chapters will describe available IIO configurable objects. + +2.1. Software triggers creation and destruction + +One of the IIO default configfs groups is the "triggers" groups. It is +automagically accessible when the configfs is mounted and can be found under +/config/iio/triggers. + +2.1.1. Trigger creation + +As simply as: + +$ mkdir /config/triggers/my_trigger + +This will create a directory associated with a trigger. To understand how this +works we first need to see "my_triggers"'s attributes: + +$ ls /config/triggers/my_trigger +activate sampling_frequency type + +Available types for triggers are: + * none, this is a default dummy trigger that does nothing. + * hrtimer, this is trigger based on high resolution timer. + +Order of operations in order to create a "hrtimer" trigger: + +$ echo hrtimer > /config/triggers/my_trigger/type +$ echo 1 > /config/triggers/my_trigger/activate +$ echo 100 > /config/triggers/my_trigger/sampling_frequency + +At this point the trigger can be used by an IIO device. + +2.1.2 Trigger destruction + +$ echo 1 > /config/triggers/my_trigger/activate + +3. Misc + +In order to add a new trigger type, one need to implement a driver that creates +an instance of struct iio_configfs_ops (see iio_configfs_trigger.h header file +in include/linux/iio) and then support it in iio_trigger_set_configfs_ops +function from industrialiio-configfs.c file. + +These are the existing drivers implementing new trigger types: + * hrtimer => iio/trigger/iio-trig-hrtimer.c + +4. Further work + +* IIO dummy device creation +* Mappings to 'soft' in kernel users such as iio_input and iio_hwmon +* IIO on IIO drivers +
Signature · 1 line
1.9.1
Re: [PATCH 3/3] iio: Documentation: Add initial documentaton for IIO
Quoted 2 lines · Daniel Baluta
This file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
typos below; I'm just trying to understand what's going on...
Quoted 12 lines
Signed-off-by Daniel Baluta <[email protected]>--- Documentation/iio/iio_configfs.txt | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/iio/iio_configfs.txtDocumentation/iio/iio_configfs.txt new file +0
-0
Documentation/iio/iio_configfs.txt line 6
Quoted 6 lines
Documentation/iio/iio_configfs.txt new file +6
-0@@ -0,0 +1,74 @@ +Industrial IIO configfs support + +1. Overview + +Configfs is a filesystem-based manager of kernel objects. IIO uses some +objects that could be easily configured using configfs (e.g: devices,
e.g.
Quoted 6 lines
Documentation/iio/iio_configfs.txt new file +6
-0+triggers). + +See Documentation/filesystems/configfs/configfs.txt for more information about +how configfs works. + +2. Usage
Documentation/iio/iio_configfs.txt line 22
Quoted 10 lines
Documentation/iio/iio_configfs.txt new file +10
-0+ +In order to use configfs support in IIO we need to select it at compile time +via CONFIG_IIO_CONFIGFS config option. + +Then, mount the configfs filesystem (usually under /config directory): + +$ mkdir /config +$ mount -t configfs none /config + +At this point, all default IIO groups will be creatd and can be accessed under
created
Documentation/iio/iio_configfs.txt line 23
Quoted 1 line
Documentation/iio/iio_configfs.txt new file +1
-0+/config/iio. Next chapters will describe available IIO configurable objects.
IIO configuration objects?
Documentation/iio/iio_configfs.txt line 25
Quoted 2 lines
Documentation/iio/iio_configfs.txt new file +2
-0+ +2.1. Software triggers creation and destruction
trigger
Quoted 5 lines
Documentation/iio/iio_configfs.txt new file +5
-0+ +One of the IIO default configfs groups is the "triggers" groups. It is +automagically accessible when the configfs is mounted and can be found under +/config/iio/triggers. +
Documentation/iio/iio_configfs.txt line 40
Quoted 10 lines
Documentation/iio/iio_configfs.txt new file +10
-0+2.1.1. Trigger creation + +As simply as: + +$ mkdir /config/triggers/my_trigger + +This will create a directory associated with a trigger. To understand how this +works we first need to see "my_triggers"'s attributes: + +$ ls /config/triggers/my_trigger
should be config/iio/triggers? here and elsewhere?
Documentation/iio/iio_configfs.txt line 47
Quoted 7 lines
Documentation/iio/iio_configfs.txt new file +7
-0+activate sampling_frequency type + +Available types for triggers are: + * none, this is a default dummy trigger that does nothing. + * hrtimer, this is trigger based on high resolution timer. + +Order of operations in order to create a "hrtimer" trigger:
Sequence of operations, or just 'operations'
Documentation/iio/iio_configfs.txt line 57
Quoted 10 lines
Documentation/iio/iio_configfs.txt new file +10
-0+ +$ echo hrtimer > /config/triggers/my_trigger/type +$ echo 1 > /config/triggers/my_trigger/activate +$ echo 100 > /config/triggers/my_trigger/sampling_frequency + +At this point the trigger can be used by an IIO device. + +2.1.2 Trigger destruction + +$ echo 1 > /config/triggers/my_trigger/activate
echo 0
probably
Documentation/iio/iio_configfs.txt line 61
Quoted 4 lines
Documentation/iio/iio_configfs.txt new file +4
-0+ +3. Misc + +In order to add a new trigger type, one need to implement a driver that creates
needs
Documentation/iio/iio_configfs.txt line 72
Quoted 11 lines
Documentation/iio/iio_configfs.txt new file +11
-0+an instance of struct iio_configfs_ops (see iio_configfs_trigger.h header file +in include/linux/iio) and then support it in iio_trigger_set_configfs_ops +function from industrialiio-configfs.c file. + +These are the existing drivers implementing new trigger types: + * hrtimer => iio/trigger/iio-trig-hrtimer.c + +4. Further work + +* IIO dummy device creation +* Mappings to 'soft' in kernel users such as iio_input and iio_hwmon
in-kernel
Documentation/iio/iio_configfs.txt line 73
Quoted 1 line
Documentation/iio/iio_configfs.txt new file +1
-0+* IIO on IIO drivers
??
Quoted 2 lines
Documentation/iio/iio_configfs.txt new file +1
-0+
Signature · 2 lines
Peter Meerwald +43-664-2444418 (mobile)
Re: [PATCH 3/3] iio: Documentation: Add initial documentaton for IIO
Quoted 6 lines · Peter Meerwald
Quoted 2 lines · Daniel Baluta
This file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
typos below; I'm just trying to understand what's going on...
Hi Peter,
Thanks a lot for your time. I agree with all your comments for this patch and will fix in v2.
<snip>
Quoted 3 lines
Quoted 1 line
+* IIO on IIO drivers
??
I will add more details about this. I was trying to describe the IIO elements that
would make sense to be configured via configfs.
Have a look at Jonathan's email:
http://marc.info/?l=linux-iio&m=142693832028677&w=2
thanks,
Daniel.
Jonathan Cameron
maintainerRe: [PATCH 3/3] iio: Documentation: Add initial documentaton for IIO
Quoted 22 lines · Daniel Baluta
Quoted 6 lines · Peter Meerwald
Quoted 2 lines · Daniel Baluta
This file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
typos below; I'm just trying to understand what's going on...
Hi Peter,
Thanks a lot for your time. I agree with all your comments for this patch and will fix in v2.
<snip>Quoted 3 lines
Quoted 1 line
+* IIO on IIO drivers
??
I will add more details about this. I was trying to describe the IIO elements that
would make sense to be configured via configfs.
Quoted 7 lines
Have a look at Jonathan's email:
http://marc.info/?l=linux-iio&m=142693832028677&w=2
thanks,
Daniel.
Might be premature / confusing to put those in the help file! If anyone cares about our motivation for the structure here they can dig out the email threads!
Re: [PATCH 3/3] iio: Documentation: Add initial documentaton for IIO
Quoted 25 lines · Jonathan Cameron
Quoted 24 lines · Daniel Baluta
Quoted 6 lines · Peter Meerwald
Quoted 2 lines · Daniel Baluta
This file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
typos below; I'm just trying to understand what's going on...
Hi Peter,
Thanks a lot for your time. I agree with all your comments for this patch and will fix in v2.
<snip>Quoted 3 lines
Quoted 1 line
+* IIO on IIO drivers
??
I will add more details about this. I was trying to describe the IIO elements that
would make sense to be configured via configfs.Have a look at Jonathan's email:
Quoted 8 lines
Quoted 5 lines
http://marc.info/?l=linux-iio&m=142693832028677&w=2
thanks,
Daniel.Might be premature / confusing to put those in the help file! If anyone cares about our motivation for the structure here they can dig out the email threads!
Agree. Thanks Jonathan!
Daniel.
Jonathan Cameron
maintainerRe: [PATCH 3/3] iio: Documentation: Add initial documentaton for IIO
In reply to Daniel BalutaQuoted 4 lines · Daniel Baluta
This file wants to be a starting point document for anyone wanting to use IIO configfs support or adding new IIO configfs functionality.
Signed-off-by Daniel Baluta <[email protected]>
Looks like a good flexible structure to me. Thanks!
Quoted 86 lines
--- Documentation/iio/iio_configfs.txt | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/iio/iio_configfs.txtDocumentation/iio/iio_configfs.txt new file +74
-0@@ -0,0 +1,74 @@ +Industrial IIO configfs support + +1. Overview + +Configfs is a filesystem-based manager of kernel objects. IIO uses some +objects that could be easily configured using configfs (e.g: devices, +triggers). + +See Documentation/filesystems/configfs/configfs.txt for more information about +how configfs works. + +2. Usage + +In order to use configfs support in IIO we need to select it at compile time +via CONFIG_IIO_CONFIGFS config option. + +Then, mount the configfs filesystem (usually under /config directory): + +$ mkdir /config +$ mount -t configfs none /config + +At this point, all default IIO groups will be creatd and can be accessed under +/config/iio. Next chapters will describe available IIO configurable objects. + +2.1. Software triggers creation and destruction + +One of the IIO default configfs groups is the "triggers" groups. It is +automagically accessible when the configfs is mounted and can be found under +/config/iio/triggers. + +2.1.1. Trigger creation + +As simply as: + +$ mkdir /config/triggers/my_trigger + +This will create a directory associated with a trigger. To understand how this +works we first need to see "my_triggers"'s attributes: + +$ ls /config/triggers/my_trigger +activate sampling_frequency type + +Available types for triggers are: + * none, this is a default dummy trigger that does nothing. + * hrtimer, this is trigger based on high resolution timer. + +Order of operations in order to create a "hrtimer" trigger: + +$ echo hrtimer > /config/triggers/my_trigger/type +$ echo 1 > /config/triggers/my_trigger/activate +$ echo 100 > /config/triggers/my_trigger/sampling_frequency + +At this point the trigger can be used by an IIO device. + +2.1.2 Trigger destruction + +$ echo 1 > /config/triggers/my_trigger/activate + +3. Misc + +In order to add a new trigger type, one need to implement a driver that creates +an instance of struct iio_configfs_ops (see iio_configfs_trigger.h header file +in include/linux/iio) and then support it in iio_trigger_set_configfs_ops +function from industrialiio-configfs.c file. + +These are the existing drivers implementing new trigger types: + * hrtimer => iio/trigger/iio-trig-hrtimer.c + +4. Further work + +* IIO dummy device creation +* Mappings to 'soft' in kernel users such as iio_input and iio_hwmon +* IIO on IIO drivers +