From: "Michal Vokáč" <michal.vokac@ysoft.com>
To: Thierry Reding <thierry.reding@gmail.com>,
Rob Herring <robh+dt@kernel.org>
Cc: "Mark Rutland" <mark.rutland@arm.com>,
devicetree@vger.kernel.org, linux-pwm@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Lukasz Majewski" <l.majewski@majess.pl>,
"Fabio Estevam" <fabio.estevam@nxp.com>,
"Lothar Waßmann" <LW@karo-electronics.de>,
"Michal Vokáč" <michal.vokac@ysoft.com>
Subject: [RFC PATCH 2/2] pmw: imx: Configure output to GPIO in disabled state
Date: Tue, 21 Aug 2018 16:38:53 +0200 [thread overview]
Message-ID: <1534862333-27950-3-git-send-email-michal.vokac@ysoft.com> (raw)
In-Reply-To: <1534862333-27950-1-git-send-email-michal.vokac@ysoft.com>
The PWM output is held at zero whenever the PWM block is disabled.
This can cause issues when inverted PWM signal polarity is needed.
Allow users to set a "default" pinctrl state that will be used when
PWM is disabled and a "pwm" pinctrl state that will be used when
PWM output is needed.
As an example, with this a PWM controlled backlight with inversed
signal polarity can be used in full brightness range. Without this
the backlight could not be turned off as brightness = 0 disables
the PWM and that in turn set output to 0V, that is full brightness.
When the pinctrl states are not correctly specifid in DT the logic
will work as before.
Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
---
drivers/pwm/pwm-imx.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 1d5242c..6212c98 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -13,6 +13,7 @@
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/io.h>
+#include <linux/pinctrl/consumer.h>
#include <linux/pwm.h>
#include <linux/of.h>
#include <linux/of_device.h>
@@ -52,10 +53,39 @@ struct imx_chip {
void __iomem *mmio_base;
struct pwm_chip chip;
+
+ struct pinctrl *pinctrl;
+ struct pinctrl_state *pinctrl_pins_default;
+ struct pinctrl_state *pinctrl_pins_pwm;
};
+
#define to_imx_chip(chip) container_of(chip, struct imx_chip, chip)
+static int imx_pwm_init_pinctrl_info(struct imx_chip *imx_chip,
+ struct platform_device *pdev)
+{
+ imx_chip->pinctrl = devm_pinctrl_get(&pdev->dev);
+ if (!imx_chip->pinctrl || IS_ERR(imx_chip->pinctrl)) {
+ dev_info(&pdev->dev, "can not get pinctrl\n");
+ return PTR_ERR(imx_chip->pinctrl);
+ }
+
+ imx_chip->pinctrl_pins_default = pinctrl_lookup_state(imx_chip->pinctrl,
+ PINCTRL_STATE_DEFAULT);
+ imx_chip->pinctrl_pins_pwm = pinctrl_lookup_state(imx_chip->pinctrl,
+ "pwm");
+
+ if (IS_ERR(imx_chip->pinctrl_pins_default) ||
+ IS_ERR(imx_chip->pinctrl_pins_pwm)) {
+ dev_info(&pdev->dev, "PWM output mux information incomplete\n");
+ devm_pinctrl_put(imx_chip->pinctrl);
+ imx_chip->pinctrl = NULL;
+ }
+
+ return 0;
+}
+
static int imx_pwm_config_v1(struct pwm_chip *chip,
struct pwm_device *pwm, int duty_ns, int period_ns)
{
@@ -216,7 +246,29 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
cr |= MX3_PWMCR_POUTC;
writel(cr, imx->mmio_base + MX3_PWMCR);
+
+ /*
+ * If we are in charge of pinctrl then switch output to
+ * the PWM signal.
+ */
+ if (imx->pinctrl)
+ pinctrl_select_state(imx->pinctrl,
+ imx->pinctrl_pins_pwm);
} else if (cstate.enabled) {
+ /*
+ * PWM block will be disabled. Normally its output will go
+ * to 0 no matter what polarity is set. In case reversed PWM
+ * polarity is required reconfigure the output pin to GPIO to
+ * keep the output at the same level as for duty-cycle = 0.
+ *
+ * First switch the muxing and then disable the PWM. In that
+ * order we do not get unwanted logic level changes on the
+ * output.
+ */
+ if (imx->pinctrl)
+ pinctrl_select_state(imx->pinctrl,
+ imx->pinctrl_pins_default);
+
writel(0, imx->mmio_base + MX3_PWMCR);
clk_disable_unprepare(imx->clk_per);
@@ -294,6 +346,10 @@ static int imx_pwm_probe(struct platform_device *pdev)
imx->chip.of_pwm_n_cells = 3;
}
+ ret = imx_pwm_init_pinctrl_info(imx, pdev);
+ if (ret)
+ return ret;
+
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
imx->mmio_base = devm_ioremap_resource(&pdev->dev, r);
if (IS_ERR(imx->mmio_base))
--
2.1.4
prev parent reply other threads:[~2018-08-21 14:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 14:38 [RFC PATCH 0/2] pwm: " Michal Vokáč
2018-08-21 14:38 ` [RFC PATCH 1/2] dt-bindings: pwm: imx: Allow switching PWM output between PWM and GPIO Michal Vokáč
2018-08-22 6:14 ` Lothar Waßmann
2018-08-22 7:01 ` Michal Vokáč
2018-08-22 11:17 ` Lothar Waßmann
2018-08-22 13:20 ` Michal Vokáč
2018-08-22 14:10 ` Lothar Waßmann
2018-08-23 9:13 ` Michal Vokáč
2018-08-23 11:18 ` Lothar Waßmann
2018-08-23 12:38 ` Michal Vokáč
2018-08-23 10:40 ` Lukasz Majewski
2018-08-23 11:19 ` Lothar Waßmann
2018-08-23 11:21 ` Michal Vokáč
2018-08-23 12:36 ` Lukasz Majewski
2018-10-09 11:03 ` Vokáč Michal
2018-08-31 12:18 ` Rob Herring
2018-08-31 12:45 ` Lothar Waßmann
2018-08-31 13:17 ` Michal Vokáč
2018-08-31 13:30 ` Lothar Waßmann
2018-10-09 10:30 ` Vokáč Michal
2018-08-21 14:38 ` Michal Vokáč [this message]
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=1534862333-27950-3-git-send-email-michal.vokac@ysoft.com \
--to=michal.vokac@ysoft.com \
--cc=LW@karo-electronics.de \
--cc=devicetree@vger.kernel.org \
--cc=fabio.estevam@nxp.com \
--cc=l.majewski@majess.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@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
all inboxes | Powered by JetHome®