From: Jonathan Richardson <jonathar@broadcom.com>
To: Tim Kryger <tim.kryger@gmail.com>
Cc: Scott Branden <sbranden@broadcom.com>,
Arun Ramamurthy <arun.ramamurthy@broadcom.com>,
Thierry Reding <thierry.reding@gmail.com>,
Ray Jui <rjui@broadcom.com>,
bcm-kernel-feedback-list@broadcom.com,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
Jonathan Richardson <jonathar@broadcom.com>
Subject: [PATCH v4 2/3] pwm: kona: Remove setting default smooth type and polarity for all channels
Date: Tue, 30 Dec 2014 14:43:29 -0800 [thread overview]
Message-ID: <1419979410-7589-3-git-send-email-jonathar@broadcom.com> (raw)
In-Reply-To: <1419979410-7589-1-git-send-email-jonathar@broadcom.com>
Setting the default polarity in probe to normal for all channels caused
the speaker pwm channel to click. The polarity does need to be set to
normal because the hw default is inversed whereas the pwm framework
defaults to normal. If a channel is enabled without setting the polarity
then the signal would be inversed while linux reports normal. A check
is now done prior to enabling the channel to ensure that the hw polarity
matches the desired polarity and is changed if there is a discrepency. This
prevents unnecessary settings being applied to unused channels but still
ensures the correct polarity to be set.
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Tested-by: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Jonathan Richardson <jonathar@broadcom.com>
---
drivers/pwm/pwm-bcm-kona.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
index 5ae4bf7..34d434a 100644
--- a/drivers/pwm/pwm-bcm-kona.c
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -95,6 +95,32 @@ static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan)
ndelay(400);
}
+static void kona_pwmc_check_set_polarity(struct pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct kona_pwmc *kp = to_kona_pwmc(chip);
+ unsigned int chan = pwm->hwpwm;
+ enum pwm_polarity polarity = pwm->polarity;
+ unsigned int hw_pol;
+ unsigned int value = 0;
+
+ value = hw_pol = readl(kp->base + PWM_CONTROL_OFFSET);
+ hw_pol = (hw_pol >> PWM_CONTROL_POLARITY_SHIFT(chan)) & 0x1;
+
+ /*
+ * If current polarity not the same as h/w then set polarity so that
+ * they match.
+ */
+ if (!hw_pol != polarity) {
+ if (polarity == PWM_POLARITY_NORMAL)
+ value |= 1 << PWM_CONTROL_POLARITY_SHIFT(chan);
+ else
+ value &= ~(1 << PWM_CONTROL_POLARITY_SHIFT(chan));
+
+ writel(value, kp->base + PWM_CONTROL_OFFSET);
+ }
+}
+
static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
@@ -165,6 +191,14 @@ static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm,
* validated immediately instead of on enable.
*/
if (test_bit(PWMF_ENABLED, &pwm->flags)) {
+ /*
+ * Ensure polarity is set properly. The default value
+ * for h/w and the PWM framework are different. If a
+ * channel is enabled without setting the polarity, the
+ * default value would be inconsistent to the signal.
+ */
+ kona_pwmc_check_set_polarity(chip, pwm);
+
value = readl(kp->base + PWM_CONTROL_OFFSET);
/*
@@ -311,12 +345,9 @@ static int kona_pwmc_probe(struct platform_device *pdev)
return ret;
}
- /* Set smooth mode, push/pull, and normal polarity for all channels */
- for (chan = 0; chan < kp->chip.npwm; chan++) {
- value |= (1 << PWM_CONTROL_SMOOTH_SHIFT(chan));
+ /* Set push/pull for all channels */
+ for (chan = 0; chan < kp->chip.npwm; chan++)
value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan));
- value |= (1 << PWM_CONTROL_POLARITY_SHIFT(chan));
- }
writel(value, kp->base + PWM_CONTROL_OFFSET);
--
1.7.9.5
next prev parent reply other threads:[~2014-12-30 22:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Jonathan Richardson <jonathar@broadcom.com>
2014-12-11 1:07 ` [PATCH v2 1/2] pwm: kona: Fix incorrect enable, config, and disable procedures Jonathan Richardson
2014-12-11 1:07 ` [PATCH v2 2/2] pwm: kona: Remove setting default smooth type and polarity for all channels Jonathan Richardson
2014-12-15 7:18 ` [PATCH v2 1/2] pwm: kona: Fix incorrect enable, config, and disable procedures Tim Kryger
2014-12-16 19:36 ` Jonathan Richardson
2014-12-17 18:46 ` [PATCH v3 " Jonathan Richardson
2014-12-17 18:46 ` [PATCH v3 2/2] pwm: kona: Remove setting default smooth type and polarity for all channels Jonathan Richardson
2014-12-20 22:38 ` [PATCH v3 1/2] pwm: kona: Fix incorrect enable, config, and disable procedures Tim Kryger
2014-12-22 22:49 ` Jonathan Richardson
2014-12-30 22:43 ` [PATCH v4 0/3] Fix bugs in kona pwm driver and pwm core Jonathan Richardson
2014-12-30 22:43 ` [PATCH v4 1/3] pwm: kona: Fix incorrect config, disable, and polarity procedures Jonathan Richardson
2014-12-30 22:43 ` Jonathan Richardson [this message]
2015-01-05 1:12 ` [PATCH v4 2/3] pwm: kona: Remove setting default smooth type and polarity for all channels Tim Kryger
2015-01-05 1:33 ` Tim Kryger
2014-12-30 22:43 ` [PATCH v4 3/3] pwm: core: Set enable state properly on failed call to enable Jonathan Richardson
2015-01-07 19:42 ` [PATCH v5 0/2] Fix bugs in kona pwm driver and pwm core Jonathan Richardson
2015-01-07 19:42 ` [PATCH v5 1/2] pwm: kona: Fix incorrect config, disable, and polarity procedures Jonathan Richardson
2015-01-07 19:42 ` [PATCH v5 2/2] pwm: core: Set enable state properly on failed call to enable Jonathan Richardson
2015-02-11 23:59 ` Dmitry Torokhov
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=1419979410-7589-3-git-send-email-jonathar@broadcom.com \
--to=jonathar@broadcom.com \
--cc=arun.ramamurthy@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=rjui@broadcom.com \
--cc=sbranden@broadcom.com \
--cc=thierry.reding@gmail.com \
--cc=tim.kryger@gmail.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).