20 #include <linux/module.h>
22 #include <linux/slab.h>
27 #include <mach/platform.h>
29 #define EP93XX_PWMx_TERM_COUNT 0x00
30 #define EP93XX_PWMx_DUTY_CYCLE 0x04
31 #define EP93XX_PWMx_ENABLE 0x08
32 #define EP93XX_PWMx_INVERT 0x0C
34 #define EP93XX_PWM_MAX_COUNT 0xFFFF
43 unsigned int val,
unsigned int off)
48 static inline unsigned int ep93xx_pwm_readl(
struct ep93xx_pwm *
pwm,
79 static inline int ep93xx_pwm_is_enabled(
struct ep93xx_pwm *
pwm)
94 static inline int ep93xx_pwm_is_inverted(
struct ep93xx_pwm *
pwm)
122 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
125 return sprintf(buf,
"%ld\n", rate / 2);
132 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
134 if (ep93xx_pwm_is_enabled(pwm)) {
136 u16 term = ep93xx_pwm_read_tc(pwm);
138 return sprintf(buf,
"%ld\n", rate / (term + 1));
140 return sprintf(buf,
"disabled\n");
148 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
157 ep93xx_pwm_disable(pwm);
167 term = ep93xx_pwm_read_tc(pwm);
172 ep93xx_pwm_write_tc(pwm, val);
173 ep93xx_pwm_write_dc(pwm, duty);
175 ep93xx_pwm_write_dc(pwm, duty);
176 ep93xx_pwm_write_tc(pwm, val);
179 if (!ep93xx_pwm_is_enabled(pwm))
180 ep93xx_pwm_enable(pwm);
188 static ssize_t ep93xx_pwm_get_duty_percent(
struct device *dev,
192 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
197 static ssize_t ep93xx_pwm_set_duty_percent(
struct device *dev,
201 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
209 if (val > 0 && val < 100) {
210 u32 term = ep93xx_pwm_read_tc(pwm);
211 ep93xx_pwm_write_dc(pwm, ((term + 1) * val / 100) - 1);
223 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
225 return sprintf(buf,
"%d\n", ep93xx_pwm_is_inverted(pwm));
232 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
241 ep93xx_pwm_normal(pwm);
243 ep93xx_pwm_invert(pwm);
253 ep93xx_pwm_get_freq, ep93xx_pwm_set_freq);
255 ep93xx_pwm_get_duty_percent, ep93xx_pwm_set_duty_percent);
257 ep93xx_pwm_get_invert, ep93xx_pwm_set_invert);
259 static struct attribute *ep93xx_pwm_attrs[] = {
260 &dev_attr_min_freq.attr,
261 &dev_attr_max_freq.attr,
263 &dev_attr_duty_percent.attr,
264 &dev_attr_invert.attr,
269 .attrs = ep93xx_pwm_attrs,
291 goto fail_no_mem_resource;
297 goto fail_no_mem_resource;
303 goto fail_no_ioremap;
311 if (IS_ERR(pwm->
clk)) {
312 err = PTR_ERR(pwm->
clk);
318 platform_set_drvdata(pdev, pwm);
321 ep93xx_pwm_disable(pwm);
335 fail_no_mem_resource:
344 struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
347 ep93xx_pwm_disable(pwm);
350 platform_set_drvdata(pdev,
NULL);
362 .name =
"ep93xx-pwm",
365 .remove =
__exit_p(ep93xx_pwm_remove),
368 static int __init ep93xx_pwm_init(
void)
373 static void __exit ep93xx_pwm_exit(
void)