Lines Matching +full:pwm +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Keem Bay PWM driver
10 * - Upon disabling a channel, the currently running
22 #include <linux/pwm.h>
34 /* PWM Register offset */
71 u32 val, u32 offset) in keembay_pwm_update_bits() argument
73 u32 buff = readl(priv->base + offset); in keembay_pwm_update_bits()
76 writel(buff, priv->base + offset); in keembay_pwm_update_bits()
91 static int keembay_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, in keembay_pwm_get_state() argument
99 clk_rate = clk_get_rate(priv->clk); in keembay_pwm_get_state()
102 highlow = readl(priv->base + KMB_PWM_LEADIN_OFFSET(pwm->hwpwm)); in keembay_pwm_get_state()
104 state->enabled = true; in keembay_pwm_get_state()
106 state->enabled = false; in keembay_pwm_get_state()
109 highlow = readl(priv->base + KMB_PWM_HIGHLOW_OFFSET(pwm->hwpwm)); in keembay_pwm_get_state()
112 state->duty_cycle = DIV_ROUND_UP_ULL(high, clk_rate); in keembay_pwm_get_state()
113 state->period = DIV_ROUND_UP_ULL(high + low, clk_rate); in keembay_pwm_get_state()
114 state->polarity = PWM_POLARITY_NORMAL; in keembay_pwm_get_state()
119 static int keembay_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in keembay_pwm_apply() argument
129 if (state->polarity != PWM_POLARITY_NORMAL) in keembay_pwm_apply()
130 return -EINVAL; in keembay_pwm_apply()
133 * Configure the pwm repeat count as infinite at (15:0) and leadin in keembay_pwm_apply()
137 KMB_PWM_LEADIN_OFFSET(pwm->hwpwm)); in keembay_pwm_apply()
139 keembay_pwm_get_state(chip, pwm, ¤t_state); in keembay_pwm_apply()
141 if (!state->enabled) { in keembay_pwm_apply()
143 keembay_pwm_disable(priv, pwm->hwpwm); in keembay_pwm_apply()
153 clk_rate = clk_get_rate(priv->clk); in keembay_pwm_apply()
154 div = clk_rate * state->duty_cycle; in keembay_pwm_apply()
157 return -ERANGE; in keembay_pwm_apply()
160 div = clk_rate * state->period; in keembay_pwm_apply()
162 div = div - high; in keembay_pwm_apply()
164 return -ERANGE; in keembay_pwm_apply()
171 writel(pwm_count, priv->base + KMB_PWM_HIGHLOW_OFFSET(pwm->hwpwm)); in keembay_pwm_apply()
173 if (state->enabled && !current_state.enabled) in keembay_pwm_apply()
174 keembay_pwm_enable(priv, pwm->hwpwm); in keembay_pwm_apply()
186 struct device *dev = &pdev->dev; in keembay_pwm_probe()
196 priv->clk = devm_clk_get(dev, NULL); in keembay_pwm_probe()
197 if (IS_ERR(priv->clk)) in keembay_pwm_probe()
198 return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get clock\n"); in keembay_pwm_probe()
200 priv->base = devm_platform_ioremap_resource(pdev, 0); in keembay_pwm_probe()
201 if (IS_ERR(priv->base)) in keembay_pwm_probe()
202 return PTR_ERR(priv->base); in keembay_pwm_probe()
204 ret = keembay_clk_enable(dev, priv->clk); in keembay_pwm_probe()
208 chip->ops = &keembay_pwm_ops; in keembay_pwm_probe()
212 return dev_err_probe(dev, ret, "Failed to add PWM chip\n"); in keembay_pwm_probe()
218 { .compatible = "intel,keembay-pwm" },
226 .name = "pwm-keembay",
232 MODULE_ALIAS("platform:pwm-keembay");
233 MODULE_DESCRIPTION("Intel Keem Bay PWM driver");