Lines Matching +full:pwm +full:- +full:offset

2  * Marvell Berlin PWM driver
6 * Author: Antoine Tenart <antoine.tenart@free-electrons.com>
19 #include <linux/pwm.h>
64 unsigned int channel, unsigned long offset) in berlin_pwm_readl() argument
66 return readl_relaxed(bpc->base + channel * 0x10 + offset); in berlin_pwm_readl()
71 unsigned long offset) in berlin_pwm_writel() argument
73 writel_relaxed(value, bpc->base + channel * 0x10 + offset); in berlin_pwm_writel()
76 static int berlin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in berlin_pwm_config() argument
84 cycles = clk_get_rate(bpc->clk); in berlin_pwm_config()
93 return -ERANGE; in berlin_pwm_config()
101 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_CONTROL); in berlin_pwm_config()
106 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_CONTROL); in berlin_pwm_config()
108 berlin_pwm_writel(bpc, pwm->hwpwm, duty, BERLIN_PWM_DUTY); in berlin_pwm_config()
109 berlin_pwm_writel(bpc, pwm->hwpwm, period, BERLIN_PWM_TCNT); in berlin_pwm_config()
115 struct pwm_device *pwm, in berlin_pwm_set_polarity() argument
121 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_CONTROL); in berlin_pwm_set_polarity()
128 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_CONTROL); in berlin_pwm_set_polarity()
133 static int berlin_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in berlin_pwm_enable() argument
138 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_EN); in berlin_pwm_enable()
140 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_EN); in berlin_pwm_enable()
146 struct pwm_device *pwm) in berlin_pwm_disable() argument
151 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_EN); in berlin_pwm_disable()
153 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_EN); in berlin_pwm_disable()
156 static int berlin_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in berlin_pwm_apply() argument
160 bool enabled = pwm->state.enabled; in berlin_pwm_apply()
162 if (state->polarity != pwm->state.polarity) { in berlin_pwm_apply()
164 berlin_pwm_disable(chip, pwm); in berlin_pwm_apply()
168 err = berlin_pwm_set_polarity(chip, pwm, state->polarity); in berlin_pwm_apply()
173 if (!state->enabled) { in berlin_pwm_apply()
175 berlin_pwm_disable(chip, pwm); in berlin_pwm_apply()
179 err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period); in berlin_pwm_apply()
184 return berlin_pwm_enable(chip, pwm); in berlin_pwm_apply()
194 { .compatible = "marvell,berlin-pwm" },
204 bpc = devm_kzalloc(&pdev->dev, sizeof(*bpc), GFP_KERNEL); in berlin_pwm_probe()
206 return -ENOMEM; in berlin_pwm_probe()
208 bpc->base = devm_platform_ioremap_resource(pdev, 0); in berlin_pwm_probe()
209 if (IS_ERR(bpc->base)) in berlin_pwm_probe()
210 return PTR_ERR(bpc->base); in berlin_pwm_probe()
212 bpc->clk = devm_clk_get_enabled(&pdev->dev, NULL); in berlin_pwm_probe()
213 if (IS_ERR(bpc->clk)) in berlin_pwm_probe()
214 return PTR_ERR(bpc->clk); in berlin_pwm_probe()
216 bpc->chip.dev = &pdev->dev; in berlin_pwm_probe()
217 bpc->chip.ops = &berlin_pwm_ops; in berlin_pwm_probe()
218 bpc->chip.npwm = BERLIN_PWM_NUMPWMS; in berlin_pwm_probe()
220 ret = devm_pwmchip_add(&pdev->dev, &bpc->chip); in berlin_pwm_probe()
222 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); in berlin_pwm_probe()
234 for (i = 0; i < bpc->chip.npwm; i++) { in berlin_pwm_suspend()
235 struct berlin_pwm_channel *channel = &bpc->channel[i]; in berlin_pwm_suspend()
237 channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE); in berlin_pwm_suspend()
238 channel->ctrl = berlin_pwm_readl(bpc, i, BERLIN_PWM_CONTROL); in berlin_pwm_suspend()
239 channel->duty = berlin_pwm_readl(bpc, i, BERLIN_PWM_DUTY); in berlin_pwm_suspend()
240 channel->tcnt = berlin_pwm_readl(bpc, i, BERLIN_PWM_TCNT); in berlin_pwm_suspend()
243 clk_disable_unprepare(bpc->clk); in berlin_pwm_suspend()
254 ret = clk_prepare_enable(bpc->clk); in berlin_pwm_resume()
258 for (i = 0; i < bpc->chip.npwm; i++) { in berlin_pwm_resume()
259 struct berlin_pwm_channel *channel = &bpc->channel[i]; in berlin_pwm_resume()
261 berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL); in berlin_pwm_resume()
262 berlin_pwm_writel(bpc, i, channel->duty, BERLIN_PWM_DUTY); in berlin_pwm_resume()
263 berlin_pwm_writel(bpc, i, channel->tcnt, BERLIN_PWM_TCNT); in berlin_pwm_resume()
264 berlin_pwm_writel(bpc, i, channel->enable, BERLIN_PWM_ENABLE); in berlin_pwm_resume()
276 .name = "berlin-pwm",
283 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
284 MODULE_DESCRIPTION("Marvell Berlin PWM driver");