SPDX: Convert all of our single license tags to Linux Kernel style
[oweals/u-boot.git] / drivers / mtd / nand / omap_gpmc.c
index 67f293dcd0169de92b669d83cf7eeeb88b25735c..6a050501b04b85bb891800008fb32653cffbed85 100644 (file)
@@ -1,13 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2004-2008 Texas Instruments, <www.ti.com>
  * Rohit Choraria <rohitkc@ti.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <asm/arch/mem.h>
 #include <linux/mtd/omap_gpmc.h>
 #include <linux/mtd/nand_ecc.h>
@@ -264,7 +263,8 @@ static int omap_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
-       uint32_t *ptr, val = 0;
+       const uint32_t *ptr;
+       uint32_t val = 0;
        int8_t i = 0, j;
 
        switch (info->ecc_scheme) {
@@ -655,14 +655,14 @@ static int omap_correct_data_bch_sw(struct mtd_info *mtd, u_char *data,
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = nand_get_controller_data(chip);
 
-       count = decode_bch(info->control, NULL, 512, read_ecc, calc_ecc,
-                                                       NULL, errloc);
+       count = decode_bch(info->control, NULL, SECTOR_BYTES,
+                               read_ecc, calc_ecc, NULL, errloc);
        if (count > 0) {
                /* correct errors */
                for (i = 0; i < count; i++) {
                        /* correct data only, not ecc bytes */
-                       if (errloc[i] < 8*512)
-                               data[errloc[i]/8] ^= 1 << (errloc[i] & 7);
+                       if (errloc[i] < SECTOR_BYTES << 3)
+                               data[errloc[i] >> 3] ^= 1 << (errloc[i] & 7);
                        debug("corrected bitflip %u\n", errloc[i]);
 #ifdef DEBUG
                        puts("read_ecc: ");
@@ -893,17 +893,14 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
 int __maybe_unused omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
 {
        struct nand_chip *nand;
-       struct mtd_info *mtd;
+       struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device);
        int err = 0;
 
-       if (nand_curr_device < 0 ||
-           nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
-           !nand_info[nand_curr_device]->name) {
+       if (!mtd) {
                printf("nand: error: no NAND devices found\n");
                return -ENODEV;
        }
 
-       mtd = nand_info[nand_curr_device];
        nand = mtd_to_nand(mtd);
        nand->options |= NAND_OWN_BUFFERS;
        nand->options &= ~NAND_SUBPAGE_READ;