14 #include <linux/module.h>
15 #include <linux/kernel.h>
17 #include <linux/slab.h>
23 #include <asm/div64.h>
24 #include <mach/hardware.h>
43 int duty_ns,
int period_ns)
54 if (period_cycles < 1)
57 prescale = (period_cycles - 1) / 1024;
58 pv = period_cycles / (prescale + 1) - 1;
63 if (duty_ns == period_ns)
66 dc = (pv + 1) * duty_ns / period_ns;
72 clk_prepare_enable(puv3->
clk);
78 clk_disable_unprepare(puv3->
clk);
87 return clk_prepare_enable(puv3->
clk);
94 clk_disable_unprepare(puv3->
clk);
97 static const struct pwm_ops puv3_pwm_ops = {
98 .config = puv3_pwm_config,
99 .enable = puv3_pwm_enable,
100 .disable = puv3_pwm_disable,
112 dev_err(&pdev->
dev,
"failed to allocate memory\n");
117 if (IS_ERR(puv3->
clk))
118 return PTR_ERR(puv3->
clk);
122 dev_err(&pdev->
dev,
"no memory resource defined\n");
131 puv3->
chip.ops = &puv3_pwm_ops;
132 puv3->
chip.base = -1;
137 dev_err(&pdev->
dev,
"pwmchip_add() failed: %d\n", ret);
141 platform_set_drvdata(pdev, puv3);
154 .name =
"PKUnity-v3-PWM",