+static struct bch_regs bch_save;
+static struct bch_regs *bch_base = (void *)BCH_BASE_ADDRESS;
+
+/*
+ * Reprogram BCH engine for 40bit ECC on chunks of 128 byte
+ * and 32 byte of metadata as required by the i.MX6UL ROM code.
+ */
+static void tx6_init_bch(void)
+{
+ u32 fl0 = readl(&bch_base->hw_bch_flash0layout0);
+ u32 fl1 = readl(&bch_base->hw_bch_flash0layout1);
+
+ bch_save.hw_bch_flash0layout0 = fl0;
+ bch_save.hw_bch_flash0layout1 = fl1;
+
+ BF_SET_VAL(fl0, 32, BCH_FLASHLAYOUT0_META_SIZE);
+ BF_SET_VAL(fl0, 7, BCH_FLASHLAYOUT0_NBLOCKS);
+
+ BF_SET_VAL(fl0, 0x14, BCH_FLASHLAYOUT0_ECC0);
+ BF_SET_VAL(fl0, 128 / 4, BCH_FLASHLAYOUT0_DATA0_SIZE);
+
+ BF_SET_VAL(fl1, 0x14, BCH_FLASHLAYOUT1_ECCN);
+ BF_SET_VAL(fl1, 128 / 4, BCH_FLASHLAYOUT1_DATAN_SIZE);
+
+ writel(fl0, &bch_base->hw_bch_flash0layout0);
+ writel(fl1, &bch_base->hw_bch_flash0layout1);
+}
+
+static void tx6_restore_bch(void)
+{
+ writel(bch_save.hw_bch_flash0layout0, &bch_base->hw_bch_flash0layout0);
+ writel(bch_save.hw_bch_flash0layout1, &bch_base->hw_bch_flash0layout1);
+}
+