/* write_oob_to_regs - write data to OOB registers @i: sub-page sector index @oob: buffer to write from @sas: spare area sector size (i.e., OOB size per FLASH_CACHE) @sector_1k: 1 for 1KiB sectors, 0 for 512B, other values are illegal  */
static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, const u8 *oob, int sas, int sector_1k)
/* write_oob_to_regs - write data to OOB registers @i: sub-page sector index @oob: buffer to write from @sas: spare area sector size (i.e., OOB size per FLASH_CACHE) @sector_1k: 1 for 1KiB sectors, 0 for 512B, other values are illegal  */
static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, const u8 *oob, int sas, int sector_1k)
{
	int tbytes = sas << sector_1k;
	int j;
	if (sector_1k && (i & 0x01))
		tbytes = max(0, tbytes - (int)ctrl->max_oob);
	tbytes = min_t(int, tbytes, ctrl->max_oob);
	for (j = 0; j < tbytes; j += 4)
		oob_reg_write(ctrl, j,
				(oob[j + 0] << 24) |
				(oob[j + 1] << 16) |
				(oob[j + 2] <<  8) |
				(oob[j + 3] <<  0));
	return tbytes;
}