Lines Matching +full:clk +full:- +full:pwm
12 #include <linux/clk.h>
21 #include <linux/pwm.h>
27 /* PWM registers and bits definitions */
47 * struct spear_pwm_chip - struct representing pwm chip
49 * @mmio_base: base address of pwm chip
50 * @clk: pointer to clk structure of pwm chip
54 struct clk *clk; member
65 return readl_relaxed(chip->mmio_base + (num << 4) + offset); in spear_pwm_readl()
72 writel_relaxed(val, chip->mmio_base + (num << 4) + offset); in spear_pwm_writel()
75 static int spear_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in spear_pwm_config() argument
93 clk_rate = clk_get_rate(pc->clk); in spear_pwm_config()
104 return -EINVAL; in spear_pwm_config()
112 return -EINVAL; in spear_pwm_config()
119 * NOTE: the clock to PWM has to be enabled first before writing to the in spear_pwm_config()
122 ret = clk_enable(pc->clk); in spear_pwm_config()
126 spear_pwm_writel(pc, pwm->hwpwm, PWMCR, in spear_pwm_config()
128 spear_pwm_writel(pc, pwm->hwpwm, PWMDCR, dc); in spear_pwm_config()
129 spear_pwm_writel(pc, pwm->hwpwm, PWMPCR, pv); in spear_pwm_config()
130 clk_disable(pc->clk); in spear_pwm_config()
135 static int spear_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in spear_pwm_enable() argument
141 rc = clk_enable(pc->clk); in spear_pwm_enable()
145 val = spear_pwm_readl(pc, pwm->hwpwm, PWMCR); in spear_pwm_enable()
147 spear_pwm_writel(pc, pwm->hwpwm, PWMCR, val); in spear_pwm_enable()
152 static void spear_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in spear_pwm_disable() argument
157 val = spear_pwm_readl(pc, pwm->hwpwm, PWMCR); in spear_pwm_disable()
159 spear_pwm_writel(pc, pwm->hwpwm, PWMCR, val); in spear_pwm_disable()
161 clk_disable(pc->clk); in spear_pwm_disable()
164 static int spear_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in spear_pwm_apply() argument
169 if (state->polarity != PWM_POLARITY_NORMAL) in spear_pwm_apply()
170 return -EINVAL; in spear_pwm_apply()
172 if (!state->enabled) { in spear_pwm_apply()
173 if (pwm->state.enabled) in spear_pwm_apply()
174 spear_pwm_disable(chip, pwm); in spear_pwm_apply()
178 err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period); in spear_pwm_apply()
182 if (!pwm->state.enabled) in spear_pwm_apply()
183 return spear_pwm_enable(chip, pwm); in spear_pwm_apply()
194 struct device_node *np = pdev->dev.of_node; in spear_pwm_probe()
200 chip = devm_pwmchip_alloc(&pdev->dev, NUM_PWM, sizeof(*pc)); in spear_pwm_probe()
205 pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); in spear_pwm_probe()
206 if (IS_ERR(pc->mmio_base)) in spear_pwm_probe()
207 return PTR_ERR(pc->mmio_base); in spear_pwm_probe()
209 pc->clk = devm_clk_get_prepared(&pdev->dev, NULL); in spear_pwm_probe()
210 if (IS_ERR(pc->clk)) in spear_pwm_probe()
211 return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk), in spear_pwm_probe()
214 chip->ops = &spear_pwm_ops; in spear_pwm_probe()
216 if (of_device_is_compatible(np, "st,spear1340-pwm")) { in spear_pwm_probe()
217 ret = clk_enable(pc->clk); in spear_pwm_probe()
219 return dev_err_probe(&pdev->dev, ret, in spear_pwm_probe()
220 "Failed to enable clk\n"); in spear_pwm_probe()
223 * Following enables PWM chip, channels would still be in spear_pwm_probe()
226 val = readl_relaxed(pc->mmio_base + PWMMCR); in spear_pwm_probe()
228 writel_relaxed(val, pc->mmio_base + PWMMCR); in spear_pwm_probe()
230 clk_disable(pc->clk); in spear_pwm_probe()
233 ret = devm_pwmchip_add(&pdev->dev, chip); in spear_pwm_probe()
235 return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); in spear_pwm_probe()
241 { .compatible = "st,spear320-pwm" },
242 { .compatible = "st,spear1340-pwm" },
250 .name = "spear-pwm",
262 MODULE_ALIAS("platform:spear-pwm");