]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/spi/ramtron.c
sf: Fix code cleanups
[karo-tx-uboot.git] / drivers / mtd / spi / ramtron.c
index 27d4039aadef64a0f0a2ab2f06774fe30a6caefc..38f9d69169b2ea4baa60b9f9839557e16855aad6 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2010
  * Reinhard Meyer, EMK Elektronik, reinhard.meyer@emk-elektronik.de
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * 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., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
 #include <spi_flash.h>
 #include "spi_flash_internal.h"
 
-/* RAMTRON commands common to all devices */
-#define CMD_RAMTRON_WREN       0x06    /* Write Enable */
-#define CMD_RAMTRON_WRDI       0x04    /* Write Disable */
-#define CMD_RAMTRON_RDSR       0x05    /* Read Status Register */
-#define CMD_RAMTRON_WRSR       0x01    /* Write Status Register */
-#define CMD_RAMTRON_READ       0x03    /* Read Data Bytes */
-#define CMD_RAMTRON_WRITE      0x02    /* Write Data Bytes */
-/* not all have those: */
-#define CMD_RAMTRON_FSTRD      0x0b    /* Fast Read (for compatibility - not used here) */
-#define CMD_RAMTRON_SLEEP      0xb9    /* Enter Sleep Mode */
-#define CMD_RAMTRON_RDID       0x9f    /* Read ID */
-#define CMD_RAMTRON_SNR                0xc3    /* Read Serial Number */
-
 /*
  * Properties of supported FRAMs
  * Note: speed is currently not used because we have no method to deliver that
@@ -196,7 +167,7 @@ static int ramtron_common(struct spi_flash *flash,
                return ret;
        }
 
-       if (command == CMD_RAMTRON_WRITE) {
+       if (command == CMD_PAGE_PROGRAM) {
                /* send WREN */
                ret = spi_flash_cmd_write_enable(flash);
                if (ret < 0) {
@@ -206,7 +177,7 @@ static int ramtron_common(struct spi_flash *flash,
        }
 
        /* do the transaction */
-       if (command == CMD_RAMTRON_WRITE)
+       if (command == CMD_PAGE_PROGRAM)
                ret = spi_flash_cmd_write(flash->spi, cmd, cmd_len, buf, len);
        else
                ret = spi_flash_cmd_read(flash->spi, cmd, cmd_len, buf, len);
@@ -223,14 +194,14 @@ static int ramtron_read(struct spi_flash *flash,
                u32 offset, size_t len, void *buf)
 {
        return ramtron_common(flash, offset, len, buf,
-               CMD_RAMTRON_READ);
+               CMD_READ_ARRAY_SLOW);
 }
 
 static int ramtron_write(struct spi_flash *flash,
                u32 offset, size_t len, const void *buf)
 {
        return ramtron_common(flash, offset, len, (void *)buf,
-               CMD_RAMTRON_WRITE);
+               CMD_PAGE_PROGRAM);
 }
 
 static int ramtron_erase(struct spi_flash *flash, u32 offset, size_t len)
@@ -259,7 +230,8 @@ struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode)
                /* JEDEC conformant RAMTRON id */
                for (i = 0; i < ARRAY_SIZE(ramtron_spi_fram_table); i++) {
                        params = &ramtron_spi_fram_table[i];
-                       if (idcode[1] == params->id1 && idcode[2] == params->id2)
+                       if (idcode[1] == params->id1 &&
+                           idcode[2] == params->id2)
                                goto found;
                }
                break;
@@ -270,7 +242,7 @@ struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode)
                 * We COULD have a non JEDEC conformant FRAM here,
                 * read the status register to verify
                 */
-               ret = spi_flash_cmd(spi, CMD_RAMTRON_RDSR, &sr, 1);
+               ret = spi_flash_cmd(spi, CMD_READ_STATUS, &sr, 1);
                if (ret)
                        return NULL;
 
@@ -280,7 +252,8 @@ struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode)
                /* now find the device */
                for (i = 0; i < ARRAY_SIZE(ramtron_spi_fram_table); i++) {
                        params = &ramtron_spi_fram_table[i];
-                       if (!strcmp(params->name, CONFIG_SPI_FRAM_RAMTRON_NON_JEDEC))
+                       if (!strcmp(params->name,
+                                   CONFIG_SPI_FRAM_RAMTRON_NON_JEDEC))
                                goto found;
                }
                debug("SF: Unsupported non-JEDEC RAMTRON device "
@@ -293,19 +266,17 @@ struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode)
 
        /* arriving here means no method has found a device we can handle */
        debug("SF/ramtron: unsupported device id0=%02x id1=%02x id2=%02x\n",
-               idcode[0], idcode[1], idcode[2]);
+             idcode[0], idcode[1], idcode[2]);
        return NULL;
 
 found:
-       sn = malloc(sizeof(*sn));
+       sn = spi_flash_alloc(struct ramtron_spi_fram, spi, params->name);
        if (!sn) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
        sn->params = params;
-       sn->flash.spi = spi;
-       sn->flash.name = params->name;
 
        sn->flash.write = ramtron_write;
        sn->flash.read = ramtron_read;