/* Wait for one or more bits in flag change. HDQ_FLAG_SET: wait until any bit in the flag is set. HDQ_FLAG_CLEAR: wait until all bits in the flag are cleared. return 0 on success and -ETIMEDOUT in the case of timeout.  */
static int hdq_wait_for_flag(struct hdq_data *hdq_data, u32 offset, u8 flag, u8 flag_set, u8 *status)
/* Wait for one or more bits in flag change. HDQ_FLAG_SET: wait until any bit in the flag is set. HDQ_FLAG_CLEAR: wait until all bits in the flag are cleared. return 0 on success and -ETIMEDOUT in the case of timeout.  */
static int hdq_wait_for_flag(struct hdq_data *hdq_data, u32 offset, u8 flag, u8 flag_set, u8 *status)
{
	int ret = 0;
	unsigned long timeout = jiffies + OMAP_HDQ_TIMEOUT;
	if (flag_set == OMAP_HDQ_FLAG_CLEAR) {
		while (((*status = hdq_reg_in(hdq_data, offset)) & flag)
			&& time_before(jiffies, timeout)) {
			schedule_timeout_uninterruptible(1);
		}
		if (*status & flag)
			ret = -ETIMEDOUT;
	} else if (flag_set == OMAP_HDQ_FLAG_SET) {
		while (!((*status = hdq_reg_in(hdq_data, offset)) & flag)
			&& time_before(jiffies, timeout)) {
			schedule_timeout_uninterruptible(1);
		}
		if (!(*status & flag))
			ret = -ETIMEDOUT;
	} else
		return -EINVAL;
	return ret;
}