From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 10/11] pwm: sti: Sync between enable/disable calls
Date: Mon, 14 Jul 2014 15:33:31 +0100 [thread overview]
Message-ID: <1405348412-7352-11-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1405348412-7352-1-git-send-email-lee.jones@linaro.org>
From: Ajit Pal Singh <ajitpal.singh@st.com>
ST PWM IP has a common enable/disable control for all the PWM
channels on a PWM cell. Disables PWM output on the PWM HW only
when disable is called for the last channel.
Signed-off-by: Ajit Pal Singh <ajitpal.singh@st.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/pwm/pwm-sti.c | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 0fdf4b4..1aa901d 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -59,6 +59,8 @@ struct sti_pwm_chip {
unsigned long *pwm_periods;
struct pwm_chip chip;
struct pwm_device *cur;
+ unsigned int en_count;
+ struct mutex sti_pwm_lock; /* To sync between enable/disable calls */
void __iomem *mmio;
};
@@ -236,32 +238,44 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
struct device *dev = pc->dev;
- int ret;
-
- ret = clk_enable(pc->clk);
- if (ret)
- return ret;
+ int ret = 0;
- ret = regmap_field_write(pc->pwm_en, 1);
- if (ret)
- dev_err(dev, "%s,pwm_en write failed\n", __func__);
+ /*
+ * Since we have a common enable for all PWM channels,
+ * do not enable if already enabled.
+ */
+ mutex_lock(&pc->sti_pwm_lock);
+ if (!pc->en_count) {
+ ret = clk_enable(pc->clk);
+ if (ret)
+ goto out;
+ ret = regmap_field_write(pc->pwm_en, 1);
+ if (ret) {
+ dev_err(dev, "failed to enable PWM device:%d\n",
+ pwm->hwpwm);
+ goto out;
+ }
+ }
+ pc->en_count++;
+out:
+ mutex_unlock(&pc->sti_pwm_lock);
return ret;
}
static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
- struct device *dev = pc->dev;
- unsigned int val;
+ mutex_lock(&pc->sti_pwm_lock);
+ if (--pc->en_count) {
+ mutex_unlock(&pc->sti_pwm_lock);
+ return;
+ }
regmap_field_write(pc->pwm_en, 0);
- regmap_read(pc->regmap, STI_CNT, &val);
-
- dev_dbg(dev, "pwm counter :%u\n", val);
-
clk_disable(pc->clk);
+ mutex_unlock(&pc->sti_pwm_lock);
}
static const struct pwm_ops sti_pwm_ops = {
@@ -352,6 +366,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
pc->cdata = cdata;
pc->dev = dev;
+ pc->en_count = 0;
+ mutex_init(&pc->sti_pwm_lock);
ret = sti_pwm_probe_dt(pc);
if (ret)
--
1.8.3.2
next prev parent reply other threads:[~2014-07-14 14:33 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-14 14:33 [PATCH v2 00/11] pwm: Introduce ST's PWM driver Lee Jones
2014-07-14 14:33 ` [PATCH v2 01/11] ARM: stih407: Add DT nodes for for PWM Lee Jones
2014-07-14 14:33 ` [PATCH v2 02/11] ARM: stih416: Add Pinctrl settings " Lee Jones
2014-07-14 14:33 ` [PATCH v2 03/11] ARM: stih416: Add DT nodes " Lee Jones
2014-07-14 14:33 ` [PATCH v2 04/11] ARM: stih416-b2020e: Enable PWM on the B2020 Rev-E Lee Jones
2014-07-14 14:33 ` [PATCH v2 05/11] ARM: multi_v7_defconfig: Enable ST's PWM driver Lee Jones
2014-07-14 14:33 ` [PATCH v2 06/11] pwm: sti: Add new driver for ST's PWM IP Lee Jones
2014-08-07 14:23 ` Thierry Reding
2014-08-08 7:38 ` Lee Jones
2014-08-08 9:46 ` Thierry Reding
2014-07-14 14:33 ` [PATCH v2 07/11] pwm: sti: Supply Device Tree binding documentation " Lee Jones
2014-07-14 14:33 ` [PATCH v2 08/11] pwm: st: Fix PWM prescaler handling Lee Jones
2014-07-14 14:33 ` [PATCH v2 09/11] pwm: sti: Ensure same period values for all channels Lee Jones
2014-08-07 14:24 ` Thierry Reding
2014-07-14 14:33 ` Lee Jones [this message]
2014-07-14 14:33 ` [PATCH v2 11/11] pwm: sti: Remove PWM period table Lee Jones
2014-07-21 12:39 ` [PATCH v2 00/11] pwm: Introduce ST's PWM driver Lee Jones
2014-08-07 13:20 ` Thierry Reding
2014-08-07 13:54 ` Lee Jones
2014-08-07 13:55 ` Thierry Reding
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=1405348412-7352-11-git-send-email-lee.jones@linaro.org \
--to=lee.jones@linaro.org \
--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).