Lines Matching +full:pwm +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Broadcom BCM7038 PWM driver
19 #include <linux/pwm.h>
41 * Maximum control word value allowed when variable-frequency PWM is used as a
42 * clock for the constant-frequency PMW.
60 unsigned int offset) in brcmstb_pwm_readl() argument
63 return __raw_readl(p->base + offset); in brcmstb_pwm_readl()
65 return readl_relaxed(p->base + offset); in brcmstb_pwm_readl()
69 unsigned int offset) in brcmstb_pwm_writel() argument
72 __raw_writel(value, p->base + offset); in brcmstb_pwm_writel()
74 writel_relaxed(value, p->base + offset); in brcmstb_pwm_writel()
86 * W = cword, if cword < 2 ^ 15 else 16-bit 2's complement of cword
88 * Fv = W x 2 ^ -16 x 27Mhz (reference clock)
92 * The PWM core framework specifies that the "duty_ns" parameter is in fact the
95 static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in brcmstb_pwm_config() argument
100 unsigned int channel = pwm->hwpwm; in brcmstb_pwm_config()
110 pc = PWM_ON_PERIOD_MAX - 1; in brcmstb_pwm_config()
121 rate = (u64)clk_get_rate(p->clk) * (u64)cword; in brcmstb_pwm_config()
132 return -EINVAL; in brcmstb_pwm_config()
151 return -EINVAL; in brcmstb_pwm_config()
194 static int brcmstb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in brcmstb_pwm_apply() argument
200 if (state->polarity != PWM_POLARITY_NORMAL) in brcmstb_pwm_apply()
201 return -EINVAL; in brcmstb_pwm_apply()
203 if (!state->enabled) { in brcmstb_pwm_apply()
204 if (pwm->state.enabled) in brcmstb_pwm_apply()
205 brcmstb_pwm_enable_set(p, pwm->hwpwm, false); in brcmstb_pwm_apply()
210 err = brcmstb_pwm_config(chip, pwm, state->duty_cycle, state->period); in brcmstb_pwm_apply()
214 if (!pwm->state.enabled) in brcmstb_pwm_apply()
215 brcmstb_pwm_enable_set(p, pwm->hwpwm, true); in brcmstb_pwm_apply()
225 { .compatible = "brcm,bcm7038-pwm", },
236 chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*p)); in brcmstb_pwm_probe()
241 p->clk = devm_clk_get_enabled(&pdev->dev, NULL); in brcmstb_pwm_probe()
242 if (IS_ERR(p->clk)) in brcmstb_pwm_probe()
243 return dev_err_probe(&pdev->dev, PTR_ERR(p->clk), in brcmstb_pwm_probe()
248 chip->ops = &brcmstb_pwm_ops; in brcmstb_pwm_probe()
250 p->base = devm_platform_ioremap_resource(pdev, 0); in brcmstb_pwm_probe()
251 if (IS_ERR(p->base)) in brcmstb_pwm_probe()
252 return PTR_ERR(p->base); in brcmstb_pwm_probe()
254 ret = devm_pwmchip_add(&pdev->dev, chip); in brcmstb_pwm_probe()
256 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); in brcmstb_pwm_probe()
265 clk_disable_unprepare(p->clk); in brcmstb_pwm_suspend()
274 return clk_prepare_enable(p->clk); in brcmstb_pwm_resume()
283 .name = "pwm-brcmstb",
291 MODULE_DESCRIPTION("Broadcom STB PWM driver");
292 MODULE_ALIAS("platform:pwm-brcmstb");