/* ECC Hamming calculation ECC is 3 bytes for 512 bytes of data (supports error correction up to max of 1-bit)  */
static int stm32_fmc2_ham_calculate(struct mtd_info *mtd, const u8 *data, u8 *ecc)
/* ECC Hamming calculation ECC is 3 bytes for 512 bytes of data (supports error correction up to max of 1-bit)  */
static int stm32_fmc2_ham_calculate(struct mtd_info *mtd, const u8 *data, u8 *ecc)
{
	struct nand_chip *chip = mtd_to_nand(mtd);
	struct stm32_fmc2_nfc *fmc2 = to_stm32_nfc(chip->controller);
	u32 heccr, sr;
	int ret;
	ret = readl_poll_timeout(fmc2->io_base + FMC2_SR, sr,
				 sr & FMC2_SR_NWRF, 10000);
	if (ret < 0) {
		pr_err("Ham timeout\n");
		return ret;
	}
	heccr = readl(fmc2->io_base + FMC2_HECCR);
	ecc[0] = heccr;
	ecc[1] = heccr >> 8;
	ecc[2] = heccr >> 16;
	stm32_fmc2_set_ecc(fmc2, false);
	return 0;
}