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.
61 unsigned int offset) in brcmstb_pwm_readl() argument
64 return __raw_readl(p->base + offset); in brcmstb_pwm_readl()
66 return readl_relaxed(p->base + offset); in brcmstb_pwm_readl()
70 unsigned int offset) in brcmstb_pwm_writel() argument
73 __raw_writel(value, p->base + offset); in brcmstb_pwm_writel()
75 writel_relaxed(value, p->base + offset); in brcmstb_pwm_writel()
87 * W = cword, if cword < 2 ^ 15 else 16-bit 2's complement of cword
89 * Fv = W x 2 ^ -16 x 27Mhz (reference clock)
93 * The PWM core framework specifies that the "duty_ns" parameter is in fact the
96 static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in brcmstb_pwm_config() argument
101 unsigned int channel = pwm->hwpwm; in brcmstb_pwm_config()
111 pc = PWM_ON_PERIOD_MAX - 1; in brcmstb_pwm_config()
122 rate = (u64)clk_get_rate(p->clk) * (u64)cword; in brcmstb_pwm_config()
133 return -EINVAL; in brcmstb_pwm_config()
152 return -EINVAL; in brcmstb_pwm_config()
195 static int brcmstb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in brcmstb_pwm_apply() argument
201 if (state->polarity != PWM_POLARITY_NORMAL) in brcmstb_pwm_apply()
202 return -EINVAL; in brcmstb_pwm_apply()
204 if (!state->enabled) { in brcmstb_pwm_apply()
205 if (pwm->state.enabled) in brcmstb_pwm_apply()
206 brcmstb_pwm_enable_set(p, pwm->hwpwm, false); in brcmstb_pwm_apply()
211 err = brcmstb_pwm_config(chip, pwm, state->duty_cycle, state->period); in brcmstb_pwm_apply()
215 if (!pwm->state.enabled) in brcmstb_pwm_apply()
216 brcmstb_pwm_enable_set(p, pwm->hwpwm, true); in brcmstb_pwm_apply()
226 { .compatible = "brcm,bcm7038-pwm", },
236 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); in brcmstb_pwm_probe()
238 return -ENOMEM; in brcmstb_pwm_probe()
240 p->clk = devm_clk_get_enabled(&pdev->dev, NULL); in brcmstb_pwm_probe()
241 if (IS_ERR(p->clk)) in brcmstb_pwm_probe()
242 return dev_err_probe(&pdev->dev, PTR_ERR(p->clk), in brcmstb_pwm_probe()
247 p->chip.dev = &pdev->dev; in brcmstb_pwm_probe()
248 p->chip.ops = &brcmstb_pwm_ops; in brcmstb_pwm_probe()
249 p->chip.npwm = 2; in brcmstb_pwm_probe()
251 p->base = devm_platform_ioremap_resource(pdev, 0); in brcmstb_pwm_probe()
252 if (IS_ERR(p->base)) in brcmstb_pwm_probe()
253 return PTR_ERR(p->base); in brcmstb_pwm_probe()
255 ret = devm_pwmchip_add(&pdev->dev, &p->chip); in brcmstb_pwm_probe()
257 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); in brcmstb_pwm_probe()
266 clk_disable_unprepare(p->clk); in brcmstb_pwm_suspend()
275 return clk_prepare_enable(p->clk); in brcmstb_pwm_resume()
284 .name = "pwm-brcmstb",
292 MODULE_DESCRIPTION("Broadcom STB PWM driver");
293 MODULE_ALIAS("platform:pwm-brcmstb");