Commit 326ed314 authored by Lukasz Majewski's avatar Lukasz Majewski Committed by Thierry Reding

pwm: imx: Add polarity inversion support to i.MX's PWMv2

With this patch the polarity settings for i.MX's PWMv2 is now supported
on top of atomic PWM setting
Signed-off-by: default avatarBhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: default avatarLukasz Majewski <l.majewski@majess.pl>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent c322f457
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define MX3_PWMCR_DOZEEN (1 << 24) #define MX3_PWMCR_DOZEEN (1 << 24)
#define MX3_PWMCR_WAITEN (1 << 23) #define MX3_PWMCR_WAITEN (1 << 23)
#define MX3_PWMCR_DBGEN (1 << 22) #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_HIGH (2 << 16)
#define MX3_PWMCR_CLKSRC_IPG (1 << 16) #define MX3_PWMCR_CLKSRC_IPG (1 << 16)
#define MX3_PWMCR_SWR (1 << 3) #define MX3_PWMCR_SWR (1 << 3)
...@@ -163,6 +164,7 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -163,6 +164,7 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_state cstate; struct pwm_state cstate;
unsigned long long c; unsigned long long c;
int ret; int ret;
u32 cr;
pwm_get_state(pwm, &cstate); pwm_get_state(pwm, &cstate);
...@@ -207,11 +209,15 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -207,11 +209,15 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm,
writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); writel(duty_cycles, imx->mmio_base + MX3_PWMSAR);
writel(period_cycles, imx->mmio_base + MX3_PWMPR); writel(period_cycles, imx->mmio_base + MX3_PWMPR);
writel(MX3_PWMCR_PRESCALER(prescale) | cr = MX3_PWMCR_PRESCALER(prescale) |
MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN | MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN |
MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH | MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH |
MX3_PWMCR_EN, MX3_PWMCR_EN;
imx->mmio_base + MX3_PWMCR);
if (state->polarity == PWM_POLARITY_INVERSED)
cr |= MX3_PWMCR_POUTC;
writel(cr, imx->mmio_base + MX3_PWMCR);
} else if (cstate.enabled) { } else if (cstate.enabled) {
writel(0, imx->mmio_base + MX3_PWMCR); writel(0, imx->mmio_base + MX3_PWMCR);
...@@ -234,6 +240,7 @@ static const struct pwm_ops imx_pwm_ops_v2 = { ...@@ -234,6 +240,7 @@ static const struct pwm_ops imx_pwm_ops_v2 = {
}; };
struct imx_pwm_data { struct imx_pwm_data {
bool polarity_supported;
const struct pwm_ops *ops; const struct pwm_ops *ops;
}; };
...@@ -242,6 +249,7 @@ static struct imx_pwm_data imx_pwm_data_v1 = { ...@@ -242,6 +249,7 @@ static struct imx_pwm_data imx_pwm_data_v1 = {
}; };
static struct imx_pwm_data imx_pwm_data_v2 = { static struct imx_pwm_data imx_pwm_data_v2 = {
.polarity_supported = true,
.ops = &imx_pwm_ops_v2, .ops = &imx_pwm_ops_v2,
}; };
...@@ -283,6 +291,12 @@ static int imx_pwm_probe(struct platform_device *pdev) ...@@ -283,6 +291,12 @@ static int imx_pwm_probe(struct platform_device *pdev)
imx->chip.npwm = 1; imx->chip.npwm = 1;
imx->chip.can_sleep = true; 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); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
imx->mmio_base = devm_ioremap_resource(&pdev->dev, r); imx->mmio_base = devm_ioremap_resource(&pdev->dev, r);
if (IS_ERR(imx->mmio_base)) if (IS_ERR(imx->mmio_base))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment