Lines Matching +full:imx1 +full:- +full:pwm

1 // SPDX-License-Identifier: GPL-2.0
3 * simple driver for PWM (Pulse Width Modulator) controller
5 * Derived from pxa PWM driver by eric miao <eric.miao@marvell.com>
18 #include <linux/pwm.h>
21 #define MX1_PWMC 0x00 /* PWM Control Register */
22 #define MX1_PWMS 0x04 /* PWM Sample Register */
23 #define MX1_PWMP 0x08 /* PWM Period Register */
41 ret = clk_prepare_enable(imx->clk_ipg); in pwm_imx1_clk_prepare_enable()
45 ret = clk_prepare_enable(imx->clk_per); in pwm_imx1_clk_prepare_enable()
47 clk_disable_unprepare(imx->clk_ipg); in pwm_imx1_clk_prepare_enable()
58 clk_disable_unprepare(imx->clk_per); in pwm_imx1_clk_disable_unprepare()
59 clk_disable_unprepare(imx->clk_ipg); in pwm_imx1_clk_disable_unprepare()
63 struct pwm_device *pwm, u64 duty_ns, u64 period_ns) in pwm_imx1_config() argument
69 * The PWM subsystem allows for exact frequencies. However, in pwm_imx1_config()
70 * I cannot connect a scope on my device to the PWM line and in pwm_imx1_config()
71 * thus cannot provide the program the PWM controller in pwm_imx1_config()
73 * Bootloader (u-boot or WinCE+haret) has programmed the PWM in pwm_imx1_config()
74 * function group already. So I'll just modify the PWM sample in pwm_imx1_config()
85 max = readl(imx->mmio_base + MX1_PWMP); in pwm_imx1_config()
88 writel(max - p, imx->mmio_base + MX1_PWMS); in pwm_imx1_config()
93 static int pwm_imx1_enable(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_imx1_enable() argument
103 value = readl(imx->mmio_base + MX1_PWMC); in pwm_imx1_enable()
105 writel(value, imx->mmio_base + MX1_PWMC); in pwm_imx1_enable()
110 static void pwm_imx1_disable(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_imx1_disable() argument
115 value = readl(imx->mmio_base + MX1_PWMC); in pwm_imx1_disable()
117 writel(value, imx->mmio_base + MX1_PWMC); in pwm_imx1_disable()
122 static int pwm_imx1_apply(struct pwm_chip *chip, struct pwm_device *pwm, in pwm_imx1_apply() argument
127 if (state->polarity != PWM_POLARITY_NORMAL) in pwm_imx1_apply()
128 return -EINVAL; in pwm_imx1_apply()
130 if (!state->enabled) { in pwm_imx1_apply()
131 if (pwm->state.enabled) in pwm_imx1_apply()
132 pwm_imx1_disable(chip, pwm); in pwm_imx1_apply()
137 err = pwm_imx1_config(chip, pwm, state->duty_cycle, state->period); in pwm_imx1_apply()
141 if (!pwm->state.enabled) in pwm_imx1_apply()
142 return pwm_imx1_enable(chip, pwm); in pwm_imx1_apply()
152 { .compatible = "fsl,imx1-pwm", },
161 imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); in pwm_imx1_probe()
163 return -ENOMEM; in pwm_imx1_probe()
165 imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in pwm_imx1_probe()
166 if (IS_ERR(imx->clk_ipg)) in pwm_imx1_probe()
167 return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_ipg), in pwm_imx1_probe()
170 imx->clk_per = devm_clk_get(&pdev->dev, "per"); in pwm_imx1_probe()
171 if (IS_ERR(imx->clk_per)) in pwm_imx1_probe()
172 return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), in pwm_imx1_probe()
175 imx->chip.ops = &pwm_imx1_ops; in pwm_imx1_probe()
176 imx->chip.dev = &pdev->dev; in pwm_imx1_probe()
177 imx->chip.npwm = 1; in pwm_imx1_probe()
179 imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); in pwm_imx1_probe()
180 if (IS_ERR(imx->mmio_base)) in pwm_imx1_probe()
181 return PTR_ERR(imx->mmio_base); in pwm_imx1_probe()
183 return devm_pwmchip_add(&pdev->dev, &imx->chip); in pwm_imx1_probe()
188 .name = "pwm-imx1",