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>
63 unsigned int channel, unsigned long offset) in berlin_pwm_readl() argument
65 return readl_relaxed(bpc->base + channel * 0x10 + offset); in berlin_pwm_readl()
70 unsigned long offset) in berlin_pwm_writel() argument
72 writel_relaxed(value, bpc->base + channel * 0x10 + offset); in berlin_pwm_writel()
75 static int berlin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in berlin_pwm_config() argument
83 cycles = clk_get_rate(bpc->clk); in berlin_pwm_config()
92 return -ERANGE; in berlin_pwm_config()
100 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_CONTROL); in berlin_pwm_config()
105 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_CONTROL); in berlin_pwm_config()
107 berlin_pwm_writel(bpc, pwm->hwpwm, duty, BERLIN_PWM_DUTY); in berlin_pwm_config()
108 berlin_pwm_writel(bpc, pwm->hwpwm, period, BERLIN_PWM_TCNT); in berlin_pwm_config()
114 struct pwm_device *pwm, in berlin_pwm_set_polarity() argument
120 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_CONTROL); in berlin_pwm_set_polarity()
127 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_CONTROL); in berlin_pwm_set_polarity()
132 static int berlin_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in berlin_pwm_enable() argument
137 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_EN); in berlin_pwm_enable()
139 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_EN); in berlin_pwm_enable()
145 struct pwm_device *pwm) in berlin_pwm_disable() argument
150 value = berlin_pwm_readl(bpc, pwm->hwpwm, BERLIN_PWM_EN); in berlin_pwm_disable()
152 berlin_pwm_writel(bpc, pwm->hwpwm, value, BERLIN_PWM_EN); in berlin_pwm_disable()
155 static int berlin_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in berlin_pwm_apply() argument
159 bool enabled = pwm->state.enabled; in berlin_pwm_apply()
161 if (state->polarity != pwm->state.polarity) { in berlin_pwm_apply()
163 berlin_pwm_disable(chip, pwm); in berlin_pwm_apply()
167 err = berlin_pwm_set_polarity(chip, pwm, state->polarity); in berlin_pwm_apply()
172 if (!state->enabled) { in berlin_pwm_apply()
174 berlin_pwm_disable(chip, pwm); in berlin_pwm_apply()
178 err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period); in berlin_pwm_apply()
183 return berlin_pwm_enable(chip, pwm); in berlin_pwm_apply()
193 { .compatible = "marvell,berlin-pwm" },
204 chip = devm_pwmchip_alloc(&pdev->dev, BERLIN_PWM_NUMPWMS, sizeof(*bpc)); in berlin_pwm_probe()
209 bpc->base = devm_platform_ioremap_resource(pdev, 0); in berlin_pwm_probe()
210 if (IS_ERR(bpc->base)) in berlin_pwm_probe()
211 return PTR_ERR(bpc->base); in berlin_pwm_probe()
213 bpc->clk = devm_clk_get_enabled(&pdev->dev, NULL); in berlin_pwm_probe()
214 if (IS_ERR(bpc->clk)) in berlin_pwm_probe()
215 return PTR_ERR(bpc->clk); in berlin_pwm_probe()
217 chip->ops = &berlin_pwm_ops; in berlin_pwm_probe()
219 ret = devm_pwmchip_add(&pdev->dev, chip); in berlin_pwm_probe()
221 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); in berlin_pwm_probe()
234 for (i = 0; i < 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()
255 ret = clk_prepare_enable(bpc->clk); in berlin_pwm_resume()
259 for (i = 0; i < chip->npwm; i++) { in berlin_pwm_resume()
260 struct berlin_pwm_channel *channel = &bpc->channel[i]; in berlin_pwm_resume()
262 berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL); in berlin_pwm_resume()
263 berlin_pwm_writel(bpc, i, channel->duty, BERLIN_PWM_DUTY); in berlin_pwm_resume()
264 berlin_pwm_writel(bpc, i, channel->tcnt, BERLIN_PWM_TCNT); in berlin_pwm_resume()
265 berlin_pwm_writel(bpc, i, channel->enable, BERLIN_PWM_ENABLE); in berlin_pwm_resume()
277 .name = "berlin-pwm",
284 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
285 MODULE_DESCRIPTION("Marvell Berlin PWM driver");