/* argument 'wait' is the time we know the voltage difference can be measured this function keeps reading the voltage until it is stable  */
static int wait_for_voltage_stable(int wait)
/* argument 'wait' is the time we know the voltage difference can be measured this function keeps reading the voltage until it is stable  */
static int wait_for_voltage_stable(int wait)
{
	int timeout, vdd_current, vdd_last;
	vdd_last = read_voltage();
	udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
	vdd_current = read_voltage();
	for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
		timeout < 100; timeout++) {
		vdd_last = vdd_current;
		udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
		vdd_current = read_voltage();
	}
	if (timeout >= 100) {
		printf("VID: Voltage adjustment timeout\n");
		return -1;
	}
	return vdd_current;
}