11 #include <linux/module.h>
12 #include <linux/kernel.h>
14 #include <linux/slab.h>
27 #define MX1_PWMC_EN (1 << 4)
31 #define MX3_PWMCR 0x00
32 #define MX3_PWMSAR 0x0C
33 #define MX3_PWMPR 0x10
34 #define MX3_PWMCR_PRESCALER(x) (((x - 1) & 0xFFF) << 4)
35 #define MX3_PWMCR_DOZEEN (1 << 24)
36 #define MX3_PWMCR_WAITEN (1 << 23)
37 #define MX3_PWMCR_DBGEN (1 << 22)
38 #define MX3_PWMCR_CLKSRC_IPG_HIGH (2 << 16)
39 #define MX3_PWMCR_CLKSRC_IPG (1 << 16)
40 #define MX3_PWMCR_EN (1 << 0)
56 #define to_imx_chip(chip) container_of(chip, struct imx_chip, chip)
81 u32 p = max * duty_ns / period_ns;
102 static int imx_pwm_config_v2(
struct pwm_chip *chip,
106 unsigned long long c;
107 unsigned long period_cycles, duty_cycles,
prescale;
115 prescale = period_cycles / 0x10000 + 1;
118 c = (
unsigned long long)period_cycles * duty_ns;
126 if (period_cycles > 2)
146 static void imx_pwm_set_enable_v2(
struct pwm_chip *chip,
bool enable)
161 static int imx_pwm_config(
struct pwm_chip *chip,
162 struct pwm_device *pwm,
int duty_ns,
int period_ns)
167 ret = clk_prepare_enable(imx->
clk_ipg);
171 ret = imx->
config(chip, pwm, duty_ns, period_ns);
173 clk_disable_unprepare(imx->
clk_ipg);
183 ret = clk_prepare_enable(imx->
clk_per);
200 clk_disable_unprepare(imx->
clk_per);
204 static struct pwm_ops imx_pwm_ops = {
205 .enable = imx_pwm_enable,
206 .disable = imx_pwm_disable,
207 .config = imx_pwm_config,
218 .config = imx_pwm_config_v1,
219 .set_enable = imx_pwm_set_enable_v1,
223 .config = imx_pwm_config_v2,
224 .set_enable = imx_pwm_set_enable_v2,
228 { .compatible =
"fsl,imx1-pwm", .data = &imx_pwm_data_v1, },
229 { .compatible =
"fsl,imx27-pwm", .data = &imx_pwm_data_v2, },
248 dev_err(&pdev->
dev,
"failed to allocate memory\n");
254 dev_err(&pdev->
dev,
"getting per clock failed with %ld\n",
261 dev_err(&pdev->
dev,
"getting ipg clock failed with %ld\n",
266 imx->
chip.ops = &imx_pwm_ops;
273 dev_err(&pdev->
dev,
"no memory resource defined\n");
289 platform_set_drvdata(pdev, imx);
297 imx = platform_get_drvdata(pdev);
309 .probe = imx_pwm_probe,