/* If called for a synchronised ADC conversion, it may sleep with the ADC semaphore held.  */
unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync)
/* If called for a synchronised ADC conversion, it may sleep with the ADC semaphore held.  */
unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync)
{
	unsigned int val;
	if (sync)
		adc_channel |= UCB_ADC_SYNC_ENA;
	ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel);
	ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel | UCB_ADC_START);
	for (;;) {
		val = ucb1x00_reg_read(ucb, UCB_ADC_DATA);
		if (val & UCB_ADC_DAT_VAL)
			break;
		set_current_state(TASK_INTERRUPTIBLE);
		schedule_timeout(1);
	}
	return UCB_ADC_DAT(val);
}