int pwm_channel_alloc(int index, struct pwm_channel *ch) { unsigned long flags; int status = 0; /* insist on PWM init, with this signal pinned out */ if (!pwm || !(pwm->mask & 1 << index)) return -ENODEV; if (index < 0 || index >= PWM_NCHAN || !ch) return -EINVAL; memset(ch, 0, sizeof *ch); spin_lock_irqsave(&pwm->lock, flags); if (pwm->channel[index]) status = -EBUSY; else { clk_enable(pwm->clk); ch->regs = pwmc_regs(pwm, index); ch->index = index; /* REVISIT: ap7000 seems to go 2x as fast as we expect!! */ ch->mck = clk_get_rate(pwm->clk); pwm->channel[index] = ch; pwm->handler[index] = NULL; /* channel and irq are always disabled when we return */ pwm_writel(pwm, PWM_DIS, 1 << index); pwm_writel(pwm, PWM_IDR, 1 << index); } spin_unlock_irqrestore(&pwm->lock, flags); return status; }
int pwm_channel_alloc(int index, struct pwm_channel *ch) { unsigned long flags; int status = 0; if (!pwm || !(pwm->mask & 1 << index)) return -ENODEV; if (index < 0 || index >= PWM_NCHAN || !ch) return -EINVAL; memset(ch, 0, sizeof *ch); spin_lock_irqsave(&pwm->lock, flags); if (pwm->channel[index]) status = -EBUSY; else { clk_enable(pwm->clk); ch->regs = pwmc_regs(pwm, index); ch->index = index; ch->mck = clk_get_rate(pwm->clk); pwm->channel[index] = ch; pwm->handler[index] = NULL; pwm_writel(pwm, PWM_DIS, 1 << index); pwm_writel(pwm, PWM_IDR, 1 << index); } spin_unlock_irqrestore(&pwm->lock, flags); return status; }