From: matthias@kaehlcke.net (Matthias Kaehlcke)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] PWM: add pwm framework support
Date: Tue, 28 Jun 2011 21:40:40 +0200 [thread overview]
Message-ID: <20110628194040.GE15091@darwin> (raw)
In-Reply-To: <1309255368-9775-2-git-send-email-s.hauer@pengutronix.de>
El Tue, Jun 28, 2011 at 12:02:47PM +0200 Sascha Hauer ha dit:
> This patch adds framework support for PWM (pulse width modulation) devices.
[...]
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> new file mode 100644
> index 0000000..79dc051
> --- /dev/null
> +++ b/drivers/pwm/core.c
[...]
> +/**
> + * pwmchip_add() - register a new pwm
> + * @chip: the pwm
> + *
> + * register a new pwm. pwm->pwm_id must be initialized. if pwm_id < 0 then
> + * a dynamically assigned id will be used, otherwise the id specified,
> + */
> +int pwmchip_add(struct pwm_chip *chip)
> +{
> + struct pwm_device *pwm;
> + int ret = 0;
> +
> + pwm = kzalloc(sizeof(*pwm), GFP_KERNEL);
> + if (!pwm)
> + return -ENOMEM;
> +
> + pwm->chip = chip;
> +
> + mutex_lock(&pwm_lock);
> +
> + if (chip->pwm_id >= 0 && find_pwm(chip->pwm_id)) {
> + ret = -EBUSY;
> + goto out;
> + }
> +
> + if (chip->pwm_id < 0)
> + chip->pwm_id = next_pwm_id++;
> +
> + list_add_tail(&pwm->node, &pwm_list);
> +out:
> + mutex_unlock(&pwm_lock);
> +
> + kfree(pwm);
as already pointed out by kurt, pwm should only be freed in case of an
error
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(pwmchip_add);
> +
> +/**
> + * pwmchip_remove() - remove a pwm
> + * @chip: the pwm
> + *
> + * remove a pwm. This function may return busy if the pwm is still requested.
> + */
> +int pwmchip_remove(struct pwm_chip *chip)
> +{
> + struct pwm_device *pwm;
> + int ret = 0;
> +
> + mutex_lock(&pwm_lock);
> +
> + pwm = find_pwm(chip->pwm_id);
> + if (!pwm) {
> + ret = -ENOENT;
> + goto out;
> + }
> +
> + if (test_bit(FLAG_REQUESTED, &pwm->flags)) {
> + ret = -EBUSY;
> + goto out;
> + }
> +
> + list_del(&pwm->node);
+ kfree(pwm);
> +out:
> + mutex_unlock(&pwm_lock);
> +
> + return ret;
> +}
[...]
best regards
--
Matthias Kaehlcke
Embedded Linux Developer
Amsterdam
It always seems impossible until it's done
(Nelson Mandela)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
next prev parent reply other threads:[~2011-06-28 19:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-28 10:02 [RFC] implement a generic PWM framework - once again Sascha Hauer
2011-06-28 10:02 ` [PATCH 1/2] PWM: add pwm framework support Sascha Hauer
2011-06-28 12:27 ` Arnd Bergmann
2011-06-28 16:18 ` Sascha Hauer
2011-06-28 17:03 ` Arnd Bergmann
2011-06-29 8:50 ` Sascha Hauer
2011-06-29 11:00 ` Arnd Bergmann
2011-06-28 19:40 ` Matthias Kaehlcke [this message]
2011-06-28 10:02 ` [PATCH 2/2] pwm: Add a i.MX23/28 pwm driver Sascha Hauer
2011-06-28 10:28 ` Lothar Waßmann
2011-06-28 15:22 ` Arnd Bergmann
2011-06-28 12:23 ` [RFC] implement a generic PWM framework - once again Dmitry Eremin-Solenikov
-- strict thread matches above, loose matches on Subject: below --
2011-06-29 9:03 [PATCH v2] implement a generic PWM framework Sascha Hauer
2011-06-29 9:03 ` [PATCH 1/2] PWM: add pwm framework support Sascha Hauer
2011-06-29 11:41 ` Arnd Bergmann
2011-06-29 19:47 ` Matthias Kaehlcke
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=20110628194040.GE15091@darwin \
--to=matthias@kaehlcke.net \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).