/* Drivers allocate PWM channels according to the board's wiring, and matching board-specific setup code. Returns zero or negative errno.  */
int pwm_channel_alloc(int index, struct pwm_channel *ch)
/* Drivers allocate PWM channels according to the board's wiring, and matching board-specific setup code. Returns zero or negative errno.  */
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;
}