openocd: fix SPDX tag format for files .c
[fw/openocd] / src / flash / nand / mx3.c
index 4e53fe877b3001739ee24ae78c4f4f0c09ba4dbc..86e94685b7d2758a801ebcd0954ebabb871d6340 100644 (file)
@@ -1,23 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 
 /***************************************************************************
  *   Copyright (C) 2009 by Alexei Babich                                   *
  *   Rezonans plc., Chelyabinsk, Russia                                    *
  *   impatt@mail.ru                                                        *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 /*
@@ -42,7 +29,7 @@ get_next_halfword_from_sram_buffer() not tested
 static const char target_not_halted_err_msg[] =
                "target must be halted to use mx3 NAND flash controller";
 static const char data_block_size_err_msg[] =
-               "minimal granularity is one half-word, %" PRId32 " is incorrect";
+               "minimal granularity is one half-word, %" PRIu32 " is incorrect";
 static const char sram_buffer_bounds_err_msg[] =
                "trying to access out of SRAM buffer bound (addr=0x%" PRIx32 ")";
 static const char get_status_register_err_msg[] = "can't get NAND status";
@@ -66,7 +53,7 @@ NAND_DEVICE_COMMAND_HANDLER(imx31_nand_device_command)
 {
        struct mx3_nf_controller *mx3_nf_info;
        mx3_nf_info = malloc(sizeof(struct mx3_nf_controller));
-       if (mx3_nf_info == NULL) {
+       if (!mx3_nf_info) {
                LOG_ERROR("no memory for nand controller");
                return ERROR_FAIL;
        }
@@ -91,16 +78,7 @@ NAND_DEVICE_COMMAND_HANDLER(imx31_nand_device_command)
        mx3_nf_info->fin = MX3_NF_FIN_NONE;
        mx3_nf_info->flags.target_little_endian =
                        (nand->target->endianness == TARGET_LITTLE_ENDIAN);
-       /*
-       * testing host endianness
-       */
-       {
-               int x = 1;
-               if (*(char *) &x == 1)
-                       mx3_nf_info->flags.host_little_endian = 1;
-               else
-                       mx3_nf_info->flags.host_little_endian = 0;
-       }
+
        return ERROR_OK;
 }
 
@@ -160,7 +138,7 @@ static int imx31_init(struct nand_device *nand)
                uint32_t gpr_register_content;
                target_read_u32(target, MX3_GPR, &gpr_register_content);
                if (gpr_register_content & 0x00000060) {
-                       LOG_ERROR("pins mode overrided by GPR");
+                       LOG_ERROR("pins mode overridden by GPR");
                        return ERROR_FAIL;
                }
        }
@@ -292,6 +270,7 @@ static int imx31_command(struct nand_device *nand, uint8_t command)
                         * offset == one half of page size
                         */
                        in_sram_address = MX3_NF_MAIN_BUFFER0 + (nand->page_size >> 1);
+                       break;
                default:
                        in_sram_address = MX3_NF_MAIN_BUFFER0;
        }
@@ -424,10 +403,10 @@ static int imx31_write_page(struct nand_device *nand, uint32_t page,
                if (oob) {
                        if (mx3_nf_info->flags.hw_ecc_enabled) {
                                /*
-                                * part of spare block will be overrided by hardware
+                                * part of spare block will be overridden by hardware
                                 * ECC generator
                                 */
-                               LOG_DEBUG("part of spare block will be overrided by hardware ECC generator");
+                               LOG_DEBUG("part of spare block will be overridden by hardware ECC generator");
                        }
                        target_write_buffer(target, MX3_NF_SPARE_BUFFER0, oob_size, oob);
                }
@@ -540,7 +519,7 @@ static int initialize_nf_controller(struct nand_device *nand)
        struct mx3_nf_controller *mx3_nf_info = nand->controller_priv;
        struct target *target = nand->target;
        /*
-       * resets NAND flash controller in zero time ? I dont know.
+       * resets NAND flash controller in zero time ? I don't know.
        */
        target_write_u16(target, MX3_NF_CFG1, MX3_NF_BIT_RESET_EN);
        {
@@ -690,21 +669,19 @@ static int do_data_output(struct nand_device *nand)
                                target_read_u16 (target, MX3_NF_ECCSTATUS, &ecc_status);
                                switch (ecc_status & 0x000c) {
                                case 1 << 2:
-                                       LOG_DEBUG("main area readed with 1 (correctable) error");
+                                       LOG_DEBUG("main area read with 1 (correctable) error");
                                        break;
                                case 2 << 2:
-                                       LOG_DEBUG("main area readed with more than 1 (incorrectable) error");
+                                       LOG_DEBUG("main area read with more than 1 (incorrectable) error");
                                        return ERROR_NAND_OPERATION_FAILED;
-                                       break;
                                }
                                switch (ecc_status & 0x0003) {
                                case 1:
-                                       LOG_DEBUG("spare area readed with 1 (correctable) error");
+                                       LOG_DEBUG("spare area read with 1 (correctable) error");
                                        break;
                                case 2:
-                                       LOG_DEBUG("main area readed with more than 1 (incorrectable) error");
+                                       LOG_DEBUG("main area read with more than 1 (incorrectable) error");
                                        return ERROR_NAND_OPERATION_FAILED;
-                                       break;
                                }
                        }
                        break;