/* Wait for flags to become set on the STATUS register on a CAM interface, checking for errors and timeout. */
static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot, u8 waitfor, int timeout_hz)
/* Wait for flags to become set on the STATUS register on a CAM interface, checking for errors and timeout. */
static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot, u8 waitfor, int timeout_hz)
{
	unsigned long timeout;
	unsigned long start;
	dprintk("%s\n", __func__);
	start = jiffies;
	timeout = jiffies + timeout_hz;
	while (1) {
		int res = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS);
		if (res < 0)
			return -EIO;
		if (res & waitfor) {
			dprintk("%s succeeded timeout:%lu\n", __func__, jiffies - start);
			return 0;
		}
		if (time_after(jiffies, timeout)) {
			break;
		}
		msleep(1);
	}
	dprintk("%s failed timeout:%lu\n", __func__, jiffies - start);
	return -ETIMEDOUT;
}