Lines Matching +full:pwm +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/pwm/pwm-pxa.c
5 * simple driver for PWM (Pulse Width Modulator) controller
7 * 2008-02-13 initial version
10 * Links to reference manuals for some of the supported PWM chips can be found
14 * - When PWM is stopped, the current PWM period stops abruptly at the next
26 #include <linux/pwm.h>
34 /* PWM has_secondary_pwm? */
35 { "pxa25x-pwm", 0 },
36 { "pxa27x-pwm", HAS_SECONDARY_PWM },
37 { "pxa168-pwm", 0 },
38 { "pxa910-pwm", 0 },
43 /* PWM registers and bits definitions */
67 static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in pxa_pwm_config() argument
73 unsigned long offset; in pxa_pwm_config() local
75 offset = pwm->hwpwm ? 0x10 : 0; in pxa_pwm_config()
77 c = clk_get_rate(pc->clk); in pxa_pwm_config()
84 prescale = (period_cycles - 1) / 1024; in pxa_pwm_config()
85 pv = period_cycles / (prescale + 1) - 1; in pxa_pwm_config()
88 return -EINVAL; in pxa_pwm_config()
95 writel(prescale | PWMCR_SD, pc->mmio_base + offset + PWMCR); in pxa_pwm_config()
96 writel(dc, pc->mmio_base + offset + PWMDCR); in pxa_pwm_config()
97 writel(pv, pc->mmio_base + offset + PWMPCR); in pxa_pwm_config()
102 static int pxa_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in pxa_pwm_apply() argument
109 if (state->polarity != PWM_POLARITY_NORMAL) in pxa_pwm_apply()
110 return -EINVAL; in pxa_pwm_apply()
112 err = clk_prepare_enable(pc->clk); in pxa_pwm_apply()
116 duty_cycle = state->enabled ? state->duty_cycle : 0; in pxa_pwm_apply()
118 err = pxa_pwm_config(chip, pwm, duty_cycle, state->period); in pxa_pwm_apply()
120 clk_disable_unprepare(pc->clk); in pxa_pwm_apply()
124 if (state->enabled && !pwm->state.enabled) in pxa_pwm_apply()
127 clk_disable_unprepare(pc->clk); in pxa_pwm_apply()
129 if (!state->enabled && pwm->state.enabled) in pxa_pwm_apply()
130 clk_disable_unprepare(pc->clk); in pxa_pwm_apply()
141 * Device tree users must create one device instance for each PWM channel.
143 * code that this is a single channel pxa25x-pwm. Currently all devices are
147 { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]},
148 { .compatible = "marvell,pxa270-pwm", .data = &pwm_id_table[0]},
149 { .compatible = "marvell,pxa168-pwm", .data = &pwm_id_table[0]},
150 { .compatible = "marvell,pxa910-pwm", .data = &pwm_id_table[0]},
166 id = of_device_get_match_data(&pdev->dev); in pwm_probe()
169 return -EINVAL; in pwm_probe()
171 chip = devm_pwmchip_alloc(&pdev->dev, in pwm_probe()
172 (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1, in pwm_probe()
178 pc->clk = devm_clk_get(&pdev->dev, NULL); in pwm_probe()
179 if (IS_ERR(pc->clk)) in pwm_probe()
180 return PTR_ERR(pc->clk); in pwm_probe()
182 chip->ops = &pxa_pwm_ops; in pwm_probe()
185 chip->of_xlate = of_pwm_single_xlate; in pwm_probe()
187 pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); in pwm_probe()
188 if (IS_ERR(pc->mmio_base)) in pwm_probe()
189 return PTR_ERR(pc->mmio_base); in pwm_probe()
191 ret = devm_pwmchip_add(&pdev->dev, chip); in pwm_probe()
193 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); in pwm_probe()
202 .name = "pxa25x-pwm",