Lines Matching +full:clk +full:- +full:pwm

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PWM framework driver for Cirrus Logic EP93xx
9 * platform device ep93xx-pwm.1 - PWMOUT1 (EGPIO14)
12 * platform device ep93xx-pwm.0 - PWMOUT
15 * platform device ep93xx-pwm.0 - PWMOUT
16 * platform device ep93xx-pwm.1 - PWMOUT1 (EGPIO14)
23 #include <linux/clk.h>
26 #include <linux/pwm.h>
37 struct clk *clk; member
45 static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in ep93xx_pwm_apply() argument
50 bool enabled = state->enabled; in ep93xx_pwm_apply()
51 void __iomem *base = ep93xx_pwm->base; in ep93xx_pwm_apply()
57 if (state->polarity != pwm->state.polarity) { in ep93xx_pwm_apply()
59 writew(0x0, ep93xx_pwm->base + EP93XX_PWMx_ENABLE); in ep93xx_pwm_apply()
60 clk_disable_unprepare(ep93xx_pwm->clk); in ep93xx_pwm_apply()
65 * The clock needs to be enabled to access the PWM registers. in ep93xx_pwm_apply()
66 * Polarity can only be changed when the PWM is disabled. in ep93xx_pwm_apply()
68 ret = clk_prepare_enable(ep93xx_pwm->clk); in ep93xx_pwm_apply()
72 if (state->polarity == PWM_POLARITY_INVERSED) in ep93xx_pwm_apply()
73 writew(0x1, ep93xx_pwm->base + EP93XX_PWMx_INVERT); in ep93xx_pwm_apply()
75 writew(0x0, ep93xx_pwm->base + EP93XX_PWMx_INVERT); in ep93xx_pwm_apply()
77 clk_disable_unprepare(ep93xx_pwm->clk); in ep93xx_pwm_apply()
80 if (!state->enabled) { in ep93xx_pwm_apply()
82 writew(0x0, ep93xx_pwm->base + EP93XX_PWMx_ENABLE); in ep93xx_pwm_apply()
83 clk_disable_unprepare(ep93xx_pwm->clk); in ep93xx_pwm_apply()
90 * The clock needs to be enabled to access the PWM registers. in ep93xx_pwm_apply()
93 if (!pwm_is_enabled(pwm)) { in ep93xx_pwm_apply()
94 ret = clk_prepare_enable(ep93xx_pwm->clk); in ep93xx_pwm_apply()
99 c = clk_get_rate(ep93xx_pwm->clk); in ep93xx_pwm_apply()
100 c *= state->period; in ep93xx_pwm_apply()
105 c *= state->duty_cycle; in ep93xx_pwm_apply()
106 do_div(c, state->period); in ep93xx_pwm_apply()
112 /* Order is important if PWM is running */ in ep93xx_pwm_apply()
122 ret = -EINVAL; in ep93xx_pwm_apply()
125 if (!pwm_is_enabled(pwm)) in ep93xx_pwm_apply()
126 clk_disable_unprepare(ep93xx_pwm->clk); in ep93xx_pwm_apply()
132 ret = clk_prepare_enable(ep93xx_pwm->clk); in ep93xx_pwm_apply()
136 writew(0x1, ep93xx_pwm->base + EP93XX_PWMx_ENABLE); in ep93xx_pwm_apply()
152 chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*ep93xx_pwm)); in ep93xx_pwm_probe()
157 ep93xx_pwm->base = devm_platform_ioremap_resource(pdev, 0); in ep93xx_pwm_probe()
158 if (IS_ERR(ep93xx_pwm->base)) in ep93xx_pwm_probe()
159 return PTR_ERR(ep93xx_pwm->base); in ep93xx_pwm_probe()
161 ep93xx_pwm->clk = devm_clk_get(&pdev->dev, "pwm_clk"); in ep93xx_pwm_probe()
162 if (IS_ERR(ep93xx_pwm->clk)) in ep93xx_pwm_probe()
163 return PTR_ERR(ep93xx_pwm->clk); in ep93xx_pwm_probe()
165 chip->ops = &ep93xx_pwm_ops; in ep93xx_pwm_probe()
167 ret = devm_pwmchip_add(&pdev->dev, chip); in ep93xx_pwm_probe()
175 { .compatible = "cirrus,ep9301-pwm" },
182 .name = "ep93xx-pwm",
189 MODULE_DESCRIPTION("Cirrus Logic EP93xx PWM driver");
192 MODULE_ALIAS("platform:ep93xx-pwm");