mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aurelio Colosimo <aurelio.colosimo@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Randy Dunlap <rdunlap@infradead.org>
Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org,
	Aurelio Colosimo <aurelio@aureliocolosimo.it>
Subject: [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs
Date: Tue,  5 Aug 2014 17:12:18 +0200	[thread overview]
Message-ID: <1407251538-17566-3-git-send-email-aurelio@aureliocolosimo.it> (raw)
In-Reply-To: <1407251538-17566-1-git-send-email-aurelio@aureliocolosimo.it>

max is the maximum number of nanoseconds accepted as duty or period by a
certain device. resolution is the minimum step actually handled by the
hardware output.

This couple of attributes permit users:
1) to know the capabilities of the pwm output;
2) to set a really supported value (by using of resolution, a precise
computation is possible);
3) to avoid them setting invalid (too big) periods.

A default value of resolution=1 and max=MAX_INT is provided in this
patch, but driver maintainers are encouraged to properly fill the new
fields in struct pwm_device.

Signed-off-by: Aurelio Colosimo <aurelio@aureliocolosimo.it>
---
 Documentation/pwm.txt |  7 +++++++
 drivers/pwm/core.c    |  2 ++
 drivers/pwm/sysfs.c   | 22 ++++++++++++++++++++++
 include/linux/pwm.h   |  2 ++
 4 files changed, 33 insertions(+)

diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt
index ca895fd..dbb1a16 100644
--- a/Documentation/pwm.txt
+++ b/Documentation/pwm.txt
@@ -74,6 +74,13 @@ period - The total period of the PWM signal (read/write).
 duty_cycle - The active time of the PWM signal (read/write).
 	Value is in nanoseconds and must be less than the period.
 
+resolution - The resolution of duty_cycle and period.
+	Value is in nanoseconds and is the min step period and duty can
+	change.
+
+max      - The max value for period.
+	Value is in nanoseconds.
+
 polarity - Changes the polarity of the PWM signal (read/write).
 	Writes to this property only work if the PWM chip supports changing
 	the polarity. The polarity can only be changed if the PWM is not
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 4b66bf0..d973ed7 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -259,6 +259,8 @@ int pwmchip_add(struct pwm_chip *chip)
 		pwm->chip = chip;
 		pwm->pwm = chip->base + i;
 		pwm->hwpwm = i;
+		pwm->resolution = 1;
+		pwm->max = UINT_MAX;
 
 		radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
 	}
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index c1d6064..1bb77e2 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -157,16 +157,38 @@ static ssize_t pwm_polarity_store(struct device *child,
 	return ret ? : size;
 }
 
+static ssize_t pwm_resolution_show(struct device *child,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	const struct pwm_device *pwm = child_to_pwm_device(child);
+
+	return sprintf(buf, "%u\n", pwm->resolution);
+}
+
+static ssize_t pwm_max_show(struct device *child,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	const struct pwm_device *pwm = child_to_pwm_device(child);
+
+	return sprintf(buf, "%u\n", pwm->max);
+}
+
 static DEVICE_ATTR(period, 0644, pwm_period_show, pwm_period_store);
 static DEVICE_ATTR(duty_cycle, 0644, pwm_duty_cycle_show, pwm_duty_cycle_store);
 static DEVICE_ATTR(enable, 0644, pwm_enable_show, pwm_enable_store);
 static DEVICE_ATTR(polarity, 0644, pwm_polarity_show, pwm_polarity_store);
+static DEVICE_ATTR(resolution, 0444, pwm_resolution_show, NULL);
+static DEVICE_ATTR(max, 0444, pwm_max_show, NULL);
 
 static struct attribute *pwm_attrs[] = {
 	&dev_attr_period.attr,
 	&dev_attr_duty_cycle.attr,
 	&dev_attr_enable.attr,
 	&dev_attr_polarity.attr,
+	&dev_attr_resolution.attr,
+	&dev_attr_max.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(pwm);
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 9bacf35..c4cc794 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -90,6 +90,8 @@ struct pwm_device {
 
 	unsigned int		period; 	/* in nanoseconds */
 	unsigned int		duty_cycle;	/* in nanoseconds */
+	unsigned int		resolution;	/* in nanoseconds */
+	unsigned int		max;		/* in nanoseconds */
 	enum pwm_polarity	polarity;
 };
 
-- 
1.9.1


      parent reply	other threads:[~2014-08-05 15:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 15:12 [PATCH 0/2] pwm: some improvements to sysfs interface Aurelio Colosimo
2014-08-05 15:12 ` [PATCH 1/2] pwm: new field name added to pwm_device Aurelio Colosimo
2014-08-05 15:12 ` Aurelio Colosimo [this message]

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=1407251538-17566-3-git-send-email-aurelio@aureliocolosimo.it \
    --to=aurelio.colosimo@gmail.com \
    --cc=aurelio@aureliocolosimo.it \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=thierry.reding@gmail.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®