linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Thierry Reding <thierry.reding@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Stefan Agner <stefan@agner.ch>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	linux-pwm@vger.kernel.org,
	Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>,
	linux-kernel@vger.kernel.org
Cc: Lothar Wassmann <LW@karo-electronics.de>,
	kernel@pengutronix.de, Fabio Estevam <fabio.estevam@nxp.com>,
	Lukasz Majewski <lukma@denx.de>,
	Lukasz Majewski <l.majewski@majess.pl>
Subject: [PATCH v5 11/11] pwm: imx: Add polarity inversion support to i.MX's PWMv2
Date: Sun, 29 Jan 2017 22:54:15 +0100	[thread overview]
Message-ID: <1485726855-16236-12-git-send-email-lukma@denx.de> (raw)
In-Reply-To: <1485726855-16236-1-git-send-email-lukma@denx.de>

With this patch the polarity settings for i.MX's PWMv2 is now supported
on top of atomic PWM setting

Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
---
Changes for v5:
- Adjust to corrected ->apply_v2() code

Changes for v4:
- MX3_PWMCR_POUTC setting adjustements after apply_v2() previous changes

Changes for v3:
- None

Changes for v2:
- New patch
---
 drivers/pwm/pwm-imx.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index e037023..9f7e787 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -38,6 +38,7 @@
 #define MX3_PWMCR_DOZEEN		(1 << 24)
 #define MX3_PWMCR_WAITEN		(1 << 23)
 #define MX3_PWMCR_DBGEN			(1 << 22)
+#define MX3_PWMCR_POUTC			(1 << 18)
 #define MX3_PWMCR_CLKSRC_IPG_HIGH	(2 << 16)
 #define MX3_PWMCR_CLKSRC_IPG		(1 << 16)
 #define MX3_PWMCR_SWR			(1 << 3)
@@ -164,6 +165,7 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 	struct pwm_state cstate;
 	unsigned long long c;
 	int ret;
+	u32 cr;
 
 	pwm_get_state(pwm, &cstate);
 
@@ -208,12 +210,15 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
 		writel(duty_cycles, imx->mmio_base + MX3_PWMSAR);
 		writel(period_cycles, imx->mmio_base + MX3_PWMPR);
 
-		writel(MX3_PWMCR_PRESCALER(prescale) |
-		       MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN |
-		       MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH |
-		       MX3_PWMCR_EN,
-		       imx->mmio_base + MX3_PWMCR);
+		cr = MX3_PWMCR_PRESCALER(prescale) |
+			MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN |
+			MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH |
+			MX3_PWMCR_EN;
+
+		if (state->polarity == PWM_POLARITY_INVERSED)
+			cr |= MX3_PWMCR_POUTC;
 
+		writel(cr, imx->mmio_base + MX3_PWMCR);
 	} else if (cstate.enabled) {
 		writel(0, imx->mmio_base + MX3_PWMCR);
 
@@ -236,6 +241,7 @@ static struct pwm_ops imx_pwm_ops_v2 = {
 };
 
 struct imx_pwm_data {
+	bool polarity_supported;
 	struct pwm_ops *pwm_ops;
 };
 
@@ -244,6 +250,7 @@ static struct imx_pwm_data imx_pwm_data_v1 = {
 };
 
 static struct imx_pwm_data imx_pwm_data_v2 = {
+	.polarity_supported = true,
 	.pwm_ops = &imx_pwm_ops_v2,
 };
 
@@ -284,6 +291,11 @@ static int imx_pwm_probe(struct platform_device *pdev)
 	imx->chip.base = -1;
 	imx->chip.npwm = 1;
 	imx->chip.can_sleep = true;
+	if (data->polarity_supported) {
+		dev_dbg(&pdev->dev, "PWM supports output inversion\n");
+		imx->chip.of_xlate = of_pwm_xlate_with_flags;
+		imx->chip.of_pwm_n_cells = 3;
+	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	imx->mmio_base = devm_ioremap_resource(&pdev->dev, r);
-- 
2.1.4

      parent reply	other threads:[~2017-01-29 21:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-29 21:54 [PATCH v5 00/11] pwm: imx: Provide atomic operation for IMX PWM driver Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 01/11] pwm: print error messages with pr_err() instead of pr_debug() Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 02/11] pwm: imx: remove ipg clock and enable per clock when required Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 03/11] pwm: imx: Add separate set of pwm ops for PWMv1 and PWMv2 Lukasz Majewski
2017-01-30  7:23   ` Thierry Reding
2017-01-30  7:43     ` Thierry Reding
2017-01-30  8:36       ` Lukasz Majewski
2017-01-30  8:45         ` Thierry Reding
2017-01-30  8:55           ` Lukasz Majewski
2017-01-30  9:04             ` Thierry Reding
2017-01-29 21:54 ` [PATCH v5 04/11] pwm: imx: Rewrite imx_pwm_*_v1 code to facilitate switch to atomic pwm operation Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 05/11] pwm: imx: Move PWMv2 software reset code to a separate function Lukasz Majewski
2017-01-30  7:26   ` Thierry Reding
2017-01-29 21:54 ` [PATCH v5 06/11] pwm: imx: Move PWMv2 wait for fifo slot " Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 07/11] pwm: imx: Provide atomic PWM support for i.MX PWMv2 Lukasz Majewski
2017-01-30  7:49   ` Boris Brezillon
2017-01-30  7:54     ` Thierry Reding
2017-01-29 21:54 ` [PATCH v5 08/11] pwm: imx: Remove redundant i.MX PWMv2 code Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 09/11] pwm: core: make the PWM_POLARITY flag in DTB optional Lukasz Majewski
2017-01-29 21:54 ` [PATCH v5 10/11] pwm: imx: doc: Update imx-pwm.txt documentation entry Lukasz Majewski
2017-01-29 21:54 ` Lukasz Majewski [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=1485726855-16236-12-git-send-email-lukma@denx.de \
    --to=lukma@denx.de \
    --cc=LW@karo-electronics.de \
    --cc=bhuvanchandra.dv@toradex.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=fabio.estevam@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=l.majewski@majess.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=stefan@agner.ch \
    --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;
as well as URLs for NNTP newsgroup(s).