Add initial configfs support for IIO
Subsystems (2)
v2 cover Add initial configfs support for IIO
This patchset adds initial support for configfs in IIO.
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
Changes since v1 are listed in each individual patch.
Daniel Baluta (3):
iio: configfs: Add configfs support to IIO
iio: trigger: Add support for highres timer trigger type
iio: Documentation: Add documentation for IIO configfs
Documentation/iio/iio_configfs.txt | 82 +++++++++ drivers/iio/Kconfig | 8 + drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 291 +++++++++++++++++++++++++++++++ drivers/iio/trigger/Kconfig | 9 + drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 154 ++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 41 +++++ 8 files changed, 588 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 v2 1/3 iio: configfs: Add configfs support to IIO
This module is the core of IIO configfs. It creates the "iio" subsystem under configfs mount point root, with one default group for "triggers".
It offers basic interface for registering software trigger types. Next patches will add "hrtimer" and "sysfs" trigger types. To add a new trigger type we must create a new kernel module which implements iio_configfs_trigger.h interface.
See Documentation/iio/iio_configfs.txt for more details on how configfs support for IIO works.
---
Changes since v1:
* addressed feedback from v1:
* https://lkml.org/lkml/2015/3/25/647
* create a directory per trigger type
* removed activate and type attributes
drivers/iio/Kconfig | 8 ++ drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 127 +++++++++++++++++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 40 ++++++++++ 4 files changed, 176 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 triggers). 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 +127 -0
127 lines not on this page · raw message
include/linux/iio/iio_configfs_trigger.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef __IIO_CONFIGFS_TRIGGER +#define __IIO_CONFIGFS_TRIGGER + +#include <linux/device.h> +#include <linux/iio/iio.h> +#include <linux/module.h> + +#define module_iio_configfs_trigger_driver (__iio_configfs_trigger) \ + module_driver(__iio_configfs_trigger, register_configfs_trigger, \ + unregister_configfs_trigger) + +enum { +IIO_TRIGGER_TYPE_MAX , +}; + +struct iio_configfs_trigger_ops ; + +struct iio_configfs_trigger_type { +int type; +struct module *owner; +struct iio_configfs_trigger_ops *trigger_ops; +}; + +struct iio_configfs_trigger_info { +char *name; +struct iio_trigger *trigger; +struct iio_configfs_trigger_type *trigger_type; +}; + +struct iio_configfs_trigger_ops { +int (*get_delay)(struct iio_configfs_trigger_info *,unsigned long *); +int (*set_delay)(struct iio_configfs_trigger_info *,unsigned long ); +int (*probe)(struct iio_configfs_trigger_info *); +int (*remove)(struct iio_configfs_trigger_info *); +}; + +int register_configfs_trigger (struct iio_configfs_trigger_type *); +int unregister_configfs_trigger (struct iio_configfs_trigger_type *); + +#endif /* __IIO_CONFIGFS_TRIGGER */
Signature · 1 line
1.9.1
Re: [PATCH v2 1/3] iio: configfs: Add configfs support to IIO
Quoted 13 lines · Daniel Baluta
drivers/iio/Kconfig +7
-0+config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g. software triggers). For more info see + Documentation/iio/iio_configfs.txt.
drivers/iio/Makefile line 10
Quoted 6 lines
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
It seems I didn't pay attention to this Makefile the first time I looked at this series. And actually reading it I noticed that industrialio-configfs.o can only be part of the industrial.ko module, can't it? So this Makefile doesn't allow to build a separate industrialio-configfs.ko module, right? If so, my previous review, in which I claimed to spot a nit, was a waste of our time.
Because I now experienced that if this gets build with CONFIG_IIO=m and CONFIG_IIO_CONFIGFS=y one gets:
$ make -C ../.. CONFIG_IIO_CONFIGFS=y M=$PWD industrialio.ko
make: Entering directory `[...]'
CC [M] [...]/drivers/iio/industrialio-core.o
CC [M] [...]/linux/drivers/iio/industrialio-event.o
CC [M] [...]drivers/iio/inkern.o
CC [M] [...]/drivers/iio/industrialio-buffer.o
CC [M] [...]/drivers/iio/industrialio-configfs.o
CC [M] [...]/drivers/iio/industrialio-trigger.o
CC [M] [...]/drivers/iio/buffer_cb.o
LD [M] [...]/drivers/iio/industrialio.o
[...]/drivers/iio/industrialio-configfs.o: In function `iio_configfs_init':
industrialio-configfs.c:(.init.text+0x0): multiple definition of `init_module'
[...]/drivers/iio/industrialio-core.o:industrialio-core.c:(.init.text+0x0): first defined here
[...]/drivers/iio/industrialio-configfs.o: In function `iio_configfs_exit':
industrialio-configfs.c:(.exit.text+0x0): multiple definition of `cleanup_module'
[...]/drivers/iio/industrialio-core.o:industrialio-core.c:(.exit.text+0x0): first defined here
make[1]: *** [[...]/drivers/iio/industrialio.o] Error 1
make: *** [industrialio.ko] Error 2
make: Leaving directory `[...]'(I didn't yet test other configurations.)
So before I waste even more of your time: were you trying to make configfs support a part of the industrialio module or were you trying to make configfs support available as a separate module?
Thanks,
Paul Bolle
Re: [PATCH v2 1/3] iio: configfs: Add configfs support to IIO
Quoted 50 lines · Paul Bolle
Quoted 13 lines · Daniel Baluta
drivers/iio/Kconfig +7
-0+config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g. software triggers). For more info see + Documentation/iio/iio_configfs.txt.drivers/iio/Makefile line 10
Quoted 6 lines
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.oIt seems I didn't pay attention to this
Makefilethe first time I looked at this series. And actually reading it I noticed that industrialio-configfs.o can only be part of the industrial.ko module, can't it? So thisMakefiledoesn't allow to build a separate industrialio-configfs.ko module, right? If so, my previous review, in which I claimed to spot a nit, was a waste of our time.Because I now experienced that if this gets build with
CONFIG_IIO=mandCONFIG_IIO_CONFIGFS=yone gets:$ make -C ../.. CONFIG_IIO_CONFIGFS=y M=$PWD industrialio.ko make: Entering directory `[...]' CC [M] [...]/drivers/iio/industrialio-core.o CC [M] [...]/linux/drivers/iio/industrialio-event.o CC [M] [...]drivers/iio/inkern.o CC [M] [...]/drivers/iio/industrialio-buffer.o CC [M] [...]/drivers/iio/industrialio-configfs.o CC [M] [...]/drivers/iio/industrialio-trigger.o CC [M] [...]/drivers/iio/buffer_cb.o LD [M] [...]/drivers/iio/industrialio.o [...]/drivers/iio/industrialio-configfs.o: In function `iio_configfs_init': industrialio-configfs.c:(.init.text+0x0): multiple definition of `init_module' [...]/drivers/iio/industrialio-core.o:industrialio-core.c:(.init.text+0x0): first defined here [...]/drivers/iio/industrialio-configfs.o: In function `iio_configfs_exit': industrialio-configfs.c:(.exit.text+0x0): multiple definition of `cleanup_module' [...]/drivers/iio/industrialio-core.o:industrialio-core.c:(.exit.text+0x0): first defined here make[1]: *** [[...]/drivers/iio/industrialio.o] Error 1 make: *** [industrialio.ko] Error 2 make: Leaving directory `[...]'
Quoted 5 lines
(I didn't yet test other configurations.)
So before I waste even more of your time: were you trying to make configfs support a part of the industrialio module or were you trying to make configfs support available as a separate module?
Hi Paul,
Thanks a lot for review. I seee the problem now :).
I want to build a separate industrialio-configs.ko module, I will fix this and resend asap.
thanks,
Daniel.
PATCH v2 2/3 iio: trigger: Add support for highres timer trigger type
In reply to Daniel BalutaThis patch adds a new trigger type - the high resoluton timer ("hrtimer") under /config/iio/triggers/ and also creates a module that implements hrtimer trigger type functionality.
A new IIO trigger is allocated when a new directory is created under /config/iio/triggers/. The name of the trigger is the same as the dir name. Each trigger will have a "delay" attribute representing the delay between two successive IIO trigger_poll calls.
---
Changes since v2:
* replaced sampling_frequency with delay to make the in kernel processing easier
* implemented hrtimer driver using the new API proposed in patch 1
drivers/iio/industrialio-configfs.c | 164 +++++++++++++++++++++++++++++++ drivers/iio/trigger/Kconfig | 9 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 154 +++++++++++++++++++++++++++++ include/linux/iio/iio_configfs_trigger.h | 1 + 5 files changed, 330 insertions(+) create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c
drivers/iio/industrialio-configfs.c +164 -0
@@ -71,7 +71,170 @@ struct iio_configfs_trigger_type *iio_get_configfs_trigger_type(int type)return t; } +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); +} + +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_get_delay (struct iio_trigger_item *item,char *page) +{ +unsigned long delay; +int ret; + +struct iio_configfs_trigger_type *t = item->trigger_info->trigger_type; + + ret = t->trigger_ops->get_delay (item->trigger_info, &delay); +if (ret <0 ) +return ret; + +return snprintf (page,PAGE_SIZE ,"%lu\n" , delay); +} + +static +ssize_t iio_trigger_item_set_delay (struct iio_trigger_item *item, +const char *page, +size_t count) +{ +int ret; +unsigned long delay; +struct iio_configfs_trigger_type *t = item->trigger_info->trigger_type; + + ret =kstrtoul (page,10 , &delay); +if (ret <0 ) +return ret; + + ret = t->trigger_ops->set_delay (item->trigger_info, delay); +if (ret <0 ) +return ret; + +return count; +} + +IIO_TRIGGER_ITEM_ATTR (delay,S_IRUGO |S_IWUSR , + iio_trigger_item_get_delay, + iio_trigger_item_set_delay); + +static struct configfs_attribute *iio_trigger_item_attrs[] = { + &iio_trigger_item_attr_delay.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_trigger_item_type; + +static struct config_item *iio_hrtimer_make_item (struct config_group *group, +const char *name) +{ +struct iio_trigger_item *trigger_item; +struct iio_configfs_trigger_info *trigger_info; +struct iio_configfs_trigger_type *trigger_type; +int ret; + + 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) { + ret = -ENOMEM ; + goto out_free_trigger_item; + } + + trigger_info->name =kstrdup (name,GFP_KERNEL ); +if (!trigger_info->name) { + ret = -ENOMEM ; + goto out_free_trigger_info; + } + + trigger_type =iio_get_configfs_trigger_type (IIO_TRIGGER_TYPE_HRTIMER ); +if (!trigger_type) { +pr_err ("Unable to get hrtimer trigger!\n" ); + ret = -ENODEV ; + goto out_free_trigger_name; + } + ret = trigger_type->trigger_ops->probe (trigger_info); +if (ret <0 ) + goto out_error_module_put; + + trigger_info->trigger_type = trigger_type; + trigger_item->trigger_info = trigger_info; + +config_item_init_type_name (&trigger_item->item, name, + &iio_trigger_item_type); + +return &trigger_item->item; +out_error_module_put: +module_put (trigger_type->owner); +out_free_trigger_name: +kfree (trigger_info->name); +out_free_trigger_info: +kfree (trigger_info); +out_free_trigger_item: +kfree (trigger_item); +return ERR_PTR (ret); +} + +static void iio_hrtimer_drop_item (struct config_group *group, +struct config_item *item) +{ +struct iio_trigger_item *trigger_item; +struct iio_configfs_trigger_type *trigger_type; + + trigger_item = container_of(item, struct iio_trigger_item, item); + trigger_type = trigger_item->trigger_info->trigger_type; + + trigger_type->trigger_ops->remove (trigger_item->trigger_info); +module_put (trigger_type->owner); +kfree (trigger_item->trigger_info->name); +kfree (trigger_item->trigger_info); +kfree (trigger_item); +} + +static struct configfs_group_operations iio_triggers_hrtimer_group_ops = { + .make_item = iio_hrtimer_make_item, + .drop_item = iio_hrtimer_drop_item, +}; + +static struct config_item_type iio_trigger_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_hrtimer_type = { + .ct_owner =THIS_MODULE , + .ct_group_ops = &iio_triggers_hrtimer_group_ops, +}; + +static struct config_group iio_triggers_hrtimer_group = { + .cg_item = { + .ci_namebuf ="hrtimer" , + .ci_type = &iio_triggers_hrtimer_type, + }, +}; +static struct config_group *iio_triggers_default_groups[] = { + &iio_triggers_hrtimer_group,NULL };
@@ -109,6 +272,7 @@ static struct configfs_subsystem iio_configfs_subsys = {static int __init iio_configfs_init (void ) { +config_group_init (&iio_triggers_hrtimer_group);config_group_init (&iio_triggers_group);config_group_init (&iio_configfs_subsys.su_group);
drivers/iio/trigger/Kconfig +9 -0
@@ -5,6 +5,15 @@ menu "Triggers - standalone" +config IIO_HRTIMER_TRIGGER + tristate "High resolution timer trigger" + depends on IIO_CONFIGFS + 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_HRTIMER_TRIGGER) += 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 +154 -0
154 lines not on this page · raw message
include/linux/iio/iio_configfs_trigger.h +1 -0
@@ -10,6 +10,7 @@ unregister_configfs_trigger)enum { +IIO_TRIGGER_TYPE_HRTIMER =0 ,IIO_TRIGGER_TYPE_MAX , };
Signature · 1 line
1.9.1
PATCH v2 3/3 iio: Documentation: Add documentation for IIO configfs
In reply to Daniel Baluta---
Changes since v1:
* addressed feedback for v1:
* https://lkml.org/lkml/2015/3/25/648
* adapted to match the changes in patches 1 and 2
* fixed some typos and clarified further work
Documentation/iio/iio_configfs.txt | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Documentation/iio/iio_configfs.txt
Documentation/iio/iio_configfs.txt new file +82 -0
@@ -0,0 +1,82 @@ +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 created and can be accessed +under /config/iio. Next chapters will describe available IIO configuration +objects. + +3. Software triggers + +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. + +Under /config/iio/triggers we will create trigger types. For the moment +we have "hrtimer" trigger time and we plan to add at least one more +"sysfs" trigger type. + +3.1 Trigger types + +Represent a specific type of trigger. For now we have an implementation +for "hrtimer" trigger type. + +3.2. Trigger creation and destruction + +As simply as: + +$ mkdir /config/triggers/hrtimer/my_trigger + +Creating my_trigger directory will result in creation of "my_trigger" +trigger of "hrtimer" type. Destruction happens when my_trigger directory +is removed. + +Each trigger can have one or more attributes specific to the trigger type. + +3.3 "hrtimer" trigger types attributes + +"hrtimer" trigger type has only one attribute: + +$ ls /config/triggers/hrtimer/my_trigger delay + +delay - represents the amount of time in nanoseconds between two +consecutive iio_trigger_poll calls. By default it is set to 100000000, +that is the equivalent of a 100Hz frequency. + +3.4. Adding a new trigger type + +In order to add a new trigger type, one needs to: + +* [iio_configfs_trigger.h] + ** add a new IIO_TRIGGER_TYPE +* [iio-trig-<type>.c] + ** declare and initialize a structure of type + iio_configfs_trigger_type + ** implement needed iio_configfs_trigger_ops + ** register/unregister the new trigger + type with the IIO configfs core +* [industrialiio-configfs.c] + ** create a new group type and add it in the default group of + trigger types. + ** create new attributes and them to the IIO configfs core. + +4. Further work + +* add "sysfs" trigger type +
Signature · 1 line
1.9.1
Re: [PATCH v2 3/3] iio: Documentation: Add documentation for IIO configfs
A whitespace nit. The horror!
Documentation/iio/iio_configfs.txt line 82
Quoted 9 lines · Daniel Baluta
Documentation/iio/iio_configfs.txt new file +0
-0** create new attributes and them to the IIO configfs core.
+[...]
+4. Further workDocumentation/iio/iio_configfs.txt new file +3
-0+ +* add "sysfs" trigger type +
"git am" whined: "new blank line at EOF".
Paul Bolle