]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/spi/sf_probe.c
Merge 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / drivers / mtd / spi / sf_probe.c
index 15256369e087336b30e2f6274cedf94c01538b0c..b863a9828348a535b668c298f5a98a71434f6070 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2010 Reinhard Meyer, EMK Elektronik
  * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
  *
- * Licensed under the GPL-2 or later.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -13,6 +13,7 @@
 #include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <asm/io.h>
 
 #include "sf_internal.h"
 
@@ -25,7 +26,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * @jedec:             Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
  * @ext_jedec:         Device ext_jedec ID
  * @sector_size:       Sector size of this device
- * @nr_sectors:        No.of sectors on this device
+ * @nr_sectors:                No.of sectors on this device
  * @flags:             Importent param, for flash specific behaviour
  */
 struct spi_flash_params {
@@ -46,6 +47,7 @@ static const struct spi_flash_params spi_flash_params_table[] = {
        {"AT45DB161D",     0x1f2600, 0x0,       64 * 1024,    32,              SECT_4K},
        {"AT45DB321D",     0x1f2700, 0x0,       64 * 1024,    64,              SECT_4K},
        {"AT45DB641D",     0x1f2800, 0x0,       64 * 1024,   128,              SECT_4K},
+       {"AT25DF321",      0x1f4701, 0x0,       64 * 1024,    64,              SECT_4K},
 #endif
 #ifdef CONFIG_SPI_FLASH_EON            /* EON */
        {"EN25Q32B",       0x1c3016, 0x0,       64 * 1024,    64,                    0},
@@ -58,6 +60,7 @@ static const struct spi_flash_params spi_flash_params_table[] = {
        {"GD25LQ32",       0xc86016, 0x0,       64 * 1024,    64,              SECT_4K},
 #endif
 #ifdef CONFIG_SPI_FLASH_MACRONIX       /* MACRONIX */
+       {"MX25L2006E",     0xc22012, 0x0,       64 * 1024,     4,                    0},
        {"MX25L4005",      0xc22013, 0x0,       64 * 1024,     8,                    0},
        {"MX25L8005",      0xc22014, 0x0,       64 * 1024,    16,                    0},
        {"MX25L1605D",     0xc22015, 0x0,       64 * 1024,    32,                    0},
@@ -65,7 +68,7 @@ static const struct spi_flash_params spi_flash_params_table[] = {
        {"MX25L6405D",     0xc22017, 0x0,       64 * 1024,   128,                    0},
        {"MX25L12805",     0xc22018, 0x0,       64 * 1024,   256,                    0},
        {"MX25L25635F",    0xc22019, 0x0,       64 * 1024,   512,                    0},
-       {"MX25L51235F",    0xc2201A, 0x0,       64 * 1024,  1024,                    0},
+       {"MX25L51235F",    0xc2201a, 0x0,       64 * 1024,  1024,                    0},
        {"MX25L12855E",    0xc22618, 0x0,       64 * 1024,   256,                    0},
 #endif
 #ifdef CONFIG_SPI_FLASH_SPANSION       /* SPANSION */
@@ -139,7 +142,7 @@ static const struct spi_flash_params spi_flash_params_table[] = {
 #endif
        /*
         * Note:
-        * Below paired flash devices has similar spi_flash_params params.
+        * Below paired flash devices has similar spi_flash params.
         * (S25FL129P_64K, S25FL128S_64K)
         * (W25Q80BL, W25Q80BV)
         * (W25Q16CL, W25Q16DV)
@@ -152,7 +155,8 @@ static const struct spi_flash_params spi_flash_params_table[] = {
         */
 };
 
-struct spi_flash *spi_flash_validate_params(struct spi_slave *spi, u8 *idcode)
+static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
+               u8 *idcode)
 {
        const struct spi_flash_params *params;
        struct spi_flash *flash;
@@ -187,8 +191,10 @@ struct spi_flash *spi_flash_validate_params(struct spi_slave *spi, u8 *idcode)
        }
        memset(flash, '\0', sizeof(*flash));
 
+       /* Assign spi data */
        flash->spi = spi;
        flash->name = params->name;
+       flash->memory_map = spi->memory_map;
 
        /* Assign spi_flash ops */
        flash->write = spi_flash_cmd_write_ops;
@@ -223,8 +229,8 @@ struct spi_flash *spi_flash_validate_params(struct spi_slave *spi, u8 *idcode)
                flash->poll_cmd = CMD_FLAG_STATUS;
 #endif
 
+       /* Configure the BAR - discover bank cmds and read current bank */
 #ifdef CONFIG_SPI_FLASH_BAR
-       /* Configure the BAR - discover bank cmds and read current bank  */
        u8 curr_bank = 0;
        if (flash->size > SPI_FLASH_16MB_BOUN) {
                flash->bank_read_cmd = (idcode[0] == 0x01) ?
@@ -275,22 +281,19 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
                debug("%s: Memory map must cover entire device\n", __func__);
                return -1;
        }
-       flash->memory_map = (void *)addr;
+       flash->memory_map = map_sysmem(addr, size);
 
        return 0;
 }
 #endif /* CONFIG_OF_CONTROL */
 
-struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
-               unsigned int max_hz, unsigned int spi_mode)
+static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi)
 {
-       struct spi_slave *spi;
        struct spi_flash *flash = NULL;
        u8 idcode[5];
        int ret;
 
        /* Setup spi_slave */
-       spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
        if (!spi) {
                printf("SF: Failed to set up slave\n");
                return NULL;
@@ -354,6 +357,26 @@ err_claim_bus:
        return NULL;
 }
 
+struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
+               unsigned int max_hz, unsigned int spi_mode)
+{
+       struct spi_slave *spi;
+
+       spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
+       return spi_flash_probe_slave(spi);
+}
+
+#ifdef CONFIG_OF_SPI_FLASH
+struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
+                                     int spi_node)
+{
+       struct spi_slave *spi;
+
+       spi = spi_setup_slave_fdt(blob, slave_node, spi_node);
+       return spi_flash_probe_slave(spi);
+}
+#endif
+
 void spi_flash_free(struct spi_flash *flash)
 {
        spi_free_slave(flash->spi);