/* Status bytes (from index 1) contain 1's complement page indirection So for N writes: N=1: ff ff ff ff ff ff ff 00 N=2: ff fe ff ff ff ff ff 00 N=3: ff fe fd ff ff ff ff 00 N=4: ff fe fd fc ff ff ff 00  */
static int ds2502_indirect_page(struct udevice *dev, u8 *status, int page)
/* Status bytes (from index 1) contain 1's complement page indirection So for N writes: N=1: ff ff ff ff ff ff ff 00 N=2: ff fe ff ff ff ff ff 00 N=3: ff fe fd ff ff ff ff 00 N=4: ff fe fd fc ff ff ff 00  */
static int ds2502_indirect_page(struct udevice *dev, u8 *status, int page)
{
	int page_seen = 0;
	do {
		u8 sb = status[page + 1];
		if (sb == 0xff)
			break;
		page = ~sb & 0xff;
		if (page >= DS2502_PAGE_COUNT) {
			dev_err(dev,
				"Illegal page redirection status byte %02x\n",
				sb);
			return -EINVAL;
		}
		if (page_seen & (1 << page)) {
			dev_err(dev, "Infinite loop in page redirection\n");
			return -EINVAL;
		}
		page_seen |= (1 << page);
	} while (1);
	return page;
}