1 #include <linux/module.h>
4 #include <linux/slab.h>
49 static inline u32 pwm_readl(
const struct pwm *
p,
unsigned offset)
56 return p->
base + 0x200 + index * 0x20;
65 dev_dbg(dev,
"%s: mr %08x, sr %08x, imr %08x\n",
71 "pwm ch%d - mr %08x, dty %u, prd %u, cnt %u\n",
94 if (!pwm || !(pwm->
mask & 1 << index))
97 if (index < 0 || index >=
PWM_NCHAN || !ch)
107 ch->
regs = pwmc_regs(pwm, index);
117 pwm_writel(pwm,
PWM_DIS, 1 << index);
118 pwm_writel(pwm,
PWM_IDR, 1 << index);
120 spin_unlock_irqrestore(&pwm->
lock, flags);
159 pwm_writel(pwm,
PWM_DIS, 1 << t);
160 pwm_writel(pwm,
PWM_IDR, 1 << t);
165 spin_unlock_irqrestore(&pwm->
lock, flags);
182 pwm_dumpregs(ch, enabled ?
"enable" :
"disable");
184 spin_unlock_irqrestore(&pwm->
lock, flags);
204 u32 val = (prescale << 8) | div;
207 if (prescale >= 10 || div == 0 || div > 255)
211 mr = pwm_readl(pwm,
PWM_MR);
212 if ((mr & 0xffff) == 0) {
215 }
else if ((mr & (0xffff << 16)) == 0) {
220 pwm_writel(pwm,
PWM_MR, mr);
221 spin_unlock_irqrestore(&pwm->
lock, flags);
237 mr = pwm_readl(pwm,
PWM_MR);
239 pwm_writel(pwm,
PWM_MR, mr & ~(0xffff << 0));
241 pwm_writel(pwm,
PWM_MR, mr & ~(0xffff << 16));
242 spin_unlock_irqrestore(&pwm->
lock, flags);
268 spin_unlock_irqrestore(&pwm->
lock, flags);
276 struct pwm *
p = _pwm;
284 irqstat = pwm_readl(pwm,
PWM_ISR);
290 index =
ffs(irqstat) - 1;
291 irqstat &= ~(1 <<
index);
295 spin_unlock(&p->
lock);
302 spin_unlock(&p->
lock);
316 if (!r || irq < 0 || !mp || !*mp)
319 dev_warn(&pdev->
dev,
"mask 0x%x ... more than %d channels\n",
336 if (IS_ERR(p->
clk)) {
337 status = PTR_ERR(p->
clk);
347 platform_set_drvdata(pdev, p);
363 struct pwm *p = platform_get_drvdata(pdev);
396 static int __init pwm_init(
void)
402 static void __exit pwm_exit(
void)