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 16/21] pwm: Use dev_add_param_int for pwm parameters
Date: Sun,  7 Apr 2013 16:00:50 +0200	[thread overview]
Message-ID: <1365343255-26497-17-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1365343255-26497-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
---
 drivers/pwm/core.c | 89 ++++++++++++++++++------------------------------------
 1 file changed, 30 insertions(+), 59 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 70ec590..db7d260 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <pwm.h>
 #include <linux/list.h>
+#include <linux/err.h>
 
 struct pwm_device {
 	struct			pwm_chip *chip;
@@ -26,22 +27,14 @@ struct pwm_device {
 #define FLAG_ENABLED	1
 	struct list_head	node;
 	struct device_d		*dev;
+
+	unsigned int		duty_ns;
+	unsigned int		period_ns;
+	unsigned int		p_enable;
 };
 
 static LIST_HEAD(pwm_list);
 
-static struct pwm_device *dev_to_pwm(struct device_d *dev)
-{
-	struct pwm_device *pwm;
-
-	list_for_each_entry(pwm, &pwm_list, node) {
-		if (pwm->dev == dev)
-			return pwm;
-	}
-
-	return NULL;
-}
-
 static struct pwm_device *_find_pwm(const char *devname)
 {
 	struct pwm_device *pwm;
@@ -54,61 +47,25 @@ static struct pwm_device *_find_pwm(const char *devname)
 	return NULL;
 }
 
-static int set_period_ns(struct device_d *dev, struct param_d *p,
-			 const char *val)
+static int set_duty_period_ns(struct param_d *p, void *priv)
 {
-	struct pwm_device *pwm = dev_to_pwm(dev);
-	int period_ns;
+	struct pwm_device *pwm = priv;
 
-	if (!val)
-		return dev_param_set_generic(dev, p, NULL);
+	pwm_config(pwm, pwm->chip->duty_ns, pwm->chip->period_ns);
 
-	period_ns = simple_strtoul(val, NULL, 0);
-	pwm_config(pwm, pwm->chip->duty_ns, period_ns);
-	return dev_param_set_generic(dev, p, val);
-}
-
-static int set_duty_ns(struct device_d *dev, struct param_d *p, const char *val)
-{
-	struct pwm_device *pwm = dev_to_pwm(dev);
-	int duty_ns;
-
-	if (!val)
-		return dev_param_set_generic(dev, p, NULL);
-
-	duty_ns = simple_strtoul(val, NULL, 0);
-	pwm_config(pwm, duty_ns, pwm->chip->period_ns);
-	return dev_param_set_generic(dev, p, val);
+	return 0;
 }
 
-static int set_enable(struct device_d *dev, struct param_d *p, const char *val)
+static int set_enable(struct param_d *p, void *priv)
 {
-	struct pwm_device *pwm = dev_to_pwm(dev);
-	int enable;
-
-	if (!val)
-		return dev_param_set_generic(dev, p, NULL);
+	struct pwm_device *pwm = priv;
 
-	enable = !!simple_strtoul(val, NULL, 0);
-	if (enable)
+	if (pwm->p_enable)
 		pwm_enable(pwm);
 	else
 		pwm_disable(pwm);
-	return dev_param_set_generic(dev, p, enable ? "1" : "0");
-}
 
-static int pwm_register_vars(struct device_d *dev)
-{
-	int ret;
-
-	ret = dev_add_param(dev, "duty_ns", set_duty_ns, NULL, 0);
-	if (!ret)
-		ret = dev_add_param(dev, "period_ns", set_period_ns, NULL, 0);
-	if (!ret)
-		ret = dev_add_param(dev, "enable", set_enable, NULL, 0);
-	if (!ret)
-		ret = dev_set_param(dev, "enable", 0);
-	return ret;
+	return 0;
 }
 
 /**
@@ -121,7 +78,7 @@ static int pwm_register_vars(struct device_d *dev)
 int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
 {
 	struct pwm_device *pwm;
-	int ret = 0;
+	struct param_d *p;
 
 	if (_find_pwm(chip->devname))
 		return -EBUSY;
@@ -131,9 +88,23 @@ int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
 	pwm->dev = dev;
 
 	list_add_tail(&pwm->node, &pwm_list);
-	pwm_register_vars(dev);
 
-	return ret;
+	p = dev_add_param_int(dev, "duty_ns", set_duty_period_ns,
+			NULL, &pwm->chip->duty_ns, "%u", pwm);
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	p = dev_add_param_int(dev, "period_ns", set_duty_period_ns,
+			NULL, &pwm->chip->period_ns, "%u", pwm);
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	p = dev_add_param_bool(dev, "enable", set_enable,
+			NULL, &pwm->p_enable, pwm);
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(pwmchip_add);
 
-- 
1.8.2.rc2


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

  parent reply	other threads:[~2013-04-07 14:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 14:00 [PATCH] Add device parameter convenience helpers Sascha Hauer
2013-04-07 14:00 ` [PATCH 01/21] param: Add dev member to struct param_d Sascha Hauer
2013-04-07 14:00 ` [PATCH 02/21] param: refactor __dev_add_param Sascha Hauer
2013-04-07 14:00 ` [PATCH 03/21] param: Add integer and boolean parameter helpers Sascha Hauer
2013-04-07 14:00 ` [PATCH 04/21] param: Add ip address convenience function Sascha Hauer
2013-04-07 14:00 ` [PATCH 05/21] net: ksz8864: Use dev_add_param_bool for enable parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 06/21] net: store ethernet device parameters in device Sascha Hauer
2013-04-07 14:00 ` [PATCH 07/21] netconsole: use dev_add_param_* helpers Sascha Hauer
2013-04-07 14:00 ` [PATCH 08/21] param: remove now unused dev_[gs]et_param_ip Sascha Hauer
2013-04-07 14:00 ` [PATCH 09/21] treewide: Use dev_add_param_int_ro where possible Sascha Hauer
2013-04-07 14:00 ` [PATCH 10/21] mci: Use dev_add_param_int for probe parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 11/21] ata: Use dev_add_param_bool " Sascha Hauer
2013-04-07 14:00 ` [PATCH 12/21] fb: Use dev_add_param_bool for enable parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 13/21] fb: imxfb: Use dev_add_param_int for alpha parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 14/21] fb: imx-ipu-fb: " Sascha Hauer
2013-04-07 14:00 ` [PATCH 15/21] param: pass param to dev_remove_param Sascha Hauer
2013-04-07 14:00 ` Sascha Hauer [this message]
2013-04-07 14:00 ` [PATCH 17/21] ARM: i.MX: iim: Use dev_add_param_bool for parameters Sascha Hauer
2013-04-07 14:00 ` [PATCH 18/21] console: Use dev_add_param_int for baudrate parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 19/21] mtd: Nand: Use dev_add_param_bool for erasebad parameter Sascha Hauer
2013-04-07 22:35   ` Alexander Aring
2013-04-08  8:11     ` Sascha Hauer
2013-04-08 10:15       ` Alexander Aring
2013-04-07 14:00 ` [PATCH 20/21] USB gadget at91: Use dev_add_param_bool for vbus parameter Sascha Hauer
2013-04-07 14:00 ` [PATCH 21/21] ARM: MXS: ocotp: Use dev_add_param_bool for parameter 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=1365343255-26497-17-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