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
--
1.9.1
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.
Signed-off-by: Daniel Baluta <[email protected]>
---
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
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 4011eff..41d5863 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -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
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 698afc2..90cc407 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -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
diff --git a/drivers/iio/industrialio-configfs.c b/drivers/iio/industrialio-configfs.c
new file mode 100644
index 0000000..d8ffd76
--- /dev/null
+++ b/drivers/iio/industrialio-configfs.c
@@ -0,0 +1,127 @@
+/*
+ * 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/init.h>
+#include <linux/kmod.h>
+#include <linux/slab.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/iio_configfs_trigger.h>
+
+static struct iio_configfs_trigger_type *trigger_types[IIO_TRIGGER_TYPE_MAX];
+static DEFINE_RWLOCK(trigger_types_lock);
+
+int register_configfs_trigger(struct iio_configfs_trigger_type *t)
+{
+ int index = t->type;
+ int ret = 0;
+
+ if (index < 0 || index >= IIO_TRIGGER_TYPE_MAX)
+ return -EINVAL;
+
+ write_lock(&trigger_types_lock);
+ if (trigger_types[index])
+ ret = -EBUSY;
+ else
+ trigger_types[index] = t;
+ write_unlock(&trigger_types_lock);
+
+ return ret;
+}
+EXPORT_SYMBOL(register_configfs_trigger);
+
+int unregister_configfs_trigger(struct iio_configfs_trigger_type *t)
+{
+ int index = t->type;
+
+ if (index < 0 || index >= IIO_TRIGGER_TYPE_MAX)
+ return -EINVAL;
+
+ write_lock(&trigger_types_lock);
+ trigger_types[index] = NULL;
+ write_unlock(&trigger_types_lock);
+
+ return 0;
+}
+EXPORT_SYMBOL(unregister_configfs_trigger);
+
+static
+struct iio_configfs_trigger_type *iio_get_configfs_trigger_type(int type)
+{
+ struct iio_configfs_trigger_type *t;
+
+ if (type < 0 || type >= IIO_TRIGGER_TYPE_MAX)
+ return ERR_PTR(-EINVAL);
+
+ read_lock(&trigger_types_lock);
+ t = trigger_types[type];
+ if (t && !try_module_get(t->owner))
+ t = NULL;
+ read_unlock(&trigger_types_lock);
+
+ return t;
+}
+
+static struct config_group *iio_triggers_default_groups[] = {
+ NULL
+};
+
+static struct config_item_type iio_triggers_group_type = {
+ .ct_owner = THIS_MODULE,
+};
+
+static struct config_group iio_triggers_group = {
+ .cg_item = {
+ .ci_namebuf = "triggers",
+ .ci_type = &iio_triggers_group_type,
+ },
+ .default_groups = iio_triggers_default_groups,
+};
+
+static struct config_group *iio_root_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_root_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");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/iio_configfs_trigger.h b/include/linux/iio/iio_configfs_trigger.h
new file mode 100644
index 0000000..75e76f2
--- /dev/null
+++ b/include/linux/iio/iio_configfs_trigger.h
@@ -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 */
--
1.9.1
This 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.
Signed-off-by: Marten Svanfeldt <[email protected]>
Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Daniel Baluta <[email protected]>
---
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
diff --git a/drivers/iio/industrialio-configfs.c b/drivers/iio/industrialio-configfs.c
index d8ffd76..a0e5d24 100644
--- a/drivers/iio/industrialio-configfs.c
+++ b/drivers/iio/industrialio-configfs.c
@@ -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);
diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig
index 7999612..e21688e 100644
--- a/drivers/iio/trigger/Kconfig
+++ b/drivers/iio/trigger/Kconfig
@@ -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
diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile
index 0694dae..fe06eb5 100644
--- a/drivers/iio/trigger/Makefile
+++ b/drivers/iio/trigger/Makefile
@@ -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
diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
new file mode 100644
index 0000000..0acde8d
--- /dev/null
+++ b/drivers/iio/trigger/iio-trig-hrtimer.c
@@ -0,0 +1,154 @@
+/**
+ * The industrial I/O periodic hrtimer trigger driver
+ *
+ * Copyright (C) Intuitive Aerial AB
+ * Written by Marten Svanfeldt, [email protected]
+ * Copyright (C) 2012, Analog Device Inc.
+ * Author: Lars-Peter Clausen <[email protected]>
+ *
+ * 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/kernel.h>
+#include <linux/slab.h>
+#include <linux/hrtimer.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/iio_configfs_trigger.h>
+
+/* default delay in ns (100Hz) */
+#define HRTIMER_TRIGGER_DEFAULT_DELAY 100000000
+
+struct iio_hrtimer_trig_info {
+ struct iio_configfs_trigger_info *trigger_info;
+ struct hrtimer timer;
+ unsigned long delay;
+};
+
+static enum hrtimer_restart iio_trig_hrtimer_trig(struct hrtimer *timer)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+
+ trig_info = container_of(timer, struct iio_hrtimer_trig_info, timer);
+
+ hrtimer_forward_now(timer, ns_to_ktime(trig_info->delay));
+ iio_trigger_poll(trig_info->trigger_info->trigger);
+
+ return HRTIMER_RESTART;
+}
+
+static int iio_trig_hrtimer_set_state(struct iio_trigger *trig, bool state)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+
+ trig_info = iio_trigger_get_drvdata(trig);
+
+ if (state)
+ hrtimer_start(&trig_info->timer, ns_to_ktime(trig_info->delay),
+ HRTIMER_MODE_REL);
+ else
+ hrtimer_cancel(&trig_info->timer);
+
+ return 0;
+}
+
+int iio_trig_hrtimer_get_delay(struct iio_configfs_trigger_info *t,
+ unsigned long *delay)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+
+ trig_info = iio_trigger_get_drvdata(t->trigger);
+ *delay = trig_info->delay;
+
+ return 0;
+}
+
+int iio_trig_hrtimer_set_delay(struct iio_configfs_trigger_info *t,
+ unsigned long delay)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+
+ trig_info = iio_trigger_get_drvdata(t->trigger);
+
+ if (!delay)
+ return -EINVAL;
+
+ trig_info->delay = delay;
+
+ return 0;
+}
+
+static const struct iio_trigger_ops iio_hrtimer_trigger_ops = {
+ .owner = THIS_MODULE,
+ .set_trigger_state = iio_trig_hrtimer_set_state,
+};
+
+static int iio_trig_hrtimer_probe(struct iio_configfs_trigger_info *t)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+ int ret;
+
+ trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
+ if (!trig_info)
+ return -ENOMEM;
+
+ trig_info->trigger_info = t;
+
+ t->trigger = iio_trigger_alloc("%s", t->name);
+ if (!t->trigger)
+ return -ENOMEM;
+
+ iio_trigger_set_drvdata(t->trigger, trig_info);
+ t->trigger->ops = &iio_hrtimer_trigger_ops;
+
+ hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ trig_info->timer.function = iio_trig_hrtimer_trig;
+
+ trig_info->delay = HRTIMER_TRIGGER_DEFAULT_DELAY;
+
+ ret = iio_trigger_register(t->trigger);
+ if (ret)
+ goto err_free_trigger;
+
+ return 0;
+err_free_trigger:
+ iio_trigger_free(t->trigger);
+
+ return ret;
+}
+
+static int iio_trig_hrtimer_remove(struct iio_configfs_trigger_info *t)
+{
+ struct iio_hrtimer_trig_info *trig_info;
+
+ trig_info = iio_trigger_get_drvdata(t->trigger);
+
+ iio_trigger_unregister(t->trigger);
+ hrtimer_cancel(&trig_info->timer);
+ iio_trigger_free(t->trigger);
+
+ return 0;
+}
+
+struct iio_configfs_trigger_ops hrtimer_trigger_ops = {
+ .get_delay = iio_trig_hrtimer_get_delay,
+ .set_delay = iio_trig_hrtimer_set_delay,
+ .probe = iio_trig_hrtimer_probe,
+ .remove = iio_trig_hrtimer_remove,
+};
+
+struct iio_configfs_trigger_type iio_configfs_hrtimer = {
+ .type = IIO_TRIGGER_TYPE_HRTIMER,
+ .owner = THIS_MODULE,
+ .trigger_ops = &hrtimer_trigger_ops,
+};
+
+module_iio_configfs_trigger_driver(iio_configfs_hrtimer);
+
+MODULE_AUTHOR("Marten Svanfeldt <[email protected]>");
+MODULE_AUTHOR("Daniel Baluta <[email protected]>");
+MODULE_DESCRIPTION("Periodic hrtimer trigger for the IIO subsystem");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/iio_configfs_trigger.h b/include/linux/iio/iio_configfs_trigger.h
index 75e76f2..6233733 100644
--- a/include/linux/iio/iio_configfs_trigger.h
+++ b/include/linux/iio/iio_configfs_trigger.h
@@ -10,6 +10,7 @@
unregister_configfs_trigger)
enum {
+ IIO_TRIGGER_TYPE_HRTIMER = 0,
IIO_TRIGGER_TYPE_MAX,
};
--
1.9.1
Signed-off-by: Daniel Baluta <[email protected]>
---
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
diff --git a/Documentation/iio/iio_configfs.txt b/Documentation/iio/iio_configfs.txt
new file mode 100644
index 0000000..a49d5a1
--- /dev/null
+++ b/Documentation/iio/iio_configfs.txt
@@ -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
+
--
1.9.1
A whitespace nit. The horror!
On Fri, 2015-04-03 at 18:58 +0300, Daniel Baluta wrote:
> --- /dev/null
> +++ b/Documentation/iio/iio_configfs.txt
> ** create new attributes and them to the IIO configfs core.
>+[...]
> +4. Further work
> +
> +* add "sysfs" trigger type
> +
"git am" whined: "new blank line at EOF".
Paul Bolle
On Fri, 2015-04-03 at 18:57 +0300, Daniel Baluta wrote:
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> +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.
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -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
On Sat, Apr 4, 2015 at 9:26 PM, Paul Bolle <[email protected]> wrote:
> On Fri, 2015-04-03 at 18:57 +0300, Daniel Baluta wrote:
>> --- a/drivers/iio/Kconfig
>> +++ b/drivers/iio/Kconfig
>> +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.
>
>> --- a/drivers/iio/Makefile
>> +++ b/drivers/iio/Makefile
>> @@ -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?
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.