mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] pwm: some improvements to sysfs interface
@ 2014-08-05 15:12 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 ` [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs Aurelio Colosimo
  0 siblings, 2 replies; 3+ messages in thread
From: Aurelio Colosimo @ 2014-08-05 15:12 UTC (permalink / raw)
  To: Thierry Reding, Randy Dunlap
  Cc: linux-pwm, linux-kernel, linux-doc, Aurelio Colosimo

This set of patches adds two more features in pwm sysfs, which I
developed for the driver of my pwm device (a virtualization of
AVR pwm outputs, not submitted to mainline yet):
    
- an optional static name for each pwm device, so that driver develop
  can give a name to the output itself, in a similar way as gpio system
  does;
    
- the attribute 'max', and the attribute 'resolution', in
  nanoseconds, specific for each pwm device.
    
  Each new field is initialized with a default (meaningful) value;
  anyway, if desired, pwm drivers maintainers should fix their
  drivers in order to use the new fields.
    
Aurelio Colosimo (2):
  pwm: new field name added to pwm_device
  pwm: new fields, max and resolution, added to sysfs

 drivers/pwm/core.c  |  2 ++
 drivers/pwm/sysfs.c | 29 ++++++++++++++++++++++++++++-
 include/linux/pwm.h |  3 +++
 3 files changed, 33 insertions(+), 1 deletion(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] pwm: new field name added to pwm_device
  2014-08-05 15:12 [PATCH 0/2] pwm: some improvements to sysfs interface Aurelio Colosimo
@ 2014-08-05 15:12 ` Aurelio Colosimo
  2014-08-05 15:12 ` [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs Aurelio Colosimo
  1 sibling, 0 replies; 3+ messages in thread
From: Aurelio Colosimo @ 2014-08-05 15:12 UTC (permalink / raw)
  To: Thierry Reding, Randy Dunlap
  Cc: linux-pwm, linux-kernel, linux-doc, Aurelio Colosimo

Since label is used dinamically, I added one more optional field,
which statically defines the name of a pwm output, in a similar way
as gpio framework does.

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

diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 4bd0c63..c1d6064 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -198,7 +198,12 @@ static int pwm_export_child(struct device *parent, struct pwm_device *pwm)
 	export->child.parent = parent;
 	export->child.devt = MKDEV(0, 0);
 	export->child.groups = pwm_groups;
-	dev_set_name(&export->child, "pwm%u", pwm->hwpwm);
+
+	if (pwm->name)
+		dev_set_name(&export->child, pwm->name, pwm->hwpwm);
+	else
+		dev_set_name(&export->child, "pwm%u", pwm->hwpwm);
+
 
 	ret = device_register(&export->child);
 	if (ret) {
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index e90628c..9bacf35 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -86,6 +86,7 @@ struct pwm_device {
 	unsigned int		pwm;
 	struct pwm_chip		*chip;
 	void			*chip_data;
+	const char		*name; /* optional static name for pwm device */
 
 	unsigned int		period; 	/* in nanoseconds */
 	unsigned int		duty_cycle;	/* in nanoseconds */
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Aurelio Colosimo @ 2014-08-05 15:12 UTC (permalink / raw)
  To: Thierry Reding, Randy Dunlap
  Cc: linux-pwm, linux-kernel, linux-doc, Aurelio Colosimo

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-05 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs Aurelio Colosimo

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®