All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: linux-iio@vger.kernel.org
Subject: [PATCH 1/2] IIO: Add frequency sysfs files to triggers
Date: Thu, 19 Apr 2012 18:05:37 +0200	[thread overview]
Message-ID: <1334851538-21408-2-git-send-email-maxime.ripard@free-electrons.com> (raw)
In-Reply-To: <1334851538-21408-1-git-send-email-maxime.ripard@free-electrons.com>

This allows to easily set the frequency for hardware triggers supporting
it.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 drivers/staging/iio/industrialio-trigger.c |   65 ++++++++++++++++++++++++++-
 drivers/staging/iio/trigger.h              |    9 ++++
 2 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/industrialio-trigger.c b/drivers/staging/iio/industrialio-trigger.c
index 47ecadd..457ab15 100644
--- a/drivers/staging/iio/industrialio-trigger.c
+++ b/drivers/staging/iio/industrialio-trigger.c
@@ -51,6 +51,42 @@ static ssize_t iio_trigger_read_name(struct device *dev,
 
 static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
 
+static ssize_t iio_trigger_read_frequency(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	struct iio_trigger *trig = dev_get_drvdata(dev);
+	return sprintf(buf, "%lu\n", trig->frequency);
+}
+
+static ssize_t iio_trigger_write_frequency(struct device *dev,
+					   struct device_attribute *attr,
+					   const char *buf,
+					   size_t len)
+{
+	struct iio_trigger *trig = dev_get_drvdata(dev);
+	unsigned long val;
+	int ret;
+
+	ret = kstrtoul(buf, 10, &val);
+	if (ret)
+		return ret;
+
+	trig->frequency = val;
+
+	if (trig->ops->update_infos) {
+		ret = trig->ops->update_infos(trig, IIO_TRIGGER_INFO_FREQUENCY);
+		if (ret)
+			return ret;
+	}
+
+	return len;
+}
+
+static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR,
+		   iio_trigger_read_frequency,
+		   iio_trigger_write_frequency);
+
 /**
  * iio_trigger_register_sysfs() - create a device for this trigger
  * @trig_info:	the trigger
@@ -59,9 +95,29 @@ static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
  **/
 static int iio_trigger_register_sysfs(struct iio_trigger *trig_info)
 {
-	return sysfs_add_file_to_group(&trig_info->dev.kobj,
-				       &dev_attr_name.attr,
-				       NULL);
+	int ret;
+	ret = sysfs_add_file_to_group(&trig_info->dev.kobj,
+				      &dev_attr_name.attr,
+				      NULL);
+	if (ret)
+		goto name_error;
+
+	if (trig_info->info_mask & IIO_TRIGGER_INFO_FREQUENCY) {
+		ret = sysfs_add_file_to_group(&trig_info->dev.kobj,
+					      &dev_attr_frequency.attr,
+					      NULL);
+		if (ret)
+			goto frequency_error;
+	}
+
+	return 0;
+
+frequency_error:
+	sysfs_remove_file_from_group(&trig_info->dev.kobj,
+				     &dev_attr_name.attr,
+				     NULL);
+name_error:
+	return ret;
 }
 
 static void iio_trigger_unregister_sysfs(struct iio_trigger *trig_info)
@@ -69,6 +125,9 @@ static void iio_trigger_unregister_sysfs(struct iio_trigger *trig_info)
 	sysfs_remove_file_from_group(&trig_info->dev.kobj,
 					   &dev_attr_name.attr,
 					   NULL);
+	sysfs_remove_file_from_group(&trig_info->dev.kobj,
+					   &dev_attr_frequency.attr,
+					   NULL);
 }
 
 int iio_trigger_register(struct iio_trigger *trig_info)
diff --git a/drivers/staging/iio/trigger.h b/drivers/staging/iio/trigger.h
index 1cfca23..a258ef8 100644
--- a/drivers/staging/iio/trigger.h
+++ b/drivers/staging/iio/trigger.h
@@ -16,6 +16,8 @@ struct iio_subirq {
 	bool enabled;
 };
 
+#define IIO_TRIGGER_INFO_FREQUENCY	(1 << 0)
+
 /**
  * struct iio_trigger_ops - operations structure for an iio_trigger.
  * @owner:		used to monitor usage count of the trigger.
@@ -32,6 +34,8 @@ struct iio_trigger_ops {
 	struct module			*owner;
 	int (*set_trigger_state)(struct iio_trigger *trig, bool state);
 	int (*try_reenable)(struct iio_trigger *trig);
+	int (*update_infos)(struct iio_trigger *trig,
+			    const unsigned long info_mask);
 	int (*validate_device)(struct iio_trigger *trig,
 			       struct iio_dev *indio_dev);
 };
@@ -52,6 +56,9 @@ struct iio_trigger_ops {
  * @subirqs:		[INTERN] information about the 'child' irqs.
  * @pool:		[INTERN] bitmap of irqs currently in use.
  * @pool_lock:		[INTERN] protection of the irq pool.
+ * @frequency:		[DRIVER] frequency of the trigger in Hz.
+ * @info_mask:		[DRIVER] What informations are to be exported in the
+ *			sysfs directory: frequency, etc....
  **/
 struct iio_trigger {
 	const struct iio_trigger_ops	*ops;
@@ -70,6 +77,8 @@ struct iio_trigger {
 	struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
 	unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
 	struct mutex			pool_lock;
+	unsigned long			frequency;
+	long				info_mask;
 };
 
 
-- 
1.7.5.4


  reply	other threads:[~2012-04-19 16:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-19 16:05 [RFC] Add frequency support in trigger core Maxime Ripard
2012-04-19 16:05 ` Maxime Ripard [this message]
2012-04-24  8:19   ` [PATCH 1/2] IIO: Add frequency sysfs files to triggers Jonathan Cameron
2012-04-26 13:48     ` Maxime Ripard
2012-04-19 16:05 ` [PATCH 2/2] Move RTC trigger to in-core frequency support Maxime Ripard
2012-04-24  8:22   ` Jonathan Cameron
2012-04-24  8:36     ` Maxime Ripard
2012-04-24  9:10       ` Jonathan Cameron
2012-04-24  8:12 ` [RFC] Add frequency support in trigger core Jonathan Cameron

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=1334851538-21408-2-git-send-email-maxime.ripard@free-electrons.com \
    --to=maxime.ripard@free-electrons.com \
    --cc=linux-iio@vger.kernel.org \
    /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.