From: Jonathan Cameron <jic23@cam.ac.uk>
To: michael.hennerich@analog.com
Cc: linux-iio@vger.kernel.org, drivers@analog.com,
device-drivers-devel@blackfin.uclinux.org
Subject: Re: [PATCH] IIO: TRIGGER: New sysfs based trigger
Date: Wed, 02 Feb 2011 18:22:44 +0000 [thread overview]
Message-ID: <4D49A0F4.5040408@cam.ac.uk> (raw)
In-Reply-To: <1296653448-10841-1-git-send-email-michael.hennerich@analog.com>
On 02/02/11 13:30, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> This patch adds a new trigger that can be invoked by writing
> the sysfs file: trigger_now. This approach can be valuable during
> automated testing or in situations, where other trigger methods
> are not applicable. For example no RTC or spare GPIOs.
> Last but not least we can allow user space applications to produce triggers.
Excellent. Very handy for testing as you say.
If we really want to commonly use this from userspace we will want a means
of registering more than one such trigger but this does fine for test
rigs. To do multiple triggers with this we could either just take a module
parameter or have a 'request_trigger' attribute under some parent device.
Still that's a question for another day. The current functionality is
enough to be getting on with.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> drivers/staging/iio/trigger/Kconfig | 6 ++
> drivers/staging/iio/trigger/Makefile | 1 +
> drivers/staging/iio/trigger/iio-trig-sysfs.c | 108 ++++++++++++++++++++++++++
> 3 files changed, 115 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/iio/trigger/iio-trig-sysfs.c
>
> diff --git a/drivers/staging/iio/trigger/Kconfig b/drivers/staging/iio/trigger/Kconfig
> index d842a58..c185e47 100644
> --- a/drivers/staging/iio/trigger/Kconfig
> +++ b/drivers/staging/iio/trigger/Kconfig
> @@ -18,4 +18,10 @@ config IIO_GPIO_TRIGGER
> help
> Provides support for using GPIO pins as IIO triggers.
>
> +config IIO_SYSFS_TRIGGER
> + tristate "SYSFS trigger"
> + depends on SYSFS
> + help
> + Provides support for using SYSFS entry as IIO triggers.
> +
> endif # IIO_TRIGGER
> diff --git a/drivers/staging/iio/trigger/Makefile b/drivers/staging/iio/trigger/Makefile
> index 10aeca5..504b9c0 100644
> --- a/drivers/staging/iio/trigger/Makefile
> +++ b/drivers/staging/iio/trigger/Makefile
> @@ -4,3 +4,4 @@
>
> obj-$(CONFIG_IIO_PERIODIC_RTC_TRIGGER) += iio-trig-periodic-rtc.o
> obj-$(CONFIG_IIO_GPIO_TRIGGER) += iio-trig-gpio.o
> +obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
> diff --git a/drivers/staging/iio/trigger/iio-trig-sysfs.c b/drivers/staging/iio/trigger/iio-trig-sysfs.c
> new file mode 100644
> index 0000000..3434f3c
> --- /dev/null
> +++ b/drivers/staging/iio/trigger/iio-trig-sysfs.c
> @@ -0,0 +1,108 @@
> +/*
> + * Copyright 2011 Analog Devices Inc.
> + *
> + * Licensed under the GPL-2 or later.
> + *
> + * iio-trig-sysfs.c
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +#include "../iio.h"
> +#include "../trigger.h"
> +
> +static ssize_t iio_sysfs_trigger_poll(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct iio_trigger *trig = dev_get_drvdata(dev);
> + iio_trigger_poll(trig, 0);
> +
> + return count;
> +}
> +
> +static DEVICE_ATTR(trigger_now, S_IWUSR, NULL, iio_sysfs_trigger_poll);
> +static IIO_TRIGGER_NAME_ATTR;
> +
> +static struct attribute *iio_sysfs_trigger_attrs[] = {
> + &dev_attr_trigger_now.attr,
> + &dev_attr_name.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group iio_sysfs_trigger_attr_group = {
> + .attrs = iio_sysfs_trigger_attrs,
> +};
> +
> +static int __devinit iio_sysfs_trigger_probe(struct platform_device *pdev)
> +{
> + struct iio_trigger *trig;
> + int ret;
> +
> + trig = iio_allocate_trigger();
> + if (!trig) {
> + ret = -ENOMEM;
> + goto out1;
> + }
> +
> + trig->control_attrs = &iio_sysfs_trigger_attr_group;
> + trig->owner = THIS_MODULE;
> + trig->name = kasprintf(GFP_KERNEL, "sysfstrig%d", pdev->id);
> + if (trig->name == NULL) {
> + ret = -ENOMEM;
> + goto out2;
> + }
> +
> + ret = iio_trigger_register(trig);
> + if (ret)
> + goto out3;
> +
> + platform_set_drvdata(pdev, trig);
> +
> + return 0;
> +out3:
> + kfree(trig->name);
> +out2:
> + iio_put_trigger(trig);
> +out1:
> +
> + return ret;
> +}
> +
> +static int __devexit iio_sysfs_trigger_remove(struct platform_device *pdev)
> +{
> + struct iio_trigger *trig = platform_get_drvdata(pdev);
> +
> + iio_trigger_unregister(trig);
> + kfree(trig->name);
> + iio_put_trigger(trig);
> +
> + return 0;
> +}
> +
> +static struct platform_driver iio_sysfs_trigger_driver = {
> + .driver = {
> + .name = "iio_sysfs_trigger",
> + .owner = THIS_MODULE,
> + },
> + .probe = iio_sysfs_trigger_probe,
> + .remove = __devexit_p(iio_sysfs_trigger_remove),
> +};
> +
> +static int __init iio_sysfs_trig_init(void)
> +{
> + return platform_driver_register(&iio_sysfs_trigger_driver);
> +}
> +module_init(iio_sysfs_trig_init);
> +
> +static void __exit iio_sysfs_trig_exit(void)
> +{
> + platform_driver_unregister(&iio_sysfs_trigger_driver);
> +}
> +module_exit(iio_sysfs_trig_exit);
> +
> +MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
> +MODULE_DESCRIPTION("Sysfs based trigger for the iio subsystem");
> +MODULE_LICENSE("GPL v2");
next prev parent reply other threads:[~2011-02-02 18:15 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-02 13:30 [PATCH] IIO: TRIGGER: New sysfs based trigger michael.hennerich
2011-02-02 18:22 ` Jonathan Cameron [this message]
2011-02-02 19:21 ` Hennerich, Michael
2011-02-03 10:13 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2011-02-02 19:21 michael.hennerich
2011-02-02 19:42 ` Greg KH
2011-02-02 19:55 ` Hennerich, Michael
2011-02-02 20:27 ` Greg KH
2011-02-02 20:36 ` Hennerich, Michael
2011-02-02 20:47 ` Mark Brown
2011-02-02 20:58 ` Greg KH
2011-02-03 9:58 ` Hennerich, Michael
2011-02-03 17:13 ` Greg KH
2011-02-04 8:38 ` Hennerich, Michael
2011-02-04 10:51 ` Jonathan Cameron
2011-02-04 14:55 ` Greg KH
2011-02-04 15:27 ` Jonathan Cameron
2011-02-04 15:34 ` Hennerich, Michael
2011-02-04 15:44 ` Jonathan Cameron
2011-02-02 19:43 ` Greg KH
2011-02-02 19:50 ` Mark Brown
2011-02-02 20:26 ` Greg KH
2011-02-02 20:31 ` Mark Brown
2011-02-02 20:48 ` Greg KH
2011-02-02 20:13 ` Hennerich, Michael
2011-02-02 20:29 ` Greg KH
2011-02-03 10:10 michael.hennerich
2011-02-07 10:05 michael.hennerich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D49A0F4.5040408@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=drivers@analog.com \
--cc=linux-iio@vger.kernel.org \
--cc=michael.hennerich@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.