From: Peter Meerwald <pmeerw@pmeerw.net>
To: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
cory.tusar@pid1solutions.com
Subject: Re: [PATCH v2 4/5] iio: trigger: Add periodic polling to SYSFS trigger
Date: Tue, 28 Jul 2015 08:34:08 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.02.1507280830550.4429@pmeerw.net> (raw)
In-Reply-To: <1438038434-13043-1-git-send-email-vladimir.barinov@cogentembedded.com>
On Tue, 28 Jul 2015, Vladimir Barinov wrote:
> Add periodic polling functionality to SYSFS trigger
typos below
> Signed-off-by: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
> ---
> Changes in version 2:
> - initially added
>
> .../ABI/testing/sysfs-bus-iio-trigger-sysfs | 11 ++++
> drivers/iio/trigger/iio-trig-sysfs.c | 58 ++++++++++++++++++++++
> 2 files changed, 69 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
> index 5235e6c..49caff2 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
> @@ -9,3 +9,14 @@ Description:
> automated testing or in situations, where other trigger methods
> are not applicable. For example no RTC or spare GPIOs.
> X is the IIO index of the trigger.
> +
> +What: /sys/bus/iio/devices/triggerX/trigger_poll
> +KernelVersion: 4.2.0
> +Contact: linux-iio@vger.kernel.org
> +Description:
> + This file is provided by the iio-trig-sysfs stand-alone trigger
> + driver. Writing this file with positive value (in milliseconds)
> + will start peroidic event triggereing of the driver, associated
periodic
triggering
> + with this trigger. Writing this file with 0 will stop perioding
> + triggering.
> + X is the IIO index of the trigger.
> diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c
> index 3dfab2b..ea79311 100644
> --- a/drivers/iio/trigger/iio-trig-sysfs.c
> +++ b/drivers/iio/trigger/iio-trig-sysfs.c
> @@ -18,6 +18,8 @@
> struct iio_sysfs_trig {
> struct iio_trigger *trig;
> struct irq_work work;
> + struct delayed_work poll_work;
> + unsigned int poll_interval; /* msec */
> int id;
> struct list_head l;
> };
> @@ -110,10 +112,63 @@ static ssize_t iio_sysfs_trigger_poll(struct device *dev,
> return count;
> }
>
> +static void iio_sysfs_trigger_queue_poll_work(struct iio_sysfs_trig *trig)
> +{
> + unsigned long delay;
> +
> + delay = msecs_to_jiffies(trig->poll_interval);
> + if (delay >= HZ)
> + delay = round_jiffies_relative(delay);
> +
> + queue_delayed_work(system_freezable_wq, &trig->poll_work, delay);
> +}
> +
> +static void iio_sysfs_trigger_poll_work(struct work_struct *work)
> +{
> + struct iio_sysfs_trig *trig = container_of(work, struct iio_sysfs_trig,
> + poll_work.work);
> +
> + irq_work_queue(&trig->work);
> + iio_sysfs_trigger_queue_poll_work(trig);
> +}
> +
> +static ssize_t iio_sysfs_trigger_get_poll(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct iio_trigger *trig = to_iio_trigger(dev);
> + struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig);
> +
> + return sprintf(buf, "%d\n", sysfs_trig->poll_interval);
> +}
> +
> +static ssize_t iio_sysfs_trigger_set_poll(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct iio_trigger *trig = to_iio_trigger(dev);
> + struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig);
> + unsigned int interval;
> + int err;
> +
> + err = kstrtouint(buf, 0, &interval);
> + if (err)
> + return err;
> +
> + sysfs_trig->poll_interval = interval;
> +
> + cancel_delayed_work_sync(&sysfs_trig->poll_work);
> + if (sysfs_trig->poll_interval > 0)
> + iio_sysfs_trigger_queue_poll_work(sysfs_trig);
> +
> + return count;
> +}
> +
> static DEVICE_ATTR(trigger_now, S_IWUSR, NULL, iio_sysfs_trigger_poll);
> +static DEVICE_ATTR(trigger_poll, S_IRUGO | S_IWUSR, iio_sysfs_trigger_get_poll,
> + iio_sysfs_trigger_set_poll);
>
> static struct attribute *iio_sysfs_trigger_attrs[] = {
> &dev_attr_trigger_now.attr,
> + &dev_attr_trigger_poll.attr,
> NULL,
> };
>
> @@ -164,6 +219,7 @@ static int iio_sysfs_trigger_probe(int id)
> iio_trigger_set_drvdata(t->trig, t);
>
> init_irq_work(&t->work, iio_sysfs_trigger_work);
> + INIT_DELAYED_WORK(&t->poll_work, iio_sysfs_trigger_poll_work);
>
> ret = iio_trigger_register(t->trig);
> if (ret)
> @@ -198,6 +254,8 @@ static int iio_sysfs_trigger_remove(int id)
> return -EINVAL;
> }
>
> + cancel_delayed_work_sync(&t->poll_work);
> +
> iio_trigger_unregister(t->trig);
> iio_trigger_free(t->trig);
>
>
--
Peter Meerwald
+43-664-2444418 (mobile)
next prev parent reply other threads:[~2015-07-28 6:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-27 23:05 [PATCH v2 0/5] iio: adc: hi8435: Add Holt HI-8435 threshold detector Vladimir Barinov
2015-07-27 23:06 ` [PATCH v2 1/5] iio: adc: hi8435: " Vladimir Barinov
2015-07-28 6:30 ` Peter Meerwald
2015-07-27 23:06 ` [PATCH v2 2/5] dt: Add vendor prefix 'holt' Vladimir Barinov
2015-07-27 23:07 ` [PATCH v2 3/5] dt: Document Holt HI-8435 bindings Vladimir Barinov
2015-07-27 23:07 ` [PATCH v2 4/5] iio: trigger: Add periodic polling to SYSFS trigger Vladimir Barinov
2015-07-28 6:34 ` Peter Meerwald [this message]
2015-07-27 23:07 ` [PATCH v2 5/5] iio: Support triggered events Vladimir Barinov
2015-07-28 6:37 ` Peter Meerwald
2015-07-29 7:56 ` Paul Bolle
2015-07-29 7:58 ` Christoph Hellwig
2015-07-29 8:03 ` Paul Bolle
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=alpine.DEB.2.02.1507280830550.4429@pmeerw.net \
--to=pmeerw@pmeerw.net \
--cc=cory.tusar@pid1solutions.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vladimir.barinov@cogentembedded.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®