devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: vineetha.g.jaya.kumaran@intel.com
To: thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de,
	robh+dt@kernel.org
Cc: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
	wan.ahmad.zainie.wan.mohamad@intel.com,
	andriy.shevchenko@intel.com, vineetha.g.jaya.kumaran@intel.com
Subject: [PATCH 1/3] pwm: Add count attribute in sysfs for Intel Keem Bay
Date: Sun, 17 May 2020 21:52:38 +0800	[thread overview]
Message-ID: <1589723560-5734-2-git-send-email-vineetha.g.jaya.kumaran@intel.com> (raw)
In-Reply-To: <1589723560-5734-1-git-send-email-vineetha.g.jaya.kumaran@intel.com>

From: "Lai, Poey Seng" <poey.seng.lai@intel.com>

In Keem Bay, the number of repetitions for the period/waveform
can be configured from userspace. This requires addition of a sysfs
attribute to get/set the repetition count. Setting this value to 0
will result in continuous repetition of the waveform until the
channel is disabled or reconfigured.

Signed-off-by: Lai, Poey Seng <poey.seng.lai@intel.com>
Signed-off-by: Vineetha G. Jaya Kumaran <vineetha.g.jaya.kumaran@intel.com>
---
 Documentation/ABI/testing/sysfs-class-pwm |  9 ++++++++
 drivers/pwm/core.c                        |  3 ++-
 drivers/pwm/sysfs.c                       | 37 +++++++++++++++++++++++++++++++
 include/linux/pwm.h                       |  2 ++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-class-pwm b/Documentation/ABI/testing/sysfs-class-pwm
index c20e613..87e219f 100644
--- a/Documentation/ABI/testing/sysfs-class-pwm
+++ b/Documentation/ABI/testing/sysfs-class-pwm
@@ -86,3 +86,12 @@ Description:
 		Capture information about a PWM signal. The output format is a
 		pair unsigned integers (period and duty cycle), separated by a
 		single space.
+
+What:		/sys/class/pwm/pwmchipN/pwmX/count
+Date:		May 2020
+KernelVersion:	5.6
+Contact:	Vineetha G. Jaya Kumaran <vineetha.g.jaya.kumaran@intel.com>
+Description:
+		Sets the repetition count of a PWM waveform. A value of 0 will
+		result in continuous repetition of the waveform until the
+		channel is disabled or reconfigured.
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index bca0496..fd42fb6 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -584,7 +584,8 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
 	if (state->period == pwm->state.period &&
 	    state->duty_cycle == pwm->state.duty_cycle &&
 	    state->polarity == pwm->state.polarity &&
-	    state->enabled == pwm->state.enabled)
+	    state->enabled == pwm->state.enabled &&
+	    state->count == pwm->state.count)
 		return 0;
 
 	if (chip->ops->apply) {
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 2389b86..3c474fa 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -215,11 +215,47 @@ static ssize_t capture_show(struct device *child,
 	return sprintf(buf, "%u %u\n", result.period, result.duty_cycle);
 }
 
+static ssize_t count_store(struct device *child,
+			      struct device_attribute *attr,
+			      const char *buf, size_t size)
+{
+	struct pwm_export *export = child_to_pwm_export(child);
+	struct pwm_device *pwm = export->pwm;
+	struct pwm_state state;
+	unsigned int val;
+	int ret;
+
+	ret = kstrtouint(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	mutex_lock(&export->lock);
+	pwm_get_state(pwm, &state);
+	state.count = val;
+	ret = pwm_apply_state(pwm, &state);
+	mutex_unlock(&export->lock);
+
+	return ret ? : size;
+}
+
+static ssize_t count_show(struct device *child,
+			    struct device_attribute *attr,
+			    char *buf)
+{
+	const struct pwm_device *pwm = child_to_pwm_device(child);
+	struct pwm_state state;
+
+	pwm_get_state(pwm, &state);
+
+	return sprintf(buf, "%d\n", state.count);
+}
+
 static DEVICE_ATTR_RW(period);
 static DEVICE_ATTR_RW(duty_cycle);
 static DEVICE_ATTR_RW(enable);
 static DEVICE_ATTR_RW(polarity);
 static DEVICE_ATTR_RO(capture);
+static DEVICE_ATTR_RW(count);
 
 static struct attribute *pwm_attrs[] = {
 	&dev_attr_period.attr,
@@ -227,6 +263,7 @@ static ssize_t capture_show(struct device *child,
 	&dev_attr_enable.attr,
 	&dev_attr_polarity.attr,
 	&dev_attr_capture.attr,
+	&dev_attr_count.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(pwm);
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 2635b2a..c874559 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -52,12 +52,14 @@ enum {
  * struct pwm_state - state of a PWM channel
  * @period: PWM period (in nanoseconds)
  * @duty_cycle: PWM duty cycle (in nanoseconds)
+ * @count: Repeat count of PWM waveforms.
  * @polarity: PWM polarity
  * @enabled: PWM enabled status
  */
 struct pwm_state {
 	unsigned int period;
 	unsigned int duty_cycle;
+	unsigned int count;
 	enum pwm_polarity polarity;
 	bool enabled;
 };
-- 
1.9.1


  reply	other threads:[~2020-05-17 13:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 13:52 [PATCH 0/3] Add PWM support for Intel Keem Bay SoC vineetha.g.jaya.kumaran
2020-05-17 13:52 ` vineetha.g.jaya.kumaran [this message]
2020-05-23 21:05   ` [PATCH 1/3] pwm: Add count attribute in sysfs for Intel Keem Bay Uwe Kleine-König
2020-06-05 13:49     ` G Jaya Kumaran, Vineetha
2020-05-17 13:52 ` [PATCH 2/3] pwm: Add PWM driver " vineetha.g.jaya.kumaran
2020-05-23 21:40   ` Uwe Kleine-König
2020-06-05 13:48     ` G Jaya Kumaran, Vineetha
2020-05-17 13:52 ` [PATCH 3/3] dt-bindings: pwm: keembay: Add bindings for Intel Keem Bay PWM vineetha.g.jaya.kumaran
2020-05-18 14:18   ` Rob Herring
2020-05-20 10:49     ` G Jaya Kumaran, Vineetha
2020-05-18 14:21   ` Rob Herring
2020-05-20 10:52     ` G Jaya Kumaran, Vineetha

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=1589723560-5734-2-git-send-email-vineetha.g.jaya.kumaran@intel.com \
    --to=vineetha.g.jaya.kumaran@intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wan.ahmad.zainie.wan.mohamad@intel.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;
as well as URLs for NNTP newsgroup(s).