Lines Matching +full:pwm +full:- +full:rcar

1 // SPDX-License-Identifier: GPL-2.0
3 * R-Car PWM Timer driver
8 * - The hardware cannot generate a 0% duty cycle.
20 #include <linux/pwm.h>
54 writel(data, rp->base + offset); in rcar_pwm_write()
59 return readl(rp->base + offset); in rcar_pwm_read()
75 unsigned long clk_rate = clk_get_rate(rp->clk); in rcar_pwm_get_clock_division()
79 return -EINVAL; in rcar_pwm_get_clock_division()
82 tmp = (u64)period_ns * clk_rate + div - 1; in rcar_pwm_get_clock_division()
84 div = ilog2(tmp - 1) + 1; in rcar_pwm_get_clock_division()
86 return (div <= RCAR_PWM_MAX_DIVISION) ? div : -ERANGE; in rcar_pwm_get_clock_division()
110 unsigned long clk_rate = clk_get_rate(rp->clk); in rcar_pwm_set_counter()
126 return -EINVAL; in rcar_pwm_set_counter()
133 static int rcar_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) in rcar_pwm_request() argument
135 return pm_runtime_get_sync(chip->dev); in rcar_pwm_request()
138 static void rcar_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) in rcar_pwm_free() argument
140 pm_runtime_put(chip->dev); in rcar_pwm_free()
147 /* Don't enable the PWM device if CYC0 or PH0 is 0 */ in rcar_pwm_enable()
151 return -EINVAL; in rcar_pwm_enable()
163 static int rcar_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in rcar_pwm_apply() argument
170 if (state->polarity != PWM_POLARITY_NORMAL) in rcar_pwm_apply()
171 return -EINVAL; in rcar_pwm_apply()
173 if (!state->enabled) { in rcar_pwm_apply()
178 div = rcar_pwm_get_clock_division(rp, state->period); in rcar_pwm_apply()
184 ret = rcar_pwm_set_counter(rp, div, state->duty_cycle, state->period); in rcar_pwm_apply()
209 rcar_pwm = devm_kzalloc(&pdev->dev, sizeof(*rcar_pwm), GFP_KERNEL); in rcar_pwm_probe()
211 return -ENOMEM; in rcar_pwm_probe()
213 rcar_pwm->base = devm_platform_ioremap_resource(pdev, 0); in rcar_pwm_probe()
214 if (IS_ERR(rcar_pwm->base)) in rcar_pwm_probe()
215 return PTR_ERR(rcar_pwm->base); in rcar_pwm_probe()
217 rcar_pwm->clk = devm_clk_get(&pdev->dev, NULL); in rcar_pwm_probe()
218 if (IS_ERR(rcar_pwm->clk)) { in rcar_pwm_probe()
219 dev_err(&pdev->dev, "cannot get clock\n"); in rcar_pwm_probe()
220 return PTR_ERR(rcar_pwm->clk); in rcar_pwm_probe()
225 rcar_pwm->chip.dev = &pdev->dev; in rcar_pwm_probe()
226 rcar_pwm->chip.ops = &rcar_pwm_ops; in rcar_pwm_probe()
227 rcar_pwm->chip.npwm = 1; in rcar_pwm_probe()
229 pm_runtime_enable(&pdev->dev); in rcar_pwm_probe()
231 ret = pwmchip_add(&rcar_pwm->chip); in rcar_pwm_probe()
233 dev_err(&pdev->dev, "failed to register PWM chip: %d\n", ret); in rcar_pwm_probe()
234 pm_runtime_disable(&pdev->dev); in rcar_pwm_probe()
245 pwmchip_remove(&rcar_pwm->chip); in rcar_pwm_remove()
247 pm_runtime_disable(&pdev->dev); in rcar_pwm_remove()
253 { .compatible = "renesas,pwm-rcar", },
262 .name = "pwm-rcar",
269 MODULE_DESCRIPTION("Renesas PWM Timer Driver");
271 MODULE_ALIAS("platform:pwm-rcar");