Lines Matching +full:output +full:- +full:polarity +full:- +full:invert

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
7 * - The .apply callback doesn't complete the currently running period before
15 #include <linux/mfd/ingenic-tcu.h>
40 u32 pwm_channels_mask = GENMASK(chip->npwm - 1, 2); in jz4740_pwm_can_use_chn()
42 device_property_read_u32(pwmchip_parent(chip)->parent, in jz4740_pwm_can_use_chn()
43 "ingenic,pwm-channels-mask", in jz4740_pwm_can_use_chn()
56 if (!jz4740_pwm_can_use_chn(chip, pwm->hwpwm)) in jz4740_pwm_request()
57 return -EBUSY; in jz4740_pwm_request()
59 snprintf(name, sizeof(name), "timer%u", pwm->hwpwm); in jz4740_pwm_request()
74 jz->clk[pwm->hwpwm] = clk; in jz4740_pwm_request()
82 struct clk *clk = jz->clk[pwm->hwpwm]; in jz4740_pwm_free()
92 /* Enable PWM output */ in jz4740_pwm_enable()
93 regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), TCU_TCSR_PWM_EN); in jz4740_pwm_enable()
96 regmap_write(jz->map, TCU_REG_TESR, BIT(pwm->hwpwm)); in jz4740_pwm_enable()
109 regmap_write(jz->map, TCU_REG_TDHRc(pwm->hwpwm), 0xffff); in jz4740_pwm_disable()
110 regmap_write(jz->map, TCU_REG_TDFRc(pwm->hwpwm), 0x0); in jz4740_pwm_disable()
113 * Disable PWM output. in jz4740_pwm_disable()
117 regmap_clear_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), TCU_TCSR_PWM_EN); in jz4740_pwm_disable()
120 regmap_write(jz->map, TCU_REG_TECR, BIT(pwm->hwpwm)); in jz4740_pwm_disable()
128 struct clk *clk = jz->clk[pwm->hwpwm]; in jz4740_pwm_apply()
137 do_div(tmp, state->period); in jz4740_pwm_apply()
141 * ------------------- in jz4740_pwm_apply()
147 * round-down function (and won't have one for a while), but if it ever in jz4740_pwm_apply()
148 * comes to light, a round-down function should be used instead. in jz4740_pwm_apply()
157 tmp = (unsigned long long)rate * state->period; in jz4740_pwm_apply()
162 tmp = (unsigned long long)rate * state->duty_cycle; in jz4740_pwm_apply()
167 duty = period - 1; in jz4740_pwm_apply()
178 regmap_write(jz->map, TCU_REG_TCNTc(pwm->hwpwm), 0); in jz4740_pwm_apply()
181 regmap_write(jz->map, TCU_REG_TDHRc(pwm->hwpwm), duty); in jz4740_pwm_apply()
184 regmap_write(jz->map, TCU_REG_TDFRc(pwm->hwpwm), period); in jz4740_pwm_apply()
187 regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), in jz4740_pwm_apply()
191 * Set polarity. in jz4740_pwm_apply()
195 * value. In theory, we should then use (period - duty) as the real duty in jz4740_pwm_apply()
199 * Here, we don't do that, and instead invert the polarity of the PWM in jz4740_pwm_apply()
203 if ((state->polarity == PWM_POLARITY_NORMAL) ^ state->enabled) in jz4740_pwm_apply()
204 regmap_clear_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), in jz4740_pwm_apply()
207 regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), in jz4740_pwm_apply()
210 if (state->enabled) in jz4740_pwm_apply()
224 struct device *dev = &pdev->dev; in jz4740_pwm_probe()
231 return -EINVAL; in jz4740_pwm_probe()
233 chip = devm_pwmchip_alloc(dev, info->num_pwms, struct_size(jz, clk, info->num_pwms)); in jz4740_pwm_probe()
238 jz->map = device_node_to_regmap(dev->parent->of_node); in jz4740_pwm_probe()
239 if (IS_ERR(jz->map)) { in jz4740_pwm_probe()
240 dev_err(dev, "regmap not found: %ld\n", PTR_ERR(jz->map)); in jz4740_pwm_probe()
241 return PTR_ERR(jz->map); in jz4740_pwm_probe()
244 chip->ops = &jz4740_pwm_ops; in jz4740_pwm_probe()
262 { .compatible = "ingenic,jz4740-pwm", .data = &jz4740_soc_info },
263 { .compatible = "ingenic,jz4725b-pwm", .data = &jz4725b_soc_info },
264 { .compatible = "ingenic,x1000-pwm", .data = &x1000_soc_info },
271 .name = "jz4740-pwm",
278 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
280 MODULE_ALIAS("platform:jz4740-pwm");