Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1251582 > unrolled thread

[PATCH v8 3/5] iio: core: Introduce IIO software triggers

Started byDaniel Baluta <daniel.baluta@intel.com>
First post2015-10-20 13:00 +0200
Last post2015-10-20 14:20 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v8 3/5] iio: core: Introduce IIO software triggers Daniel Baluta <daniel.baluta@intel.com> - 2015-10-20 13:00 +0200
    [RFC PATCH] iio: core: iio_triggers_group_type can be static kbuild test robot <lkp@intel.com> - 2015-10-20 14:20 +0200
    Re: [PATCH v8 3/5] iio: core: Introduce IIO software triggers kbuild test robot <lkp@intel.com> - 2015-10-20 14:20 +0200

#1251582 — [PATCH v8 3/5] iio: core: Introduce IIO software triggers

FromDaniel Baluta <daniel.baluta@intel.com>
Date2015-10-20 13:00 +0200
Subject[PATCH v8 3/5] iio: core: Introduce IIO software triggers
Message-ID<qlCO6-1qN-9@gated-at.bofh.it>
A software trigger associates an IIO device trigger with a software
interrupt source (e.g: timer, sysfs). This patch adds the generic
infrastructure for handling software triggers.

Software interrupts sources are kept in a iio_trigger_types_list and
registered separately when the associated kernel module is loaded.

Software triggers can be created directly from drivers or from user
space via configfs interface.

Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
 drivers/iio/Kconfig                   |   7 ++
 drivers/iio/Makefile                  |   1 +
 drivers/iio/industrialio-configfs.c   |  37 ++++++++-
 drivers/iio/industrialio-sw-trigger.c | 137 ++++++++++++++++++++++++++++++++++
 include/linux/iio/sw_trigger.h        | 120 +++++++++++++++++++++++++++++
 5 files changed, 301 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iio/industrialio-sw-trigger.c
 create mode 100644 include/linux/iio/sw_trigger.h

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 7a4815a..293593e 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -46,6 +46,13 @@ config IIO_CONSUMERS_PER_TRIGGER
 	This value controls the maximum number of consumers that a
 	given trigger may handle. Default is 2.
 
+config IIO_SW_TRIGGER
+	bool "Enable software triggers support"
+	help
+	 Provides IIO core support for software triggers. A software
+	 trigger can be created via configfs or directly by a driver
+	 using the API provided.
+
 config IIO_TRIGGERED_EVENT
 	tristate
 	select IIO_TRIGGER
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index e109f95..3524636 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -7,6 +7,7 @@ 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_SW_TRIGGER) += industrialio-sw-trigger.o
 
 obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o
 
diff --git a/drivers/iio/industrialio-configfs.c b/drivers/iio/industrialio-configfs.c
index 211b52e..9a9f8bc 100644
--- a/drivers/iio/industrialio-configfs.c
+++ b/drivers/iio/industrialio-configfs.c
@@ -15,8 +15,43 @@
 #include <linux/slab.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/sw_trigger.h>
 
-static struct config_item_type iio_triggers_group_type = {
+static struct config_group *trigger_make_group(struct config_group *group,
+					       const char *name)
+{
+	struct iio_sw_trigger *t;
+
+	t = iio_sw_trigger_create(group->cg_item.ci_name, name);
+	if (IS_ERR(t))
+		return ERR_CAST(t);
+
+	config_item_set_name(&t->group.cg_item, "%s", name);
+
+	return &t->group;
+}
+
+static void trigger_drop_group(struct config_group *group,
+			       struct config_item *item)
+{
+	struct iio_sw_trigger *t = to_iio_sw_trigger(item);
+
+	iio_sw_trigger_destroy(t);
+	config_item_put(item);
+}
+
+static struct configfs_group_operations trigger_ops = {
+	.make_group	= &trigger_make_group,
+	.drop_item	= &trigger_drop_group,
+};
+
+struct config_item_type iio_trigger_type_group_type = {
+	.ct_group_ops = &trigger_ops,
+	.ct_owner       = THIS_MODULE,
+};
+EXPORT_SYMBOL(iio_trigger_type_group_type);
+
+struct config_item_type iio_triggers_group_type = {
 	.ct_owner = THIS_MODULE,
 };
 
diff --git a/drivers/iio/industrialio-sw-trigger.c b/drivers/iio/industrialio-sw-trigger.c
new file mode 100644
index 0000000..bdff360
--- /dev/null
+++ b/drivers/iio/industrialio-sw-trigger.c
@@ -0,0 +1,137 @@
+/*
+ * The Industrial I/O core, software trigger functions
+ *
+ * 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/module.h>
+#include <linux/init.h>
+#include <linux/kmod.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#include <linux/iio/sw_trigger.h>
+
+static LIST_HEAD(iio_trigger_types_list);
+static DEFINE_MUTEX(iio_trigger_types_lock);
+
+static
+struct iio_sw_trigger_type *__iio_find_sw_trigger_type(const char *name,
+						       unsigned len)
+{
+	struct iio_sw_trigger_type *t = NULL, *iter;
+
+	list_for_each_entry(iter, &iio_trigger_types_list, list)
+		if (!strcmp(iter->name, name)) {
+			t = iter;
+			break;
+		}
+
+	return t;
+}
+
+int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t)
+{
+	struct iio_sw_trigger_type *iter;
+	int ret = 0;
+
+	mutex_lock(&iio_trigger_types_lock);
+	iter = __iio_find_sw_trigger_type(t->name, strlen(t->name));
+	if (iter)
+		ret = -EBUSY;
+	else
+		list_add_tail(&t->list, &iio_trigger_types_list);
+	mutex_unlock(&iio_trigger_types_lock);
+
+	if (!ret)
+		iio_sw_trigger_type_configfs_register(t);
+
+	return ret;
+}
+EXPORT_SYMBOL(iio_register_sw_trigger_type);
+
+void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t)
+{
+	struct iio_sw_trigger_type *iter;
+
+	mutex_lock(&iio_trigger_types_lock);
+	iter = __iio_find_sw_trigger_type(t->name, strlen(t->name));
+	if (iter)
+		list_del(&t->list);
+	mutex_unlock(&iio_trigger_types_lock);
+
+	iio_sw_trigger_type_configfs_unregister(t);
+}
+EXPORT_SYMBOL(iio_unregister_sw_trigger_type);
+
+static
+struct iio_sw_trigger_type *iio_get_sw_trigger_type(const char *name)
+{
+	struct iio_sw_trigger_type *t;
+
+	mutex_lock(&iio_trigger_types_lock);
+	t = __iio_find_sw_trigger_type(name, strlen(name));
+	if (t && !try_module_get(t->owner))
+		t = NULL;
+	mutex_unlock(&iio_trigger_types_lock);
+
+	return t;
+}
+
+struct iio_sw_trigger *iio_sw_trigger_create(const char *type, const char *name)
+{
+	struct iio_sw_trigger *t;
+	struct iio_sw_trigger_type *tt;
+
+	tt = iio_get_sw_trigger_type(type);
+	if (!tt) {
+		pr_err("Invalid trigger type: %s\n", type);
+		return ERR_PTR(-EINVAL);
+	}
+	t = tt->ops->probe(name);
+	if (IS_ERR(t))
+		goto out_module_put;
+
+	t->trigger_type = tt;
+
+	return t;
+out_module_put:
+	module_put(tt->owner);
+	return t;
+}
+EXPORT_SYMBOL(iio_sw_trigger_create);
+
+void iio_sw_trigger_destroy(struct iio_sw_trigger *t)
+{
+	struct iio_sw_trigger_type *tt = t->trigger_type;
+
+	tt->ops->remove(t);
+	module_put(tt->owner);
+}
+EXPORT_SYMBOL(iio_sw_trigger_destroy);
+
+int iio_sw_trigger_type_configfs_register(struct iio_sw_trigger_type *tt)
+{
+#ifdef CONFIG_IIO_CONFIGFS
+	config_group_init_type_name(&tt->group, tt->name,
+				    &iio_trigger_type_group_type);
+
+	return configfs_register_group(&iio_triggers_group, &tt->group);
+#else
+	return 0;
+#endif
+}
+EXPORT_SYMBOL_GPL(iio_sw_trigger_type_configfs_register);
+
+void iio_sw_trigger_type_configfs_unregister(struct iio_sw_trigger_type *tt)
+{
+#ifdef CONFIG_IIO_CONFIGFS
+	configfs_unregister_group(&tt->group);
+#endif
+}
+EXPORT_SYMBOL_GPL(iio_sw_trigger_type_configfs_unregister);
+
diff --git a/include/linux/iio/sw_trigger.h b/include/linux/iio/sw_trigger.h
new file mode 100644
index 0000000..51331b2
--- /dev/null
+++ b/include/linux/iio/sw_trigger.h
@@ -0,0 +1,120 @@
+/*
+ * Industrial I/O software trigger interface
+ *
+ * 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.
+ */
+
+#ifndef __IIO_SW_TRIGGER
+#define __IIO_SW_TRIGGER
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/iio/iio.h>
+#include <linux/configfs.h>
+
+#define module_iio_sw_trigger_driver(__iio_sw_trigger_type) \
+	module_driver(__iio_sw_trigger_type, iio_register_sw_trigger_type, \
+		      iio_unregister_sw_trigger_type)
+
+struct iio_sw_trigger_ops;
+extern struct config_group iio_triggers_group;
+extern struct config_item_type iio_trigger_type_group_type;
+
+struct iio_sw_trigger_type {
+	const char *name;
+	struct module *owner;
+	const struct iio_sw_trigger_ops *ops;
+	struct list_head list;
+	struct config_group group;
+};
+
+struct iio_sw_trigger {
+	struct iio_trigger *trigger;
+	struct iio_sw_trigger_type *trigger_type;
+	struct config_group group;
+};
+
+struct iio_sw_trigger_ops {
+	struct iio_sw_trigger* (*probe)(const char *);
+	int (*remove)(struct iio_sw_trigger *);
+};
+
+static inline
+struct iio_sw_trigger *to_iio_sw_trigger(struct config_item *item)
+{
+	return container_of(to_config_group(item), struct iio_sw_trigger,
+			    group);
+}
+
+#ifdef CONFIG_IIO_SW_TRIGGER
+/**
+ * iio_register_sw_trigger_type() - register a software trigger type
+ *
+ * @tt: software trigger type to be registered
+ */
+int iio_register_sw_trigger_type(struct iio_sw_trigger_type *tt);
+
+/**
+ * iio_unregister_sw_trigger_type() - unregister a software trigger type
+ *
+ * @tt: software trigger type to be unregistered
+ */
+void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *tt);
+
+struct iio_sw_trigger *iio_sw_trigger_create(const char *, const char *);
+void iio_sw_trigger_destroy(struct iio_sw_trigger *);
+
+int iio_sw_trigger_type_configfs_register(struct iio_sw_trigger_type *tt);
+void iio_sw_trigger_type_configfs_unregister(struct iio_sw_trigger_type *tt);
+
+static inline
+void iio_swt_group_init_type_name(struct iio_sw_trigger *t,
+				  const char *name,
+				  struct config_item_type *type)
+{
+#ifdef CONFIG_CONFIGFS_FS
+	config_group_init_type_name(&t->group, name, type);
+#endif
+}
+
+#else
+static inline
+int iio_register_sw_trigger_type(struct iio_sw_trigger_type *tt)
+{
+	return 0;
+}
+
+static inline
+void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *tt)
+{ }
+
+static inline
+struct iio_sw_trigger *iio_sw_trigger_create(const char *type, const char *name)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+void iio_sw_trigger_destroy(struct iio_sw_trigger *tt)
+{ }
+
+static inline
+int iio_sw_trigger_type_configfs_register(struct iio_sw_trigger_type *tt)
+{
+	return 0;
+}
+
+static inline
+void iio_sw_trigger_type_configfs_unregister(struct iio_sw_trigger_type *tt)
+{ }
+
+static inline
+void iio_swt_group_init_type_name(struct iio_sw_trigger *t,
+				  const char *name,
+				  struct config_item_type *type)
+{ }
+#endif
+#endif /* __IIO_SW_TRIGGER */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1251628 — [RFC PATCH] iio: core: iio_triggers_group_type can be static

Fromkbuild test robot <lkp@intel.com>
Date2015-10-20 14:20 +0200
Subject[RFC PATCH] iio: core: iio_triggers_group_type can be static
Message-ID<qlE3w-3rm-25@gated-at.bofh.it>
In reply to#1251582
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---
 industrialio-configfs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-configfs.c b/drivers/iio/industrialio-configfs.c
index 9a9f8bc..cbce23b 100644
--- a/drivers/iio/industrialio-configfs.c
+++ b/drivers/iio/industrialio-configfs.c
@@ -51,7 +51,7 @@ struct config_item_type iio_trigger_type_group_type = {
 };
 EXPORT_SYMBOL(iio_trigger_type_group_type);
 
-struct config_item_type iio_triggers_group_type = {
+static struct config_item_type iio_triggers_group_type = {
 	.ct_owner = THIS_MODULE,
 };
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1251630

Fromkbuild test robot <lkp@intel.com>
Date2015-10-20 14:20 +0200
Message-ID<qlE3w-3rm-27@gated-at.bofh.it>
In reply to#1251582
Hi Daniel,

[auto build test WARNING on next-20151020 -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Daniel-Baluta/configfs-Allow-dynamic-group-creation/20151020-185453
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/iio/industrialio-configfs.c:54:25: sparse: symbol 'iio_triggers_group_type' was not declared. Should it be static?

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web