Lines Matching +full:- +full:pwm
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
18 #include <linux/pwm.h>
26 /* PWM has_secondary_pwm? */
27 { "pxa25x-pwm", 0 },
28 { "pxa27x-pwm", HAS_SECONDARY_PWM },
29 { "pxa168-pwm", 0 },
30 { "pxa910-pwm", 0 },
35 /* PWM registers and bits definitions */
60 static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in pxa_pwm_config() argument
69 offset = pwm->hwpwm ? 0x10 : 0; in pxa_pwm_config()
71 c = clk_get_rate(pc->clk); in pxa_pwm_config()
78 prescale = (period_cycles - 1) / 1024; in pxa_pwm_config()
79 pv = period_cycles / (prescale + 1) - 1; in pxa_pwm_config()
82 return -EINVAL; in pxa_pwm_config()
89 /* NOTE: the clock to PWM has to be enabled first in pxa_pwm_config()
92 rc = clk_prepare_enable(pc->clk); in pxa_pwm_config()
96 writel(prescale, pc->mmio_base + offset + PWMCR); in pxa_pwm_config()
97 writel(dc, pc->mmio_base + offset + PWMDCR); in pxa_pwm_config()
98 writel(pv, pc->mmio_base + offset + PWMPCR); in pxa_pwm_config()
100 clk_disable_unprepare(pc->clk); in pxa_pwm_config()
104 static int pxa_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in pxa_pwm_enable() argument
108 return clk_prepare_enable(pc->clk); in pxa_pwm_enable()
111 static void pxa_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in pxa_pwm_disable() argument
115 clk_disable_unprepare(pc->clk); in pxa_pwm_disable()
127 * Device tree users must create one device instance for each PWM channel.
129 * code that this is a single channel pxa25x-pwm. Currently all devices are
133 { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]},
134 { .compatible = "marvell,pxa270-pwm", .data = &pwm_id_table[0]},
135 { .compatible = "marvell,pxa168-pwm", .data = &pwm_id_table[0]},
136 { .compatible = "marvell,pxa910-pwm", .data = &pwm_id_table[0]},
148 return id ? id->data : NULL; in pxa_pwm_get_id_dt()
154 struct pwm_device *pwm; in pxa_pwm_of_xlate() local
156 pwm = pwm_request_from_chip(pc, 0, NULL); in pxa_pwm_of_xlate()
157 if (IS_ERR(pwm)) in pxa_pwm_of_xlate()
158 return pwm; in pxa_pwm_of_xlate()
160 pwm->args.period = args->args[0]; in pxa_pwm_of_xlate()
162 return pwm; in pxa_pwm_of_xlate()
168 struct pxa_pwm_chip *pwm; in pwm_probe() local
173 id = pxa_pwm_get_id_dt(&pdev->dev); in pwm_probe()
176 return -EINVAL; in pwm_probe()
178 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); in pwm_probe()
179 if (pwm == NULL) in pwm_probe()
180 return -ENOMEM; in pwm_probe()
182 pwm->clk = devm_clk_get(&pdev->dev, NULL); in pwm_probe()
183 if (IS_ERR(pwm->clk)) in pwm_probe()
184 return PTR_ERR(pwm->clk); in pwm_probe()
186 pwm->chip.dev = &pdev->dev; in pwm_probe()
187 pwm->chip.ops = &pxa_pwm_ops; in pwm_probe()
188 pwm->chip.base = -1; in pwm_probe()
189 pwm->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1; in pwm_probe()
192 pwm->chip.of_xlate = pxa_pwm_of_xlate; in pwm_probe()
193 pwm->chip.of_pwm_n_cells = 1; in pwm_probe()
197 pwm->mmio_base = devm_ioremap_resource(&pdev->dev, r); in pwm_probe()
198 if (IS_ERR(pwm->mmio_base)) in pwm_probe()
199 return PTR_ERR(pwm->mmio_base); in pwm_probe()
201 ret = pwmchip_add(&pwm->chip); in pwm_probe()
203 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); in pwm_probe()
207 platform_set_drvdata(pdev, pwm); in pwm_probe()
217 return -ENODEV; in pwm_remove()
219 return pwmchip_remove(&chip->chip); in pwm_remove()
224 .name = "pxa25x-pwm",