mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/5] PWM: Implement devicetree support
Date: Fri, 28 Feb 2014 15:24:52 +0100	[thread overview]
Message-ID: <1393597495-13896-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1393597495-13896-1-git-send-email-s.hauer@pengutronix.de>

This implements of_pwm_request() for PWM client drivers.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/pwm/core.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++------
 include/pwm.h      |  2 ++
 2 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 7f30724..cc33dec 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -143,6 +143,24 @@ int pwmchip_remove(struct pwm_chip *chip)
 }
 EXPORT_SYMBOL_GPL(pwmchip_remove);
 
+static int __pwm_request(struct pwm_device *pwm)
+{
+	int ret;
+
+	if (test_bit(FLAG_REQUESTED, &pwm->flags))
+		return -EBUSY;
+
+	if (pwm->chip->ops->request) {
+		ret = pwm->chip->ops->request(pwm->chip);
+		if (ret)
+			return ret;
+	}
+
+	set_bit(FLAG_REQUESTED, &pwm->flags);
+
+	return 0;
+}
+
 /*
  * pwm_request - request a PWM device
  */
@@ -155,20 +173,59 @@ struct pwm_device *pwm_request(const char *devname)
 	if (!pwm)
 		return NULL;
 
-	if (test_bit(FLAG_REQUESTED, &pwm->flags))
+	ret = __pwm_request(pwm);
+	if (ret)
 		return NULL;
 
-	if (pwm->chip->ops->request) {
-		ret = pwm->chip->ops->request(pwm->chip);
-		if (ret)
-			return NULL;
+	return pwm;
+}
+EXPORT_SYMBOL_GPL(pwm_request);
+
+static struct pwm_device *of_node_to_pwm_device(struct device_node *np)
+{
+	struct pwm_device *pwm;
+
+	list_for_each_entry(pwm, &pwm_list, node) {
+		if (pwm->hwdev && pwm->hwdev->device_node == np)
+			return pwm;
 	}
 
-	set_bit(FLAG_REQUESTED, &pwm->flags);
+        return ERR_PTR(-ENODEV);
+}
+
+struct pwm_device *of_pwm_request(struct device_node *np, const char *con_id)
+{
+	struct of_phandle_args args;
+	int index = 0;
+	struct pwm_device *pwm;
+	int ret;
+
+	if (con_id)
+		return ERR_PTR(-EINVAL);
+
+	ret = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
+			&args);
+	if (ret) {
+		pr_debug("%s(): can't parse \"pwms\" property\n", __func__);
+		return ERR_PTR(ret);
+	}
+
+	pwm = of_node_to_pwm_device(args.np);
+	if (IS_ERR(pwm)) {
+		pr_debug("%s(): PWM chip not found\n", __func__);
+		return pwm;
+	}
+
+	if (args.args_count > 1)
+		pwm_set_period(pwm, args.args[1]);
+
+	ret = __pwm_request(pwm);
+	if (ret)
+		return ERR_PTR(-ret);
 
 	return pwm;
 }
-EXPORT_SYMBOL_GPL(pwm_request);
+EXPORT_SYMBOL_GPL(of_pwm_request);
 
 /*
  * pwm_free - free a PWM device
diff --git a/include/pwm.h b/include/pwm.h
index 5ca9fa0..59d86d4 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -9,6 +9,8 @@ struct device_d;
  */
 struct pwm_device *pwm_request(const char *pwmname);
 
+struct pwm_device *of_pwm_request(struct device_node *np, const char *con_id);
+
 /*
  * pwm_free - free a PWM device
  */
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2014-02-28 14:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28 14:24 [PATCH 1/5] PWM: Add functions for getting/setting period/duty cycle Sascha Hauer
2014-02-28 14:24 ` Sascha Hauer [this message]
2014-02-28 14:24 ` [PATCH 3/5] led: move led_of_parse_trigger to core Sascha Hauer
2014-02-28 14:24 ` [PATCH 4/5] led: Add pwm-led driver Sascha Hauer
2014-02-28 14:24 ` [PATCH 5/5] led: Add default-on trigger Sascha Hauer

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=1393597495-13896-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox