sf: probe: Simply the BAR configuration logic
authorJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Thu, 26 Sep 2013 08:54:58 +0000 (14:24 +0530)
committerJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Mon, 7 Oct 2013 12:25:45 +0000 (17:55 +0530)
Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
drivers/mtd/spi/spi_flash_internal.h
drivers/mtd/spi/spi_flash_probe.c

index ce34ce0c34986afbb4f490e2e74ab139aa6606a1..61de2378fd11d16ba086e738877da0c1361fba80 100644 (file)
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
 
-/* Manufacture ID's */
-#define SPI_FLASH_SPANSION_IDCODE0     0x01
-#define SPI_FLASH_STMICRO_IDCODE0      0x20
-#define SPI_FLASH_WINBOND_IDCODE0      0xef
-
 #ifdef CONFIG_SPI_FLASH_BAR
 /* Bank addr access commands */
 # define CMD_BANKADDR_BRWR             0x17
@@ -102,9 +97,6 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 #ifdef CONFIG_SPI_FLASH_BAR
 /* Program the bank address register */
 int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel);
-
-/* Configure the BAR - discover the bank cmds */
-int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);
 #endif
 
 /*
index 8ea69158e72b1fe39a7f5cb29654dd761e982dc1..cc30ad1a8cada4e798640e3be65a0a7c3c2ebf23 100644 (file)
@@ -221,54 +221,36 @@ struct spi_flash *spi_flash_validate_ids(struct spi_slave *spi, u8 *idcode)
                flash->poll_cmd = CMD_FLAG_STATUS;
 #endif
 
-       /* Flash powers up read-only, so clear BP# bits */
-#if defined(CONFIG_SPI_FLASH_ATMEL) || \
-       defined(CONFIG_SPI_FLASH_MACRONIX) || \
-       defined(CONFIG_SPI_FLASH_SST)
-               spi_flash_cmd_write_status(flash, 0);
-#endif
-
-       return flash;
-}
-
 #ifdef CONFIG_SPI_FLASH_BAR
-int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
-{
-       u8 cmd;
+       /* Configure the BAR - discover bank cmds and read current bank  */
        u8 curr_bank = 0;
-
-       /* discover bank cmds */
-       switch (idcode0) {
-       case SPI_FLASH_SPANSION_IDCODE0:
-               flash->bank_read_cmd = CMD_BANKADDR_BRRD;
-               flash->bank_write_cmd = CMD_BANKADDR_BRWR;
-               break;
-       case SPI_FLASH_STMICRO_IDCODE0:
-       case SPI_FLASH_WINBOND_IDCODE0:
-               flash->bank_read_cmd = CMD_EXTNADDR_RDEAR;
-               flash->bank_write_cmd = CMD_EXTNADDR_WREAR;
-               break;
-       default:
-               printf("SF: Unsupported bank commands %02x\n", idcode0);
-               return -1;
-       }
-
-       /* read the bank reg - on which bank the flash is in currently */
-       cmd = flash->bank_read_cmd;
        if (flash->size > SPI_FLASH_16MB_BOUN) {
-               if (spi_flash_read_common(flash, &cmd, 1, &curr_bank, 1)) {
+               flash->bank_read_cmd = (idcode[0] == 0x01) ?
+                                       CMD_BANKADDR_BRRD : CMD_EXTNADDR_RDEAR;
+               flash->bank_write_cmd = (idcode[0] == 0x01) ?
+                                       CMD_BANKADDR_BRWR : CMD_EXTNADDR_WREAR;
+
+               if (spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
+                                         &curr_bank, 1)) {
                        debug("SF: fail to read bank addr register\n");
-                       return -1;
+                       return NULL;
                }
                flash->bank_curr = curr_bank;
        } else {
                flash->bank_curr = curr_bank;
        }
+#endif
 
-       return 0;
-}
+       /* Flash powers up read-only, so clear BP# bits */
+#if defined(CONFIG_SPI_FLASH_ATMEL) || \
+       defined(CONFIG_SPI_FLASH_MACRONIX) || \
+       defined(CONFIG_SPI_FLASH_SST)
+               spi_flash_cmd_write_status(flash, 0);
 #endif
 
+       return flash;
+}
+
 #ifdef CONFIG_OF_CONTROL
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
@@ -302,7 +284,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 {
        struct spi_slave *spi;
        struct spi_flash *flash = NULL;
-       u8 idcode[5], *idp;
+       u8 idcode[5];
        int ret;
 
        /* Setup spi_slave */
@@ -332,18 +314,10 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 #endif
 
        /* Validate ID's from flash dev table */
-       idp = idcode;
-       flash = spi_flash_validate_ids(spi, idp);
+       flash = spi_flash_validate_ids(spi, idcode);
        if (!flash)
                goto err_read_id;
 
-#ifdef CONFIG_SPI_FLASH_BAR
-       /* Configure the BAR - discover bank cmds and read current bank  */
-       ret = spi_flash_bank_config(flash, *idp);
-       if (ret < 0)
-               goto err_read_id;
-#endif
-
 #ifdef CONFIG_OF_CONTROL
        if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
                debug("SF: FDT decode error\n");