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 */
43 ret = clk_prepare_enable(imx->clk_ipg); in pwm_imx1_clk_prepare_enable()
47 ret = clk_prepare_enable(imx->clk_per); in pwm_imx1_clk_prepare_enable()
49 clk_disable_unprepare(imx->clk_ipg); in pwm_imx1_clk_prepare_enable()
60 clk_disable_unprepare(imx->clk_per); in pwm_imx1_clk_disable_unprepare()
61 clk_disable_unprepare(imx->clk_ipg); in pwm_imx1_clk_disable_unprepare()
65 struct pwm_device *pwm, u64 duty_ns, u64 period_ns) in pwm_imx1_config() argument
71 * The PWM subsystem allows for exact frequencies. However, in pwm_imx1_config()
72 * I cannot connect a scope on my device to the PWM line and in pwm_imx1_config()
73 * thus cannot provide the program the PWM controller in pwm_imx1_config()
75 * Bootloader (u-boot or WinCE+haret) has programmed the PWM in pwm_imx1_config()
76 * function group already. So I'll just modify the PWM sample in pwm_imx1_config()
87 max = readl(imx->mmio_base + MX1_PWMP); in pwm_imx1_config()
90 writel(max - p, imx->mmio_base + MX1_PWMS); in pwm_imx1_config()
95 static int pwm_imx1_enable(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_imx1_enable() argument
105 value = readl(imx->mmio_base + MX1_PWMC); in pwm_imx1_enable()
107 writel(value, imx->mmio_base + MX1_PWMC); in pwm_imx1_enable()
112 static void pwm_imx1_disable(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_imx1_disable() argument
117 value = readl(imx->mmio_base + MX1_PWMC); in pwm_imx1_disable()
119 writel(value, imx->mmio_base + MX1_PWMC); in pwm_imx1_disable()
124 static int pwm_imx1_apply(struct pwm_chip *chip, struct pwm_device *pwm, in pwm_imx1_apply() argument
129 if (state->polarity != PWM_POLARITY_NORMAL) in pwm_imx1_apply()
130 return -EINVAL; in pwm_imx1_apply()
132 if (!state->enabled) { in pwm_imx1_apply()
133 if (pwm->state.enabled) in pwm_imx1_apply()
134 pwm_imx1_disable(chip, pwm); in pwm_imx1_apply()
139 err = pwm_imx1_config(chip, pwm, state->duty_cycle, state->period); in pwm_imx1_apply()
143 if (!pwm->state.enabled) in pwm_imx1_apply()
144 return pwm_imx1_enable(chip, pwm); in pwm_imx1_apply()
154 { .compatible = "fsl,imx1-pwm", },
164 chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx)); in pwm_imx1_probe()
169 imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in pwm_imx1_probe()
170 if (IS_ERR(imx->clk_ipg)) in pwm_imx1_probe()
171 return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_ipg), in pwm_imx1_probe()
174 imx->clk_per = devm_clk_get(&pdev->dev, "per"); in pwm_imx1_probe()
175 if (IS_ERR(imx->clk_per)) in pwm_imx1_probe()
176 return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), in pwm_imx1_probe()
179 chip->ops = &pwm_imx1_ops; in pwm_imx1_probe()
181 imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); in pwm_imx1_probe()
182 if (IS_ERR(imx->mmio_base)) in pwm_imx1_probe()
183 return PTR_ERR(imx->mmio_base); in pwm_imx1_probe()
185 return devm_pwmchip_add(&pdev->dev, chip); in pwm_imx1_probe()
190 .name = "pwm-imx1",