sf: Use spi_flash_alloc() in each SPI flash driver
authorSimon Glass <sjg@chromium.org>
Mon, 11 Mar 2013 06:08:03 +0000 (06:08 +0000)
committerSimon Glass <sjg@chromium.org>
Tue, 19 Mar 2013 15:45:36 +0000 (08:45 -0700)
Rather than each device having its own way to allocate a SPI flash
structure, use the new allocation function everywhere. This will make it
easier to extend the interface without breaking devices.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/mtd/spi/atmel.c
drivers/mtd/spi/eon.c
drivers/mtd/spi/macronix.c
drivers/mtd/spi/ramtron.c
drivers/mtd/spi/spansion.c
drivers/mtd/spi/sst.c
drivers/mtd/spi/stmicro.c
drivers/mtd/spi/winbond.c

index 006f6d5d04fcb2258b3014fa41a32bdbadd8fb56..6a92c4b774b41ff85dbb834ccc206e12b8a7017d 100644 (file)
@@ -480,15 +480,13 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       asf = malloc(sizeof(struct atmel_spi_flash));
+       asf = spi_flash_alloc(struct atmel_spi_flash, spi, params->name);
        if (!asf) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
        asf->params = params;
-       asf->flash.spi = spi;
-       asf->flash.name = params->name;
 
        /* Assuming power-of-two page size initially. */
        page_size = 1 << params->l2_page_size;
@@ -513,7 +511,6 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
                        asf->flash.erase = dataflash_erase_at45;
                        page_size += 1 << (params->l2_page_size - 5);
                } else {
-                       asf->flash.read = spi_flash_cmd_read_fast;
                        asf->flash.write = dataflash_write_p2;
                        asf->flash.erase = dataflash_erase_p2;
                }
@@ -524,9 +521,6 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 
        case DF_FAMILY_AT26F:
        case DF_FAMILY_AT26DF:
-               asf->flash.read = spi_flash_cmd_read_fast;
-               asf->flash.write = spi_flash_cmd_write_multi;
-               asf->flash.erase = spi_flash_cmd_erase;
                asf->flash.page_size = page_size;
                asf->flash.sector_size = 4096;
                /* clear SPRL# bit for locked flash */
index 691ed4efc4f61096da88314dc202f9c6b9a3f82f..b16e7ab098ea36b7d1146ad7028fe3ec910e2e85 100644 (file)
@@ -46,18 +46,12 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       flash = malloc(sizeof(*flash));
+       flash = spi_flash_alloc_base(spi, params->name);
        if (!flash) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
-       flash->spi = spi;
-       flash->name = params->name;
-
-       flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spi_flash_cmd_erase;
-       flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * 16 * 16;
        flash->size = 256 * 16
index c97a39d49981201aa66178716b1cd457b55b7edc..036c30d3beee54488de1b20b4cedd8b93b2a7d75 100644 (file)
@@ -97,18 +97,12 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       flash = malloc(sizeof(*flash));
+       flash = spi_flash_alloc_base(spi, params->name);
        if (!flash) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
-       flash->spi = spi;
-       flash->name = params->name;
-
-       flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spi_flash_cmd_erase;
-       flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * 16 * 16;
        flash->size = flash->sector_size * params->nr_blocks;
index 099978149696968452e2851530687f6b358d2c4f..5299a6dbde09882e1e76ca232442d68dba698237 100644 (file)
@@ -284,15 +284,13 @@ struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode)
        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;
index 9288672c84cfbfb1ba8b076a03b2c58e54d63ffe..bc558c4c96ba317bffac1a66730bc28c2f49be32 100644 (file)
@@ -128,18 +128,12 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       flash = malloc(sizeof(*flash));
+       flash = spi_flash_alloc_base(spi, params->name);
        if (!flash) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
-       flash->spi = spi;
-       flash->name = params->name;
-
-       flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spi_flash_cmd_erase;
-       flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * params->pages_per_sector;
        flash->size = flash->sector_size * params->nr_sectors;
index ced4f2473f47189c45169638df6b20cb5a500485..95f5490c350ac0f85287b518f1b2427286c30ee3 100644 (file)
@@ -203,22 +203,16 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       stm = malloc(sizeof(*stm));
+       stm = spi_flash_alloc(struct sst_spi_flash, spi, params->name);
        if (!stm) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
        stm->params = params;
-       stm->flash.spi = spi;
-       stm->flash.name = params->name;
 
        if (stm->params->flags & SST_FEAT_WP)
                stm->flash.write = sst_write_wp;
-       else
-               stm->flash.write = spi_flash_cmd_write_multi;
-       stm->flash.erase = spi_flash_cmd_erase;
-       stm->flash.read = spi_flash_cmd_read_fast;
        stm->flash.page_size = 256;
        stm->flash.sector_size = 4096;
        stm->flash.size = stm->flash.sector_size * params->nr_sectors;
index 8a193449d0cda34b983feed97b4fa4b481321569..2a9972bd4ee519f97c67c7df3e6c0c4ac49fa49d 100644 (file)
@@ -176,18 +176,12 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
                return NULL;
        }
 
-       flash = malloc(sizeof(*flash));
+       flash = spi_flash_alloc_base(spi, params->name);
        if (!flash) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
-       flash->spi = spi;
-       flash->name = params->name;
-
-       flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spi_flash_cmd_erase;
-       flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * params->pages_per_sector;
        flash->size = flash->sector_size * params->nr_sectors;
index 441830216944ef035d233ee72afd8e13b4662e50..05dc6449263d69aca7e5d7c582439b6c5b3dd304 100644 (file)
@@ -92,18 +92,12 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
                return NULL;
        }
 
-       flash = malloc(sizeof(*flash));
+       flash = spi_flash_alloc_base(spi, params->name);
        if (!flash) {
                debug("SF: Failed to allocate memory\n");
                return NULL;
        }
 
-       flash->spi = spi;
-       flash->name = params->name;
-
-       flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spi_flash_cmd_erase;
-       flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 4096;
        flash->size = 4096 * 16 * params->nr_blocks;