Lines Matching +full:pwm +full:- +full:offset
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>
51 unsigned int offset) in rcar_pwm_write() argument
53 writel(data, rp->base + offset); in rcar_pwm_write()
56 static u32 rcar_pwm_read(struct rcar_pwm_chip *rp, unsigned int offset) in rcar_pwm_read() argument
58 return readl(rp->base + offset); in rcar_pwm_read()
62 unsigned int offset) in rcar_pwm_update() argument
66 value = rcar_pwm_read(rp, offset); in rcar_pwm_update()
69 rcar_pwm_write(rp, value, offset); in rcar_pwm_update()
74 unsigned long clk_rate = clk_get_rate(rp->clk); in rcar_pwm_get_clock_division()
78 return -EINVAL; in rcar_pwm_get_clock_division()
81 tmp = (u64)period_ns * clk_rate + div - 1; in rcar_pwm_get_clock_division()
83 div = ilog2(tmp - 1) + 1; in rcar_pwm_get_clock_division()
85 return (div <= RCAR_PWM_MAX_DIVISION) ? div : -ERANGE; in rcar_pwm_get_clock_division()
109 unsigned long clk_rate = clk_get_rate(rp->clk); in rcar_pwm_set_counter()
125 return -EINVAL; in rcar_pwm_set_counter()
132 static int rcar_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) in rcar_pwm_request() argument
137 static void rcar_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) in rcar_pwm_free() argument
146 /* Don't enable the PWM device if CYC0 or PH0 is 0 */ in rcar_pwm_enable()
150 return -EINVAL; in rcar_pwm_enable()
162 static int rcar_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in rcar_pwm_apply() argument
169 if (state->polarity != PWM_POLARITY_NORMAL) in rcar_pwm_apply()
170 return -EINVAL; in rcar_pwm_apply()
172 if (!state->enabled) { in rcar_pwm_apply()
177 div = rcar_pwm_get_clock_division(rp, state->period); in rcar_pwm_apply()
183 ret = rcar_pwm_set_counter(rp, div, state->duty_cycle, state->period); in rcar_pwm_apply()
208 chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*rcar_pwm)); 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()
223 chip->ops = &rcar_pwm_ops; in rcar_pwm_probe()
227 pm_runtime_enable(&pdev->dev); in rcar_pwm_probe()
231 dev_err(&pdev->dev, "failed to register PWM chip: %d\n", ret); in rcar_pwm_probe()
232 pm_runtime_disable(&pdev->dev); in rcar_pwm_probe()
245 pm_runtime_disable(&pdev->dev); in rcar_pwm_remove()
249 { .compatible = "renesas,pwm-rcar", },
258 .name = "pwm-rcar",
265 MODULE_DESCRIPTION("Renesas PWM Timer Driver");
267 MODULE_ALIAS("platform:pwm-rcar");